[UGLY DFAFT PATCH] draft: emacs: custom variable to choose default reply-to behaviour

Tomi Ollila tomi.ollila at iki.fi
Fri Jun 29 12:05:53 PDT 2012


This is one draft solution to provide an implementation described in
id:"87y5n7z5aj.fsf at yoom.home.cworth.org"

Comments how things could be done better (or totally different way)
are welcome -- and specially, if you are better than me in elisp
(which you probably are) reuse any code freely in your implementation...

There are some things missing (like declare-functions (and specially, one
`custom-set`) and new code is not necessarily located at the most suitable
places -- for now the changes are "localized" to 2 places.

This implementation uses custom variable and based on that the 4 keybindings
are set -- if custom variable is nil then bindings point to the setting
interface functions. Currenlty after later changes outside of those setting
functions does not change bindings -- in the future using
customize-save-variable that will change bindings -- but always when using
setq/set to change the (custom) variable will not change the bindings (so
the variable can be made out-of-sync with the bindings -- if that matters).
---
 emacs/notmuch-show.el |   58 +++++++++++++++++++++++++++++++++++++++++++++++-
 emacs/notmuch.el      |   23 +++++++++++++++++-
 2 files changed, 77 insertions(+), 4 deletions(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 4349836..10eb75d 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -1134,6 +1134,61 @@ reset based on the original query."
   "Submap for stash commands")
 (fset 'notmuch-show-stash-map notmuch-show-stash-map)
 
+;;; draft code ;;;
+(defcustom notmuch-reply-to-default nil
+  "Doc string (i.e. not documented yet)"
+  :type '(choice (const :tag "reply to all" 'all)
+		 (const :tag "reply to sender" 'sender))
+  ;;:custom-set 'set-default-and-keybinding
+  :group 'notmuch-send)
+
+(defun notmuch-choose-reply-keybindings ()
+  (interactive)
+  (defun ia () (interactive) (insert "a") (exit-minibuffer))
+  (defun is () (interactive) (insert "s") (exit-minibuffer))
+  (defun iA () (interactive) (insert "A") (exit-minibuffer))
+  (defun iS () (interactive) (insert "S") (exit-minibuffer))
+  (let ((map (make-keymap)))
+    (suppress-keymap map t)
+    ;;(define-key map "?" 'helep)
+    (define-key map "a" 'ia)
+    (define-key map "s" 'is)
+    (define-key map "A" 'iA)
+    (define-key map "S" 'iS)
+    (save-excursion
+      (let ((val (read-from-minibuffer
+		  "Reply to all or sender only? [asAS?]:" nil map)))
+	(cond ((string= val "a") t)
+	      ((string= val "s") nil)
+	      ((string= val "A")
+	       (customize-save-variable 'notmuch-reply-to-default 'all)
+	       (notmuch-show-set-reply-keybindings) ;; not needed when ...
+	       (notmuch-search-set-reply-keybindings) t) ;; custom-set in use.
+	      ((string= val "S")
+	       (customize-save-variable 'notmuch-reply-to-default 'sender)
+	       (notmuch-show-set-reply-keybindings) ;; not needed when ...
+	       (notmuch-search-set-reply-keybindings) nil) ;; custom-set in use
+	      )))))
+
+(defun notmuch-show-choose-reply-keybindings ()
+  (interactive)
+  (if (notmuch-choose-reply-keybindings)
+      (notmuch-show-reply)
+    (notmuch-show-reply-sender)))
+
+(defun notmuch-show-set-reply-keybindings (&optional map)
+  (unless map
+    (set 'map notmuch-show-mode-map))
+  (cond ((eq notmuch-reply-to-default 'all)
+	 (define-key map "r" 'notmuch-show-reply)
+	 (define-key map "R" 'notmuch-show-reply-sender))
+	((eq notmuch-reply-to-default 'sender)
+	 (define-key map "r" 'notmuch-show-reply-sender)
+	 (define-key map "R" 'notmuch-show-reply))
+	(t
+	 (define-key map "r" 'notmuch-show-choose-reply-keybindings)
+	 (define-key map "R" 'notmuch-show-choose-reply-keybindings))))
+
 (defvar notmuch-show-mode-map
       (let ((map (make-sparse-keymap)))
 	(define-key map "?" 'notmuch-help)
@@ -1145,8 +1200,6 @@ reset based on the original query."
 	(define-key map "s" 'notmuch-search)
 	(define-key map "m" 'notmuch-mua-new-mail)
 	(define-key map "f" 'notmuch-show-forward-message)
-	(define-key map "r" 'notmuch-show-reply-sender)
-	(define-key map "R" 'notmuch-show-reply)
 	(define-key map "|" 'notmuch-show-pipe-message)
 	(define-key map "w" 'notmuch-show-save-attachments)
 	(define-key map "V" 'notmuch-show-view-raw-message)
@@ -1174,6 +1227,7 @@ reset based on the original query."
 	(define-key map "$" 'notmuch-show-toggle-process-crypto)
 	(define-key map "<" 'notmuch-show-toggle-thread-indentation)
 	(define-key map "t" 'toggle-truncate-lines)
+	(notmuch-show-set-reply-keybindings map)
 	map)
       "Keymap for \"notmuch show\" buffers.")
 (fset 'notmuch-show-mode-map notmuch-show-mode-map)
diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index c6236db..a95e191 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -203,6 +203,26 @@ For a mouse binding, return nil."
   :group 'notmuch-search
   :group 'notmuch-hooks)
 
+;;; draft code ;;;
+(defun notmuch-search-choose-reply-keybindings ()
+  (interactive)
+  (if (notmuch-choose-reply-keybindings)
+      (notmuch-search-reply-to-thread)
+    (notmuch-search-reply-to-thread-sender)))
+
+(defun notmuch-search-set-reply-keybindings (&optional map)
+  (unless map
+    (set 'map notmuch-search-mode-map))
+  (cond ((eq notmuch-reply-to-default 'all)
+	 (define-key map "r" 'notmuch-search-reply-to-thread)
+	 (define-key map "R" 'notmuch-search-reply-to-thread-sender))
+	((eq notmuch-reply-to-default 'sender)
+	 (define-key map "r" 'notmuch-search-reply-to-thread-sender)
+	 (define-key map "R" 'notmuch-search-reply-to-thread))
+	(t
+	 (define-key map "r" 'notmuch-search-choose-reply-keybindings)
+	 (define-key map "R" 'notmuch-search-choose-reply-keybindings))))
+
 (defvar notmuch-search-mode-map
   (let ((map (make-sparse-keymap)))
     (define-key map "?" 'notmuch-help)
@@ -215,8 +235,6 @@ For a mouse binding, return nil."
     (define-key map ">" 'notmuch-search-last-thread)
     (define-key map "p" 'notmuch-search-previous-thread)
     (define-key map "n" 'notmuch-search-next-thread)
-    (define-key map "r" 'notmuch-search-reply-to-thread-sender)
-    (define-key map "R" 'notmuch-search-reply-to-thread)
     (define-key map "m" 'notmuch-mua-new-mail)
     (define-key map "s" 'notmuch-search)
     (define-key map "o" 'notmuch-search-toggle-order)
@@ -231,6 +249,7 @@ For a mouse binding, return nil."
     (define-key map "-" 'notmuch-search-remove-tag)
     (define-key map "+" 'notmuch-search-add-tag)
     (define-key map (kbd "RET") 'notmuch-search-show-thread)
+    (notmuch-search-set-reply-keybindings map)
     map)
   "Keymap for \"notmuch search\" buffers.")
 (fset 'notmuch-search-mode-map notmuch-search-mode-map)
-- 
1.7.1



More information about the notmuch mailing list