comparison lisp/packages/func-menu.el @ 82:6a378aca36af r20-0b91

Import from CVS: tag r20-0b91
author cvs
date Mon, 13 Aug 2007 09:07:36 +0200
parents 131b0175ea99
children 4be1180a9e89
comparison
equal deleted inserted replaced
81:ebca3d831cea 82:6a378aca36af
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 2nd May 1996 4 ;;; Last modified: David Hughes 13th January 1997
5 ;;; Version: 2.43 5 ;;; Version: 2.45
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 Windows versions of Emacs: 46 ;;; Support for non X Window 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 ;;;
61 ;;; Fortran90 regexp 70 ;;; Fortran90 regexp
62 ;;; John Turner <turner@xdiv.lanl.gov> 71 ;;; John Turner <turner@xdiv.lanl.gov>
63 ;;; 72 ;;;
64 ;;; Patch to error trap in fume-rescan-buffer 73 ;;; Patch to error trap in fume-rescan-buffer
65 ;;; Andy Piper <andyp@parallax.co.uk> 74 ;;; Andy Piper <andyp@parallax.co.uk>
66 ;;; 75 ;;;
67 ;;; Java support 76 ;;; Java support
77 ;;; Bob Weiner <weiner@infodock.com>
68 ;;; Heddy Boubaker <boubaker@dgac.fr> 78 ;;; Heddy Boubaker <boubaker@dgac.fr>
69 ;;; 79 ;;;
70 ;;; Patch for fume-rescan-buffer{-trigger} 80 ;;; Patch for fume-rescan-buffer{-trigger}
71 ;;; Christoph Wedler <wedler@vivaldi.fmi.uni-passau.de> 81 ;;; Christoph Wedler <wedler@vivaldi.fmi.uni-passau.de>
72 ;;; 82 ;;;
138 ;;; 148 ;;;
139 ;;; SGML support; submenu indexing 149 ;;; SGML support; submenu indexing
140 ;;; Thomas Plass <thomas.plass@mid-heidelberg.de> 150 ;;; Thomas Plass <thomas.plass@mid-heidelberg.de>
141 ;;; 151 ;;;
142 ;;; Extensions to fume-function-name-regexp-lisp 152 ;;; Extensions to fume-function-name-regexp-lisp
153 ;;; Vladimir Alexiev <vladimir@cs.ualberta.ca>
143 ;;; Kari Heinola <kph@dpe.fi> 154 ;;; Kari Heinola <kph@dpe.fi>
144 ;;; Milo A. Chan <chan@jpmorgan.com> 155 ;;; Milo A. Chan <chan@jpmorgan.com>
145 ;;; Jack Repenning <jackr@step7.informix.com> 156 ;;; Jack Repenning <jackr@step7.informix.com>
146 ;;; Cedric Beust <Cedric.Beust@sophia.inria.fr> 157 ;;; Cedric Beust <Cedric.Beust@sophia.inria.fr>
147 ;;; Joachim Krumnow <krumnow@srsir02.ext.sap-ag.de> 158 ;;; Joachim Krumnow <krumnow@srsir02.ext.sap-ag.de>
160 ;;; Paolo Frasconi <paolo@mcculloch.ing.unifi.it> 171 ;;; Paolo Frasconi <paolo@mcculloch.ing.unifi.it>
161 ;;; C. Michael Holloway <c.m.holloway@larc.nasa.gov> 172 ;;; C. Michael Holloway <c.m.holloway@larc.nasa.gov>
162 ;;; Philippe Queinnec <queinnec@cenatls.cena.dgac.fr> 173 ;;; Philippe Queinnec <queinnec@cenatls.cena.dgac.fr>
163 ;;; 174 ;;;
164 ;;; Assembly support 175 ;;; Assembly support
165 ;;; Bob Weiner <weiner@mot.com> 176 ;;; Bob Weiner <weiner@infodock.com>
166 ;;; 177 ;;;
167 ;;; Removal of cl dependencies 178 ;;; Removal of cl dependencies
168 ;;; Russell Ritchie <russell@gssec.bt.co.uk> 179 ;;; Russell Ritchie <russell@gssec.bt.co.uk>
169 ;;; 180 ;;;
170 ;;; C++ mode enhancemencements for func-menu 181 ;;; C++ mode enhancemencements for func-menu
200 211
201 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 212 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
202 ;;;;;;;;;;;;;;;;;;;;;;;; Environment Initialisation ;;;;;;;;;;;;;;;;;;;;;; 213 ;;;;;;;;;;;;;;;;;;;;;;;; Environment Initialisation ;;;;;;;;;;;;;;;;;;;;;;
203 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 214 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
204 215
205 (defconst fume-version "2.43") 216 (defconst fume-version "2.45")
206 217
207 (defconst fume-developer "David Hughes <ukchugd@ukpmr.cs.philips.nl>") 218 (defconst fume-developer "David Hughes <ukchugd@ukpmr.cs.philips.nl>")
208 219
209 (defun fume-about () 220 (defun fume-about ()
210 (interactive) 221 (interactive)
211 (sit-for 0) 222 (sit-for 0)
212 (message "Func-Menu version %s, ¨ 1996 %s" fume-version fume-developer)) 223 (message "Func-Menu version %s, © 1996 %s" fume-version fume-developer))
213 224
214 (defconst fume-running-xemacs (string-match "XEmacs\\|Lucid" emacs-version)) 225 (defconst fume-running-xemacs (string-match "XEmacs\\|Lucid" emacs-version))
215 226
216 (defmacro fume-defvar-local (var value &optional doc) 227 (defmacro fume-defvar-local (var value &optional doc)
217 "Defines SYMBOL as an advertised variable. 228 "Defines SYMBOL as an advertised variable.
363 (boundp 'local-post-command-hook)) 374 (boundp 'local-post-command-hook))
364 375
365 (cond ((fboundp 'add-submenu) 376 (cond ((fboundp 'add-submenu)
366 (defconst fume-add-submenu 'add-submenu) 377 (defconst fume-add-submenu 'add-submenu)
367 (defun fume-munge-menu-args (menu-name submenu before) 378 (defun fume-munge-menu-args (menu-name submenu before)
368 (list nil (cons menu-name submenu) before))) 379 (list fume-menu-path (cons menu-name submenu) before)))
369 (t 380 (t
370 (defconst fume-add-submenu 'add-menu) 381 (defconst fume-add-submenu 'add-menu)
371 (defun fume-munge-menu-args (menu-name submenu before) 382 (defun fume-munge-menu-args (menu-name submenu before)
372 (list nil menu-name submenu before)))) 383 (list fume-menu-path menu-name submenu before))))
373 384
374 (defun fume-add-submenu (menu-name submenu before) 385 (defun fume-add-submenu (menu-name submenu before)
375 (apply fume-add-submenu (fume-munge-menu-args menu-name submenu before))) 386 (apply fume-add-submenu (fume-munge-menu-args menu-name submenu before)))
376 387
377 (defconst fume-not-tty 388 (defconst fume-not-tty
395 Note, this is a buffer-local variable.") 406 Note, this is a buffer-local variable.")
396 407
397 (defvar fume-buffer-name "*Function List*" 408 (defvar fume-buffer-name "*Function List*"
398 "Name of buffer used to list functions when fume-list-functions called") 409 "Name of buffer used to list functions when fume-list-functions called")
399 410
400 (fume-defvar-local 411 (defvar fume-menubar-menu-name "Functions"
401 fume-menubar-menu-name "Functions"
402 "*Set this to the string you want to appear in the menubar") 412 "*Set this to the string you want to appear in the menubar")
413
414 ;;; Bob Weiner <weiner@infodock.com>
415 (defvar fume-menu-path nil
416 "Menubar menu under which the function menu should be installed.
417 Nil means install it on the menubar itself. Otherwise, it should be a list
418 of strings, each string names a successively deeper menu under which the
419 new menu should be located.")
403 420
404 (defvar fume-menubar-menu-location "Buffers" 421 (defvar fume-menubar-menu-location "Buffers"
405 "*Set this nil if you want the menu to appear last on the menubar. 422 "*Set this nil if you want the menu to appear last on the menubar.
406 Otherwise set this to the menu you want \"Functions\" to appear in front of.") 423 Otherwise set this to the menu you want \"Functions\" to appear in front of.")
407 424
518 ;;; Every fume-function-name-regexp-<language> should uniquely identify a 535 ;;; Every fume-function-name-regexp-<language> should uniquely identify a
519 ;;; function for that certain language. 536 ;;; function for that certain language.
520 537
521 ;;; Lisp 538 ;;; Lisp
522 ;;; 539 ;;;
523 ;;; Jack Repenning <jackr@step7.informix.com> 540 ;;; Vladimir Alexiev <vladimir@cs.ualberta.ca>
524 ;;; Cedric Beust <Cedric.Beust@sophia.inria.fr>
525 (defvar fume-function-name-regexp-lisp 541 (defvar fume-function-name-regexp-lisp
526 (concat 542 (concat
527 "\\(^(defun+\\s-*[#:?A-Za-z0-9_+->]+\\s-*(\\)" 543 "^[ \t]*" ; Allow whitespace |(or (fboundp 'foo)
528 "\\|" 544 ; for the construct | (defun foo ()
529 "\\(^(defsubst+\\s-*[#:?A-Za-z0-9_+->]+\\s-*(\\)" 545 "(\\(def[^vc][a-z]*\\)" ; Allow (def* except (defvar, (defconst
530 "\\|" 546 "\\s-+" ; At least one whitespace
531 "\\(^(defmacro+\\s-*[#:?A-Za-z0-9_+->]+\\s-*(\\)" 547 "'?[#:?A-Za-z0-9_+>-]+" ; Allow (defalias 'foo 'bar)
532 "\\|" 548 "\\s-*" ; Whitespace
533 "\\(^(defadvice+\\s-*[#:?A-Za-z0-9_+->]+\\s-*(\\)" 549 "\\(nil\\|(\\)" ; nil or (arg list
534 "\\|"
535 "\\(^(de+\\s-*[#:?A-Za-z0-9_+->]+\\s-*(\\)"
536 "\\|"
537 "\\(^(dmd+\\s-*[#:?A-Za-z0-9_+->]+\\s-*(\\)"
538 ) 550 )
539 "Expression to get lisp function names") 551 "Expression to get lisp function names")
540 552
541 ;;; C 553 ;;; C
542 ;;; 554 ;;;
543 ;;; Danny Bar-Dov <danny@acet02.amil.co.il> 555 ;;; Danny Bar-Dov <danny@acet02.amil.co.il>
544 (defvar fume-function-name-regexp-c 556 (defvar fume-function-name-regexp-c
545 (concat 557 (concat
546 "^[a-zA-Z0-9]+\\s-?" ; type specs; there can be no 558 "^[a-zA-Z0-9_]+\\s-?" ; type specs; there can be no
547 "\\([a-zA-Z0-9_*]+\\s-+\\)?" ; more than 3 tokens, right? 559 "\\([a-zA-Z0-9_*]+\\s-+\\)?" ; more than 3 tokens, right?
548 "\\([a-zA-Z0-9_*]+\\s-+\\)?" 560 "\\([a-zA-Z0-9_*]+\\s-+\\)?"
549 "\\([*&]+\\s-*\\)?" ; pointer 561 "\\([*&]+\\s-*\\)?" ; pointer
550 "\\([a-zA-Z0-9_*]+\\)[ \t\n]*(" ; name 562 "\\([a-zA-Z0-9_*]+\\)[ \t\n]*(" ; name
551 ) 563 )
552 "Expression to get C function names") 564 "Expression to get C function names")
553 565
554 ;;; C++ 566 ;;; C++
555 ;;; 567 ;;;
785 ;;; 797 ;;;
786 ;;; Paul Filipski & Anthony Girardin <{filipski,girardin}@blackhawk.com> 798 ;;; Paul Filipski & Anthony Girardin <{filipski,girardin}@blackhawk.com>
787 (defvar fume-function-name-regexp-make 799 (defvar fume-function-name-regexp-make
788 "^\\(\\(\\$\\s(\\)?\\(\\w\\|\\.\\)+\\(:sh\\)?\\(\\s)\\)?\\)\\s *\\(::?\\|\\+?=\\)" 800 "^\\(\\(\\$\\s(\\)?\\(\\w\\|\\.\\)+\\(:sh\\)?\\(\\s)\\)?\\)\\s *\\(::?\\|\\+?=\\)"
789 "Expression to get makefile target names") 801 "Expression to get makefile target names")
802 (add-hook 'makefile-mode-hook 'fume-add-menubar-entry)
790 803
791 ;;; Directory Listings 804 ;;; Directory Listings
792 ;;; 805 ;;;
793 ;;; Norbert Kiesel <norbert@i3.informatik.rwth-aachen.de> 806 ;;; Norbert Kiesel <norbert@i3.informatik.rwth-aachen.de>
794 ;;; regexp stolen from font-lock-mode 807 ;;; regexp stolen from font-lock-mode
817 ;;; Matt Sale <mdsale@icdc.delcoelect.com> 830 ;;; Matt Sale <mdsale@icdc.delcoelect.com>
818 (defvar fume-function-name-regexp-verilog 831 (defvar fume-function-name-regexp-verilog
819 "^\\(task\\|function\\|module\\|primitive\\)[ \t]+\\([A-Za-z0-9_+-]*\\)[ \t]*(?" 832 "^\\(task\\|function\\|module\\|primitive\\)[ \t]+\\([A-Za-z0-9_+-]*\\)[ \t]*(?"
820 "Expression to get verilog module names") 833 "Expression to get verilog module names")
821 834
835 ;;; Idl
836 ;;;
837 ;;; Lubos Pochman <lubos@rsinc.com>
838 (defvar fume-function-name-regexp-idl
839 (cons "^\\s *\\([pP][rR][oO]\\|[fF][uU][nN][cC][tT][iI][oO][nN]\\)\\s +\\([A-Za-z][A-Za-z0-9_$]*\\)" 2)
840 "Expression to get Idl function Names")
822 841
823 ;;; Assembly 842 ;;; Assembly
824 (defvar fume-function-name-regexp-asm 843 (defvar fume-function-name-regexp-asm
825 "^\\([a-zA-Z_.$][a-zA-Z0-9_.$]*\\)[ \t]*:" 844 "^\\([a-zA-Z_.$][a-zA-Z0-9_.$]*\\)[ \t]*:"
826 "Expression to get assembly label names") 845 "Expression to get assembly label names")
917 (fame-mode . fume-function-name-regexp-fame) 936 (fame-mode . fume-function-name-regexp-fame)
918 937
919 ;; Verilog 938 ;; Verilog
920 (verilog-mode . fume-function-name-regexp-verilog) 939 (verilog-mode . fume-function-name-regexp-verilog)
921 940
941 ;; Idl
942 (idl-mode . fume-function-name-regexp-idl)
943
922 ;; Assembly 944 ;; Assembly
923 (asm-mode . fume-function-name-regexp-asm) 945 (asm-mode . fume-function-name-regexp-asm)
924 ) 946 )
925 947
926 "The connection between a mode and the regexp that matches function names.") 948 "The connection between a mode and the regexp that matches function names.")
935 "Searches for the next function in BUFFER." 957 "Searches for the next function in BUFFER."
936 (set-buffer buffer) 958 (set-buffer buffer)
937 ;; Search for the function 959 ;; Search for the function
938 (if (re-search-forward fume-function-name-regexp nil t) 960 (if (re-search-forward fume-function-name-regexp nil t)
939 (let ((char (progn 961 (let ((char (progn
940 (backward-up-list 1) 962 (if (string-match
963 "[({[]"
964 (char-to-string (char-after (1- (point)))))
965 (backward-char)
966 (forward-word -1))
941 (save-excursion 967 (save-excursion
942 (goto-char (scan-sexps (point) 1)) 968 (goto-char (scan-sexps (point) 1))
943 (skip-chars-forward "[ \t\n]") 969 (skip-chars-forward "[ \t\n]")
944 (following-char))))) 970 (following-char)))))
945 ;; Skip this function name if it is a prototype declaration. 971 ;; Skip this function name if it is a prototype declaration.
983 (if (looking-at ":") 1009 (if (looking-at ":")
984 (setq end (1- end))) 1010 (setq end (1- end)))
985 (cons (buffer-substring beg end) beg)))) 1011 (cons (buffer-substring beg end) beg))))
986 1012
987 ;;; Specialised routine to get the next C function name in the buffer. 1013 ;;; Specialised routine to get the next C function name in the buffer.
1014 ;;; Modified 16/12/96: Jerome Bertorelle <bertorel@telspace.alcatel.fr>
988 ;;; 1015 ;;;
989 (defun fume-find-next-c-function-name (buffer) 1016 (defun fume-find-next-c-function-name (buffer)
990 "Searches for the next C function in BUFFER." 1017 "Searches for the next C function in BUFFER."
991 (set-buffer buffer) 1018 (set-buffer buffer)
992 ;; Search for the function 1019 ;; Search for the function
997 (goto-char (scan-sexps (point) 1)) 1024 (goto-char (scan-sexps (point) 1))
998 (skip-chars-forward "[ \t\n]") 1025 (skip-chars-forward "[ \t\n]")
999 (following-char))))) 1026 (following-char)))))
1000 ;; Skip this function name if it is a prototype declaration. 1027 ;; Skip this function name if it is a prototype declaration.
1001 (if (eq char ?\;) 1028 (if (eq char ?\;)
1002 (fume-find-next-function-name buffer) 1029 (fume-find-next-c-function-name buffer)
1003 (let (beg 1030 (let (beg
1004 name) 1031 name)
1005 ;; Get the function name and position 1032 ;; Get the function name and position
1006 (forward-sexp -1) 1033 (forward-sexp -1)
1007 (setq beg (point)) 1034 (setq beg (point))
1016 (re-search-backward "\"," nil t) 1043 (re-search-backward "\"," nil t)
1017 (setq name 1044 (setq name
1018 (format "%s %s" 1045 (format "%s %s"
1019 name 1046 name
1020 (buffer-substring beg (point)))))))) 1047 (buffer-substring beg (point))))))))
1021 ;; kludge to avoid 'void' in menu 1048 ;; kludge to avoid 'void' etc in menu
1022 (if (string-match "^void\\s-*" name) 1049 (if (string-match "^void$\\|^if$\\|^switch$\\|^while$" name)
1023 (fume-find-next-function-name buffer) 1050 (fume-find-next-c-function-name buffer)
1024 (cons name beg))))))) 1051 (cons name beg)))))))
1025 1052
1053 ;;; Peter Pezaris <pez@dwwc.com>
1054 ;;;
1026 (defun fume-cc-inside-comment () 1055 (defun fume-cc-inside-comment ()
1027 (let ((here (point)) 1056 (memq (buffer-syntactic-context) '(comment block-comment)))
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)))))
1039 1057
1040 ;;; <jrm@odi.com> 1058 ;;; <jrm@odi.com>
1041 ;;; <ajp@eng.cam.ac.uk> 1059 ;;; <ajp@eng.cam.ac.uk>
1042 ;;; <schittko@fokus.gmd.de> 1060 ;;; <schittko@fokus.gmd.de>
1061 ;;; <ukchugd@ukpmr.cs.philips.nl> - speedup, David Hughes 24th November 1996
1043 ;;; 1062 ;;;
1044 (defun fume-match-find-next-function-name (buffer) 1063 (defun fume-match-find-next-function-name (buffer)
1045 "General next function name in BUFFER finder using match. 1064 ;; General next function name in BUFFER finder using match.
1046 The regexp is assumed to be a two item list the car of which is the regexp to 1065 ;; The regexp is assumed to be a two item list the car of which is the regexp
1047 use, and the cdr of which is the match position of the function name." 1066 ;; to use, and the cdr of which is the match position of the function name
1048 (set-buffer buffer) 1067 (set-buffer buffer)
1049 (let ((result nil) 1068 (let ((r (car fume-function-name-regexp))
1050 (continue t) 1069 (p (cdr fume-function-name-regexp)))
1051 (regexp (car fume-function-name-regexp))) 1070 (catch 'found
1052 (while continue 1071 (while (re-search-forward r nil t)
1053 ;; Search for the function 1072 (catch 'skip
1054 (if (re-search-forward regexp nil t) 1073 (if (fume-cc-inside-comment) (throw 'skip t))
1055 (if (fume-cc-inside-comment) 1074 (save-excursion
1056 () ; skip spurious finds in comments 1075 (re-search-backward r nil t)
1057 (let ((first-token (save-excursion 1076 (if (string= "typedef" (fume-what-looking-at)) (throw 'skip t))
1058 (re-search-backward regexp nil t) 1077 (re-search-forward r nil t))
1059 (prog1 (fume-what-looking-at) 1078 (backward-up-list 1)
1060 (re-search-forward regexp nil t)))) 1079 (save-excursion
1061 (last-char (progn 1080 (goto-char (scan-sexps (point) 1))
1062 (backward-up-list 1) 1081 (if (eq ?\; (following-char)) (throw 'skip t))) ; skip prototypes
1063 (save-excursion 1082 (throw
1064 (goto-char (scan-sexps (point) 1)) 1083 'found
1065 (following-char))))) 1084 (cons (buffer-substring (setq p (match-beginning p)) (point)) p))))
1066 ;; Skip function name if it's a prototype or typedef declaration 1085 nil)))
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))
1078 1086
1079 ;;; Specialised routine to find the next Perl function 1087 ;;; Specialised routine to find the next Perl function
1080 ;;; 1088 ;;;
1081 (defun fume-find-next-perl-function-name (buffer) 1089 (defun fume-find-next-perl-function-name (buffer)
1082 "Searches for the next Perl function in BUFFER." 1090 "Searches for the next Perl function in BUFFER."
1083 (fume-find-next-sexp buffer)) 1091 (fume-find-next-sexp buffer))
1084 1092
1085 ;;; Specialised routine to find the next Java function 1093 ;;; Specialised routine to find the next Java function
1094 ;;; Bob Weiner <weiner@infodock.com>
1086 ;;; Heddy Boubaker <boubaker@dgac.fr> 1095 ;;; Heddy Boubaker <boubaker@dgac.fr>
1087 ;;; 1096 ;;;
1088 (defun fume-find-next-java-function-name (buffer) 1097 (defun fume-find-next-java-function-name (buffer)
1089 "Searches for the next Java function in BUFFER." 1098 "Searches for the next Java function in BUFFER."
1090 (set-buffer buffer) 1099 (set-buffer buffer)
1093 (end (match-end 1))) 1102 (end (match-end 1)))
1094 (goto-char (match-beginning 2)) 1103 (goto-char (match-beginning 2))
1095 (forward-sexp) 1104 (forward-sexp)
1096 (if (and (looking-at "[^;(]*{") 1105 (if (and (looking-at "[^;(]*{")
1097 (not (fume-cc-inside-comment))) 1106 (not (fume-cc-inside-comment)))
1098 ;; This is a method definition and we're not 1107 ;; This is a method definition and we're not in a comment
1099 ;; in a comment.
1100 (let ((str (buffer-substring beg end))) 1108 (let ((str (buffer-substring beg end)))
1101 (or (string-match "if\\|switch\\|catch\\|for\\|while" str) 1109 ;; Bob Weiner <weiner@infodock.com> added exact match
1102 ;; These constructs look like methods definitions 1110 ;; delimiters so function names that happen to contain
1103 ;; but are not. 1111 ;; any of these terms are not eliminated. The old version
1112 ;; would ignore "notify()" since it contained "if".
1113 (or (string-match "\\`\\(if\\|switch\\|catch\\|for\\|while\\)\\'"
1114 str)
1115 ;; These constructs look like method definitions but are not
1104 (cons str beg))) 1116 (cons str beg)))
1105 (fume-find-next-java-function-name buffer))))) 1117 (fume-find-next-java-function-name buffer)))))
1106 1118
1107 ;;; Specialised routine to find the next Python function 1119 ;;; Specialised routine to find the next Python function
1108 ;;; Shuichi Koga <skoga@virginia.edu> 1120 ;;; Shuichi Koga <skoga@virginia.edu>
1368 (if (re-search-forward fume-function-name-regexp nil t) 1380 (if (re-search-forward fume-function-name-regexp nil t)
1369 (let ((beg (match-beginning 2)) 1381 (let ((beg (match-beginning 2))
1370 (end (match-end 2))) 1382 (end (match-end 2)))
1371 (cons (buffer-substring beg end) beg)))) 1383 (cons (buffer-substring beg end) beg))))
1372 1384
1385 ;;; Specialised routine to get the next idl function in the buffer
1386 ;;;
1387 ;;; Lubos Pochman <lubos@rsinc.com>
1388 (defun fume-find-next-idl-function-name (buffer)
1389 "Searches for the next idl function in BUFFER."
1390 (set-buffer buffer)
1391 (if (re-search-forward (car fume-function-name-regexp-idl) nil t)
1392 (let ((beg (match-beginning (cdr fume-function-name-regexp-idl)))
1393 (end (match-end (cdr fume-function-name-regexp-idl))))
1394 (cons (buffer-substring beg end) beg))))
1395
1396
1373 ;;; Assembly 1397 ;;; Assembly
1374 ;;; Bob Weiner <weiner@mot.com> 1398 ;;; Bob Weiner <weiner@infodock.com>
1375 ;;; 1399 ;;;
1376 (defun fume-find-next-asm-function-name (buffer) 1400 (defun fume-find-next-asm-function-name (buffer)
1377 "Searches for the next assembler function in BUFFER." 1401 "Searches for the next assembler function in BUFFER."
1378 (set-buffer buffer) 1402 (set-buffer buffer)
1379 ;; Search for the function 1403 ;; Search for the function
1415 (python-mode . fume-find-next-python-function-name) 1439 (python-mode . fume-find-next-python-function-name)
1416 (scheme-mode . fume-find-next-scheme-function) 1440 (scheme-mode . fume-find-next-scheme-function)
1417 (sgml-mode . fume-find-next-sgml-element-name) 1441 (sgml-mode . fume-find-next-sgml-element-name)
1418 (tcl-mode . fume-match-find-next-function-name) 1442 (tcl-mode . fume-match-find-next-function-name)
1419 (verilog-mode . fume-find-next-verilog-function-name) 1443 (verilog-mode . fume-find-next-verilog-function-name)
1444 (idl-mode . fume-find-next-idl-function-name)
1420 ) 1445 )
1421 1446
1422 "The connection between a mode and the defun that finds function names. 1447 "The connection between a mode and the defun that finds function names.
1423 If no connection is in this alist for a given mode, a default method is used") 1448 If no connection is in this alist for a given mode, a default method is used")
1424 1449
1425 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 1450 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1426 ;;;;;;;;;;;;;;;;;;;;;;;; General utility functions ;;;;;;;;;;;;;;;;;;;;;;; 1451 ;;;;;;;;;;;;;;;;;;;;;;;; General utility functions ;;;;;;;;;;;;;;;;;;;;;;;
1427 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 1452 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1428 1453
1429 ;;; Routine to refresh the modeline 1454 ;;; modeline refresh routine
1430 ;;; 1455 ;;;
1431 (if (fboundp 'redraw-modeline) ; faster built-in method 1456 (or (fboundp 'redraw-modeline)
1432 (defalias 'fume-refresh-modeline 'redraw-modeline) 1457 (defun redraw-modeline () (set-buffer-modified-p (buffer-modified-p))))
1433 (defun fume-refresh-modeline () ; use old kludge method
1434 (set-buffer-modified-p (buffer-modified-p))))
1435 1458
1436 ;;; Smart mouse positioning 1459 ;;; Smart mouse positioning
1437 ;;; 1460 ;;;
1438 (if (fboundp 'window-edges) ; old method 1461 (if (fboundp 'window-edges) ; old method
1439 (defun fume-set-mouse-position () 1462 (defun fume-set-mouse-position ()
1462 'fume-find-next-function-name))) 1485 'fume-find-next-function-name)))
1463 fume-function-name-regexp) 1486 fume-function-name-regexp)
1464 1487
1465 ;;; Routines to add/remove/update function menu from menubar 1488 ;;; Routines to add/remove/update function menu from menubar
1466 ;;; 1489 ;;;
1467 (defsubst fume-add-menubar-entry () 1490 (defun fume-add-menubar-entry ()
1468 (interactive) 1491 (interactive)
1469 (save-window-excursion (function-menu t))) 1492 (save-window-excursion (function-menu t)))
1470 1493
1471 (defsubst fume-remove-menubar-entry () 1494 (defun fume-remove-menubar-entry ()
1472 (interactive) 1495 (interactive)
1473 (cond ((and fume-running-xemacs current-menubar) 1496 (cond ((and fume-running-xemacs current-menubar)
1474 (delete-menu-item (list fume-menubar-menu-name)) 1497 (delete-menu-item (list fume-menubar-menu-name))
1475 ;; force update of the menubar 1498 ;; force update of the menubar
1476 (fume-refresh-modeline)))) 1499 (redraw-modeline))))
1477 1500
1478 (defsubst fume-update-menubar-entry () 1501 (defun fume-update-menubar-entry ()
1479 "Returns t if menubar was updated. Nil otherwise" 1502 "Returns t if menubar was updated. Nil otherwise"
1480 (and fume-running-xemacs 1503 (and fume-running-xemacs
1481 fume-not-tty 1504 fume-not-tty
1482 (assoc fume-menubar-menu-name current-menubar) 1505 (assoc fume-menubar-menu-name current-menubar)
1483 (fume-add-menubar-entry) 1506 (fume-add-menubar-entry)
1484 t)) 1507 t))
1485 1508
1486 (defsubst fume-trim-string (string) 1509 (defun fume-trim-string (string)
1487 "Returns STRING with leading and trailing whitespace removed." 1510 "Returns STRING with leading and trailing whitespace removed."
1488 (if (string-match "^[ \t]*" (setq string (format "%s" string))) 1511 (if (string-match "^[ \t]*" (setq string (format "%s" string)))
1489 (setq string (substring string (match-end 0)))) 1512 (setq string (substring string (match-end 0))))
1490 (if (string-match "[ \t]*$" string) 1513 (if (string-match "[ \t]*$" string)
1491 (setq string (substring string 0 (match-beginning 0)))) 1514 (setq string (substring string 0 (match-beginning 0))))
1492 string) 1515 string)
1493 1516
1494 (defvar fume-syntax-table nil) 1517 (defvar fume-syntax-table nil)
1495 1518
1496 (defsubst fume-what-looking-at () 1519 (defun fume-what-looking-at (&optional check-primary-selection-p)
1497 (let (name 1520 (or (and check-primary-selection-p
1498 (orig-syntax-table (copy-syntax-table (syntax-table)))) 1521 primary-selection-extent
1499 (if fume-syntax-table 1522 (condition-case ()
1500 () 1523 (prog1 (buffer-substring (region-beginning) (region-end))
1501 (setq fume-syntax-table (copy-syntax-table)) 1524 (and zmacs-regions (zmacs-deactivate-region) (sit-for 0)))
1502 (modify-syntax-entry ?: "w" fume-syntax-table)) 1525 (error nil)))
1503 (unwind-protect 1526 (let (name
1504 (progn 1527 (orig-syntax-table (copy-syntax-table (syntax-table))))
1505 (set-syntax-table fume-syntax-table) 1528 (if fume-syntax-table
1506 (save-excursion 1529 ()
1507 (while (looking-at "\\sw\\|\\s_") (forward-char 1)) 1530 (setq fume-syntax-table (copy-syntax-table))
1508 (if (re-search-backward "\\sw\\|\\s_" nil t) 1531 (modify-syntax-entry ?: "w" fume-syntax-table))
1509 (let ((beg (progn (forward-char 1) (point)))) 1532 (unwind-protect
1510 (forward-sexp -1) 1533 (progn
1511 (while (looking-at "\\s'") (forward-char 1)) 1534 (set-syntax-table fume-syntax-table)
1512 (setq name (buffer-substring beg (point))))))) 1535 (save-excursion
1513 (set-syntax-table orig-syntax-table) 1536 (while (looking-at "\\sw\\|\\s_") (forward-char 1))
1514 name))) 1537 (if (re-search-backward "\\sw\\|\\s_" nil t)
1515 1538 (let ((beg (progn (forward-char 1) (point))))
1516 ;;; Find function name that point is in. 1539 (forward-sexp -1)
1517 ;;; The trick is to start from the end... 1540 (while (looking-at "\\s'") (forward-char 1))
1518 ;;; 1541 (setq name (buffer-substring beg (point)))))))
1519 (defsubst fume-function-before-point () 1542 (set-syntax-table orig-syntax-table)
1543 name))))
1544
1545 ;;; Find function name that point is in
1546 ;;; (trick is to start from the end)
1547 ;;;
1548 (defun fume-function-before-point ()
1520 (if (or fume-modeline-funclist (fume-rescan-buffer) fume-modeline-funclist) 1549 (if (or fume-modeline-funclist (fume-rescan-buffer) fume-modeline-funclist)
1521 (let (result 1550 (let ((p (point)))
1522 (pt (point)))
1523 (save-excursion 1551 (save-excursion
1524 (catch 'found 1552 (catch 'found
1525 (mapcar (function 1553 (mapcar (function
1526 (lambda (p) 1554 (lambda (x)
1527 (goto-char (cdr p)) 1555 (goto-char (cdr x))
1528 (beginning-of-line 1) 1556 (beginning-of-line 1)
1529 (if (>= pt (point)) 1557 (if (>= p (point)) (throw 'found (car x)))))
1530 (throw 'found (setq result (car p)))))) 1558 fume-modeline-funclist) nil)))))
1531 fume-modeline-funclist))
1532 result))))
1533 1559
1534 ;;; Routines to add a buffer local post command hook 1560 ;;; Routines to add a buffer local post command hook
1535 ;;; 1561 ;;;
1536 (defsubst fume-post-command-hook-p (hook) 1562 (defun fume-post-command-hook-p (hook)
1537 (memq hook (if fume-use-local-post-command-hook 1563 (memq hook (if fume-use-local-post-command-hook
1538 local-post-command-hook 1564 local-post-command-hook
1539 post-command-hook))) 1565 post-command-hook)))
1540 1566
1541 (defsubst fume-add-post-command-hook (hook &optional append) 1567 (defun fume-add-post-command-hook (hook &optional append)
1542 (or (fume-post-command-hook-p hook) 1568 (or (fume-post-command-hook-p hook)
1543 (cond (fume-use-local-post-command-hook 1569 (cond (fume-use-local-post-command-hook
1544 (add-hook 'local-post-command-hook hook append)) 1570 (add-hook 'local-post-command-hook hook append))
1545 ((fboundp 'make-local-hook) 1571 ((fboundp 'make-local-hook)
1546 (make-local-hook 'post-command-hook) 1572 (make-local-hook 'post-command-hook)
1548 (t 1574 (t
1549 ;; NOT make-variable-buffer-local 1575 ;; NOT make-variable-buffer-local
1550 (make-local-variable 'post-command-hook) 1576 (make-local-variable 'post-command-hook)
1551 (add-hook 'post-command-hook hook append))))) 1577 (add-hook 'post-command-hook hook append)))))
1552 1578
1553 (defsubst fume-remove-post-command-hook (hook) 1579 (defun fume-remove-post-command-hook (hook)
1554 (and (fume-post-command-hook-p hook) 1580 (and (fume-post-command-hook-p hook)
1555 (cond (fume-use-local-post-command-hook 1581 (cond (fume-use-local-post-command-hook
1556 (remove-hook 'local-post-command-hook hook)) 1582 (remove-hook 'local-post-command-hook hook))
1557 ((fboundp 'make-local-hook) 1583 ((fboundp 'make-local-hook)
1558 (remove-hook 'post-command-hook hook t)) 1584 (remove-hook 'post-command-hook hook t))
1559 (t 1585 (t
1560 (remove-hook 'post-command-hook hook))))) 1586 (remove-hook 'post-command-hook hook)))))
1561 1587
1562 ;;; Routine to install the modeline feature 1588 ;;; Routine to install the modeline feature
1563 ;;; 1589 ;;;
1564 (defsubst fume-maybe-install-modeline-feature () 1590 (defun fume-maybe-install-modeline-feature ()
1565 (cond ((and fume-display-in-modeline-p (fume-set-defaults)) 1591 (cond ((and fume-display-in-modeline-p (fume-set-defaults))
1566 (or fume-modeline-funclist 1592 (or fume-modeline-funclist
1567 (fume-post-command-hook-p 'fume-tickle-modeline) 1593 (fume-post-command-hook-p 'fume-tickle-modeline)
1568 (fume-rescan-buffer)) 1594 (fume-rescan-buffer))
1569 (fume-add-post-command-hook 'fume-tickle-modeline) 1595 (fume-add-post-command-hook 'fume-tickle-modeline)
1592 (t 1618 (t
1593 fume-modeline-buffer-identification-0)))) 1619 fume-modeline-buffer-identification-0))))
1594 (cond ((not fume-display-in-modeline-p) 1620 (cond ((not fume-display-in-modeline-p)
1595 (fume-remove-post-command-hook 'fume-tickle-modeline) 1621 (fume-remove-post-command-hook 'fume-tickle-modeline)
1596 (fume-add-post-command-hook 'fume-maybe-install-modeline-feature))) 1622 (fume-add-post-command-hook 'fume-maybe-install-modeline-feature)))
1597 ;; force an update of the mode line 1623 ;; force update of the modeline
1598 (fume-refresh-modeline)) 1624 (redraw-modeline))
1599 1625
1600 (fume-defvar-local fume-modeline-buffer-identification-0 nil 1626 (fume-defvar-local fume-modeline-buffer-identification-0 nil
1601 "Storage for original modeline-buffer-identification") 1627 "Storage for original modeline-buffer-identification")
1602 1628
1603 (fume-defvar-local fume-modeline-buffer-identification-1 nil 1629 (fume-defvar-local fume-modeline-buffer-identification-1 nil
1643 (mapcar (function (lambda (i) (cons (car i) (cdr i)))) list))) 1669 (mapcar (function (lambda (i) (cons (car i) (cdr i)))) list)))
1644 1670
1645 ;;; Sort function to sort items depending on their function-name 1671 ;;; Sort function to sort items depending on their function-name
1646 ;;; An item looks like (NAME . POSITION). 1672 ;;; An item looks like (NAME . POSITION).
1647 ;;; 1673 ;;;
1648 (defsubst fume-sort-by-name (item1 item2) 1674 (defun fume-sort-by-name (item1 item2)
1649 (or (string-lessp (car item1) (car item2)) 1675 (or (string-lessp (car item1) (car item2))
1650 (string-equal (car item1) (car item2)))) 1676 (string-equal (car item1) (car item2))))
1651 1677
1652 ;;; Sort function to sort items depending on their position 1678 ;;; Sort function to sort items depending on their position
1653 ;;; 1679 ;;;
1654 (defsubst fume-sort-by-position (item1 item2) 1680 (defun fume-sort-by-position (item1 item2)
1655 (<= (cdr item1) (cdr item2))) 1681 (<= (cdr item1) (cdr item2)))
1656 1682
1657 ;;; Support function to calculate relative position in buffer 1683 ;;; Support function to calculate relative position in buffer
1658 ;;; 1684 ;;;
1659 (defsubst fume-relative-position () 1685 (defun fume-relative-position ()
1660 (let ((pos (point)) 1686 (let ((pos (point))
1661 (total (buffer-size))) 1687 (total (buffer-size)))
1662 (if (> total 50000) 1688 (if (> total 50000)
1663 ;; Avoid overflow from multiplying by 100! 1689 ;; Avoid overflow from multiplying by 100!
1664 (/ (1- pos) (max (/ total 100) 1)) 1690 (/ (1- pos) (max (/ total 100) 1))
1666 (max total 1))))) 1692 (max total 1)))))
1667 1693
1668 ;;; Split LIST into sublists of max length N 1694 ;;; Split LIST into sublists of max length N
1669 ;;; Example (fume-split '(1 2 3 4 5 6 7 8) 3)-> '((1 2 3) (4 5 6) (7 8)) 1695 ;;; Example (fume-split '(1 2 3 4 5 6 7 8) 3)-> '((1 2 3) (4 5 6) (7 8))
1670 ;;; 1696 ;;;
1671 (defsubst fume-split (list n) 1697 (defun fume-split (list n)
1672 (let ((i 0) 1698 (let ((i 0)
1673 result 1699 result
1674 sublist 1700 sublist
1675 (remain list)) 1701 (remain list))
1676 (while remain 1702 (while remain
1780 (car (funcall find (current-buffer))))))) 1806 (car (funcall find (current-buffer)))))))
1781 (error nil))))) 1807 (error nil)))))
1782 (let ((fume-scanning-message nil)) 1808 (let ((fume-scanning-message nil))
1783 (fume-rescan-buffer)))))) 1809 (fume-rescan-buffer))))))
1784 1810
1785 (defsubst fume-install-rescan-buffer-trigger () 1811 (defun fume-install-rescan-buffer-trigger ()
1786 (cond ((not (fume-post-command-hook-p 'fume-rescan-buffer-trigger)) 1812 (cond ((not (fume-post-command-hook-p 'fume-rescan-buffer-trigger))
1787 (fume-add-post-command-hook 'fume-rescan-buffer-trigger 'append) 1813 (fume-add-post-command-hook 'fume-rescan-buffer-trigger 'append)
1788 ;; Make narrow-to-region tickle func-menu 1814 ;; Make narrow-to-region tickle func-menu
1789 (or (fboundp 'fume-narrow-to-region) 1815 (or (fboundp 'fume-narrow-to-region)
1790 (fset 'fume-narrow-to-region 1816 (fset 'fume-narrow-to-region
1862 (let ((fume-rescan-inhibit-p t)) 1888 (let ((fume-rescan-inhibit-p t))
1863 (fume-update-menubar-entry))) 1889 (fume-update-menubar-entry)))
1864 ;; Reset dirty flag 1890 ;; Reset dirty flag
1865 (setq fume-funclist-dirty-p nil)) 1891 (setq fume-funclist-dirty-p nil))
1866 1892
1893 (defun fume-scan-buffer ()
1894 (or fume-funclist (progn (fume-set-defaults) (fume-rescan-buffer))))
1895
1867 ;;; Routine to position cursor 1896 ;;; Routine to position cursor
1868 ;;; 1897 ;;;
1869 (defun fume-goto-function (fn pos) 1898 (defun fume-goto-function (fn pos)
1870 "Position cursor at function FN at location POS" 1899 "Position cursor at function FN at location POS"
1871 (let ((orig-pos (point)) 1900 (let ((orig-pos (point))
1919 (call-interactively 'function-menu))) 1948 (call-interactively 'function-menu)))
1920 (error (select-window currwin))))) 1949 (error (select-window currwin)))))
1921 1950
1922 ;;; Interface for Key bindings 1951 ;;; Interface for Key bindings
1923 ;;; 1952 ;;;
1924 (defun function-menu (&optional use-menubar) 1953 (defun function-menu (&optional use-menubar return-only)
1925 "Pop up a menu of functions for selection with the mouse. 1954 "Pop up a menu of functions for selection with the mouse.
1955 Jumps to the selected function. A mark is set at the old position,
1956 so you can easily go back with C-u \\[set-mark-command].
1926 1957
1927 With a prefix arg adds the menu to the current menubar. 1958 With a prefix arg adds the menu to the current menubar.
1928 Jumps to the selected function. A mark is set at the old position, 1959 Optional second argument, RETURN-ONLY if non-nil simply returns
1929 so you can easily go back with C-u \\[set-mark-command]." 1960 the basic menu of functions."
1930 (interactive "P") 1961 (interactive "P")
1931 1962
1932 (setq use-menubar 1963 (setq use-menubar
1933 (and use-menubar fume-running-xemacs fume-not-tty current-menubar)) 1964 (and use-menubar fume-running-xemacs fume-not-tty current-menubar))
1934 1965
1980 (fume-split fume-funclist fume-max-items)))) 2011 (fume-split fume-funclist fume-max-items))))
1981 2012
1982 (or (> count 1) 2013 (or (> count 1)
1983 (setq function-menu-items (cdr (car function-menu-items)))) 2014 (setq function-menu-items (cdr (car function-menu-items))))
1984 2015
1985 (setq function-menu 2016 (if return-only
1986 (` ((,@ function-menu-items) 2017 nil
1987 "----" 2018 (setq function-menu
1988 ["Display full list of functions" 2019 (` ((,@ function-menu-items)
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)
2005 "----" 2020 "----"
2006 ["Remove Function Menu from menubar" 2021 ["Display full list of functions"
2007 fume-remove-menubar-entry t])) 2022 fume-list-functions t]
2008 fume-menubar-menu-location)) 2023 [(, (concat "Rescan buffer : " (buffer-name)))
2009 2024 (fume-rescan-buffer (, (null use-menubar))) t]
2010 ((and fume-not-tty ; trap tty segmentation faults... 2025 "----"
2011 (not (popup-menu-up-p))) 2026 ["Toggle modeline display"
2012 (or (fume-update-menubar-entry) 2027 fume-toggle-modeline-display t]
2013 (setq function-menu 2028 ["Toggle buffer auto rescanning"
2014 (cons 2029 fume-toggle-auto-rescanning t]
2015 ["Put Function Menu into menubar" 2030 ["About Func-Menu" fume-about t])))
2016 (function-menu t) t] 2031
2017 (cons "----" function-menu)))) 2032 (cond (use-menubar
2018 2033 (fume-remove-menubar-entry)
2019 (if fume-auto-position-popup 2034 (set-buffer-menubar (copy-sequence current-menubar))
2020 (fume-set-mouse-position)) 2035 (fume-add-submenu
2021 2036 fume-menubar-menu-name
2022 (popup-menu (cons "Functions" function-menu))))))))) 2037 (` ((,@ function-menu)
2038 "----"
2039 ["Remove Function Menu from menubar"
2040 fume-remove-menubar-entry t]))
2041 fume-menubar-menu-location))
2042
2043 ((and fume-not-tty ; trap tty segmentation faults...
2044 (not (popup-menu-up-p)))
2045 (or (fume-update-menubar-entry)
2046 (setq function-menu
2047 (cons
2048 ["Put Function Menu into menubar"
2049 (function-menu t) t]
2050 (cons "----" function-menu))))
2051
2052 (if fume-auto-position-popup
2053 (fume-set-mouse-position))
2054
2055 (popup-menu
2056 (cons fume-menubar-menu-name function-menu)))))
2057
2058 ;; Return basic function menu for display by another function
2059 function-menu-items)))))
2023 2060
2024 (defun fume-mouse-function-goto (event) 2061 (defun fume-mouse-function-goto (event)
2025 "Goto function clicked on or prompt in minibuffer (with completion)." 2062 "Goto function clicked on or prompt in minibuffer (with completion)."
2026 (interactive "@e") 2063 (interactive "@e")
2027 (goto-char (event-point event)) 2064 (let ((orig-pos (point)))
2028 (let ((fume-no-prompt-on-valid-default t)) 2065 (goto-char (event-point event))
2029 (fume-prompt-function-goto))) 2066 (let ((fume-no-prompt-on-valid-default t))
2067 (fume-prompt-function-goto))
2068 (or (= orig-pos (point))
2069 (push-mark orig-pos (null fume-scanning-message)))))
2030 2070
2031 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 2071 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2032 ;;;;;;;;;;;;;;;; Keyboard access to func-menu for tty users ;;;;;;;;;;;;;; 2072 ;;;;;;;;;;;;;;;; Keyboard access to func-menu for tty users ;;;;;;;;;;;;;;
2033 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 2073 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2034 2074
2043 ;;; 2083 ;;;
2044 (defun fume-prompt-function-goto (&optional other-window-p) 2084 (defun fume-prompt-function-goto (&optional other-window-p)
2045 "Goto function prompted for in minibuffer (with completion). 2085 "Goto function prompted for in minibuffer (with completion).
2046 With prefix arg, jumps to function in a different window." 2086 With prefix arg, jumps to function in a different window."
2047 (interactive "P") 2087 (interactive "P")
2048 (and (interactive-p) current-prefix-arg (setq other-window-p t)) 2088 (let* ((default-name (fume-what-looking-at t))
2049 (let* ((default-name (fume-what-looking-at))
2050 (OrigBuffer (current-buffer)) 2089 (OrigBuffer (current-buffer))
2051 (TargetBuffer 2090 (flistMode (eq major-mode 'fume-list-mode))
2052 (if (eq major-mode 'fume-list-mode) fume-list-srcbuffer OrigBuffer)) 2091 (no-prompt (or flistMode fume-no-prompt-on-valid-default))
2053 (fume-no-prompt-on-valid-default 2092 (TargetBuffer (if flistMode fume-list-srcbuffer OrigBuffer)))
2054 (or fume-no-prompt-on-valid-default
2055 (eq major-mode 'fume-list-mode))))
2056 (switch-to-buffer TargetBuffer) 2093 (switch-to-buffer TargetBuffer)
2057 ;; Create funclist and set defaults 2094 (fume-scan-buffer) ;; Create funclist and set defaults if required
2058 (cond ((null fume-funclist)
2059 (fume-set-defaults)
2060 (fume-rescan-buffer)))
2061 (let* (;; verify default-name is a valid function name 2095 (let* (;; verify default-name is a valid function name
2062 (default-exists-p (assoc default-name fume-funclist)) 2096 (default-exists-p (assoc default-name fume-funclist))
2063 ;; Prompt for function name in minibuffer, unless there is a valid 2097 ;; Prompt for function name in minibuffer, unless there is a valid
2064 ;; function name at point & fume-no-prompt-on-valid-default set to t 2098 ;; function name at point & fume-no-prompt-on-valid-default set to t
2065 (function-name 2099 (function-name
2066 (if (and default-exists-p 2100 (if (and default-exists-p no-prompt)
2067 fume-no-prompt-on-valid-default)
2068 "" 2101 ""
2069 (completing-read 2102 (let ((this-command last-command)) ; preserve last-command
2070 (format "Goto function%s%s: " 2103 (completing-read
2071 (if other-window-p " other window" "") 2104 (format "Goto function%s%s: "
2072 (if default-exists-p 2105 (if other-window-p " other window" "")
2073 (concat " (" default-name ")") 2106 (if default-exists-p
2074 "")) 2107 (concat " (" default-name ")")
2075 fume-funclist nil t))) 2108 ""))
2109 fume-funclist nil t))))
2076 ;; Use default function name if just RET was pressed 2110 ;; Use default function name if just RET was pressed
2077 (function-name (if (and default-exists-p (string= "" function-name)) 2111 (function-name (if (and default-exists-p (string= "" function-name))
2078 default-name 2112 default-name
2079 function-name))) 2113 function-name)))
2080 (switch-to-buffer OrigBuffer) 2114 (switch-to-buffer OrigBuffer)
2081 ;; Goto function or just return if function name is empty string 2115 ;; Goto function or just return if function name is empty string
2082 (cond ((not (string= "" function-name)) 2116 (cond ((not (string= "" function-name))
2083 (if other-window-p 2117 (if other-window-p
2084 (cond ((prog1 (one-window-p) 2118 (cond ((prog1 (one-window-p)
2085 (switch-to-buffer-other-window TargetBuffer)) 2119 (if (not (windowp other-window-p))
2120 (switch-to-buffer-other-window TargetBuffer)
2121 (select-window other-window-p)
2122 (switch-to-buffer TargetBuffer)))
2086 (other-window 1) 2123 (other-window 1)
2087 (shrink-window-if-larger-than-buffer) 2124 (shrink-window-if-larger-than-buffer)
2088 (other-window 1))) 2125 (other-window 1)))
2089 (switch-to-buffer TargetBuffer)) 2126 (switch-to-buffer TargetBuffer))
2090 (fume-goto-function 2127 (fume-goto-function
2095 (delete-other-windows) 2132 (delete-other-windows)
2096 (fume-prompt-function-goto)) 2133 (fume-prompt-function-goto))
2097 2134
2098 (defun fume-prompt-function-goto-other-window () 2135 (defun fume-prompt-function-goto-other-window ()
2099 (interactive) 2136 (interactive)
2100 (let ((current-prefix-arg 1)) 2137 (fume-prompt-function-goto t))
2101 (call-interactively 'fume-prompt-function-goto))) 2138
2102 2139 (defun fume-list-functions-show-fn-other-window (&optional window)
2103 (defun fume-list-functions-show-fn-other-window ()
2104 (interactive) 2140 (interactive)
2105 (beginning-of-line) 2141 (beginning-of-line)
2106 (select-window 2142 (select-window
2107 (prog1 (selected-window) 2143 (prog1 (selected-window) (fume-prompt-function-goto (or window t)))))
2108 (fume-prompt-function-goto-other-window)))) 2144
2109 2145 (defun fume-list-functions-show-prev-fn-other-window (&optional window)
2110 (defun fume-list-functions-show-prev-fn-other-window ()
2111 (interactive) 2146 (interactive)
2112 (forward-line -1) 2147 (forward-line -1)
2113 (fume-list-functions-show-fn-other-window)) 2148 (fume-list-functions-show-fn-other-window window))
2114 2149
2115 (defun fume-list-functions-show-next-fn-other-window () 2150 (defun fume-list-functions-show-next-fn-other-window (&optional window)
2116 (interactive) 2151 (interactive)
2117 (forward-line 1) 2152 (forward-line 1)
2118 (beginning-of-line) 2153 (beginning-of-line)
2119 (fume-list-functions-show-fn-other-window)) 2154 (fume-list-functions-show-fn-other-window window))
2120 2155
2121 (defun fume-list-functions-help () 2156 (defun fume-list-functions-help ()
2122 (interactive) 2157 (interactive)
2123 (fume-about) 2158 (fume-about)
2124 (sit-for 1) 2159 (sit-for 1)
2183 (defvar fume-list-mode-hook nil "*Hook to run after fume-list-mode entered") 2218 (defvar fume-list-mode-hook nil "*Hook to run after fume-list-mode entered")
2184 2219
2185 (defun fume-list-functions (&optional this-window) 2220 (defun fume-list-functions (&optional this-window)
2186 "Creates a temporary buffer listing functions found in the current buffer" 2221 "Creates a temporary buffer listing functions found in the current buffer"
2187 (interactive "P") 2222 (interactive "P")
2223 (fume-scan-buffer) ;; Create funclist and set defaults if required
2188 (let ((func-near-point (format "^%s$" (fume-function-before-point)))) 2224 (let ((func-near-point (format "^%s$" (fume-function-before-point))))
2189 (cond ((or fume-function-name-regexp (fume-maybe-install-modeline-feature)) 2225 (cond ((or fume-function-name-regexp (fume-maybe-install-modeline-feature))
2190 (save-excursion 2226 (save-excursion
2191 (let ((srcbuffer (current-buffer))) 2227 (let ((srcbuffer (current-buffer)))
2192 (set-buffer (get-buffer-create fume-buffer-name)) 2228 (set-buffer (get-buffer-create fume-buffer-name))
2227 (fume-list-functions-help)))) 2263 (fume-list-functions-help))))
2228 (t 2264 (t
2229 (error "Func-Menu is not operative in this buffer"))))) 2265 (error "Func-Menu is not operative in this buffer")))))
2230 2266
2231 (provide 'func-menu) 2267 (provide 'func-menu)
2268
2269 ;;; end of file