unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH] emacs: use define-derived-mode for defining modes.
@ 2016-08-28 18:41 Steven Allen
  2016-09-01 14:57 ` Tomi Ollila
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Steven Allen @ 2016-08-28 18:41 UTC (permalink / raw)
  To: notmuch

This sets up and runs all the correct hooks and reduces some redundancy.
---
 emacs/notmuch-hello.el | 8 +-------
 emacs/notmuch-show.el  | 7 +------
 emacs/notmuch-tree.el  | 7 +------
 emacs/notmuch.el       | 7 +------
 4 files changed, 4 insertions(+), 25 deletions(-)

diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el
index 75ccf57..d582bff 100644
--- a/emacs/notmuch-hello.el
+++ b/emacs/notmuch-hello.el
@@ -671,7 +671,7 @@ with `notmuch-hello-query-counts'."
   "Keymap for \"notmuch hello\" buffers.")
 (fset 'notmuch-hello-mode-map notmuch-hello-mode-map)
 
-(defun notmuch-hello-mode ()
+(define-derived-mode notmuch-hello-mode fundamental-mode "notmuch-hello"
  "Major mode for convenient notmuch navigation. This is your entry portal into notmuch.
 
 Saved searches are \"bookmarks\" for arbitrary queries. Hit RET
@@ -702,13 +702,7 @@ The screen may be customized via `\\[customize]'.
 Complete list of currently available key bindings:
 
 \\{notmuch-hello-mode-map}"
- (interactive)
- (kill-all-local-variables)
  (setq notmuch-buffer-refresh-function #'notmuch-hello-update)
- (use-local-map notmuch-hello-mode-map)
- (setq major-mode 'notmuch-hello-mode
-	mode-name "notmuch-hello")
- (run-mode-hooks 'notmuch-hello-mode-hook)
  ;;(setq buffer-read-only t)
 )
 
diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 6d3149b..eb6877e 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -1454,7 +1454,7 @@ reset based on the original query."
   "Keymap for \"notmuch show\" buffers.")
 (fset 'notmuch-show-mode-map notmuch-show-mode-map)
 
-(defun notmuch-show-mode ()
+(define-derived-mode notmuch-show-mode fundamental-mode "notmuch-show"
   "Major mode for viewing a thread with notmuch.
 
 This buffer contains the results of the \"notmuch show\" command
@@ -1482,12 +1482,7 @@ You can add or remove arbitrary tags from the current message with
 All currently available key bindings:
 
 \\{notmuch-show-mode-map}"
-  (interactive)
-  (kill-all-local-variables)
   (setq notmuch-buffer-refresh-function #'notmuch-show-refresh-view)
-  (use-local-map notmuch-show-mode-map)
-  (setq major-mode 'notmuch-show-mode
-	mode-name "notmuch-show")
   (setq buffer-read-only t
 	truncate-lines t))
 
diff --git a/emacs/notmuch-tree.el b/emacs/notmuch-tree.el
index 5231319..d864e6d 100644
--- a/emacs/notmuch-tree.el
+++ b/emacs/notmuch-tree.el
@@ -803,7 +803,7 @@ This function inserts a collection of several complete threads as
 passed to it by notmuch-tree-process-filter."
   (mapc 'notmuch-tree-insert-forest-thread forest))
 
-(defun notmuch-tree-mode ()
+(define-derived-mode notmuch-tree-mode fundamental-mode "notmuch-tree"
   "Major mode displaying messages (as opposed to threads) of of a notmuch search.
 
 This buffer contains the results of a \"notmuch tree\" of your
@@ -817,12 +817,7 @@ Complete list of currently available key bindings:
 
 \\{notmuch-tree-mode-map}"
 
-  (interactive)
-  (kill-all-local-variables)
   (setq notmuch-buffer-refresh-function #'notmuch-tree-refresh-view)
-  (use-local-map notmuch-tree-mode-map)
-  (setq major-mode 'notmuch-tree-mode
-	mode-name "notmuch-tree")
   (hl-line-mode 1)
   (setq buffer-read-only t
 	truncate-lines t))
diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index 43d56f7..ecf7198 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -331,7 +331,7 @@ This face is the default value for the \"unread\" tag in
   :group 'notmuch-search
   :group 'notmuch-faces)
 
-(defun notmuch-search-mode ()
+(define-derived-mode notmuch-search-mode fundamental-mode "notmuch-search"
   "Major mode displaying results of a notmuch search.
 
 This buffer contains the results of a \"notmuch search\" of your
@@ -361,8 +361,6 @@ new, global search.
 Complete list of currently available key bindings:
 
 \\{notmuch-search-mode-map}"
-  (interactive)
-  (kill-all-local-variables)
   (make-local-variable 'notmuch-search-query-string)
   (make-local-variable 'notmuch-search-oldest-first)
   (make-local-variable 'notmuch-search-target-thread)
@@ -370,10 +368,7 @@ Complete list of currently available key bindings:
   (setq notmuch-buffer-refresh-function #'notmuch-search-refresh-view)
   (set (make-local-variable 'scroll-preserve-screen-position) t)
   (add-to-invisibility-spec (cons 'ellipsis t))
-  (use-local-map notmuch-search-mode-map)
   (setq truncate-lines t)
-  (setq major-mode 'notmuch-search-mode
-	mode-name "notmuch-search")
   (setq buffer-read-only t))
 
 (defun notmuch-search-get-result (&optional pos)
-- 
2.9.3

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] emacs: use define-derived-mode for defining modes.
  2016-08-28 18:41 [PATCH] emacs: use define-derived-mode for defining modes Steven Allen
@ 2016-09-01 14:57 ` Tomi Ollila
  2016-09-10  0:38 ` David Bremner
  2016-09-10 16:10 ` David Bremner
  2 siblings, 0 replies; 7+ messages in thread
From: Tomi Ollila @ 2016-09-01 14:57 UTC (permalink / raw)
  To: Steven Allen, notmuch

On Sun, Aug 28 2016, Steven Allen <steven@stebalien.com> wrote:

> This sets up and runs all the correct hooks and reduces some redundancy.

I don't why this would work or not, but I put this into my build
configuration so let's see...

Tomi

> ---
>  emacs/notmuch-hello.el | 8 +-------
>  emacs/notmuch-show.el  | 7 +------
>  emacs/notmuch-tree.el  | 7 +------
>  emacs/notmuch.el       | 7 +------
>  4 files changed, 4 insertions(+), 25 deletions(-)
>
> diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el
> index 75ccf57..d582bff 100644
> --- a/emacs/notmuch-hello.el
> +++ b/emacs/notmuch-hello.el
> @@ -671,7 +671,7 @@ with `notmuch-hello-query-counts'."
>    "Keymap for \"notmuch hello\" buffers.")
>  (fset 'notmuch-hello-mode-map notmuch-hello-mode-map)
>  
> -(defun notmuch-hello-mode ()
> +(define-derived-mode notmuch-hello-mode fundamental-mode "notmuch-hello"
>   "Major mode for convenient notmuch navigation. This is your entry portal into notmuch.
>  
>  Saved searches are \"bookmarks\" for arbitrary queries. Hit RET
> @@ -702,13 +702,7 @@ The screen may be customized via `\\[customize]'.
>  Complete list of currently available key bindings:
>  
>  \\{notmuch-hello-mode-map}"
> - (interactive)
> - (kill-all-local-variables)
>   (setq notmuch-buffer-refresh-function #'notmuch-hello-update)
> - (use-local-map notmuch-hello-mode-map)
> - (setq major-mode 'notmuch-hello-mode
> -	mode-name "notmuch-hello")
> - (run-mode-hooks 'notmuch-hello-mode-hook)
>   ;;(setq buffer-read-only t)
>  )
>  
> diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
> index 6d3149b..eb6877e 100644
> --- a/emacs/notmuch-show.el
> +++ b/emacs/notmuch-show.el
> @@ -1454,7 +1454,7 @@ reset based on the original query."
>    "Keymap for \"notmuch show\" buffers.")
>  (fset 'notmuch-show-mode-map notmuch-show-mode-map)
>  
> -(defun notmuch-show-mode ()
> +(define-derived-mode notmuch-show-mode fundamental-mode "notmuch-show"
>    "Major mode for viewing a thread with notmuch.
>  
>  This buffer contains the results of the \"notmuch show\" command
> @@ -1482,12 +1482,7 @@ You can add or remove arbitrary tags from the current message with
>  All currently available key bindings:
>  
>  \\{notmuch-show-mode-map}"
> -  (interactive)
> -  (kill-all-local-variables)
>    (setq notmuch-buffer-refresh-function #'notmuch-show-refresh-view)
> -  (use-local-map notmuch-show-mode-map)
> -  (setq major-mode 'notmuch-show-mode
> -	mode-name "notmuch-show")
>    (setq buffer-read-only t
>  	truncate-lines t))
>  
> diff --git a/emacs/notmuch-tree.el b/emacs/notmuch-tree.el
> index 5231319..d864e6d 100644
> --- a/emacs/notmuch-tree.el
> +++ b/emacs/notmuch-tree.el
> @@ -803,7 +803,7 @@ This function inserts a collection of several complete threads as
>  passed to it by notmuch-tree-process-filter."
>    (mapc 'notmuch-tree-insert-forest-thread forest))
>  
> -(defun notmuch-tree-mode ()
> +(define-derived-mode notmuch-tree-mode fundamental-mode "notmuch-tree"
>    "Major mode displaying messages (as opposed to threads) of of a notmuch search.
>  
>  This buffer contains the results of a \"notmuch tree\" of your
> @@ -817,12 +817,7 @@ Complete list of currently available key bindings:
>  
>  \\{notmuch-tree-mode-map}"
>  
> -  (interactive)
> -  (kill-all-local-variables)
>    (setq notmuch-buffer-refresh-function #'notmuch-tree-refresh-view)
> -  (use-local-map notmuch-tree-mode-map)
> -  (setq major-mode 'notmuch-tree-mode
> -	mode-name "notmuch-tree")
>    (hl-line-mode 1)
>    (setq buffer-read-only t
>  	truncate-lines t))
> diff --git a/emacs/notmuch.el b/emacs/notmuch.el
> index 43d56f7..ecf7198 100644
> --- a/emacs/notmuch.el
> +++ b/emacs/notmuch.el
> @@ -331,7 +331,7 @@ This face is the default value for the \"unread\" tag in
>    :group 'notmuch-search
>    :group 'notmuch-faces)
>  
> -(defun notmuch-search-mode ()
> +(define-derived-mode notmuch-search-mode fundamental-mode "notmuch-search"
>    "Major mode displaying results of a notmuch search.
>  
>  This buffer contains the results of a \"notmuch search\" of your
> @@ -361,8 +361,6 @@ new, global search.
>  Complete list of currently available key bindings:
>  
>  \\{notmuch-search-mode-map}"
> -  (interactive)
> -  (kill-all-local-variables)
>    (make-local-variable 'notmuch-search-query-string)
>    (make-local-variable 'notmuch-search-oldest-first)
>    (make-local-variable 'notmuch-search-target-thread)
> @@ -370,10 +368,7 @@ Complete list of currently available key bindings:
>    (setq notmuch-buffer-refresh-function #'notmuch-search-refresh-view)
>    (set (make-local-variable 'scroll-preserve-screen-position) t)
>    (add-to-invisibility-spec (cons 'ellipsis t))
> -  (use-local-map notmuch-search-mode-map)
>    (setq truncate-lines t)
> -  (setq major-mode 'notmuch-search-mode
> -	mode-name "notmuch-search")
>    (setq buffer-read-only t))
>  
>  (defun notmuch-search-get-result (&optional pos)
> -- 
> 2.9.3
>
> _______________________________________________
> notmuch mailing list
> notmuch@notmuchmail.org
> https://notmuchmail.org/mailman/listinfo/notmuch

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] emacs: use define-derived-mode for defining modes.
  2016-08-28 18:41 [PATCH] emacs: use define-derived-mode for defining modes Steven Allen
  2016-09-01 14:57 ` Tomi Ollila
@ 2016-09-10  0:38 ` David Bremner
  2016-09-10  1:31   ` Steven Allen
  2016-09-10 16:10 ` David Bremner
  2 siblings, 1 reply; 7+ messages in thread
From: David Bremner @ 2016-09-10  0:38 UTC (permalink / raw)
  To: Steven Allen, notmuch

Steven Allen <steven@stebalien.com> writes:

> This sets up and runs all the correct hooks and reduces some redundancy.
> ---
>  emacs/notmuch-hello.el | 8 +-------
>  emacs/notmuch-show.el  | 7 +------
>  emacs/notmuch-tree.el  | 7 +------
>  emacs/notmuch.el       | 7 +------
>  4 files changed, 4 insertions(+), 25 deletions(-)
>
> diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el
> index 75ccf57..d582bff 100644
> --- a/emacs/notmuch-hello.el
> +++ b/emacs/notmuch-hello.el
> @@ -671,7 +671,7 @@ with `notmuch-hello-query-counts'."
>    "Keymap for \"notmuch hello\" buffers.")
>  (fset 'notmuch-hello-mode-map notmuch-hello-mode-map)
>  
> -(defun notmuch-hello-mode ()
> +(define-derived-mode notmuch-hello-mode fundamental-mode "notmuch-hello"
>   "Major mode for convenient notmuch navigation. This is your entry portal into notmuch.

The idea seems sane, but shouldn't we derive from special-mode?

d

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] emacs: use define-derived-mode for defining modes.
  2016-09-10  0:38 ` David Bremner
@ 2016-09-10  1:31   ` Steven Allen
  2016-09-10  8:08     ` Tomi Ollila
  0 siblings, 1 reply; 7+ messages in thread
From: Steven Allen @ 2016-09-10  1:31 UTC (permalink / raw)
  To: David Bremner, notmuch

[-- Attachment #1: Type: text/plain, Size: 483 bytes --]


David Bremner <david@tethera.net> writes:
> Steven Allen <steven@stebalien.com> writes:
>
>> This sets up and runs all the correct hooks and reduces some redundancy.
>> ---
>
> The idea seems sane, but shouldn't we derive from special-mode?

Special mode pre-defines some keybindings (although they appear to be
similar, I haven't really looked into it). For precedent, gnus derives
From fundamental-mode.

-- 
Steven Allen
((Do Not Email <honeypot@stebalien.com>))

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 800 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] emacs: use define-derived-mode for defining modes.
  2016-09-10  1:31   ` Steven Allen
@ 2016-09-10  8:08     ` Tomi Ollila
  0 siblings, 0 replies; 7+ messages in thread
From: Tomi Ollila @ 2016-09-10  8:08 UTC (permalink / raw)
  To: Steven Allen, David Bremner, notmuch

On Sat, Sep 10 2016, Steven Allen <steven@stebalien.com> wrote:

> [ Unknown signature status ]
>
> David Bremner <david@tethera.net> writes:
>> Steven Allen <steven@stebalien.com> writes:
>>
>>> This sets up and runs all the correct hooks and reduces some redundancy.
>>> ---
>>
>> The idea seems sane, but shouldn't we derive from special-mode?
>
> Special mode pre-defines some keybindings (although they appear to be
> similar, I haven't really looked into it). For precedent, gnus derives
> From fundamental-mode.

I patched the patch and changed fundamental-mode to special-mode --
read-only hello buffer prevented me to write custom search
(M-x toggle-read-only helped there)

I grepped emacs 24.5 sources derived-mo.*special-mo,
derived-mo.*fundamental-mo and derived-mo.*nil and line counts
were 48, 54 and 28, respectively.

all gnus modes (that use define-derived-mode) derive from fundamental
mode -- but perhaps gnus precedes special-mode (or not, it may be that
special mode were there before big bang (like all other stuff not created
by humans), who knows ;)

Anyway, I think it is safer choice to use fundamental-mode (don't know
about nil) than special-mode -- as there are so many corners in manual
testing that would need to be covered...

Tests passed using the original patch.

Tomi


>
> -- 
> Steven Allen
> ((Do Not Email <honeypot@stebalien.com>))
> _______________________________________________
> notmuch mailing list
> notmuch@notmuchmail.org
> https://notmuchmail.org/mailman/listinfo/notmuch

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] emacs: use define-derived-mode for defining modes.
  2016-08-28 18:41 [PATCH] emacs: use define-derived-mode for defining modes Steven Allen
  2016-09-01 14:57 ` Tomi Ollila
  2016-09-10  0:38 ` David Bremner
@ 2016-09-10 16:10 ` David Bremner
  2016-09-10 16:19   ` Steven Allen
  2 siblings, 1 reply; 7+ messages in thread
From: David Bremner @ 2016-09-10 16:10 UTC (permalink / raw)
  To: Steven Allen, notmuch

Steven Allen <steven@stebalien.com> writes:

> This sets up and runs all the correct hooks and reduces some redundancy.

pushed to master

d

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] emacs: use define-derived-mode for defining modes.
  2016-09-10 16:10 ` David Bremner
@ 2016-09-10 16:19   ` Steven Allen
  0 siblings, 0 replies; 7+ messages in thread
From: Steven Allen @ 2016-09-10 16:19 UTC (permalink / raw)
  To: David Bremner, notmuch

[-- Attachment #1: Type: text/plain, Size: 270 bytes --]


David Bremner <david@tethera.net> writes:
> Steven Allen <steven@stebalien.com> writes:
>
>> This sets up and runs all the correct hooks and reduces some redundancy.
>
> pushed to master

Thanks!

-- 
Steven Allen
((Do Not Email <honeypot@stebalien.com>))

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 800 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2016-09-10 16:19 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-28 18:41 [PATCH] emacs: use define-derived-mode for defining modes Steven Allen
2016-09-01 14:57 ` Tomi Ollila
2016-09-10  0:38 ` David Bremner
2016-09-10  1:31   ` Steven Allen
2016-09-10  8:08     ` Tomi Ollila
2016-09-10 16:10 ` David Bremner
2016-09-10 16:19   ` Steven Allen

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).