Function: easy-mmode--mode-docstring

easy-mmode--mode-docstring is a byte-compiled function defined in easy-mmode.el.gz.

Signature

(easy-mmode--mode-docstring DOC MODE-PRETTY-NAME KEYMAP-SYM GETTER GLOBAL)

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/easy-mmode.el.gz
(defun easy-mmode--mode-docstring (doc mode-pretty-name keymap-sym
                                       getter global)
  ;; If we have a doc string, and it's already complete (which we
  ;; guess at with the simple heuristic below), then just return that
  ;; as is.
  (if (and doc (string-match-p "\\bARG\\b" doc))
      doc
    ;; Compose a new doc string.
    (with-temp-buffer
      (let ((lines (if doc
                       (string-lines doc)
                     (list (format "Toggle %s on or off." mode-pretty-name)))))
        ;; Insert the first line from the doc string.
        (insert (pop lines))
        ;; Ensure that we have (only) one blank line after the first
        ;; line.
        (ensure-empty-lines)
        (while (and lines
                    (equal (car lines) ""))
          (pop lines))
        ;; Insert the doc string.
        (dolist (line lines)
          (insert line "\n"))
        (ensure-empty-lines)
        ;; Insert the boilerplate.
        (let* ((fill-prefix nil)
               (docs-fc (bound-and-true-p emacs-lisp-docstring-fill-column))
               (fill-column (if (integerp docs-fc) docs-fc 65))
               (argdoc (format
                        easy-mmode--arg-docstring
                        (if global "global " "")
                        mode-pretty-name
                        (concat
                         (if (symbolp getter) "the variable ")
                         (format "`%s'"
                                 ;; Avoid having quotes turn into pretty quotes.
                                 (string-replace "'" "\\='" (format "%S" getter)))))))
          (let ((start (point)))
            (insert argdoc)
            (when (fboundp 'fill-region) ;Don't break bootstrap!
              (fill-region start (point) 'left t))))
        ;; Finally, insert the keymap.
        (when (and (boundp keymap-sym)
                   (or (not doc)
                       (not (string-search "\\{" doc))))
          (ensure-empty-lines)
          (insert (format "\\{%s}" keymap-sym)))
        (buffer-string)))))