id and ad on a comment that belongs to no form find no object

This commit is contained in:
Joseph Ferano 2026-09-25 21:05:02 +07:00
parent 095701b29b
commit 5c044a7b40
2 changed files with 29 additions and 3 deletions

View File

@ -1596,9 +1596,16 @@ On a comment block that sits directly on a form, that form."
(while (and (flan-fln--comment-line-p (point))
(zerop (current-indentation))
(zerop (forward-line 1))))
(if (flan-fln--toplevel-start-p (point)) (point) pos))))
(flan-fln--with-comments
(flan-fln--whole-lines (flan-fln--toplevel-bounds pos)))))
(if (flan-fln--toplevel-start-p (point)) (point) pos)))
(orig pos))
;; A lone comment -- a blank line away from every form -- belongs to
;; none, and the form above it is not what was pointed at.
(let ((b (flan-fln--with-comments
(flan-fln--whole-lines (flan-fln--toplevel-bounds pos)))))
(and b
(or (not (flan-fln--comment-line-p orig))
(and (<= (car b) orig) (< orig (cdr b))))
b))))
(defun flan-fln--with-trailing-blanks (b)
"Whole lines B and the empty lines after them.

View File

@ -891,6 +891,25 @@ comment:
(test-flan-fln--is (format "under Evil, %s on %s keeps comments with their forms"
(car c) (nth 1 c))
(funcall deleted (car c) (nth 1 c)) (nth 2 c)))
;; A lone comment belongs to no form: id and ad find nothing.
(dolist (text '("fn a() -> i64\n 1\n\n; lone\n\nfn b() -> i64\n 2\n"
"fn a() -> i64\n 1\n\n; lone\n"))
(dolist (keys '("did" "dad"))
(let ((b (generate-new-buffer "lone.fln")))
(switch-to-buffer b)
(insert text)
(flan-fln-mode)
(evil-initialize-state)
(evil-normal-state)
(goto-char (point-min))
(search-forward "; lone")
(goto-char (match-beginning 0))
(ignore-errors (execute-kbd-macro keys))
(test-flan-fln--is (format "under Evil, %s on a lone comment%s changes nothing"
keys (if (string-suffix-p "lone\n" text) " at the end" ""))
(buffer-string) text)
(set-buffer-modified-p nil)
(kill-buffer b))))
;; A comment deeper than a form, at the end of its block, is
;; that block's, not the next form's.
(dolist (c '(("dad" "fn a" "fn a() -> i64\n 1\n ; end of a\nfn b() -> i64\n 2\n"