* Add support for imenu
@ 2017-05-23 15:25 Damien Cassou
2017-05-23 16:45 ` Jani Nikula
2017-05-24 6:14 ` [PATCH] Add Emacs' imenu support in notmuch-show and notmuch-search Damien Cassou
0 siblings, 2 replies; 15+ messages in thread
From: Damien Cassou @ 2017-05-23 15:25 UTC (permalink / raw)
To: notmuch
[-- Attachment #1: Type: text/plain, Size: 246 bytes --]
Please find attached a patch adding imenu support in both search
and show modes.
--
Damien Cassou
http://damiencassou.seasidehosting.st
"Success is the ability to go from one failure to another without
losing enthusiasm." --Winston Churchill
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-imenu-support-in-notmuch-show-and-notmuch-search.patch --]
[-- Type: text/x-patch, Size: 3799 bytes --]
From aa29c3e4227ad95e940a047494ef5367eaa57596 Mon Sep 17 00:00:00 2001
From: Damien Cassou <damien@cassou.me>
Date: Tue, 23 May 2017 17:19:57 +0200
Subject: [PATCH] Add imenu support in notmuch-show and notmuch-search
---
emacs/notmuch-show.el | 22 +++++++++++++++++++++-
emacs/notmuch.el | 27 ++++++++++++++++++++++++---
2 files changed, 45 insertions(+), 4 deletions(-)
diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index c670160..b7d6429 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -1516,7 +1516,11 @@
\\{notmuch-show-mode-map}"
(setq notmuch-buffer-refresh-function #'notmuch-show-refresh-view)
(setq buffer-read-only t
- truncate-lines t))
+ truncate-lines t)
+ (setq imenu-prev-index-position-function
+ #'notmuch-show-imenu-prev-index-position-function)
+ (setq imenu-extract-index-name-function
+ #'notmuch-show-imenu-extract-index-name-function))
(defun notmuch-tree-from-show-current-query ()
"Call notmuch tree with the current query"
@@ -2455,6 +2459,22 @@ (list (completing-read "Mime type to use (default text/plain): "
(mailcap-mime-types) nil nil nil nil "text/plain")))
(notmuch-show-apply-to-current-part-handle #'notmuch-show--mm-display-part mime-type))
+(defun notmuch-show-imenu-prev-index-position-function ()
+ "Move point to previous message in notmuch-show buffer.
+This function is used as a value for
+`imenu-prev-index-position-function'."
+ (if (bobp)
+ nil
+ (notmuch-show-previous-message)
+ t))
+
+(defun notmuch-show-imenu-extract-index-name-function ()
+ "Return imenu name for line at point.
+This function is used as a value for
+`imenu-extract-index-name-function'. Point should be at the
+beginning of the line."
+ (buffer-substring-no-properties (line-beginning-position) (line-end-position)))
+
(provide 'notmuch-show)
;;; notmuch-show.el ends here
diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index 40b9fab..90af68e 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -374,7 +374,11 @@ (setq notmuch-buffer-refresh-function #'notmuch-search-refresh-view)
(set (make-local-variable 'scroll-preserve-screen-position) t)
(add-to-invisibility-spec (cons 'ellipsis t))
(setq truncate-lines t)
- (setq buffer-read-only t))
+ (setq buffer-read-only t)
+ (setq imenu-prev-index-position-function
+ #'notmuch-search-imenu-prev-index-position-function)
+ (setq imenu-extract-index-name-function
+ #'notmuch-search-imenu-extract-index-name-function))
(defun notmuch-search-get-result (&optional pos)
"Return the result object for the thread at POS (or point).
@@ -1094,8 +1098,8 @@ (bury-buffer))
;; Find the first notmuch buffer.
(setq first (loop for buffer in (buffer-list)
- if (notmuch-interesting-buffer buffer)
- return buffer))
+ if (notmuch-interesting-buffer buffer)
+ return buffer))
(if first
;; If the first one we found is any other than the starting
@@ -1104,6 +1108,23 @@ (unless (eq first start)
(switch-to-buffer first))
(notmuch))))
+;;;; Imenu Support
+
+(defun notmuch-search-imenu-prev-index-position-function ()
+ "Move point to previous message in notmuch-search buffer.
+This function is used as a value for
+`imenu-prev-index-position-function'."
+ (notmuch-search-previous-thread))
+
+(defun notmuch-search-imenu-extract-index-name-function ()
+ "Return imenu name for line at point.
+This function is used as a value for
+`imenu-extract-index-name-function'. Point should be at the
+beginning of the line."
+ (let ((subject (notmuch-search-find-subject))
+ (author (notmuch-search-find-authors)))
+ (format "%s (%s)" subject author)))
+
(setq mail-user-agent 'notmuch-user-agent)
(provide 'notmuch)
--
2.9.4
^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: Add support for imenu
2017-05-23 15:25 Add support for imenu Damien Cassou
@ 2017-05-23 16:45 ` Jani Nikula
2017-05-24 6:17 ` Damien Cassou
2017-05-24 6:14 ` [PATCH] Add Emacs' imenu support in notmuch-show and notmuch-search Damien Cassou
1 sibling, 1 reply; 15+ messages in thread
From: Jani Nikula @ 2017-05-23 16:45 UTC (permalink / raw)
To: Damien Cassou, notmuch; +Cc: notmuch
On Tue, 23 May 2017, Damien Cassou <damien@cassou.me> wrote:
> Please find attached a patch adding imenu support in both search
> and show modes.
I would appreciate a commit message explaining what the patch is about,
written to someone who doesn't know what imenu is, or how it could be
applicable in search and show modes.
Please also look into using git send-email if possible, instead of
attaching the patch.
BR,
Jani.
>
> --
> Damien Cassou
> http://damiencassou.seasidehosting.st
>
> "Success is the ability to go from one failure to another without
> losing enthusiasm." --Winston Churchill
> From aa29c3e4227ad95e940a047494ef5367eaa57596 Mon Sep 17 00:00:00 2001
> From: Damien Cassou <damien@cassou.me>
> Date: Tue, 23 May 2017 17:19:57 +0200
> Subject: [PATCH] Add imenu support in notmuch-show and notmuch-search
>
> ---
> emacs/notmuch-show.el | 22 +++++++++++++++++++++-
> emacs/notmuch.el | 27 ++++++++++++++++++++++++---
> 2 files changed, 45 insertions(+), 4 deletions(-)
>
> diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
> index c670160..b7d6429 100644
> --- a/emacs/notmuch-show.el
> +++ b/emacs/notmuch-show.el
> @@ -1516,7 +1516,11 @@
> \\{notmuch-show-mode-map}"
> (setq notmuch-buffer-refresh-function #'notmuch-show-refresh-view)
> (setq buffer-read-only t
> - truncate-lines t))
> + truncate-lines t)
> + (setq imenu-prev-index-position-function
> + #'notmuch-show-imenu-prev-index-position-function)
> + (setq imenu-extract-index-name-function
> + #'notmuch-show-imenu-extract-index-name-function))
>
> (defun notmuch-tree-from-show-current-query ()
> "Call notmuch tree with the current query"
> @@ -2455,6 +2459,22 @@ (list (completing-read "Mime type to use (default text/plain): "
> (mailcap-mime-types) nil nil nil nil "text/plain")))
> (notmuch-show-apply-to-current-part-handle #'notmuch-show--mm-display-part mime-type))
>
> +(defun notmuch-show-imenu-prev-index-position-function ()
> + "Move point to previous message in notmuch-show buffer.
> +This function is used as a value for
> +`imenu-prev-index-position-function'."
> + (if (bobp)
> + nil
> + (notmuch-show-previous-message)
> + t))
> +
> +(defun notmuch-show-imenu-extract-index-name-function ()
> + "Return imenu name for line at point.
> +This function is used as a value for
> +`imenu-extract-index-name-function'. Point should be at the
> +beginning of the line."
> + (buffer-substring-no-properties (line-beginning-position) (line-end-position)))
> +
> (provide 'notmuch-show)
>
> ;;; notmuch-show.el ends here
> diff --git a/emacs/notmuch.el b/emacs/notmuch.el
> index 40b9fab..90af68e 100644
> --- a/emacs/notmuch.el
> +++ b/emacs/notmuch.el
> @@ -374,7 +374,11 @@ (setq notmuch-buffer-refresh-function #'notmuch-search-refresh-view)
> (set (make-local-variable 'scroll-preserve-screen-position) t)
> (add-to-invisibility-spec (cons 'ellipsis t))
> (setq truncate-lines t)
> - (setq buffer-read-only t))
> + (setq buffer-read-only t)
> + (setq imenu-prev-index-position-function
> + #'notmuch-search-imenu-prev-index-position-function)
> + (setq imenu-extract-index-name-function
> + #'notmuch-search-imenu-extract-index-name-function))
>
> (defun notmuch-search-get-result (&optional pos)
> "Return the result object for the thread at POS (or point).
> @@ -1094,8 +1098,8 @@ (bury-buffer))
>
> ;; Find the first notmuch buffer.
> (setq first (loop for buffer in (buffer-list)
> - if (notmuch-interesting-buffer buffer)
> - return buffer))
> + if (notmuch-interesting-buffer buffer)
> + return buffer))
>
> (if first
> ;; If the first one we found is any other than the starting
> @@ -1104,6 +1108,23 @@ (unless (eq first start)
> (switch-to-buffer first))
> (notmuch))))
>
> +;;;; Imenu Support
> +
> +(defun notmuch-search-imenu-prev-index-position-function ()
> + "Move point to previous message in notmuch-search buffer.
> +This function is used as a value for
> +`imenu-prev-index-position-function'."
> + (notmuch-search-previous-thread))
> +
> +(defun notmuch-search-imenu-extract-index-name-function ()
> + "Return imenu name for line at point.
> +This function is used as a value for
> +`imenu-extract-index-name-function'. Point should be at the
> +beginning of the line."
> + (let ((subject (notmuch-search-find-subject))
> + (author (notmuch-search-find-authors)))
> + (format "%s (%s)" subject author)))
> +
> (setq mail-user-agent 'notmuch-user-agent)
>
> (provide 'notmuch)
> --
> 2.9.4
>
> _______________________________________________
> notmuch mailing list
> notmuch@notmuchmail.org
> https://notmuchmail.org/mailman/listinfo/notmuch
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH] Add Emacs' imenu support in notmuch-show and notmuch-search
2017-05-23 15:25 Add support for imenu Damien Cassou
2017-05-23 16:45 ` Jani Nikula
@ 2017-05-24 6:14 ` Damien Cassou
2017-06-10 0:12 ` David Bremner
1 sibling, 1 reply; 15+ messages in thread
From: Damien Cassou @ 2017-05-24 6:14 UTC (permalink / raw)
To: Damien Cassou, notmuch
Emacs' major modes can facilitate navigation in their buffers by
supporting Imenu. In such major modes, launching Imenu (M-x imenu)
makes Emacs display a list of items (e.g., function definitions in a
code buffer). Selecting an item from this list moves point to this
item.
This patch adds Imenu support to both notmuch-show and notmuch-search
buffers:
* in notmuch-show, Imenu will present a list of all messages in the
currently visible thread;
* in notmuch-search, Imenu will present a list of all messages in the
search buffer.
---
emacs/notmuch-show.el | 22 +++++++++++++++++++++-
emacs/notmuch.el | 27 ++++++++++++++++++++++++---
2 files changed, 45 insertions(+), 4 deletions(-)
diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index c670160..b7d6429 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -1516,7 +1516,11 @@
\\{notmuch-show-mode-map}"
(setq notmuch-buffer-refresh-function #'notmuch-show-refresh-view)
(setq buffer-read-only t
- truncate-lines t))
+ truncate-lines t)
+ (setq imenu-prev-index-position-function
+ #'notmuch-show-imenu-prev-index-position-function)
+ (setq imenu-extract-index-name-function
+ #'notmuch-show-imenu-extract-index-name-function))
(defun notmuch-tree-from-show-current-query ()
"Call notmuch tree with the current query"
@@ -2455,6 +2459,22 @@ (list (completing-read "Mime type to use (default text/plain): "
(mailcap-mime-types) nil nil nil nil "text/plain")))
(notmuch-show-apply-to-current-part-handle #'notmuch-show--mm-display-part mime-type))
+(defun notmuch-show-imenu-prev-index-position-function ()
+ "Move point to previous message in notmuch-show buffer.
+This function is used as a value for
+`imenu-prev-index-position-function'."
+ (if (bobp)
+ nil
+ (notmuch-show-previous-message)
+ t))
+
+(defun notmuch-show-imenu-extract-index-name-function ()
+ "Return imenu name for line at point.
+This function is used as a value for
+`imenu-extract-index-name-function'. Point should be at the
+beginning of the line."
+ (buffer-substring-no-properties (line-beginning-position) (line-end-position)))
+
(provide 'notmuch-show)
;;; notmuch-show.el ends here
diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index 40b9fab..90af68e 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -374,7 +374,11 @@ (setq notmuch-buffer-refresh-function #'notmuch-search-refresh-view)
(set (make-local-variable 'scroll-preserve-screen-position) t)
(add-to-invisibility-spec (cons 'ellipsis t))
(setq truncate-lines t)
- (setq buffer-read-only t))
+ (setq buffer-read-only t)
+ (setq imenu-prev-index-position-function
+ #'notmuch-search-imenu-prev-index-position-function)
+ (setq imenu-extract-index-name-function
+ #'notmuch-search-imenu-extract-index-name-function))
(defun notmuch-search-get-result (&optional pos)
"Return the result object for the thread at POS (or point).
@@ -1094,8 +1098,8 @@ (bury-buffer))
;; Find the first notmuch buffer.
(setq first (loop for buffer in (buffer-list)
- if (notmuch-interesting-buffer buffer)
- return buffer))
+ if (notmuch-interesting-buffer buffer)
+ return buffer))
(if first
;; If the first one we found is any other than the starting
@@ -1104,6 +1108,23 @@ (unless (eq first start)
(switch-to-buffer first))
(notmuch))))
+;;;; Imenu Support
+
+(defun notmuch-search-imenu-prev-index-position-function ()
+ "Move point to previous message in notmuch-search buffer.
+This function is used as a value for
+`imenu-prev-index-position-function'."
+ (notmuch-search-previous-thread))
+
+(defun notmuch-search-imenu-extract-index-name-function ()
+ "Return imenu name for line at point.
+This function is used as a value for
+`imenu-extract-index-name-function'. Point should be at the
+beginning of the line."
+ (let ((subject (notmuch-search-find-subject))
+ (author (notmuch-search-find-authors)))
+ (format "%s (%s)" subject author)))
+
(setq mail-user-agent 'notmuch-user-agent)
(provide 'notmuch)
--
2.9.4
^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: Add support for imenu
2017-05-23 16:45 ` Jani Nikula
@ 2017-05-24 6:17 ` Damien Cassou
0 siblings, 0 replies; 15+ messages in thread
From: Damien Cassou @ 2017-05-24 6:17 UTC (permalink / raw)
To: Jani Nikula, notmuch; +Cc: notmuch
Jani Nikula <jani@nikula.org> writes:
> I would appreciate a commit message explaining what the patch is
> about, written to someone who doesn't know what imenu is, or how
> it could be applicable in search and show modes.
done
> Please also look into using git send-email if possible, instead
> of attaching the patch.
done.
--
Damien Cassou
http://damiencassou.seasidehosting.st
"Success is the ability to go from one failure to another without
losing enthusiasm." --Winston Churchill
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] Add Emacs' imenu support in notmuch-show and notmuch-search
2017-05-24 6:14 ` [PATCH] Add Emacs' imenu support in notmuch-show and notmuch-search Damien Cassou
@ 2017-06-10 0:12 ` David Bremner
2017-06-10 21:49 ` Damien Cassou
0 siblings, 1 reply; 15+ messages in thread
From: David Bremner @ 2017-06-10 0:12 UTC (permalink / raw)
To: Damien Cassou, notmuch
Damien Cassou <damien@cassou.me> writes:
> Emacs' major modes can facilitate navigation in their buffers by
> supporting Imenu. In such major modes, launching Imenu (M-x imenu)
> makes Emacs display a list of items (e.g., function definitions in a
> code buffer). Selecting an item from this list moves point to this
> item.
>
> This patch adds Imenu support to both notmuch-show and notmuch-search
> buffers:
>
> * in notmuch-show, Imenu will present a list of all messages in the
> currently visible thread;
>
> * in notmuch-search, Imenu will present a list of all messages in the
> search buffer.
In show mode the chosen imenu index function seems less useful to me; it
treats indentation level as significant, so in threads with many levels
of reply, one has to type many periods. It's also not clear to me that
the information on the header line is very helpful for navigation, even
without indentation.
d
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] Add Emacs' imenu support in notmuch-show and notmuch-search
2017-06-10 0:12 ` David Bremner
@ 2017-06-10 21:49 ` Damien Cassou
2017-06-11 1:29 ` David Bremner
0 siblings, 1 reply; 15+ messages in thread
From: Damien Cassou @ 2017-06-10 21:49 UTC (permalink / raw)
To: David Bremner, notmuch
David Bremner <david@tethera.net> writes:
> In show mode the chosen imenu index function seems less useful
> to me; it treats indentation level as significant, so in threads
> with many levels of reply, one has to type many periods. It's
> also not clear to me that the information on the header line is
> very helpful for navigation, even without indentation.
I guess you are using the default imenu frontend which is both
ugly and inefficient. I also guess few people care about adding
imenu support to packages for this exact reason. The counsel's
version is quite good though (see attached screenshot). The
indentation is respected making the imenu content a visual
overview of the thread (and you don't have to type any periods).
I can still get rid of indentation if you confirm you don't want
it. For example, I understand that it would be nice to have better
integration with the original imenu frontend (even though the
default frontend is so bad I doubt anyone not having a better
version ever uses imenu at all). You also say the information on
the header line is not very helpful. Do you have any other
suggestion? I'm open to trying several different alternatives and
see what people prefer.
Bye
--
Damien Cassou
http://damiencassou.seasidehosting.st
"Success is the ability to go from one failure to another without
losing enthusiasm." --Winston Churchill
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] Add Emacs' imenu support in notmuch-show and notmuch-search
2017-06-10 21:49 ` Damien Cassou
@ 2017-06-11 1:29 ` David Bremner
2017-06-11 9:28 ` Damien Cassou
0 siblings, 1 reply; 15+ messages in thread
From: David Bremner @ 2017-06-11 1:29 UTC (permalink / raw)
To: Damien Cassou, notmuch
Damien Cassou <damien@cassou.me> writes:
> David Bremner <david@tethera.net> writes:
>> In show mode the chosen imenu index function seems less useful
>> to me; it treats indentation level as significant, so in threads
>> with many levels of reply, one has to type many periods. It's
>> also not clear to me that the information on the header line is
>> very helpful for navigation, even without indentation.
>
> I guess you are using the default imenu frontend which is both
> ugly and inefficient. I also guess few people care about adding
> imenu support to packages for this exact reason. The counsel's
> version is quite good though (see attached screenshot). The
> indentation is respected making the imenu content a visual
> overview of the thread (and you don't have to type any periods).
I am indeed using the default. I think you forgot the screen shot.
> I can still get rid of indentation if you confirm you don't want
> it.
I think so, although to be honest I never tried imenu before testing
your patches, perhaps we should wait for other opinions.
> You also say the information on
> the header line is not very helpful. Do you have any other
> suggestion? I'm open to trying several different alternatives and
> see what people prefer.
I guess I don't really understand how the matching is supposed to
work. If the user has to type from the beginning of the index string,
then I guess putting either the date or the subject first might be
helpful. It's probably true that there is no one good order for all
threads. Some threads change subject often, others author, and one I'm
looking at right now has 25 messages with two authors and one subject.
d
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] Add Emacs' imenu support in notmuch-show and notmuch-search
2017-06-11 1:29 ` David Bremner
@ 2017-06-11 9:28 ` Damien Cassou
2017-06-11 11:00 ` David Bremner
0 siblings, 1 reply; 15+ messages in thread
From: Damien Cassou @ 2017-06-11 9:28 UTC (permalink / raw)
To: David Bremner, notmuch
[-- Attachment #1: Type: text/plain, Size: 1400 bytes --]
David Bremner <david@tethera.net> writes:
> I am indeed using the default. I think you forgot the screen
> shot.
indeed. Attached to this email.
>> I can still get rid of indentation if you confirm you don't
>> want it.
>
> I think so, although to be honest I never tried imenu before
> testing your patches, perhaps we should wait for other opinions.
I advise you to install counsel at least for that (I don't use it
for anything else).
>> You also say the information on the header line is not very
>> helpful. Do you have any other suggestion? I'm open to trying
>> several different alternatives and see what people prefer.
>
> I guess I don't really understand how the matching is supposed
> to work. If the user has to type from the beginning of the index
> string, then I guess putting either the date or the subject
> first might be helpful.
That depends on the frontend. For example, with counsel-imenu, I
can type "attach" to filter by emails in the thread with the
attachment tag.
> It's probably true that there is no one good order for all
> threads. Some threads change subject often, others author, and
> one I'm looking at right now has 25 messages with two authors
> and one subject.
--
Damien Cassou
http://damiencassou.seasidehosting.st
"Success is the ability to go from one failure to another without
losing enthusiasm." --Winston Churchill
[-- Attachment #2: Screenshot from 2017-06-10 22-24-26.png --]
[-- Type: image/png, Size: 297873 bytes --]
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH] Add Emacs' imenu support in notmuch-show and notmuch-search
2017-06-11 9:28 ` Damien Cassou
@ 2017-06-11 11:00 ` David Bremner
2017-06-12 13:30 ` Damien Cassou
0 siblings, 1 reply; 15+ messages in thread
From: David Bremner @ 2017-06-11 11:00 UTC (permalink / raw)
To: Damien Cassou, notmuch
Damien Cassou <damien@cassou.me> writes:
> David Bremner <david@tethera.net> writes:
>> I am indeed using the default. I think you forgot the screen
>> shot.
>
>
> indeed. Attached to this email.
>
>
>>> I can still get rid of indentation if you confirm you don't
>>> want it.
>>
>> I think so, although to be honest I never tried imenu before
>> testing your patches, perhaps we should wait for other opinions.
>
>
> I advise you to install counsel at least for that (I don't use it
> for anything else).
>
OK, I see with counsel-imenu the current indexing by header lines is
reasonable. It might be improvable by adding the subject, but I'm not
sure about line lengths.
- maybe the docstrings should recomment counsel-imenu?
- I think the indentation should probably go to make it more
usable with the builtin imenu
^ permalink raw reply [flat|nested] 15+ messages in thread
* (no subject)
2017-06-11 11:00 ` David Bremner
@ 2017-06-12 13:30 ` Damien Cassou
2017-06-12 13:30 ` [PATCH] Add Emacs' imenu support in notmuch-show and notmuch-search Damien Cassou
2017-06-14 1:22 ` David Bremner
0 siblings, 2 replies; 15+ messages in thread
From: Damien Cassou @ 2017-06-12 13:30 UTC (permalink / raw)
To: David Bremner, Damien Cassou, notmuch
> OK, I see with counsel-imenu the current indexing by header lines is
> reasonable. It might be improvable by adding the subject, but I'm
> not sure about line lengths.
> - maybe the docstrings should recomment counsel-imenu?
I'm not sure as the function
`notmuch-show-imenu-extract-index-name-function` is private and there
are other imenu frontends available. What about a NEWS entry instead
along those lines:
* Add Emacs' imenu support in notmuch-show and notmuch-search
Emacs' major modes can facilitate navigation in their buffers by
supporting Imenu. In such major modes, launching Imenu (M-x imenu)
makes Emacs display a list of items (e.g., function definitions in
a code buffer). Selecting an item from this list moves point to
this item.
This release adds Imenu support to both notmuch-show and
notmuch-search buffers:
* in notmuch-show, Imenu will present a list of all messages in
the currently visible thread;
* in notmuch-search, Imenu will present a list of all messages in the
search buffer.
We recommand an external imenu frontend, such as counsel-imenu,
which will make the experience much better that the default `M-x
imenu`.
> I think the indentation should probably go to make it more usable
> with the builtin imenu
I did that in the patch even though I liked it with indentation better.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH] Add Emacs' imenu support in notmuch-show and notmuch-search
2017-06-12 13:30 ` Damien Cassou
@ 2017-06-12 13:30 ` Damien Cassou
2017-06-14 1:22 ` David Bremner
1 sibling, 0 replies; 15+ messages in thread
From: Damien Cassou @ 2017-06-12 13:30 UTC (permalink / raw)
To: David Bremner, Damien Cassou, notmuch
Emacs' major modes can facilitate navigation in their buffers by
supporting Imenu. In such major modes, launching Imenu (M-x imenu)
makes Emacs display a list of items (e.g., function definitions in a
code buffer). Selecting an item from this list moves point to this
item.
This patch adds Imenu support to both notmuch-show and notmuch-search
buffers:
* in notmuch-show, Imenu will present a list of all messages in the
currently visible thread;
* in notmuch-search, Imenu will present a list of all messages in the
search buffer.
---
emacs/notmuch-show.el | 23 ++++++++++++++++++++++-
emacs/notmuch.el | 27 ++++++++++++++++++++++++---
2 files changed, 46 insertions(+), 4 deletions(-)
diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index e7c22da..0f157ec 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -1516,7 +1516,11 @@
\\{notmuch-show-mode-map}"
(setq notmuch-buffer-refresh-function #'notmuch-show-refresh-view)
(setq buffer-read-only t
- truncate-lines t))
+ truncate-lines t)
+ (setq imenu-prev-index-position-function
+ #'notmuch-show-imenu-prev-index-position-function)
+ (setq imenu-extract-index-name-function
+ #'notmuch-show-imenu-extract-index-name-function))
(defun notmuch-tree-from-show-current-query ()
"Call notmuch tree with the current query"
@@ -2465,6 +2469,23 @@ (list (completing-read "Mime type to use (default text/plain): "
(mailcap-mime-types) nil nil nil nil "text/plain")))
(notmuch-show-apply-to-current-part-handle #'notmuch-show--mm-display-part mime-type))
+(defun notmuch-show-imenu-prev-index-position-function ()
+ "Move point to previous message in notmuch-show buffer.
+This function is used as a value for
+`imenu-prev-index-position-function'."
+ (if (bobp)
+ nil
+ (notmuch-show-previous-message)
+ t))
+
+(defun notmuch-show-imenu-extract-index-name-function ()
+ "Return imenu name for line at point.
+This function is used as a value for
+`imenu-extract-index-name-function'. Point should be at the
+beginning of the line."
+ (back-to-indentation)
+ (buffer-substring-no-properties (point) (line-end-position)))
+
(provide 'notmuch-show)
;;; notmuch-show.el ends here
diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index 40b9fab..90af68e 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -374,7 +374,11 @@ (setq notmuch-buffer-refresh-function #'notmuch-search-refresh-view)
(set (make-local-variable 'scroll-preserve-screen-position) t)
(add-to-invisibility-spec (cons 'ellipsis t))
(setq truncate-lines t)
- (setq buffer-read-only t))
+ (setq buffer-read-only t)
+ (setq imenu-prev-index-position-function
+ #'notmuch-search-imenu-prev-index-position-function)
+ (setq imenu-extract-index-name-function
+ #'notmuch-search-imenu-extract-index-name-function))
(defun notmuch-search-get-result (&optional pos)
"Return the result object for the thread at POS (or point).
@@ -1094,8 +1098,8 @@ (bury-buffer))
;; Find the first notmuch buffer.
(setq first (loop for buffer in (buffer-list)
- if (notmuch-interesting-buffer buffer)
- return buffer))
+ if (notmuch-interesting-buffer buffer)
+ return buffer))
(if first
;; If the first one we found is any other than the starting
@@ -1104,6 +1108,23 @@ (unless (eq first start)
(switch-to-buffer first))
(notmuch))))
+;;;; Imenu Support
+
+(defun notmuch-search-imenu-prev-index-position-function ()
+ "Move point to previous message in notmuch-search buffer.
+This function is used as a value for
+`imenu-prev-index-position-function'."
+ (notmuch-search-previous-thread))
+
+(defun notmuch-search-imenu-extract-index-name-function ()
+ "Return imenu name for line at point.
+This function is used as a value for
+`imenu-extract-index-name-function'. Point should be at the
+beginning of the line."
+ (let ((subject (notmuch-search-find-subject))
+ (author (notmuch-search-find-authors)))
+ (format "%s (%s)" subject author)))
+
(setq mail-user-agent 'notmuch-user-agent)
(provide 'notmuch)
--
2.9.4
^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re:
2017-06-12 13:30 ` Damien Cassou
2017-06-12 13:30 ` [PATCH] Add Emacs' imenu support in notmuch-show and notmuch-search Damien Cassou
@ 2017-06-14 1:22 ` David Bremner
2017-06-14 9:44 ` Re: David Bremner
1 sibling, 1 reply; 15+ messages in thread
From: David Bremner @ 2017-06-14 1:22 UTC (permalink / raw)
To: Damien Cassou, Damien Cassou, notmuch
Damien Cassou <damien@cassou.me> writes:
>> OK, I see with counsel-imenu the current indexing by header lines is
>> reasonable. It might be improvable by adding the subject, but I'm
>> not sure about line lengths.
>> - maybe the docstrings should recomment counsel-imenu?
>
> I'm not sure as the function
> `notmuch-show-imenu-extract-index-name-function` is private and there
> are other imenu frontends available. What about a NEWS entry instead
> along those lines:
>
> * Add Emacs' imenu support in notmuch-show and notmuch-search
>
> Emacs' major modes can facilitate navigation in their buffers by
> supporting Imenu. In such major modes, launching Imenu (M-x imenu)
> makes Emacs display a list of items (e.g., function definitions in
> a code buffer). Selecting an item from this list moves point to
> this item.
>
> This release adds Imenu support to both notmuch-show and
> notmuch-search buffers:
>
> * in notmuch-show, Imenu will present a list of all messages in
> the currently visible thread;
>
> * in notmuch-search, Imenu will present a list of all messages in the
> search buffer.
>
> We recommand an external imenu frontend, such as counsel-imenu,
> which will make the experience much better that the default `M-x
> imenu`.
That sounds fine.
>> I think the indentation should probably go to make it more usable
>> with the builtin imenu
>
> I did that in the patch even though I liked it with indentation better.
I haven't had a chance to test the new version yet, but I think I know
what you mean from testing counsel-imenu. Is it worth adding a
customization variable so that the user can choose indentation if they
have a more sophisticated imenu front end?
d
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re:
2017-06-14 1:22 ` David Bremner
@ 2017-06-14 9:44 ` David Bremner
2017-06-14 9:54 ` Re: Damien Cassou
0 siblings, 1 reply; 15+ messages in thread
From: David Bremner @ 2017-06-14 9:44 UTC (permalink / raw)
To: Damien Cassou, Damien Cassou, notmuch
David Bremner <david@tethera.net> writes:
>> I did that in the patch even though I liked it with indentation better.
>
> I haven't had a chance to test the new version yet, but I think I know
> what you mean from testing counsel-imenu. Is it worth adding a
> customization variable so that the user can choose indentation if they
> have a more sophisticated imenu front end?
So this version is ok with both builtin and counsel imenu front
ends. It's up to you. Do you want to leave the question of controllable
indentation for a later commit or add it now?
d
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re:
2017-06-14 9:44 ` Re: David Bremner
@ 2017-06-14 9:54 ` Damien Cassou
2017-06-14 11:06 ` imenu support David Bremner
0 siblings, 1 reply; 15+ messages in thread
From: Damien Cassou @ 2017-06-14 9:54 UTC (permalink / raw)
To: David Bremner, notmuch
David Bremner <david@tethera.net> writes:
> David Bremner <david@tethera.net> writes:
>
>>> I did that in the patch even though I liked it with
>>> indentation better.
>>
>> I haven't had a chance to test the new version yet, but I think
>> I know what you mean from testing counsel-imenu. Is it worth
>> adding a customization variable so that the user can choose
>> indentation if they have a more sophisticated imenu front end?
>
> So this version is ok with both builtin and counsel imenu front
> ends. It's up to you. Do you want to leave the question of
> controllable indentation for a later commit or add it now?
if you are ok to merge that right now, that would be perfect for
me. Thanks.
--
Damien Cassou
http://damiencassou.seasidehosting.st
"Success is the ability to go from one failure to another without
losing enthusiasm." --Winston Churchill
^ permalink raw reply [flat|nested] 15+ messages in thread
* imenu support
2017-06-14 9:54 ` Re: Damien Cassou
@ 2017-06-14 11:06 ` David Bremner
0 siblings, 0 replies; 15+ messages in thread
From: David Bremner @ 2017-06-14 11:06 UTC (permalink / raw)
To: Damien Cassou, notmuch
Damien Cassou <damien@cassou.me> writes:
> David Bremner <david@tethera.net> writes:
>
>> David Bremner <david@tethera.net> writes:
>>
>>>> I did that in the patch even though I liked it with
>>>> indentation better.
>>>
>>> I haven't had a chance to test the new version yet, but I think
>>> I know what you mean from testing counsel-imenu. Is it worth
>>> adding a customization variable so that the user can choose
>>> indentation if they have a more sophisticated imenu front end?
>>
>> So this version is ok with both builtin and counsel imenu front
>> ends. It's up to you. Do you want to leave the question of
>> controllable indentation for a later commit or add it now?
>
> if you are ok to merge that right now, that would be perfect for
> me. Thanks.
OK, done.
By the way, I notice a certain overlap of functionality between
counsel-imenu support and the way I use tree-view (Z) from show mode.
Given the small amount of code I think it's fine to support imenu as
well, but I thought I'd mention it.
d
^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~2017-06-14 11:06 UTC | newest]
Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-05-23 15:25 Add support for imenu Damien Cassou
2017-05-23 16:45 ` Jani Nikula
2017-05-24 6:17 ` Damien Cassou
2017-05-24 6:14 ` [PATCH] Add Emacs' imenu support in notmuch-show and notmuch-search Damien Cassou
2017-06-10 0:12 ` David Bremner
2017-06-10 21:49 ` Damien Cassou
2017-06-11 1:29 ` David Bremner
2017-06-11 9:28 ` Damien Cassou
2017-06-11 11:00 ` David Bremner
2017-06-12 13:30 ` Damien Cassou
2017-06-12 13:30 ` [PATCH] Add Emacs' imenu support in notmuch-show and notmuch-search Damien Cassou
2017-06-14 1:22 ` David Bremner
2017-06-14 9:44 ` Re: David Bremner
2017-06-14 9:54 ` Re: Damien Cassou
2017-06-14 11:06 ` imenu support David Bremner
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).