[RFC] [PATCH] emacs: Add support for saved search accelerators.
Mark Walters
markwalters1009 at gmail.com
Tue May 6 09:41:21 PDT 2014
Hi
Yes this looks nice modulo polishing. I think the nifty window-splitting
Austin's notmuch-go does is moderately orthogonal to the keyboard
shortcuts (since shortcuts can be used without it, and it could be used
for other things too)
On Tue, 06 May 2014, David Edmondson <dme at dme.org> wrote:
> Extended the saved search definition to allow the inclusion of an
> accelerator key for the search. Bind 'j' in the common mode map as a
> leader for such accelerator keys.
> ---
>
> This arose out a conversation in #notmuch and Mark's patch to extend
> the saved search custom specification based on requirements for an
> external package (Austin's notmuch-go.el).
>
> Re-organising the layout of the saved searches is missing (as it's
> lots of fiddling about with absolute numbers and I didn't want to
> waste time on it if this is going nowhere), so the saved searches may
> not all line up correctly in notmuch-hello.
>
> emacs/notmuch-hello.el | 8 ++++++--
> emacs/notmuch-lib.el | 27 +++++++++++++++++++++++++++
> 2 files changed, 33 insertions(+), 2 deletions(-)
>
> diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el
> index 3de5238..56379ef 100644
> --- a/emacs/notmuch-hello.el
> +++ b/emacs/notmuch-hello.el
> @@ -85,6 +85,7 @@ searches so they still work in customize."
> (group :format "%v" :inline t (const :format " Query: " :query) (string :format "%v")))
> (checklist :inline t
> :format "%v"
> + (group :format "%v" :inline t (const :format " Key: " :key) (string :format "%v"))
if you use key-sequence rather than string then this is a bit nicer. It
allows a multiple key press binding: eg "n i" or "C-n".
> (group :format "%v" :inline t (const :format "Count-Query: " :count-query) (string :format "%v"))
> (group :format "%v" :inline t (const :format "" :sort-order)
> (choice :tag " Sort Order"
> @@ -551,7 +552,8 @@ with `notmuch-hello-query-counts'."
> (when elem
> (if (> column-indent 0)
> (widget-insert (make-string column-indent ? )))
> - (let* ((name (plist-get elem :name))
> + (let* ((key (plist-get elem :key))
> + (name (plist-get elem :name))
> (query (plist-get elem :query))
> (oldest-first (case (plist-get elem :sort-order)
> (newest-first nil)
> @@ -564,7 +566,9 @@ with `notmuch-hello-query-counts'."
> :notify #'notmuch-hello-widget-search
> :notmuch-search-terms query
> :notmuch-search-oldest-first oldest-first
> - name)
> + (if key
> + (concat name " (" key ")")
> + name))
I think it might be worth having an option to suppress the display of
the binding: I think inbox (i) would annoy me, but it is good for discoverability.
I, personally, would be completely happy without the displayed binding.
Actually just a thought: could ? in jump-mode-map be bound to something
that displayed the bindings?
> (setq column-indent
> (1+ (max 0 (- column-width (length name)))))))
> (setq count (1+ count))
> diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
> index 2941da3..9aa7ba7 100644
> --- a/emacs/notmuch-lib.el
> +++ b/emacs/notmuch-lib.el
> @@ -130,6 +130,7 @@ For example, if you wanted to remove an \"inbox\" tag and add an
> (define-key map "m" 'notmuch-mua-new-mail)
> (define-key map "=" 'notmuch-refresh-this-buffer)
> (define-key map "G" 'notmuch-poll-and-refresh-this-buffer)
> + (define-key map "j" 'notmuch-jump)
> map)
> "Keymap shared by all notmuch modes.")
>
> @@ -845,6 +846,32 @@ status."
> (defvar notmuch-show-process-crypto nil)
> (make-variable-buffer-local 'notmuch-show-process-crypto)
>
> +;; Jump key support:
> +
> +(defvar notmuch-jump-search nil)
> +(defun notmuch-jump-map ()
> + (let ((map (make-sparse-keymap)))
> + (set-keymap-parent map nil)
if you make the parent keymap the minibuffer-local-map then the various
exits from the minibuffer work (ctrl-g and return for example)
> + (suppress-keymap map)
> + (dolist (saved-search notmuch-saved-searches)
> + (let ((key (plist-get saved-search :key)))
> + (when key
> + (define-key map key `(lambda ()
> + (interactive)
> + (setq notmuch-jump-search ',saved-search)
> + (exit-minibuffer)
> + )))))
> + map))
> +
> +(defun notmuch-jump ()
> + "Read a saved search accelerator key and perform the associated
> +search."
> + (interactive)
> + (read-from-minibuffer "Jump to saved search: " nil (notmuch-jump-map))
> + (when notmuch-jump-search
> + (notmuch-search (plist-get notmuch-jump-search :query)
> + (plist-get notmuch-jump-search :oldest-first))))
These two plist-gets should be notmuch-saved-search-get. That is a
helper so that people with old style saved searches (a cons cell of name
and query) don't get errors.
(There were also a couple of "not yet declared" things.)
Best wishes
Mark
> +
> (provide 'notmuch-lib)
>
> ;; Local Variables:
> --
> 2.0.0.rc0
>
> _______________________________________________
> notmuch mailing list
> notmuch at notmuchmail.org
> http://notmuchmail.org/mailman/listinfo/notmuch
More information about the notmuch
mailing list