Skip to content

Commit 5a1b050

Browse files
committed
org-colview: Do not rely on `current-column' ignoring display properties
* lisp/org-macs.el (org-current-text-column): New macro calculating current column without accounting display text properties. * lisp/org-colview.el (org-columns-check-computed): (org-columns-next-allowed-value): (org-columns-new): (org-columns-delete): (org-columns-edit-attributes): (org-columns-widen): (org-columns-move-right): (org-columns-move-left): (org-columns-update): Use the new macro when calculating point position in the column view table overlay. Do _not_ use the new macro when we want to get the visual column position of the point. Fixes "test-org-colview/" failures on Emacs 29 after Emacs commit 4243747b1b8c3b7e3463822804b32e83febe2878: ;; Fix 'current-column' in the presence of display strings ;; * src/indent.c (check_display_width): Support calculation of width ;; of 'display' properties whose values are strings. This fixes the ;; value returned by 'current-column' when display strings are ;; present between BOL and point. (Bug#53795) See https://orgmode.org/list/CACnOyijQc7BDDtrYQb+=VoGWkpWAyMu7O4qsvGpsU6SCgwiM8Q@mail.gmail.com
1 parent 8f5bf17 commit 5a1b050

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

lisp/org-colview.el

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ for the duration of the command.")
557557

558558
(defun org-columns-check-computed ()
559559
"Throw an error if current column value is computed."
560-
(let ((spec (nth (current-column) org-columns-current-fmt-compiled)))
560+
(let ((spec (nth (org-current-text-column) org-columns-current-fmt-compiled)))
561561
(and
562562
(nth 3 spec)
563563
(assoc spec (get-text-property (line-beginning-position) 'org-summaries))
@@ -713,7 +713,8 @@ When PREVIOUS is set, go to the previous value. When NTH is
713713
an integer, select that value."
714714
(interactive)
715715
(org-columns-check-computed)
716-
(let* ((column (current-column))
716+
(let* ((column (org-current-text-column))
717+
(visible-column (current-column))
717718
(key (get-char-property (point) 'org-columns-key))
718719
(value (get-char-property (point) 'org-columns-value))
719720
(pom (or (get-text-property (line-beginning-position) 'org-hd-marker)
@@ -763,7 +764,7 @@ an integer, select that value."
763764
;; the right place on the current line.
764765
(let ((org-columns-inhibit-recalculation)) (org-columns-redo))
765766
(org-columns-update key)
766-
(org-move-to-column column))))))
767+
(org-move-to-column visible-column))))))
767768

768769
(defun org-colview-construct-allowed-dates (s)
769770
"Construct a list of three dates around the date in S.
@@ -925,14 +926,14 @@ details."
925926
(if spec
926927
(progn (setcar spec (car new))
927928
(setcdr spec (cdr new)))
928-
(push new (nthcdr (current-column) org-columns-current-fmt-compiled)))
929+
(push new (nthcdr (org-current-text-column) org-columns-current-fmt-compiled)))
929930
(org-columns-store-format)
930931
(org-columns-redo)))
931932

932933
(defun org-columns-delete ()
933934
"Delete the column at point from columns view."
934935
(interactive)
935-
(let ((spec (nth (current-column) org-columns-current-fmt-compiled)))
936+
(let ((spec (nth (org-current-text-column) org-columns-current-fmt-compiled)))
936937
(when (y-or-n-p (format "Are you sure you want to remove column %S? "
937938
(nth 1 spec)))
938939
(setq org-columns-current-fmt-compiled
@@ -942,18 +943,18 @@ details."
942943
;; updating it may prove counter-intuitive. See comments in
943944
;; `org-columns-move-right' for details.
944945
(let ((org-columns-inhibit-recalculation t)) (org-columns-redo))
945-
(when (>= (current-column) (length org-columns-current-fmt-compiled))
946+
(when (>= (org-current-text-column) (length org-columns-current-fmt-compiled))
946947
(backward-char)))))
947948

948949
(defun org-columns-edit-attributes ()
949950
"Edit the attributes of the current column."
950951
(interactive)
951-
(org-columns-new (nth (current-column) org-columns-current-fmt-compiled)))
952+
(org-columns-new (nth (org-current-text-column) org-columns-current-fmt-compiled)))
952953

953954
(defun org-columns-widen (arg)
954955
"Make the column wider by ARG characters."
955956
(interactive "p")
956-
(let* ((n (current-column))
957+
(let* ((n (org-current-text-column))
957958
(entry (nth n org-columns-current-fmt-compiled))
958959
(width (aref org-columns-current-maxwidths n)))
959960
(setq width (max 1 (+ width arg)))
@@ -969,7 +970,7 @@ details."
969970
(defun org-columns-move-right ()
970971
"Swap this column with the one to the right."
971972
(interactive)
972-
(let* ((n (current-column))
973+
(let* ((n (org-current-text-column))
973974
(cell (nthcdr n org-columns-current-fmt-compiled))
974975
e)
975976
(when (>= n (1- (length org-columns-current-fmt-compiled)))
@@ -993,7 +994,7 @@ details."
993994
(defun org-columns-move-left ()
994995
"Swap this column with the one to the left."
995996
(interactive)
996-
(let* ((n (current-column)))
997+
(let* ((n (org-current-text-column)))
997998
(when (= n 0)
998999
(error "Cannot shift this column further to the left"))
9991000
(backward-char 1)
@@ -1039,7 +1040,7 @@ the current buffer."
10391040
(let ((key (overlay-get ov 'org-columns-key)))
10401041
(when (and key (equal key p) (overlay-start ov))
10411042
(goto-char (overlay-start ov))
1042-
(let* ((spec (nth (current-column) org-columns-current-fmt-compiled))
1043+
(let* ((spec (nth (org-current-text-column) org-columns-current-fmt-compiled))
10431044
(value
10441045
(or (cdr (assoc spec
10451046
(get-text-property (line-beginning-position)
@@ -1049,7 +1050,7 @@ the current buffer."
10491050
(let ((displayed (org-columns--displayed-value spec value))
10501051
(format (overlay-get ov 'org-columns-format))
10511052
(width
1052-
(aref org-columns-current-maxwidths (current-column))))
1053+
(aref org-columns-current-maxwidths (org-current-text-column))))
10531054
(overlay-put ov 'org-columns-value value)
10541055
(overlay-put ov 'org-columns-value-modified displayed)
10551056
(overlay-put ov

lisp/org-macs.el

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,6 +1042,11 @@ Return width in pixels when PIXELS is non-nil."
10421042
pixel-width
10431043
(/ pixel-width symbol-width)))))))
10441044

1045+
(defmacro org-current-text-column ()
1046+
"Like `current-column' but ignore display properties."
1047+
`(string-width (buffer-substring-no-properties
1048+
(line-beginning-position) (point))))
1049+
10451050
(defun org-not-nil (v)
10461051
"If V not nil, and also not the string \"nil\", then return V.
10471052
Otherwise return nil."

0 commit comments

Comments
 (0)