From 5c044a7b406e6ba986da5bcd3df96ef84d28d991 Mon Sep 17 00:00:00 2001 From: Joseph Ferano Date: Fri, 25 Sep 2026 21:05:02 +0700 Subject: [PATCH] id and ad on a comment that belongs to no form find no object --- emacs/flan-fln-mode.el | 13 ++++++++++--- emacs/test-flan-fln.el | 19 +++++++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/emacs/flan-fln-mode.el b/emacs/flan-fln-mode.el index e34cf308..dfd90147 100644 --- a/emacs/flan-fln-mode.el +++ b/emacs/flan-fln-mode.el @@ -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. diff --git a/emacs/test-flan-fln.el b/emacs/test-flan-fln.el index 0dbb9014..cd114184 100644 --- a/emacs/test-flan-fln.el +++ b/emacs/test-flan-fln.el @@ -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"