* bug#33263: 27.0.50; Tidying up Gnus modes
@ 2018-11-05 2:53 Eric Abrahamsen
2018-11-05 14:14 ` Noam Postavsky
` (2 more replies)
0 siblings, 3 replies; 11+ messages in thread
From: Eric Abrahamsen @ 2018-11-05 2:53 UTC (permalink / raw)
To: 33263
[-- Attachment #1: Type: text/plain, Size: 940 bytes --]
The attached patch does a couple of things to clean up Gnus's various
major modes:
- Creates a do-nothing `gnus-mode', derived from `special-mode', to
serve as parent mode for all the other major modes. This isn't so
important, but sometimes it would be nice to do (derived-mode-p
'gnus-mode).
- Derives everything from `gnus-mode', and turns a couple of modes from
functions that manually set up modes into proper calls to
`define-derived-mode'.
- Removes code like "(setq buffer-read-only t)", as that's automatically
done by `special-mode'.
- Where appropriate, deletes custom definitions for gnus-*-mode-hook, as
these hooks are already automatically created by the define-mode
calls. (Maybe this removal isn't worth doing?)
This patch probably needs more testing, but I'm floating it first for
any comments.
Eric
In GNU Emacs 27.0.50 (build 2, x86_64-pc-linux-gnu, GTK+ Version 3.24.1)
of 2018-10-31 built on slip
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Provide-new-gnus-mode-derive-all-gnus-major-modes-fr.patch --]
[-- Type: text/x-patch, Size: 14401 bytes --]
From 395babb983e466d21928433c18faddedf3d88e8f Mon Sep 17 00:00:00 2001
From: Eric Abrahamsen <eric@ericabrahamsen.net>
Date: Mon, 25 Jun 2018 17:40:19 -0700
Subject: [PATCH] Provide new gnus-mode, derive all gnus major modes from this
* lisp/gnus/gnus.el (gnus-mode): New do-nothing major mode, derived
from special mode.
* lisp/gnus/gnus-sum.el (gnus-summary-mode): Change from a function to
a major mode, derive from gnus-mode.
(gnus-summary-setup-buffer): Change call a bit -- can no longer pass
an argument to the mode function.
* lisp/gnus/gnus-srvr.el (gnus-browse-mode): Derive from gnus-mode.
(gnus-server-setup-buffer): Remove unnecessary function.
(gnus-enter-server-buffer): Call gnus-server-mode here, and call it
whether the server buffer already existed or not.
(gnus-server-mode): Change from a function to a major mode.
(gnus-server-mode-hook): Delete custom option, this is automatically
created.
* lisp/gnus/gnus-salt.el (gnus-tree-mode): Derive from gnus-mode.
(gnus-tree-mode-hook): Delete custom option, this is automatically
created.
* lisp/gnus/gnus-kill.el (gnus-kill-file-mode-hook): Delete custom
option.
* lisp/gnus/gnus-group.el (gnus-group-mode):
* lisp/gnus/gnus-art.el (gnus-article-mode):
* lisp/gnus/gnus-agent.el (gnus-category-mode): Derive from gnus-mode.
(gnus-category-mode-hook): Delete custom option.
---
lisp/gnus/gnus-agent.el | 10 ++-------
lisp/gnus/gnus-art.el | 8 ++-----
lisp/gnus/gnus-group.el | 8 ++-----
lisp/gnus/gnus-kill.el | 5 -----
lisp/gnus/gnus-salt.el | 9 +-------
lisp/gnus/gnus-srvr.el | 46 +++++++++--------------------------------
lisp/gnus/gnus-sum.el | 20 ++++--------------
lisp/gnus/gnus.el | 6 ++++++
8 files changed, 27 insertions(+), 85 deletions(-)
diff --git a/lisp/gnus/gnus-agent.el b/lisp/gnus/gnus-agent.el
index 18e6174fa0..93a675584f 100644
--- a/lisp/gnus/gnus-agent.el
+++ b/lisp/gnus/gnus-agent.el
@@ -2575,9 +2575,6 @@ gnus-agent-fetch-group-1
;;; Agent Category Mode
;;;
-(defvar gnus-category-mode-hook nil
- "Hook run in `gnus-category-mode' buffers.")
-
(defvar gnus-category-line-format " %(%20c%): %g\n"
"Format of category lines.
@@ -2613,7 +2610,6 @@ gnus-category-line-format-spec
(defvar gnus-category-mode-line-format-spec nil)
(defvar gnus-category-mode-map nil)
-(put 'gnus-category-mode 'mode-class 'special)
(unless gnus-category-mode-map
(setq gnus-category-mode-map (make-sparse-keymap))
@@ -2655,9 +2651,8 @@ gnus-category-make-menu-bar
(gnus-run-hooks 'gnus-category-menu-hook)))
-(define-derived-mode gnus-category-mode fundamental-mode "Category"
+(define-derived-mode gnus-category-mode gnus-mode "Category"
"Major mode for listing and editing agent categories.
-
All normal editing commands are switched off.
\\<gnus-category-mode-map>
For more in-depth information on this mode, read the manual
@@ -2672,8 +2667,7 @@ gnus-category-mode
(gnus-set-default-directory)
(setq mode-line-process nil)
(buffer-disable-undo)
- (setq truncate-lines t)
- (setq buffer-read-only t))
+ (setq truncate-lines t))
(defalias 'gnus-category-position-point 'gnus-goto-colon)
diff --git a/lisp/gnus/gnus-art.el b/lisp/gnus/gnus-art.el
index f28e6db3c7..c78bb3325f 100644
--- a/lisp/gnus/gnus-art.el
+++ b/lisp/gnus/gnus-art.el
@@ -4388,8 +4388,6 @@ article-verify-cancel-lock
;;; Gnus article mode
;;;
-(put 'gnus-article-mode 'mode-class 'special)
-
(set-keymap-parent gnus-article-mode-map widget-keymap)
(gnus-define-keys gnus-article-mode-map
@@ -4467,9 +4465,8 @@ gnus-article-make-menu-bar
(defvar bookmark-make-record-function)
(defvar shr-put-image-function)
-(define-derived-mode gnus-article-mode fundamental-mode "Article"
+(define-derived-mode gnus-article-mode gnus-mode "Article"
"Major mode for displaying an article.
-
All normal editing commands are switched off.
The following commands are available in addition to all summary mode
@@ -4510,8 +4507,7 @@ gnus-article-mode
(setq cursor-in-non-selected-windows nil))
(gnus-set-default-directory)
(buffer-disable-undo)
- (setq buffer-read-only t
- show-trailing-whitespace nil)
+ (setq show-trailing-whitespace nil)
(mm-enable-multibyte))
(defun gnus-article-setup-buffer ()
diff --git a/lisp/gnus/gnus-group.el b/lisp/gnus/gnus-group.el
index 6af27afbfa..d526894b3a 100644
--- a/lisp/gnus/gnus-group.el
+++ b/lisp/gnus/gnus-group.el
@@ -567,8 +567,6 @@ gnus-group-list-option
;;; Gnus group mode
;;;
-(put 'gnus-group-mode 'mode-class 'special)
-
(gnus-define-keys gnus-group-mode-map
" " gnus-group-read-group
"=" gnus-group-select-group
@@ -1106,9 +1104,8 @@ gnus-group-make-tool-bar
(set (make-local-variable 'tool-bar-map) map))))
gnus-group-tool-bar-map)
-(define-derived-mode gnus-group-mode fundamental-mode "Group"
+(define-derived-mode gnus-group-mode gnus-mode "Group"
"Major mode for reading news.
-
All normal editing commands are switched off.
\\<gnus-group-mode-map>
The group buffer lists (some of) the groups available. For instance,
@@ -1131,8 +1128,7 @@ gnus-group-mode
(setq mode-line-process nil)
(buffer-disable-undo)
(setq truncate-lines t)
- (setq buffer-read-only t
- show-trailing-whitespace nil)
+ (setq show-trailing-whitespace nil)
(gnus-set-default-directory)
(gnus-update-format-specifications nil 'group 'group-mode)
(gnus-update-group-mark-positions)
diff --git a/lisp/gnus/gnus-kill.el b/lisp/gnus/gnus-kill.el
index 60732c11d5..e65ff51ce7 100644
--- a/lisp/gnus/gnus-kill.el
+++ b/lisp/gnus/gnus-kill.el
@@ -29,11 +29,6 @@
(require 'gnus-art)
(require 'gnus-range)
-(defcustom gnus-kill-file-mode-hook nil
- "Hook for Gnus kill file mode."
- :group 'gnus-score-kill
- :type 'hook)
-
(defcustom gnus-kill-expiry-days 7
"Number of days before expiring unused kill file entries."
:group 'gnus-score-kill
diff --git a/lisp/gnus/gnus-salt.el b/lisp/gnus/gnus-salt.el
index aff841760a..0504465de3 100644
--- a/lisp/gnus/gnus-salt.el
+++ b/lisp/gnus/gnus-salt.el
@@ -396,11 +396,6 @@ gnus-generate-tree-function
(function :tag "Other" nil))
:group 'gnus-summary-tree)
-(defcustom gnus-tree-mode-hook nil
- "Hook run in tree mode buffers."
- :type 'hook
- :group 'gnus-summary-tree)
-
;;; Internal variables.
(defvar gnus-tmp-name)
@@ -445,8 +440,6 @@ gnus-tree-mode-map
'undefined 'gnus-tree-read-summary-keys map)
map))
-(put 'gnus-tree-mode 'mode-class 'special)
-
(defun gnus-tree-make-menu-bar ()
(unless (boundp 'gnus-tree-menu)
(easy-menu-define
@@ -454,7 +447,7 @@ gnus-tree-make-menu-bar
'("Tree"
["Select article" gnus-tree-select-article t]))))
-(define-derived-mode gnus-tree-mode fundamental-mode "Tree"
+(define-derived-mode gnus-tree-mode gnus-mode "Tree"
"Major mode for displaying thread trees."
(gnus-set-format 'tree-mode)
(gnus-set-format 'tree t)
diff --git a/lisp/gnus/gnus-srvr.el b/lisp/gnus/gnus-srvr.el
index dfca5e9d2c..03718fd104 100644
--- a/lisp/gnus/gnus-srvr.el
+++ b/lisp/gnus/gnus-srvr.el
@@ -36,11 +36,6 @@
(autoload 'gnus-group-make-nnir-group "nnir")
-(defcustom gnus-server-mode-hook nil
- "Hook run in `gnus-server-mode' buffers."
- :group 'gnus-server
- :type 'hook)
-
(defcustom gnus-server-exit-hook nil
"Hook run when exiting the server buffer."
:group 'gnus-server
@@ -108,7 +103,7 @@ gnus-server-line-format-spec
(defvar gnus-server-mode-line-format-spec nil)
(defvar gnus-server-killed-servers nil)
-(defvar gnus-server-mode-map)
+(defvar gnus-server-mode-map nil)
(defcustom gnus-server-menu-hook nil
"Hook run after the creation of the server mode menu."
@@ -150,11 +145,8 @@ gnus-server-make-menu-bar
(gnus-run-hooks 'gnus-server-menu-hook)))
-(defvar gnus-server-mode-map nil)
-(put 'gnus-server-mode 'mode-class 'special)
-
(unless gnus-server-mode-map
- (setq gnus-server-mode-map (make-sparse-keymap))
+ (setq gnus-server-mode-map (make-keymap))
(suppress-keymap gnus-server-mode-map)
(gnus-define-keys gnus-server-mode-map
@@ -253,9 +245,8 @@ gnus-server-font-lock-keywords
("(\\(offline\\))" 1 'gnus-server-offline)
("(\\(denied\\))" 1 'gnus-server-denied)))
-(defun gnus-server-mode ()
+(define-derived-mode gnus-server-mode gnus-mode "Server"
"Major mode for listing and editing servers.
-
All normal editing commands are switched off.
\\<gnus-server-mode-map>
For more in-depth information on this mode, read the manual
@@ -264,23 +255,16 @@ gnus-server-mode
The following commands are available:
\\{gnus-server-mode-map}"
- ;; FIXME: Use define-derived-mode.
- (interactive)
(when (gnus-visual-p 'server-menu 'menu)
(gnus-server-make-menu-bar))
- (kill-all-local-variables)
(gnus-simplify-mode-line)
- (setq major-mode 'gnus-server-mode)
- (setq mode-name "Server")
(gnus-set-default-directory)
(setq mode-line-process nil)
- (use-local-map gnus-server-mode-map)
(buffer-disable-undo)
(setq truncate-lines t)
- (setq buffer-read-only t)
(set (make-local-variable 'font-lock-defaults)
- '(gnus-server-font-lock-keywords t))
- (gnus-run-mode-hooks 'gnus-server-mode-hook))
+ '(gnus-server-font-lock-keywords t)))
+
(defun gnus-server-insert-server-line (name method)
(let* ((gnus-tmp-name name)
@@ -320,21 +304,15 @@ gnus-server-insert-server-line
(defun gnus-enter-server-buffer ()
"Set up the server buffer."
- (gnus-server-setup-buffer)
(gnus-configure-windows 'server)
;; Usually `gnus-configure-windows' will finish with the
;; `gnus-server-buffer' selected as the current buffer, but not always (I
;; bumped into it when starting from a dedicated *Group* frame, and
;; gnus-configure-windows opened *Server* into its own dedicated frame).
(with-current-buffer (get-buffer gnus-server-buffer)
+ (gnus-server-mode)
(gnus-server-prepare)))
-(defun gnus-server-setup-buffer ()
- "Initialize the server buffer."
- (unless (get-buffer gnus-server-buffer)
- (with-current-buffer (gnus-get-buffer-create gnus-server-buffer)
- (gnus-server-mode))))
-
(defun gnus-server-prepare ()
(gnus-set-format 'server-mode)
(gnus-set-format 'server t)
@@ -717,12 +695,10 @@ gnus-browse-subscribe-newsgroup-method
function
(repeat function)))
-(defvar gnus-browse-mode-hook nil)
-(defvar gnus-browse-mode-map nil)
-(put 'gnus-browse-mode 'mode-class 'special)
+(defvar gnus-browse-mode-map (make-keymap))
(unless gnus-browse-mode-map
- (setq gnus-browse-mode-map (make-keymap))
+ (defvar gnus-browse-mode-map (make-keymap))
(suppress-keymap gnus-browse-mode-map)
(gnus-define-keys
@@ -897,9 +873,8 @@ gnus-browse-foreign-server
(gnus-message 5 "Connecting to %s...done" (nth 1 method))
t))))
-(define-derived-mode gnus-browse-mode fundamental-mode "Browse Server"
+(define-derived-mode gnus-browse-mode gnus-mode "Browse Server"
"Major mode for browsing a foreign server.
-
All normal editing commands are switched off.
\\<gnus-browse-mode-map>
@@ -918,8 +893,7 @@ gnus-browse-mode
(setq mode-line-process nil)
(buffer-disable-undo)
(setq truncate-lines t)
- (gnus-set-default-directory)
- (setq buffer-read-only t))
+ (gnus-set-default-directory))
(defun gnus-browse-read-group (&optional no-article number)
"Enter the group at the current line.
diff --git a/lisp/gnus/gnus-sum.el b/lisp/gnus/gnus-sum.el
index f9fae3792b..67abf6d640 100644
--- a/lisp/gnus/gnus-sum.el
+++ b/lisp/gnus/gnus-sum.el
@@ -1842,8 +1842,6 @@ gnus-summary-bubble-group
;;; Gnus summary mode
;;;
-(put 'gnus-summary-mode 'mode-class 'special)
-
(defvar gnus-article-commands-menu)
;; Non-orthogonal keys
@@ -3052,10 +3050,8 @@ bookmark-make-record-function
\f
(defvar bidi-paragraph-direction)
-(defun gnus-summary-mode (&optional group)
+(define-derived-mode gnus-summary-mode gnus-mode "Summary"
"Major mode for reading articles.
-
-All normal editing commands are switched off.
\\<gnus-summary-mode-map>
Each line in this buffer represents one article. To read an
article, you can, for instance, type `\\[gnus-summary-next-page]'. To move forwards
@@ -3072,24 +3068,16 @@ gnus-summary-mode
The following commands are available:
\\{gnus-summary-mode-map}"
- ;; FIXME: Use define-derived-mode.
- (interactive)
- (kill-all-local-variables)
(let ((gnus-summary-local-variables gnus-newsgroup-variables))
(gnus-summary-make-local-variables))
(gnus-summary-make-local-variables)
- (setq gnus-newsgroup-name group)
(when (gnus-visual-p 'summary-menu 'menu)
(gnus-summary-make-menu-bar)
(gnus-summary-make-tool-bar))
(gnus-make-thread-indent-array)
(gnus-simplify-mode-line)
- (setq major-mode 'gnus-summary-mode)
- (setq mode-name "Summary")
- (use-local-map gnus-summary-mode-map)
(buffer-disable-undo)
- (setq buffer-read-only t
- show-trailing-whitespace nil
+ (setq show-trailing-whitespace nil
truncate-lines t
bidi-paragraph-direction 'left-to-right)
(add-to-invisibility-spec '(gnus-sum . t))
@@ -3101,7 +3089,6 @@ gnus-summary-mode
(make-local-variable 'gnus-summary-dummy-line-format-spec)
(make-local-variable 'gnus-summary-mark-positions)
(add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
- (gnus-run-mode-hooks 'gnus-summary-mode-hook)
(turn-on-gnus-mailing-list-mode)
(mm-enable-multibyte)
(set (make-local-variable 'bookmark-make-record-function)
@@ -3493,7 +3480,8 @@ gnus-summary-setup-buffer
(not gnus-newsgroup-prepared))
(set-buffer (gnus-get-buffer-create buffer))
(setq gnus-summary-buffer (current-buffer))
- (gnus-summary-mode group)
+ (setq gnus-newsgroup-name group)
+ (gnus-summary-mode)
(when (gnus-group-quit-config group)
(set (make-local-variable 'gnus-single-article-buffer) nil))
(make-local-variable 'gnus-article-buffer)
diff --git a/lisp/gnus/gnus.el b/lisp/gnus/gnus.el
index 2786323f67..6c59b13574 100644
--- a/lisp/gnus/gnus.el
+++ b/lisp/gnus/gnus.el
@@ -637,6 +637,12 @@ gnus-summary-low-read
"Face used for low interest read articles."
:group 'gnus-summary)
+;;; Base gnus-mode
+
+(define-derived-mode gnus-mode special-mode nil
+ "Base mode from which all other gnus modes derive.
+This does nothing but derive from `special-mode', and should not
+be used directly.")
;;;
;;; Gnus buffers
--
2.19.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* bug#33263: 27.0.50; Tidying up Gnus modes
2018-11-05 2:53 bug#33263: 27.0.50; Tidying up Gnus modes Eric Abrahamsen
@ 2018-11-05 14:14 ` Noam Postavsky
2018-11-05 17:51 ` Eric Abrahamsen
2018-11-10 4:01 ` bug#33263: 27.0.50; Tidying up Gnus modes, [PATCH] Provide new gnus-mode, derive all gnus major modes from this Noam Postavsky
2018-11-23 17:45 ` bug#33263: 27.0.50; Tidying up Gnus modes Eric Abrahamsen
2 siblings, 1 reply; 11+ messages in thread
From: Noam Postavsky @ 2018-11-05 14:14 UTC (permalink / raw)
To: Eric Abrahamsen; +Cc: 33263
Eric Abrahamsen <eric@ericabrahamsen.net> writes:
> +(defvar gnus-browse-mode-map (make-keymap))
>
> (unless gnus-browse-mode-map
> - (setq gnus-browse-mode-map (make-keymap))
> + (defvar gnus-browse-mode-map (make-keymap))
This doesn't look right.
> -(defun gnus-summary-mode (&optional group)
> +(define-derived-mode gnus-summary-mode gnus-mode "Summary"
> "Major mode for reading articles.
> - (gnus-summary-mode group)
> + (setq gnus-newsgroup-name group)
> + (gnus-summary-mode)
> (when (gnus-group-quit-config group)
Where does GROUP come from now?
^ permalink raw reply [flat|nested] 11+ messages in thread
* bug#33263: 27.0.50; Tidying up Gnus modes
2018-11-05 14:14 ` Noam Postavsky
@ 2018-11-05 17:51 ` Eric Abrahamsen
2018-11-06 13:27 ` Noam Postavsky
0 siblings, 1 reply; 11+ messages in thread
From: Eric Abrahamsen @ 2018-11-05 17:51 UTC (permalink / raw)
To: 33263
Noam Postavsky <npostavs@gmail.com> writes:
> Eric Abrahamsen <eric@ericabrahamsen.net> writes:
>
>> +(defvar gnus-browse-mode-map (make-keymap))
>>
>> (unless gnus-browse-mode-map
>> - (setq gnus-browse-mode-map (make-keymap))
>> + (defvar gnus-browse-mode-map (make-keymap))
>
> This doesn't look right.
Hmm, you're right, I think I got confused there. TBH I don't really know
why these things are wrapped in `unless', but I think what should have
happened is that `gnus-browse-mode-map' is first defvar'ed to nil, and
later setq'ed to (make-keymap).
>> -(defun gnus-summary-mode (&optional group)
>> +(define-derived-mode gnus-summary-mode gnus-mode "Summary"
>> "Major mode for reading articles.
>
>> - (gnus-summary-mode group)
>> + (setq gnus-newsgroup-name group)
>> + (gnus-summary-mode)
>> (when (gnus-group-quit-config group)
>
> Where does GROUP come from now?
GROUP has always been passed down through gnus-group-read-group (which
picks it up from the group under point) => gnus-summary-read-group =>
gnus-summary-read-group-1 => gnus-summary-setup-buffer =>
gnus-summary-mode.
When gnus-summary-mode was a function it was passed GROUP as an argument
and set it as the (buffer-local) gnus-newsgroup-name variable. I
couldn't see anything in the rest of gnus-summary-mode that would need
that variable set, but you never know if Gnus is checking something four
levels deep. So I pulled that up and set it in
gnus-summary-setup-buffer, before the call to the major mode, forgetting
that calling gnus-summary-mode would of course clear out buffer-local
variables. *And* failing to notice that gnus-summary-setup-buffer sets
the variable *again* later on. So it was originally set twice.
I've been testing for a while, and don't think anything called from the
gnus-summary-mode code needs to be aware of gnus-newsgroup-name, but I
will look a little closer. Anything that *does* rely on knowing which
group we're opening should definitely be hoisted up to
gnus-summary-setup-buffer. Then I'll just delete the first setting of
gnus-newsgroup-name and leave the later one.
Thanks for looking at this.
^ permalink raw reply [flat|nested] 11+ messages in thread
* bug#33263: 27.0.50; Tidying up Gnus modes
2018-11-05 17:51 ` Eric Abrahamsen
@ 2018-11-06 13:27 ` Noam Postavsky
2018-11-06 16:21 ` Eric Abrahamsen
0 siblings, 1 reply; 11+ messages in thread
From: Noam Postavsky @ 2018-11-06 13:27 UTC (permalink / raw)
To: Eric Abrahamsen; +Cc: 33263
Eric Abrahamsen <eric@ericabrahamsen.net> writes:
> Noam Postavsky <npostavs@gmail.com> writes:
>
>> Eric Abrahamsen <eric@ericabrahamsen.net> writes:
>>
>>> +(defvar gnus-browse-mode-map (make-keymap))
>>>
>>> (unless gnus-browse-mode-map
>>> - (setq gnus-browse-mode-map (make-keymap))
>>> + (defvar gnus-browse-mode-map (make-keymap))
>>
>> This doesn't look right.
>
> Hmm, you're right, I think I got confused there. TBH I don't really know
> why these things are wrapped in `unless', but I think what should have
> happened is that `gnus-browse-mode-map' is first defvar'ed to nil, and
> later setq'ed to (make-keymap).
The usual idiom for this is
(defvar gnus-browse-mode-map
(let ((map (make-sparse-keymap)))
(define-key map ...)
...
map))
It seems that (the expansion of) gnus-define-keys relies on dynamic
binding of the map variable (i.e., it must be called after the defvar,
not inside), so that's the reason to split in two parts.
^ permalink raw reply [flat|nested] 11+ messages in thread
* bug#33263: 27.0.50; Tidying up Gnus modes
2018-11-06 13:27 ` Noam Postavsky
@ 2018-11-06 16:21 ` Eric Abrahamsen
2018-11-06 16:28 ` Noam Postavsky
0 siblings, 1 reply; 11+ messages in thread
From: Eric Abrahamsen @ 2018-11-06 16:21 UTC (permalink / raw)
To: 33263
Noam Postavsky <npostavs@gmail.com> writes:
> Eric Abrahamsen <eric@ericabrahamsen.net> writes:
>
>> Noam Postavsky <npostavs@gmail.com> writes:
>>
>>> Eric Abrahamsen <eric@ericabrahamsen.net> writes:
>>>
>>>> +(defvar gnus-browse-mode-map (make-keymap))
>>>>
>>>> (unless gnus-browse-mode-map
>>>> - (setq gnus-browse-mode-map (make-keymap))
>>>> + (defvar gnus-browse-mode-map (make-keymap))
>>>
>>> This doesn't look right.
>>
>> Hmm, you're right, I think I got confused there. TBH I don't really know
>> why these things are wrapped in `unless', but I think what should have
>> happened is that `gnus-browse-mode-map' is first defvar'ed to nil, and
>> later setq'ed to (make-keymap).
>
> The usual idiom for this is
>
> (defvar gnus-browse-mode-map
> (let ((map (make-sparse-keymap)))
> (define-key map ...)
> ...
> map))
>
> It seems that (the expansion of) gnus-define-keys relies on dynamic
> binding of the map variable (i.e., it must be called after the defvar,
> not inside), so that's the reason to split in two parts.
Right, I got that much, I was mostly wondering why the `unless' -- it's
unlikely these files would be loaded multiple times, and even if they
were, that wouldn't break anything, would it?
^ permalink raw reply [flat|nested] 11+ messages in thread
* bug#33263: 27.0.50; Tidying up Gnus modes
2018-11-06 16:21 ` Eric Abrahamsen
@ 2018-11-06 16:28 ` Noam Postavsky
2018-11-06 17:37 ` Eric Abrahamsen
0 siblings, 1 reply; 11+ messages in thread
From: Noam Postavsky @ 2018-11-06 16:28 UTC (permalink / raw)
To: Eric Abrahamsen; +Cc: 33263
On Tue, 6 Nov 2018 at 11:22, Eric Abrahamsen <eric@ericabrahamsen.net> wrote:
> >>>> +(defvar gnus-browse-mode-map (make-keymap))
> >>>>
> >>>> (unless gnus-browse-mode-map
> >>>> - (setq gnus-browse-mode-map (make-keymap))
> >>>> + (defvar gnus-browse-mode-map (make-keymap))
> Right, I got that much, I was mostly wondering why the `unless' -- it's
> unlikely these files would be loaded multiple times, and even if they
> were, that wouldn't break anything, would it?
Without the `unless', if the user had made changes to
gnus-browse-mode-map they would be lost upon reload (as you say, it's
not especially likely to happen, but I guess the original author
wanted to preserve the semantics of the single defvar form).
^ permalink raw reply [flat|nested] 11+ messages in thread
* bug#33263: 27.0.50; Tidying up Gnus modes
2018-11-06 16:28 ` Noam Postavsky
@ 2018-11-06 17:37 ` Eric Abrahamsen
0 siblings, 0 replies; 11+ messages in thread
From: Eric Abrahamsen @ 2018-11-06 17:37 UTC (permalink / raw)
To: 33263
Noam Postavsky <npostavs@gmail.com> writes:
> On Tue, 6 Nov 2018 at 11:22, Eric Abrahamsen <eric@ericabrahamsen.net> wrote:
>
>> >>>> +(defvar gnus-browse-mode-map (make-keymap))
>> >>>>
>> >>>> (unless gnus-browse-mode-map
>> >>>> - (setq gnus-browse-mode-map (make-keymap))
>> >>>> + (defvar gnus-browse-mode-map (make-keymap))
>
>> Right, I got that much, I was mostly wondering why the `unless' -- it's
>> unlikely these files would be loaded multiple times, and even if they
>> were, that wouldn't break anything, would it?
>
> Without the `unless', if the user had made changes to
> gnus-browse-mode-map they would be lost upon reload (as you say, it's
> not especially likely to happen, but I guess the original author
> wanted to preserve the semantics of the single defvar form).
Got it, thanks for the explanation. I'll fix this, and look more closely
at the "group" argument to `gnus-summary-mode'.
Eric
^ permalink raw reply [flat|nested] 11+ messages in thread
* bug#33263: 27.0.50; Tidying up Gnus modes, [PATCH] Provide new gnus-mode, derive all gnus major modes from this
2018-11-05 2:53 bug#33263: 27.0.50; Tidying up Gnus modes Eric Abrahamsen
2018-11-05 14:14 ` Noam Postavsky
@ 2018-11-10 4:01 ` Noam Postavsky
2018-11-10 4:55 ` Eric Abrahamsen
2018-11-23 17:45 ` bug#33263: 27.0.50; Tidying up Gnus modes Eric Abrahamsen
2 siblings, 1 reply; 11+ messages in thread
From: Noam Postavsky @ 2018-11-10 4:01 UTC (permalink / raw)
To: 33263; +Cc: Eric Abrahamsen, Lars Ingebrigtsen
[-- Attachment #1: Type: text/plain, Size: 22 bytes --]
[forwarding to list]
[-- Attachment #2: Type: message/rfc822, Size: 18464 bytes --]
[-- Attachment #2.1.1: Type: text/plain, Size: 812 bytes --]
Here's a new version of the patch. I fixed the keymap thing, and looked
carefully at the code called from `gnus-summary-mode'.
`turn-on-mailing-list-mode' clearly belongs in
`gnus-summary-setup-buffer', so I moved it up there. The format spec and
mark position stuff doesn't vary depending on the group, but I have
dreams of a day when it will, so I moved that up, too.
I added more docs and comments making the separation of concerns clear:
`gnus-summary-setup-buffer' handles group-dependent setup,
`gnus-summary-mode' handles group-independent stuff. That's also the
motivation for moving the three `make-local-variables', which would
otherwise be a pointless change.
I hope this is acceptable (I'm cc'ing Lars in case he has an opinion).
I'll run it locally for a week or so, then push to master.
Eric
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2.1.2: 0001-Provide-new-gnus-mode-derive-all-gnus-major-modes-fr.patch --]
[-- Type: text/x-patch, Size: 16739 bytes --]
From 777e86d060320f2341ae231ff48d453ae3f503d3 Mon Sep 17 00:00:00 2001
From: Eric Abrahamsen <eric@ericabrahamsen.net>
Date: Mon, 25 Jun 2018 17:40:19 -0700
Subject: [PATCH] Provide new gnus-mode, derive all gnus major modes from this
* lisp/gnus/gnus.el (gnus-mode): New do-nothing major mode, derived
from special mode.
* lisp/gnus/gnus-sum.el (gnus-summary-mode): Change from a function to
a major mode, derive from gnus-mode.
(gnus-summary-setup-buffer): Change call a bit -- can no longer pass
an argument to the mode function.
* lisp/gnus/gnus-srvr.el (gnus-browse-mode): Derive from gnus-mode.
(gnus-server-setup-buffer): Remove unnecessary function.
(gnus-enter-server-buffer): Call gnus-server-mode here, and call it
whether the server buffer already existed or not.
(gnus-server-mode): Change from a function to a major mode.
(gnus-server-mode-hook): Delete custom option, this is automatically
created.
* lisp/gnus/gnus-salt.el (gnus-tree-mode): Derive from gnus-mode.
(gnus-tree-mode-hook): Delete custom option, this is automatically
created.
* lisp/gnus/gnus-kill.el (gnus-kill-file-mode-hook): Delete custom
option.
* lisp/gnus/gnus-group.el (gnus-group-mode):
* lisp/gnus/gnus-art.el (gnus-article-mode):
* lisp/gnus/gnus-agent.el (gnus-category-mode): Derive from gnus-mode.
(gnus-category-mode-hook): Delete custom option.
---
lisp/gnus/gnus-agent.el | 10 ++------
lisp/gnus/gnus-art.el | 8 ++-----
lisp/gnus/gnus-group.el | 8 ++-----
lisp/gnus/gnus-kill.el | 5 ----
lisp/gnus/gnus-salt.el | 9 +-------
lisp/gnus/gnus-srvr.el | 44 ++++++++---------------------------
lisp/gnus/gnus-sum.el | 51 +++++++++++++++++++++--------------------
lisp/gnus/gnus.el | 6 +++++
8 files changed, 48 insertions(+), 93 deletions(-)
diff --git a/lisp/gnus/gnus-agent.el b/lisp/gnus/gnus-agent.el
index 18e6174fa0..93a675584f 100644
--- a/lisp/gnus/gnus-agent.el
+++ b/lisp/gnus/gnus-agent.el
@@ -2575,9 +2575,6 @@ gnus-agent-fetch-group-1
;;; Agent Category Mode
;;;
-(defvar gnus-category-mode-hook nil
- "Hook run in `gnus-category-mode' buffers.")
-
(defvar gnus-category-line-format " %(%20c%): %g\n"
"Format of category lines.
@@ -2613,7 +2610,6 @@ gnus-category-line-format-spec
(defvar gnus-category-mode-line-format-spec nil)
(defvar gnus-category-mode-map nil)
-(put 'gnus-category-mode 'mode-class 'special)
(unless gnus-category-mode-map
(setq gnus-category-mode-map (make-sparse-keymap))
@@ -2655,9 +2651,8 @@ gnus-category-make-menu-bar
(gnus-run-hooks 'gnus-category-menu-hook)))
-(define-derived-mode gnus-category-mode fundamental-mode "Category"
+(define-derived-mode gnus-category-mode gnus-mode "Category"
"Major mode for listing and editing agent categories.
-
All normal editing commands are switched off.
\\<gnus-category-mode-map>
For more in-depth information on this mode, read the manual
@@ -2672,8 +2667,7 @@ gnus-category-mode
(gnus-set-default-directory)
(setq mode-line-process nil)
(buffer-disable-undo)
- (setq truncate-lines t)
- (setq buffer-read-only t))
+ (setq truncate-lines t))
(defalias 'gnus-category-position-point 'gnus-goto-colon)
diff --git a/lisp/gnus/gnus-art.el b/lisp/gnus/gnus-art.el
index f28e6db3c7..c78bb3325f 100644
--- a/lisp/gnus/gnus-art.el
+++ b/lisp/gnus/gnus-art.el
@@ -4388,8 +4388,6 @@ article-verify-cancel-lock
;;; Gnus article mode
;;;
-(put 'gnus-article-mode 'mode-class 'special)
-
(set-keymap-parent gnus-article-mode-map widget-keymap)
(gnus-define-keys gnus-article-mode-map
@@ -4467,9 +4465,8 @@ gnus-article-make-menu-bar
(defvar bookmark-make-record-function)
(defvar shr-put-image-function)
-(define-derived-mode gnus-article-mode fundamental-mode "Article"
+(define-derived-mode gnus-article-mode gnus-mode "Article"
"Major mode for displaying an article.
-
All normal editing commands are switched off.
The following commands are available in addition to all summary mode
@@ -4510,8 +4507,7 @@ gnus-article-mode
(setq cursor-in-non-selected-windows nil))
(gnus-set-default-directory)
(buffer-disable-undo)
- (setq buffer-read-only t
- show-trailing-whitespace nil)
+ (setq show-trailing-whitespace nil)
(mm-enable-multibyte))
(defun gnus-article-setup-buffer ()
diff --git a/lisp/gnus/gnus-group.el b/lisp/gnus/gnus-group.el
index 6af27afbfa..d526894b3a 100644
--- a/lisp/gnus/gnus-group.el
+++ b/lisp/gnus/gnus-group.el
@@ -567,8 +567,6 @@ gnus-group-list-option
;;; Gnus group mode
;;;
-(put 'gnus-group-mode 'mode-class 'special)
-
(gnus-define-keys gnus-group-mode-map
" " gnus-group-read-group
"=" gnus-group-select-group
@@ -1106,9 +1104,8 @@ gnus-group-make-tool-bar
(set (make-local-variable 'tool-bar-map) map))))
gnus-group-tool-bar-map)
-(define-derived-mode gnus-group-mode fundamental-mode "Group"
+(define-derived-mode gnus-group-mode gnus-mode "Group"
"Major mode for reading news.
-
All normal editing commands are switched off.
\\<gnus-group-mode-map>
The group buffer lists (some of) the groups available. For instance,
@@ -1131,8 +1128,7 @@ gnus-group-mode
(setq mode-line-process nil)
(buffer-disable-undo)
(setq truncate-lines t)
- (setq buffer-read-only t
- show-trailing-whitespace nil)
+ (setq show-trailing-whitespace nil)
(gnus-set-default-directory)
(gnus-update-format-specifications nil 'group 'group-mode)
(gnus-update-group-mark-positions)
diff --git a/lisp/gnus/gnus-kill.el b/lisp/gnus/gnus-kill.el
index 60732c11d5..e65ff51ce7 100644
--- a/lisp/gnus/gnus-kill.el
+++ b/lisp/gnus/gnus-kill.el
@@ -29,11 +29,6 @@
(require 'gnus-art)
(require 'gnus-range)
-(defcustom gnus-kill-file-mode-hook nil
- "Hook for Gnus kill file mode."
- :group 'gnus-score-kill
- :type 'hook)
-
(defcustom gnus-kill-expiry-days 7
"Number of days before expiring unused kill file entries."
:group 'gnus-score-kill
diff --git a/lisp/gnus/gnus-salt.el b/lisp/gnus/gnus-salt.el
index aff841760a..0504465de3 100644
--- a/lisp/gnus/gnus-salt.el
+++ b/lisp/gnus/gnus-salt.el
@@ -396,11 +396,6 @@ gnus-generate-tree-function
(function :tag "Other" nil))
:group 'gnus-summary-tree)
-(defcustom gnus-tree-mode-hook nil
- "Hook run in tree mode buffers."
- :type 'hook
- :group 'gnus-summary-tree)
-
;;; Internal variables.
(defvar gnus-tmp-name)
@@ -445,8 +440,6 @@ gnus-tree-mode-map
'undefined 'gnus-tree-read-summary-keys map)
map))
-(put 'gnus-tree-mode 'mode-class 'special)
-
(defun gnus-tree-make-menu-bar ()
(unless (boundp 'gnus-tree-menu)
(easy-menu-define
@@ -454,7 +447,7 @@ gnus-tree-make-menu-bar
'("Tree"
["Select article" gnus-tree-select-article t]))))
-(define-derived-mode gnus-tree-mode fundamental-mode "Tree"
+(define-derived-mode gnus-tree-mode gnus-mode "Tree"
"Major mode for displaying thread trees."
(gnus-set-format 'tree-mode)
(gnus-set-format 'tree t)
diff --git a/lisp/gnus/gnus-srvr.el b/lisp/gnus/gnus-srvr.el
index dfca5e9d2c..400199083a 100644
--- a/lisp/gnus/gnus-srvr.el
+++ b/lisp/gnus/gnus-srvr.el
@@ -36,11 +36,6 @@
(autoload 'gnus-group-make-nnir-group "nnir")
-(defcustom gnus-server-mode-hook nil
- "Hook run in `gnus-server-mode' buffers."
- :group 'gnus-server
- :type 'hook)
-
(defcustom gnus-server-exit-hook nil
"Hook run when exiting the server buffer."
:group 'gnus-server
@@ -108,7 +103,7 @@ gnus-server-line-format-spec
(defvar gnus-server-mode-line-format-spec nil)
(defvar gnus-server-killed-servers nil)
-(defvar gnus-server-mode-map)
+(defvar gnus-server-mode-map nil)
(defcustom gnus-server-menu-hook nil
"Hook run after the creation of the server mode menu."
@@ -150,11 +145,8 @@ gnus-server-make-menu-bar
(gnus-run-hooks 'gnus-server-menu-hook)))
-(defvar gnus-server-mode-map nil)
-(put 'gnus-server-mode 'mode-class 'special)
-
(unless gnus-server-mode-map
- (setq gnus-server-mode-map (make-sparse-keymap))
+ (setq gnus-server-mode-map (make-keymap))
(suppress-keymap gnus-server-mode-map)
(gnus-define-keys gnus-server-mode-map
@@ -253,9 +245,8 @@ gnus-server-font-lock-keywords
("(\\(offline\\))" 1 'gnus-server-offline)
("(\\(denied\\))" 1 'gnus-server-denied)))
-(defun gnus-server-mode ()
+(define-derived-mode gnus-server-mode gnus-mode "Server"
"Major mode for listing and editing servers.
-
All normal editing commands are switched off.
\\<gnus-server-mode-map>
For more in-depth information on this mode, read the manual
@@ -264,23 +255,16 @@ gnus-server-mode
The following commands are available:
\\{gnus-server-mode-map}"
- ;; FIXME: Use define-derived-mode.
- (interactive)
(when (gnus-visual-p 'server-menu 'menu)
(gnus-server-make-menu-bar))
- (kill-all-local-variables)
(gnus-simplify-mode-line)
- (setq major-mode 'gnus-server-mode)
- (setq mode-name "Server")
(gnus-set-default-directory)
(setq mode-line-process nil)
- (use-local-map gnus-server-mode-map)
(buffer-disable-undo)
(setq truncate-lines t)
- (setq buffer-read-only t)
(set (make-local-variable 'font-lock-defaults)
- '(gnus-server-font-lock-keywords t))
- (gnus-run-mode-hooks 'gnus-server-mode-hook))
+ '(gnus-server-font-lock-keywords t)))
+
(defun gnus-server-insert-server-line (name method)
(let* ((gnus-tmp-name name)
@@ -320,21 +304,15 @@ gnus-server-insert-server-line
(defun gnus-enter-server-buffer ()
"Set up the server buffer."
- (gnus-server-setup-buffer)
(gnus-configure-windows 'server)
;; Usually `gnus-configure-windows' will finish with the
;; `gnus-server-buffer' selected as the current buffer, but not always (I
;; bumped into it when starting from a dedicated *Group* frame, and
;; gnus-configure-windows opened *Server* into its own dedicated frame).
- (with-current-buffer (get-buffer gnus-server-buffer)
+ (with-current-buffer (get-buffer-create gnus-server-buffer)
+ (gnus-server-mode)
(gnus-server-prepare)))
-(defun gnus-server-setup-buffer ()
- "Initialize the server buffer."
- (unless (get-buffer gnus-server-buffer)
- (with-current-buffer (gnus-get-buffer-create gnus-server-buffer)
- (gnus-server-mode))))
-
(defun gnus-server-prepare ()
(gnus-set-format 'server-mode)
(gnus-set-format 'server t)
@@ -717,9 +695,7 @@ gnus-browse-subscribe-newsgroup-method
function
(repeat function)))
-(defvar gnus-browse-mode-hook nil)
(defvar gnus-browse-mode-map nil)
-(put 'gnus-browse-mode 'mode-class 'special)
(unless gnus-browse-mode-map
(setq gnus-browse-mode-map (make-keymap))
@@ -897,9 +873,8 @@ gnus-browse-foreign-server
(gnus-message 5 "Connecting to %s...done" (nth 1 method))
t))))
-(define-derived-mode gnus-browse-mode fundamental-mode "Browse Server"
+(define-derived-mode gnus-browse-mode gnus-mode "Browse Server"
"Major mode for browsing a foreign server.
-
All normal editing commands are switched off.
\\<gnus-browse-mode-map>
@@ -918,8 +893,7 @@ gnus-browse-mode
(setq mode-line-process nil)
(buffer-disable-undo)
(setq truncate-lines t)
- (gnus-set-default-directory)
- (setq buffer-read-only t))
+ (gnus-set-default-directory))
(defun gnus-browse-read-group (&optional no-article number)
"Enter the group at the current line.
diff --git a/lisp/gnus/gnus-sum.el b/lisp/gnus/gnus-sum.el
index f9fae3792b..6ba413eefa 100644
--- a/lisp/gnus/gnus-sum.el
+++ b/lisp/gnus/gnus-sum.el
@@ -1842,8 +1842,6 @@ gnus-summary-bubble-group
;;; Gnus summary mode
;;;
-(put 'gnus-summary-mode 'mode-class 'special)
-
(defvar gnus-article-commands-menu)
;; Non-orthogonal keys
@@ -3052,10 +3050,8 @@ bookmark-make-record-function
\f
(defvar bidi-paragraph-direction)
-(defun gnus-summary-mode (&optional group)
+(define-derived-mode gnus-summary-mode gnus-mode "Summary"
"Major mode for reading articles.
-
-All normal editing commands are switched off.
\\<gnus-summary-mode-map>
Each line in this buffer represents one article. To read an
article, you can, for instance, type `\\[gnus-summary-next-page]'. To move forwards
@@ -3072,24 +3068,16 @@ gnus-summary-mode
The following commands are available:
\\{gnus-summary-mode-map}"
- ;; FIXME: Use define-derived-mode.
- (interactive)
- (kill-all-local-variables)
(let ((gnus-summary-local-variables gnus-newsgroup-variables))
(gnus-summary-make-local-variables))
(gnus-summary-make-local-variables)
- (setq gnus-newsgroup-name group)
(when (gnus-visual-p 'summary-menu 'menu)
(gnus-summary-make-menu-bar)
(gnus-summary-make-tool-bar))
(gnus-make-thread-indent-array)
(gnus-simplify-mode-line)
- (setq major-mode 'gnus-summary-mode)
- (setq mode-name "Summary")
- (use-local-map gnus-summary-mode-map)
(buffer-disable-undo)
- (setq buffer-read-only t
- show-trailing-whitespace nil
+ (setq show-trailing-whitespace nil
truncate-lines t
bidi-paragraph-direction 'left-to-right)
(add-to-invisibility-spec '(gnus-sum . t))
@@ -3100,14 +3088,13 @@ gnus-summary-mode
(make-local-variable 'gnus-summary-dummy-line-format)
(make-local-variable 'gnus-summary-dummy-line-format-spec)
(make-local-variable 'gnus-summary-mark-positions)
+ (make-local-variable 'gnus-article-buffer)
+ (make-local-variable 'gnus-article-current)
+ (make-local-variable 'gnus-original-article-buffer)
(add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
- (gnus-run-mode-hooks 'gnus-summary-mode-hook)
- (turn-on-gnus-mailing-list-mode)
(mm-enable-multibyte)
(set (make-local-variable 'bookmark-make-record-function)
- 'gnus-summary-bookmark-make-record)
- (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
- (gnus-update-summary-mark-positions))
+ 'gnus-summary-bookmark-make-record))
(defun gnus-summary-make-local-variables ()
"Make all the local summary buffer variables."
@@ -3478,8 +3465,11 @@ gnus-summary-set-article-display-arrow
(current-buffer))))))
(defun gnus-summary-setup-buffer (group)
- "Initialize summary buffer.
-If the setup was successful, non-nil is returned."
+ "Initialize summary buffer for GROUP.
+This function does all setup work that relies on the specific
+value of GROUP, and puts the buffer in `gnus-summary-mode'.
+
+Returns non-nil if the setup was successful."
(let ((buffer (gnus-summary-buffer-name group))
(dead-name (concat "*Dead Summary "
(gnus-group-decoded-name group) "*")))
@@ -3493,13 +3483,15 @@ gnus-summary-setup-buffer
(not gnus-newsgroup-prepared))
(set-buffer (gnus-get-buffer-create buffer))
(setq gnus-summary-buffer (current-buffer))
- (gnus-summary-mode group)
+ (gnus-summary-mode)
(when (gnus-group-quit-config group)
(set (make-local-variable 'gnus-single-article-buffer) nil))
- (make-local-variable 'gnus-article-buffer)
- (make-local-variable 'gnus-article-current)
- (make-local-variable 'gnus-original-article-buffer)
(setq gnus-newsgroup-name group)
+ (turn-on-gnus-mailing-list-mode)
+ ;; This function doesn't currently depend on GROUP, but might in
+ ;; the future.
+ (gnus-update-summary-mark-positions)
+ (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
;; Set any local variables in the group parameters.
(gnus-summary-set-local-parameters gnus-newsgroup-name)
t)))
@@ -3935,6 +3927,15 @@ gnus-summary-read-group
(defun gnus-summary-read-group-1 (group show-all no-article
kill-buffer no-display
&optional select-articles)
+ "Display articles and threads in a Summary buffer for GROUP."
+ ;; This function calls `gnus-summary-setup-buffer' to create the
+ ;; buffer, put it in `gnus-summary-mode', and set local variables;
+ ;; `gnus-select-newsgroup' to update the group's active and marks
+ ;; from the server; and `gnus-summary-prepare' to actually insert
+ ;; lines for articles. The rest of the function is mostly concerned
+ ;; with limiting and positioning and windowing and other visual
+ ;; effects.
+
;; Killed foreign groups can't be entered.
;; (when (and (not (gnus-group-native-p group))
;; (not (gnus-gethash group gnus-newsrc-hashtb)))
diff --git a/lisp/gnus/gnus.el b/lisp/gnus/gnus.el
index 2786323f67..6c59b13574 100644
--- a/lisp/gnus/gnus.el
+++ b/lisp/gnus/gnus.el
@@ -637,6 +637,12 @@ gnus-summary-low-read
"Face used for low interest read articles."
:group 'gnus-summary)
+;;; Base gnus-mode
+
+(define-derived-mode gnus-mode special-mode nil
+ "Base mode from which all other gnus modes derive.
+This does nothing but derive from `special-mode', and should not
+be used directly.")
;;;
;;; Gnus buffers
--
2.19.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* bug#33263: 27.0.50; Tidying up Gnus modes, [PATCH] Provide new gnus-mode, derive all gnus major modes from this
2018-11-10 4:01 ` bug#33263: 27.0.50; Tidying up Gnus modes, [PATCH] Provide new gnus-mode, derive all gnus major modes from this Noam Postavsky
@ 2018-11-10 4:55 ` Eric Abrahamsen
2018-11-10 20:18 ` Eric Abrahamsen
0 siblings, 1 reply; 11+ messages in thread
From: Eric Abrahamsen @ 2018-11-10 4:55 UTC (permalink / raw)
To: Noam Postavsky; +Cc: 33263, Lars Ingebrigtsen
Noam Postavsky <npostavs@gmail.com> writes:
> [forwarding to list]
[...]
Bah, sorry about that.
And it turns out that the mark position stuff does depend on the group!
In mysterious ways that aren't clear to me yet. So I'll continue poking
at this patch until I've got a better sense of how stuff interacts.
Eric
^ permalink raw reply [flat|nested] 11+ messages in thread
* bug#33263: 27.0.50; Tidying up Gnus modes, [PATCH] Provide new gnus-mode, derive all gnus major modes from this
2018-11-10 4:55 ` Eric Abrahamsen
@ 2018-11-10 20:18 ` Eric Abrahamsen
0 siblings, 0 replies; 11+ messages in thread
From: Eric Abrahamsen @ 2018-11-10 20:18 UTC (permalink / raw)
To: Noam Postavsky; +Cc: 33263, Lars Ingebrigtsen
[-- Attachment #1: Type: text/plain, Size: 543 bytes --]
Eric Abrahamsen <eric@ericabrahamsen.net> writes:
> Noam Postavsky <npostavs@gmail.com> writes:
>
>> [forwarding to list]
>
> [...]
>
> Bah, sorry about that.
>
> And it turns out that the mark position stuff does depend on the group!
> In mysterious ways that aren't clear to me yet. So I'll continue poking
> at this patch until I've got a better sense of how stuff interacts.
Aaaand... It wasn't that mysterious after all, I'd transposed two
function calls. Here's the patch that I'm dog-fooding, and I will be
quiet for a while.
Eric
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Provide-new-gnus-mode-derive-all-gnus-major-modes-fr.patch --]
[-- Type: text/x-patch, Size: 16739 bytes --]
From 002d08bb05fbb070cd4082094174dd3f0d35f187 Mon Sep 17 00:00:00 2001
From: Eric Abrahamsen <eric@ericabrahamsen.net>
Date: Mon, 25 Jun 2018 17:40:19 -0700
Subject: [PATCH] Provide new gnus-mode, derive all gnus major modes from this
* lisp/gnus/gnus.el (gnus-mode): New do-nothing major mode, derived
from special mode.
* lisp/gnus/gnus-sum.el (gnus-summary-mode): Change from a function to
a major mode, derive from gnus-mode.
(gnus-summary-setup-buffer): Change call a bit -- can no longer pass
an argument to the mode function.
* lisp/gnus/gnus-srvr.el (gnus-browse-mode): Derive from gnus-mode.
(gnus-server-setup-buffer): Remove unnecessary function.
(gnus-enter-server-buffer): Call gnus-server-mode here, and call it
whether the server buffer already existed or not.
(gnus-server-mode): Change from a function to a major mode.
(gnus-server-mode-hook): Delete custom option, this is automatically
created.
* lisp/gnus/gnus-salt.el (gnus-tree-mode): Derive from gnus-mode.
(gnus-tree-mode-hook): Delete custom option, this is automatically
created.
* lisp/gnus/gnus-kill.el (gnus-kill-file-mode-hook): Delete custom
option.
* lisp/gnus/gnus-group.el (gnus-group-mode):
* lisp/gnus/gnus-art.el (gnus-article-mode):
* lisp/gnus/gnus-agent.el (gnus-category-mode): Derive from gnus-mode.
(gnus-category-mode-hook): Delete custom option.
---
lisp/gnus/gnus-agent.el | 10 ++------
lisp/gnus/gnus-art.el | 8 ++-----
lisp/gnus/gnus-group.el | 8 ++-----
lisp/gnus/gnus-kill.el | 5 ----
lisp/gnus/gnus-salt.el | 9 +-------
lisp/gnus/gnus-srvr.el | 44 ++++++++---------------------------
lisp/gnus/gnus-sum.el | 51 +++++++++++++++++++++--------------------
lisp/gnus/gnus.el | 6 +++++
8 files changed, 48 insertions(+), 93 deletions(-)
diff --git a/lisp/gnus/gnus-agent.el b/lisp/gnus/gnus-agent.el
index 18e6174fa0..93a675584f 100644
--- a/lisp/gnus/gnus-agent.el
+++ b/lisp/gnus/gnus-agent.el
@@ -2575,9 +2575,6 @@ gnus-agent-fetch-group-1
;;; Agent Category Mode
;;;
-(defvar gnus-category-mode-hook nil
- "Hook run in `gnus-category-mode' buffers.")
-
(defvar gnus-category-line-format " %(%20c%): %g\n"
"Format of category lines.
@@ -2613,7 +2610,6 @@ gnus-category-line-format-spec
(defvar gnus-category-mode-line-format-spec nil)
(defvar gnus-category-mode-map nil)
-(put 'gnus-category-mode 'mode-class 'special)
(unless gnus-category-mode-map
(setq gnus-category-mode-map (make-sparse-keymap))
@@ -2655,9 +2651,8 @@ gnus-category-make-menu-bar
(gnus-run-hooks 'gnus-category-menu-hook)))
-(define-derived-mode gnus-category-mode fundamental-mode "Category"
+(define-derived-mode gnus-category-mode gnus-mode "Category"
"Major mode for listing and editing agent categories.
-
All normal editing commands are switched off.
\\<gnus-category-mode-map>
For more in-depth information on this mode, read the manual
@@ -2672,8 +2667,7 @@ gnus-category-mode
(gnus-set-default-directory)
(setq mode-line-process nil)
(buffer-disable-undo)
- (setq truncate-lines t)
- (setq buffer-read-only t))
+ (setq truncate-lines t))
(defalias 'gnus-category-position-point 'gnus-goto-colon)
diff --git a/lisp/gnus/gnus-art.el b/lisp/gnus/gnus-art.el
index f28e6db3c7..c78bb3325f 100644
--- a/lisp/gnus/gnus-art.el
+++ b/lisp/gnus/gnus-art.el
@@ -4388,8 +4388,6 @@ article-verify-cancel-lock
;;; Gnus article mode
;;;
-(put 'gnus-article-mode 'mode-class 'special)
-
(set-keymap-parent gnus-article-mode-map widget-keymap)
(gnus-define-keys gnus-article-mode-map
@@ -4467,9 +4465,8 @@ gnus-article-make-menu-bar
(defvar bookmark-make-record-function)
(defvar shr-put-image-function)
-(define-derived-mode gnus-article-mode fundamental-mode "Article"
+(define-derived-mode gnus-article-mode gnus-mode "Article"
"Major mode for displaying an article.
-
All normal editing commands are switched off.
The following commands are available in addition to all summary mode
@@ -4510,8 +4507,7 @@ gnus-article-mode
(setq cursor-in-non-selected-windows nil))
(gnus-set-default-directory)
(buffer-disable-undo)
- (setq buffer-read-only t
- show-trailing-whitespace nil)
+ (setq show-trailing-whitespace nil)
(mm-enable-multibyte))
(defun gnus-article-setup-buffer ()
diff --git a/lisp/gnus/gnus-group.el b/lisp/gnus/gnus-group.el
index 6af27afbfa..d526894b3a 100644
--- a/lisp/gnus/gnus-group.el
+++ b/lisp/gnus/gnus-group.el
@@ -567,8 +567,6 @@ gnus-group-list-option
;;; Gnus group mode
;;;
-(put 'gnus-group-mode 'mode-class 'special)
-
(gnus-define-keys gnus-group-mode-map
" " gnus-group-read-group
"=" gnus-group-select-group
@@ -1106,9 +1104,8 @@ gnus-group-make-tool-bar
(set (make-local-variable 'tool-bar-map) map))))
gnus-group-tool-bar-map)
-(define-derived-mode gnus-group-mode fundamental-mode "Group"
+(define-derived-mode gnus-group-mode gnus-mode "Group"
"Major mode for reading news.
-
All normal editing commands are switched off.
\\<gnus-group-mode-map>
The group buffer lists (some of) the groups available. For instance,
@@ -1131,8 +1128,7 @@ gnus-group-mode
(setq mode-line-process nil)
(buffer-disable-undo)
(setq truncate-lines t)
- (setq buffer-read-only t
- show-trailing-whitespace nil)
+ (setq show-trailing-whitespace nil)
(gnus-set-default-directory)
(gnus-update-format-specifications nil 'group 'group-mode)
(gnus-update-group-mark-positions)
diff --git a/lisp/gnus/gnus-kill.el b/lisp/gnus/gnus-kill.el
index 60732c11d5..e65ff51ce7 100644
--- a/lisp/gnus/gnus-kill.el
+++ b/lisp/gnus/gnus-kill.el
@@ -29,11 +29,6 @@
(require 'gnus-art)
(require 'gnus-range)
-(defcustom gnus-kill-file-mode-hook nil
- "Hook for Gnus kill file mode."
- :group 'gnus-score-kill
- :type 'hook)
-
(defcustom gnus-kill-expiry-days 7
"Number of days before expiring unused kill file entries."
:group 'gnus-score-kill
diff --git a/lisp/gnus/gnus-salt.el b/lisp/gnus/gnus-salt.el
index aff841760a..0504465de3 100644
--- a/lisp/gnus/gnus-salt.el
+++ b/lisp/gnus/gnus-salt.el
@@ -396,11 +396,6 @@ gnus-generate-tree-function
(function :tag "Other" nil))
:group 'gnus-summary-tree)
-(defcustom gnus-tree-mode-hook nil
- "Hook run in tree mode buffers."
- :type 'hook
- :group 'gnus-summary-tree)
-
;;; Internal variables.
(defvar gnus-tmp-name)
@@ -445,8 +440,6 @@ gnus-tree-mode-map
'undefined 'gnus-tree-read-summary-keys map)
map))
-(put 'gnus-tree-mode 'mode-class 'special)
-
(defun gnus-tree-make-menu-bar ()
(unless (boundp 'gnus-tree-menu)
(easy-menu-define
@@ -454,7 +447,7 @@ gnus-tree-make-menu-bar
'("Tree"
["Select article" gnus-tree-select-article t]))))
-(define-derived-mode gnus-tree-mode fundamental-mode "Tree"
+(define-derived-mode gnus-tree-mode gnus-mode "Tree"
"Major mode for displaying thread trees."
(gnus-set-format 'tree-mode)
(gnus-set-format 'tree t)
diff --git a/lisp/gnus/gnus-srvr.el b/lisp/gnus/gnus-srvr.el
index dfca5e9d2c..400199083a 100644
--- a/lisp/gnus/gnus-srvr.el
+++ b/lisp/gnus/gnus-srvr.el
@@ -36,11 +36,6 @@
(autoload 'gnus-group-make-nnir-group "nnir")
-(defcustom gnus-server-mode-hook nil
- "Hook run in `gnus-server-mode' buffers."
- :group 'gnus-server
- :type 'hook)
-
(defcustom gnus-server-exit-hook nil
"Hook run when exiting the server buffer."
:group 'gnus-server
@@ -108,7 +103,7 @@ gnus-server-line-format-spec
(defvar gnus-server-mode-line-format-spec nil)
(defvar gnus-server-killed-servers nil)
-(defvar gnus-server-mode-map)
+(defvar gnus-server-mode-map nil)
(defcustom gnus-server-menu-hook nil
"Hook run after the creation of the server mode menu."
@@ -150,11 +145,8 @@ gnus-server-make-menu-bar
(gnus-run-hooks 'gnus-server-menu-hook)))
-(defvar gnus-server-mode-map nil)
-(put 'gnus-server-mode 'mode-class 'special)
-
(unless gnus-server-mode-map
- (setq gnus-server-mode-map (make-sparse-keymap))
+ (setq gnus-server-mode-map (make-keymap))
(suppress-keymap gnus-server-mode-map)
(gnus-define-keys gnus-server-mode-map
@@ -253,9 +245,8 @@ gnus-server-font-lock-keywords
("(\\(offline\\))" 1 'gnus-server-offline)
("(\\(denied\\))" 1 'gnus-server-denied)))
-(defun gnus-server-mode ()
+(define-derived-mode gnus-server-mode gnus-mode "Server"
"Major mode for listing and editing servers.
-
All normal editing commands are switched off.
\\<gnus-server-mode-map>
For more in-depth information on this mode, read the manual
@@ -264,23 +255,16 @@ gnus-server-mode
The following commands are available:
\\{gnus-server-mode-map}"
- ;; FIXME: Use define-derived-mode.
- (interactive)
(when (gnus-visual-p 'server-menu 'menu)
(gnus-server-make-menu-bar))
- (kill-all-local-variables)
(gnus-simplify-mode-line)
- (setq major-mode 'gnus-server-mode)
- (setq mode-name "Server")
(gnus-set-default-directory)
(setq mode-line-process nil)
- (use-local-map gnus-server-mode-map)
(buffer-disable-undo)
(setq truncate-lines t)
- (setq buffer-read-only t)
(set (make-local-variable 'font-lock-defaults)
- '(gnus-server-font-lock-keywords t))
- (gnus-run-mode-hooks 'gnus-server-mode-hook))
+ '(gnus-server-font-lock-keywords t)))
+
(defun gnus-server-insert-server-line (name method)
(let* ((gnus-tmp-name name)
@@ -320,21 +304,15 @@ gnus-server-insert-server-line
(defun gnus-enter-server-buffer ()
"Set up the server buffer."
- (gnus-server-setup-buffer)
(gnus-configure-windows 'server)
;; Usually `gnus-configure-windows' will finish with the
;; `gnus-server-buffer' selected as the current buffer, but not always (I
;; bumped into it when starting from a dedicated *Group* frame, and
;; gnus-configure-windows opened *Server* into its own dedicated frame).
- (with-current-buffer (get-buffer gnus-server-buffer)
+ (with-current-buffer (get-buffer-create gnus-server-buffer)
+ (gnus-server-mode)
(gnus-server-prepare)))
-(defun gnus-server-setup-buffer ()
- "Initialize the server buffer."
- (unless (get-buffer gnus-server-buffer)
- (with-current-buffer (gnus-get-buffer-create gnus-server-buffer)
- (gnus-server-mode))))
-
(defun gnus-server-prepare ()
(gnus-set-format 'server-mode)
(gnus-set-format 'server t)
@@ -717,9 +695,7 @@ gnus-browse-subscribe-newsgroup-method
function
(repeat function)))
-(defvar gnus-browse-mode-hook nil)
(defvar gnus-browse-mode-map nil)
-(put 'gnus-browse-mode 'mode-class 'special)
(unless gnus-browse-mode-map
(setq gnus-browse-mode-map (make-keymap))
@@ -897,9 +873,8 @@ gnus-browse-foreign-server
(gnus-message 5 "Connecting to %s...done" (nth 1 method))
t))))
-(define-derived-mode gnus-browse-mode fundamental-mode "Browse Server"
+(define-derived-mode gnus-browse-mode gnus-mode "Browse Server"
"Major mode for browsing a foreign server.
-
All normal editing commands are switched off.
\\<gnus-browse-mode-map>
@@ -918,8 +893,7 @@ gnus-browse-mode
(setq mode-line-process nil)
(buffer-disable-undo)
(setq truncate-lines t)
- (gnus-set-default-directory)
- (setq buffer-read-only t))
+ (gnus-set-default-directory))
(defun gnus-browse-read-group (&optional no-article number)
"Enter the group at the current line.
diff --git a/lisp/gnus/gnus-sum.el b/lisp/gnus/gnus-sum.el
index f9fae3792b..1c4be09e2e 100644
--- a/lisp/gnus/gnus-sum.el
+++ b/lisp/gnus/gnus-sum.el
@@ -1842,8 +1842,6 @@ gnus-summary-bubble-group
;;; Gnus summary mode
;;;
-(put 'gnus-summary-mode 'mode-class 'special)
-
(defvar gnus-article-commands-menu)
;; Non-orthogonal keys
@@ -3052,10 +3050,8 @@ bookmark-make-record-function
\f
(defvar bidi-paragraph-direction)
-(defun gnus-summary-mode (&optional group)
+(define-derived-mode gnus-summary-mode gnus-mode "Summary"
"Major mode for reading articles.
-
-All normal editing commands are switched off.
\\<gnus-summary-mode-map>
Each line in this buffer represents one article. To read an
article, you can, for instance, type `\\[gnus-summary-next-page]'. To move forwards
@@ -3072,24 +3068,16 @@ gnus-summary-mode
The following commands are available:
\\{gnus-summary-mode-map}"
- ;; FIXME: Use define-derived-mode.
- (interactive)
- (kill-all-local-variables)
(let ((gnus-summary-local-variables gnus-newsgroup-variables))
(gnus-summary-make-local-variables))
(gnus-summary-make-local-variables)
- (setq gnus-newsgroup-name group)
(when (gnus-visual-p 'summary-menu 'menu)
(gnus-summary-make-menu-bar)
(gnus-summary-make-tool-bar))
(gnus-make-thread-indent-array)
(gnus-simplify-mode-line)
- (setq major-mode 'gnus-summary-mode)
- (setq mode-name "Summary")
- (use-local-map gnus-summary-mode-map)
(buffer-disable-undo)
- (setq buffer-read-only t
- show-trailing-whitespace nil
+ (setq show-trailing-whitespace nil
truncate-lines t
bidi-paragraph-direction 'left-to-right)
(add-to-invisibility-spec '(gnus-sum . t))
@@ -3100,14 +3088,13 @@ gnus-summary-mode
(make-local-variable 'gnus-summary-dummy-line-format)
(make-local-variable 'gnus-summary-dummy-line-format-spec)
(make-local-variable 'gnus-summary-mark-positions)
+ (make-local-variable 'gnus-article-buffer)
+ (make-local-variable 'gnus-article-current)
+ (make-local-variable 'gnus-original-article-buffer)
(add-hook 'pre-command-hook 'gnus-set-global-variables nil t)
- (gnus-run-mode-hooks 'gnus-summary-mode-hook)
- (turn-on-gnus-mailing-list-mode)
(mm-enable-multibyte)
(set (make-local-variable 'bookmark-make-record-function)
- 'gnus-summary-bookmark-make-record)
- (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
- (gnus-update-summary-mark-positions))
+ 'gnus-summary-bookmark-make-record))
(defun gnus-summary-make-local-variables ()
"Make all the local summary buffer variables."
@@ -3478,8 +3465,11 @@ gnus-summary-set-article-display-arrow
(current-buffer))))))
(defun gnus-summary-setup-buffer (group)
- "Initialize summary buffer.
-If the setup was successful, non-nil is returned."
+ "Initialize summary buffer for GROUP.
+This function does all setup work that relies on the specific
+value of GROUP, and puts the buffer in `gnus-summary-mode'.
+
+Returns non-nil if the setup was successful."
(let ((buffer (gnus-summary-buffer-name group))
(dead-name (concat "*Dead Summary "
(gnus-group-decoded-name group) "*")))
@@ -3493,13 +3483,15 @@ gnus-summary-setup-buffer
(not gnus-newsgroup-prepared))
(set-buffer (gnus-get-buffer-create buffer))
(setq gnus-summary-buffer (current-buffer))
- (gnus-summary-mode group)
+ (gnus-summary-mode)
(when (gnus-group-quit-config group)
(set (make-local-variable 'gnus-single-article-buffer) nil))
- (make-local-variable 'gnus-article-buffer)
- (make-local-variable 'gnus-article-current)
- (make-local-variable 'gnus-original-article-buffer)
(setq gnus-newsgroup-name group)
+ (turn-on-gnus-mailing-list-mode)
+ ;; These functions don't currently depend on GROUP, but might in
+ ;; the future.
+ (gnus-update-format-specifications nil 'summary 'summary-mode 'summary-dummy)
+ (gnus-update-summary-mark-positions)
;; Set any local variables in the group parameters.
(gnus-summary-set-local-parameters gnus-newsgroup-name)
t)))
@@ -3935,6 +3927,15 @@ gnus-summary-read-group
(defun gnus-summary-read-group-1 (group show-all no-article
kill-buffer no-display
&optional select-articles)
+ "Display articles and threads in a Summary buffer for GROUP."
+ ;; This function calls `gnus-summary-setup-buffer' to create the
+ ;; buffer, put it in `gnus-summary-mode', and set local variables;
+ ;; `gnus-select-newsgroup' to update the group's active and marks
+ ;; from the server; and `gnus-summary-prepare' to actually insert
+ ;; lines for articles. The rest of the function is mostly concerned
+ ;; with limiting and positioning and windowing and other visual
+ ;; effects.
+
;; Killed foreign groups can't be entered.
;; (when (and (not (gnus-group-native-p group))
;; (not (gnus-gethash group gnus-newsrc-hashtb)))
diff --git a/lisp/gnus/gnus.el b/lisp/gnus/gnus.el
index 2786323f67..6c59b13574 100644
--- a/lisp/gnus/gnus.el
+++ b/lisp/gnus/gnus.el
@@ -637,6 +637,12 @@ gnus-summary-low-read
"Face used for low interest read articles."
:group 'gnus-summary)
+;;; Base gnus-mode
+
+(define-derived-mode gnus-mode special-mode nil
+ "Base mode from which all other gnus modes derive.
+This does nothing but derive from `special-mode', and should not
+be used directly.")
;;;
;;; Gnus buffers
--
2.19.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* bug#33263: 27.0.50; Tidying up Gnus modes
2018-11-05 2:53 bug#33263: 27.0.50; Tidying up Gnus modes Eric Abrahamsen
2018-11-05 14:14 ` Noam Postavsky
2018-11-10 4:01 ` bug#33263: 27.0.50; Tidying up Gnus modes, [PATCH] Provide new gnus-mode, derive all gnus major modes from this Noam Postavsky
@ 2018-11-23 17:45 ` Eric Abrahamsen
2 siblings, 0 replies; 11+ messages in thread
From: Eric Abrahamsen @ 2018-11-23 17:45 UTC (permalink / raw)
To: 33263-done
Okay, I've been running this for more than a week and it seems fine so
far. I'll push it, and watch for repercussions.
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2018-11-23 17:45 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-11-05 2:53 bug#33263: 27.0.50; Tidying up Gnus modes Eric Abrahamsen
2018-11-05 14:14 ` Noam Postavsky
2018-11-05 17:51 ` Eric Abrahamsen
2018-11-06 13:27 ` Noam Postavsky
2018-11-06 16:21 ` Eric Abrahamsen
2018-11-06 16:28 ` Noam Postavsky
2018-11-06 17:37 ` Eric Abrahamsen
2018-11-10 4:01 ` bug#33263: 27.0.50; Tidying up Gnus modes, [PATCH] Provide new gnus-mode, derive all gnus major modes from this Noam Postavsky
2018-11-10 4:55 ` Eric Abrahamsen
2018-11-10 20:18 ` Eric Abrahamsen
2018-11-23 17:45 ` bug#33263: 27.0.50; Tidying up Gnus modes Eric Abrahamsen
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.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).