diff options
| author | Stefan Kangas | 2019-08-21 03:38:49 +0200 |
|---|---|---|
| committer | Stefan Kangas | 2019-10-06 21:57:58 +0200 |
| commit | dc8108e10910352ab97c8200b23672072c374a91 (patch) | |
| tree | b485dce08b9c1904abec8ecf0b7db8d359d27d5d | |
| parent | 8de2e69f021b5b2920a07d82c9869bb394171d41 (diff) | |
| download | emacs-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.
| -rw-r--r-- | doc/emacs/frames.texi | 10 | ||||
| -rw-r--r-- | etc/NEWS | 12 | ||||
| -rw-r--r-- | lisp/mwheel.el | 75 |
3 files changed, 71 insertions, 26 deletions
diff --git a/doc/emacs/frames.texi b/doc/emacs/frames.texi index ba1424aa2a3..869b77d86bd 100644 --- a/doc/emacs/frames.texi +++ b/doc/emacs/frames.texi | |||
| @@ -201,10 +201,12 @@ deactivating the mark. @xref{Shift Selection}. | |||
| 201 | @vindex mouse-wheel-progressive-speed | 201 | @vindex mouse-wheel-progressive-speed |
| 202 | Some mice have a ``wheel'' which can be used for scrolling. Emacs | 202 | Some mice have a ``wheel'' which can be used for scrolling. Emacs |
| 203 | supports scrolling windows with the mouse wheel, by default, on most | 203 | supports scrolling windows with the mouse wheel, by default, on most |
| 204 | graphical displays. To toggle this feature, use @kbd{M-x | 204 | graphical displays. There is also support for increasing or |
| 205 | mouse-wheel-mode}. The variables @code{mouse-wheel-follow-mouse} and | 205 | decreasing the height of the default face, by default bound to |
| 206 | @code{mouse-wheel-scroll-amount} determine where and by how much | 206 | scrolling with the @key{Ctrl} modifier. To toggle this feature, use |
| 207 | buffers are scrolled. The variable | 207 | @kbd{M-x mouse-wheel-mode}. The variables |
| 208 | @code{mouse-wheel-follow-mouse} and @code{mouse-wheel-scroll-amount} | ||
| 209 | determine where and by how much buffers are scrolled. The variable | ||
| 208 | @code{mouse-wheel-progressive-speed} determines whether the scroll | 210 | @code{mouse-wheel-progressive-speed} determines whether the scroll |
| 209 | speed is linked to how fast you move the wheel. | 211 | speed is linked to how fast you move the wheel. |
| 210 | 212 | ||
| @@ -2309,6 +2309,18 @@ bool vector. | |||
| 2309 | ** 'regexp-quote' may return its argument string. | 2309 | ** 'regexp-quote' may return its argument string. |
| 2310 | If the argument needs no quoting, it can be returned instead of a copy. | 2310 | If the argument needs no quoting, it can be returned instead of a copy. |
| 2311 | 2311 | ||
| 2312 | +++ | ||
| 2313 | ** Mouse scroll up and down with control key modifier changes font size. | ||
| 2314 | Previously, the control key modifier was used to scroll up or down by | ||
| 2315 | an amount which was close to near a full screen. This is now instead | ||
| 2316 | available by scrolling with the meta modifier key. | ||
| 2317 | |||
| 2318 | To get the old behaviour back, customize the variable | ||
| 2319 | 'mouse-wheel-scroll-amount', or add the following to your init file: | ||
| 2320 | |||
| 2321 | (customize-set-variable 'mouse-wheel-scroll-amount | ||
| 2322 | '(5 ((shift) . 1) ((control) . nil))) | ||
| 2323 | |||
| 2312 | 2324 | ||
| 2313 | * Lisp Changes in Emacs 27.1 | 2325 | * Lisp Changes in Emacs 27.1 |
| 2314 | 2326 | ||
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. |
| 89 | This is an alist mapping the modifier key to the amount to scroll when | 90 | This is an alist mapping the modifier key to the amount to scroll when |
| 90 | the wheel is moved with the modifier key depressed. | 91 | the wheel is moved with the modifier key depressed. |
| 91 | Elements of the list have the form (MODIFIERS . AMOUNT) or just AMOUNT if | 92 | Elements of the list have the form (MODIFIER . AMOUNT) or just AMOUNT if |
| 92 | MODIFIERS is nil. | 93 | MODIFIER is nil. |
| 93 | 94 | ||
| 94 | AMOUNT should be the number of lines to scroll, or nil for near full | 95 | AMOUNT should be the number of lines to scroll, or nil for near full |
| 95 | screen. It can also be a floating point number, specifying the fraction of | 96 | screen. It can also be a floating point number, specifying the fraction of |
| 96 | a full screen to scroll. A near full screen is `next-screen-context-lines' | 97 | a full screen to scroll. A near full screen is `next-screen-context-lines' |
| 97 | less than a full screen." | 98 | less than a full screen. |
| 99 | |||
| 100 | If AMOUNT is the symbol text-scale, this means that with | ||
| 101 | MODIFIER, the mouse wheel will change the face height instead of | ||
| 102 | scrolling." | ||
| 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. | ||
| 330 | BINDINGS is a list of key bindings, FUNS is a list of functions. | ||
| 331 | This 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 |