Mercurial > hg > xemacs-beta
annotate lisp/mwheel.el @ 5818:15b0715c204d
Avoid passing patterns to with charset property to FcNameUnparse.
Prevents crash reported by Raymond Toy.
| author | Stephen J. Turnbull <stephen@xemacs.org> |
|---|---|
| date | Sat, 18 Oct 2014 21:20:42 +0900 |
| parents | 308d34e9f07d |
| children |
| rev | line source |
|---|---|
| 428 | 1 ;;; mwheel.el --- Mouse support for MS intelli-mouse type mice |
| 2 | |
| 3 ;; Copyright (C) 1998, Free Software Foundation, Inc. | |
| 4 ;; Maintainer: William M. Perry <wmperry@cs.indiana.edu> | |
| 5 ;; Keywords: mouse | |
| 6 | |
| 7 ;; This file is part of XEmacs. | |
| 8 | |
|
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
2546
diff
changeset
|
9 ;; XEmacs is free software: you can redistribute it and/or modify it |
|
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
2546
diff
changeset
|
10 ;; under the terms of the GNU General Public License as published by the |
|
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
2546
diff
changeset
|
11 ;; Free Software Foundation, either version 3 of the License, or (at your |
|
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
2546
diff
changeset
|
12 ;; option) any later version. |
| 428 | 13 |
|
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
2546
diff
changeset
|
14 ;; XEmacs is distributed in the hope that it will be useful, but WITHOUT |
|
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
2546
diff
changeset
|
15 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
2546
diff
changeset
|
16 ;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
2546
diff
changeset
|
17 ;; for more details. |
| 428 | 18 |
| 19 ;; You should have received a copy of the GNU General Public License | |
|
5402
308d34e9f07d
Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents:
2546
diff
changeset
|
20 ;; along with XEmacs. If not, see <http://www.gnu.org/licenses/>. |
| 428 | 21 |
| 22 ;;; Synched up with: Not synched. | |
| 23 | |
| 24 ;;; Commentary: | |
| 25 | |
| 26 ;; This code will enable the use of the infamous 'wheel' on the new | |
| 27 ;; crop of mice. Under XFree86 and the XSuSE X Servers, the wheel | |
| 28 ;; events are sent as button4/button5 events. | |
| 29 | |
| 30 ;; I for one would prefer some way of converting the button4/button5 | |
| 31 ;; events into different event types, like 'mwheel-up' or | |
| 32 ;; 'mwheel-down', but I cannot find a way to do this very easily (or | |
| 33 ;; portably), so for now I just live with it. | |
| 34 | |
| 35 ;; To enable this code, simply put this at the top of your .emacs | |
| 36 ;; file: | |
| 37 ;; | |
| 38 ;; (autoload 'mwheel-install "mwheel" "Enable mouse wheel support.") | |
| 39 ;; (mwheel-install) | |
| 40 | |
| 41 ;;; Code: | |
| 42 | |
| 43 (require 'custom) | |
| 44 (require 'cl) | |
| 45 | |
| 502 | 46 (globally-declare-fboundp |
| 47 '(event-basic-type | |
| 48 posn-window event-start mwheel-event-window mwheel-event-button)) | |
| 49 | |
| 1621 | 50 (defcustom mwheel-scroll-amount '(5 1 nil) |
| 428 | 51 "Amount to scroll windows by when spinning the mouse wheel. |
| 1621 | 52 A list with 3 elements specifying the amount to scroll on: a normal wheel |
| 53 event, a wheel event with the shift key pressed, and a wheel event with the | |
| 54 control key pressed, in that order. | |
| 428 | 55 |
| 56 Each item should be the number of lines to scroll, or `nil' for near | |
| 57 full screen. | |
| 58 A near full screen is `next-screen-context-lines' less than a full screen." | |
| 59 :group 'mouse | |
| 1621 | 60 :type '(list |
| 428 | 61 (choice :tag "Normal" |
| 62 (const :tag "Full screen" :value nil) | |
| 63 (integer :tag "Specific # of lines")) | |
| 64 (choice :tag "Shifted" | |
| 65 (const :tag "Full screen" :value nil) | |
| 1621 | 66 (integer :tag "Specific # of lines")) |
| 67 (choice :tag "Controlled" | |
| 68 (const :tag "Full screen" :value nil) | |
| 428 | 69 (integer :tag "Specific # of lines")))) |
| 70 | |
| 71 (defcustom mwheel-follow-mouse nil | |
| 72 "Whether the mouse wheel should scroll the window that the mouse is over. | |
| 73 This can be slightly disconcerting, but some people may prefer it." | |
| 74 :group 'mouse | |
| 75 :type 'boolean) | |
| 76 | |
| 77 (if (not (fboundp 'event-button)) | |
| 78 (defun mwheel-event-button (event) | |
| 79 (let ((x (symbol-name (event-basic-type event)))) | |
| 80 (if (not (string-match "^mouse-\\([0-9]+\\)" x)) | |
| 81 (error "Not a button event: %S" event)) | |
| 82 (string-to-int (substring x (match-beginning 1) (match-end 1))))) | |
| 83 (fset 'mwheel-event-button 'event-button)) | |
| 84 | |
| 85 (if (not (fboundp 'event-window)) | |
| 86 (defun mwheel-event-window (event) | |
| 87 (posn-window (event-start event))) | |
| 88 (fset 'mwheel-event-window 'event-window)) | |
| 89 | |
| 90 (defun mwheel-scroll (event) | |
| 91 (interactive "e") | |
| 92 (let ((curwin (if mwheel-follow-mouse | |
| 93 (prog1 | |
| 94 (selected-window) | |
| 95 (select-window (mwheel-event-window event))))) | |
| 96 (amt (if (memq 'shift (event-modifiers event)) | |
| 1621 | 97 (cadr mwheel-scroll-amount) |
| 98 (if (memq 'control (event-modifiers event)) | |
| 99 (caddr mwheel-scroll-amount) | |
| 100 (car mwheel-scroll-amount))))) | |
| 458 | 101 (unwind-protect |
| 102 (case (mwheel-event-button event) | |
| 103 (4 (scroll-down amt)) | |
| 104 (5 (scroll-up amt)) | |
| 105 (otherwise (error "Bad binding in mwheel-scroll"))) | |
| 106 (if curwin (select-window curwin))) | |
| 107 )) | |
| 428 | 108 |
| 109 ;;;###autoload | |
| 110 (defun mwheel-install () | |
| 111 "Enable mouse wheel support." | |
| 444 | 112 (interactive) |
| 1621 | 113 (let ((keys '([(mouse-4)] [(shift mouse-4)] [(control mouse-4)] |
| 114 [(mouse-5)] [(shift mouse-5)] [(control mouse-5)]))) | |
| 115 | |
| 428 | 116 ;; This condition-case is here because Emacs 19 will throw an error |
| 117 ;; if you try to define a key that it does not know about. I for one | |
| 118 ;; prefer to just unconditionally do a mwheel-install in my .emacs, so | |
| 119 ;; that if the wheeled-mouse is there, it just works, and this way it | |
| 120 ;; doesn't yell at me if I'm on my laptop or another machine, etc. | |
| 121 (condition-case () | |
| 122 (while keys | |
| 123 (define-key global-map (car keys) 'mwheel-scroll) | |
| 124 (setq keys (cdr keys))) | |
| 125 (error nil)))) | |
| 458 | 126 |
| 2546 | 127 ;;;###autoload |
| 128 (define-behavior 'mwheel | |
| 129 "This code enables the use of the infamous 'wheel' on the new | |
| 130 crop of mice. Under XFree86 and the XSuSE X Servers, the wheel | |
| 131 events are sent as button4/button5 events, which are automatically | |
| 132 set up to do scrolling in the expected way. The actual way that the | |
| 133 scrolling works can be controlled by `mwheel-scroll-amount' and | |
| 134 `mwheel-follow-mouse'." | |
| 135 :group 'mouse | |
| 136 :short-doc "Mouse wheel support for X Windows" | |
| 137 :enable 'mwheel-install) | |
| 138 | |
| 428 | 139 (provide 'mwheel) |
| 140 | |
| 141 ;;; mwheel.el ends here |
