Modify kill and exit functions on emacs notmuch mode

classic Classic list List threaded Threaded
6 messages Options
katsuyuki2388 katsuyuki2388
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Modify kill and exit functions on emacs notmuch mode

Hi, I modified kill and exit functions on emacs notmuch mode.
I want to hear your opinion about the change.

_______________________________________________
notmuch mailing list
[hidden email]
https://notmuchmail.org/mailman/listinfo/notmuch
katsuyuki2388 katsuyuki2388
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[PATCH 1/2] emacs: retrun to the previous notmuch buffer when exit

From: Kiso Katsuyuki <[hidden email]>

When kill and exit from a notmuch mode buffer
(notmuch-show-mode, notmuch-tree-mode,
notmuch-search-mode, notmuch-hello-mode, notmuch-message-mode),
return to the previous notmuch mode buffer. It's because
the previous notmuch buffer is often buried and I have to
select it with a buffer-switching command.
---
 emacs/notmuch-draft.el |  6 ++++--
 emacs/notmuch-lib.el   | 17 +++++++++++++++--
 emacs/notmuch-mua.el   |  7 +++++--
 emacs/notmuch-tree.el  |  6 ++++--
 4 files changed, 28 insertions(+), 8 deletions(-)

diff --git a/emacs/notmuch-draft.el b/emacs/notmuch-draft.el
index fb7f4f55..8717f317 100644
--- a/emacs/notmuch-draft.el
+++ b/emacs/notmuch-draft.el
@@ -214,10 +214,12 @@ applied to newly inserted messages)."
     (set-buffer-modified-p nil)))
 
 (defun notmuch-draft-postpone ()
-  "Save the draft message in the notmuch database and exit buffer."
+  "Save the draft message in the notmuch database, exit buffer,
+and select the previous notmuch buffer."
   (interactive)
   (notmuch-draft-save)
-  (kill-buffer))
+  (kill-buffer)
+  (notmuch-select-previous-notmuch-buffer))
 
 (defun notmuch-draft-resume (id)
   "Resume editing of message with id ID."
diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
index 337b20ac..0371c23f 100644
--- a/emacs/notmuch-lib.el
+++ b/emacs/notmuch-lib.el
@@ -260,15 +260,28 @@ depending on the value of `notmuch-poll-script'."
   (error "Notmuch: poll script `%s' failed!" notmuch-poll-script)))
     (notmuch-call-notmuch-process "new")))
 
