浏览代码

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
Ihor Radchenko 2 年之前
父节点
当前提交
9db57aee3e
共有 11 个文件被更改,包括 34 次插入29 次删除
  1. 2 2
      lisp/ob-core.el
  2. 1 1
      lisp/ob-exp.el
  3. 1 1
      lisp/oc.el
  4. 2 2
      lisp/org-agenda.el
  5. 1 1
      lisp/org-capture.el
  6. 2 2
      lisp/org-element.el
  7. 11 11
      lisp/org-list.el
  8. 6 1
      lisp/org-macs.el
  9. 2 2
      lisp/org-src.el
  10. 5 5
      lisp/org.el
  11. 1 1
      lisp/ox.el

+ 2 - 2
lisp/ob-core.el

@@ -1982,7 +1982,7 @@ region is not active then the point is demarcated."
            (save-excursion
              (goto-char place)
              (let ((lang (nth 0 info))
-                   (indent (make-string (current-indentation) ?\s)))
+                   (indent (make-string (org-current-text-indentation) ?\s)))
 	       (when (string-match "^[[:space:]]*$"
 				   (buffer-substring (line-beginning-position)
 						     (line-end-position)))
@@ -2740,7 +2740,7 @@ specified as an an \"attachment:\" style link."
     (unless (eq (org-element-type element) 'src-block)
       (error "Not in a source block"))
     (goto-char (org-babel-where-is-src-block-head element))
-    (let* ((ind (current-indentation))
+    (let* ((ind (org-current-text-indentation))
 	   (body-start (line-beginning-position 2))
 	   (body (org-element-normalize-string
 		  (if (or org-src-preserve-indentation

+ 1 - 1
lisp/ob-exp.el

@@ -263,7 +263,7 @@ this template."
 			     (insert rep))))
 		        (`src-block
 		         (let ((match-start (copy-marker (match-beginning 0)))
-			       (ind (current-indentation)))
+			       (ind (org-current-text-indentation)))
 			   ;; Take care of matched block: compute
 			   ;; replacement string.  In particular, a nil
 			   ;; REPLACEMENT means the block is left as-is

+ 1 - 1
lisp/oc.el

@@ -1525,7 +1525,7 @@ CONTEXT is the element or object at point, as returned by `org-element-context'.
      ;; unaffected.
      ((eq type 'item)
       (> (point) (+ (org-element-property :begin context)
-                    (current-indentation)
+                    (org-current-text-indentation)
                     (if (org-element-property :checkbox context)
                         5 1))))
      ;; Other elements are invalid.

+ 2 - 2
lisp/org-agenda.el

@@ -3748,10 +3748,10 @@ removed from the entry content.  Currently only `planning' is allowed here."
 	     ;; find and remove min common indentation
 	     (goto-char (point-min))
 	     (untabify (point-min) (point-max))
-	     (setq ind (current-indentation))
+	     (setq ind (org-current-text-indentation))
 	     (while (not (eobp))
 	       (unless (looking-at "[ \t]*$")
-		 (setq ind (min ind (current-indentation))))
+		 (setq ind (min ind (org-current-text-indentation))))
 	       (beginning-of-line 2))
 	     (goto-char (point-min))
 	     (while (not (eobp))

+ 1 - 1
lisp/org-capture.el

@@ -1275,7 +1275,7 @@ may have been stored before."
 	(when item
 	  (let ((i (save-excursion
 		     (goto-char (org-element-property :post-affiliated item))
-		     (current-indentation))))
+		     (org-current-text-indentation))))
 	    (save-excursion
 	      (goto-char beg)
 	      (save-excursion

+ 2 - 2
lisp/org-element.el

@@ -1616,7 +1616,7 @@ CONTENTS is the contents of the element."
 	   ;; At a new item: end previous sibling.
 	   ((looking-at item-re)
 	    (let ((ind (save-excursion (skip-chars-forward " \t")
-				       (current-column))))
+				       (org-current-text-column))))
 	      (setq top-ind (min top-ind ind))
 	      (while (and items (<= ind (nth 1 (car items))))
 		(let ((item (pop items)))
@@ -1650,7 +1650,7 @@ CONTENTS is the contents of the element."
 	   (t
 	    (let ((ind (save-excursion
 			 (skip-chars-forward " \t")
-			 (current-column)))
+			 (org-current-text-column)))
 		  (end (save-excursion
 			 (skip-chars-backward " \r\t\n")
 			 (line-beginning-position 2))))

+ 11 - 11
lisp/org-list.el

@@ -411,7 +411,7 @@ group 4: description tag")
 	   (ind-ref (if (or (looking-at "^[ \t]*$")
 			    (and inlinetask-re (looking-at inlinetask-re)))
 			10000
-		      (current-indentation))))
+		      (org-current-text-indentation))))
       (cond
        ((eq (nth 2 context) 'invalid) nil)
        ((looking-at item-re) (point))
@@ -433,7 +433,7 @@ group 4: description tag")
 	;; Look for an item, less indented that reference line.
 	(catch 'exit
 	  (while t
-	    (let ((ind (current-indentation)))
+	    (let ((ind (org-current-text-indentation)))
 	      (cond
 	       ;; This is exactly what we want.
 	       ((and (looking-at item-re) (< ind ind-ref))
@@ -603,7 +603,7 @@ Assume point is at an item."
 	   (item-re (org-item-re))
 	   (inlinetask-re (and (featurep 'org-inlinetask)
 			       (org-inlinetask-outline-regexp)))
-	   (beg-cell (cons (point) (current-indentation)))
+	   (beg-cell (cons (point) (org-current-text-indentation)))
            itm-lst itm-lst-2 end-lst end-lst-2 struct
 	   (assoc-at-point
 	    ;; Return association at point.
@@ -629,7 +629,7 @@ Assume point is at an item."
       (save-excursion
 	(catch 'exit
 	  (while t
-	    (let ((ind (current-indentation)))
+	    (let ((ind (org-current-text-indentation)))
 	      (cond
 	       ((<= (point) lim-up)
 		;; At upward limit: if we ended at an item, store it,
@@ -689,7 +689,7 @@ Assume point is at an item."
       ;;    position of items in END-LST-2.
       (catch 'exit
 	(while t
-	  (let ((ind (current-indentation)))
+	  (let ((ind (org-current-text-indentation)))
 	    (cond
 	     ((>= (point) lim-down)
 	      ;; At downward limit: this is de facto the end of the
@@ -1840,7 +1840,7 @@ Initial position of cursor is restored after the changes."
 		(org-inlinetask-goto-beginning))
 	       ;; Shift only non-empty lines.
 	       ((looking-at-p "^[ \t]*\\S-")
-		(indent-line-to (+ (current-indentation) delta))))
+		(indent-line-to (+ (org-current-text-indentation) delta))))
 	      (forward-line -1))))
 	 (modify-item
 	  ;; Replace ITEM first line elements with new elements from
@@ -1848,7 +1848,7 @@ Initial position of cursor is restored after the changes."
 	  (lambda (item)
 	    (goto-char item)
 	    (let* ((new-ind (org-list-get-ind item struct))
-		   (old-ind (current-indentation))
+		   (old-ind (org-current-text-indentation))
 		   (new-bul (org-list-bullet-string
 			     (org-list-get-bullet item struct)))
 		   (old-bul (org-list-get-bullet item old-struct))
@@ -1938,7 +1938,7 @@ Initial position of cursor is restored after the changes."
 			;; Ignore empty lines.  Also ignore blocks and
 			;; drawers contents.
 			(unless (looking-at-p "[ \t]*$")
-			  (setq min-ind (min (current-indentation) min-ind))
+			  (setq min-ind (min (org-current-text-indentation) min-ind))
 			  (cond
 			   ((and (looking-at "#\\+BEGIN\\(:\\|_\\S-+\\)")
 				 (re-search-forward
@@ -3031,7 +3031,7 @@ With a prefix argument ARG, change the region in a single item."
 	     (save-excursion
 	       (catch 'exit
 		 (while (< (point) end)
-		   (let ((i (current-indentation)))
+		   (let ((i (org-current-text-indentation)))
 		     (cond
 		      ;; Skip blank lines and inline tasks.
 		      ((looking-at "^[ \t]*$"))
@@ -3047,7 +3047,7 @@ With a prefix argument ARG, change the region in a single item."
 	       (while (< (point) end)
 		 (unless (or (looking-at "^[ \t]*$")
 			     (looking-at org-outline-regexp-bol))
-		   (indent-line-to (+ (current-indentation) delta)))
+		   (indent-line-to (+ (org-current-text-indentation) delta)))
 		 (forward-line))))))
 	(skip-blanks
 	 (lambda (pos)
@@ -3139,7 +3139,7 @@ With a prefix argument ARG, change the region in a single item."
 	;;         set them as item's body.
 	(arg (let* ((bul (org-list-bullet-string "-"))
 		    (bul-len (length bul))
-		    (ref-ind (current-indentation)))
+		    (ref-ind (org-current-text-indentation)))
 	       (skip-chars-forward " \t")
 	       (insert bul)
 	       (forward-line)

+ 6 - 1
lisp/org-macs.el

@@ -400,7 +400,7 @@ line.  Return nil if it fails."
 		   (save-excursion
                      (when skip-fl (forward-line))
 		     (while (re-search-forward "^[ \t]*\\S-" nil t)
-		       (let ((ind (current-indentation)))
+		       (let ((ind (org-current-text-indentation)))
 			 (if (zerop ind) (throw :exit nil)
 			   (setq min-ind (min min-ind ind))))))
 		   min-ind))))
@@ -1101,6 +1101,11 @@ Return width in pixels when PIXELS is non-nil."
   `(string-width (buffer-substring-no-properties
                   (line-beginning-position) (point))))
 
+(defmacro org-current-text-indentation ()
+  "Like `current-indentation', but ignore display/invisible properties."
+  `(let ((buffer-invisibility-spec nil))
+     (current-indentation)))
+
 (defun org-not-nil (v)
   "If V not nil, and also not the string \"nil\", then return V.
 Otherwise return nil."

+ 2 - 2
lisp/org-src.el

@@ -533,11 +533,11 @@ Leave point in edit buffer."
 	     (block-ind (org-with-point-at (org-element-property :begin datum)
                           (cond
                            ((save-excursion (skip-chars-backward " \t") (bolp))
-			    (current-indentation))
+			    (org-current-text-indentation))
                            ((org-element-property :parent datum)
                             (org--get-expected-indentation
                              (org-element-property :parent datum) nil))
-                           (t (current-indentation)))))
+                           (t (org-current-text-indentation)))))
 	     (content-ind org-edit-src-content-indentation)
              (blank-line (save-excursion (beginning-of-line)
                                          (looking-at-p "^[[:space:]]*$")))

+ 5 - 5
lisp/org.el

@@ -18818,13 +18818,13 @@ Also align node properties according to `org-property-format'."
                (let ((element (org-element-at-point))
                      block-content-ind some-ind)
                  (org-with-point-at (org-element-property :begin element)
-                   (setq block-content-ind (+ (current-indentation)
+                   (setq block-content-ind (+ (org-current-text-indentation)
                                               org-edit-src-content-indentation))
                    (forward-line)
 		   (save-match-data (re-search-forward "^[ \t]*\\S-" nil t))
                    (backward-char)
                    (setq some-ind (if (looking-at-p "#\\+end_src")
-                                      block-content-ind (current-indentation))))
+                                      block-content-ind (org-current-text-indentation))))
                  (indent-line-to (min block-content-ind some-ind))))
 	     (org-babel-do-key-sequence-in-edit-buffer (kbd "TAB")))
 	    (t
@@ -18933,7 +18933,7 @@ assumed to be significant there."
 		;; might break the list as a whole.  On the other
 		;; hand, when at a plain list, indent it as a whole.
 		(cond ((eq type 'plain-list)
-		       (let ((offset (- ind (current-indentation))))
+		       (let ((offset (- ind (org-current-text-indentation))))
 			 (unless (zerop offset)
 			   (indent-rigidly (org-element-property :begin element)
 					   (org-element-property :end element)
@@ -19393,7 +19393,7 @@ region only contains such lines."
               (catch 'zerop
                 (while (< (point) end)
                   (unless (looking-at-p "[ \t]*$")
-                    (let ((ind (current-indentation)))
+                    (let ((ind (org-current-text-indentation)))
                       (setq min-ind (min min-ind ind))
                       (when (zerop ind) (throw 'zerop t))))
                   (forward-line)))))
@@ -19599,7 +19599,7 @@ strictly within a source block, use appropriate comment syntax."
 	      (goto-char (point-min))
 	      (while (and (not (eobp)) (not (zerop min-indent)))
 		(unless (looking-at "[ \t]*$")
-		  (setq min-indent (min min-indent (current-indentation))))
+		  (setq min-indent (min min-indent (org-current-text-indentation))))
 		(forward-line)))
 	    ;; Then loop over all lines.
 	    (save-excursion

+ 1 - 1
lisp/ox.el

@@ -3236,7 +3236,7 @@ storing and resolving footnotes.  It is created automatically."
 	    (beginning-of-line)
 	    ;; Extract arguments from keyword's value.
 	    (let* ((value (org-element-property :value element))
-		   (ind (current-indentation))
+		   (ind (org-current-text-indentation))
 		   location
 		   (coding-system-for-read
 		    (or (and (string-match ":coding +\\(\\S-+\\)>" value)