annotate lisp/prim/mode-motion.el @ 129:e292c9648bb9 xemacs-20-1p3

Import from CVS: tag xemacs-20-1p3
author cvs
date Mon, 13 Aug 2007 09:28:38 +0200
parents 131b0175ea99
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;; Mode-specific mouse-highlighting of text.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 ;; Copyright (C) 1992, 1993 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;; This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;; under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; XEmacs is distributed in the hope that it will be useful, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;; General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; You should have received a copy of the GNU General Public License
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
17 ;; along with XEmacs; see the file COPYING. If not, write to the
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 16
diff changeset
18 ;; Free Software Foundation, 59 Temple Place - Suite 330,
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
19 ;; Boston, MA 02111-1307, USA.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;;; Synched up with: Not in FSF.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 (defvar mode-motion-hook nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 "Function or functions which are called whenever the mouse moves.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 You should normally use this rather than `mouse-motion-handler', which
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 does some additional window-system-dependent things. This hook is local
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 to every buffer, and should normally be set up by major-modes which want
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 to use special highlighting. Every time the mouse moves over a window,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 the mode-motion-hook of the buffer of that window is run.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 (make-variable-buffer-local 'mode-motion-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 (defvar mode-motion-extent nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 (make-variable-buffer-local 'mode-motion-extent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 (defvar mode-motion-help-echo-string nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 "String to be added as the 'help-echo property of the mode-motion extent.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 In order for this to work, you need to add the hook function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 `mode-motion-add-help-echo' to the mode-motion hook. If this is a function,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 it will be called with one argument (the event) and should return a string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 to be added. This variable is local to every buffer.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 (make-variable-buffer-local 'mode-motion-help-echo-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 (defun mode-motion-ensure-extent-ok (event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 (let ((buffer (event-buffer event)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 (if (and (extent-live-p mode-motion-extent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 (eq buffer (extent-object mode-motion-extent)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 (setq mode-motion-extent (make-extent nil nil buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 (set-extent-property mode-motion-extent 'mouse-face 'highlight))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 (defun mode-motion-highlight-internal (event backward forward)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 (let* ((buffer (event-buffer event))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 (point (and buffer (event-point event))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 (if (and buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 (not (eq buffer mouse-grabbed-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 ;; #### ack!! Too many calls to save-window-excursion /
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 ;; save-excursion (x-track-pointer calls, so does
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 ;; minibuf-mouse-tracker ...) This needs to be looked
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 ;; into. It's complicated by the fact that sometimes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 ;; a mode-motion-hook might really want to change
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 ;; the point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 ;; #### The save-excursion must come before the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 ;; save-window-excursion in order to function properly. I
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 ;; haven't given this much thought. Is it a bug that this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 ;; ordering is necessary or is it correct behavior?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 (save-window-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 (set-buffer buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 (mode-motion-ensure-extent-ok event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 (if point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 (goto-char point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 (condition-case nil (funcall backward) (error nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 (setq point (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 (condition-case nil (funcall forward) (error nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 (if (eq point (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 (detach-extent mode-motion-extent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 (set-extent-endpoints mode-motion-extent point (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 ;; not over text; zero the extent.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 (detach-extent mode-motion-extent)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 (defun mode-motion-highlight-line (event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 "For use as the value of `mode-motion-hook' -- highlight line under mouse."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 (mode-motion-highlight-internal event 'beginning-of-line 'end-of-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 (defun mode-motion-highlight-word (event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 "For use as the value of `mode-motion-hook' -- highlight word under mouse."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 (mode-motion-highlight-internal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 event
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 #'(lambda () (default-mouse-track-beginning-of-word nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 #'(lambda () (default-mouse-track-end-of-word nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 (defun mode-motion-highlight-symbol (event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 "For use as the value of `mode-motion-hook' -- highlight symbol under mouse."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (mode-motion-highlight-internal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 event
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 #'(lambda () (default-mouse-track-beginning-of-word t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 #'(lambda () (default-mouse-track-end-of-word t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 (defun mode-motion-highlight-sexp (event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 "For use as the value of `mode-motion-hook' -- highlight form under mouse."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 (mode-motion-highlight-internal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 event
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 #'(lambda ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 (if (= (char-syntax (following-char)) ?\()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 (goto-char (scan-sexps (point) -1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 #'(lambda ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (if (= (char-syntax (following-char)) ?\))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 (forward-char 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 (goto-char (scan-sexps (point) 1)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 (defun mode-motion-add-help-echo (event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 "For use as the value of `mode-motion-hook' -- add a 'help-echo property.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 This causes the string in the 'help-echo property to be displayed when the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 mouse moves over the extent. See `mode-motion-help-echo-string' for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 documentation on how to control the string that is added."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 (mode-motion-ensure-extent-ok event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (let ((string (cond ((null mode-motion-help-echo-string) nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 ((stringp mode-motion-help-echo-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 mode-motion-help-echo-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (t (funcall mode-motion-help-echo-string event)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 (if (stringp string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 (set-extent-property mode-motion-extent 'help-echo string))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 (provide 'mode-motion)