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.
This commit is contained in:
Ihor Radchenko 2023-08-03 16:03:56 +03:00
parent 8b9e3be9a9
commit b11894aa55
No known key found for this signature in database
GPG Key ID: 6470762A7DA11D8B
1 changed files with 12 additions and 6 deletions

View File

@ -210,9 +210,11 @@ for `tabulated-list-printer'."
(progn (progn
(goto-char (car report)) (goto-char (car report))
(forward-line 0) (forward-line 0)
(prog1 (number-to-string (prog1 (propertize
(number-to-string
(cl-incf last-line (cl-incf last-line
(count-lines last-pos (point)))) (count-lines last-pos (point))))
'org-lint-marker (car report))
(setf last-pos (point)))) (setf last-pos (point))))
(cdr report))))) (cdr report)))))
;; Insert trust level in generated reports. Also sort them ;; 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)))) (let ((trust (symbol-name (org-lint-checker-trust c))))
(mapcar (mapcar
(lambda (report) (lambda (report)
(list (car report) trust (nth 1 report) c)) (list (copy-marker (car report)) trust (nth 1 report) c))
(save-excursion (save-excursion
(funcall (org-lint-checker-function c) (funcall (org-lint-checker-function c)
ast))))) ast)))))
@ -245,6 +247,10 @@ for `tabulated-list-printer'."
"Return current report line, as a number." "Return current report line, as a number."
(string-to-number (aref (tabulated-list-get-entry) 0))) (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) (defun org-lint--current-checker (&optional entry)
"Return current report checker. "Return current report checker.
When optional argument ENTRY is non-nil, use this entry instead 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 () (defun org-lint--jump-to-source ()
"Move to source line that generated the report at point." "Move to source line that generated the report at point."
(interactive) (interactive)
(let ((l (org-lint--current-line))) (let ((mk (org-lint--current-marker)))
(switch-to-buffer-other-window org-lint--source-buffer) (switch-to-buffer-other-window org-lint--source-buffer)
(org-goto-line l) (goto-char mk)
(org-fold-show-set-visibility 'local) (org-fold-show-set-visibility 'local)
(recenter))) (recenter)))