Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id B34B1431FCB for ; Fri, 29 Jun 2012 12:05:47 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id a2liDA+L8Scg for ; Fri, 29 Jun 2012 12:05:46 -0700 (PDT) Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34]) by olra.theworths.org (Postfix) with ESMTP id 1E314431FAF for ; Fri, 29 Jun 2012 12:05:46 -0700 (PDT) Received: by guru.guru-group.fi (Postfix, from userid 501) id 6D3DB1002A4; Fri, 29 Jun 2012 22:05:55 +0300 (EEST) From: Tomi Ollila To: notmuch@notmuchmail.org Subject: [UGLY DFAFT PATCH] draft: emacs: custom variable to choose default reply-to behaviour Date: Fri, 29 Jun 2012 22:05:53 +0300 Message-Id: <1340996753-30258-1-git-send-email-tomi.ollila@iki.fi> X-Mailer: git-send-email 1.7.1 In-Reply-To: <87y5n7z5aj.fsf@yoom.home.cworth.org> References: <87y5n7z5aj.fsf@yoom.home.cworth.org> Cc: Tomi Ollila X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 29 Jun 2012 19:05:47 -0000 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