all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Boruch Baum <boruch_baum@gmx.com>
To: Emacs-Devel List <emacs-devel@gnu.org>
Subject: ~Make emacs friendlier: package documentation [POC CODE INCLUDED]
Date: Thu, 15 Oct 2020 15:09:29 -0400	[thread overview]
Message-ID: <20201015190929.gdvx7j2yukcdcoaw@E15-2016.optimum.net> (raw)

[-- Attachment #1: Type: text/plain, Size: 766 bytes --]

A programmer's idea of a friendly environment might be the opposite of a
user's in that what programmer enjoys writing documentation, and having
to repeat the process with almost identical text in more than place, and
in more than one format. There are docstrings, and then there's the
commentary at the top of the elisp file, and then any info file, and
what else.

Attached is working proof-of-concept code to allow a user to easily get
all a package's in-line documentation, in the format of an org-mode
buffer, to cover cases where there is no info file, or to supplement the
info file.

Evaluate the code, Perform M-x pack-doc, and select an emacs-lisp
package file.

--
hkp://keys.gnupg.net
CA45 09B5 5351 7C11 A9D1  7286 0036 9E45 1595 8BC0

[-- Attachment #2: pack-doc.el --]
[-- Type: text/plain, Size: 2025 bytes --]

;;; pack-doc.el --- Make org documetation from package source file -*- lexical-binding: t -*-

(defun pack-doc (file)
  "Create documentation in org-mode format from FILE.
FILE is an elisp source file formatted according to the emacs
style. Result is an org mode buffer containing the file's
doumentary comments and docstrings."
  (interactive "f")
  ;; TODO: handle prompt for file if NIL
  (switch-to-buffer (get-buffer-create (concat (file-name-nondirectory file) ".org")))
  (insert-file-contents-literally file nil nil nil 'replace)
  (goto-char (point-min))
  ;; Comment-out docstrings
  (let (p0 p1 p2)
    (while (setq p0 (re-search-forward "^(def" nil t))
      (when (not (re-search-forward "^ +\"" nil t))
        (error "badly formatted file, near %d" p0))
      (setq p1 (match-beginning 0))
      (replace-match "")
      (when (not (re-search-forward "\")?$" nil t))
        (error "badly formatted file, near %d" p0))
      (setq p2 (match-beginning 0))
      (replace-match "")
      (goto-char p1)
      (narrow-to-region p1 p2) ; because p2 moves with every replacement
      (while (re-search-forward "^" nil t)
        (replace-match ";;"))
      (widen)))
  ;; Comment-out def* and adjust pre-existing comments
  (dolist (repl '(("^;;; " ";;;; ")
                  ("^$"    ";;")
                  ("^(def" ";;; (def")))
    (goto-char (point-min))
    (while (re-search-forward (car repl) nil t)
      (replace-match (cadr repl))))
  ;; Remove everything else
  (goto-char (point-min))
  (delete-non-matching-lines  "^;" (point-min) (point-max))
  ;; Create org headings and remove extra blank lines
  (dolist (repl '(("^;;;;" "**")
                  ("^;;; (def[^ ]+" "***")
                  ("^;;;" "***")
                  ("^;;" " ")
                  ("^ +$" "")
                  ("\n\n+" "\n\n")))
    (goto-char (point-min))
    (while (re-search-forward (car repl) nil t)
      (replace-match (cadr repl))))
  ;; Create top heading
  (goto-char 1)
  (delete-char 1)
  ;; Ta-da!
  (org-mode))

             reply	other threads:[~2020-10-15 19:09 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-15 19:09 Boruch Baum [this message]
2020-10-15 19:24 ` ~Make emacs friendlier: package documentation [POC CODE INCLUDED] Eli Zaretskii
2020-10-15 19:41   ` Boruch Baum
2020-10-16  6:39     ` Eli Zaretskii
2020-10-16  7:34       ` Boruch Baum
2020-10-16 10:20         ` Eli Zaretskii
2020-10-18  5:58           ` Boruch Baum
2020-10-18 14:53             ` Eli Zaretskii
2020-10-18 15:05               ` Boruch Baum
2020-10-18 15:12                 ` Eli Zaretskii
2020-10-18 15:28                   ` Boruch Baum
2020-10-18 16:00                     ` Eli Zaretskii
2020-10-18 16:29                       ` Boruch Baum
2020-10-18 17:05                         ` Eli Zaretskii
2020-10-18 13:11         ` Stefan Monnier
2020-10-18 14:43           ` Boruch Baum
2020-10-18 15:50             ` Stefan Kangas
2020-10-18 16:20               ` Boruch Baum
2020-10-18 17:13                 ` Stefan Kangas
2020-10-18 20:40                 ` Kévin Le Gouguec
2020-10-19  2:55                   ` Boruch Baum
2020-10-21  5:52                     ` Kévin Le Gouguec
2020-10-21  6:00                       ` Boruch Baum
2020-10-21 22:31                     ` Stefan Monnier
2020-10-18 15:58             ` Boruch Baum
2020-10-18 20:18           ` Stefan Monnier
2020-10-19  2:24             ` Eli Zaretskii
2020-10-19  2:59               ` Boruch Baum
2020-10-19  3:16                 ` Stefan Monnier
2020-10-20  5:11                   ` Richard Stallman
2020-10-20  5:51                     ` Boruch Baum

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201015190929.gdvx7j2yukcdcoaw@E15-2016.optimum.net \
    --to=boruch_baum@gmx.com \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.