Ihor Radchenko <[email protected]> writes: > Yes, org-move-marker will make sense. At least, we commonly use that > kind of naming to expand built-in functions.
Thanks, renamed to org-move-marker. If this version looks good to you, shall I merge it? > Also, I think there are some places where we do almost the same thing, > but copy marker. I’ll look into similar uses of copy-marker separately later. -- Slawomir Grochowski
>From 0617c1225c4fcd5d55ff95cf3528b0415be17d27 Mon Sep 17 00:00:00 2001 From: Slawomir Grochowski <[email protected]> Date: Sat, 13 Jun 2026 08:20:30 +0200 Subject: [PATCH] ; org: Move marker helper to org-macs * lisp/org-macs.el (org-move-marker): New function. * lisp/org-colview.el (org-columns--ensure-and-move-marker): Remove. (org-columns-goto-top-level, org-columns--prepare-rows) (org-agenda-columns): Use `org-move-marker'. * lisp/org-table.el (org-table-recalculate, org-table-analyze): Use it. * testing/lisp/test-org-macs.el (test-org/move-marker): Test it. Refactoring: Move Function, Replace Inline Code with Function Call. No behavior change. --- lisp/org-colview.el | 12 +++--------- lisp/org-macs.el | 6 ++++++ lisp/org-table.el | 12 +++++------- testing/lisp/test-org-macs.el | 11 +++++++++++ 4 files changed, 25 insertions(+), 16 deletions(-) diff --git a/lisp/org-colview.el b/lisp/org-colview.el index 92556d0c7..124e756a5 100644 --- a/lisp/org-colview.el +++ b/lisp/org-colview.el @@ -978,18 +978,12 @@ back to the next source, ultimately to (org-columns-compile-format selected-columns-format) selected-columns-format)) -(defun org-columns--ensure-and-move-marker (marker &optional position) - "Return MARKER moved to POSITION in the current buffer. -When MARKER is nil, create a new marker first. POSITION defaults -to point." - (move-marker (or marker (make-marker)) (or position (point)))) - (defun org-columns-goto-top-level () "Move to the beginning of the column view area. Also sets `org-columns-top-level-marker' to the new position." (goto-char (setq org-columns-top-level-marker - (org-columns--ensure-and-move-marker + (org-move-marker org-columns-top-level-marker (cond ((org-before-first-heading-p) (point-min)) ((org-entry-get nil "COLUMNS" t) org-entry-property-inherited-from) @@ -1013,7 +1007,7 @@ COLUMNS-FORMAT is non-nil, use it instead of the format selected from the buffer." (when global (goto-char (point-min))) (setq org-columns-begin-marker - (org-columns--ensure-and-move-marker org-columns-begin-marker)) + (org-move-marker org-columns-begin-marker)) (org-columns-goto-top-level) (org-columns-get-format columns-format) (unless org-columns-inhibit-recalculation (org-columns-compute-all)) @@ -1960,7 +1954,7 @@ definition." (interactive nil org-agenda-mode) (org-columns-remove-overlays) (setq org-columns-begin-marker - (org-columns--ensure-and-move-marker org-columns-begin-marker)) + (org-move-marker org-columns-begin-marker)) (let* ((org-columns--time (float-time)) (org-done-keywords org-done-keywords-for-agenda) (columns-format diff --git a/lisp/org-macs.el b/lisp/org-macs.el index 2e482bb14..b18618d9f 100644 --- a/lisp/org-macs.el +++ b/lisp/org-macs.el @@ -743,6 +743,12 @@ Optional argument REGEXP selects variables to clone." ;;; Miscellaneous +(defun org-move-marker (marker &optional position) + "Move MARKER to POSITION in the current buffer and return it. +When MARKER is nil, create a new marker first. POSITION defaults +to point." + (move-marker (or marker (make-marker)) (or position (point)))) + (defsubst org-call-with-arg (command arg) "Call COMMAND interactively, but pretend prefix arg was ARG." (let ((current-prefix-arg arg)) (call-interactively command))) diff --git a/lisp/org-table.el b/lisp/org-table.el index c0e2c140c..633017b11 100644 --- a/lisp/org-table.el +++ b/lisp/org-table.el @@ -3052,10 +3052,9 @@ existing formula for column %s" (org-table-message-once-per-second log-last-time "Re-applying formulas to full table...(line %d)" cnt))) - (if (markerp org-last-recalc-line) - (move-marker org-last-recalc-line (line-beginning-position)) - (setq org-last-recalc-line - (copy-marker (line-beginning-position)))) + (setq org-last-recalc-line + (org-move-marker + org-last-recalc-line (line-beginning-position))) (dolist (entry eqlcol) (goto-char org-last-recalc-line) (org-table-goto-column @@ -4954,9 +4953,8 @@ This function sets up the following dynamically scoped variables: (push (list field line col) org-table-named-field-locations)))))))))) ;; Reuse existing markers when possible. - (if (markerp org-table-current-begin-pos) - (move-marker org-table-current-begin-pos (point)) - (setq org-table-current-begin-pos (point-marker))) + (setq org-table-current-begin-pos + (org-move-marker org-table-current-begin-pos)) ;; Analyze the line types. (let ((l 0) hlines dlines types) (while (looking-at "[ \t]*|\\(-\\)?") diff --git a/testing/lisp/test-org-macs.el b/testing/lisp/test-org-macs.el index 015668fc8..d68895272 100644 --- a/testing/lisp/test-org-macs.el +++ b/testing/lisp/test-org-macs.el @@ -154,6 +154,17 @@ ;;; Buffers +(ert-deftest test-org/move-marker () + "Test `org-move-marker' specifications." + (org-test-with-temp-text "A<point>B" + (let ((marker (org-move-marker nil))) + (should (markerp marker)) + (should (eq (current-buffer) (marker-buffer marker))) + (should (= (point) marker)) + (goto-char (point-min)) + (should (eq marker (org-move-marker marker (point-max)))) + (should (= (point-max) marker))))) + (ert-deftest test-org-base-buffer-file-name () "Test `org-base-buffer-file-name'." ;; Test direct buffer resolution -- 2.39.5
