unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Kangas <stefan@marxist.se>
To: Eli Zaretskii <eliz@gnu.org>
Cc: "Tak Kunihiro" <homeros.misasa@gmail.com>,
	"Juri Linkov" <juri@linkov.net>, "Richard Stallman" <rms@gnu.org>,
	28182@debbugs.gnu.org, "積丹尼 Dan Jacobson" <jidanni@jidanni.org>
Subject: bug#28182: maybe implement CTRL++ to zoom text
Date: Sat, 28 Sep 2019 16:15:38 +0200	[thread overview]
Message-ID: <CADwFkmmr-L=FY0vEgS8LBAKjXc+Wok-UARhWx0hL-Q7PmjL9=Q@mail.gmail.com> (raw)
In-Reply-To: <83lfu8h6pn.fsf@gnu.org>

[-- Attachment #1: Type: text/plain, Size: 1229 bytes --]

Eli Zaretskii <eliz@gnu.org> writes:

> > I've attached a tentative patch along those lines.  WDYT?
>
> Any reason to make the new behavior be the default, i.e. break
> backward compatibility?  Why not make this an opt-in feature instead?

I think it's a better default, since it's more in line with user
expectations.  The "Ctrl+mouse whell changes font size" behaviour is
pretty ubiquitous in browsers, text editors and IDEs.  From the top of
my head, you can change the font size (sometimes called "zoom") using
this shortcut in Firefox, Chrome, Safari, Eclipse, LibreOffice, Adobe
Reader, evince, and many, many others.  From searching the web, this
seems to be the default also in Atom, Sublime Text, TextMate,
Notepad++ and IntelliJ.  VSCode stands out by making this optional.

We could of course make it an opt-in feature should we want to do that.

> > I'm not sure exactly how to reformulate the doc string for
> > mouse-wheel-scroll-amount to fit the new behaviour.  I'll have to
> > think about it a bit more.  Do let me know if you have any ideas.
>
> I'm not sure we need to change the doc string, but we definitely need
> to change the :version tag.

Fixed that in the attached patch.

Best regards,
Stefan Kangas

[-- Attachment #2: 0001-Support-changing-font-size-using-mouse-wheel.patch --]
[-- Type: text/x-patch, Size: 8199 bytes --]

From 3814fcf37ba429b302add3591b6dbb255496a20e Mon Sep 17 00:00:00 2001
From: Stefan Kangas <stefankangas@gmail.com>
Date: Wed, 21 Aug 2019 03:38:49 +0200
Subject: [PATCH] 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.
---
 doc/emacs/frames.texi | 10 +++---
 etc/NEWS              | 12 +++++++
 lisp/mwheel.el        | 75 ++++++++++++++++++++++++++++++-------------
 3 files changed, 71 insertions(+), 26 deletions(-)

diff --git a/doc/emacs/frames.texi b/doc/emacs/frames.texi
index 367ac43a0a..1f4aa95c87 100644
--- a/doc/emacs/frames.texi
+++ b/doc/emacs/frames.texi
@@ -200,10 +200,12 @@ Mouse Commands
 @vindex mouse-wheel-progressive-speed
   Some mice have a ``wheel'' which can be used for scrolling.  Emacs
 supports scrolling windows with the mouse wheel, by default, on most
-graphical displays.  To toggle this feature, use @kbd{M-x
-mouse-wheel-mode}.  The variables @code{mouse-wheel-follow-mouse} and
-@code{mouse-wheel-scroll-amount} determine where and by how much
-buffers are scrolled.  The variable
+graphical displays.  There is also support for increasing or
+decreasing the height of the default face, by default bound to
+scrolling with the @key{Ctrl} modifier.  To toggle this feature, use
+@kbd{M-x mouse-wheel-mode}.  The variables
+@code{mouse-wheel-follow-mouse} and @code{mouse-wheel-scroll-amount}
+determine where and by how much buffers are scrolled.  The variable
 @code{mouse-wheel-progressive-speed} determines whether the scroll
 speed is linked to how fast you move the wheel.
 
diff --git a/etc/NEWS b/etc/NEWS
index 97b96d1e4e..c50ccd5309 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -2212,6 +2212,18 @@ bool vector.
 ** 'regexp-quote' may return its argument string.
 If the argument needs no quoting, it can be returned instead of a copy.
 
++++
+** Mouse scroll up and down with control key modifier changes font size.
+Previously, the control key modifier was used to scroll up or down by
+an amount which was close to near a full screen.  This is now instead
+available by scrolling with the meta modifier key.
+
+To get the old behaviour back, customize the variable
+'mouse-wheel-scroll-amount', or add the following to your init file:
+
+(customize-set-variable 'mouse-wheel-scroll-amount
+                        '(5 ((shift) . 1) ((control) . nil)))
+
 \f
 * Lisp Changes in Emacs 27.1
 
diff --git a/lisp/mwheel.el b/lisp/mwheel.el
index dfea55374b..f05aae5369 100644
--- a/lisp/mwheel.el
+++ b/lisp/mwheel.el
@@ -84,17 +84,22 @@ mouse-wheel-inhibit-click-time
   :group 'mouse
   :type 'number)
 
-(defcustom mouse-wheel-scroll-amount '(5 ((shift) . 1) ((control) . nil))
+(defcustom mouse-wheel-scroll-amount
+  '(5 ((shift) . 1) ((meta) . nil) ((control) . text-scale))
   "Amount to scroll windows by when spinning the mouse wheel.
 This is an alist mapping the modifier key to the amount to scroll when
 the wheel is moved with the modifier key depressed.
-Elements of the list have the form (MODIFIERS . AMOUNT) or just AMOUNT if
-MODIFIERS is nil.
+Elements of the list have the form (MODIFIER . AMOUNT) or just AMOUNT if
+MODIFIER is nil.
 
 AMOUNT should be the number of lines to scroll, or nil for near full
 screen.  It can also be a floating point number, specifying the fraction of
 a full screen to scroll.  A near full screen is `next-screen-context-lines'
-less than a full screen."
+less than a full screen.
+
+If AMOUNT is the symbol text-scale, this means that with
+MODIFIER, the mouse wheel will change the face height instead of
+scrolling."
   :group 'mouse
   :type '(cons
 	  (choice :tag "Normal"
@@ -105,20 +110,22 @@ mouse-wheel-scroll-amount
 		   (repeat (choice :tag "modifier"
 				   (const alt) (const control) (const hyper)
 				   (const meta) (const shift) (const super)))
-		   (choice :tag "scroll amount"
-			   (const :tag "Full screen" :value nil)
-			   (integer :tag "Specific # of lines")
-			   (float :tag "Fraction of window"))))
+		   (choice :tag "action"
+			   (const :tag "Scroll full screen" :value nil)
+			   (integer :tag "Scroll specific # of lines")
+			   (float :tag "Scroll fraction of window"))))
           (repeat
            (cons
             (repeat (choice :tag "modifier"
 			    (const alt) (const control) (const hyper)
                             (const meta) (const shift) (const super)))
-            (choice :tag "scroll amount"
-                    (const :tag "Full screen" :value nil)
-                    (integer :tag "Specific # of lines")
-                    (float :tag "Fraction of window")))))
-  :set 'mouse-wheel-change-button)
+            (choice :tag "action"
+                    (const :tag "Scroll full screen" :value nil)
+                    (integer :tag "Scroll specific # of lines")
+                    (float :tag "Scroll fraction of window")
+                    (const :tag "Change face size" :value text-scale)))))
+  :set 'mouse-wheel-change-button
+  :version "27.1")
 
 (defcustom mouse-wheel-progressive-speed t
   "If non-nil, the faster the user moves the wheel, the faster the scrolling.
@@ -306,6 +313,15 @@ mwheel-scroll
 (put 'mwheel-scroll 'scroll-command t)
 
 (defvar mwheel-installed-bindings nil)
+(defvar mwheel-installed-text-scale-bindings nil)
+
+(defun mouse-wheel--remove-bindings (bindings funs)
+  "Remove key BINDINGS if they're bound to any function in FUNS.
+BINDINGS is a list of key bindings, FUNS is a list of functions.
+This is a helper function for `mouse-wheel-mode'."
+  (dolist (key bindings)
+    (when (memq (lookup-key (current-global-map) key) funs)
+      (global-unset-key key))))
 
 (define-minor-mode mouse-wheel-mode
   "Toggle mouse wheel support (Mouse Wheel mode)."
@@ -318,17 +334,32 @@ mouse-wheel-mode
   :global t
   :group 'mouse
   ;; Remove previous bindings, if any.
-  (while mwheel-installed-bindings
-    (let ((key (pop mwheel-installed-bindings)))
-      (when (eq (lookup-key (current-global-map) key) 'mwheel-scroll)
-        (global-unset-key key))))
+  (mouse-wheel--remove-bindings mwheel-installed-bindings
+                                '(mwheel-scroll))
+  (mouse-wheel--remove-bindings mwheel-installed-text-scale-bindings
+                                '(text-scale-increase
+                                  text-scale-decrease))
+  (setq mwheel-installed-bindings nil)
+  (setq mwheel-installed-text-scale-bindings nil)
   ;; Setup bindings as needed.
   (when mouse-wheel-mode
-    (dolist (event (list mouse-wheel-down-event mouse-wheel-up-event mouse-wheel-right-event mouse-wheel-left-event))
-      (dolist (key (mapcar (lambda (amt) `[(,@(if (consp amt) (car amt)) ,event)])
-                           mouse-wheel-scroll-amount))
-        (global-set-key key 'mwheel-scroll)
-        (push key mwheel-installed-bindings)))))
+    (dolist (binding mouse-wheel-scroll-amount)
+      (cond
+       ;; Bindings for changing font size.
+       ((and (consp binding) (eq (cdr binding) 'text-scale))
+        (let ((increase-key `[,(list (caar binding) mouse-wheel-down-event)])
+              (decrease-key `[,(list (caar binding) mouse-wheel-up-event)]))
+          (global-set-key increase-key 'text-scale-increase)
+          (global-set-key decrease-key 'text-scale-decrease)
+          (push increase-key mwheel-installed-text-scale-bindings)
+          (push decrease-key mwheel-installed-text-scale-bindings)))
+       ;; Bindings for scrolling.
+       (t
+        (dolist (event (list mouse-wheel-down-event mouse-wheel-up-event
+                             mouse-wheel-right-event mouse-wheel-left-event))
+          (let ((key `[(,@(if (consp binding) (car binding)) ,event)]))
+            (global-set-key key 'mwheel-scroll)
+            (push key mwheel-installed-bindings))))))))
 
 ;;; Compatibility entry point
 ;; preloaded ;;;###autoload
-- 
2.20.1


  reply	other threads:[~2019-09-28 14:15 UTC|newest]

Thread overview: 72+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-29 23:06 bug#39847: Document how users can make text-zoom keys same as browser 積丹尼 Dan Jacobson
2020-03-01  3:39 ` Eli Zaretskii
2020-03-01  5:23   ` 積丹尼 Dan Jacobson
2020-03-01 15:45     ` Eli Zaretskii
2020-03-02  0:23       ` 積丹尼 Dan Jacobson
2020-03-03  3:37   ` Richard Stallman
2020-03-03 15:32     ` Drew Adams
2020-03-03 16:31       ` 積丹尼 Dan Jacobson
2020-03-03 19:55       ` Stefan Kangas
2017-08-22  3:05         ` bug#28182: maybe implement CTRL++ to zoom text 積丹尼 Dan Jacobson
2017-08-22 12:30           ` Nathan Moreau
2017-08-22 14:30           ` Eli Zaretskii
2017-08-23 14:16             ` Richard Stallman
2017-08-23 17:55               ` Eli Zaretskii
2017-08-23 23:05               ` Tak Kunihiro
2017-08-23 23:23                 ` Drew Adams
2017-08-23 14:57           ` 積丹尼 Dan Jacobson
2017-08-23 15:55             ` Drew Adams
2017-08-23 16:05           ` 積丹尼 Dan Jacobson
2017-08-23 16:19             ` Drew Adams
2017-08-23 23:11           ` 積丹尼 Dan Jacobson
2017-08-23 23:28             ` Drew Adams
2019-08-21  1:51           ` Stefan Kangas
2019-08-21  2:12             ` Drew Adams
2019-08-21 13:19               ` Stefan Kangas
2019-08-24 22:06                 ` Juri Linkov
2019-08-27  0:40                   ` Stefan Kangas
2019-08-27 21:13                     ` Juri Linkov
2019-09-28 13:09                       ` Stefan Kangas
2019-09-28 13:48                         ` Eli Zaretskii
2019-09-28 14:15                           ` Stefan Kangas [this message]
2019-09-29  1:09                             ` Richard Stallman
2019-09-29  1:40                               ` Stefan Kangas
2019-09-29  7:36                                 ` Eli Zaretskii
2019-09-29 15:33                                   ` Richard Stallman
2019-09-29 15:40                                     ` Eli Zaretskii
2019-09-29 15:37                                 ` Richard Stallman
2019-09-29 15:44                                   ` Eli Zaretskii
2019-09-29 23:36                                     ` Richard Stallman
2019-09-30  3:52                                       ` Lars Ingebrigtsen
2019-09-30  6:16                                       ` Eli Zaretskii
2019-09-30  9:02                                         ` Robert Pluim
2019-09-30  9:16                                           ` Eli Zaretskii
2019-10-02 20:17                                             ` Alan Third
2019-09-30 14:57                                         ` Richard Stallman
2019-10-15  6:42                                           ` Stefan Kangas
2019-10-15 14:15                                             ` Drew Adams
2019-10-16  3:29                                               ` Richard Stallman
2019-10-15 17:51                                             ` Juri Linkov
2019-10-16  3:27                                             ` Richard Stallman
2019-10-05 23:56                             ` Stefan Kangas
2019-10-06 17:28                               ` Eli Zaretskii
2019-10-06 19:59                                 ` Stefan Kangas
2019-10-07 18:22                                   ` Juri Linkov
2019-10-08 14:56                                     ` Stefan Kangas
2019-10-08 21:58                                       ` Stefan Kangas
2019-10-09  6:08                                         ` Eli Zaretskii
2019-10-09 21:56                                           ` Stefan Kangas
2019-10-10  7:26                                             ` Eli Zaretskii
2019-10-11  0:18                                               ` Stefan Kangas
2019-10-10  8:00                                             ` Robert Pluim
2019-10-11  0:24                                               ` Stefan Kangas
2019-10-11  5:53                                                 ` Robert Pluim
2019-10-13 22:05                                                   ` Stefan Kangas
2019-10-09 20:54                                         ` Juri Linkov
2020-03-03 20:03           ` bug#28182: bug#39847: Document how users can make text-zoom keys same as browser 積丹尼 Dan Jacobson
2020-03-03 20:24         ` Drew Adams
2020-03-03 20:51           ` Stefan Kangas
2020-03-03 21:04             ` 積丹尼 Dan Jacobson
2020-03-03 21:13             ` Drew Adams
2020-08-05 12:08         ` bug#28182: " Lars Ingebrigtsen
     [not found] <<87y3qcs3nf.fsf@jidanni.org>
     [not found] ` <<831so3bror.fsf@gnu.org>
     [not found]   ` <<E1dkWS3-0005Wd-6g@fencepost.gnu.org>
2017-08-23 14:29     ` bug#28182: maybe implement CTRL++ to zoom text Drew Adams

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CADwFkmmr-L=FY0vEgS8LBAKjXc+Wok-UARhWx0hL-Q7PmjL9=Q@mail.gmail.com' \
    --to=stefan@marxist.se \
    --cc=28182@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=homeros.misasa@gmail.com \
    --cc=jidanni@jidanni.org \
    --cc=juri@linkov.net \
    --cc=rms@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).