aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorStefan Kangas2019-08-21 03:38:49 +0200
committerStefan Kangas2019-10-06 21:57:58 +0200
commitdc8108e10910352ab97c8200b23672072c374a91 (patch)
treeb485dce08b9c1904abec8ecf0b7db8d359d27d5d /lisp
parent8de2e69f021b5b2920a07d82c9869bb394171d41 (diff)
downloademacs-dc8108e10910352ab97c8200b23672072c374a91.tar.gz
emacs-dc8108e10910352ab97c8200b23672072c374a91.zip
Support changing font size using mouse wheel
* lisp/mwheel.el (mouse-wheel-mode): Support changing font size (text scaling) using mouse wheel. (Bug#28182) (mouse-wheel-scroll-amount): Bind the Ctrl modifier to text scaling. (mwheel-installed-text-scale-bindings): New variable. (mouse-wheel--remove-bindings): New helper function for 'mouse-wheel-mode'. * doc/emacs/frames.texi (Mouse Commands): Document this feature. * etc/NEWS: Announce it.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/mwheel.el75
1 files changed, 53 insertions, 22 deletions
diff --git a/lisp/mwheel.el b/lisp/mwheel.el
index 4862406fa19..9b67e71886f 100644
--- a/lisp/mwheel.el
+++ b/lisp/mwheel.el
@@ -84,17 +84,22 @@ set to the event sent when clicking on the mouse wheel button."
84 :group 'mouse 84 :group 'mouse
85 :type 'number) 85 :type 'number)
86 86
87(defcustom mouse-wheel-scroll-amount '(5 ((shift) . 1) ((control) . nil)) 87(defcustom mouse-wheel-scroll-amount
88 '(5 ((shift) . 1) ((meta) . nil) ((control) . text-scale))
88 "Amount to scroll windows by when spinning the mouse wheel. 89 "Amount to scroll windows by when spinning the mouse wheel.
89This is an alist mapping the modifier key to the amount to scroll when 90This is an alist mapping the modifier key to the amount to scroll when
90the wheel is moved with the modifier key depressed. 91the wheel is moved with the modifier key depressed.
91Elements of the list have the form (MODIFIERS . AMOUNT) or just AMOUNT if 92Elements of the list have the form (MODIFIER . AMOUNT) or just AMOUNT if
92MODIFIERS is nil. 93MODIFIER is nil.
93 94
94AMOUNT should be the number of lines to scroll, or nil for near full 95AMOUNT should be the number of lines to scroll, or nil for near full
95screen. It can also be a floating point number, specifying the fraction of 96screen. It can also be a floating point number, specifying the fraction of
96a full screen to scroll. A near full screen is `next-screen-context-lines' 97a full screen to scroll. A near full screen is `next-screen-context-lines'
97less than a full screen." 98less than a full screen.
99
100If AMOUNT is the symbol text-scale, this means that with
101MODIFIER, the mouse wheel will change the face height instead of
102scrolling."
98 :group 'mouse 103 :group 'mouse
99 :type '(cons 104 :type '(cons
100 (choice :tag "Normal" 105 (choice :tag "Normal"
@@ -105,20 +110,22 @@ less than a full screen."
105 (repeat (choice :tag "modifier" 110 (repeat (choice :tag "modifier"
106 (const alt) (const control) (const hyper) 111 (const alt) (const control) (const hyper)
107 (const meta) (const shift) (const super))) 112 (const meta) (const shift) (const super)))
108 (choice :tag "scroll amount" 113 (choice :tag "action"
109 (const :tag "Full screen" :value nil) 114 (const :tag "Scroll full screen" :value nil)
110 (integer :tag "Specific # of lines") 115 (integer :tag "Scroll specific # of lines")
111 (float :tag "Fraction of window")))) 116 (float :tag "Scroll fraction of window"))))
112 (repeat 117 (repeat
113 (cons 118 (cons
114 (repeat (choice :tag "modifier" 119 (repeat (choice :tag "modifier"
115 (const alt) (const control) (const hyper) 120 (const alt) (const control) (const hyper)
116 (const meta) (const shift) (const super))) 121 (const meta) (const shift) (const super)))
117 (choice :tag "scroll amount" 122 (choice :tag "action"
118 (const :tag "Full screen" :value nil) 123 (const :tag "Scroll full screen" :value nil)
119 (integer :tag "Specific # of lines") 124 (integer :tag "Scroll specific # of lines")
120 (float :tag "Fraction of window"))))) 125 (float :tag "Scroll fraction of window")
121 :set 'mouse-wheel-change-button) 126 (const :tag "Change face size" :value text-scale)))))
127 :set 'mouse-wheel-change-button
128 :version "27.1")
122 129
123(defcustom mouse-wheel-progressive-speed t 130(defcustom mouse-wheel-progressive-speed t
124 "If non-nil, the faster the user moves the wheel, the faster the scrolling. 131 "If non-nil, the faster the user moves the wheel, the faster the scrolling.
@@ -316,6 +323,15 @@ non-Windows systems."
316(put 'mwheel-scroll 'scroll-command t) 323(put 'mwheel-scroll 'scroll-command t)
317 324
318(defvar mwheel-installed-bindings nil) 325(defvar mwheel-installed-bindings nil)
326(defvar mwheel-installed-text-scale-bindings nil)
327
328(defun mouse-wheel--remove-bindings (bindings funs)
329 "Remove key BINDINGS if they're bound to any function in FUNS.
330BINDINGS is a list of key bindings, FUNS is a list of functions.
331This is a helper function for `mouse-wheel-mode'."
332 (dolist (key bindings)
333 (when (memq (lookup-key (current-global-map) key) funs)
334 (global-unset-key key))))
319 335
320(define-minor-mode mouse-wheel-mode 336(define-minor-mode mouse-wheel-mode
321 "Toggle mouse wheel support (Mouse Wheel mode)." 337 "Toggle mouse wheel support (Mouse Wheel mode)."
@@ -328,17 +344,32 @@ non-Windows systems."
328 :global t 344 :global t
329 :group 'mouse 345 :group 'mouse
330 ;; Remove previous bindings, if any. 346 ;; Remove previous bindings, if any.
331 (while mwheel-installed-bindings 347 (mouse-wheel--remove-bindings mwheel-installed-bindings
332 (let ((key (pop mwheel-installed-bindings))) 348 '(mwheel-scroll))
333 (when (eq (lookup-key (current-global-map) key) 'mwheel-scroll) 349 (mouse-wheel--remove-bindings mwheel-installed-text-scale-bindings
334 (global-unset-key key)))) 350 '(text-scale-increase
351 text-scale-decrease))
352 (setq mwheel-installed-bindings nil)
353 (setq mwheel-installed-text-scale-bindings nil)
335 ;; Setup bindings as needed. 354 ;; Setup bindings as needed.
336 (when mouse-wheel-mode 355 (when mouse-wheel-mode
337 (dolist (event (list mouse-wheel-down-event mouse-wheel-up-event mouse-wheel-right-event mouse-wheel-left-event)) 356 (dolist (binding mouse-wheel-scroll-amount)
338 (dolist (key (mapcar (lambda (amt) `[(,@(if (consp amt) (car amt)) ,event)]) 357 (cond
339 mouse-wheel-scroll-amount)) 358 ;; Bindings for changing font size.
340 (global-set-key key 'mwheel-scroll) 359 ((and (consp binding) (eq (cdr binding) 'text-scale))
341 (push key mwheel-installed-bindings))))) 360 (let ((increase-key `[,(list (caar binding) mouse-wheel-down-event)])
361 (decrease-key `[,(list (caar binding) mouse-wheel-up-event)]))
362 (global-set-key increase-key 'text-scale-increase)
363 (global-set-key decrease-key 'text-scale-decrease)
364 (push increase-key mwheel-installed-text-scale-bindings)
365 (push decrease-key mwheel-installed-text-scale-bindings)))
366 ;; Bindings for scrolling.
367 (t
368 (dolist (event (list mouse-wheel-down-event mouse-wheel-up-event
369 mouse-wheel-right-event mouse-wheel-left-event))
370 (let ((key `[(,@(if (consp binding) (car binding)) ,event)]))
371 (global-set-key key 'mwheel-scroll)
372 (push key mwheel-installed-bindings))))))))
342 373
343;;; Compatibility entry point 374;;; Compatibility entry point
344;; preloaded ;;;###autoload 375;; preloaded ;;;###autoload