Move `org-string-width' to "org-macs.el"

* lisp/org.el (org-string-width): Move from here...
* lisp/org-macs.el (org-string-width): ... to here.
This commit is contained in:
Nicolas Goaziou 2017-07-27 15:23:31 +02:00
parent 27466a38bc
commit 9a60db0ec3
2 changed files with 21 additions and 21 deletions

View File

@ -60,6 +60,27 @@ and end of string are ignored."
(setq string (replace-match "" nil nil string)))
(split-string string separators)))
(defun org-string-width (s)
"Compute width of string S, ignoring invisible characters."
(let ((invisiblep (lambda (v)
;; Non-nil if a V `invisible' property means
;; that that text is meant to be invisible.
(or (eq t buffer-invisibility-spec)
(assoc-string v buffer-invisibility-spec))))
(len (length s)))
(let ((invisible-parts nil))
(let ((cursor 0))
(while (setq cursor (text-property-not-all cursor len 'invisible nil s))
(let ((end (or (next-single-property-change cursor 'invisible s len))))
(when (funcall invisiblep (get-text-property cursor 'invisible s))
(push (cons cursor end) invisible-parts))
(setq cursor end))))
(let ((new-string s))
(pcase-dolist (`(,begin . ,end) invisible-parts)
(setq new-string (concat (substring new-string 0 begin)
(substring new-string end))))
(string-width new-string)))))
(defun org-not-nil (v)
"If V not nil, and also not the string \"nil\", then return V.
Otherwise return nil."

View File

@ -21822,27 +21822,6 @@ If DELETE is non-nil, delete all those overlays."
(interactive "p")
(self-insert-command N))
(defun org-string-width (s)
"Compute width of string S, ignoring invisible characters."
(let ((invisiblep (lambda (v)
;; Non-nil if a V `invisible' property means
;; that that text is meant to be invisible.
(or (eq t buffer-invisibility-spec)
(assoc-string v buffer-invisibility-spec))))
(len (length s)))
(let ((invisible-parts nil))
(let ((cursor 0))
(while (setq cursor (text-property-not-all cursor len 'invisible nil s))
(let ((end (or (next-single-property-change cursor 'invisible s len))))
(when (funcall invisiblep (get-text-property cursor 'invisible s))
(push (cons cursor end) invisible-parts))
(setq cursor end))))
(let ((new-string s))
(pcase-dolist (`(,begin . ,end) invisible-parts)
(setq new-string (concat (substring new-string 0 begin)
(substring new-string end))))
(string-width new-string)))))
(defun org-shorten-string (s maxlength)
"Shorten string S so that it is no longer than MAXLENGTH characters.
If the string is shorter or has length MAXLENGTH, just return the