Fix `org-string-width'
* lisp/org.el (org-string-width): Better handle various invisible characters.
This commit is contained in:
parent
720b213a35
commit
27466a38bc
41
lisp/org.el
41
lisp/org.el
|
@ -21823,28 +21823,25 @@ If DELETE is non-nil, delete all those overlays."
|
||||||
(self-insert-command N))
|
(self-insert-command N))
|
||||||
|
|
||||||
(defun org-string-width (s)
|
(defun org-string-width (s)
|
||||||
"Compute width of string, ignoring invisible characters.
|
"Compute width of string S, ignoring invisible characters."
|
||||||
This ignores character with invisibility property `org-link', and also
|
(let ((invisiblep (lambda (v)
|
||||||
characters with property `org-cwidth', because these will become invisible
|
;; Non-nil if a V `invisible' property means
|
||||||
upon the next fontification round."
|
;; that that text is meant to be invisible.
|
||||||
(let (b l)
|
(or (eq t buffer-invisibility-spec)
|
||||||
(when (or (eq t buffer-invisibility-spec)
|
(assoc-string v buffer-invisibility-spec))))
|
||||||
(assq 'org-link buffer-invisibility-spec))
|
(len (length s)))
|
||||||
(while (setq b (text-property-any 0 (length s)
|
(let ((invisible-parts nil))
|
||||||
'invisible 'org-link s))
|
(let ((cursor 0))
|
||||||
(setq s (concat (substring s 0 b)
|
(while (setq cursor (text-property-not-all cursor len 'invisible nil s))
|
||||||
(substring s (or (next-single-property-change
|
(let ((end (or (next-single-property-change cursor 'invisible s len))))
|
||||||
b 'invisible s)
|
(when (funcall invisiblep (get-text-property cursor 'invisible s))
|
||||||
(length s)))))))
|
(push (cons cursor end) invisible-parts))
|
||||||
(while (setq b (text-property-any 0 (length s) 'org-cwidth t s))
|
(setq cursor end))))
|
||||||
(setq s (concat (substring s 0 b)
|
(let ((new-string s))
|
||||||
(substring s (or (next-single-property-change
|
(pcase-dolist (`(,begin . ,end) invisible-parts)
|
||||||
b 'org-cwidth s)
|
(setq new-string (concat (substring new-string 0 begin)
|
||||||
(length s))))))
|
(substring new-string end))))
|
||||||
(setq l (string-width s) b -1)
|
(string-width new-string)))))
|
||||||
(while (setq b (text-property-any (1+ b) (length s) 'org-dwidth t s))
|
|
||||||
(setq l (- l (get-text-property b 'org-dwidth-n s))))
|
|
||||||
l))
|
|
||||||
|
|
||||||
(defun org-shorten-string (s maxlength)
|
(defun org-shorten-string (s maxlength)
|
||||||
"Shorten string S so that it is no longer than MAXLENGTH characters.
|
"Shorten string S so that it is no longer than MAXLENGTH characters.
|
||||||
|
|
Loading…
Reference in New Issue