bbdb-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] Support for notmuch mua (version 2)


From: jao
Subject: [PATCH] Support for notmuch mua (version 2)
Date: Fri, 26 Aug 2022 00:55:03 +0100

Extended support for notmuch, including adding and editing BBDB records.

---
This is a slightly improved version of my previous patch with a correction in
how the notmuch insinuate function is registered (it was added to a wrong hook
in the previous patch).
---
 ChangeLog            | 10 ++++++++
 configure.ac         |  1 +
 lisp/Makefile.am     | 14 ++++++++----
 lisp/bbdb-mua.el     | 17 +++++++++++---
 lisp/bbdb-notmuch.el | 54 ++++++++++++++++++++++++++++++++++++++++++++
 lisp/bbdb.el         |  7 ++++--
 lisp/makefile-temp   | 24 +++++++++++++-------
 m4/emacs_notmuch.m4  | 39 ++++++++++++++++++++++++++++++++
 8 files changed, 149 insertions(+), 17 deletions(-)
 create mode 100644 lisp/bbdb-notmuch.el
 create mode 100644 m4/emacs_notmuch.m4

diff --git a/ChangeLog b/ChangeLog
index 7d43db3..3caca26 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2022-08-24 jao <jao@gnu.org>
+       Support for notmuch mua
+       * lisp/bbdb-notmuch.el: new file with auxiliary functions.
+       * lisp/bbdb.el (bbdb-init-functions): register notmuch.
+       * lisp/bbdb-mua.el (bbdb-message-header, bbdb-mua-update-records)
+       (bbdb-mua-wrapper): use the functions in bbdb-notmuch.el.
+       * lisp/Makefile.am, lisp/makefile-temp: declare bbdb-notmuch.
+       * configure.ac, m4/emacs_notmuch: new EMACS_NOTMUCH macro to
+       declare notmuch's installation directory.
+
 2022-07-05  Arash Esbati <arash@gnu.org>
        Silence the compiler.
        * lisp/bbdb.el, lisp/bbdb-com.el: Fix unescaped single quotes in
diff --git a/configure.ac b/configure.ac
index edb11c7..32204ee 100644
--- a/configure.ac
+++ b/configure.ac
@@ -50,6 +50,7 @@ AS_IF([test "$EMACS" = no], [AC_MSG_ERROR([cannot find 
Emacs])])
 EMACS_VM
 EMACS_MU4E
 EMACS_WL
+EMACS_NOTMUCH
 AC_SUBST([AM_ELCFLAGS])

 # Generate lisp/bbdb-site.el via lisp/Makefile as pkgdatadir is only known
diff --git a/lisp/Makefile.am b/lisp/Makefile.am
index 547d9cd..4cde8e8 100644
--- a/lisp/Makefile.am
+++ b/lisp/Makefile.am
@@ -4,19 +4,19 @@

 # Author: Roland Winkler <winkler@gnu.org>
 #        Christian Egli <christian.egli@sbs.ch>
-#
+#
 # This file is part of the Insidious Big Brother Database (aka BBDB),
-#
+#
 # BBDB is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # the Free Software Foundation, either version 3 of the License, or
 # (at your option) any later version.
-#
+#
 # BBDB is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
-#
+#
 # You should have received a copy of the GNU General Public License
 # along with BBDB.  If not, see <http://www.gnu.org/licenses/>.

@@ -60,6 +60,12 @@ dist_lisp_LISP += bbdb-wl.el
 # in the Emacs load path when compiling BBDB with WL support.
 endif

+if NOTMUCH
+dist_lisp_LISP += bbdb-notmuch.el
+# We use the Automake variable AM_ELCFLAGS to include the notmuch lisp 
directory
+# in the Emacs load path when compiling BBDB with notmuch support.
+endif
+
 lisp_DATA = bbdb-loaddefs.el

 MOSTLYCLEANFILES = bbdb-loaddefs.el
