Function: bytecomp--docstring-line-width

bytecomp--docstring-line-width is a byte-compiled function defined in bytecomp.el.gz.

Signature

(bytecomp--docstring-line-width STR)

Documentation

An approximation of the displayed width of docstring line STR.

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/bytecomp.el.gz
(defun bytecomp--docstring-line-width (str)
  "An approximation of the displayed width of docstring line STR."
  ;; For literal key sequence substitutions (e.g. "\\`C-h'"), just
  ;; remove the markup as `substitute-command-keys' would.
  (when (string-search "\\`" str)
    (setq str (replace-regexp-in-string
               (rx "\\`" (group (* (not "'"))) "'")
               "\\1"
               str t)))
  ;; Heuristic: We can't reliably do `substitute-command-keys'
  ;; substitutions, since the value of a keymap in general can't be
  ;; known at compile time.  So instead, we assume that these
  ;; substitutions are of some constant length.
  (when (string-search "\\[" str)
    (setq str (replace-regexp-in-string
               (rx "\\[" (* (not "]")) "]")
               ;; We assume that substitutions have this length.
               ;; To preserve the non-expansive property of the transform,
               ;; it shouldn't be more than 3 characters long.
               "xxx"
               str t t)))
  (setq str
        (replace-regexp-in-string
         (rx (or
              ;; Ignore some URLs.
              (seq "http" (? "s") "://" (* nonl))
              ;; Ignore these `substitute-command-keys' substitutions.
              (seq "\\" (or "="
                            (seq "<" (* (not ">")) ">")
                            (seq "{" (* (not "}")) "}")))
              ;; Ignore the function signature that's stashed at the end of
              ;; the doc string (in some circumstances).
              (seq bol "(" (+ (any word "-/:[]&"))
                   ;; One or more arguments.
                   (+ " " (or
                           ;; Arguments.
                           (+ (or (syntax symbol)
                                  (any word "-/:[]&=()<>.,?^\\#*'\"")))
                           ;; Argument that is a list.
                           (seq "(" (* (not ")")) ")")))
                   ")")))
         "" str t t))
  (length str))