+(defun notmuch-select-previous-notmuch-buffer ()
+  "Select the previous notmuch buffer."
+  (catch 'get-notmuch-buffer
+    (dolist (buffer (buffer-list))
+      (let ((buffer-mode (buffer-local-value 'major-mode buffer)))
+ (when (memq buffer-mode '(notmuch-show-mode
+  notmuch-tree-mode
+  notmuch-search-mode
+  notmuch-hello-mode
+  notmuch-message-mode))
+  (throw 'get-notmuch-buffer (switch-to-buffer buffer)))))))
+
 (defun notmuch-bury-or-kill-this-buffer ()
   "Undisplay the current buffer.
 
 Bury the current buffer, unless there is only one window showing
-it, in which case it is killed."
+it, in which case it is killed. Then, select the previous notmuch buffer."
   (interactive)
   (if (> (length (get-buffer-window-list nil nil t)) 1)
       (bury-buffer)
-    (kill-buffer)))
+    (kill-buffer))
+  (notmuch-select-previous-notmuch-buffer))
 
 (defun notmuch-documentation-first-line (symbol)
   "Return the first line of the documentation string for SYMBOL."
diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el
index 93747b1c..c1d533f7 100644
--- a/emacs/notmuch-mua.el
+++ b/emacs/notmuch-mua.el
@@ -292,6 +292,7 @@ mutiple parts get a header."
 
 (define-key notmuch-message-mode-map (kbd "C-c C-c") #'notmuch-mua-send-and-exit)
 (define-key notmuch-message-mode-map (kbd "C-c C-s") #'notmuch-mua-send)
+(define-key notmuch-message-mode-map (kbd "C-c C-k") #'notmuch-mua-kill-buffer)
 (define-key notmuch-message-mode-map (kbd "C-c C-p") #'notmuch-draft-postpone)
 (define-key notmuch-message-mode-map (kbd "C-x C-s") #'notmuch-draft-save)
 
@@ -552,7 +553,8 @@ unencrypted.  Really send? "))))
 
 (defun notmuch-mua-send-and-exit (&optional arg)
   (interactive "P")
-  (notmuch-mua-send-common arg 't))
+  (notmuch-mua-send-common arg 't)
+  (notmuch-select-previous-notmuch-buffer))
 
 (defun notmuch-mua-send (&optional arg)
   (interactive "P")
@@ -560,7 +562,8 @@ unencrypted.  Really send? "))))
 
 (defun notmuch-mua-kill-buffer ()
   (interactive)
-  (message-kill-buffer))
+  (message-kill-buffer)
+  (notmuch-select-previous-notmuch-buffer))
 
 (defun notmuch-mua-message-send-hook ()
   "The default function used for `notmuch-mua-send-hook', this
diff --git a/emacs/notmuch-tree.el b/emacs/notmuch-tree.el
index d4d40761..64706397 100644
--- a/emacs/notmuch-tree.el
+++ b/emacs/notmuch-tree.el
@@ -531,10 +531,12 @@ Shows in split pane or whole window according to value of
     (notmuch-tree-next-matching-message)))
 
 (defun notmuch-tree-quit ()
-  "Close the split view or exit tree."
+  "Close the split view or exit tree. When exit from tree, select the
+previous notmuch buffer"
   (interactive)
   (unless (notmuch-tree-close-message-window)
-    (kill-buffer (current-buffer))))
+    (kill-buffer (current-buffer))
+    (notmuch-select-previous-notmuch-buffer)))
 
 (defun notmuch-tree-close-message-window ()
   "Close the message-window. Return t if close succeeds."
--
2.12.2

_______________________________________________
notmuch mailing list
[hidden email]
https://notmuchmail.org/mailman/listinfo/notmuch
katsuyuki2388 katsuyuki2388
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[PATCH 2/2] NEWS: emacs notmuch buffer exit functions are modified

In reply to this post by katsuyuki2388
From: Kiso Katsuyuki <[hidden email]>

---
 NEWS | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/NEWS b/NEWS
index 70bce788..af9d5fb8 100644
--- a/NEWS
+++ b/NEWS
@@ -11,6 +11,14 @@ Emacs
 
 Fix filename stashing in tree view.
 
+Return to the previous notmuch buffer when kill and exit from a notmuch buffer
+
+  When kill and exit from a notmuch buffer (notmuch-hello-mode,
+  notmuch-search-mode, notmuch-show-mode, notmuch-tree-mode,
+  notmuch-message-mode), the previous notmuch buffer is often buried.
+  So kill and exit functions are modified to return to the previous
+  notmuch buffer.
+
 Notmuch 0.24.1 (2017-04-01)
 ===========================
 
--
2.12.2

_______________________________________________
notmuch mailing list
[hidden email]
https://notmuchmail.org/mailman/listinfo/notmuch
Tomi Ollila-2 Tomi Ollila-2
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Modify kill and exit functions on emacs notmuch mode

In reply to this post by katsuyuki2388
On Sat, Jun 03 2017, katsuyuki wrote:

> Hi, I modified kill and exit functions on emacs notmuch mode.
> I want to hear your opinion about the change.


Some years ago I had a problem notmuch choosing "strange" buffer when
exiting e.g. mail buffer (and I sent a patch to "fix" that). Eventually
the problem was in my own elisp configurations and after I fixed that
I've had no problems what buffer emacs choose when closing notmuch
buffers. That doesn't mean that there could still be something to
improve there...

... but as someone(tm) may know, everyone have their own workflow
( https://xkcd.com/1172/ ) in their notmuch usage -- someone may
e.g. start writing email based on arbitrary C code buffer, and
after email send, return to that buffer instead of going to some
other notmuch buffer.

An alternative to this series would be adding a buffer selection
hook variable which anyone can set to bre^H^H^H^improve their
usage.

Tomi

_______________________________________________
notmuch mailing list
[hidden email]
https://notmuchmail.org/mailman/listinfo/notmuch
David Bremner-2 David Bremner-2
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Modify kill and exit functions on emacs notmuch mode

Tomi Ollila <[hidden email]> writes:

>
> ... but as someone(tm) may know, everyone have their own workflow
> ( https://xkcd.com/1172/ ) in their notmuch usage -- someone may
> e.g. start writing email based on arbitrary C code buffer, and
> after email send, return to that buffer instead of going to some
> other notmuch buffer.
>

Yeah, that was my first thought on seeing this series; that's actually a
pretty typical workflow for me. But I haven't had a chance to test the
series out yet.

d
_______________________________________________
notmuch mailing list
[hidden email]
https://notmuchmail.org/mailman/listinfo/notmuch
katsuyuki2388 katsuyuki2388
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Modify kill and exit functions on emacs notmuch mode

In reply to this post by Tomi Ollila-2

> ... but as someone(tm) may know, everyone have their own workflow
> ( https://xkcd.com/1172/ ) in their notmuch usage -- someone may
> e.g. start writing email based on arbitrary C code buffer, and
> after email send, return to that buffer instead of going to some
> other notmuch buffer.

I see. Many people may not feel unusefulness, as you said, and
I misunderstood that the selection priority of asterisk buffers like
"*notmuch-hello*" are lower than file buffers.
The problem seems to be my environmental problem because
there are no difference of priority between asterisk buffers and
file ones by default ('emacs -q').

> An alternative to this series would be adding a buffer selection
> hook variable which anyone can set to bre^H^H^H^improve their
> usage.

I appreciate your advice, but I am satisfied with this change and
will keep this change local now.

Warm Regards,
Kiso

--
-----------------------------------------------------------
木曽 勝之 (Katsuyuki Kiso)

mail: [hidden email]
-----------------------------------------------------------
_______________________________________________
notmuch mailing list
[hidden email]
https://notmuchmail.org/mailman/listinfo/notmuch
Loading...