diff --git a/lisp/bbdb-mua.el b/lisp/bbdb-mua.el
index df0366a..8cc1a5d 100644
--- a/lisp/bbdb-mua.el
+++ b/lisp/bbdb-mua.el
@@ -65,6 +65,8 @@

   (autoload 'bbdb/wl-header "bbdb-wl")

+  (autoload 'bbdb/notmuch-header "bbdb-notmuch")
+
   (autoload 'message-field-value "message")
   (autoload 'mail-decode-encoded-word-string "mail-parse"))

@@ -74,6 +76,7 @@
     (rmail rmail-mode rmail-summary-mode)
     (mh mhe-mode mhe-summary-mode mh-folder-mode)
     (mu4e mu4e-view-mode)  ; Tackle `mu4e-headers-mode' later
+    (notmuch notmuch-show-mode notmuch-tree-mode)
     (wl wl-summary-mode wl-draft-mode mime-view-mode)
     (message message-mode mu4e-compose-mode notmuch-message-mode)
     (mail mail-mode))
@@ -88,6 +91,7 @@ Return values include
   vm        Viewmail
   mh        Emacs interface to the MH mail system (aka MH-E)
   mu4e      Mu4e
+  notmuch   Notmuch
   wl        Wanderlust
   message   Mail and News composition mode that goes with Gnus
   mail      Emacs Mail Mode."
@@ -138,6 +142,7 @@ MIME encoded headers are decoded.  Return nil if HEADER 
does not exist."
                        (rmail-get-header header)))
                     ((eq mua 'mh) (bbdb/mh-header header))
                     ((eq mua 'mu4e) (message-field-value header))
+                    ((eq mua 'notmuch) (bbdb/notmuch-header header))
                     ((eq mua 'wl) (bbdb/wl-header header))
                     ((memq mua '(message mail)) (message-field-value header))
                     (t (error "BBDB/%s: header function undefined" mua)))))
@@ -638,11 +643,16 @@ If SORT is non-nil, sort records according to 
`bbdb-record-lessp'."
                       gnus-article-buffer))
         (bbdb-update-records (bbdb-get-address-components header-class)
                              action sort))
+       ;; notmuch
+       ((eq mua 'notmuch)
+        (bbdb-update-records (bbdb-get-address-components header-class)
+                             action sort))
+
        ;; Wanderlust
        ((eq mua 'wl)
         (bbdb-update-records (bbdb-get-address-components header-class)
                              action sort))
-      ;; Message and Mail
+       ;; Message and Mail
        ((memq mua '(message mail))
         (bbdb-update-records (bbdb-get-address-components header-class)
                              action sort))))))
@@ -659,10 +669,11 @@ If SORT is non-nil, sort records according to 
`bbdb-record-lessp'."
             (save-current-buffer
               (gnus-summary-select-article) ; sets buffer `gnus-summary-buffer'
               ,@body))
