From: Tak Kunihiro <tkk@misasa.okayama-u.ac.jp>
To: eliz@gnu.org
Cc: tkk@misasa.okayama-u.ac.jp, 26599@debbugs.gnu.org
Subject: bug#26599: patch for mwheel.el
Date: Fri, 28 Apr 2017 18:12:50 +0900 (JST) [thread overview]
Message-ID: <20170428.181250.449319557.tkk@misasa.okayama-u.ac.jp> (raw)
In-Reply-To: <83wpa5m3jk.fsf@gnu.org>
[-- Attachment #1: Type: Text/Plain, Size: 1313 bytes --]
>> >> Keyboard is the primary scroll device. Thus I want to turn
>> >> auto-hscroll-mode t by default.
>> >>
>> >> Occasionally I want to use mouse as scroll device. When I use mouse,
>> >> I want to set turn auto-hscroll-mode nil, especially after
>> >> implementation of <wheel-right> and <wheel-left>.
>> >>
>> >> When I come back to keyboard, I want to set auto-hscroll-mode t again.
>> >
>> > This looks like a very specialized use case, so I'm not sure we need a
>> > solution for it in Emacs.
>>
>> I see how you see.
>>
>> How I described, is similar to how spreadsheet program reacts. It
>> lets user scroll both by <wheel-left> and <left>.
>>
>> I very often edit a buffer with long and short line (for example,
>> LaTeX table), using mouse and keyboard. However, as you infer, this
>> can be already very special.
>
> What makes this special is that you want Emacs to work differently
> depending on the input device. Emacs normally makes a significant
> effort in the other direction: to produce the same behavior no matter
> where input came from.
>
> I'm not sure we want to have such unusual behavior as part of Emacs.
Can you take a look minor-mode that I want to invoke by hook? I still
think this is potentially useful to mouse-loving cloud using
<wheel-left> and <wheel-right>.
[-- Attachment #2: touchpad.el --]
[-- Type: Text/Plain, Size: 7601 bytes --]
;;; touchpad.el --- Scroll two dimensionally by touchpad
;; Copyright (C) 2017 Tak Kunihiro
;; Author: Tak Kunihiro <tkk@misasa.okayama-u.ac.jp>
;; Maintainer: Tak Kunihiro <tkk@misasa.okayama-u.ac.jp>
;; URL: http://dream.misasa.okayama-u.ac.jp
;; Package-Requires: ((emacs "26.1"))
;; Version: 1.0.0
;; Package-Version: 20170427.1515
;; Keywords: mouse, scroll
;;; This file is NOT part of GNU Emacs
;;; License
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 3, or (at your option)
;; any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program; see the file COPYING. If not, write to
;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth
;; Floor, Boston, MA 02110-1301, USA.
;;; Commentary:
;; To interactively toggle the mode:
;;
;; M-x touchpad-mode
;;
;; To make the mode permanent, add the following lines to your init
;; file.
;;
;; (require 'touchpad)
;; (touchpad-mode 1)
;;
;; This package offers a global minor mode which makes swiping
;; touchpad scroll smoothly. This package disables
;; `auto-hscroll-mode' during scroll because of following two aspects.
;; (1) It should be off during vertical scroll. Let’s consider a
;; buffer is with short and long alternative lines and when point
;; is at the end of long line, at the top of current window.
;; After `scroll-up 1', point jumps to the end of the next short
;; line and you see scope shifts suddenly leftward. This behavior
;; is sometimes unexpected one.
;; (2) It should be off during horizontal scroll. During horizontal
;; scroll, you may scroll a little in vertical direction without
;; intention. The horizontal scroll should be tolerance against
;; such perturbation. The source of concern is same as (1).
;; After scroll, you want to set `auto-hscroll-mode' back again
;; otherwise too inconvenient for further edition. Approach of this
;; package is to turn on another minor-mode `touchpad--2d-mode' with
;; `auto-hscroll-mode' nil at the beginning of `mwheel-scroll'. The
;; minor mode is turned off upon any key inputs that move point.
;;; Change Log:
;; 20170409.1204
;; - (setq scroll-conservatively 100) on minor mode may work as backup
;;; Todo:
;; - Release as a package
(require 'mwheel)
;;; Code:
(defvar touchpad--cursor-type cursor-type
"Cursor used by user. This variable is used internally to
restore original `cursor-type'.")
(define-minor-mode touchpad-mode
"A minor mode to scroll text two dimensionally. With a prefix argument ARG,
enable Touchpad Mode if ARG is positive, and disable it
otherwise. If called from Lisp, enable Touchpad Mode if ARG is
omitted or nil."
:init-value nil
:group 'scrolling
:global t
(if touchpad-mode
(progn
(advice-add 'mwheel-scroll :before 'touchpad-enable--2d-mode)
;; (add-hook 'mwheel-pre-scroll-hook 'touchpad-enable--2d-mode)
(setq mwheel-tilt-scroll-p t))
(advice-remove 'mwheel-scroll #'touchpad-enable--2d-mode)
;; (remove-hook 'mwheel-pre-scroll-hook 'touchpad-enable--2d-mode)
(dolist (var '(mwheel-tilt-scroll-p))
(custom-reevaluate-setting var))))
;; (defun touchpad-enable--2d-mode ()
;; "Enable minor mode `touchpad--2d-mode' to disable
;; `auto-hscroll-mode'. This is supposed to be called before actual
;; scrolling."
;; (let ((buffer (window-buffer (mwheel-event-window last-input-event))))
;; (with-current-buffer buffer
;; (touchpad--2d-mode 1)))) ; turn on minor-mode
(defun touchpad-enable--2d-mode (func &rest args)
"Enable minor mode `touchpad--2d-mode' to disable
`auto-hscroll-mode'. This is supposed to be adviced before
`mwheel-scroll'."
(let ((buffer (window-buffer (mwheel-event-window last-input-event))))
(with-current-buffer buffer
(touchpad--2d-mode 1)))) ; turn on minor-mode
(defun touchpad-disable--2d-mode ()
"Disable minor mode `touchpad--2d-mode' to enable
`auto-hscroll-mode' back. Then invoke command that is bound to
the original key."
(interactive)
(touchpad--2d-mode 0) ; turn off minor-mode
(call-interactively (key-binding (this-command-keys))))
(define-minor-mode touchpad--2d-mode
"A minor-mode with `auto-hscroll-mode' off. This minor mode is used
internally."
:init-value nil
:keymap (let ((map (make-sparse-keymap)))
(define-key map [remap keyboard-quit] 'touchpad-disable--2d-mode)
(define-key map [remap mouse-set-point] 'touchpad-disable--2d-mode)
(define-key map [remap right-char] 'touchpad-disable--2d-mode)
(define-key map [remap forward-char] 'touchpad-disable--2d-mode)
(define-key map [remap forward-word] 'touchpad-disable--2d-mode)
(define-key map [remap forward-sentence] 'touchpad-disable--2d-mode)
(define-key map [remap forward-paragraph] 'touchpad-disable--2d-mode)
(define-key map [remap forward-page] 'touchpad-disable--2d-mode)
(define-key map [remap left-char] 'touchpad-disable--2d-mode)
(define-key map [remap backward-char] 'touchpad-disable--2d-mode)
(define-key map [remap backward-word] 'touchpad-disable--2d-mode)
(define-key map [remap backward-sentence] 'touchpad-disable--2d-mode)
(define-key map [remap backward-paragraph] 'touchpad-disable--2d-mode)
(define-key map [remap backward-page] 'touchpad-disable--2d-mode)
(define-key map [remap move-beginning-of-line] 'touchpad-disable--2d-mode)
(define-key map [remap move-end-of-line] 'touchpad-disable--2d-mode)
(define-key map [remap next-line] 'touchpad-disable--2d-mode)
(define-key map [remap next-error] 'touchpad-disable--2d-mode)
(define-key map [remap scroll-up-command] 'touchpad-disable--2d-mode)
(define-key map [remap previous-line] 'touchpad-disable--2d-mode)
(define-key map [remap previous-error] 'touchpad-disable--2d-mode)
(define-key map [remap scroll-down-command] 'touchpad-disable--2d-mode)
(define-key map [remap beginning-of-defun] 'touchpad-disable--2d-mode)
(define-key map [remap beginning-of-buffer] 'touchpad-disable--2d-mode)
(define-key map [remap end-of-defun] 'touchpad-disable--2d-mode)
(define-key map [remap end-of-buffer] 'touchpad-disable--2d-mode)
(define-key map [remap goto-char] 'touchpad-disable--2d-mode)
(define-key map [remap goto-line] 'touchpad-disable--2d-mode)
(define-key map [remap move-to-column] 'touchpad-disable--2d-mode)
;; list as much as think of ... or map all but
;; (where-is-internal 'mwheel-scroll)?
map)
:group 'scrolling
(if touchpad--2d-mode
(progn
(setq-local auto-hscroll-mode nil)
(setq-local cursor-type 'hollow))
(setq-local auto-hscroll-mode t)
(setq-local cursor-type touchpad--cursor-type)))
(provide 'touchpad)
;;; touchpad.el ends here
next prev parent reply other threads:[~2017-04-28 9:12 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-22 1:27 bug#26599: patch for mwheel.el Tak Kunihiro
2017-04-22 7:52 ` Eli Zaretskii
2017-04-23 6:13 ` Tak Kunihiro
2017-04-26 5:01 ` Eli Zaretskii
2017-04-26 6:08 ` Tak Kunihiro
2017-04-26 10:50 ` Eli Zaretskii
2017-04-26 12:32 ` Tak Kunihiro
2017-04-26 15:31 ` Eli Zaretskii
2017-04-26 23:33 ` Tak Kunihiro
2017-04-27 2:36 ` Eli Zaretskii
2017-04-27 5:27 ` Tak Kunihiro
2017-04-27 14:25 ` Eli Zaretskii
2017-04-27 23:16 ` Tak Kunihiro
2017-04-28 6:47 ` Eli Zaretskii
2017-04-28 9:12 ` Tak Kunihiro [this message]
2017-05-19 8:55 ` Eli Zaretskii
2019-06-24 16:38 ` Lars Ingebrigtsen
2020-01-20 20:06 ` Stefan Kangas
2020-01-20 22:47 ` Juri Linkov
2020-01-21 7:17 ` Tak Kunihiro
2020-01-21 9:46 ` Stefan Kangas
2020-01-22 5:46 ` Tak Kunihiro
2020-03-13 23:43 ` Tak Kunihiro
2020-03-13 23:52 ` Tak Kunihiro
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170428.181250.449319557.tkk@misasa.okayama-u.ac.jp \
--to=tkk@misasa.okayama-u.ac.jp \
--cc=26599@debbugs.gnu.org \
--cc=eliz@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 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.