From: Mark Walters <markwalters1009@gmail.com>
To: notmuch@notmuchmail.org
Subject: [PATCH 01/11] emacs: move notmuch-help to lib
Date: Tue, 29 Oct 2013 22:55:28 +0000 [thread overview]
Message-ID: <1383087338-10220-2-git-send-email-markwalters1009@gmail.com> (raw)
In-Reply-To: <1383087338-10220-1-git-send-email-markwalters1009@gmail.com>
notmuch-help is in notmuch.el not notmuch-lib.el and this is
incovenient for the way pick/tree uses it. I think lib makes more
sense anyway so move it there.
---
emacs/notmuch-lib.el | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++
emacs/notmuch.el | 87 --------------------------------------------------
2 files changed, 87 insertions(+), 87 deletions(-)
diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
index 6541282..e7c5c97 100644
--- a/emacs/notmuch-lib.el
+++ b/emacs/notmuch-lib.el
@@ -215,6 +215,93 @@ depending on the value of `notmuch-poll-script'."
(interactive)
(kill-buffer (current-buffer)))
+(defun notmuch-documentation-first-line (symbol)
+ "Return the first line of the documentation string for SYMBOL."
+ (let ((doc (documentation symbol)))
+ (if doc
+ (with-temp-buffer
+ (insert (documentation symbol t))
+ (goto-char (point-min))
+ (let ((beg (point)))
+ (end-of-line)
+ (buffer-substring beg (point))))
+ "")))
+
+(defun notmuch-prefix-key-description (key)
+ "Given a prefix key code, return a human-readable string representation.
+
+This is basically just `format-kbd-macro' but we also convert ESC to M-."
+ (let ((desc (format-kbd-macro (vector key))))
+ (if (string= desc "ESC")
+ "M-"
+ (concat desc " "))))
+
+(defun notmuch-describe-keymap (keymap ua-keys &optional prefix tail)
+ "Return a list of strings, each describing one binding in KEYMAP.
+
+Each string gives a human-readable description of the key and a
+one-line description of the bound function. See `notmuch-help'
+for an overview of how this documentation is extracted.
+
+UA-KEYS should be a key sequence bound to `universal-argument'.
+It will be used to describe bindings of commands that support a
+prefix argument. PREFIX and TAIL are used internally."
+ (map-keymap
+ (lambda (key binding)
+ (cond ((mouse-event-p key) nil)
+ ((keymapp binding)
+ (setq tail
+ (notmuch-describe-keymap
+ binding ua-keys (notmuch-prefix-key-description key) tail)))
+ (t
+ (when (and ua-keys (symbolp binding)
+ (get binding 'notmuch-prefix-doc))
+ ;; Documentation for prefixed command
+ (let ((ua-desc (key-description ua-keys)))
+ (push (concat ua-desc " " prefix (format-kbd-macro (vector key))
+ "\t" (get binding 'notmuch-prefix-doc))
+ tail)))
+ ;; Documentation for command
+ (push (concat prefix (format-kbd-macro (vector key)) "\t"
+ (or (and (symbolp binding) (get binding 'notmuch-doc))
+ (notmuch-documentation-first-line binding)))
+ tail))))
+ keymap)
+ tail)
+
+(defun notmuch-substitute-command-keys (doc)
+ "Like `substitute-command-keys' but with documentation, not function names."
+ (let ((beg 0))
+ (while (string-match "\\\\{\\([^}[:space:]]*\\)}" doc beg)
+ (let* ((keymap-name (substring doc (match-beginning 1) (match-end 1)))
+ (keymap (symbol-value (intern keymap-name)))
+ (ua-keys (where-is-internal 'universal-argument keymap t))
+ (desc-list (notmuch-describe-keymap keymap ua-keys))
+ (desc (mapconcat #'identity desc-list "\n")))
+ (setq doc (replace-match desc 1 1 doc)))
+ (setq beg (match-end 0)))
+ doc))
+
+(defun notmuch-help ()
+ "Display help for the current notmuch mode.
+
+This is similar to `describe-function' for the current major
+mode, but bindings tables are shown with documentation strings
+rather than command names. By default, this uses the first line
+of each command's documentation string. A command can override
+this by setting the 'notmuch-doc property of its command symbol.
+A command that supports a prefix argument can explicitly document
+its prefixed behavior by setting the 'notmuch-prefix-doc property
+of its command symbol."
+ (interactive)
+ (let* ((mode major-mode)
+ (doc (substitute-command-keys (notmuch-substitute-command-keys (documentation mode t)))))
+ (with-current-buffer (generate-new-buffer "*notmuch-help*")
+ (insert doc)
+ (goto-char (point-min))
+ (set-buffer-modified-p nil)
+ (view-buffer (current-buffer) 'kill-buffer-if-not-modified))))
+
(defvar notmuch-buffer-refresh-function nil
"Function to call to refresh the current buffer.")
(make-variable-buffer-local 'notmuch-buffer-refresh-function)
diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index d0cd906..19210cb 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -119,93 +119,6 @@ To enter a line break in customize, press \\[quoted-insert] C-j."
(mm-save-part p))))
mm-handle))
-(defun notmuch-documentation-first-line (symbol)
- "Return the first line of the documentation string for SYMBOL."
- (let ((doc (documentation symbol)))
- (if doc
- (with-temp-buffer
- (insert (documentation symbol t))
- (goto-char (point-min))
- (let ((beg (point)))
- (end-of-line)
- (buffer-substring beg (point))))
- "")))
-
-(defun notmuch-prefix-key-description (key)
- "Given a prefix key code, return a human-readable string representation.
-
-This is basically just `format-kbd-macro' but we also convert ESC to M-."
- (let ((desc (format-kbd-macro (vector key))))
- (if (string= desc "ESC")
- "M-"
- (concat desc " "))))
-
-(defun notmuch-describe-keymap (keymap ua-keys &optional prefix tail)
- "Return a list of strings, each describing one binding in KEYMAP.
-
-Each string gives a human-readable description of the key and a
-one-line description of the bound function. See `notmuch-help'
-for an overview of how this documentation is extracted.
-
-UA-KEYS should be a key sequence bound to `universal-argument'.
-It will be used to describe bindings of commands that support a
-prefix argument. PREFIX and TAIL are used internally."
- (map-keymap
- (lambda (key binding)
- (cond ((mouse-event-p key) nil)
- ((keymapp binding)
- (setq tail
- (notmuch-describe-keymap
- binding ua-keys (notmuch-prefix-key-description key) tail)))
- (t
- (when (and ua-keys (symbolp binding)
- (get binding 'notmuch-prefix-doc))
- ;; Documentation for prefixed command
- (let ((ua-desc (key-description ua-keys)))
- (push (concat ua-desc " " prefix (format-kbd-macro (vector key))
- "\t" (get binding 'notmuch-prefix-doc))
- tail)))
- ;; Documentation for command
- (push (concat prefix (format-kbd-macro (vector key)) "\t"
- (or (and (symbolp binding) (get binding 'notmuch-doc))
- (notmuch-documentation-first-line binding)))
- tail))))
- keymap)
- tail)
-
-(defun notmuch-substitute-command-keys (doc)
- "Like `substitute-command-keys' but with documentation, not function names."
- (let ((beg 0))
- (while (string-match "\\\\{\\([^}[:space:]]*\\)}" doc beg)
- (let* ((keymap-name (substring doc (match-beginning 1) (match-end 1)))
- (keymap (symbol-value (intern keymap-name)))
- (ua-keys (where-is-internal 'universal-argument keymap t))
- (desc-list (notmuch-describe-keymap keymap ua-keys))
- (desc (mapconcat #'identity desc-list "\n")))
- (setq doc (replace-match desc 1 1 doc)))
- (setq beg (match-end 0)))
- doc))
-
-(defun notmuch-help ()
- "Display help for the current notmuch mode.
-
-This is similar to `describe-function' for the current major
-mode, but bindings tables are shown with documentation strings
-rather than command names. By default, this uses the first line
-of each command's documentation string. A command can override
-this by setting the 'notmuch-doc property of its command symbol.
-A command that supports a prefix argument can explicitly document
-its prefixed behavior by setting the 'notmuch-prefix-doc property
-of its command symbol."
- (interactive)
- (let* ((mode major-mode)
- (doc (substitute-command-keys (notmuch-substitute-command-keys (documentation mode t)))))
- (with-current-buffer (generate-new-buffer "*notmuch-help*")
- (insert doc)
- (goto-char (point-min))
- (set-buffer-modified-p nil)
- (view-buffer (current-buffer) 'kill-buffer-if-not-modified))))
-
(require 'hl-line)
(defun notmuch-hl-line-mode ()
--
1.7.9.1
next prev parent reply other threads:[~2013-10-29 23:02 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-29 22:55 [PATCH 00/11] Move notmuch-tree to mainline Mark Walters
2013-10-29 22:55 ` Mark Walters [this message]
2013-10-29 22:55 ` [PATCH 02/11] emacs: tree: remove unneeded declarations Mark Walters
2013-10-29 22:55 ` [PATCH 03/11] emacs: move notmuch-tree from contrib to mainline Mark Walters
2013-10-29 22:55 ` [PATCH 04/11] emacs: add tree to the makefile Mark Walters
2013-10-29 22:55 ` [PATCH 05/11] test: move emacs-tree test into mainline Mark Walters
2013-10-29 22:55 ` [PATCH 06/11] emacs: tree: remove test for emacs from tree test Mark Walters
2013-10-29 22:55 ` [PATCH 07/11] emacs: minimal change to autoload notmuch-tree Mark Walters
2013-10-29 22:55 ` [PATCH 08/11] test: tree: remove require from tests Mark Walters
2013-10-29 22:55 ` [PATCH 09/11] emacs: move search based tree functions to notmuch.el Mark Walters
2013-10-29 22:55 ` [PATCH 10/11] emacs: add z to common keymap Mark Walters
2013-10-29 22:55 ` [PATCH 11/11] emacs: move the show entry to tree into show.el Mark Walters
2013-10-30 18:01 ` [PATCH 00/11] Move notmuch-tree to mainline Tomi Ollila
2013-10-30 18:48 ` Mark Walters
2013-11-01 9:23 ` [PATCH v2 7-11] Fix commit messages Mark Walters
2013-11-01 9:23 ` [PATCH v2 7/11] emacs: minimal change to load notmuch-tree by default Mark Walters
2013-11-01 9:23 ` [PATCH v2 8/11] test: tree: remove require from tests Mark Walters
2013-11-01 9:23 ` [PATCH v2 9/11] emacs: move search based tree functions to notmuch.el Mark Walters
2013-11-01 9:23 ` [PATCH v2 10/11] emacs: add z to common keymap Mark Walters
2013-11-01 9:23 ` [PATCH v2 11/11] emacs: move the show entry to tree into show.el Mark Walters
2013-11-01 12:04 ` [PATCH v2 7-11] Fix commit messages Tomi Ollila
2013-11-07 12:20 ` [PATCH 00/11] Move notmuch-tree to mainline David Bremner
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
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1383087338-10220-2-git-send-email-markwalters1009@gmail.com \
--to=markwalters1009@gmail.com \
--cc=notmuch@notmuchmail.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 public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).