aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Kangas2025-03-14 23:22:11 +0100
committerStefan Kangas2025-03-15 04:06:31 +0100
commit33cc5427cbec224d55fac9d76b7c2978fdd5034b (patch)
tree0389e64e88a309557c08d1bc83e33536d0c4f6cc
parent6b295347a9f7491ae4c16d942b3b12a54fc2373a (diff)
downloademacs-33cc5427cbec224d55fac9d76b7c2978fdd5034b.tar.gz
emacs-33cc5427cbec224d55fac9d76b7c2978fdd5034b.zip
Add :set attribute to winner-dont-bind-my-keys
* lisp/winner.el (winner--set-dont-bind-my-keys): New function. (winner-dont-bind-my-keys): Allow setting with setopt. (winner-mode-map): Use defvar-keymap. * test/lisp/winner-tests.el: New file.
-rw-r--r--lisp/winner.el36
-rw-r--r--test/lisp/winner-tests.el32
2 files changed, 54 insertions, 14 deletions
diff --git a/lisp/winner.el b/lisp/winner.el
index b2f462365cf..7fcb44131e6 100644
--- a/lisp/winner.el
+++ b/lisp/winner.el
@@ -24,11 +24,11 @@
24;;; Commentary: 24;;; Commentary:
25 25
26;; Winner mode is a global minor mode that records the changes in the 26;; Winner mode is a global minor mode that records the changes in the
27;; window configuration (i.e. how the frames are partitioned into 27;; window configuration (in other words, how the frames are partitioned
28;; windows) so that the changes can be "undone" using the command 28;; into windows), so that the changes can be "undone" using the command
29;; `winner-undo'. By default this one is bound to the key sequence 29;; `winner-undo'. By default, it is bound to the key sequence `C-c
30;; ctrl-c left. If you change your mind (while undoing), you can 30;; <left>'. If you change your mind (while undoing), you can press
31;; press ctrl-c right (calling `winner-redo'). 31;; `C-c <right>' (`winner-redo').
32 32
33;;; Code: 33;;; Code:
34 34
@@ -44,9 +44,21 @@
44 "Restoring window configurations." 44 "Restoring window configurations."
45 :group 'windows) 45 :group 'windows)
46 46
47(defun winner--set-dont-bind-my-keys (symbol value)
48 (defvar winner-mode-map)
49 (when (boundp 'winner-mode-map)
50 (if value
51 (progn (keymap-unset winner-mode-map "C-c <left>")
52 (keymap-unset winner-mode-map "C-c <left>"))
53 ;; Default bindings.
54 (keymap-set winner-mode-map "C-c <left>" #'winner-undo)
55 (keymap-set winner-mode-map "C-c <right>" #'winner-redo)))
56 (set-default symbol value))
57
47(defcustom winner-dont-bind-my-keys nil 58(defcustom winner-dont-bind-my-keys nil
48 "Non-nil means do not bind keys in Winner mode." 59 "Non-nil means do not bind default keys in Winner mode."
49 :type 'boolean) 60 :type 'boolean
61 :set #'winner--set-dont-bind-my-keys)
50 62
51(defcustom winner-ring-size 200 63(defcustom winner-ring-size 200
52 "Maximum number of stored window configurations per frame." 64 "Maximum number of stored window configurations per frame."
@@ -321,13 +333,9 @@ You may want to include buffer names such as *Help*, *Apropos*,
321 "Functions to run whenever Winner mode is turned off." 333 "Functions to run whenever Winner mode is turned off."
322 :type 'hook) 334 :type 'hook)
323 335
324(defvar winner-mode-map 336(defvar-keymap winner-mode-map
325 (let ((map (make-sparse-keymap))) 337 :doc "Keymap for Winner mode.")
326 (unless winner-dont-bind-my-keys 338(setopt winner-dont-bind-my-keys winner-dont-bind-my-keys)
327 (define-key map [(control c) left] #'winner-undo)
328 (define-key map [(control c) right] #'winner-redo))
329 map)
330 "Keymap for Winner mode.")
331 339
332(defvar-keymap winner-repeat-map 340(defvar-keymap winner-repeat-map
333 :doc "Keymap to repeat winner key sequences. Used in `repeat-mode'." 341 :doc "Keymap to repeat winner key sequences. Used in `repeat-mode'."
diff --git a/test/lisp/winner-tests.el b/test/lisp/winner-tests.el
new file mode 100644
index 00000000000..549ab2c117e
--- /dev/null
+++ b/test/lisp/winner-tests.el
@@ -0,0 +1,32 @@
1;;; winner-tests.el --- Tests for winner.el -*- lexical-binding: t; -*-
2
3;; Copyright (C) 2025 Free Software Foundation, Inc.
4
5;; This file is part of GNU Emacs.
6
7;; GNU Emacs is free software: you can redistribute it and/or modify
8;; it under the terms of the GNU General Public License as published by
9;; the Free Software Foundation, either version 3 of the License, or
10;; (at your option) any later version.
11
12;; GNU Emacs is distributed in the hope that it will be useful,
13;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15;; GNU General Public License for more details.
16
17;; You should have received a copy of the GNU General Public License
18;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
19
20;;; Code:
21
22(require 'winner)
23
24(ert-deftest winner-dont-bind-my-keys ()
25 (should (keymap-lookup winner-mode-map "C-c <left>"))
26 (setopt winner-dont-bind-my-keys t)
27 (should-not (keymap-lookup winner-mode-map "C-c <left>"))
28 (setopt winner-dont-bind-my-keys nil)
29 (should (keymap-lookup winner-mode-map "C-c <left>")))
30
31(provide 'winner-tests)
32;;; winner-tests.el ends here