Mercurial > hg > xemacs-beta
comparison lisp/packages/func-menu.el @ 70:131b0175ea99 r20-0b30
Import from CVS: tag r20-0b30
author | cvs |
---|---|
date | Mon, 13 Aug 2007 09:02:59 +0200 |
parents | e04119814345 |
children | 6a378aca36af |
comparison
equal
deleted
inserted
replaced
69:804d1389bcd6 | 70:131b0175ea99 |
---|---|
1 ;;; func-menu.el --- Jump to a function within a buffer. | 1 ;;; func-menu.el --- Jump to a function within a buffer. |
2 ;;; | 2 ;;; |
3 ;;; David Hughes <ukchugd@ukpmr.cs.philips.nl> | 3 ;;; David Hughes <ukchugd@ukpmr.cs.philips.nl> |
4 ;;; Last modified: David Hughes 13th January 1997 | 4 ;;; Last modified: David Hughes 2nd May 1996 |
5 ;;; Version: 2.45 | 5 ;;; Version: 2.43 |
6 ;;; Keywords: tools, c, lisp | 6 ;;; Keywords: tools, c, lisp |
7 ;;; | 7 ;;; |
8 ;;; This program is free software; you can redistribute it and/or modify | 8 ;;; This program is free software; you can redistribute it and/or modify |
9 ;;; it under the terms of the GNU General Public License as published by | 9 ;;; it under the terms of the GNU General Public License as published by |
10 ;;; the Free Software Foundation; either version 2, or (at your option) | 10 ;;; the Free Software Foundation; either version 2, or (at your option) |
41 ;;; to where you were. Alternatively, you can use enter the name of the | 41 ;;; to where you were. Alternatively, you can use enter the name of the |
42 ;;; desired function via the minibuffer which offers completing read input. In | 42 ;;; desired function via the minibuffer which offers completing read input. In |
43 ;;; addition, the name of the function before point is optionally displayed in | 43 ;;; addition, the name of the function before point is optionally displayed in |
44 ;;; the modeline. | 44 ;;; the modeline. |
45 ;;; | 45 ;;; |
46 ;;; Support for non X Window versions of Emacs: | 46 ;;; Support for non X Windows versions of Emacs: |
47 ;;; =========================================== | 47 ;;; ============================================ |
48 ;;; This package can also be used for non X versions of Emacs. In this case, | 48 ;;; This package can also be used for non X versions of Emacs. In this case, |
49 ;;; only modeline display and completing read input from the minibuffer are | 49 ;;; only modeline display and completing read input from the minibuffer are |
50 ;;; possible. | 50 ;;; possible. |
51 ;;; | 51 ;;; |
52 ;;; Modes supported: | 52 ;;; Modes supported: |
56 ;;; Postscript, Prolog, PVS, Python, SGML, Scheme, Tcl, Verilog | 56 ;;; Postscript, Prolog, PVS, Python, SGML, Scheme, Tcl, Verilog |
57 ;;; | 57 ;;; |
58 ;;; Acknowledgements: | 58 ;;; Acknowledgements: |
59 ;;; ================= | 59 ;;; ================= |
60 ;;; | 60 ;;; |
61 ;;; Fix to fume-function-name-regexp-c | |
62 ;;; Jonathan Edwards <edwards@intranet.com> | |
63 ;;; | |
64 ;;; Speedup for fume-cc-inside-comment | |
65 ;;; Peter Pezaris <pez@dwwc.com> | |
66 ;;; | |
67 ;;; Made menu placement more flexible | |
68 ;;; Bob Weiner <weiner@infodock.com> | |
69 ;;; | |
70 ;;; Fortran90 regexp | 61 ;;; Fortran90 regexp |
71 ;;; John Turner <turner@xdiv.lanl.gov> | 62 ;;; John Turner <turner@xdiv.lanl.gov> |
72 ;;; | 63 ;;; |
73 ;;; Patch to error trap in fume-rescan-buffer | 64 ;;; Patch to error trap in fume-rescan-buffer |
74 ;;; Andy Piper <andyp@parallax.co.uk> | 65 ;;; Andy Piper <andyp@parallax.co.uk> |
75 ;;; | 66 ;;; |
76 ;;; Java support | 67 ;;; Java support |
77 ;;; Bob Weiner <weiner@infodock.com> | |
78 ;;; Heddy Boubaker <boubaker@dgac.fr> | 68 ;;; Heddy Boubaker <boubaker@dgac.fr> |
79 ;;; | 69 ;;; |
80 ;;; Patch for fume-rescan-buffer{-trigger} | 70 ;;; Patch for fume-rescan-buffer{-trigger} |
81 ;;; Christoph Wedler <wedler@vivaldi.fmi.uni-passau.de> | 71 ;;; Christoph Wedler <wedler@vivaldi.fmi.uni-passau.de> |
82 ;;; | 72 ;;; |
148 ;;; | 138 ;;; |
149 ;;; SGML support; submenu indexing | 139 ;;; SGML support; submenu indexing |
150 ;;; Thomas Plass <thomas.plass@mid-heidelberg.de> | 140 ;;; Thomas Plass <thomas.plass@mid-heidelberg.de> |
151 ;;; | 141 ;;; |
152 ;;; Extensions to fume-function-name-regexp-lisp | 142 ;;; Extensions to fume-function-name-regexp-lisp |
153 ;;; Vladimir Alexiev <vladimir@cs.ualberta.ca> | |
154 ;;; Kari Heinola <kph@dpe.fi> | 143 ;;; Kari Heinola <kph@dpe.fi> |
155 ;;; Milo A. Chan <chan@jpmorgan.com> | 144 ;;; Milo A. Chan <chan@jpmorgan.com> |
156 ;;; Jack Repenning <jackr@step7.informix.com> | 145 ;;; Jack Repenning <jackr@step7.informix.com> |
157 ;;; Cedric Beust <Cedric.Beust@sophia.inria.fr> | 146 ;;; Cedric Beust <Cedric.Beust@sophia.inria.fr> |
158 ;;; Joachim Krumnow <krumnow@srsir02.ext.sap-ag.de> | 147 ;;; Joachim Krumnow <krumnow@srsir02.ext.sap-ag.de> |
171 ;;; Paolo Frasconi <paolo@mcculloch.ing.unifi.it> | 160 ;;; Paolo Frasconi <paolo@mcculloch.ing.unifi.it> |
172 ;;; C. Michael Holloway <c.m.holloway@larc.nasa.gov> | 161 ;;; C. Michael Holloway <c.m.holloway@larc.nasa.gov> |
173 ;;; Philippe Queinnec <queinnec@cenatls.cena.dgac.fr> | 162 ;;; Philippe Queinnec <queinnec@cenatls.cena.dgac.fr> |
174 ;;; | 163 ;;; |
175 ;;; Assembly support | 164 ;;; Assembly support |
176 ;;; Bob Weiner <weiner@infodock.com> | 165 ;;; Bob Weiner <weiner@mot.com> |
177 ;;; | 166 ;;; |
178 ;;; Removal of cl dependencies | 167 ;;; Removal of cl dependencies |
179 ;;; Russell Ritchie <russell@gssec.bt.co.uk> | 168 ;;; Russell Ritchie <russell@gssec.bt.co.uk> |
180 ;;; | 169 ;;; |
181 ;;; C++ mode enhancemencements for func-menu | 170 ;;; C++ mode enhancemencements for func-menu |
211 | 200 |
212 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 201 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
213 ;;;;;;;;;;;;;;;;;;;;;;;; Environment Initialisation ;;;;;;;;;;;;;;;;;;;;;; | 202 ;;;;;;;;;;;;;;;;;;;;;;;; Environment Initialisation ;;;;;;;;;;;;;;;;;;;;;; |
214 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 203 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
215 | 204 |
216 (defconst fume-version "2.45") | 205 (defconst fume-version "2.43") |
217 | 206 |
218 (defconst fume-developer "David Hughes <ukchugd@ukpmr.cs.philips.nl>") | 207 (defconst fume-developer "David Hughes <ukchugd@ukpmr.cs.philips.nl>") |
219 | 208 |
220 (defun fume-about () | 209 (defun fume-about () |
221 (interactive) | 210 (interactive) |
222 (sit-for 0) | 211 (sit-for 0) |
223 (message "Func-Menu version %s, © 1996 %s" fume-version fume-developer)) | 212 (message "Func-Menu version %s, ¨ 1996 %s" fume-version fume-developer)) |
224 | 213 |
225 (defconst fume-running-xemacs (string-match "XEmacs\\|Lucid" emacs-version)) | 214 (defconst fume-running-xemacs (string-match "XEmacs\\|Lucid" emacs-version)) |
226 | 215 |
227 (defmacro fume-defvar-local (var value &optional doc) | 216 (defmacro fume-defvar-local (var value &optional doc) |
228 "Defines SYMBOL as an advertised variable. | 217 "Defines SYMBOL as an advertised variable. |
374 (boundp 'local-post-command-hook)) | 363 (boundp 'local-post-command-hook)) |
375 | 364 |
376 (cond ((fboundp 'add-submenu) | 365 (cond ((fboundp 'add-submenu) |
377 (defconst fume-add-submenu 'add-submenu) | 366 (defconst fume-add-submenu 'add-submenu) |
378 (defun fume-munge-menu-args (menu-name submenu before) | 367 (defun fume-munge-menu-args (menu-name submenu before) |
379 (list fume-menu-path (cons menu-name submenu) before))) | 368 (list nil (cons menu-name submenu) before))) |
380 (t | 369 (t |
381 (defconst fume-add-submenu 'add-menu) | 370 (defconst fume-add-submenu 'add-menu) |
382 (defun fume-munge-menu-args (menu-name submenu before) | 371 (defun fume-munge-menu-args (menu-name submenu before) |
383 (list fume-menu-path menu-name submenu before)))) | 372 (list nil menu-name submenu before)))) |
384 | 373 |
385 (defun fume-add-submenu (menu-name submenu before) | 374 (defun fume-add-submenu (menu-name submenu before) |
386 (apply fume-add-submenu (fume-munge-menu-args menu-name submenu before))) | 375 (apply fume-add-submenu (fume-munge-menu-args menu-name submenu before))) |
387 | 376 |
388 ;; this seems to really be `should I try to change the menubar' | |
389 (defconst fume-not-tty | 377 (defconst fume-not-tty |
390 (or (featurep 'menubar) ;; XEmacs | 378 (or (and (fboundp 'device-type) (not (eq 'tty (device-type)))) |
391 (featurep 'menu-bar))) ;; GNU Emacs | 379 (and (symbol-value 'window-system) t))) ; obsolete test |
392 | 380 |
393 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 381 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
394 ;;;;;;;;;;;;;;;;;;;;;;;;;; Customizable Variables ;;;;;;;;;;;;;;;;;;;;;;;; | 382 ;;;;;;;;;;;;;;;;;;;;;;;;;; Customizable Variables ;;;;;;;;;;;;;;;;;;;;;;;; |
395 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 383 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
396 | 384 |
407 Note, this is a buffer-local variable.") | 395 Note, this is a buffer-local variable.") |
408 | 396 |
409 (defvar fume-buffer-name "*Function List*" | 397 (defvar fume-buffer-name "*Function List*" |
410 "Name of buffer used to list functions when fume-list-functions called") | 398 "Name of buffer used to list functions when fume-list-functions called") |
411 | 399 |
412 (defvar fume-menubar-menu-name "Functions" | 400 (fume-defvar-local |
401 fume-menubar-menu-name "Functions" | |
413 "*Set this to the string you want to appear in the menubar") | 402 "*Set this to the string you want to appear in the menubar") |
414 | |
415 ;;; Bob Weiner <weiner@infodock.com> | |
416 (defvar fume-menu-path nil | |
417 "Menubar menu under which the function menu should be installed. | |
418 Nil means install it on the menubar itself. Otherwise, it should be a list | |
419 of strings, each string names a successively deeper menu under which the | |
420 new menu should be located.") | |
421 | 403 |
422 (defvar fume-menubar-menu-location "Buffers" | 404 (defvar fume-menubar-menu-location "Buffers" |
423 "*Set this nil if you want the menu to appear last on the menubar. | 405 "*Set this nil if you want the menu to appear last on the menubar. |
424 Otherwise set this to the menu you want \"Functions\" to appear in front of.") | 406 Otherwise set this to the menu you want \"Functions\" to appear in front of.") |
425 | 407 |
449 | 431 |
450 (defvar fume-rescan-trigger-counter-buffer-size 10000 | 432 (defvar fume-rescan-trigger-counter-buffer-size 10000 |
451 "Used to tune the frequency of automatic checks on the buffer. | 433 "Used to tune the frequency of automatic checks on the buffer. |
452 The function fume-rescan-buffer-trigger only works whenever the value of the | 434 The function fume-rescan-buffer-trigger only works whenever the value of the |
453 variable fume-rescan-trigger-counter reaches zero, whereupon it gets reset to | 435 variable fume-rescan-trigger-counter reaches zero, whereupon it gets reset to |
454 the maximum of a) buffer-size/fume-rescan-trigger-counter-buffer-size | 436 buffer-size/fume-rescan-trigger-counter-buffer-size.") |
455 or b) fume-rescan-trigger-counter-min") | |
456 | |
457 (defvar fume-rescan-trigger-counter-min 50 | |
458 "Used to tune the frequency of automatic checks on the buffer. | |
459 The function fume-rescan-buffer-trigger only works whenever the value of the | |
460 variable fume-rescan-trigger-counter reaches zero, whereupon it gets reset to | |
461 the maximum of a) buffer-size/fume-rescan-trigger-counter-buffer-size | |
462 or b) fume-rescan-trigger-counter-min") | |
463 | 437 |
464 (fume-defvar-local | 438 (fume-defvar-local |
465 fume-sort-function 'fume-sort-by-name | 439 fume-sort-function 'fume-sort-by-name |
466 "*The function to use for sorting the function menu. | 440 "*The function to use for sorting the function menu. |
467 | 441 |
544 ;;; Every fume-function-name-regexp-<language> should uniquely identify a | 518 ;;; Every fume-function-name-regexp-<language> should uniquely identify a |
545 ;;; function for that certain language. | 519 ;;; function for that certain language. |
546 | 520 |
547 ;;; Lisp | 521 ;;; Lisp |
548 ;;; | 522 ;;; |
549 ;;; Vladimir Alexiev <vladimir@cs.ualberta.ca> | 523 ;;; Jack Repenning <jackr@step7.informix.com> |
550 ;;; JTL: 24. Feb. 97 added "/" as part of function names | 524 ;;; Cedric Beust <Cedric.Beust@sophia.inria.fr> |
551 (defvar fume-function-name-regexp-lisp | 525 (defvar fume-function-name-regexp-lisp |
552 (concat | 526 (concat |
553 "^[ \t]*" ; Allow whitespace |(or (fboundp 'foo) | 527 "\\(^(defun+\\s-*[#:?A-Za-z0-9_+->]+\\s-*(\\)" |
554 ; for the construct | (defun foo () | 528 "\\|" |
555 "(\\(def[^vc][a-z]*\\)" ; Allow (def* except (defvar, (defconst | 529 "\\(^(defsubst+\\s-*[#:?A-Za-z0-9_+->]+\\s-*(\\)" |
556 "\\s-+" ; At least one whitespace | 530 "\\|" |
557 "'?[#:?/A-Za-z0-9_+>-]+" ; Allow (defalias 'foo 'bar) | 531 "\\(^(defmacro+\\s-*[#:?A-Za-z0-9_+->]+\\s-*(\\)" |
558 "\\s-*" ; Whitespace | 532 "\\|" |
559 "\\(nil\\|(\\)" ; nil or (arg list | 533 "\\(^(defadvice+\\s-*[#:?A-Za-z0-9_+->]+\\s-*(\\)" |
534 "\\|" | |
535 "\\(^(de+\\s-*[#:?A-Za-z0-9_+->]+\\s-*(\\)" | |
536 "\\|" | |
537 "\\(^(dmd+\\s-*[#:?A-Za-z0-9_+->]+\\s-*(\\)" | |
560 ) | 538 ) |
561 "Expression to get lisp function names") | 539 "Expression to get lisp function names") |
562 | 540 |
563 ;;; C | 541 ;;; C |
564 ;;; | 542 ;;; |
565 ;;; Danny Bar-Dov <danny@acet02.amil.co.il> | 543 ;;; Danny Bar-Dov <danny@acet02.amil.co.il> |
566 (defvar fume-function-name-regexp-c | 544 (defvar fume-function-name-regexp-c |
567 (concat | 545 (concat |
568 "^[a-zA-Z0-9_]+\\s-?" ; type specs; there can be no | 546 "^[a-zA-Z0-9]+\\s-?" ; type specs; there can be no |
569 "\\([a-zA-Z0-9_*]+\\s-+\\)?" ; more than 3 tokens, right? | 547 "\\([a-zA-Z0-9_*]+\\s-+\\)?" ; more than 3 tokens, right? |
570 "\\([a-zA-Z0-9_*]+\\s-+\\)?" | 548 "\\([a-zA-Z0-9_*]+\\s-+\\)?" |
571 "\\([*&]+\\s-*\\)?" ; pointer | 549 "\\([*&]+\\s-*\\)?" ; pointer |
572 "\\([a-zA-Z0-9_*]+\\)[ \t\n]*(" ; name | 550 "\\([a-zA-Z0-9_*]+\\)[ \t\n]*(" ; name |
573 ) | 551 ) |
574 "Expression to get C function names") | 552 "Expression to get C function names") |
575 | 553 |
576 ;;; C++ | 554 ;;; C++ |
577 ;;; | 555 ;;; |
807 ;;; | 785 ;;; |
808 ;;; Paul Filipski & Anthony Girardin <{filipski,girardin}@blackhawk.com> | 786 ;;; Paul Filipski & Anthony Girardin <{filipski,girardin}@blackhawk.com> |
809 (defvar fume-function-name-regexp-make | 787 (defvar fume-function-name-regexp-make |
810 "^\\(\\(\\$\\s(\\)?\\(\\w\\|\\.\\)+\\(:sh\\)?\\(\\s)\\)?\\)\\s *\\(::?\\|\\+?=\\)" | 788 "^\\(\\(\\$\\s(\\)?\\(\\w\\|\\.\\)+\\(:sh\\)?\\(\\s)\\)?\\)\\s *\\(::?\\|\\+?=\\)" |
811 "Expression to get makefile target names") | 789 "Expression to get makefile target names") |
812 (add-hook 'makefile-mode-hook 'fume-add-menubar-entry) | |
813 | 790 |
814 ;;; Directory Listings | 791 ;;; Directory Listings |
815 ;;; | 792 ;;; |
816 ;;; Norbert Kiesel <norbert@i3.informatik.rwth-aachen.de> | 793 ;;; Norbert Kiesel <norbert@i3.informatik.rwth-aachen.de> |
817 ;;; regexp stolen from font-lock-mode | 794 ;;; regexp stolen from font-lock-mode |
840 ;;; Matt Sale <mdsale@icdc.delcoelect.com> | 817 ;;; Matt Sale <mdsale@icdc.delcoelect.com> |
841 (defvar fume-function-name-regexp-verilog | 818 (defvar fume-function-name-regexp-verilog |
842 "^\\(task\\|function\\|module\\|primitive\\)[ \t]+\\([A-Za-z0-9_+-]*\\)[ \t]*(?" | 819 "^\\(task\\|function\\|module\\|primitive\\)[ \t]+\\([A-Za-z0-9_+-]*\\)[ \t]*(?" |
843 "Expression to get verilog module names") | 820 "Expression to get verilog module names") |
844 | 821 |
845 ;;; Idl | |
846 ;;; | |
847 ;;; Lubos Pochman <lubos@rsinc.com> | |
848 (defvar fume-function-name-regexp-idl | |
849 (cons "^\\s *\\([pP][rR][oO]\\|[fF][uU][nN][cC][tT][iI][oO][nN]\\)\\s +\\([A-Za-z][A-Za-z0-9_$]*\\)" 2) | |
850 "Expression to get Idl function Names") | |
851 | 822 |
852 ;;; Assembly | 823 ;;; Assembly |
853 (defvar fume-function-name-regexp-asm | 824 (defvar fume-function-name-regexp-asm |
854 "^\\([a-zA-Z_.$][a-zA-Z0-9_.$]*\\)[ \t]*:" | 825 "^\\([a-zA-Z_.$][a-zA-Z0-9_.$]*\\)[ \t]*:" |
855 "Expression to get assembly label names") | 826 "Expression to get assembly label names") |
946 (fame-mode . fume-function-name-regexp-fame) | 917 (fame-mode . fume-function-name-regexp-fame) |
947 | 918 |
948 ;; Verilog | 919 ;; Verilog |
949 (verilog-mode . fume-function-name-regexp-verilog) | 920 (verilog-mode . fume-function-name-regexp-verilog) |
950 | 921 |
951 ;; Idl | |
952 (idl-mode . fume-function-name-regexp-idl) | |
953 | |
954 ;; Assembly | 922 ;; Assembly |
955 (asm-mode . fume-function-name-regexp-asm) | 923 (asm-mode . fume-function-name-regexp-asm) |
956 ) | 924 ) |
957 | 925 |
958 "The connection between a mode and the regexp that matches function names.") | 926 "The connection between a mode and the regexp that matches function names.") |
967 "Searches for the next function in BUFFER." | 935 "Searches for the next function in BUFFER." |
968 (set-buffer buffer) | 936 (set-buffer buffer) |
969 ;; Search for the function | 937 ;; Search for the function |
970 (if (re-search-forward fume-function-name-regexp nil t) | 938 (if (re-search-forward fume-function-name-regexp nil t) |
971 (let ((char (progn | 939 (let ((char (progn |
972 (if (string-match | 940 (backward-up-list 1) |
973 "[({[]" | |
974 (char-to-string (char-after (1- (point))))) | |
975 (backward-char) | |
976 (forward-word -1)) | |
977 (save-excursion | 941 (save-excursion |
978 (goto-char (scan-sexps (point) 1)) | 942 (goto-char (scan-sexps (point) 1)) |
979 (skip-chars-forward "[ \t\n]") | 943 (skip-chars-forward "[ \t\n]") |
980 (following-char))))) | 944 (following-char))))) |
981 ;; Skip this function name if it is a prototype declaration. | 945 ;; Skip this function name if it is a prototype declaration. |
1019 (if (looking-at ":") | 983 (if (looking-at ":") |
1020 (setq end (1- end))) | 984 (setq end (1- end))) |
1021 (cons (buffer-substring beg end) beg)))) | 985 (cons (buffer-substring beg end) beg)))) |
1022 | 986 |
1023 ;;; Specialised routine to get the next C function name in the buffer. | 987 ;;; Specialised routine to get the next C function name in the buffer. |
1024 ;;; Modified 16/12/96: Jerome Bertorelle <bertorel@telspace.alcatel.fr> | |
1025 ;;; | 988 ;;; |
1026 (defun fume-find-next-c-function-name (buffer) | 989 (defun fume-find-next-c-function-name (buffer) |
1027 "Searches for the next C function in BUFFER." | 990 "Searches for the next C function in BUFFER." |
1028 (set-buffer buffer) | 991 (set-buffer buffer) |
1029 ;; Search for the function | 992 ;; Search for the function |
1034 (goto-char (scan-sexps (point) 1)) | 997 (goto-char (scan-sexps (point) 1)) |
1035 (skip-chars-forward "[ \t\n]") | 998 (skip-chars-forward "[ \t\n]") |
1036 (following-char))))) | 999 (following-char))))) |
1037 ;; Skip this function name if it is a prototype declaration. | 1000 ;; Skip this function name if it is a prototype declaration. |
1038 (if (eq char ?\;) | 1001 (if (eq char ?\;) |
1039 (fume-find-next-c-function-name buffer) | 1002 (fume-find-next-function-name buffer) |
1040 (let (beg | 1003 (let (beg |
1041 name) | 1004 name) |
1042 ;; Get the function name and position | 1005 ;; Get the function name and position |
1043 (forward-sexp -1) | 1006 (forward-sexp -1) |
1044 (setq beg (point)) | 1007 (setq beg (point)) |
1053 (re-search-backward "\"," nil t) | 1016 (re-search-backward "\"," nil t) |
1054 (setq name | 1017 (setq name |
1055 (format "%s %s" | 1018 (format "%s %s" |
1056 name | 1019 name |
1057 (buffer-substring beg (point)))))))) | 1020 (buffer-substring beg (point)))))))) |
1058 ;; kludge to avoid 'void' etc in menu | 1021 ;; kludge to avoid 'void' in menu |
1059 (if (string-match "^void$\\|^if$\\|^switch$\\|^while$" name) | 1022 (if (string-match "^void\\s-*" name) |
1060 (fume-find-next-c-function-name buffer) | 1023 (fume-find-next-function-name buffer) |
1061 (cons name beg))))))) | 1024 (cons name beg))))))) |
1062 | 1025 |
1063 ;;; Peter Pezaris <pez@dwwc.com> | |
1064 ;;; | |
1065 (defun fume-cc-inside-comment () | 1026 (defun fume-cc-inside-comment () |
1066 (memq (buffer-syntactic-context) '(comment block-comment))) | 1027 (let ((here (point)) |
1028 (bol-point (save-excursion (beginning-of-line) (point)))) | |
1029 (or | |
1030 (save-excursion (and (re-search-backward "\/\/" bol-point t 1) t)) | |
1031 (save-excursion | |
1032 (and | |
1033 (re-search-backward "\\(/[*]\\)\\|\\([*]/\\)" (point-min) t 1) | |
1034 (looking-at "/[*]") | |
1035 (goto-char here) | |
1036 (or (beginning-of-line 1) t) | |
1037 (re-search-forward "[ \t]*/?[*][ \t]*" here t 1) | |
1038 t))))) | |
1067 | 1039 |
1068 ;;; <jrm@odi.com> | 1040 ;;; <jrm@odi.com> |
1069 ;;; <ajp@eng.cam.ac.uk> | 1041 ;;; <ajp@eng.cam.ac.uk> |
1070 ;;; <schittko@fokus.gmd.de> | 1042 ;;; <schittko@fokus.gmd.de> |
1071 ;;; <ukchugd@ukpmr.cs.philips.nl> - speedup, David Hughes 24th November 1996 | |
1072 ;;; | 1043 ;;; |
1073 (defun fume-match-find-next-function-name (buffer) | 1044 (defun fume-match-find-next-function-name (buffer) |
1074 ;; General next function name in BUFFER finder using match. | 1045 "General next function name in BUFFER finder using match. |
1075 ;; The regexp is assumed to be a two item list the car of which is the regexp | 1046 The regexp is assumed to be a two item list the car of which is the regexp to |
1076 ;; to use, and the cdr of which is the match position of the function name | 1047 use, and the cdr of which is the match position of the function name." |
1077 (set-buffer buffer) | 1048 (set-buffer buffer) |
1078 (let ((r (car fume-function-name-regexp)) | 1049 (let ((result nil) |
1079 (p (cdr fume-function-name-regexp))) | 1050 (continue t) |
1080 (catch 'found | 1051 (regexp (car fume-function-name-regexp))) |
1081 (while (re-search-forward r nil t) | 1052 (while continue |
1082 (catch 'skip | 1053 ;; Search for the function |
1083 (if (fume-cc-inside-comment) (throw 'skip t)) | 1054 (if (re-search-forward regexp nil t) |
1084 (save-excursion | 1055 (if (fume-cc-inside-comment) |
1085 (re-search-backward r nil t) | 1056 () ; skip spurious finds in comments |
1086 (if (string= "typedef" (fume-what-looking-at)) (throw 'skip t)) | 1057 (let ((first-token (save-excursion |
1087 (re-search-forward r nil t)) | 1058 (re-search-backward regexp nil t) |
1088 (backward-up-list 1) | 1059 (prog1 (fume-what-looking-at) |
1089 (save-excursion | 1060 (re-search-forward regexp nil t)))) |
1090 (goto-char (scan-sexps (point) 1)) | 1061 (last-char (progn |
1091 (if (eq ?\; (following-char)) (throw 'skip t))) ; skip prototypes | 1062 (backward-up-list 1) |
1092 (throw | 1063 (save-excursion |
1093 'found | 1064 (goto-char (scan-sexps (point) 1)) |
1094 (cons (buffer-substring (setq p (match-beginning p)) (point)) p)))) | 1065 (following-char))))) |
1095 nil))) | 1066 ;; Skip function name if it's a prototype or typedef declaration |
1067 (if (or (eq last-char ?\;) (string= first-token "typedef")) | |
1068 nil | |
1069 (setq result | |
1070 ;; Get function name and position including scope | |
1071 (cons (buffer-substring | |
1072 (match-beginning (cdr fume-function-name-regexp)) | |
1073 (point)) | |
1074 (match-beginning (cdr fume-function-name-regexp))) | |
1075 continue nil)))) | |
1076 (setq continue nil))) | |
1077 result)) | |
1096 | 1078 |
1097 ;;; Specialised routine to find the next Perl function | 1079 ;;; Specialised routine to find the next Perl function |
1098 ;;; | 1080 ;;; |
1099 (defun fume-find-next-perl-function-name (buffer) | 1081 (defun fume-find-next-perl-function-name (buffer) |
1100 "Searches for the next Perl function in BUFFER." | 1082 "Searches for the next Perl function in BUFFER." |
1101 (fume-find-next-sexp buffer)) | 1083 (fume-find-next-sexp buffer)) |
1102 | 1084 |
1103 ;;; Specialised routine to find the next Java function | 1085 ;;; Specialised routine to find the next Java function |
1104 ;;; Bob Weiner <weiner@infodock.com> | |
1105 ;;; Heddy Boubaker <boubaker@dgac.fr> | 1086 ;;; Heddy Boubaker <boubaker@dgac.fr> |
1106 ;;; | 1087 ;;; |
1107 (defun fume-find-next-java-function-name (buffer) | 1088 (defun fume-find-next-java-function-name (buffer) |
1108 "Searches for the next Java function in BUFFER." | 1089 "Searches for the next Java function in BUFFER." |
1109 (set-buffer buffer) | 1090 (set-buffer buffer) |
1112 (end (match-end 1))) | 1093 (end (match-end 1))) |
1113 (goto-char (match-beginning 2)) | 1094 (goto-char (match-beginning 2)) |
1114 (forward-sexp) | 1095 (forward-sexp) |
1115 (if (and (looking-at "[^;(]*{") | 1096 (if (and (looking-at "[^;(]*{") |
1116 (not (fume-cc-inside-comment))) | 1097 (not (fume-cc-inside-comment))) |
1117 ;; This is a method definition and we're not in a comment | 1098 ;; This is a method definition and we're not |
1099 ;; in a comment. | |
1118 (let ((str (buffer-substring beg end))) | 1100 (let ((str (buffer-substring beg end))) |
1119 ;; Bob Weiner <weiner@infodock.com> added exact match | 1101 (or (string-match "if\\|switch\\|catch\\|for\\|while" str) |
1120 ;; delimiters so function names that happen to contain | 1102 ;; These constructs look like methods definitions |
1121 ;; any of these terms are not eliminated. The old version | 1103 ;; but are not. |
1122 ;; would ignore "notify()" since it contained "if". | |
1123 (or (string-match "\\`\\(if\\|switch\\|catch\\|for\\|while\\)\\'" | |
1124 str) | |
1125 ;; These constructs look like method definitions but are not | |
1126 (cons str beg))) | 1104 (cons str beg))) |
1127 (fume-find-next-java-function-name buffer))))) | 1105 (fume-find-next-java-function-name buffer))))) |
1128 | 1106 |
1129 ;;; Specialised routine to find the next Python function | 1107 ;;; Specialised routine to find the next Python function |
1130 ;;; Shuichi Koga <skoga@virginia.edu> | 1108 ;;; Shuichi Koga <skoga@virginia.edu> |
1390 (if (re-search-forward fume-function-name-regexp nil t) | 1368 (if (re-search-forward fume-function-name-regexp nil t) |
1391 (let ((beg (match-beginning 2)) | 1369 (let ((beg (match-beginning 2)) |
1392 (end (match-end 2))) | 1370 (end (match-end 2))) |
1393 (cons (buffer-substring beg end) beg)))) | 1371 (cons (buffer-substring beg end) beg)))) |
1394 | 1372 |
1395 ;;; Specialised routine to get the next idl function in the buffer | |
1396 ;;; | |
1397 ;;; Lubos Pochman <lubos@rsinc.com> | |
1398 (defun fume-find-next-idl-function-name (buffer) | |
1399 "Searches for the next idl function in BUFFER." | |
1400 (set-buffer buffer) | |
1401 (if (re-search-forward (car fume-function-name-regexp-idl) nil t) | |
1402 (let ((beg (match-beginning (cdr fume-function-name-regexp-idl))) | |
1403 (end (match-end (cdr fume-function-name-regexp-idl)))) | |
1404 (cons (buffer-substring beg end) beg)))) | |
1405 | |
1406 | |
1407 ;;; Assembly | 1373 ;;; Assembly |
1408 ;;; Bob Weiner <weiner@infodock.com> | 1374 ;;; Bob Weiner <weiner@mot.com> |
1409 ;;; | 1375 ;;; |
1410 (defun fume-find-next-asm-function-name (buffer) | 1376 (defun fume-find-next-asm-function-name (buffer) |
1411 "Searches for the next assembler function in BUFFER." | 1377 "Searches for the next assembler function in BUFFER." |
1412 (set-buffer buffer) | 1378 (set-buffer buffer) |
1413 ;; Search for the function | 1379 ;; Search for the function |
1449 (python-mode . fume-find-next-python-function-name) | 1415 (python-mode . fume-find-next-python-function-name) |
1450 (scheme-mode . fume-find-next-scheme-function) | 1416 (scheme-mode . fume-find-next-scheme-function) |
1451 (sgml-mode . fume-find-next-sgml-element-name) | 1417 (sgml-mode . fume-find-next-sgml-element-name) |
1452 (tcl-mode . fume-match-find-next-function-name) | 1418 (tcl-mode . fume-match-find-next-function-name) |
1453 (verilog-mode . fume-find-next-verilog-function-name) | 1419 (verilog-mode . fume-find-next-verilog-function-name) |
1454 (idl-mode . fume-find-next-idl-function-name) | |
1455 ) | 1420 ) |
1456 | 1421 |
1457 "The connection between a mode and the defun that finds function names. | 1422 "The connection between a mode and the defun that finds function names. |
1458 If no connection is in this alist for a given mode, a default method is used") | 1423 If no connection is in this alist for a given mode, a default method is used") |
1459 | 1424 |
1460 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 1425 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
1461 ;;;;;;;;;;;;;;;;;;;;;;;; General utility functions ;;;;;;;;;;;;;;;;;;;;;;; | 1426 ;;;;;;;;;;;;;;;;;;;;;;;; General utility functions ;;;;;;;;;;;;;;;;;;;;;;; |
1462 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 1427 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
1463 | 1428 |
1464 ;;; modeline refresh routine | 1429 ;;; Routine to refresh the modeline |
1465 ;;; | 1430 ;;; |
1466 (or (fboundp 'redraw-modeline) | 1431 (if (fboundp 'redraw-modeline) ; faster built-in method |
1467 (defun redraw-modeline () (set-buffer-modified-p (buffer-modified-p)))) | 1432 (defalias 'fume-refresh-modeline 'redraw-modeline) |
1433 (defun fume-refresh-modeline () ; use old kludge method | |
1434 (set-buffer-modified-p (buffer-modified-p)))) | |
1468 | 1435 |
1469 ;;; Smart mouse positioning | 1436 ;;; Smart mouse positioning |
1470 ;;; | 1437 ;;; |
1471 (if (fboundp 'window-edges) ; old method | 1438 (if (fboundp 'window-edges) ; old method |
1472 (defun fume-set-mouse-position () | 1439 (defun fume-set-mouse-position () |
1495 'fume-find-next-function-name))) | 1462 'fume-find-next-function-name))) |
1496 fume-function-name-regexp) | 1463 fume-function-name-regexp) |
1497 | 1464 |
1498 ;;; Routines to add/remove/update function menu from menubar | 1465 ;;; Routines to add/remove/update function menu from menubar |
1499 ;;; | 1466 ;;; |
1500 (defun fume-add-menubar-entry () | 1467 (defsubst fume-add-menubar-entry () |
1501 (interactive) | 1468 (interactive) |
1502 (save-window-excursion (function-menu t))) | 1469 (save-window-excursion (function-menu t))) |
1503 | 1470 |
1504 (defun fume-remove-menubar-entry () | 1471 (defsubst fume-remove-menubar-entry () |
1505 (interactive) | 1472 (interactive) |
1506 (cond ((and fume-running-xemacs current-menubar) | 1473 (cond ((and fume-running-xemacs current-menubar) |
1507 (delete-menu-item (list fume-menubar-menu-name)) | 1474 (delete-menu-item (list fume-menubar-menu-name)) |
1508 ;; force update of the menubar | 1475 ;; force update of the menubar |
1509 (redraw-modeline)))) | 1476 (fume-refresh-modeline)))) |
1510 | 1477 |
1511 (defun fume-update-menubar-entry () | 1478 (defsubst fume-update-menubar-entry () |
1512 "Returns t if menubar was updated. Nil otherwise" | 1479 "Returns t if menubar was updated. Nil otherwise" |
1513 (and fume-running-xemacs | 1480 (and fume-running-xemacs |
1514 fume-not-tty | 1481 fume-not-tty |
1515 (assoc fume-menubar-menu-name current-menubar) | 1482 (assoc fume-menubar-menu-name current-menubar) |
1516 (fume-add-menubar-entry) | 1483 (fume-add-menubar-entry) |
1517 t)) | 1484 t)) |
1518 | 1485 |
1519 (defun fume-trim-string (string) | 1486 (defsubst fume-trim-string (string) |
1520 "Returns STRING with leading and trailing whitespace removed." | 1487 "Returns STRING with leading and trailing whitespace removed." |
1521 (if (string-match "^[ \t]*" (setq string (format "%s" string))) | 1488 (if (string-match "^[ \t]*" (setq string (format "%s" string))) |
1522 (setq string (substring string (match-end 0)))) | 1489 (setq string (substring string (match-end 0)))) |
1523 (if (string-match "[ \t]*$" string) | 1490 (if (string-match "[ \t]*$" string) |
1524 (setq string (substring string 0 (match-beginning 0)))) | 1491 (setq string (substring string 0 (match-beginning 0)))) |
1525 string) | 1492 string) |
1526 | 1493 |
1527 (defvar fume-syntax-table nil) | 1494 (defvar fume-syntax-table nil) |
1528 | 1495 |
1529 (defun fume-what-looking-at (&optional check-primary-selection-p) | 1496 (defsubst fume-what-looking-at () |
1530 (or (and check-primary-selection-p | 1497 (let (name |
1531 primary-selection-extent | 1498 (orig-syntax-table (copy-syntax-table (syntax-table)))) |
1532 (condition-case () | 1499 (if fume-syntax-table |
1533 (prog1 (buffer-substring (region-beginning) (region-end)) | 1500 () |
1534 (and zmacs-regions (zmacs-deactivate-region) (sit-for 0))) | 1501 (setq fume-syntax-table (copy-syntax-table)) |
1535 (error nil))) | 1502 (modify-syntax-entry ?: "w" fume-syntax-table)) |
1536 (let (name | 1503 (unwind-protect |
1537 (orig-syntax-table (copy-syntax-table (syntax-table)))) | 1504 (progn |
1538 (if fume-syntax-table | 1505 (set-syntax-table fume-syntax-table) |
1539 () | 1506 (save-excursion |
1540 (setq fume-syntax-table (copy-syntax-table)) | 1507 (while (looking-at "\\sw\\|\\s_") (forward-char 1)) |
1541 (modify-syntax-entry ?: "w" fume-syntax-table)) | 1508 (if (re-search-backward "\\sw\\|\\s_" nil t) |
1542 (unwind-protect | 1509 (let ((beg (progn (forward-char 1) (point)))) |
1543 (progn | 1510 (forward-sexp -1) |
1544 (set-syntax-table fume-syntax-table) | 1511 (while (looking-at "\\s'") (forward-char 1)) |
1545 (save-excursion | 1512 (setq name (buffer-substring beg (point))))))) |
1546 (while (looking-at "\\sw\\|\\s_") (forward-char 1)) | 1513 (set-syntax-table orig-syntax-table) |
1547 (if (re-search-backward "\\sw\\|\\s_" nil t) | 1514 name))) |
1548 (let ((beg (progn (forward-char 1) (point)))) | 1515 |
1549 (forward-sexp -1) | 1516 ;;; Find function name that point is in. |
1550 (while (looking-at "\\s'") (forward-char 1)) | 1517 ;;; The trick is to start from the end... |
1551 (setq name (buffer-substring beg (point))))))) | 1518 ;;; |
1552 (set-syntax-table orig-syntax-table) | 1519 (defsubst fume-function-before-point () |
1553 name)))) | |
1554 | |
1555 ;;; Find function name that point is in | |
1556 ;;; (trick is to start from the end) | |
1557 ;;; | |
1558 (defun fume-function-before-point () | |
1559 (if (or fume-modeline-funclist (fume-rescan-buffer) fume-modeline-funclist) | 1520 (if (or fume-modeline-funclist (fume-rescan-buffer) fume-modeline-funclist) |
1560 (let ((p (point))) | 1521 (let (result |
1522 (pt (point))) | |
1561 (save-excursion | 1523 (save-excursion |
1562 (catch 'found | 1524 (catch 'found |
1563 (mapcar (function | 1525 (mapcar (function |
1564 (lambda (x) | 1526 (lambda (p) |
1565 (goto-char (cdr x)) | 1527 (goto-char (cdr p)) |
1566 (beginning-of-line 1) | 1528 (beginning-of-line 1) |
1567 (if (>= p (point)) (throw 'found (car x))))) | 1529 (if (>= pt (point)) |
1568 fume-modeline-funclist) nil))))) | 1530 (throw 'found (setq result (car p)))))) |
1531 fume-modeline-funclist)) | |
1532 result)))) | |
1569 | 1533 |
1570 ;;; Routines to add a buffer local post command hook | 1534 ;;; Routines to add a buffer local post command hook |
1571 ;;; | 1535 ;;; |
1572 (defun fume-post-command-hook-p (hook) | 1536 (defsubst fume-post-command-hook-p (hook) |
1573 (memq hook (if fume-use-local-post-command-hook | 1537 (memq hook (if fume-use-local-post-command-hook |
1574 local-post-command-hook | 1538 local-post-command-hook |
1575 post-command-hook))) | 1539 post-command-hook))) |
1576 | 1540 |
1577 (defun fume-add-post-command-hook (hook &optional append) | 1541 (defsubst fume-add-post-command-hook (hook &optional append) |
1578 (or (fume-post-command-hook-p hook) | 1542 (or (fume-post-command-hook-p hook) |
1579 (cond (fume-use-local-post-command-hook | 1543 (cond (fume-use-local-post-command-hook |
1580 (add-hook 'local-post-command-hook hook append)) | 1544 (add-hook 'local-post-command-hook hook append)) |
1581 ((fboundp 'make-local-hook) | 1545 ((fboundp 'make-local-hook) |
1582 (make-local-hook 'post-command-hook) | 1546 (make-local-hook 'post-command-hook) |
1584 (t | 1548 (t |
1585 ;; NOT make-variable-buffer-local | 1549 ;; NOT make-variable-buffer-local |
1586 (make-local-variable 'post-command-hook) | 1550 (make-local-variable 'post-command-hook) |
1587 (add-hook 'post-command-hook hook append))))) | 1551 (add-hook 'post-command-hook hook append))))) |
1588 | 1552 |
1589 (defun fume-remove-post-command-hook (hook) | 1553 (defsubst fume-remove-post-command-hook (hook) |
1590 (and (fume-post-command-hook-p hook) | 1554 (and (fume-post-command-hook-p hook) |
1591 (cond (fume-use-local-post-command-hook | 1555 (cond (fume-use-local-post-command-hook |
1592 (remove-hook 'local-post-command-hook hook)) | 1556 (remove-hook 'local-post-command-hook hook)) |
1593 ((fboundp 'make-local-hook) | 1557 ((fboundp 'make-local-hook) |
1594 (remove-hook 'post-command-hook hook t)) | 1558 (remove-hook 'post-command-hook hook t)) |
1595 (t | 1559 (t |
1596 (remove-hook 'post-command-hook hook))))) | 1560 (remove-hook 'post-command-hook hook))))) |
1597 | 1561 |
1598 ;;; Routine to install the modeline feature | 1562 ;;; Routine to install the modeline feature |
1599 ;;; | 1563 ;;; |
1600 (defun fume-maybe-install-modeline-feature () | 1564 (defsubst fume-maybe-install-modeline-feature () |
1601 (cond ((and fume-display-in-modeline-p (fume-set-defaults)) | 1565 (cond ((and fume-display-in-modeline-p (fume-set-defaults)) |
1602 (or fume-modeline-funclist | 1566 (or fume-modeline-funclist |
1603 (fume-post-command-hook-p 'fume-tickle-modeline) | 1567 (fume-post-command-hook-p 'fume-tickle-modeline) |
1604 (fume-rescan-buffer)) | 1568 (fume-rescan-buffer)) |
1605 (fume-add-post-command-hook 'fume-tickle-modeline) | 1569 (fume-add-post-command-hook 'fume-tickle-modeline) |
1628 (t | 1592 (t |
1629 fume-modeline-buffer-identification-0)))) | 1593 fume-modeline-buffer-identification-0)))) |
1630 (cond ((not fume-display-in-modeline-p) | 1594 (cond ((not fume-display-in-modeline-p) |
1631 (fume-remove-post-command-hook 'fume-tickle-modeline) | 1595 (fume-remove-post-command-hook 'fume-tickle-modeline) |
1632 (fume-add-post-command-hook 'fume-maybe-install-modeline-feature))) | 1596 (fume-add-post-command-hook 'fume-maybe-install-modeline-feature))) |
1633 ;; force update of the modeline | 1597 ;; force an update of the mode line |
1634 (redraw-modeline)) | 1598 (fume-refresh-modeline)) |
1635 | 1599 |
1636 (fume-defvar-local fume-modeline-buffer-identification-0 nil | 1600 (fume-defvar-local fume-modeline-buffer-identification-0 nil |
1637 "Storage for original modeline-buffer-identification") | 1601 "Storage for original modeline-buffer-identification") |
1638 | 1602 |
1639 (fume-defvar-local fume-modeline-buffer-identification-1 nil | 1603 (fume-defvar-local fume-modeline-buffer-identification-1 nil |
1679 (mapcar (function (lambda (i) (cons (car i) (cdr i)))) list))) | 1643 (mapcar (function (lambda (i) (cons (car i) (cdr i)))) list))) |
1680 | 1644 |
1681 ;;; Sort function to sort items depending on their function-name | 1645 ;;; Sort function to sort items depending on their function-name |
1682 ;;; An item looks like (NAME . POSITION). | 1646 ;;; An item looks like (NAME . POSITION). |
1683 ;;; | 1647 ;;; |
1684 (defun fume-sort-by-name (item1 item2) | 1648 (defsubst fume-sort-by-name (item1 item2) |
1685 (or (string-lessp (car item1) (car item2)) | 1649 (or (string-lessp (car item1) (car item2)) |
1686 (string-equal (car item1) (car item2)))) | 1650 (string-equal (car item1) (car item2)))) |
1687 | 1651 |
1688 ;;; Sort function to sort items depending on their position | 1652 ;;; Sort function to sort items depending on their position |
1689 ;;; | 1653 ;;; |
1690 (defun fume-sort-by-position (item1 item2) | 1654 (defsubst fume-sort-by-position (item1 item2) |
1691 (<= (cdr item1) (cdr item2))) | 1655 (<= (cdr item1) (cdr item2))) |
1692 | 1656 |
1693 ;;; Support function to calculate relative position in buffer | 1657 ;;; Support function to calculate relative position in buffer |
1694 ;;; | 1658 ;;; |
1695 (defun fume-relative-position () | 1659 (defsubst fume-relative-position () |
1696 (let ((pos (point)) | 1660 (let ((pos (point)) |
1697 (total (buffer-size))) | 1661 (total (buffer-size))) |
1698 (if (> total 50000) | 1662 (if (> total 50000) |
1699 ;; Avoid overflow from multiplying by 100! | 1663 ;; Avoid overflow from multiplying by 100! |
1700 (/ (1- pos) (max (/ total 100) 1)) | 1664 (/ (1- pos) (max (/ total 100) 1)) |
1702 (max total 1))))) | 1666 (max total 1))))) |
1703 | 1667 |
1704 ;;; Split LIST into sublists of max length N | 1668 ;;; Split LIST into sublists of max length N |
1705 ;;; Example (fume-split '(1 2 3 4 5 6 7 8) 3)-> '((1 2 3) (4 5 6) (7 8)) | 1669 ;;; Example (fume-split '(1 2 3 4 5 6 7 8) 3)-> '((1 2 3) (4 5 6) (7 8)) |
1706 ;;; | 1670 ;;; |
1707 (defun fume-split (list n) | 1671 (defsubst fume-split (list n) |
1708 (let ((i 0) | 1672 (let ((i 0) |
1709 result | 1673 result |
1710 sublist | 1674 sublist |
1711 (remain list)) | 1675 (remain list)) |
1712 (while remain | 1676 (while remain |
1787 "Automatically spots when a buffer rescan becomes necessary" | 1751 "Automatically spots when a buffer rescan becomes necessary" |
1788 (if fume-auto-rescan-buffer-p | 1752 (if fume-auto-rescan-buffer-p |
1789 (if (> fume-rescan-trigger-counter 0) | 1753 (if (> fume-rescan-trigger-counter 0) |
1790 (setq fume-rescan-trigger-counter (1- fume-rescan-trigger-counter)) | 1754 (setq fume-rescan-trigger-counter (1- fume-rescan-trigger-counter)) |
1791 (setq fume-rescan-trigger-counter | 1755 (setq fume-rescan-trigger-counter |
1792 (max fume-rescan-trigger-counter-min | 1756 (/ (buffer-size) fume-rescan-trigger-counter-buffer-size)) |
1793 (/ (buffer-size) fume-rescan-trigger-counter-buffer-size))) | |
1794 (if (or fume-funclist-dirty-p | 1757 (if (or fume-funclist-dirty-p |
1795 (save-excursion | 1758 (save-excursion |
1796 (let (find fnam) | 1759 (let (find fnam) |
1797 (condition-case () | 1760 (condition-case () |
1798 (and fume-function-name-regexp | 1761 (and fume-function-name-regexp |
1817 (car (funcall find (current-buffer))))))) | 1780 (car (funcall find (current-buffer))))))) |
1818 (error nil))))) | 1781 (error nil))))) |
1819 (let ((fume-scanning-message nil)) | 1782 (let ((fume-scanning-message nil)) |
1820 (fume-rescan-buffer)))))) | 1783 (fume-rescan-buffer)))))) |
1821 | 1784 |
1822 (defun fume-install-rescan-buffer-trigger () | 1785 (defsubst fume-install-rescan-buffer-trigger () |
1823 (cond ((not (fume-post-command-hook-p 'fume-rescan-buffer-trigger)) | 1786 (cond ((not (fume-post-command-hook-p 'fume-rescan-buffer-trigger)) |
1824 (fume-add-post-command-hook 'fume-rescan-buffer-trigger 'append) | 1787 (fume-add-post-command-hook 'fume-rescan-buffer-trigger 'append) |
1825 ;; Make narrow-to-region tickle func-menu | 1788 ;; Make narrow-to-region tickle func-menu |
1826 (or (fboundp 'fume-narrow-to-region) | 1789 (or (fboundp 'fume-narrow-to-region) |
1827 (fset 'fume-narrow-to-region | 1790 (fset 'fume-narrow-to-region |
1899 (let ((fume-rescan-inhibit-p t)) | 1862 (let ((fume-rescan-inhibit-p t)) |
1900 (fume-update-menubar-entry))) | 1863 (fume-update-menubar-entry))) |
1901 ;; Reset dirty flag | 1864 ;; Reset dirty flag |
1902 (setq fume-funclist-dirty-p nil)) | 1865 (setq fume-funclist-dirty-p nil)) |
1903 | 1866 |
1904 (defun fume-scan-buffer () | |
1905 (or fume-funclist (progn (fume-set-defaults) (fume-rescan-buffer)))) | |
1906 | |
1907 ;;; Routine to position cursor | 1867 ;;; Routine to position cursor |
1908 ;;; | 1868 ;;; |
1909 (defun fume-goto-function (fn pos) | 1869 (defun fume-goto-function (fn pos) |
1910 "Position cursor at function FN at location POS" | 1870 "Position cursor at function FN at location POS" |
1911 (let ((orig-pos (point)) | 1871 (let ((orig-pos (point)) |
1959 (call-interactively 'function-menu))) | 1919 (call-interactively 'function-menu))) |
1960 (error (select-window currwin))))) | 1920 (error (select-window currwin))))) |
1961 | 1921 |
1962 ;;; Interface for Key bindings | 1922 ;;; Interface for Key bindings |
1963 ;;; | 1923 ;;; |
1964 (defun function-menu (&optional use-menubar return-only) | 1924 (defun function-menu (&optional use-menubar) |
1965 "Pop up a menu of functions for selection with the mouse. | 1925 "Pop up a menu of functions for selection with the mouse. |
1926 | |
1927 With a prefix arg adds the menu to the current menubar. | |
1966 Jumps to the selected function. A mark is set at the old position, | 1928 Jumps to the selected function. A mark is set at the old position, |
1967 so you can easily go back with C-u \\[set-mark-command]. | 1929 so you can easily go back with C-u \\[set-mark-command]." |
1968 | |
1969 With a prefix arg adds the menu to the current menubar. | |
1970 Optional second argument, RETURN-ONLY if non-nil simply returns | |
1971 the basic menu of functions." | |
1972 (interactive "P") | 1930 (interactive "P") |
1973 | 1931 |
1974 (setq use-menubar | 1932 (setq use-menubar |
1975 (and use-menubar fume-running-xemacs fume-not-tty current-menubar)) | 1933 (and use-menubar fume-running-xemacs fume-not-tty current-menubar)) |
1976 | 1934 |
2022 (fume-split fume-funclist fume-max-items)))) | 1980 (fume-split fume-funclist fume-max-items)))) |
2023 | 1981 |
2024 (or (> count 1) | 1982 (or (> count 1) |
2025 (setq function-menu-items (cdr (car function-menu-items)))) | 1983 (setq function-menu-items (cdr (car function-menu-items)))) |
2026 | 1984 |
2027 (if return-only | 1985 (setq function-menu |
2028 nil | 1986 (` ((,@ function-menu-items) |
2029 (setq function-menu | 1987 "----" |
2030 (` ((,@ function-menu-items) | 1988 ["Display full list of functions" |
1989 fume-list-functions t] | |
1990 [(, (concat "Rescan buffer : " (buffer-name))) | |
1991 (fume-rescan-buffer (, (null use-menubar))) t] | |
1992 "----" | |
1993 ["Toggle modeline display" | |
1994 fume-toggle-modeline-display t] | |
1995 ["Toggle buffer auto rescanning" | |
1996 fume-toggle-auto-rescanning t] | |
1997 ["About Func-Menu" fume-about t]))) | |
1998 | |
1999 (cond (use-menubar | |
2000 (fume-remove-menubar-entry) | |
2001 (set-buffer-menubar (copy-sequence current-menubar)) | |
2002 (fume-add-submenu | |
2003 fume-menubar-menu-name | |
2004 (` ((,@ function-menu) | |
2031 "----" | 2005 "----" |
2032 ["Display full list of functions" | 2006 ["Remove Function Menu from menubar" |
2033 fume-list-functions t] | 2007 fume-remove-menubar-entry t])) |
2034 [(, (concat "Rescan buffer : " (buffer-name))) | 2008 fume-menubar-menu-location)) |
2035 (fume-rescan-buffer (, (null use-menubar))) t] | 2009 |
2036 "----" | 2010 ((and fume-not-tty ; trap tty segmentation faults... |
2037 ["Toggle modeline display" | 2011 (not (popup-menu-up-p))) |
2038 fume-toggle-modeline-display t] | 2012 (or (fume-update-menubar-entry) |
2039 ["Toggle buffer auto rescanning" | 2013 (setq function-menu |
2040 fume-toggle-auto-rescanning t] | 2014 (cons |
2041 ["About Func-Menu" fume-about t]))) | 2015 ["Put Function Menu into menubar" |
2042 | 2016 (function-menu t) t] |
2043 (cond (use-menubar | 2017 (cons "----" function-menu)))) |
2044 (fume-remove-menubar-entry) | 2018 |
2045 (set-buffer-menubar (copy-sequence current-menubar)) | 2019 (if fume-auto-position-popup |
2046 (fume-add-submenu | 2020 (fume-set-mouse-position)) |
2047 fume-menubar-menu-name | 2021 |
2048 (` ((,@ function-menu) | 2022 (popup-menu (cons "Functions" function-menu))))))))) |
2049 "----" | |
2050 ["Remove Function Menu from menubar" | |
2051 fume-remove-menubar-entry t])) | |
2052 fume-menubar-menu-location)) | |
2053 | |
2054 ((and fume-not-tty ; trap tty segmentation faults... | |
2055 (not (popup-menu-up-p))) | |
2056 (or (fume-update-menubar-entry) | |
2057 (setq function-menu | |
2058 (cons | |
2059 ["Put Function Menu into menubar" | |
2060 (function-menu t) t] | |
2061 (cons "----" function-menu)))) | |
2062 | |
2063 (if fume-auto-position-popup | |
2064 (fume-set-mouse-position)) | |
2065 | |
2066 (popup-menu | |
2067 (cons fume-menubar-menu-name function-menu))))) | |
2068 | |
2069 ;; Return basic function menu for display by another function | |
2070 function-menu-items))))) | |
2071 | 2023 |
2072 (defun fume-mouse-function-goto (event) | 2024 (defun fume-mouse-function-goto (event) |
2073 "Goto function clicked on or prompt in minibuffer (with completion)." | 2025 "Goto function clicked on or prompt in minibuffer (with completion)." |
2074 (interactive "@e") | 2026 (interactive "@e") |
2075 (let ((orig-pos (point))) | 2027 (goto-char (event-point event)) |
2076 (goto-char (event-point event)) | 2028 (let ((fume-no-prompt-on-valid-default t)) |
2077 (let ((fume-no-prompt-on-valid-default t)) | 2029 (fume-prompt-function-goto))) |
2078 (fume-prompt-function-goto)) | |
2079 (or (= orig-pos (point)) | |
2080 (push-mark orig-pos (null fume-scanning-message))))) | |
2081 | 2030 |
2082 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 2031 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2083 ;;;;;;;;;;;;;;;; Keyboard access to func-menu for tty users ;;;;;;;;;;;;;; | 2032 ;;;;;;;;;;;;;;;; Keyboard access to func-menu for tty users ;;;;;;;;;;;;;; |
2084 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 2033 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2085 | 2034 |
2094 ;;; | 2043 ;;; |
2095 (defun fume-prompt-function-goto (&optional other-window-p) | 2044 (defun fume-prompt-function-goto (&optional other-window-p) |
2096 "Goto function prompted for in minibuffer (with completion). | 2045 "Goto function prompted for in minibuffer (with completion). |
2097 With prefix arg, jumps to function in a different window." | 2046 With prefix arg, jumps to function in a different window." |
2098 (interactive "P") | 2047 (interactive "P") |
2099 (let* ((default-name (fume-what-looking-at t)) | 2048 (and (interactive-p) current-prefix-arg (setq other-window-p t)) |
2049 (let* ((default-name (fume-what-looking-at)) | |
2100 (OrigBuffer (current-buffer)) | 2050 (OrigBuffer (current-buffer)) |
2101 (flistMode (eq major-mode 'fume-list-mode)) | 2051 (TargetBuffer |
2102 (no-prompt (or flistMode fume-no-prompt-on-valid-default)) | 2052 (if (eq major-mode 'fume-list-mode) fume-list-srcbuffer OrigBuffer)) |
2103 (TargetBuffer (if flistMode fume-list-srcbuffer OrigBuffer))) | 2053 (fume-no-prompt-on-valid-default |
2054 (or fume-no-prompt-on-valid-default | |
2055 (eq major-mode 'fume-list-mode)))) | |
2104 (switch-to-buffer TargetBuffer) | 2056 (switch-to-buffer TargetBuffer) |
2105 (fume-scan-buffer) ;; Create funclist and set defaults if required | 2057 ;; Create funclist and set defaults |
2058 (cond ((null fume-funclist) | |
2059 (fume-set-defaults) | |
2060 (fume-rescan-buffer))) | |
2106 (let* (;; verify default-name is a valid function name | 2061 (let* (;; verify default-name is a valid function name |
2107 (default-exists-p (assoc default-name fume-funclist)) | 2062 (default-exists-p (assoc default-name fume-funclist)) |
2108 ;; Prompt for function name in minibuffer, unless there is a valid | 2063 ;; Prompt for function name in minibuffer, unless there is a valid |
2109 ;; function name at point & fume-no-prompt-on-valid-default set to t | 2064 ;; function name at point & fume-no-prompt-on-valid-default set to t |
2110 (function-name | 2065 (function-name |
2111 (if (and default-exists-p no-prompt) | 2066 (if (and default-exists-p |
2067 fume-no-prompt-on-valid-default) | |
2112 "" | 2068 "" |
2113 (let ((this-command last-command)) ; preserve last-command | 2069 (completing-read |
2114 (completing-read | 2070 (format "Goto function%s%s: " |
2115 (format "Goto function%s%s: " | 2071 (if other-window-p " other window" "") |
2116 (if other-window-p " other window" "") | 2072 (if default-exists-p |
2117 (if default-exists-p | 2073 (concat " (" default-name ")") |
2118 (concat " (" default-name ")") | 2074 "")) |
2119 "")) | 2075 fume-funclist nil t))) |
2120 fume-funclist nil t)))) | |
2121 ;; Use default function name if just RET was pressed | 2076 ;; Use default function name if just RET was pressed |
2122 (function-name (if (and default-exists-p (string= "" function-name)) | 2077 (function-name (if (and default-exists-p (string= "" function-name)) |
2123 default-name | 2078 default-name |
2124 function-name))) | 2079 function-name))) |
2125 (switch-to-buffer OrigBuffer) | 2080 (switch-to-buffer OrigBuffer) |
2126 ;; Goto function or just return if function name is empty string | 2081 ;; Goto function or just return if function name is empty string |
2127 (cond ((not (string= "" function-name)) | 2082 (cond ((not (string= "" function-name)) |
2128 (if other-window-p | 2083 (if other-window-p |
2129 (cond ((prog1 (one-window-p) | 2084 (cond ((prog1 (one-window-p) |
2130 (if (not (windowp other-window-p)) | 2085 (switch-to-buffer-other-window TargetBuffer)) |
2131 (switch-to-buffer-other-window TargetBuffer) | |
2132 (select-window other-window-p) | |
2133 (switch-to-buffer TargetBuffer))) | |
2134 (other-window 1) | 2086 (other-window 1) |
2135 (shrink-window-if-larger-than-buffer) | 2087 (shrink-window-if-larger-than-buffer) |
2136 (other-window 1))) | 2088 (other-window 1))) |
2137 (switch-to-buffer TargetBuffer)) | 2089 (switch-to-buffer TargetBuffer)) |
2138 (fume-goto-function | 2090 (fume-goto-function |
2143 (delete-other-windows) | 2095 (delete-other-windows) |
2144 (fume-prompt-function-goto)) | 2096 (fume-prompt-function-goto)) |
2145 | 2097 |
2146 (defun fume-prompt-function-goto-other-window () | 2098 (defun fume-prompt-function-goto-other-window () |
2147 (interactive) | 2099 (interactive) |
2148 (fume-prompt-function-goto t)) | 2100 (let ((current-prefix-arg 1)) |
2149 | 2101 (call-interactively 'fume-prompt-function-goto))) |
2150 (defun fume-list-functions-show-fn-other-window (&optional window) | 2102 |
2103 (defun fume-list-functions-show-fn-other-window () | |
2151 (interactive) | 2104 (interactive) |
2152 (beginning-of-line) | 2105 (beginning-of-line) |
2153 (select-window | 2106 (select-window |
2154 (prog1 (selected-window) (fume-prompt-function-goto (or window t))))) | 2107 (prog1 (selected-window) |
2155 | 2108 (fume-prompt-function-goto-other-window)))) |
2156 (defun fume-list-functions-show-prev-fn-other-window (&optional window) | 2109 |
2110 (defun fume-list-functions-show-prev-fn-other-window () | |
2157 (interactive) | 2111 (interactive) |
2158 (forward-line -1) | 2112 (forward-line -1) |
2159 (fume-list-functions-show-fn-other-window window)) | 2113 (fume-list-functions-show-fn-other-window)) |
2160 | 2114 |
2161 (defun fume-list-functions-show-next-fn-other-window (&optional window) | 2115 (defun fume-list-functions-show-next-fn-other-window () |
2162 (interactive) | 2116 (interactive) |
2163 (forward-line 1) | 2117 (forward-line 1) |
2164 (beginning-of-line) | 2118 (beginning-of-line) |
2165 (fume-list-functions-show-fn-other-window window)) | 2119 (fume-list-functions-show-fn-other-window)) |
2166 | 2120 |
2167 (defun fume-list-functions-help () | 2121 (defun fume-list-functions-help () |
2168 (interactive) | 2122 (interactive) |
2169 (fume-about) | 2123 (fume-about) |
2170 (sit-for 1) | 2124 (sit-for 1) |
2229 (defvar fume-list-mode-hook nil "*Hook to run after fume-list-mode entered") | 2183 (defvar fume-list-mode-hook nil "*Hook to run after fume-list-mode entered") |
2230 | 2184 |
2231 (defun fume-list-functions (&optional this-window) | 2185 (defun fume-list-functions (&optional this-window) |
2232 "Creates a temporary buffer listing functions found in the current buffer" | 2186 "Creates a temporary buffer listing functions found in the current buffer" |
2233 (interactive "P") | 2187 (interactive "P") |
2234 (fume-scan-buffer) ;; Create funclist and set defaults if required | |
2235 (let ((func-near-point (format "^%s$" (fume-function-before-point)))) | 2188 (let ((func-near-point (format "^%s$" (fume-function-before-point)))) |
2236 (cond ((or fume-function-name-regexp (fume-maybe-install-modeline-feature)) | 2189 (cond ((or fume-function-name-regexp (fume-maybe-install-modeline-feature)) |
2237 (save-excursion | 2190 (save-excursion |
2238 (let ((srcbuffer (current-buffer))) | 2191 (let ((srcbuffer (current-buffer))) |
2239 (set-buffer (get-buffer-create fume-buffer-name)) | 2192 (set-buffer (get-buffer-create fume-buffer-name)) |
2274 (fume-list-functions-help)))) | 2227 (fume-list-functions-help)))) |
2275 (t | 2228 (t |
2276 (error "Func-Menu is not operative in this buffer"))))) | 2229 (error "Func-Menu is not operative in this buffer"))))) |
2277 | 2230 |
2278 (provide 'func-menu) | 2231 (provide 'func-menu) |
2279 | |
2280 ;;; end of file |