unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Tomi Ollila <tomi.ollila@iki.fi>
To: notmuch@notmuchmail.org
Cc: Tomi Ollila <tomi.ollila@iki.fi>
Subject: [UGLY DFAFT PATCH] draft: emacs: custom variable to choose default reply-to behaviour
Date: Fri, 29 Jun 2012 22:05:53 +0300	[thread overview]
Message-ID: <1340996753-30258-1-git-send-email-tomi.ollila@iki.fi> (raw)
In-Reply-To: <87y5n7z5aj.fsf@yoom.home.cworth.org>

This is one draft solution to provide an implementation described in
id:"87y5n7z5aj.fsf@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

      reply	other threads:[~2012-06-29 19:05 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-27 16:46 [PATCH] Restore original keybinding ('r' = reply-to-all) Carl Worth
2012-06-27 17:55 ` Jameson Graef Rollins
2012-06-27 18:32   ` Daniel Schoepe
2012-06-28  0:06   ` David Bremner
2012-06-28  7:02     ` Mark Walters
2012-06-28 16:16       ` Jameson Graef Rollins
2012-06-28  8:28     ` Jani Nikula
2012-06-28 15:24     ` Jesse Rosenthal
2012-06-28 16:05       ` Philip Hands
2012-06-28 16:21         ` Jameson Graef Rollins
2012-06-28 17:01           ` Thomas Jost
2012-06-28 17:59         ` Carl Worth
2012-06-29 19:05           ` Tomi Ollila [this message]

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=1340996753-30258-1-git-send-email-tomi.ollila@iki.fi \
    --to=tomi.ollila@iki.fi \
    --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).