mirror of
https://git.savannah.gnu.org/git/emacs/org-mode.git
synced 2024-12-13 09:32:19 +00:00
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:
parent
27466a38bc
commit
9a60db0ec3
@ -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."
|
||||
|
21
lisp/org.el
21
lisp/org.el
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user