Skip to content

Commit 9db57ae

Browse files
committed
Do not use visual `current-indentation' when we need real values
* lisp/org-macs.el (org-current-text-indentation): New macro calculating the real text indentation disregarding buffer visibility. (org-do-remove-indentation): * lisp/org-src.el (org-src--edit-element): * lisp/org.el (org-indent-line): (org-indent-region): (org-toggle-fixed-width): (org-comment-or-uncomment-region): * lisp/ox.el (org-export-expand-include-keyword): Use `org-current-text-indentation' instead of `current-indentation' and `org-current-text-column' instead of `current-column' when we need real text values but not visible values. See https://debbugs.gnu.org/cgi/bugreport.cgi?bug=56837 Reported-by: tony aldon <tony.aldon.adm@gmail.com> Link: https://orgmode.org/list/87k0h49s7z.fsf@localhost
1 parent 0641ece commit 9db57ae

File tree

11 files changed

+34
-29
lines changed

11 files changed

+34
-29
lines changed

lisp/ob-core.el

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1982,7 +1982,7 @@ region is not active then the point is demarcated."
19821982
(save-excursion
19831983
(goto-char place)
19841984
(let ((lang (nth 0 info))
1985-
(indent (make-string (current-indentation) ?\s)))
1985+
(indent (make-string (org-current-text-indentation) ?\s)))
19861986
(when (string-match "^[[:space:]]*$"
19871987
(buffer-substring (line-beginning-position)
19881988
(line-end-position)))
@@ -2740,7 +2740,7 @@ specified as an an \"attachment:\" style link."
27402740
(unless (eq (org-element-type element) 'src-block)
27412741
(error "Not in a source block"))
27422742
(goto-char (org-babel-where-is-src-block-head element))
2743-
(let* ((ind (current-indentation))
2743+
(let* ((ind (org-current-text-indentation))
27442744
(body-start (line-beginning-position 2))
27452745
(body (org-element-normalize-string
27462746
(if (or org-src-preserve-indentation

lisp/ob-exp.el

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ this template."
263263
(insert rep))))
264264
(`src-block
265265
(let ((match-start (copy-marker (match-beginning 0)))
266-
(ind (current-indentation)))
266+
(ind (org-current-text-indentation)))
267267
;; Take care of matched block: compute
268268
;; replacement string. In particular, a nil
269269
;; REPLACEMENT means the block is left as-is

lisp/oc.el

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1525,7 +1525,7 @@ CONTEXT is the element or object at point, as returned by `org-element-context'.
15251525
;; unaffected.
15261526
((eq type 'item)
15271527
(> (point) (+ (org-element-property :begin context)
1528-
(current-indentation)
1528+
(org-current-text-indentation)
15291529
(if (org-element-property :checkbox context)
15301530
5 1))))
15311531
;; Other elements are invalid.

lisp/org-agenda.el

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3748,10 +3748,10 @@ removed from the entry content. Currently only `planning' is allowed here."
37483748
;; find and remove min common indentation
37493749
(goto-char (point-min))
37503750
(untabify (point-min) (point-max))
3751-
(setq ind (current-indentation))
3751+
(setq ind (org-current-text-indentation))
37523752
(while (not (eobp))
37533753
(unless (looking-at "[ \t]*$")
3754-
(setq ind (min ind (current-indentation))))
3754+
(setq ind (min ind (org-current-text-indentation))))
37553755
(beginning-of-line 2))
37563756
(goto-char (point-min))
37573757
(while (not (eobp))

lisp/org-capture.el

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1275,7 +1275,7 @@ may have been stored before."
12751275
(when item
12761276
(let ((i (save-excursion
12771277
(goto-char (org-element-property :post-affiliated item))
1278-
(current-indentation))))
1278+
(org-current-text-indentation))))
12791279
(save-excursion
12801280
(goto-char beg)
12811281
(save-excursion

lisp/org-element.el

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1616,7 +1616,7 @@ CONTENTS is the contents of the element."
16161616
;; At a new item: end previous sibling.
16171617
((looking-at item-re)
16181618
(let ((ind (save-excursion (skip-chars-forward " \t")
1619-
(current-column))))
1619+
(org-current-text-column))))
16201620
(setq top-ind (min top-ind ind))
16211621
(while (and items (<= ind (nth 1 (car items))))
16221622
(let ((item (pop items)))
@@ -1650,7 +1650,7 @@ CONTENTS is the contents of the element."
16501650
(t
16511651
(let ((ind (save-excursion
16521652
(skip-chars-forward " \t")
1653-
(current-column)))
1653+
(org-current-text-column)))
16541654
(end (save-excursion
16551655
(skip-chars-backward " \r\t\n")
16561656
(line-beginning-position 2))))

lisp/org-list.el

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ group 4: description tag")
411411
(ind-ref (if (or (looking-at "^[ \t]*$")
412412
(and inlinetask-re (looking-at inlinetask-re)))
413413
10000
414-
(current-indentation))))
414+
(org-current-text-indentation))))
415415
(cond
416416
((eq (nth 2 context) 'invalid) nil)
417417
((looking-at item-re) (point))
@@ -433,7 +433,7 @@ group 4: description tag")
433433
;; Look for an item, less indented that reference line.
434434
(catch 'exit
435435
(while t
436-
(let ((ind (current-indentation)))
436+
(let ((ind (org-current-text-indentation)))
437437
(cond
438438
;; This is exactly what we want.
439439
((and (looking-at item-re) (< ind ind-ref))
@@ -603,7 +603,7 @@ Assume point is at an item."
603603
(item-re (org-item-re))
604604
(inlinetask-re (and (featurep 'org-inlinetask)
605605
(org-inlinetask-outline-regexp)))
606-
(beg-cell (cons (point) (current-indentation)))
606+
(beg-cell (cons (point) (org-current-text-indentation)))
607607
itm-lst itm-lst-2 end-lst end-lst-2 struct
608608
(assoc-at-point
609609
;; Return association at point.
@@ -629,7 +629,7 @@ Assume point is at an item."
629629
(save-excursion
630630
(catch 'exit
631631
(while t
632-
(let ((ind (current-indentation)))
632+
(let ((ind (org-current-text-indentation)))
633633
(cond
634634
((<= (point) lim-up)
635635
;; At upward limit: if we ended at an item, store it,
@@ -689,7 +689,7 @@ Assume point is at an item."
689689
;; position of items in END-LST-2.
690690
(catch 'exit
691691
(while t
692-
(let ((ind (current-indentation)))
692+
(let ((ind (org-current-text-indentation)))
693693
(cond
694694
((>= (point) lim-down)
695695
;; At downward limit: this is de facto the end of the
@@ -1840,15 +1840,15 @@ Initial position of cursor is restored after the changes."
18401840
(org-inlinetask-goto-beginning))
18411841
;; Shift only non-empty lines.
18421842
((looking-at-p "^[ \t]*\\S-")
1843-
(indent-line-to (+ (current-indentation) delta))))
1843+
(indent-line-to (+ (org-current-text-indentation) delta))))
18441844
(forward-line -1))))
18451845
(modify-item
18461846
;; Replace ITEM first line elements with new elements from
18471847
;; STRUCT, if appropriate.
18481848
(lambda (item)
18491849
(goto-char item)
18501850
(let* ((new-ind (org-list-get-ind item struct))
1851-
(old-ind (current-indentation))
1851+
(old-ind (org-current-text-indentation))
18521852
(new-bul (org-list-bullet-string
18531853
(org-list-get-bullet item struct)))
18541854
(old-bul (org-list-get-bullet item old-struct))
@@ -1938,7 +1938,7 @@ Initial position of cursor is restored after the changes."
19381938
;; Ignore empty lines. Also ignore blocks and
19391939
;; drawers contents.
19401940
(unless (looking-at-p "[ \t]*$")
1941-
(setq min-ind (min (current-indentation) min-ind))
1941+
(setq min-ind (min (org-current-text-indentation) min-ind))
19421942
(cond
19431943
((and (looking-at "#\\+BEGIN\\(:\\|_\\S-+\\)")
19441944
(re-search-forward
@@ -3031,7 +3031,7 @@ With a prefix argument ARG, change the region in a single item."
30313031
(save-excursion
30323032
(catch 'exit
30333033
(while (< (point) end)
3034-
(let ((i (current-indentation)))
3034+
(let ((i (org-current-text-indentation)))
30353035
(cond
30363036
;; Skip blank lines and inline tasks.
30373037
((looking-at "^[ \t]*$"))
@@ -3047,7 +3047,7 @@ With a prefix argument ARG, change the region in a single item."
30473047
(while (< (point) end)
30483048
(unless (or (looking-at "^[ \t]*$")
30493049
(looking-at org-outline-regexp-bol))
3050-
(indent-line-to (+ (current-indentation) delta)))
3050+
(indent-line-to (+ (org-current-text-indentation) delta)))
30513051
(forward-line))))))
30523052
(skip-blanks
30533053
(lambda (pos)
@@ -3139,7 +3139,7 @@ With a prefix argument ARG, change the region in a single item."
31393139
;; set them as item's body.
31403140
(arg (let* ((bul (org-list-bullet-string "-"))
31413141
(bul-len (length bul))
3142-
(ref-ind (current-indentation)))
3142+
(ref-ind (org-current-text-indentation)))
31433143
(skip-chars-forward " \t")
31443144
(insert bul)
31453145
(forward-line)

lisp/org-macs.el

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ line. Return nil if it fails."
400400
(save-excursion
401401
(when skip-fl (forward-line))
402402
(while (re-search-forward "^[ \t]*\\S-" nil t)
403-
(let ((ind (current-indentation)))
403+
(let ((ind (org-current-text-indentation)))
404404
(if (zerop ind) (throw :exit nil)
405405
(setq min-ind (min min-ind ind))))))
406406
min-ind))))
@@ -1101,6 +1101,11 @@ Return width in pixels when PIXELS is non-nil."
11011101
`(string-width (buffer-substring-no-properties
11021102
(line-beginning-position) (point))))
11031103

1104+
(defmacro org-current-text-indentation ()
1105+
"Like `current-indentation', but ignore display/invisible properties."
1106+
`(let ((buffer-invisibility-spec nil))
1107+
(current-indentation)))
1108+
11041109
(defun org-not-nil (v)
11051110
"If V not nil, and also not the string \"nil\", then return V.
11061111
Otherwise return nil."

lisp/org-src.el

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -533,11 +533,11 @@ Leave point in edit buffer."
533533
(block-ind (org-with-point-at (org-element-property :begin datum)
534534
(cond
535535
((save-excursion (skip-chars-backward " \t") (bolp))
536-
(current-indentation))
536+
(org-current-text-indentation))
537537
((org-element-property :parent datum)
538538
(org--get-expected-indentation
539539
(org-element-property :parent datum) nil))
540-
(t (current-indentation)))))
540+
(t (org-current-text-indentation)))))
541541
(content-ind org-edit-src-content-indentation)
542542
(blank-line (save-excursion (beginning-of-line)
543543
(looking-at-p "^[[:space:]]*$")))

lisp/org.el

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18818,13 +18818,13 @@ Also align node properties according to `org-property-format'."
1881818818
(let ((element (org-element-at-point))
1881918819
block-content-ind some-ind)
1882018820
(org-with-point-at (org-element-property :begin element)
18821-
(setq block-content-ind (+ (current-indentation)
18821+
(setq block-content-ind (+ (org-current-text-indentation)
1882218822
org-edit-src-content-indentation))
1882318823
(forward-line)
1882418824
(save-match-data (re-search-forward "^[ \t]*\\S-" nil t))
1882518825
(backward-char)
1882618826
(setq some-ind (if (looking-at-p "#\\+end_src")
18827-
block-content-ind (current-indentation))))
18827+
block-content-ind (org-current-text-indentation))))
1882818828
(indent-line-to (min block-content-ind some-ind))))
1882918829
(org-babel-do-key-sequence-in-edit-buffer (kbd "TAB")))
1883018830
(t
@@ -18933,7 +18933,7 @@ assumed to be significant there."
1893318933
;; might break the list as a whole. On the other
1893418934
;; hand, when at a plain list, indent it as a whole.
1893518935
(cond ((eq type 'plain-list)
18936-
(let ((offset (- ind (current-indentation))))
18936+
(let ((offset (- ind (org-current-text-indentation))))
1893718937
(unless (zerop offset)
1893818938
(indent-rigidly (org-element-property :begin element)
1893918939
(org-element-property :end element)
@@ -19393,7 +19393,7 @@ region only contains such lines."
1939319393
(catch 'zerop
1939419394
(while (< (point) end)
1939519395
(unless (looking-at-p "[ \t]*$")
19396-
(let ((ind (current-indentation)))
19396+
(let ((ind (org-current-text-indentation)))
1939719397
(setq min-ind (min min-ind ind))
1939819398
(when (zerop ind) (throw 'zerop t))))
1939919399
(forward-line)))))
@@ -19599,7 +19599,7 @@ strictly within a source block, use appropriate comment syntax."
1959919599
(goto-char (point-min))
1960019600
(while (and (not (eobp)) (not (zerop min-indent)))
1960119601
(unless (looking-at "[ \t]*$")
19602-
(setq min-indent (min min-indent (current-indentation))))
19602+
(setq min-indent (min min-indent (org-current-text-indentation))))
1960319603
(forward-line)))
1960419604
;; Then loop over all lines.
1960519605
(save-excursion

0 commit comments

Comments
 (0)