* bug#60334: [PATCH] whitespace: Use `define-globalized-minor-mode' for global mode
@ 2022-12-26 6:32 Richard Hansen
2022-12-31 8:20 ` Eli Zaretskii
0 siblings, 1 reply; 4+ messages in thread
From: Richard Hansen @ 2022-12-26 6:32 UTC (permalink / raw)
To: 60334
[-- Attachment #1.1.1: Type: text/plain, Size: 456 bytes --]
Attached patch:
whitespace: Use `define-globalized-minor-mode' for global mode
* lisp/whitespace.el (global-whitespace-mode): Fix interoperability
between `whitespace-mode' and `global-whitespace-mode' by using
`define-globalized-minor-mode'.
* test/lisp/whitespace-tests.el (whitespace-tests--global): Add a
regression test.
It would be nice to install this on emacs-29, but I'm OK with this going
on master.
[-- Attachment #1.1.2: 0001-whitespace-Use-define-globalized-minor-mode-for-glob.patch --]
[-- Type: text/x-patch, Size: 3925 bytes --]
From 55b683aa6b821564ec235fb02b48bec6d9f9630a Mon Sep 17 00:00:00 2001
From: Richard Hansen <rhansen@rhansen.org>
Date: Sat, 10 Dec 2022 00:57:15 -0500
Subject: [PATCH] whitespace: Use `define-globalized-minor-mode' for global
mode
* lisp/whitespace.el (global-whitespace-mode): Fix interoperability
between `whitespace-mode' and `global-whitespace-mode' by using
`define-globalized-minor-mode'.
* test/lisp/whitespace-tests.el (whitespace-tests--global): Add a
regression test.
---
lisp/whitespace.el | 35 ++++++-----------------------------
test/lisp/whitespace-tests.el | 18 ++++++++++++++++++
2 files changed, 24 insertions(+), 29 deletions(-)
diff --git a/lisp/whitespace.el b/lisp/whitespace.el
index bc9d4b7998..3dc4771da2 100644
--- a/lisp/whitespace.el
+++ b/lisp/whitespace.el
@@ -1014,34 +1014,11 @@ whitespace-newline-mode
;;;###autoload
-(define-minor-mode global-whitespace-mode
- "Toggle whitespace visualization globally (Global Whitespace mode).
-
-See also `whitespace-style', `whitespace-newline' and
-`whitespace-display-mappings'."
- :lighter " WS"
+(define-globalized-minor-mode global-whitespace-mode
+ whitespace-mode
+ whitespace-turn-on-if-enabled
:init-value nil
- :global t
- :group 'whitespace
- (cond
- (noninteractive ; running a batch job
- (setq global-whitespace-mode nil))
- (global-whitespace-mode ; global-whitespace-mode on
- (save-current-buffer
- (add-hook 'find-file-hook 'whitespace-turn-on-if-enabled)
- (add-hook 'after-change-major-mode-hook 'whitespace-turn-on-if-enabled)
- (dolist (buffer (buffer-list)) ; adjust all local mode
- (set-buffer buffer)
- (unless whitespace-mode
- (whitespace-turn-on-if-enabled)))))
- (t ; global-whitespace-mode off
- (save-current-buffer
- (remove-hook 'find-file-hook 'whitespace-turn-on-if-enabled)
- (remove-hook 'after-change-major-mode-hook 'whitespace-turn-on-if-enabled)
- (dolist (buffer (buffer-list)) ; adjust all local mode
- (set-buffer buffer)
- (unless whitespace-mode
- (whitespace-turn-off)))))))
+ :group 'whitespace)
(defvar whitespace-enable-predicate
(lambda ()
@@ -1067,7 +1044,7 @@ whitespace-enable-predicate
(defun whitespace-turn-on-if-enabled ()
(when (funcall whitespace-enable-predicate)
- (whitespace-turn-on)))
+ (whitespace-mode)))
;;;###autoload
(define-minor-mode global-whitespace-newline-mode
@@ -2559,7 +2536,7 @@ whitespace-display-char-on
(setq whitespace-display-table-was-local t)
;; Save the old table so we can restore it when
;; `whitespace-mode' is switched off again.
- (when (or whitespace-mode global-whitespace-mode)
+ (when whitespace-mode
(setq whitespace-display-table
(copy-sequence buffer-display-table)))
;; Assure `buffer-display-table' is unique
diff --git a/test/lisp/whitespace-tests.el b/test/lisp/whitespace-tests.el
index 513328f5c7..e93d7ec92b 100644
--- a/test/lisp/whitespace-tests.el
+++ b/test/lisp/whitespace-tests.el
@@ -57,6 +57,24 @@ whitespace-tests--cleanup-string
(whitespace-cleanup)
(buffer-string)))
+(ert-deftest whitespace-tests--global ()
+ (let ((backup global-whitespace-mode)
+ (noninteractive nil)
+ (whitespace-enable-predicate (lambda () t)))
+ (unwind-protect
+ (progn
+ (global-whitespace-mode 1)
+ (ert-with-test-buffer-selected ()
+ (normal-mode)
+ (should whitespace-mode)
+ (global-whitespace-mode -1)
+ (should (null whitespace-mode))
+ (whitespace-mode 1)
+ (should whitespace-mode)
+ (global-whitespace-mode 1)
+ (should whitespace-mode)))
+ (global-whitespace-mode (if backup 1 -1)))))
+
(ert-deftest whitespace-tests--clear-markers ()
(whitespace-tests--with-test-buffer '(face empty)
(whitespace-mode -1)
--
2.39.0
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply related [flat|nested] 4+ messages in thread
* bug#60334: [PATCH] whitespace: Use `define-globalized-minor-mode' for global mode
2022-12-26 6:32 bug#60334: [PATCH] whitespace: Use `define-globalized-minor-mode' for global mode Richard Hansen
@ 2022-12-31 8:20 ` Eli Zaretskii
2022-12-31 8:29 ` Richard Hansen
0 siblings, 1 reply; 4+ messages in thread
From: Eli Zaretskii @ 2022-12-31 8:20 UTC (permalink / raw)
To: Richard Hansen; +Cc: 60334
> Date: Mon, 26 Dec 2022 01:32:20 -0500
> From: Richard Hansen <rhansen@rhansen.org>
>
> Attached patch:
>
> whitespace: Use `define-globalized-minor-mode' for global mode
>
> * lisp/whitespace.el (global-whitespace-mode): Fix interoperability
> between `whitespace-mode' and `global-whitespace-mode' by using
> `define-globalized-minor-mode'.
> * test/lisp/whitespace-tests.el (whitespace-tests--global): Add a
> regression test.
>
> It would be nice to install this on emacs-29, but I'm OK with this going
> on master.
I tried to install this on master (it's too late for such changes on
the emacs-29 branch), but the patch failed to apply. Could you please
rebase this on master and resubmit?
Thanks.
^ permalink raw reply [flat|nested] 4+ messages in thread
* bug#60334: [PATCH] whitespace: Use `define-globalized-minor-mode' for global mode
2022-12-31 8:20 ` Eli Zaretskii
@ 2022-12-31 8:29 ` Richard Hansen
2022-12-31 8:49 ` Eli Zaretskii
0 siblings, 1 reply; 4+ messages in thread
From: Richard Hansen @ 2022-12-31 8:29 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: 60334
[-- Attachment #1.1.1: Type: text/plain, Size: 256 bytes --]
On 12/31/22 03:20, Eli Zaretskii wrote:
> I tried to install this on master (it's too late for such changes on
> the emacs-29 branch), but the patch failed to apply. Could you please
> rebase this on master and resubmit?
See attached.
Thanks!
[-- Attachment #1.1.2: v2-0001-whitespace-Use-define-globalized-minor-mode-for-g.patch --]
[-- Type: text/x-patch, Size: 3939 bytes --]
From c3f7656456c1c8d2d35584b3361aab0f02840416 Mon Sep 17 00:00:00 2001
From: Richard Hansen <rhansen@rhansen.org>
Date: Sat, 10 Dec 2022 00:57:15 -0500
Subject: [PATCH v2] whitespace: Use `define-globalized-minor-mode' for global
mode
* lisp/whitespace.el (global-whitespace-mode): Fix interoperability
between `whitespace-mode' and `global-whitespace-mode' by using
`define-globalized-minor-mode'.
* test/lisp/whitespace-tests.el (whitespace-tests--global): Add a
regression test.
---
lisp/whitespace.el | 35 ++++++-----------------------------
test/lisp/whitespace-tests.el | 18 ++++++++++++++++++
2 files changed, 24 insertions(+), 29 deletions(-)
diff --git a/lisp/whitespace.el b/lisp/whitespace.el
index 558be1841a..7a30274a33 100644
--- a/lisp/whitespace.el
+++ b/lisp/whitespace.el
@@ -1014,34 +1014,11 @@ whitespace-newline-mode
;;;###autoload
-(define-minor-mode global-whitespace-mode
- "Toggle whitespace visualization globally (Global Whitespace mode).
-
-See also `whitespace-style', `whitespace-newline' and
-`whitespace-display-mappings'."
- :lighter " WS"
+(define-globalized-minor-mode global-whitespace-mode
+ whitespace-mode
+ whitespace-turn-on-if-enabled
:init-value nil
- :global t
- :group 'whitespace
- (cond
- (noninteractive ; running a batch job
- (setq global-whitespace-mode nil))
- (global-whitespace-mode ; global-whitespace-mode on
- (save-current-buffer
- (add-hook 'find-file-hook 'whitespace-turn-on-if-enabled)
- (add-hook 'after-change-major-mode-hook 'whitespace-turn-on-if-enabled)
- (dolist (buffer (buffer-list)) ; adjust all local mode
- (set-buffer buffer)
- (unless whitespace-mode
- (whitespace-turn-on-if-enabled)))))
- (t ; global-whitespace-mode off
- (save-current-buffer
- (remove-hook 'find-file-hook 'whitespace-turn-on-if-enabled)
- (remove-hook 'after-change-major-mode-hook 'whitespace-turn-on-if-enabled)
- (dolist (buffer (buffer-list)) ; adjust all local mode
- (set-buffer buffer)
- (unless whitespace-mode
- (whitespace-turn-off)))))))
+ :group 'whitespace)
(defvar whitespace-enable-predicate
(lambda ()
@@ -1067,7 +1044,7 @@ whitespace-enable-predicate
(defun whitespace-turn-on-if-enabled ()
(when (funcall whitespace-enable-predicate)
- (whitespace-turn-on)))
+ (whitespace-mode)))
;;;###autoload
(define-minor-mode global-whitespace-newline-mode
@@ -2511,7 +2488,7 @@ whitespace-display-char-on
(setq whitespace-display-table-was-local t)
;; Save the old table so we can restore it when
;; `whitespace-mode' is switched off again.
- (when (or whitespace-mode global-whitespace-mode)
+ (when whitespace-mode
(setq whitespace-display-table
(copy-sequence buffer-display-table)))
;; Assure `buffer-display-table' is unique
diff --git a/test/lisp/whitespace-tests.el b/test/lisp/whitespace-tests.el
index d72748cd0c..3a53e02503 100644
--- a/test/lisp/whitespace-tests.el
+++ b/test/lisp/whitespace-tests.el
@@ -57,6 +57,24 @@ whitespace-tests--cleanup-string
(whitespace-cleanup)
(buffer-string)))
+(ert-deftest whitespace-tests--global ()
+ (let ((backup global-whitespace-mode)
+ (noninteractive nil)
+ (whitespace-enable-predicate (lambda () t)))
+ (unwind-protect
+ (progn
+ (global-whitespace-mode 1)
+ (ert-with-test-buffer-selected ()
+ (normal-mode)
+ (should whitespace-mode)
+ (global-whitespace-mode -1)
+ (should (null whitespace-mode))
+ (whitespace-mode 1)
+ (should whitespace-mode)
+ (global-whitespace-mode 1)
+ (should whitespace-mode)))
+ (global-whitespace-mode (if backup 1 -1)))))
+
(ert-deftest whitespace-cleanup-eob ()
(let ((whitespace-style '(empty)))
(should (equal (whitespace-tests--cleanup-string "a\n")
--
2.39.0
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply related [flat|nested] 4+ messages in thread
* bug#60334: [PATCH] whitespace: Use `define-globalized-minor-mode' for global mode
2022-12-31 8:29 ` Richard Hansen
@ 2022-12-31 8:49 ` Eli Zaretskii
0 siblings, 0 replies; 4+ messages in thread
From: Eli Zaretskii @ 2022-12-31 8:49 UTC (permalink / raw)
To: Richard Hansen; +Cc: 60334-done
> Date: Sat, 31 Dec 2022 03:29:43 -0500
> Cc: 60334@debbugs.gnu.org
> From: Richard Hansen <rhansen@rhansen.org>
>
> On 12/31/22 03:20, Eli Zaretskii wrote:
> > I tried to install this on master (it's too late for such changes on
> > the emacs-29 branch), but the patch failed to apply. Could you please
> > rebase this on master and resubmit?
>
> See attached.
Thanks, installed on master, and closing the bug.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-12-31 8:49 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-26 6:32 bug#60334: [PATCH] whitespace: Use `define-globalized-minor-mode' for global mode Richard Hansen
2022-12-31 8:20 ` Eli Zaretskii
2022-12-31 8:29 ` Richard Hansen
2022-12-31 8:49 ` Eli Zaretskii
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.