From b11894aa556d94c8bc9c0b52082af91d30227f50 Mon Sep 17 00:00:00 2001 From: Ihor Radchenko Date: Thu, 3 Aug 2023 16:03:56 +0300 Subject: [PATCH] org-lint: Use markers instead of line number to track report positions * lisp/org-lint.el (org-lint--generate-reports): Store marker to reports as text property in the Line field. (org-lint--current-marker): New function retrieving marker corresponding to current report. (org-lint--jump-to-source): Jump using marker, not line number. This fixes *Org Lint* report jumping to wrong location when the Org buffer is edited while going through the report. --- lisp/org-lint.el | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/lisp/org-lint.el b/lisp/org-lint.el index 6259e7e47..bb8e7c7c2 100644 --- a/lisp/org-lint.el +++ b/lisp/org-lint.el @@ -210,9 +210,11 @@ for `tabulated-list-printer'." (progn (goto-char (car report)) (forward-line 0) - (prog1 (number-to-string - (cl-incf last-line - (count-lines last-pos (point)))) + (prog1 (propertize + (number-to-string + (cl-incf last-line + (count-lines last-pos (point)))) + 'org-lint-marker (car report)) (setf last-pos (point)))) (cdr report))))) ;; Insert trust level in generated reports. Also sort them @@ -222,7 +224,7 @@ for `tabulated-list-printer'." (let ((trust (symbol-name (org-lint-checker-trust c)))) (mapcar (lambda (report) - (list (car report) trust (nth 1 report) c)) + (list (copy-marker (car report)) trust (nth 1 report) c)) (save-excursion (funcall (org-lint-checker-function c) ast))))) @@ -245,6 +247,10 @@ for `tabulated-list-printer'." "Return current report line, as a number." (string-to-number (aref (tabulated-list-get-entry) 0))) +(defun org-lint--current-marker () + "Return current report marker." + (get-text-property 0 'org-lint-marker (aref (tabulated-list-get-entry) 0))) + (defun org-lint--current-checker (&optional entry) "Return current report checker. When optional argument ENTRY is non-nil, use this entry instead @@ -266,9 +272,9 @@ CHECKERS is the list of checkers used." (defun org-lint--jump-to-source () "Move to source line that generated the report at point." (interactive) - (let ((l (org-lint--current-line))) + (let ((mk (org-lint--current-marker))) (switch-to-buffer-other-window org-lint--source-buffer) - (org-goto-line l) + (goto-char mk) (org-fold-show-set-visibility 'local) (recenter)))