Mercurial > hg > xemacs-beta
comparison lisp/hyperbole/hui-mouse.el @ 0:376386a54a3c r19-14
Import from CVS: tag r19-14
author | cvs |
---|---|
date | Mon, 13 Aug 2007 08:45:50 +0200 |
parents | |
children | 4103f0995bd7 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:376386a54a3c |
---|---|
1 ;;!emacs | |
2 ;; | |
3 ;; FILE: hui-mouse.el | |
4 ;; SUMMARY: Use key or mouse key for many functions, e.g. Hypb menus. | |
5 ;; See the "${data-directory}/hypb-mouse.txt" file and the | |
6 ;; documentation strings for functions herein. | |
7 ;; USAGE: GNU Emacs Lisp Library | |
8 ;; KEYWORDS: hypermedia, mouse | |
9 ;; | |
10 ;; AUTHOR: Bob Weiner | |
11 ;; ORG: Brown U. | |
12 ;; | |
13 ;; ORIG-DATE: 04-Feb-89 | |
14 ;; LAST-MOD: 1-Nov-95 at 20:45:57 by Bob Weiner | |
15 ;; | |
16 ;; This file is part of Hyperbole. | |
17 ;; Available for use and distribution under the same terms as GNU Emacs. | |
18 ;; | |
19 ;; Copyright (C) 1989-1995, Free Software Foundation, Inc. | |
20 ;; Developed with support from Motorola Inc. | |
21 ;; | |
22 ;; DESCRIPTION: | |
23 ;; | |
24 ;; This code is machine independent. It works best with a pointing device but | |
25 ;; may also be used from a keyboard. When used with a pointing device it | |
26 ;; requires an Emacs command that sets point to the location of the pointing | |
27 ;; device's cursor. | |
28 ;; | |
29 ;; If you want to use your shift-middle mouse button to select Hyperbole menu | |
30 ;; items and Hyperbole buttons, follow these instructions. | |
31 ;; | |
32 ;; If you plan to use a mouse only with X windows (Lucid Emacs, GNU Emacs | |
33 ;; 19, or Epoch), NEXTSTEP, SunView, Apollo's DM, and you want to use the | |
34 ;; shift-middle and shift-right buttons, you need not do any mouse | |
35 ;; configuration. Your Emacs executable must have been built so as to | |
36 ;; include the mouse support files for your window system, however. These | |
37 ;; are in the Emacs "src" directory: for X "x*.c", for SunView "sunfns.c", | |
38 ;; and for Apollo DM "apollo.c" and "apollo.el". | |
39 ;; | |
40 ;; To use a different mouse key or a different window system, modify the | |
41 ;; mouse key bindings in "hmouse-key.el". | |
42 ;; | |
43 ;; Using the Action Mouse Key to browse through and delete files from | |
44 ;; Dired listings is exceptionally nice, just as it is when reading mail. | |
45 ;; | |
46 ;; DESCRIP-END. | |
47 | |
48 ;;; ************************************************************************ | |
49 ;;; Public variables | |
50 ;;; ************************************************************************ | |
51 | |
52 (defvar hmouse-set-point-command nil | |
53 "*Command that sets point to mouse cursor position.") | |
54 | |
55 (defvar action-key-default-function 'hui:menu | |
56 "*Symbol name of function run by the Action Key in an unspecified context.") | |
57 | |
58 (defvar assist-key-default-function 'hkey-summarize | |
59 "*Symbol name of function run by the Assist Key in an unspecified context.") | |
60 | |
61 ;;; ************************************************************************ | |
62 ;;; Hyperbole context-sensitive keys dispatch table | |
63 ;;; ************************************************************************ | |
64 | |
65 (defvar hkey-value nil | |
66 "Communicates a value between a Smart Key predicate and its actions.") | |
67 | |
68 (defvar hkey-alist | |
69 '( | |
70 ;; | |
71 ;; If click in the minibuffer and reading an argument, | |
72 ;; accept argument or give completion help. | |
73 ((and (> (minibuffer-depth) 0) | |
74 (eq (selected-window) (minibuffer-window)) | |
75 (not (eq hargs:reading-p 'hmenu))) . | |
76 ((exit-minibuffer) . (smart-completion-help))) | |
77 ;; | |
78 ;; If reading a Hyperbole menu item or a Hyperbole completion-based | |
79 ;; argument, allow selection of an item at point. | |
80 ((if (> (minibuffer-depth) 0) (setq hkey-value (hargs:at-p))) . | |
81 ((hargs:select-p hkey-value) . | |
82 (hargs:select-p hkey-value 'assist))) | |
83 ;; | |
84 ((if (not (eobp)) | |
85 (or (eolp) (if selective-display | |
86 (= (following-char) ?\^M)))) . | |
87 ((smart-scroll-up) . (smart-scroll-down))) | |
88 ;; | |
89 ((eq major-mode 'smart-menu-mode) . | |
90 ((smart-menu-select) . (smart-menu-help))) | |
91 ;; | |
92 ;; If on a Hyperbole button, perform action or give help. | |
93 ((if (fboundp 'hbut:at-p) (or (hbut:at-p) (hbut:label-p))) . | |
94 ((hui:hbut-act 'hbut:current) . (hui:hbut-help 'hbut:current))) | |
95 ;; | |
96 ;; The Smart Menu system provides menus within Emacs running on a dumb | |
97 ;; terminal. It is part of InfoDock and is not available separately. | |
98 ((and (fboundp 'smart-menu-choose-menu) | |
99 (setq hkey-value (and hkey-always-display-menu | |
100 (smart-menu-choose-menu))) | |
101 (not (and (get-buffer-window *smart-menu-buffer*) | |
102 (eq hkey-value *smart-menu-curr*)))) . | |
103 ((smart-menu hkey-value) . | |
104 (smart-menu hkey-value))) | |
105 ;; | |
106 ;; | |
107 ;; View minor mode | |
108 ((if (boundp 'view-minor-mode) view-minor-mode) . | |
109 ((cond ((last-line-p) | |
110 (view-quit)) | |
111 ((pos-visible-in-window-p (point-max)) | |
112 (goto-char (point-max))) | |
113 (t (scroll-up))) . | |
114 (scroll-down))) | |
115 ;; | |
116 ;; View major mode | |
117 ((eq major-mode 'view-mode) . | |
118 ((View-scroll-lines-forward) . (View-scroll-lines-backward))) | |
119 ;; | |
120 ((eq major-mode 'kotl-mode) . | |
121 ((kotl-mode:action-key) . (kotl-mode:help-key))) | |
122 ;; | |
123 ;; Support direct selection and viewing on in-memory relational databases. | |
124 ;; Rdb-mode has not been publicly released. | |
125 ;; It is not included with Hyperbole. | |
126 ((eq major-mode 'rdb-mode) . ((smart-rdb) . (smart-rdb-assist))) | |
127 ;; | |
128 ;; Restore window config and hide help buffer when click at buffer end. | |
129 ((if (= (point) (point-max)) (string-match "Help\\*$" (buffer-name))) . | |
130 ((hkey-help-hide) . (hkey-help-hide))) | |
131 ;; | |
132 ;; Support the OO-Browser, a part of InfoDock, XEmacs, and soon to be a | |
133 ;; part of Emacs. | |
134 ((or (br-in-browser) (eq major-mode 'br-mode)) . | |
135 ((smart-br-dispatch) . (smart-br-assist-dispatch))) | |
136 ;; | |
137 ((and (memq major-mode '(c-mode c++-c-mode)) | |
138 buffer-file-name (setq hkey-value (smart-c-at-tag-p))) . | |
139 ((smart-c) . (smart-c nil 'next-tag))) | |
140 ;; | |
141 ((and (eq major-mode 'asm-mode) | |
142 buffer-file-name (setq hkey-value (smart-asm-at-tag-p))) . | |
143 ((smart-asm) . (smart-asm nil 'next-tag))) | |
144 ;; | |
145 ((if (smart-lisp-mode-p) (smart-lisp-at-tag-p)) . | |
146 ((smart-lisp) . (smart-lisp 'next-tag))) | |
147 ;; | |
148 ((and (eq major-mode 'c++-mode) buffer-file-name | |
149 ;; Don't use smart-c++-at-tag-p here since it will prevent #include | |
150 ;; lines from matching. | |
151 (setq hkey-value (smart-c-at-tag-p))) . | |
152 ( ;; Only fboundp if OO-Browser has been loaded. | |
153 (if (fboundp 'c++-to-definition) | |
154 (smart-c++-oobr) (smart-c++)) . | |
155 (if (fboundp 'c++-to-definition) | |
156 (smart-c++-oobr) | |
157 (smart-c++ nil 'next-tag)))) | |
158 ;; | |
159 ((and (eq major-mode 'objc-mode) buffer-file-name | |
160 (setq hkey-value (smart-objc-at-tag-p))) . | |
161 ( ;; Only fboundp if OO-Browser has been loaded. | |
162 (if (fboundp 'objc-to-definition) | |
163 (smart-objc-oobr) (smart-objc)) . | |
164 (if (fboundp 'objc-to-definition) | |
165 (smart-objc-oobr) | |
166 (smart-objc nil 'next-tag)))) | |
167 ;; | |
168 ((and (eq major-mode 'fortran-mode) | |
169 buffer-file-name (setq hkey-value (smart-fortran-at-tag-p))) . | |
170 ((smart-fortran) . (smart-fortran nil 'next-tag))) | |
171 ;; | |
172 ((eq major-mode 'occur-mode) . | |
173 ((occur-mode-goto-occurrence) . (occur-mode-goto-occurrence))) | |
174 ;; | |
175 ((eq major-mode 'moccur-mode) . | |
176 ((moccur-mode-goto-occurrence) . (moccur-mode-goto-occurrence))) | |
177 ;; | |
178 ((eq major-mode 'calendar-mode) . | |
179 ((smart-calendar) . (smart-calendar-assist))) | |
180 ;; | |
181 ((eq major-mode 'unix-apropos-mode) . | |
182 ((smart-apropos) . (smart-apropos-assist))) | |
183 ;; | |
184 ((eq major-mode 'outline-mode) . | |
185 ((smart-outline) . (smart-outline-assist))) | |
186 ;; | |
187 ((eq major-mode 'Info-mode) . | |
188 ((smart-info) . (smart-info-assist))) | |
189 ;; | |
190 ((if (boundp 'hmail:reader) | |
191 (or (eq major-mode hmail:reader) | |
192 (eq major-mode hmail:lister))) . | |
193 ((smart-hmail) . (smart-hmail-assist))) | |
194 ;; | |
195 ((eq major-mode 'gnus-group-mode) | |
196 (smart-gnus-group) . (smart-gnus-group-assist)) | |
197 ;; | |
198 ((eq major-mode 'gnus-summary-mode) | |
199 (smart-gnus-summary) . (smart-gnus-summary-assist)) | |
200 ;; | |
201 ((eq major-mode 'gnus-article-mode) | |
202 (smart-gnus-article) . (smart-gnus-article-assist)) | |
203 ;; | |
204 ((eq major-mode 'Buffer-menu-mode) . | |
205 ((smart-buffer-menu) . (smart-buffer-menu-assist))) | |
206 ;; | |
207 ((eq major-mode 'dired-mode) . | |
208 ((smart-dired) . (smart-dired-assist))) | |
209 ;; | |
210 ((eq major-mode 'tar-mode) . | |
211 ((smart-tar) . (smart-tar-assist))) | |
212 ;; | |
213 ;; Follow references in man pages. | |
214 ((setq hkey-value (smart-man-entry-ref)) . | |
215 ((smart-man-display hkey-value) . | |
216 (smart-man-display hkey-value))) | |
217 ;; | |
218 ((eq major-mode 'w3-mode) . | |
219 ((w3-follow-link) . (w3-goto-last-buffer))) | |
220 ;; | |
221 ((if (boundp 'rolo-display-buffer) | |
222 (equal (buffer-name) rolo-display-buffer)) . | |
223 ((smart-wrolo) . (smart-wrolo-assist))) | |
224 ;; | |
225 ;; Gomoku game | |
226 ((eq major-mode 'gomoku-mode) . | |
227 ((gomoku-human-plays) . (gomoku-human-takes-back))) | |
228 ;; | |
229 ;; Outline minor mode is on and usable. | |
230 (selective-display . | |
231 ((smart-outline) . (smart-outline-assist))) | |
232 ) | |
233 "Alist of predicates and form-conses for Action and Assist Keys. | |
234 When the Action or Assist Key is pressed, the first or second form, | |
235 respectively, associated with the first non-nil predicate is evaluated.") | |
236 | |
237 ;;; ************************************************************************ | |
238 ;;; driver code | |
239 ;;; ************************************************************************ | |
240 | |
241 ;; The following autoload is needed if another subsystem besides | |
242 ;; Hyperbole uses this mouse handling code. | |
243 (autoload 'var:append "hvar" "Append to a list variable." nil) | |
244 | |
245 (require 'hargs) | |
246 (require 'hmouse-key) | |
247 (if hyperb:window-system | |
248 (progn | |
249 (defvar hmouse-alist hkey-alist | |
250 "Alist of predicates and form-conses for context-sensitive smart key mouse actions. | |
251 When the action-key or the assist-key is pressed, the first or | |
252 second form, respectively, associated with the first non-nil predicate is | |
253 evaluated.") | |
254 (load "hui-window"))) | |
255 | |
256 ;;; ************************************************************************ | |
257 ;;; support code | |
258 ;;; ************************************************************************ | |
259 | |
260 ;; The 'load' line below loads any local Smart Key function definitions. | |
261 ;; The public distribution contains none. You may leave it commented out if | |
262 ;; you prefer. | |
263 ;; (load "smart-local" t) | |
264 | |
265 ;;; ************************************************************************ | |
266 ;;; Required Init functions | |
267 ;;; ************************************************************************ | |
268 | |
269 (defun first-line-p () | |
270 "Returns true if point is on the first line of the buffer." | |
271 (save-excursion (beginning-of-line) (bobp))) | |
272 | |
273 (defun last-line-p () | |
274 "Returns true if point is on the last line of the buffer." | |
275 (save-excursion (end-of-line) (eobp))) | |
276 | |
277 (defun smart-completion-help () | |
278 "Offer completion help for current minibuffer argument, if any." | |
279 (if (where-is-internal 'minibuffer-completion-help (current-local-map)) | |
280 (minibuffer-completion-help))) | |
281 | |
282 (defun smart-symlink-expand (path) | |
283 "Returns referent for possible symbolic link, PATH." | |
284 (if (not (fboundp 'symlink-referent)) | |
285 path | |
286 (let ((start 0) (len (length path)) (ref) (part)) | |
287 (while (and (< start len) (setq part (string-match "/[^/]*" path start))) | |
288 (setq part (concat ref | |
289 (substring path start (setq start (match-end 0)))) | |
290 ref (symlink-referent part))) | |
291 ref))) | |
292 | |
293 ;;; ************************************************************************ | |
294 ;;; smart-buffer-menu functions | |
295 ;;; ************************************************************************ | |
296 | |
297 (defun smart-buffer-menu (&optional in-browser) | |
298 "Uses a single key or mouse key to manipulate buffer-menu entries. | |
299 | |
300 Invoked via a key press when in Buffer-menu-mode. It assumes that its | |
301 caller has already checked that the key was pressed in an appropriate buffer | |
302 and has moved the cursor there. | |
303 | |
304 Optional non-nil IN-BROWSER indicates use within the OO-Browser. | |
305 | |
306 If key is pressed: | |
307 (1) on the first column of an entry, the selected buffer is marked for | |
308 display; | |
309 (2) on the second column of an entry, the selected buffer is marked to be | |
310 saved; | |
311 (3) anywhere else within an entry line, all saves and deletes are done, and | |
312 selected buffers are displayed, including the one just clicked on (if | |
313 IN-BROWSER, only the selected buffer is displayed); | |
314 (4) on or after the last line in the buffer, all saves and deletes are done." | |
315 | |
316 (interactive) | |
317 (cond ((last-line-p) (Buffer-menu-execute)) | |
318 ((bolp) (Buffer-menu-mark)) | |
319 ((save-excursion | |
320 (goto-char (1- (point))) | |
321 (bolp)) | |
322 (Buffer-menu-save)) | |
323 (in-browser (br-buffer-menu-select)) | |
324 (t (Buffer-menu-select)))) | |
325 | |
326 (defun smart-buffer-menu-assist () | |
327 "Uses a single assist-key or mouse assist-key to manipulate buffer-menu entries. | |
328 | |
329 Invoked via an assist-key press when in Buffer-menu-mode. It assumes that its | |
330 caller has already checked that the assist-key was pressed in an appropriate | |
331 buffer and has moved the cursor there. | |
332 | |
333 If assist-key is pressed: | |
334 (1) on the first or second column of an entry, the selected buffer is unmarked | |
335 for display and for saving or deletion; | |
336 (2) anywhere else within an entry line, the selected buffer is marked for | |
337 deletion; | |
338 (3) on or after the last line in the buffer, all display, save, and delete | |
339 marks on all entries are undone." | |
340 | |
341 (interactive) | |
342 (cond ((last-line-p) (progn (list-buffers) (forward-line 3))) | |
343 ((bolp) (Buffer-menu-unmark)) | |
344 ((save-excursion | |
345 (goto-char (1- (point))) | |
346 (bolp)) | |
347 (Buffer-menu-unmark)) | |
348 (t (Buffer-menu-delete)))) | |
349 | |
350 ;;; ************************************************************************ | |
351 ;;; smart-calendar functions | |
352 ;;; ************************************************************************ | |
353 | |
354 (defun smart-calendar () | |
355 "Uses a single key or mouse key to manipulate the scrolling calendar. | |
356 | |
357 Invoked via a key press when in calendar-mode. It assumes that its | |
358 caller has already checked that the key was pressed in an appropriate buffer | |
359 and has moved the cursor there. | |
360 | |
361 If key is pressed: | |
362 (1) at the end of the buffer, the calendar is scrolled forward 3 months; | |
363 (2) to the left of any dates on a calendar line, the calendar is scrolled | |
364 backward 3 months; | |
365 (3) on a date, the diary entries for the date, if any, are displayed." | |
366 | |
367 (interactive) | |
368 (cond ((eobp) (calendar-cursor-to-nearest-date) | |
369 (scroll-calendar-left-three-months 1)) | |
370 ((< (current-column) 5) (calendar-cursor-to-nearest-date) | |
371 (scroll-calendar-right-three-months 1)) | |
372 (t (calendar-cursor-to-nearest-date) | |
373 (view-diary-entries 1)))) | |
374 | |
375 (defun smart-calendar-assist () | |
376 "Uses a single assist-key or mouse assist-key to manipulate the scrolling calendar. | |
377 | |
378 Invoked via an assist-key press when in calendar-mode. It assumes that its | |
379 caller has already checked that the assist-key was pressed in an appropriate | |
380 buffer and has moved the cursor there. | |
381 | |
382 If assist-key is pressed: | |
383 (1) at the end of the buffer, the calendar is scrolled backward 3 months; | |
384 (2) to the left of any dates on a calendar line, the calendar is scrolled | |
385 forward 3 months; | |
386 (3) anywhere else, all dates with marking diary entries are marked in the | |
387 calendar window." | |
388 | |
389 (interactive) | |
390 (cond ((eobp) (calendar-cursor-to-nearest-date) | |
391 (scroll-calendar-right-three-months 1)) | |
392 ((< (current-column) 5) (calendar-cursor-to-nearest-date) | |
393 (scroll-calendar-left-three-months 1)) | |
394 (t (mark-diary-entries)))) | |
395 | |
396 | |
397 ;;; ************************************************************************ | |
398 ;;; smart-dired functions | |
399 ;;; ************************************************************************ | |
400 | |
401 (defun smart-dired () | |
402 "Uses a single key or mouse key to manipulate directory entries. | |
403 | |
404 Invoked via a key press when in dired-mode. It assumes that its | |
405 caller has already checked that the key was pressed in an appropriate buffer | |
406 and has moved the cursor there. | |
407 | |
408 If key is pressed: | |
409 (1) within an entry line, the selected file/directory is displayed for | |
410 editing in the other window; | |
411 (2) on or after the last line in the buffer, if any deletes are to be | |
412 performed, they are executed after user verification, otherwise, this | |
413 dired invocation is quit." | |
414 | |
415 (interactive) | |
416 (cond ((last-line-p) | |
417 (let (flagged) | |
418 (save-excursion | |
419 (goto-char 1) | |
420 (setq flagged (re-search-forward "^D" nil t))) | |
421 (if flagged | |
422 (cond ((fboundp 'dired-do-deletions) | |
423 (dired-do-deletions)) | |
424 ;; For Tree-dired compatibility | |
425 ((fboundp 'dired-do-flagged-delete) | |
426 (dired-do-flagged-delete)) | |
427 (t (error "(smart-dired): No Dired expunge function."))) | |
428 (dired-quit)))) | |
429 (t (hpath:find-other-window (dired-get-filename))))) | |
430 | |
431 (defun smart-dired-assist () | |
432 "Uses a single assist-key or mouse assist-key to manipulate directory entries. | |
433 | |
434 Invoked via an assist-key press when in dired-mode. It assumes that its | |
435 caller has already checked that the assist-key was pressed in an appropriate | |
436 buffer and has moved the cursor there. | |
437 | |
438 If assist-key is pressed: | |
439 (1) on a '~' character, all backup files in the directory are marked for | |
440 deletion; | |
441 (2) on a '#' character, all auto-save files in the directory are marked for | |
442 deletion; | |
443 (3) anywhere else within an entry line, the current entry is marked for | |
444 deletion; | |
445 (4) on or after the last line in the buffer, all delete marks on all entries | |
446 are undone." | |
447 | |
448 (interactive) | |
449 (cond ((last-line-p) | |
450 (dired-unflag (- (count-lines (point-min) (point-max)))) | |
451 (goto-char (point-max))) | |
452 ((looking-at "~") (dired-flag-backup-files)) | |
453 ((looking-at "#") (dired-flag-auto-save-files)) | |
454 (t (dired-flag-file-deleted 1)))) | |
455 | |
456 ;;; ************************************************************************ | |
457 ;;; smart-gnus functions | |
458 ;;; ************************************************************************ | |
459 | |
460 (defun smart-gnus-group () | |
461 "Uses a key or mouse key to move through Gnus Newsgroup listings. | |
462 Invoked via a key press when in gnus-group-mode. It assumes that its caller | |
463 has already checked that the key was pressed in an appropriate buffer and has | |
464 moved the cursor to the selected buffer. | |
465 | |
466 If key is pressed within: | |
467 (1) a GNUS-GROUP line, that newsgroup is read; | |
468 (2) to the left of any GNUS-GROUP line, on any of the whitespace, the current | |
469 group is unsubscribed or resubscribed; | |
470 (3) at the end of the GNUS-GROUP buffer, after all lines, checks for new | |
471 news." | |
472 | |
473 (interactive) | |
474 (cond ((last-line-p) (gnus-group-get-new-news)) | |
475 ((progn (skip-chars-backward " U") (bolp)) | |
476 (gnus-group-unsubscribe-current-group)) | |
477 (t (gnus-group-read-group nil)))) | |
478 | |
479 (defun smart-gnus-group-assist () | |
480 "Uses an assist-key or assist-mouse key to move through Gnus Newsgroup listings. | |
481 Invoked via an assist-key press when in gnus-group-mode. It assumes that its | |
482 caller has already checked that the key was pressed in an appropriate buffer | |
483 and has moved the cursor to the selected buffer. | |
484 | |
485 If key is pressed within: | |
486 (1) a GNUS-GROUP line, that newsgroup is read; | |
487 (2) to the left of any GNUS-GROUP line, on any of the whitespace, the user is | |
488 prompted for a group name to subscribe or unsubscribe to; | |
489 (3) at the end of the GNUS-GROUP buffer, after all lines, quits from the | |
490 newsreader." | |
491 | |
492 (interactive) | |
493 (cond ((last-line-p) (gnus-group-exit)) | |
494 ((progn (skip-chars-backward " U") (bolp)) | |
495 (call-interactively 'gnus-group-unsubscribe-group)) | |
496 (t (gnus-group-read-group nil)))) | |
497 | |
498 (defun smart-gnus-summary () | |
499 "Uses a key or mouse key to move through Gnus News article listings. | |
500 Invoked via a key press when in gnus-summary-mode. It assumes that its caller | |
501 has already checked that the key was pressed in an appropriate buffer and has | |
502 moved the cursor to the selected buffer. | |
503 | |
504 If key is pressed within: | |
505 (1) to the left of an article number, that article is marked as unread; | |
506 (2) a GNUS-SUMMARY line, that article is read, marked deleted, and scrolled | |
507 forward; | |
508 (3) at the end of the GNUS-SUMMARY buffer, the next undeleted article | |
509 is read or the next group is entered." | |
510 | |
511 (interactive) | |
512 (cond ((last-line-p) | |
513 (if gnus-current-article | |
514 (progn (goto-char (point-min)) | |
515 (re-search-forward | |
516 (format "^.[ ]+%d:" gnus-current-article) nil t) | |
517 (setq this-command 'gnus-summary-next-page) | |
518 (call-interactively 'gnus-summary-next-page)) | |
519 (goto-char (point-min)) | |
520 (setq this-command 'gnus-summary-first-unread-article) | |
521 (call-interactively 'gnus-summary-first-unread-article))) | |
522 ((save-excursion (skip-chars-backward " D") (bolp)) | |
523 (gnus-summary-mark-as-unread-forward 1)) | |
524 (t (setq this-command 'gnus-summary-next-page) | |
525 (call-interactively 'gnus-summary-next-page)))) | |
526 | |
527 (defun smart-gnus-summary-assist () | |
528 "Uses an assist-key or assist-mouse key to move through Gnus News articles. | |
529 Invoked via an assist-key press when in gnus-summary-mode. It assumes that its | |
530 caller has already checked that the key was pressed in an appropriate buffer | |
531 and has moved the cursor to the selected buffer. | |
532 | |
533 If key is pressed within: | |
534 (1) to the left of an article number, that article is marked as unread; | |
535 (2) a GNUS-SUMMARY line, that article is read and scrolled backward; | |
536 (3) at the end of the GNUS-SUMMARY buffer, the summary is exited, the user | |
537 is returned to group mode." | |
538 | |
539 (interactive) | |
540 (cond ((last-line-p) | |
541 (setq this-command 'gnus-summary-prev-page) | |
542 (call-interactively 'gnus-summary-exit)) | |
543 ((save-excursion (skip-chars-backward " D") (bolp)) | |
544 (gnus-summary-mark-as-unread-backward 1)) | |
545 (t (setq this-command 'gnus-summary-prev-page) | |
546 (call-interactively 'gnus-summary-prev-page)))) | |
547 | |
548 (defun smart-gnus-article () | |
549 "Uses a key or mouse key to move through Gnus netnews articles. | |
550 | |
551 Invoked via a key press when in gnus-article-mode. | |
552 It assumes that its caller has already checked that the key was pressed in an | |
553 appropriate buffer and has moved the cursor to the selected buffer. | |
554 | |
555 If key is pressed within: | |
556 (1) the first line or end of an article, the next unread message is displayed; | |
557 (2) the first line of an Info cross reference, the reference is followed; | |
558 (3) anywhere else, the window is scrolled up a windowful." | |
559 (interactive) | |
560 (cond ((or (last-line-p) (and (not (eolp)) (first-line-p))) | |
561 (unwind-protect | |
562 (progn (set-buffer gnus-summary-buffer) | |
563 (setq this-command 'gnus-summary-next-unread-article) | |
564 (gnus-summary-next-unread-article) | |
565 (gnus-summary-goto-subject gnus-current-article) | |
566 ) | |
567 (let ((artic (get-buffer-window gnus-article-buffer))) | |
568 (if artic (select-window artic))))) | |
569 ((and (not (eolp)) (Info-handle-in-note))) | |
570 (t (smart-scroll-up)))) | |
571 | |
572 (defun smart-gnus-article-assist () | |
573 "Uses an assist-key or mouse assist-key to move through Gnus netnews articles. | |
574 | |
575 Invoked via an assist-key press when in gnus-article-mode. | |
576 It assumes that its caller has already checked that the assist-key was pressed in | |
577 an appropriate buffer and has moved the cursor to the selected buffer. | |
578 | |
579 If assist-key is pressed within: | |
580 (1) the first line or end of an article, the previous message is displayed; | |
581 (2) the first line of an Info cross reference, the reference is followed; | |
582 (3) anywhere else, the window is scrolled down a windowful." | |
583 (interactive) | |
584 (cond ((or (last-line-p) (and (not (eolp)) (first-line-p))) | |
585 (unwind-protect | |
586 (progn (set-buffer gnus-summary-buffer) | |
587 (setq this-command 'gnus-summary-prev-article) | |
588 (gnus-summary-prev-article nil) | |
589 (gnus-summary-goto-subject gnus-current-article) | |
590 ) | |
591 (let ((artic (get-buffer-window gnus-summary-buffer))) | |
592 (if artic (select-window artic))))) | |
593 ((and (not (eolp)) (Info-handle-in-note))) | |
594 (t (smart-scroll-down)))) | |
595 | |
596 ;;; ************************************************************************ | |
597 ;;; smart-hmail functions | |
598 ;;; ************************************************************************ | |
599 | |
600 (defun smart-hmail () | |
601 "Uses a key or mouse key to move through e-mail messages and summaries. | |
602 | |
603 Invoked via a key press when in hmail:reader or hmail:lister mode. | |
604 It assumes that its caller has already checked that the key was pressed in an | |
605 appropriate buffer and has moved the cursor to the selected buffer. | |
606 | |
607 If key is pressed within: | |
608 (1) a msg buffer, within the first line or at the end of a message, | |
609 the next undeleted message is displayed; | |
610 (2) a msg buffer within the first line of an Info cross reference, the | |
611 reference is followed; | |
612 (3) anywhere else in a msg buffer, the window is scrolled up a windowful; | |
613 (4) a msg summary buffer on a header entry, the message corresponding to | |
614 the header is displayed in the msg window; | |
615 (5) a msg summary buffer, on or after the last line, the messages marked | |
616 for deletion are expunged." | |
617 | |
618 (interactive) | |
619 ;; | |
620 ;; Branch on buffer type | |
621 ;; | |
622 (cond ((eq major-mode hmail:reader) | |
623 (cond ((or (last-line-p) (and (not (eolp)) (first-line-p))) | |
624 (rmail:msg-next)) | |
625 ((and (not (eolp)) (Info-handle-in-note))) | |
626 ((smart-scroll-up)))) | |
627 ;; | |
628 ;; Assume are in msg summary buffer | |
629 ;; | |
630 ((last-line-p) (lmail:expunge)) | |
631 (t (lmail:goto)))) | |
632 | |
633 (defun smart-hmail-assist () | |
634 "Uses an assist key or mouse key to move through e-mail messages and summaries. | |
635 | |
636 Invoked via an assist key press when in hmail:reader or hmail:lister mode. | |
637 It assumes that its caller has already checked that the assist-key was pressed in | |
638 an appropriate buffer and has moved the cursor to the selected buffer. | |
639 | |
640 If assist-key is pressed within: | |
641 (1) a msg buffer, within the first line or at the end of a message, | |
642 the previous undeleted message is displayed; | |
643 (2) a msg buffer within the first line of an Info cross reference, the | |
644 reference is followed; | |
645 (3) anywhere else in a msg buffer, the window is scrolled down a windowful; | |
646 (4) a msg summary buffer on a header entry, the message corresponding to | |
647 the header is marked as deleted; | |
648 (5) a msg summary buffer, on or after the last line, all messages are | |
649 marked undeleted." | |
650 | |
651 (interactive) | |
652 ;; | |
653 ;; Branch on buffer type | |
654 ;; | |
655 (cond ((eq major-mode hmail:reader) | |
656 (cond ((or (last-line-p) (and (not (eolp)) (first-line-p))) | |
657 (rmail:msg-prev)) | |
658 ((and (not (eolp)) (Info-handle-in-note))) | |
659 ((smart-scroll-down)))) | |
660 ;; | |
661 ;; Assume are in msg summary buffer | |
662 ;; | |
663 ((last-line-p) (lmail:undelete-all)) | |
664 (t (lmail:delete)))) | |
665 | |
666 | |
667 ;;; ************************************************************************ | |
668 ;;; smart-info functions | |
669 ;;; ************************************************************************ | |
670 ;;; Autoloaded in "hyperbole.el". | |
671 | |
672 ;;; ************************************************************************ | |
673 ;;; smart-man functions | |
674 ;;; ************************************************************************ | |
675 | |
676 ;; "unix-apropos.el" is a publicly available Emacs Lisp package that | |
677 ;; allows man page browsing from apropos listings. "superman.el" is a | |
678 ;; newer, much more complete package that you would probably prefer at | |
679 ;; this point, but there is no Smart Key apropos support for it. There | |
680 ;; is smart key support within the man page buffers it produces, however. | |
681 ;; | |
682 | |
683 (defun smart-apropos () | |
684 "Moves through UNIX man apropos listings by using one key or mouse key. | |
685 | |
686 Invoked via a key press when in unix-apropos-mode. It assumes that | |
687 its caller has already checked that the key was pressed in an appropriate | |
688 buffer and has moved the cursor to the selected buffer. | |
689 | |
690 If key is pressed: | |
691 (1) on a UNIX man apropos entry, the man page for that entry is displayed in | |
692 another window; | |
693 (2) on or after the last line, the buffer in the other window is scrolled up | |
694 a windowful." | |
695 | |
696 (interactive) | |
697 (if (last-line-p) | |
698 (scroll-other-window) | |
699 (unix-apropos-get-man))) | |
700 | |
701 (defun smart-apropos-assist () | |
702 "Moves through UNIX man apropos listings by using one assist-key or mouse assist-key. | |
703 | |
704 Invoked via an assist-key press when in unix-apropos-mode. It assumes that | |
705 its caller has already checked that the assist-key was pressed in an appropriate | |
706 buffer and has moved the cursor to the selected buffer. | |
707 | |
708 If assist-key is pressed: | |
709 (1) on a UNIX man apropos entry, the man page for that entry is displayed in | |
710 another window; | |
711 (2) on or after the last line, the buffer in the other window is scrolled down | |
712 a windowful." | |
713 | |
714 (interactive) | |
715 (if (last-line-p) | |
716 (scroll-other-window (- 3 (window-height))) | |
717 (unix-apropos-get-man))) | |
718 | |
719 (defun smart-man-display (lisp-form) | |
720 "Evaluates LISP-FORM returned from 'smart-man-entry-ref' to display a man page." | |
721 (eval lisp-form)) | |
722 | |
723 (defun smart-man-entry-ref () | |
724 "Returns form which displays referenced manual entry that point is on or nil. | |
725 Handles references in sections: NAME, SEE ALSO, or PACKAGES USED. Also can | |
726 display C routine definitions selected in a man page, see | |
727 'smart-man-c-routine-ref'. | |
728 | |
729 Man page buffer must either have an attached file or else a `man-path' | |
730 local variable containing its pathname." | |
731 (interactive) | |
732 (let ((ref "")) | |
733 (if (not (or (if (string-match "Manual Entry\\|\\*man " | |
734 (buffer-name (current-buffer))) | |
735 (progn (and (boundp 'man-path) man-path | |
736 (setq ref (smart-symlink-expand man-path))) | |
737 t)) | |
738 (if buffer-file-name | |
739 (string-match "/man/" (setq ref (smart-symlink-expand | |
740 buffer-file-name)))))) | |
741 (setq ref nil) | |
742 (or (setq ref (or (smart-man-file-ref) | |
743 (smart-man-c-routine-ref))) | |
744 (save-excursion | |
745 (let ((opoint (point)) | |
746 (case-fold-search)) | |
747 (and | |
748 (re-search-backward "^[.A-Z]" nil t) | |
749 (looking-at | |
750 "\\(\\.SH[ \t]+\\)?\\(SEE ALSO\\|NAME\\|PACKAGES USED\\)") | |
751 (progn (goto-char opoint) | |
752 (skip-chars-backward "-_a-zA-Z0-9?.(") | |
753 (let ((start (point))) | |
754 (skip-chars-forward "-_a-zA-Z0-9?.()") | |
755 (setq ref (buffer-substring start (point))) | |
756 ;; Leave only one char within ref parens | |
757 (if ref | |
758 (if (string-match "(\\(.\\)\\(.+\\))" ref) | |
759 (setq ref (concat (substring ref 0 (match-end 1)) | |
760 "\)")))) | |
761 ))))))) | |
762 (cond ((equal ref "") nil) | |
763 ((stringp ref) (list 'manual-entry ref)) | |
764 (t ref)))) | |
765 | |
766 (defun smart-man-c-routine-ref () | |
767 "Returns form to jump to def of C function whose name is at point, if any. | |
768 Valid sections within the man page are: ROUTINES, MACROS or FUNCTIONS. | |
769 Uses (smart-tags-file) function to determine etags file from which to | |
770 locate the definition. | |
771 | |
772 Returns etags file name if point is on an identifier in the appropriate | |
773 section and the jump is done, otherwise, returns nil." | |
774 (let ((ref) | |
775 (opoint (point)) | |
776 (case-fold-search)) | |
777 (save-excursion | |
778 (and (re-search-backward "^[.A-Z]" nil t) | |
779 (looking-at "^\\(FUNCTIONS\\|ROUTINES\\|MACROS\\)[ \t\n]") | |
780 (progn (goto-char opoint) | |
781 (skip-chars-backward "_~<>:a-zA-Z0-9(") | |
782 (if (or (looking-at "\\([_~<>:a-zA-Z0-9]+\\)[ \t\n]*(") | |
783 (looking-at "\\([_~<:A-Z][_<>:A-Z0-9]+\\)")) | |
784 (setq ref (buffer-substring | |
785 (match-beginning 1) (match-end 1)) | |
786 ))))) | |
787 (if ref | |
788 (let ((tags-file-name | |
789 (smart-tags-file (if (and (boundp 'man-path) man-path) | |
790 man-path | |
791 default-directory)))) | |
792 (and (file-exists-p tags-file-name) | |
793 (file-readable-p tags-file-name) | |
794 (list 'let (list (list 'tags-file-name tags-file-name)) | |
795 (list (if (br-in-browser) | |
796 'find-tag 'find-tag-other-window) | |
797 ref))))))) | |
798 | |
799 (defun smart-man-file-ref () | |
800 "Returns form to eval to display file whose name point is on, within a FILES man page section. | |
801 If not on a file name, returns nil." | |
802 (let ((ref) | |
803 (opoint (point)) | |
804 (case-fold-search)) | |
805 (save-excursion | |
806 (and (re-search-backward "^[.A-Z]" nil t) | |
807 (looking-at "^FILES[ \t\n]") | |
808 (progn (goto-char opoint) | |
809 (skip-chars-backward "^ \t") | |
810 (if (looking-at "/[^ \t\n]+") | |
811 (setq ref (buffer-substring | |
812 (match-beginning 0) (match-end 0)) | |
813 ))))) | |
814 (if ref | |
815 (list (if (br-in-browser) | |
816 'find-file 'find-file-other-window) | |
817 ref)))) | |
818 | |
819 ;;; ************************************************************************ | |
820 ;;; smart-outline functions | |
821 ;;; ************************************************************************ | |
822 | |
823 ;; The functions in this section require InfoDock's version of outline.el | |
824 ;; in order to work properly. | |
825 | |
826 (defvar smart-outline-cut nil | |
827 "Non-nil means outline region was cut and is ready to be pasted at point.") | |
828 | |
829 (let ((proc | |
830 '((lambda () | |
831 (make-local-variable 'smart-outline-cut) | |
832 ;; Non-nil means outline region was cut and is available to be | |
833 ;; pasted at point. | |
834 (setq smart-outline-cut nil) | |
835 )))) | |
836 (if (boundp 'outline-mode-map) | |
837 (eval proc) | |
838 (var:append 'outline-mode-hook proc))) | |
839 | |
840 (defun smart-outline () | |
841 "Collapses, expands, and moves outline entries. | |
842 Invoked via a key press when in outline-mode. It assumes that | |
843 its caller has already checked that the key was pressed in an appropriate | |
844 buffer and has moved the cursor to the selected buffer. | |
845 | |
846 If key is pressed: | |
847 (1) after an outline heading has been cut via the Action Key, then paste the | |
848 cut heading at point; | |
849 (2) at the end of buffer, show all buffer text | |
850 (3) at the beginning of a heading line, cut the headings subtree from the | |
851 buffer; | |
852 (4) on a header line but not at the beginning or end, if headings subtree is | |
853 hidden then show it, otherwise hide it; | |
854 (5) anywhere else, scroll up a windowful." | |
855 | |
856 (interactive) | |
857 (cond (smart-outline-cut | |
858 (setq smart-outline-cut nil) (yank)) | |
859 ((eobp) (show-all)) | |
860 ((and (bolp) (looking-at outline-regexp)) | |
861 (setq smart-outline-cut t) | |
862 (kill-region | |
863 (point) | |
864 (or (outline-get-next-sibling) | |
865 ;; Skip past start of current entry | |
866 (progn (re-search-forward outline-regexp nil t) | |
867 (smart-outline-to-entry-end t (outline-level)))))) | |
868 | |
869 ((or (eolp) (zerop (save-excursion (beginning-of-line) | |
870 (outline-level)))) | |
871 (smart-scroll-up)) | |
872 ;; On an outline header line but not at the start/end of line. | |
873 ((smart-outline-subtree-hidden-p) | |
874 (show-subtree)) | |
875 (t (hide-subtree)))) | |
876 | |
877 | |
878 (defun smart-outline-assist () | |
879 "Collapses, expands, and moves outline entries. | |
880 Invoked via an assist-key press when in outline-mode. It assumes that | |
881 its caller has already checked that the assist-key was pressed in an appropriate | |
882 buffer and has moved the cursor to the selected buffer. | |
883 | |
884 If assist-key is pressed: | |
885 (1) after an outline heading has been cut via the action-key, allow multiple | |
886 pastes throughout the buffer (last paste should be done with the Action Key, | |
887 not the Assist Key); | |
888 (2) at the end of buffer, hide all bodies in buffer; | |
889 (3) at the beginning of a heading line, cut the current heading (sans | |
890 subtree) from the buffer; | |
891 (4) on a header line but not at the beginning or end, if heading body is | |
892 hidden then show it, otherwise hide it; | |
893 (5) anywhere else, scroll down a windowful." | |
894 | |
895 (interactive) | |
896 (cond (smart-outline-cut (yank)) | |
897 ((eobp) (hide-body )) | |
898 ((and (bolp) (looking-at outline-regexp)) | |
899 (setq smart-outline-cut t) | |
900 (kill-region (point) | |
901 ;; Skip past start of current entry | |
902 (progn (re-search-forward outline-regexp nil t) | |
903 (smart-outline-to-entry-end | |
904 nil (outline-level))))) | |
905 ((or (eolp) (zerop (save-excursion (beginning-of-line) | |
906 (outline-level)))) | |
907 (smart-scroll-down)) | |
908 ;; On an outline header line but not at the start/end of line. | |
909 ((smart-outline-subtree-hidden-p) | |
910 (show-entry)) | |
911 (t (hide-entry)))) | |
912 | |
913 (defun smart-outline-to-entry-end | |
914 (&optional include-sub-entries curr-entry-level) | |
915 "Goes to end of whole entry if optional INCLUDE-SUB-ENTRIES is non-nil. | |
916 CURR-ENTRY-LEVEL is an integer representing the length of the current level | |
917 string which matched to 'outline-regexp'. If INCLUDE-SUB-ENTRIES is nil, | |
918 CURR-ENTRY-LEVEL is not needed." | |
919 (let (next-entry-exists) | |
920 (while (and (setq next-entry-exists | |
921 (re-search-forward outline-regexp nil t)) | |
922 include-sub-entries | |
923 (save-excursion | |
924 (beginning-of-line) | |
925 (> (outline-level) | |
926 curr-entry-level)))) | |
927 (if next-entry-exists | |
928 (progn (beginning-of-line) (point)) | |
929 (goto-char (point-max))))) | |
930 | |
931 (defun smart-outline-subtree-hidden-p () | |
932 "Returns t if at least initial subtree of heading is hidden, else nil." | |
933 (save-excursion | |
934 (if (re-search-forward "[\n\^M]" nil t) (= (preceding-char) ?\^M)))) | |
935 | |
936 ;;; ************************************************************************ | |
937 ;;; smart-tar functions | |
938 ;;; ************************************************************************ | |
939 | |
940 (defun smart-tar () | |
941 "Uses a single key or mouse key to manipulate tar file entries. | |
942 | |
943 Invoked via a key press when in tar-mode. It assumes that its | |
944 caller has already checked that the key was pressed in an appropriate buffer | |
945 and has moved the cursor there. | |
946 | |
947 If key is pressed: | |
948 (1) within an entry line, the selected file/directory is displayed for | |
949 editing in the other window; | |
950 (2) on or after the last line in the buffer, if any deletes are to be | |
951 performed, they are executed after user verification, otherwise, this | |
952 tar file browser is quit." | |
953 | |
954 (interactive) | |
955 (cond ((last-line-p) | |
956 (let (flagged) | |
957 (save-excursion | |
958 (goto-char 1) | |
959 (setq flagged (re-search-forward "^D" nil t))) | |
960 (if flagged | |
961 (tar-expunge) | |
962 (kill-buffer nil)))) | |
963 (t (tar-extract-other-window)))) | |
964 | |
965 (defun smart-tar-assist () | |
966 "Uses a single assist-key or mouse assist-key to manipulate tar file entries. | |
967 | |
968 Invoked via an assist-key press when in dired-mode. It assumes that its | |
969 caller has already checked that the assist-key was pressed in an appropriate | |
970 buffer and has moved the cursor there. | |
971 | |
972 If assist-key is pressed: | |
973 (1) on an entry line, the current entry is marked for deletion; | |
974 (2) on or after the last line in the buffer, all delete marks on all entries | |
975 are undone." | |
976 | |
977 (interactive) | |
978 (cond ((last-line-p) | |
979 (tar-unflag (- (count-lines (point-min) (point-max)))) | |
980 (goto-char (point-max))) | |
981 (t (tar-flag-deleted 1)))) | |
982 | |
983 ;;; ************************************************************************ | |
984 ;;; smart-wrolo functions | |
985 ;;; ************************************************************************ | |
986 | |
987 (defun smart-wrolo () | |
988 "In wrolo match buffer, edits current entry. | |
989 Uses one key or mouse key. | |
990 | |
991 Invoked via a key press when in the 'rolo-display-buffer'. It assumes that | |
992 its caller has already checked that the key was pressed in an appropriate | |
993 buffer and has moved the cursor to the selected buffer." | |
994 (interactive) | |
995 (rolo-edit-entry)) | |
996 | |
997 (fset 'smart-wrolo-assist 'smart-wrolo) | |
998 | |
999 (provide 'hui-mouse) |