-           ((memq mua '(mail message rmail mh vm mu4e wl))
+           ((memq mua '(mail message rmail mh vm mu4e notmuch wl))
             (cond ((eq mua 'vm) (vm-follow-summary-cursor))
                   ((eq mua 'mh) (mh-show)))
-            ;; rmail, mail, message, mu4e and wl do not require any wrapper
+            ;; rmail, mail, message, mu4e, notmuch and wl do not require any
+            ;; wrapper
             ,@body))))

 (define-obsolete-function-alias 'bbdb-mua-update-interactive-p
diff --git a/lisp/bbdb-notmuch.el b/lisp/bbdb-notmuch.el
new file mode 100644
index 0000000..504f546
--- /dev/null
+++ b/lisp/bbdb-notmuch.el
@@ -0,0 +1,54 @@
+;;; bbdb-notmuch.el --- BBDB interface to notmuch -*- lexical-binding: t -*-
+
+;; Copyright (C) 2022  Free Software Foundation, Inc.
+
+;; This file is part of the Insidious Big Brother Database (aka BBDB),
+
+;; BBDB is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; BBDB is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with BBDB.  If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+;; This file contains the BBDB interface to notmuch.
+;; See the BBDB info manual for documentation.
+
+;;; Code:
+
+(require 'bbdb)
+(require 'notmuch-show)
+(require 'notmuch-tree)
+
+(defvar notmuch-show-mode-map)
+(defvar notmuch-tree-mode-map)
+
+;;;###autoload
+(defun bbdb/notmuch-header (header)
+  "Find and return the value of HEADER in the current buffer.
+Return nil if HEADER is not in the message.  This function works
+in notmuch-show-mode and notmuch-tree-mode buffers."
+  (let ((ps (if (derived-mode-p 'notmuch-tree-mode)
+                (notmuch-tree-get-message-properties)
+              (notmuch-show-get-message-properties)))
+        (hdk (cond ((stringp header)
+                    (intern (format ":%s" (capitalize header))))
+                   ((keywordp header) header))))
+    (plist-get (plist-get ps :headers) hdk)))
+
+;;;###autoload
+(defun bbdb-insinuate-notmuch ()
+  "Hook BBDB into notmuch.
+Do not call this in your init file.  Use `bbdb-initialize'."
+  (dolist (m (list notmuch-show-mode-map notmuch-tree-mode-map))
+    (define-key m ":" 'bbdb-mua-display-sender)
+    (define-key m ";" 'bbdb-mua-edit-field-sender)))
+
+;;; bbdb-notmuch.el ends here
diff --git a/lisp/bbdb.el b/lisp/bbdb.el
index e18c54b..a8ce43b 100644
--- a/lisp/bbdb.el
+++ b/lisp/bbdb.el
@@ -1706,6 +1706,7 @@ See also `bbdb-silent'.")
 (declare-function bbdb-insinuate-mail "bbdb-message" ())
 (declare-function bbdb-insinuate-message "bbdb-message" ())
 (declare-function bbdb-insinuate-mu4e "bbdb-m4e" ())
+(declare-function bbdb-insinuate-notmuch "bbdb-notmuch" ())
 (declare-function bbdb-insinuate-sc "bbdb-sc" ())
 (declare-function bbdb-pgp "bbdb-pgp" ())
 (declare-function bbdb-insinuate-wl "bbdb-wl" ())
@@ -1731,8 +1732,9 @@ See also `bbdb-silent'.")
      ,(lambda () (add-hook 'message-setup-hook #'bbdb-insinuate-message)))
     (mu4e                       ; the mu4e user agent
      ,(lambda () (add-hook 'mu4e-main-mode-hook #'bbdb-insinuate-mu4e)))
-
-    (sc                         ; supercite
+    (notmuch                    ; the notmuch user agent
+     ,(lambda () (add-hook 'notmuch-hello-mode-hook #'bbdb-insinuate-notmuch)))
+    (sc                                 ; supercite
      ,(lambda () (add-hook 'sc-load-hook #'bbdb-insinuate-sc)))
     (anniv                      ; anniversaries
      ,(lambda () (add-hook 'diary-list-entries-hook 
#'bbdb-anniv-diary-entries)))
@@ -4815,6 +4817,7 @@ mail/news readers, composers, and miscellaneous packages:
   gnus       Gnus mail/news reader.
   mh-e       MH-E mail reader.
   mu4e       Mu4e mail reader.
+  notmuch    Notmuch mail reader.
   rmail      Rmail mail reader.
   vm         VM mail reader.
   mail       Mail (M-x mail).
diff --git a/lisp/makefile-temp b/lisp/makefile-temp
index d355ab5..a32b485 100644
--- a/lisp/makefile-temp
+++ b/lisp/makefile-temp
@@ -1,18 +1,18 @@
 # Cheap BBDB makefile  -*- Makefile -*-
 # Copyright (C) 2010-2022 Roland Winkler <winkler@gnu.org>
-#
+#
 # This file is part of the Insidious Big Brother Database (aka BBDB),
-#
+#
 # BBDB is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # the Free Software Foundation, either version 3 of the License, or
 # (at your option) any later version.
-#
+#
 # BBDB is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
-#
+#
 # You should have received a copy of the GNU General Public License
 # along with BBDB.  If not, see <http://www.gnu.org/licenses/>.

@@ -63,6 +63,11 @@ VM = -eval '(unless (string= "$(VMDIR)" "") (push "$(VMDIR)" 
load-path))'
 WLDIR =
 WL = -eval '(unless (string= "$(WLDIR)" "") (push "$(WLDIR)" load-path))'

+# notmuch is not part of GNU Emacs.  If you want to use BBDB with WL
+# then the variable NOTMUCHDIR should point to your wl/lisp directory.
+NOTMUCHDIR =
+NOTMUCHDIR = -eval '(unless (string= "$(NOTMUCHDIR)" "") (push "$(NOTMUCHDIR)" 
load-path))'
+
 .SUFFIXES: .elc .el .tar .Z .gz .uu

 SRCS = bbdb.el bbdb-site.el bbdb-com.el bbdb-tex.el bbdb-anniv.el \
@@ -82,10 +87,11 @@ ELC =       bbdb.elc bbdb-site.elc bbdb-com.elc 
bbdb-tex.elc bbdb-anniv.elc \

 all: bbdb

-bbdb:  bbdb-loaddefs.el $(ELC)
-mu4e:  bbdb-mu4e.elc
-vm:    bbdb-vm.elc bbdb-vm-aux.elc
-wl:    bbdb-wl.elc
+bbdb:          bbdb-loaddefs.el $(ELC)
+mu4e:          bbdb-mu4e.elc
+vm:            bbdb-vm.elc bbdb-vm-aux.elc
+wl:            bbdb-wl.elc
+notmuch:       bbdb-notmuch.elc

 bbdb-loaddefs.el: $(SRCS)
 #      2011-12-11: We switched from bbdb-autoloads.el to bbdb-loaddefs.el.
@@ -144,6 +150,8 @@ bbdb-mu4e.elc: bbdb-mu4e.el bbdb-mua.elc
        $(emacs) $(MU4E) --funcall batch-byte-compile $(@:.elc=.el)
 bbdb-wl.elc: bbdb-wl.el bbdb-mua.elc
        $(emacs_compile) $(@:.elc=.el)
+bbdb-notmuch.elc: bbdb-notmuch.el bbdb-mua.elc
+       $(emacs) $(VM) --funcall batch-byte-compile $(@:.elc=.el)
 bbdb-vm.elc: bbdb-vm.el bbdb-mua.elc
        $(emacs) $(VM) --funcall batch-byte-compile $(@:.elc=.el)
 bbdb-vm-aux.elc: bbdb-vm-aux.el bbdb-mua.elc
diff --git a/m4/emacs_notmuch.m4 b/m4/emacs_notmuch.m4
new file mode 100644
index 0000000..605b390
--- /dev/null
+++ b/m4/emacs_notmuch.m4
@@ -0,0 +1,39 @@
+### emacs_vm.m4
+
+## Copyright (C) 2010-2022  Free Software Foundation, Inc.
+##
+## This file is part of the Insidious Big Brother Database (aka BBDB),
+##
+## BBDB is free software: you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation, either version 3 of the License, or
+## (at your option) any later version.
+##
+## BBDB is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with BBDB.  If not, see <http://www.gnu.org/licenses/>.
+
+AC_DEFUN([EMACS_NOTMUCH],
+[
+AC_ARG_WITH([notmuch-dir],
+AS_HELP_STRING([--with-notmuch-dir=DIR], [where to find NOTMUCH lisp 
directory]),
+# if NOTMUCH was requested, make sure we have access to the source
+[if test "x$with_notmuch_dir" != xno -a "x$with_notmuch_dir" != "x"; then
+    AC_MSG_CHECKING([for NOTMUCH files])
+    # convert path to absolute and canonicalize it.
+    NOTMUCHDIR=$(${EMACS} -batch --quick -eval "(message \"%s\" 
(expand-file-name \"${with_notmuch_dir}\"))" 2>&1)
+    NOTMUCH_LOCATE=$(${EMACS} -batch --quick --directory="${NOTMUCHDIR}" -eval 
"(if (locate-library \"notmuch\") (message \"notmuch\"))" 2>&1)
+    if test "x$NOTMUCH_LOCATE" = "x"; then
+       AC_MSG_ERROR([*** NOTMUCH notmuch.el must exist in directory passed to 
--with-notmuch-dir.])
+    fi
+    AC_MSG_RESULT($NOTMUCHDIR)
+    # append NOTMUCHDIR to AM_ELCFLAGS
+    AM_ELCFLAGS="--directory=$NOTMUCHDIR $AM_ELCFLAGS"
+ fi])
+# New conditional NOTMUCH
+AM_CONDITIONAL([NOTMUCH], [test x$NOTMUCHDIR != x])
+])
--
2.37.2



reply via email to

[Prev in Thread] Current Thread [Next in Thread]