unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Damien Cassou <damien@cassou.me>
To: notmuch@notmuchmail.org
Subject: Add support for imenu
Date: Tue, 23 May 2017 17:25:43 +0200	[thread overview]
Message-ID: <87mva3r3wo.fsf@cassou.me> (raw)

[-- 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


             reply	other threads:[~2017-05-23 15:30 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-23 15:25 Damien Cassou [this message]
2017-05-23 16:45 ` Add support for imenu 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

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=87mva3r3wo.fsf@cassou.me \
    --to=damien@cassou.me \
    --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).