Function: org--string-from-props
org--string-from-props is a byte-compiled function defined in
org-macs.el.gz.
Signature
(org--string-from-props S PROPERTY BEG END)
Documentation
Return the visible part of string S.
Visible part is determined according to text PROPERTY, which is
either invisible or display. BEG and END are 0-indices
delimiting S.
Source Code
;; Defined in /usr/src/emacs/lisp/org/org-macs.el.gz
(defun org--string-from-props (s property beg end)
"Return the visible part of string S.
Visible part is determined according to text PROPERTY, which is
either `invisible' or `display'. BEG and END are 0-indices
delimiting S."
(let ((width 0)
(cursor beg))
(while (setq beg (text-property-not-all beg end property nil s))
(let* ((next (next-single-property-change beg property s end))
(spec (get-text-property beg property s))
(value
(pcase property
(`invisible
;; If `invisible' property means text is to be
;; invisible, return 0. Otherwise return nil so as
;; to resume search.
(and (or (eq t buffer-invisibility-spec)
(assoc-string spec buffer-invisibility-spec))
0))
(`display
(pcase spec
(`nil nil)
(`(space . ,props)
(let ((width (plist-get props :width)))
(and (wholenump width) width)))
(`(image . ,_)
(and (fboundp 'image-size)
(ceiling (car (image-size spec)))))
((pred stringp)
;; Displayed string could contain invisible parts,
;; but no nested display.
(org--string-from-props spec 'invisible 0 (length spec)))
(_
;; Un-handled `display' value. Ignore it.
;; Consider the original string instead.
nil)))
(_ (error "Unknown property: %S" property)))))
(when value
(cl-incf width
;; When looking for `display' parts, we still need
;; to look for `invisible' property elsewhere.
(+ (cond ((eq property 'display)
(org--string-from-props s 'invisible cursor beg))
((= cursor beg) 0)
(t (string-width (substring s cursor beg))))
value))
(setq cursor next))
(setq beg next)))
(+ width
;; Look for `invisible' property in the last part of the
;; string. See above.
(cond ((eq property 'display)
(org--string-from-props s 'invisible cursor end))
((= cursor end) 0)
(t (string-width (substring s cursor end)))))))