annotate lisp/prim/mode-motion.el @ 0:376386a54a3c r19-14

Import from CVS: tag r19-14
author cvs
date Mon, 13 Aug 2007 08:45:50 +0200
parents
children 0293115a14e9
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
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; along with XEmacs; see the file COPYING. If not, write to the Free
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;;; Synched up with: Not in FSF.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 (defvar mode-motion-hook nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 "Function or functions which are called whenever the mouse moves.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 You should normally use this rather than `mouse-motion-handler', which
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 does some additional window-system-dependent things. This hook is local
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 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
27 to use special highlighting. Every time the mouse moves over a window,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 the mode-motion-hook of the buffer of that window is run.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 (make-variable-buffer-local 'mode-motion-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 (defvar mode-motion-extent nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 (make-variable-buffer-local 'mode-motion-extent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 (defvar mode-motion-help-echo-string nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 "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
37 In order for this to work, you need to add the hook function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 `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
39 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
40 to be added. This variable is local to every buffer.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 (make-variable-buffer-local 'mode-motion-help-echo-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 (defun mode-motion-ensure-extent-ok (event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 (let ((buffer (event-buffer event)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 (if (and (extent-live-p mode-motion-extent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 (eq buffer (extent-object mode-motion-extent)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 (setq mode-motion-extent (make-extent nil nil buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 (set-extent-property mode-motion-extent 'mouse-face 'highlight))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 (defun mode-motion-highlight-internal (event backward forward)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 (let* ((buffer (event-buffer event))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 (point (and buffer (event-point event))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 (if (and buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 (not (eq buffer mouse-grabbed-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 ;; #### ack!! Too many calls to save-window-excursion /
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 ;; save-excursion (x-track-pointer calls, so does
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 ;; minibuf-mouse-tracker ...) This needs to be looked
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 ;; into. It's complicated by the fact that sometimes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 ;; a mode-motion-hook might really want to change
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 ;; the point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 ;; #### The save-excursion must come before the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 ;; save-window-excursion in order to function properly. I
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 ;; haven't given this much thought. Is it a bug that this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 ;; ordering is necessary or is it correct behavior?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 (save-window-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 (set-buffer buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 (mode-motion-ensure-extent-ok event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 (if point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 (goto-char point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 (condition-case nil (funcall backward) (error nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 (setq point (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 (condition-case nil (funcall forward) (error nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 (if (eq point (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 (detach-extent mode-motion-extent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 (set-extent-endpoints mode-motion-extent point (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 ;; not over text; zero the extent.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 (detach-extent mode-motion-extent)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 (defun mode-motion-highlight-line (event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 "For use as the value of `mode-motion-hook' -- highlight line under mouse."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 (mode-motion-highlight-internal event 'beginning-of-line 'end-of-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 (defun mode-motion-highlight-word (event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 "For use as the value of `mode-motion-hook' -- highlight word under mouse."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 (mode-motion-highlight-internal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 event
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 #'(lambda () (default-mouse-track-beginning-of-word nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 #'(lambda () (default-mouse-track-end-of-word nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 (defun mode-motion-highlight-symbol (event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 "For use as the value of `mode-motion-hook' -- highlight symbol under mouse."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 (mode-motion-highlight-internal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 event
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 #'(lambda () (default-mouse-track-beginning-of-word t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 #'(lambda () (default-mouse-track-end-of-word t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 (defun mode-motion-highlight-sexp (event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 "For use as the value of `mode-motion-hook' -- highlight form under mouse."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 (mode-motion-highlight-internal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 event
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 #'(lambda ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 (if (= (char-syntax (following-char)) ?\()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 (goto-char (scan-sexps (point) -1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 #'(lambda ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 (if (= (char-syntax (following-char)) ?\))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (forward-char 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 (goto-char (scan-sexps (point) 1)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 (defun mode-motion-add-help-echo (event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 "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
116 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
117 mouse moves over the extent. See `mode-motion-help-echo-string' for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 documentation on how to control the string that is added."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 (mode-motion-ensure-extent-ok event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 (let ((string (cond ((null mode-motion-help-echo-string) nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 ((stringp mode-motion-help-echo-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 mode-motion-help-echo-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (t (funcall mode-motion-help-echo-string event)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (if (stringp string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 (set-extent-property mode-motion-extent 'help-echo string))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (provide 'mode-motion)