org-element: Untabify strings without semantics during parsing
* contrib/lisp/org-element.el (org-element-parse-objects): Untabify strings between objects to avoid any `tab-width' mismatch. * contrib/lisp/org-element.el (org-element-normalize-contents): No longer need to handle tabs.
This commit is contained in:
parent
3fc0afb5ee
commit
4725d00f84
|
@ -3201,10 +3201,13 @@ allowed in the current object."
|
||||||
(while (setq candidates (org-element-get-next-object-candidates
|
(while (setq candidates (org-element-get-next-object-candidates
|
||||||
end restriction candidates))
|
end restriction candidates))
|
||||||
(setq next-object (funcall get-next-object candidates))
|
(setq next-object (funcall get-next-object candidates))
|
||||||
;; 1. Text before any object.
|
;; 1. Text before any object. Untabify it.
|
||||||
(let ((obj-beg (org-element-get-property :begin next-object)))
|
(let ((obj-beg (org-element-get-property :begin next-object)))
|
||||||
(unless (= (point) obj-beg)
|
(unless (= (point) obj-beg)
|
||||||
(push (buffer-substring-no-properties (point) obj-beg) acc)))
|
(push (replace-regexp-in-string
|
||||||
|
"\t" (make-string tab-width ? )
|
||||||
|
(buffer-substring-no-properties (point) obj-beg))
|
||||||
|
acc)))
|
||||||
;; 2. Object...
|
;; 2. Object...
|
||||||
(let ((obj-end (org-element-get-property :end next-object))
|
(let ((obj-end (org-element-get-property :end next-object))
|
||||||
(cont-beg (org-element-get-property :contents-begin next-object)))
|
(cont-beg (org-element-get-property :contents-begin next-object)))
|
||||||
|
@ -3233,9 +3236,12 @@ allowed in the current object."
|
||||||
next-object)
|
next-object)
|
||||||
acc)
|
acc)
|
||||||
(goto-char obj-end)))
|
(goto-char obj-end)))
|
||||||
;; 3. Text after last object.
|
;; 3. Text after last object. Untabify it.
|
||||||
(unless (= (point) end)
|
(unless (= (point) end)
|
||||||
(push (buffer-substring-no-properties (point) end) acc))
|
(push (replace-regexp-in-string
|
||||||
|
"\t" (make-string tab-width ? )
|
||||||
|
(buffer-substring-no-properties (point) end))
|
||||||
|
acc))
|
||||||
;; Result.
|
;; Result.
|
||||||
(nreverse acc))))
|
(nreverse acc))))
|
||||||
|
|
||||||
|
@ -3445,16 +3451,15 @@ Return the normalized element."
|
||||||
(let ((contents (org-element-get-contents element)))
|
(let ((contents (org-element-get-contents element)))
|
||||||
(if (not (or ignore-first (stringp (car contents)))) contents
|
(if (not (or ignore-first (stringp (car contents)))) contents
|
||||||
(catch 'exit
|
(catch 'exit
|
||||||
;; 1. Remove tabs from each string in CONTENTS. Get maximal
|
;; 1. Get maximal common indentation (MCI) among each string
|
||||||
;; common indentation (MCI) along the way.
|
;; in CONTENTS.
|
||||||
(let* ((ind-list (unless ignore-first
|
(let* ((ind-list (unless ignore-first
|
||||||
(list (org-get-string-indentation (car contents)))))
|
(list (org-get-string-indentation (car contents)))))
|
||||||
(contents
|
(contents
|
||||||
(mapcar
|
(mapcar
|
||||||
(lambda (object)
|
(lambda (object)
|
||||||
(if (not (stringp object)) object
|
(if (not (stringp object)) object
|
||||||
(let ((start 0)
|
(let ((start 0))
|
||||||
(object (org-remove-tabs object)))
|
|
||||||
(while (string-match "\n\\( *\\)" object start)
|
(while (string-match "\n\\( *\\)" object start)
|
||||||
(setq start (match-end 0))
|
(setq start (match-end 0))
|
||||||
(push (length (match-string 1 object)) ind-list))
|
(push (length (match-string 1 object)) ind-list))
|
||||||
|
|
Loading…
Reference in New Issue