Mercurial > emacs
annotate lisp/find-file.el @ 83676:27d11c1d4e46
Merge from emacs--devo--0
Patches applied:
* emacs--devo--0 (patch 857-862)
- Update from CVS
- Merge from emacs--rel--22
- Update from CVS: lisp/emacs-lisp/avl-tree.el: New file.
* emacs--rel--22 (patch 97-100)
- Update from CVS
- Merge from gnus--rel--5.10
* gnus--rel--5.10 (patch 246-247)
- Update from CVS
Revision: emacs@sv.gnu.org/emacs--multi-tty--0--patch-38
author | Miles Bader <miles@gnu.org> |
---|---|
date | Mon, 27 Aug 2007 09:21:49 +0000 |
parents | 9355f9b7bbff |
children | 73661ddc7ac7 f55f9811f5d7 |
rev | line source |
---|---|
10491 | 1 ;;; find-file.el --- find a file corresponding to this one given a pattern |
2 | |
18127 | 3 ;; Author: Henry Guillaume <henri@tibco.com, henry@c032.aone.net.au> |
21057 | 4 ;; Maintainer: FSF |
10491 | 5 ;; Keywords: c, matching, tools |
6 | |
74439 | 7 ;; Copyright (C) 1994, 1995, 2001, 2002, 2003, 2004, |
75347 | 8 ;; 2005, 2006, 2007 Free Software Foundation, Inc. |
10491 | 9 |
14169 | 10 ;; This file is part of GNU Emacs. |
10491 | 11 |
14169 | 12 ;; GNU Emacs is free software; you can redistribute it and/or modify |
13 ;; it under the terms of the GNU General Public License as published by | |
78236
9355f9b7bbff
Switch license to GPLv3 or later.
Glenn Morris <rgm@gnu.org>
parents:
75347
diff
changeset
|
14 ;; the Free Software Foundation; either version 3, or (at your option) |
14169 | 15 ;; any later version. |
10491 | 16 |
14169 | 17 ;; GNU Emacs is distributed in the hope that it will be useful, |
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 ;; GNU General Public License for more details. | |
10491 | 21 |
14169 | 22 ;; You should have received a copy of the GNU General Public License |
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
64091 | 24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
25 ;; Boston, MA 02110-1301, USA. | |
10491 | 26 |
27 ;;; Commentary: | |
28 | |
29 ;; PURPOSE: | |
30816 | 30 ;; This package features a function called ff-find-other-file, which performs |
31 ;; the following function: | |
10491 | 32 ;; |
33 ;; When in a .c file, find the first corresponding .h file in a set | |
34 ;; of directories and display it, and vice-versa from the .h file. | |
35 ;; | |
36 ;; Many people maintain their include file in a directory separate to their | |
37 ;; src directory, and very often you may be editing a file and have a need to | |
38 ;; visit the "other file". This package searches through a set of directories | |
39 ;; to find that file. | |
40 ;; | |
41 ;; THE "OTHER FILE", or "corresponding file", generally has the same basename, | |
30816 | 42 ;; and just has a different extension as described by the ff-other-file-alist |
10491 | 43 ;; variable: |
44 ;; | |
45 ;; '(("\\.cc$" (".hh" ".h")) | |
46 ;; ("\\.hh$" (".cc" ".C" ".CC" ".cxx" ".cpp"))) | |
47 ;; | |
48 ;; If the current file has a .cc extension, ff-find-other-file will attempt | |
49 ;; to look for a .hh file, and then a .h file in some directory as described | |
50 ;; below. The mechanism here is to replace the matched part of the original | |
51 ;; filename with each of the corresponding extensions in turn. | |
52 ;; | |
53 ;; Alternatively, there are situations where the filename of the other file | |
54 ;; cannot be determined easily with regexps. For example, a .c file may | |
55 ;; have two corresponding .h files, for its public and private parts, or | |
56 ;; the filename for the .c file contains part of the pathname of the .h | |
57 ;; file, as between src/fooZap.cc and include/FOO/zap.hh. In that case, the | |
58 ;; format above can be changed to include a function to be called when the | |
59 ;; current file matches the regexp: | |
60 ;; | |
57719
018ef6100fc5
(cc-other-file-alist): Bring it in line with cc-mode's auto-mode-alist entries and use \' instead of $.
Daniel Pfeiffer <occitan@esperanto.org>
parents:
52650
diff
changeset
|
61 ;; '(("\\.cc$" cc--function) |
10491 | 62 ;; ("\\.hh$" hh-function)) |
63 ;; | |
30816 | 64 ;; These functions must return a list consisting of the possible names of the |
65 ;; corresponding file, with or without path. There is no real need for more | |
10491 | 66 ;; than one function, and one could imagine the following value for cc-other- |
67 ;; file-alist: | |
68 ;; | |
69 ;; (setq cc-other-file-alist | |
70 ;; '(("\\.cc$" ff-cc-hh-converter) | |
71 ;; ("\\.hh$" ff-cc-hh-converter) | |
72 ;; ("\\.c$" (".h")) | |
73 ;; ("\\.h$" (".c" ".cc" ".C" ".CC" ".cxx" ".cpp")))) | |
49588
37645a051842
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48009
diff
changeset
|
74 ;; |
10491 | 75 ;; ff-cc-hh-converter is included at the end of this file as a reference. |
49588
37645a051842
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48009
diff
changeset
|
76 ;; |
10491 | 77 ;; SEARCHING is carried out in a set of directories specified by the |
78 ;; ff-search-directories variable: | |
79 ;; | |
80 ;; ("." "../../src" "../include/*" "/usr/local/*/src/*" "$PROJECT/src") | |
81 ;; | |
82 ;; This means that the corresponding file will be searched for first in | |
83 ;; the current directory, then in ../../src, then in one of the directories | |
84 ;; under ../include, and so on. The star is _not_ a general wildcard | |
85 ;; character: it just indicates that the subdirectories of this directory | |
86 ;; must each be searched in turn. Environment variables will be expanded in | |
87 ;; the ff-search-directories variable. | |
88 ;; | |
89 ;; If the point is on a #include line, the file to be #included is searched | |
90 ;; for in the same manner. This can be disabled with the ff-ignore-include | |
91 ;; variable, or by calling ff-get-other-file instead of ff-find-other-file. | |
92 ;; | |
93 ;; If the file was not found, ff-find-other-file will prompt you for where | |
94 ;; to create the new "corresponding file" (defaults to the current directory), | |
30816 | 95 ;; unless the variable ff-always-try-to-create is set to nil. |
10491 | 96 ;; |
30816 | 97 ;; GIVEN AN ARGUMENT (with the ^U prefix), ff-find-other-file will get the |
98 ;; other file in another (the other?) window (see find-file-other-window and | |
99 ;; switch-to-buffer-other-window). This can be set on a more permanent basis | |
100 ;; by setting ff-always-in-other-window to t in which case the ^U prefix will | |
10491 | 101 ;; do the opposite of what was described above. |
102 ;; | |
103 ;; THERE ARE FIVE AVAILABLE HOOKS, called in this order if non-nil: | |
104 ;; | |
47354
27533450eb3b
(ff-pre-find-hook, ff-pre-load-hook, ff-post-load-hook)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44880
diff
changeset
|
105 ;; - ff-pre-find-hook - called before the search for the other file starts |
27533450eb3b
(ff-pre-find-hook, ff-pre-load-hook, ff-post-load-hook)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44880
diff
changeset
|
106 ;; - ff-not-found-hook - called when the other file could not be found |
27533450eb3b
(ff-pre-find-hook, ff-pre-load-hook, ff-post-load-hook)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44880
diff
changeset
|
107 ;; - ff-pre-load-hook - called just before the other file is 'loaded' |
27533450eb3b
(ff-pre-find-hook, ff-pre-load-hook, ff-post-load-hook)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44880
diff
changeset
|
108 ;; - ff-file-created-hook - called when the other file is created |
27533450eb3b
(ff-pre-find-hook, ff-pre-load-hook, ff-post-load-hook)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44880
diff
changeset
|
109 ;; - ff-post-load-hook - called just after the other file is 'loaded' |
10491 | 110 ;; |
47354
27533450eb3b
(ff-pre-find-hook, ff-pre-load-hook, ff-post-load-hook)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44880
diff
changeset
|
111 ;; The *load-hook allow you to place point where you want it in the other |
30816 | 112 ;; file. |
10491 | 113 |
114 ;; CREDITS: | |
115 ;; Many thanks go to TUSC Computer Systems Pty Ltd for providing an environ- | |
116 ;; ment that made the development of this package possible. | |
117 ;; | |
118 ;; Many thanks also go to all those who provided valuable feedback throughout | |
119 ;; the development of this package: | |
120 ;; Rolf Ebert in particular, Fritz Knabe, Heddy Boubaker, Sebastian Kremer, | |
30816 | 121 ;; Vasco Lopes Paulo, Mark A. Plaksin, Robert Lang, Trevor West, Kevin |
16510
e619a826afdb
Enabled commentary for Finder.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
122 ;; Pereira, Benedict Lofstedt & Justin Vallon. |
10491 | 123 |
16510
e619a826afdb
Enabled commentary for Finder.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
124 ;;; Code: |
10491 | 125 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
126 ;; User definable variables: | |
127 | |
21087 | 128 (defgroup ff nil |
129 "Find a file corresponding to this one given a pattern." | |
130 :prefix "ff-" | |
30816 | 131 :link '(emacs-commentary-link "find-file") |
21087 | 132 :group 'find-file) |
10491 | 133 |
47354
27533450eb3b
(ff-pre-find-hook, ff-pre-load-hook, ff-post-load-hook)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44880
diff
changeset
|
134 (defcustom ff-pre-find-hook nil |
21087 | 135 "*List of functions to be called before the search for the file starts." |
136 :type 'hook | |
137 :group 'ff) | |
10491 | 138 |
47354
27533450eb3b
(ff-pre-find-hook, ff-pre-load-hook, ff-post-load-hook)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44880
diff
changeset
|
139 (defcustom ff-pre-load-hook nil |
21087 | 140 "*List of functions to be called before the other file is loaded." |
141 :type 'hook | |
142 :group 'ff) | |
10491 | 143 |
47354
27533450eb3b
(ff-pre-find-hook, ff-pre-load-hook, ff-post-load-hook)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44880
diff
changeset
|
144 (defcustom ff-post-load-hook nil |
21087 | 145 "*List of functions to be called after the other file is loaded." |
146 :type 'hook | |
147 :group 'ff) | |
10491 | 148 |
47354
27533450eb3b
(ff-pre-find-hook, ff-pre-load-hook, ff-post-load-hook)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44880
diff
changeset
|
149 (defcustom ff-not-found-hook nil |
21087 | 150 "*List of functions to be called if the other file could not be found." |
151 :type 'hook | |
152 :group 'ff) | |
10491 | 153 |
47354
27533450eb3b
(ff-pre-find-hook, ff-pre-load-hook, ff-post-load-hook)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44880
diff
changeset
|
154 (defcustom ff-file-created-hook nil |
21087 | 155 "*List of functions to be called if the other file needs to be created." |
156 :type 'hook | |
157 :group 'ff) | |
10491 | 158 |
21087 | 159 (defcustom ff-case-fold-search nil |
160 "*Non-nil means ignore cases in matches (see `case-fold-search'). | |
161 If you have extensions in different cases, you will want this to be nil." | |
162 :type 'boolean | |
163 :group 'ff) | |
10491 | 164 |
21087 | 165 (defcustom ff-always-in-other-window nil |
166 "*If non-nil, find the corresponding file in another window by default. | |
167 To override this, give an argument to `ff-find-other-file'." | |
168 :type 'boolean | |
169 :group 'ff) | |
10491 | 170 |
21087 | 171 (defcustom ff-ignore-include nil |
172 "*If non-nil, ignore `#include' lines." | |
173 :type 'boolean | |
174 :group 'ff) | |
10491 | 175 |
21087 | 176 (defcustom ff-always-try-to-create t |
177 "*If non-nil, always attempt to create the other file if it was not found." | |
178 :type 'boolean | |
179 :group 'ff) | |
180 | |
181 (defcustom ff-quiet-mode nil | |
182 "*If non-nil, trace which directories are being searched." | |
183 :type 'boolean | |
184 :group 'ff) | |
10491 | 185 |
52650
ccb0467830b0
(ff-special-constructs): Add autoload cookie.
Andreas Schwab <schwab@suse.de>
parents:
52401
diff
changeset
|
186 ;;;###autoload |
30816 | 187 (defvar ff-special-constructs |
10491 | 188 '( |
189 ;; C/C++ include, for NeXTSTEP too | |
190 ("^\#\\s *\\(include\\|import\\)\\s +[<\"]\\(.*\\)[>\"]" . | |
191 (lambda () | |
71923
6d714c43de54
(ff-special-constructs): Doc fix. Also, for C/C++
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
68651
diff
changeset
|
192 (buffer-substring (match-beginning 2) (match-end 2)))) |
10491 | 193 ) |
71923
6d714c43de54
(ff-special-constructs): Doc fix. Also, for C/C++
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
68651
diff
changeset
|
194 ;; We include `ff-treat-as-special' documentation here so that autoload |
6d714c43de54
(ff-special-constructs): Doc fix. Also, for C/C++
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
68651
diff
changeset
|
195 ;; can make it available to be read prior to loading this file. |
6d714c43de54
(ff-special-constructs): Doc fix. Also, for C/C++
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
68651
diff
changeset
|
196 "*List of special constructs for `ff-treat-as-special' to recognize. |
6d714c43de54
(ff-special-constructs): Doc fix. Also, for C/C++
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
68651
diff
changeset
|
197 Each element, tried in order, has the form (REGEXP . EXTRACT). |
6d714c43de54
(ff-special-constructs): Doc fix. Also, for C/C++
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
68651
diff
changeset
|
198 If REGEXP matches the current line (from the beginning of the line), |
6d714c43de54
(ff-special-constructs): Doc fix. Also, for C/C++
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
68651
diff
changeset
|
199 `ff-treat-as-special' calls function EXTRACT with no args. |
6d714c43de54
(ff-special-constructs): Doc fix. Also, for C/C++
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
68651
diff
changeset
|
200 If EXTRACT returns nil, keep trying. Otherwise, return the |
6d714c43de54
(ff-special-constructs): Doc fix. Also, for C/C++
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
68651
diff
changeset
|
201 filename that EXTRACT returned.") |
10491 | 202 |
47860
621b10466c9a
(ff-related-file-alist): New alias.
Richard M. Stallman <rms@gnu.org>
parents:
47354
diff
changeset
|
203 (defvaralias 'ff-related-file-alist 'ff-other-file-alist) |
21087 | 204 (defcustom ff-other-file-alist 'cc-other-file-alist |
10491 | 205 "*Alist of extensions to find given the current file's extension. |
206 | |
207 This list should contain the most used extensions before the others, | |
208 since the search algorithm searches sequentially through each | |
11272 | 209 directory specified in `ff-search-directories'. If a file is not found, |
210 a new one is created with the first matching extension (`.cc' yields `.hh'). | |
21087 | 211 This alist should be set by the major mode." |
212 :type '(choice (repeat (list regexp (choice (repeat string) function))) | |
213 symbol) | |
214 :group 'ff) | |
10491 | 215 |
21087 | 216 (defcustom ff-search-directories 'cc-search-directories |
10491 | 217 "*List of directories to search for a specific file. |
218 | |
11272 | 219 Set by default to `cc-search-directories', expanded at run-time. |
10491 | 220 |
221 This list is searched through with each extension specified in | |
11272 | 222 `ff-other-file-alist' that matches this file's extension. So the |
63505
185136bab53f
(ff-search-directories, ff-special-constructs, ff-find-other-file): Fix spelling
Juanma Barranquero <lekktu@gmail.com>
parents:
57719
diff
changeset
|
223 longer the list, the longer it'll take to realize that a file |
10491 | 224 may not exist. |
225 | |
30816 | 226 A typical format is |
10491 | 227 |
16510
e619a826afdb
Enabled commentary for Finder.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
228 '(\".\" \"/usr/include\" \"$PROJECT/*/include\") |
10491 | 229 |
11272 | 230 Environment variables can be inserted between slashes (`/'). |
10491 | 231 They will be replaced by their definition. If a variable does |
11272 | 232 not exist, it is replaced (silently) with an empty string. |
10491 | 233 |
11272 | 234 The stars are *not* wildcards: they are searched for together with |
235 the preceding slash. The star represents all the subdirectories except | |
21087 | 236 `..', and each of these subdirectories will be searched in turn." |
237 :type '(choice (repeat directory) symbol) | |
238 :group 'ff) | |
10491 | 239 |
21087 | 240 (defcustom cc-search-directories |
16510
e619a826afdb
Enabled commentary for Finder.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
241 '("." "/usr/include" "/usr/local/include/*") |
21087 | 242 "*See the description of the `ff-search-directories' variable." |
243 :type '(repeat directory) | |
244 :group 'ff) | |
10491 | 245 |
21087 | 246 (defcustom cc-other-file-alist |
57719
018ef6100fc5
(cc-other-file-alist): Bring it in line with cc-mode's auto-mode-alist entries and use \' instead of $.
Daniel Pfeiffer <occitan@esperanto.org>
parents:
52650
diff
changeset
|
247 '(("\\.cc\\'" (".hh" ".h")) |
018ef6100fc5
(cc-other-file-alist): Bring it in line with cc-mode's auto-mode-alist entries and use \' instead of $.
Daniel Pfeiffer <occitan@esperanto.org>
parents:
52650
diff
changeset
|
248 ("\\.hh\\'" (".cc" ".C")) |
10491 | 249 |
57719
018ef6100fc5
(cc-other-file-alist): Bring it in line with cc-mode's auto-mode-alist entries and use \' instead of $.
Daniel Pfeiffer <occitan@esperanto.org>
parents:
52650
diff
changeset
|
250 ("\\.c\\'" (".h")) |
018ef6100fc5
(cc-other-file-alist): Bring it in line with cc-mode's auto-mode-alist entries and use \' instead of $.
Daniel Pfeiffer <occitan@esperanto.org>
parents:
52650
diff
changeset
|
251 ("\\.h\\'" (".c" ".cc" ".C" ".CC" ".cxx" ".cpp")) |
018ef6100fc5
(cc-other-file-alist): Bring it in line with cc-mode's auto-mode-alist entries and use \' instead of $.
Daniel Pfeiffer <occitan@esperanto.org>
parents:
52650
diff
changeset
|
252 |
018ef6100fc5
(cc-other-file-alist): Bring it in line with cc-mode's auto-mode-alist entries and use \' instead of $.
Daniel Pfeiffer <occitan@esperanto.org>
parents:
52650
diff
changeset
|
253 ("\\.C\\'" (".H" ".hh" ".h")) |
018ef6100fc5
(cc-other-file-alist): Bring it in line with cc-mode's auto-mode-alist entries and use \' instead of $.
Daniel Pfeiffer <occitan@esperanto.org>
parents:
52650
diff
changeset
|
254 ("\\.H\\'" (".C" ".CC")) |
10491 | 255 |
57719
018ef6100fc5
(cc-other-file-alist): Bring it in line with cc-mode's auto-mode-alist entries and use \' instead of $.
Daniel Pfeiffer <occitan@esperanto.org>
parents:
52650
diff
changeset
|
256 ("\\.CC\\'" (".HH" ".H" ".hh" ".h")) |
018ef6100fc5
(cc-other-file-alist): Bring it in line with cc-mode's auto-mode-alist entries and use \' instead of $.
Daniel Pfeiffer <occitan@esperanto.org>
parents:
52650
diff
changeset
|
257 ("\\.HH\\'" (".CC")) |
018ef6100fc5
(cc-other-file-alist): Bring it in line with cc-mode's auto-mode-alist entries and use \' instead of $.
Daniel Pfeiffer <occitan@esperanto.org>
parents:
52650
diff
changeset
|
258 |
018ef6100fc5
(cc-other-file-alist): Bring it in line with cc-mode's auto-mode-alist entries and use \' instead of $.
Daniel Pfeiffer <occitan@esperanto.org>
parents:
52650
diff
changeset
|
259 ("\\.c\\+\\+\\'" (".h++" ".hh" ".h")) |
018ef6100fc5
(cc-other-file-alist): Bring it in line with cc-mode's auto-mode-alist entries and use \' instead of $.
Daniel Pfeiffer <occitan@esperanto.org>
parents:
52650
diff
changeset
|
260 ("\\.h\\+\\+\\'" (".c++")) |
10491 | 261 |
57719
018ef6100fc5
(cc-other-file-alist): Bring it in line with cc-mode's auto-mode-alist entries and use \' instead of $.
Daniel Pfeiffer <occitan@esperanto.org>
parents:
52650
diff
changeset
|
262 ("\\.cpp\\'" (".hpp" ".hh" ".h")) |
018ef6100fc5
(cc-other-file-alist): Bring it in line with cc-mode's auto-mode-alist entries and use \' instead of $.
Daniel Pfeiffer <occitan@esperanto.org>
parents:
52650
diff
changeset
|
263 ("\\.hpp\\'" (".cpp")) |
10491 | 264 |
57719
018ef6100fc5
(cc-other-file-alist): Bring it in line with cc-mode's auto-mode-alist entries and use \' instead of $.
Daniel Pfeiffer <occitan@esperanto.org>
parents:
52650
diff
changeset
|
265 ("\\.cxx\\'" (".hxx" ".hh" ".h")) |
018ef6100fc5
(cc-other-file-alist): Bring it in line with cc-mode's auto-mode-alist entries and use \' instead of $.
Daniel Pfeiffer <occitan@esperanto.org>
parents:
52650
diff
changeset
|
266 ("\\.hxx\\'" (".cxx"))) |
10491 | 267 "*Alist of extensions to find given the current file's extension. |
268 | |
269 This list should contain the most used extensions before the others, | |
270 since the search algorithm searches sequentially through each directory | |
11272 | 271 specified in `ff-search-directories'. If a file is not found, a new one |
21087 | 272 is created with the first matching extension (`.cc' yields `.hh')." |
273 :type '(repeat (list regexp (choice (repeat string) function))) | |
274 :group 'ff) | |
10491 | 275 |
21087 | 276 (defcustom modula2-other-file-alist |
10491 | 277 '( |
278 ("\\.mi$" (".md")) ;; Modula-2 module definition | |
279 ("\\.md$" (".mi")) ;; and implementation. | |
280 ) | |
21087 | 281 "*See the description for the `ff-search-directories' variable." |
282 :type '(repeat (list regexp (choice (repeat string) function))) | |
283 :group 'ff) | |
284 | |
10491 | 285 |
286 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
287 ;; No user definable variables beyond this point! | |
288 ;; ============================================== | |
289 | |
47354
27533450eb3b
(ff-pre-find-hook, ff-pre-load-hook, ff-post-load-hook)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44880
diff
changeset
|
290 (make-variable-buffer-local 'ff-pre-find-hook) |
27533450eb3b
(ff-pre-find-hook, ff-pre-load-hook, ff-post-load-hook)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44880
diff
changeset
|
291 (make-variable-buffer-local 'ff-pre-load-hook) |
27533450eb3b
(ff-pre-find-hook, ff-pre-load-hook, ff-post-load-hook)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44880
diff
changeset
|
292 (make-variable-buffer-local 'ff-post-load-hook) |
27533450eb3b
(ff-pre-find-hook, ff-pre-load-hook, ff-post-load-hook)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44880
diff
changeset
|
293 (make-variable-buffer-local 'ff-not-found-hook) |
27533450eb3b
(ff-pre-find-hook, ff-pre-load-hook, ff-post-load-hook)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44880
diff
changeset
|
294 (make-variable-buffer-local 'ff-file-created-hook) |
10491 | 295 (make-variable-buffer-local 'ff-case-fold-search) |
296 (make-variable-buffer-local 'ff-always-in-other-window) | |
297 (make-variable-buffer-local 'ff-ignore-include) | |
298 (make-variable-buffer-local 'ff-quiet-mode) | |
299 (make-variable-buffer-local 'ff-other-file-alist) | |
300 (make-variable-buffer-local 'ff-search-directories) | |
301 | |
302 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
303 ;; User entry points | |
304 | |
305 ;;;###autoload | |
306 (defun ff-get-other-file (&optional in-other-window) | |
11272 | 307 "Find the header or source file corresponding to this file. |
30816 | 308 See also the documentation for `ff-find-other-file'. |
10491 | 309 |
11272 | 310 If optional IN-OTHER-WINDOW is non-nil, find the file in another window." |
10491 | 311 (interactive "P") |
312 (let ((ignore ff-ignore-include)) | |
313 (setq ff-ignore-include t) | |
314 (ff-find-the-other-file in-other-window) | |
315 (setq ff-ignore-include ignore))) | |
316 | |
48009
8b3977d58df6
(ff-find-related-file): Fix autoload cookie.
Richard M. Stallman <rms@gnu.org>
parents:
47860
diff
changeset
|
317 ;;;###autoload |
47860
621b10466c9a
(ff-related-file-alist): New alias.
Richard M. Stallman <rms@gnu.org>
parents:
47354
diff
changeset
|
318 (defalias 'ff-find-related-file 'ff-find-other-file) |
621b10466c9a
(ff-related-file-alist): New alias.
Richard M. Stallman <rms@gnu.org>
parents:
47354
diff
changeset
|
319 |
10491 | 320 ;;;###autoload |
321 (defun ff-find-other-file (&optional in-other-window ignore-include) | |
11272 | 322 "Find the header or source file corresponding to this file. |
323 Being on a `#include' line pulls in that file. | |
10491 | 324 |
11272 | 325 If optional IN-OTHER-WINDOW is non-nil, find the file in the other window. |
326 If optional IGNORE-INCLUDE is non-nil, ignore being on `#include' lines. | |
10491 | 327 |
328 Variables of interest include: | |
329 | |
30816 | 330 - `ff-case-fold-search' |
331 Non-nil means ignore cases in matches (see `case-fold-search'). | |
10491 | 332 If you have extensions in different cases, you will want this to be nil. |
333 | |
30816 | 334 - `ff-always-in-other-window' |
10491 | 335 If non-nil, always open the other file in another window, unless an |
30816 | 336 argument is given to `ff-find-other-file'. |
10491 | 337 |
30816 | 338 - `ff-ignore-include' |
10491 | 339 If non-nil, ignores #include lines. |
340 | |
30816 | 341 - `ff-always-try-to-create' |
10491 | 342 If non-nil, always attempt to create the other file if it was not found. |
343 | |
30816 | 344 - `ff-quiet-mode' |
10491 | 345 If non-nil, traces which directories are being searched. |
346 | |
30816 | 347 - `ff-special-constructs' |
63505
185136bab53f
(ff-search-directories, ff-special-constructs, ff-find-other-file): Fix spelling
Juanma Barranquero <lekktu@gmail.com>
parents:
57719
diff
changeset
|
348 A list of regular expressions specifying how to recognize special |
30816 | 349 constructs such as include files etc, and an associated method for |
10491 | 350 extracting the filename from that construct. |
351 | |
30816 | 352 - `ff-other-file-alist' |
10491 | 353 Alist of extensions to find given the current file's extension. |
354 | |
30816 | 355 - `ff-search-directories' |
10491 | 356 List of directories searched through with each extension specified in |
30816 | 357 `ff-other-file-alist' that matches this file's extension. |
10491 | 358 |
47354
27533450eb3b
(ff-pre-find-hook, ff-pre-load-hook, ff-post-load-hook)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44880
diff
changeset
|
359 - `ff-pre-find-hook' |
10491 | 360 List of functions to be called before the search for the file starts. |
361 | |
47354
27533450eb3b
(ff-pre-find-hook, ff-pre-load-hook, ff-post-load-hook)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44880
diff
changeset
|
362 - `ff-pre-load-hook' |
10491 | 363 List of functions to be called before the other file is loaded. |
364 | |
47354
27533450eb3b
(ff-pre-find-hook, ff-pre-load-hook, ff-post-load-hook)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44880
diff
changeset
|
365 - `ff-post-load-hook' |
10491 | 366 List of functions to be called after the other file is loaded. |
367 | |
47354
27533450eb3b
(ff-pre-find-hook, ff-pre-load-hook, ff-post-load-hook)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44880
diff
changeset
|
368 - `ff-not-found-hook' |
10491 | 369 List of functions to be called if the other file could not be found. |
370 | |
47354
27533450eb3b
(ff-pre-find-hook, ff-pre-load-hook, ff-post-load-hook)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44880
diff
changeset
|
371 - `ff-file-created-hook' |
10491 | 372 List of functions to be called if the other file has been created." |
373 (interactive "P") | |
374 (let ((ignore ff-ignore-include)) | |
375 (setq ff-ignore-include ignore-include) | |
376 (ff-find-the-other-file in-other-window) | |
377 (setq ff-ignore-include ignore))) | |
378 | |
379 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
380 ;; Support functions | |
381 | |
382 (defun ff-find-the-other-file (&optional in-other-window) | |
11272 | 383 "Find the header or source file corresponding to the current file. |
384 Being on a `#include' line pulls in that file, but see the help on | |
385 the `ff-ignore-include' variable. | |
10491 | 386 |
11272 | 387 If optional IN-OTHER-WINDOW is non-nil, find the file in another window." |
10491 | 388 |
389 (let (match ;; matching regexp for this file | |
390 suffixes ;; set of replacing regexps for the matching regexp | |
391 action ;; function to generate the names of the other files | |
392 fname ;; basename of this file | |
393 pos ;; where we start matching filenames | |
394 stub ;; name of the file without extension | |
395 alist ;; working copy of the list of file extensions | |
396 pathname ;; the pathname of the file or the #include line | |
397 default-name ;; file we should create if none found | |
30816 | 398 format ;; what we have to match |
399 found ;; name of the file or buffer found - nil if none | |
10491 | 400 dirs ;; local value of ff-search-directories |
401 no-match) ;; whether we know about this kind of file | |
402 | |
47354
27533450eb3b
(ff-pre-find-hook, ff-pre-load-hook, ff-post-load-hook)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44880
diff
changeset
|
403 (run-hooks 'ff-pre-find-hook 'ff-pre-find-hooks) |
10491 | 404 |
405 (message "Working...") | |
406 | |
407 (setq dirs | |
408 (if (symbolp ff-search-directories) | |
409 (ff-list-replace-env-vars (symbol-value ff-search-directories)) | |
410 (ff-list-replace-env-vars ff-search-directories))) | |
411 | |
71923
6d714c43de54
(ff-special-constructs): Doc fix. Also, for C/C++
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
68651
diff
changeset
|
412 (setq fname (ff-treat-as-special)) |
10491 | 413 |
414 (cond | |
415 ((and (not ff-ignore-include) fname) | |
416 (setq default-name fname) | |
417 (setq found (ff-get-file dirs fname nil in-other-window))) | |
418 | |
419 ;; let's just get the corresponding file | |
420 (t | |
421 (setq alist (if (symbolp ff-other-file-alist) | |
422 (symbol-value ff-other-file-alist) | |
423 ff-other-file-alist) | |
424 pathname (if (buffer-file-name) | |
425 (buffer-file-name) | |
426 "/none.none")) | |
427 | |
38273
910cd30b1586
(ff-find-the-other-file): Use file-name-nondirectory
Eli Zaretskii <eliz@gnu.org>
parents:
30816
diff
changeset
|
428 (setq fname (file-name-nondirectory pathname) |
10491 | 429 no-match nil |
430 match (car alist)) | |
431 | |
432 ;; find the table entry corresponding to this file | |
433 (setq pos (ff-string-match (car match) fname)) | |
434 (while (and match (if (and pos (>= pos 0)) nil (not pos))) | |
435 (setq alist (cdr alist)) | |
436 (setq match (car alist)) | |
437 (setq pos (ff-string-match (car match) fname))) | |
438 | |
439 ;; no point going on if we haven't found anything | |
440 (if (not match) | |
441 (setq no-match t) | |
442 | |
443 ;; otherwise, suffixes contains what we need | |
444 (setq suffixes (car (cdr match)) | |
445 action (car (cdr match)) | |
446 found nil) | |
447 | |
30816 | 448 ;; if we have a function to generate new names, |
10491 | 449 ;; invoke it with the name of the current file |
450 (if (and (atom action) (fboundp action)) | |
451 (progn | |
452 (setq suffixes (funcall action (buffer-file-name)) | |
453 match (cons (car match) (list suffixes)) | |
454 stub nil | |
455 default-name (car suffixes))) | |
456 | |
457 ;; otherwise build our filename stub | |
30816 | 458 (cond |
10491 | 459 |
460 ;; get around the problem that 0 and nil both mean false! | |
461 ((= pos 0) | |
462 (setq format "") | |
463 (setq stub "") | |
464 ) | |
465 | |
466 (t | |
467 (setq format (concat "\\(.+\\)" (car match))) | |
468 (string-match format fname) | |
469 (setq stub (substring fname (match-beginning 1) (match-end 1))) | |
470 )) | |
471 | |
472 ;; if we find nothing, we should try to get a file like this one | |
473 (setq default-name | |
474 (concat stub (car (car (cdr match)))))) | |
475 | |
476 ;; do the real work - find the file | |
30816 | 477 (setq found |
10491 | 478 (ff-get-file dirs |
479 stub | |
30816 | 480 suffixes |
10491 | 481 in-other-window))))) |
482 | |
483 (cond | |
484 (no-match ;; could not even determine the other file | |
485 (message "")) | |
486 | |
30816 | 487 (t |
10491 | 488 (cond |
489 | |
490 ((not found) ;; could not find the other file | |
491 | |
47354
27533450eb3b
(ff-pre-find-hook, ff-pre-load-hook, ff-post-load-hook)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44880
diff
changeset
|
492 (run-hooks 'ff-not-found-hook 'ff-not-found-hooks) |
10491 | 493 |
30816 | 494 (cond |
10491 | 495 (ff-always-try-to-create ;; try to create the file |
496 (let (name pathname) | |
497 | |
498 (setq name | |
499 (expand-file-name | |
500 (read-file-name | |
501 (format "Find or create %s in: " default-name) | |
502 default-directory default-name nil))) | |
49588
37645a051842
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48009
diff
changeset
|
503 |
10491 | 504 (setq pathname |
505 (if (file-directory-p name) | |
506 (concat (file-name-as-directory name) default-name) | |
507 (setq found name))) | |
49588
37645a051842
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48009
diff
changeset
|
508 |
10491 | 509 (ff-find-file pathname in-other-window t))) |
510 | |
511 (t ;; don't create the file, just whinge | |
17548 | 512 (message "No file found for %s" fname)))) |
10491 | 513 |
514 (t ;; matching file found | |
515 nil)))) | |
516 | |
517 found)) ;; return buffer-name or filename | |
518 | |
42097
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
519 (defun ff-other-file-name () |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
520 "Return name of the header or source file corresponding to the current file. |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
521 Being on a `#include' line pulls in that file, but see the help on |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
522 the `ff-ignore-include' variable." |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
523 |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
524 (let (match ;; matching regexp for this file |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
525 suffixes ;; set of replacing regexps for the matching regexp |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
526 action ;; function to generate the names of the other files |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
527 fname ;; basename of this file |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
528 pos ;; where we start matching filenames |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
529 stub ;; name of the file without extension |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
530 alist ;; working copy of the list of file extensions |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
531 pathname ;; the pathname of the file or the #include line |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
532 default-name ;; file we should create if none found |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
533 format ;; what we have to match |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
534 found ;; name of the file or buffer found - nil if none |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
535 dirs ;; local value of ff-search-directories |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
536 no-match) ;; whether we know about this kind of file |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
537 |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
538 (message "Working...") |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
539 |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
540 (setq dirs |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
541 (if (symbolp ff-search-directories) |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
542 (ff-list-replace-env-vars (symbol-value ff-search-directories)) |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
543 (ff-list-replace-env-vars ff-search-directories))) |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
544 |
71923
6d714c43de54
(ff-special-constructs): Doc fix. Also, for C/C++
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
68651
diff
changeset
|
545 (setq fname (ff-treat-as-special)) |
42097
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
546 |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
547 (cond |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
548 ((and (not ff-ignore-include) fname) |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
549 (setq default-name fname) |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
550 (setq found (ff-get-file-name dirs fname nil))) |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
551 |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
552 ;; let's just get the corresponding file |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
553 (t |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
554 (setq alist (if (symbolp ff-other-file-alist) |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
555 (symbol-value ff-other-file-alist) |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
556 ff-other-file-alist) |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
557 pathname (if (buffer-file-name) |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
558 (buffer-file-name) |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
559 "/none.none")) |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
560 |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
561 (setq fname (file-name-nondirectory pathname) |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
562 no-match nil |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
563 match (car alist)) |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
564 |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
565 ;; find the table entry corresponding to this file |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
566 (setq pos (ff-string-match (car match) fname)) |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
567 (while (and match (if (and pos (>= pos 0)) nil (not pos))) |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
568 (setq alist (cdr alist)) |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
569 (setq match (car alist)) |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
570 (setq pos (ff-string-match (car match) fname))) |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
571 |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
572 ;; no point going on if we haven't found anything |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
573 (if (not match) |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
574 (setq no-match t) |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
575 |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
576 ;; otherwise, suffixes contains what we need |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
577 (setq suffixes (car (cdr match)) |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
578 action (car (cdr match)) |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
579 found nil) |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
580 |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
581 ;; if we have a function to generate new names, |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
582 ;; invoke it with the name of the current file |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
583 (if (and (atom action) (fboundp action)) |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
584 (progn |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
585 (setq suffixes (funcall action (buffer-file-name)) |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
586 match (cons (car match) (list suffixes)) |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
587 stub nil |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
588 default-name (car suffixes))) |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
589 |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
590 ;; otherwise build our filename stub |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
591 (cond |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
592 |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
593 ;; get around the problem that 0 and nil both mean false! |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
594 ((= pos 0) |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
595 (setq format "") |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
596 (setq stub "") |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
597 ) |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
598 |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
599 (t |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
600 (setq format (concat "\\(.+\\)" (car match))) |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
601 (string-match format fname) |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
602 (setq stub (substring fname (match-beginning 1) (match-end 1))) |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
603 )) |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
604 |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
605 ;; if we find nothing, we should try to get a file like this one |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
606 (setq default-name |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
607 (concat stub (car (car (cdr match)))))) |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
608 |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
609 ;; do the real work - find the file |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
610 (setq found |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
611 (ff-get-file-name dirs stub suffixes))))) |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
612 found)) ;; return buffer-name or filename |
e12d545c9a48
(ff-other-file-name): New function.
Richard M. Stallman <rms@gnu.org>
parents:
38273
diff
changeset
|
613 |
30816 | 614 (defun ff-get-file (search-dirs filename &optional suffix-list other-window) |
615 "Find a file in the SEARCH-DIRS with the given FILENAME (or filename stub). | |
616 If (optional) SUFFIX-LIST is nil, search for fname, otherwise search | |
617 for fname with each of the given suffixes. Get the file or the buffer | |
618 corresponding to the name of the first file found, or nil." | |
619 (let ((filename (ff-get-file-name search-dirs filename suffix-list))) | |
49588
37645a051842
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48009
diff
changeset
|
620 |
30816 | 621 (cond |
10491 | 622 ((not filename) |
623 nil) | |
624 | |
13896 | 625 ((bufferp (get-file-buffer filename)) |
626 (ff-switch-to-buffer (get-file-buffer filename) other-window) | |
10491 | 627 filename) |
49588
37645a051842
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48009
diff
changeset
|
628 |
10491 | 629 ((file-exists-p filename) |
630 (ff-find-file filename other-window nil) | |
631 filename) | |
632 | |
633 (t | |
634 nil)))) | |
635 | |
636 (defun ff-get-file-name (search-dirs fname-stub &optional suffix-list) | |
30816 | 637 "Find a file in SEARCH-DIRS with the given name (or stub) FNAME-STUB. |
638 If (optional) SUFFIX-LIST is nil, search for FNAME-STUB, otherwise | |
639 search for FNAME-STUB with each of the given suffixes. Return the | |
640 name of the first file found." | |
10491 | 641 (let* (dirs ;; working copy of dirs to search |
642 dir ;; the current dir considered | |
643 file ;; filename being looked for | |
644 rest ;; pathname after first /* | |
645 this-suffix ;; the suffix we are currently considering | |
646 suffixes ;; working copy of suffix-list | |
647 filename ;; built filename | |
648 blist ;; list of live buffers | |
649 buf ;; current buffer in blist | |
650 found) ;; whether we have found anything | |
651 | |
652 (setq suffixes suffix-list) | |
653 | |
654 ;; suffixes is nil => fname-stub is the file we are looking for | |
655 ;; otherwise fname-stub is a stub, and we append a suffix | |
656 (if suffixes | |
657 (setq this-suffix (car suffixes)) | |
658 (setq this-suffix "") | |
659 (setq suffixes (list ""))) | |
49588
37645a051842
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48009
diff
changeset
|
660 |
10491 | 661 ;; find whether the file is in a buffer first |
662 (while (and suffixes (not found)) | |
663 (setq filename (concat fname-stub this-suffix)) | |
664 | |
665 (if (not ff-quiet-mode) | |
17548 | 666 (message "Finding buffer %s..." filename)) |
10491 | 667 |
17548 | 668 (if (bufferp (get-file-buffer filename)) |
669 (setq found (buffer-file-name (get-file-buffer filename)))) | |
10491 | 670 |
671 (setq blist (buffer-list)) | |
672 (setq buf (buffer-name (car blist))) | |
673 (while (and blist (not found)) | |
674 | |
675 (if (string-match (concat filename "<[0-9]+>") buf) | |
16510
e619a826afdb
Enabled commentary for Finder.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
676 (setq found (buffer-file-name (car blist)))) |
10491 | 677 |
678 (setq blist (cdr blist)) | |
679 (setq buf (buffer-name (car blist)))) | |
680 | |
681 (setq suffixes (cdr suffixes)) | |
682 (setq this-suffix (car suffixes))) | |
683 | |
684 ;; now look for the real file | |
685 (setq dirs search-dirs) | |
686 (setq dir (car dirs)) | |
687 (while (and (not found) dirs) | |
688 | |
689 (setq suffixes suffix-list) | |
690 | |
691 ;; if dir does not contain '/*', look for the file | |
692 (if (and dir (not (string-match "\\([^*]*\\)/\\\*\\(/.*\\)*" dir))) | |
30816 | 693 (progn |
49588
37645a051842
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48009
diff
changeset
|
694 |
10491 | 695 ;; suffixes is nil => fname-stub is the file we are looking for |
696 ;; otherwise fname-stub is a stub, and we append a suffix | |
697 (if suffixes | |
698 (setq this-suffix (car suffixes)) | |
699 (setq this-suffix "") | |
700 (setq suffixes (list ""))) | |
49588
37645a051842
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48009
diff
changeset
|
701 |
10491 | 702 (while (and suffixes (not found)) |
703 | |
704 (setq filename (concat fname-stub this-suffix)) | |
705 (setq file (concat dir "/" filename)) | |
49588
37645a051842
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48009
diff
changeset
|
706 |
10491 | 707 (if (not ff-quiet-mode) |
17548 | 708 (message "Finding %s..." file)) |
10491 | 709 |
710 (if (file-exists-p file) | |
711 (setq found file)) | |
49588
37645a051842
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48009
diff
changeset
|
712 |
10491 | 713 (setq suffixes (cdr suffixes)) |
714 (setq this-suffix (car suffixes)))) | |
715 | |
716 ;; otherwise dir matches the '/*', so search each dir separately | |
717 (progn | |
718 (if (match-beginning 2) | |
719 (setq rest (substring dir (match-beginning 2) (match-end 2))) | |
720 (setq rest "") | |
721 ) | |
722 (setq dir (substring dir (match-beginning 1) (match-end 1))) | |
723 | |
724 (let ((dirlist (ff-all-dirs-under dir '(".."))) | |
725 this-dir compl-dirs) | |
726 | |
727 (setq this-dir (car dirlist)) | |
728 (while dirlist | |
729 (setq compl-dirs | |
730 (append | |
731 compl-dirs | |
732 (list (concat this-dir rest)) | |
733 )) | |
734 (setq dirlist (cdr dirlist)) | |
735 (setq this-dir (car dirlist))) | |
736 | |
737 (if compl-dirs | |
738 (setq found (ff-get-file-name compl-dirs | |
739 fname-stub | |
740 suffix-list)))))) | |
741 (setq dirs (cdr dirs)) | |
742 (setq dir (car dirs))) | |
743 | |
744 (if found | |
745 (message "%s found" found)) | |
746 | |
747 found)) | |
748 | |
749 (defun ff-string-match (regexp string &optional start) | |
13896 | 750 "Like `string-match', but set `case-fold-search' temporarily. |
11272 | 751 The value used comes from `ff-case-fold-search'." |
752 (let ((case-fold-search ff-case-fold-search)) | |
10491 | 753 (if regexp |
11272 | 754 (string-match regexp string start)))) |
10491 | 755 |
756 (defun ff-list-replace-env-vars (search-list) | |
757 "Replace environment variables (of the form $VARIABLE) in SEARCH-LIST." | |
758 (let (list | |
759 (var (car search-list))) | |
760 (while search-list | |
761 (if (string-match "\\(.*\\)\\$[({]*\\([a-zA-Z0-9_]+\\)[)}]*\\(.*\\)" var) | |
762 (setq var | |
763 (concat | |
764 (substring var (match-beginning 1) (match-end 1)) | |
765 (getenv (substring var (match-beginning 2) (match-end 2))) | |
766 (substring var (match-beginning 3) (match-end 3))))) | |
767 (setq search-list (cdr search-list)) | |
768 (setq list (cons var list)) | |
769 (setq var (car search-list))) | |
770 (setq search-list (reverse list)))) | |
771 | |
772 (defun ff-treat-as-special () | |
30816 | 773 "Return the file to look for if the construct was special, else nil. |
71923
6d714c43de54
(ff-special-constructs): Doc fix. Also, for C/C++
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
68651
diff
changeset
|
774 See variable `ff-special-constructs'." |
6d714c43de54
(ff-special-constructs): Doc fix. Also, for C/C++
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
68651
diff
changeset
|
775 (save-excursion |
6d714c43de54
(ff-special-constructs): Doc fix. Also, for C/C++
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
68651
diff
changeset
|
776 (beginning-of-line 1) |
6d714c43de54
(ff-special-constructs): Doc fix. Also, for C/C++
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
68651
diff
changeset
|
777 (let* (fname |
6d714c43de54
(ff-special-constructs): Doc fix. Also, for C/C++
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
68651
diff
changeset
|
778 (list ff-special-constructs) |
6d714c43de54
(ff-special-constructs): Doc fix. Also, for C/C++
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
68651
diff
changeset
|
779 (elem (car list)) |
6d714c43de54
(ff-special-constructs): Doc fix. Also, for C/C++
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
68651
diff
changeset
|
780 (regexp (car elem)) |
6d714c43de54
(ff-special-constructs): Doc fix. Also, for C/C++
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
68651
diff
changeset
|
781 (match (cdr elem))) |
6d714c43de54
(ff-special-constructs): Doc fix. Also, for C/C++
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
68651
diff
changeset
|
782 (while (and list (not fname)) |
6d714c43de54
(ff-special-constructs): Doc fix. Also, for C/C++
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
68651
diff
changeset
|
783 (if (and (looking-at regexp) match) |
6d714c43de54
(ff-special-constructs): Doc fix. Also, for C/C++
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
68651
diff
changeset
|
784 (setq fname (funcall match))) |
6d714c43de54
(ff-special-constructs): Doc fix. Also, for C/C++
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
68651
diff
changeset
|
785 (setq list (cdr list)) |
6d714c43de54
(ff-special-constructs): Doc fix. Also, for C/C++
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
68651
diff
changeset
|
786 (setq elem (car list)) |
6d714c43de54
(ff-special-constructs): Doc fix. Also, for C/C++
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
68651
diff
changeset
|
787 (setq regexp (car elem)) |
6d714c43de54
(ff-special-constructs): Doc fix. Also, for C/C++
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
68651
diff
changeset
|
788 (setq match (cdr elem))) |
6d714c43de54
(ff-special-constructs): Doc fix. Also, for C/C++
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
68651
diff
changeset
|
789 fname))) |
10491 | 790 |
791 (defun ff-basename (string) | |
30816 | 792 "Return the basename of pathname STRING." |
10491 | 793 (setq string (concat "/" string)) |
794 (string-match ".*/\\([^/]+\\)$" string) | |
795 (setq string (substring string (match-beginning 1) (match-end 1)))) | |
796 | |
797 (defun ff-all-dirs-under (here &optional exclude) | |
11272 | 798 "Get all the directory files under directory HERE. |
10491 | 799 Exclude all files in the optional EXCLUDE list." |
800 (if (file-directory-p here) | |
801 (condition-case nil | |
802 (progn | |
803 (let ((files (directory-files here t)) | |
804 (dirlist (list)) | |
805 file) | |
806 (while files | |
807 (setq file (car files)) | |
808 (if (and | |
809 (file-directory-p file) | |
810 (not (member (ff-basename file) exclude))) | |
811 (setq dirlist (cons file dirlist))) | |
812 (setq files (cdr files))) | |
813 (setq dirlist (reverse dirlist)))) | |
814 (error nil)) | |
815 nil)) | |
816 | |
817 (defun ff-switch-file (f1 f2 file &optional in-other-window new-file) | |
11272 | 818 "Call F1 or F2 on FILE, according to IN-OTHER-WINDOW. |
819 In addition, this runs various hooks. | |
10491 | 820 |
11272 | 821 Either F1 or F2 receives FILE as the sole argument. |
822 The decision of which one to call is based on IN-OTHER-WINDOW | |
823 and on the global variable `ff-always-in-other-window'. | |
10491 | 824 |
11272 | 825 F1 and F2 are typically `find-file' / `find-file-other-window' |
826 or `switch-to-buffer' / `switch-to-buffer-other-window' function pairs. | |
827 | |
47354
27533450eb3b
(ff-pre-find-hook, ff-pre-load-hook, ff-post-load-hook)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44880
diff
changeset
|
828 If optional NEW-FILE is t, then a special hook (`ff-file-created-hook') is |
27533450eb3b
(ff-pre-find-hook, ff-pre-load-hook, ff-post-load-hook)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44880
diff
changeset
|
829 called before `ff-post-load-hook'." |
27533450eb3b
(ff-pre-find-hook, ff-pre-load-hook, ff-post-load-hook)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44880
diff
changeset
|
830 (run-hooks 'ff-pre-load-hook 'ff-pre-load-hooks) |
10491 | 831 (if (or |
832 (and in-other-window (not ff-always-in-other-window)) | |
833 (and (not in-other-window) ff-always-in-other-window)) | |
834 (funcall f2 file) | |
835 (funcall f1 file)) | |
836 (if new-file | |
47354
27533450eb3b
(ff-pre-find-hook, ff-pre-load-hook, ff-post-load-hook)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44880
diff
changeset
|
837 (run-hooks 'ff-file-created-hook 'ff-file-created-hooks)) |
27533450eb3b
(ff-pre-find-hook, ff-pre-load-hook, ff-post-load-hook)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44880
diff
changeset
|
838 (run-hooks 'ff-post-load-hook 'ff-post-load-hooks)) |
10491 | 839 |
840 (defun ff-find-file (file &optional in-other-window new-file) | |
13896 | 841 "Like `find-file', but may show the file in another window." |
30816 | 842 (ff-switch-file 'find-file |
843 'find-file-other-window | |
10491 | 844 file in-other-window new-file)) |
845 | |
13896 | 846 (defun ff-switch-to-buffer (buffer-or-name &optional in-other-window) |
847 "Like `switch-to-buffer', but may show the buffer in another window." | |
10491 | 848 |
30816 | 849 (ff-switch-file 'switch-to-buffer |
850 'switch-to-buffer-other-window | |
13896 | 851 buffer-or-name in-other-window nil)) |
10491 | 852 |
22192
bf83c23f3300
(ff-emacs-19, ff-xemacs): Functions deleted.
Richard M. Stallman <rms@gnu.org>
parents:
21087
diff
changeset
|
853 ;;;###autoload |
bf83c23f3300
(ff-emacs-19, ff-xemacs): Functions deleted.
Richard M. Stallman <rms@gnu.org>
parents:
21087
diff
changeset
|
854 (defun ff-mouse-find-other-file (event) |
bf83c23f3300
(ff-emacs-19, ff-xemacs): Functions deleted.
Richard M. Stallman <rms@gnu.org>
parents:
21087
diff
changeset
|
855 "Visit the file you click on." |
bf83c23f3300
(ff-emacs-19, ff-xemacs): Functions deleted.
Richard M. Stallman <rms@gnu.org>
parents:
21087
diff
changeset
|
856 (interactive "e") |
bf83c23f3300
(ff-emacs-19, ff-xemacs): Functions deleted.
Richard M. Stallman <rms@gnu.org>
parents:
21087
diff
changeset
|
857 (save-excursion |
30816 | 858 (mouse-set-point event) |
22192
bf83c23f3300
(ff-emacs-19, ff-xemacs): Functions deleted.
Richard M. Stallman <rms@gnu.org>
parents:
21087
diff
changeset
|
859 (ff-find-other-file nil))) |
10491 | 860 |
22192
bf83c23f3300
(ff-emacs-19, ff-xemacs): Functions deleted.
Richard M. Stallman <rms@gnu.org>
parents:
21087
diff
changeset
|
861 ;;;###autoload |
bf83c23f3300
(ff-emacs-19, ff-xemacs): Functions deleted.
Richard M. Stallman <rms@gnu.org>
parents:
21087
diff
changeset
|
862 (defun ff-mouse-find-other-file-other-window (event) |
30816 | 863 "Visit the file you click on in another window." |
22192
bf83c23f3300
(ff-emacs-19, ff-xemacs): Functions deleted.
Richard M. Stallman <rms@gnu.org>
parents:
21087
diff
changeset
|
864 (interactive "e") |
bf83c23f3300
(ff-emacs-19, ff-xemacs): Functions deleted.
Richard M. Stallman <rms@gnu.org>
parents:
21087
diff
changeset
|
865 (save-excursion |
30816 | 866 (mouse-set-point event) |
22192
bf83c23f3300
(ff-emacs-19, ff-xemacs): Functions deleted.
Richard M. Stallman <rms@gnu.org>
parents:
21087
diff
changeset
|
867 (ff-find-other-file t))) |
10491 | 868 |
869 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
870 ;; This section offers an example of user defined function to select files | |
871 | |
11272 | 872 (defun ff-upcase-p (string &optional start end) |
30816 | 873 "Return t if STRING is all uppercase. |
11272 | 874 Given START and/or END, checks between these characters." |
10491 | 875 (let (match str) |
876 (if (not start) | |
877 (setq start 0)) | |
878 (if (not end) | |
879 (setq end (length string))) | |
880 (if (= start end) | |
881 (setq end (1+ end))) | |
882 (setq str (substring string start end)) | |
30816 | 883 (if (and |
10491 | 884 (ff-string-match "[A-Z]+" str) |
885 (setq match (match-data)) | |
886 (= (car match) 0) | |
887 (= (car (cdr match)) (length str))) | |
888 t | |
889 nil))) | |
890 | |
891 (defun ff-cc-hh-converter (arg) | |
11272 | 892 "Discriminate file extensions. |
893 Build up a new file list based possibly on part of the directory name | |
894 and the name of the file passed in." | |
10491 | 895 (ff-string-match "\\(.*\\)/\\([^/]+\\)/\\([^.]+\\).\\([^/]+\\)$" arg) |
30816 | 896 (let ((path (if (match-beginning 1) |
10491 | 897 (substring arg (match-beginning 1) (match-end 1)) nil)) |
30816 | 898 (dire (if (match-beginning 2) |
10491 | 899 (substring arg (match-beginning 2) (match-end 2)) nil)) |
30816 | 900 (file (if (match-beginning 3) |
10491 | 901 (substring arg (match-beginning 3) (match-end 3)) nil)) |
30816 | 902 (extn (if (match-beginning 4) |
10491 | 903 (substring arg (match-beginning 4) (match-end 4)) nil)) |
904 return-list) | |
905 (cond | |
906 ;; fooZapJunk.cc => ZapJunk.{hh,h} or fooZapJunk.{hh,h} | |
30816 | 907 ((and (string= extn "cc") |
10491 | 908 (ff-string-match "^\\([a-z]+\\)\\([A-Z].+\\)$" file)) |
909 (let ((stub (substring file (match-beginning 2) (match-end 2)))) | |
910 (setq dire (upcase (substring file (match-beginning 1) (match-end 1)))) | |
911 (setq return-list (list (concat stub ".hh") | |
912 (concat stub ".h") | |
913 (concat file ".hh") | |
914 (concat file ".h"))) | |
915 )) | |
916 ;; FOO/ZapJunk.hh => fooZapJunk.{cc,C} or ZapJunk.{cc,C} | |
11272 | 917 ((and (string= extn "hh") (ff-upcase-p dire) file) |
10491 | 918 (let ((stub (concat (downcase dire) file))) |
30816 | 919 (setq return-list (list (concat stub ".cc") |
10491 | 920 (concat stub ".C") |
921 (concat file ".cc") | |
922 (concat file ".C"))) | |
923 )) | |
924 ;; zap.cc => zap.hh or zap.h | |
925 ((string= extn "cc") | |
926 (let ((stub file)) | |
927 (setq return-list (list (concat stub ".hh") | |
928 (concat stub ".h"))) | |
929 )) | |
930 ;; zap.hh => zap.cc or zap.C | |
931 ((string= extn "hh") | |
932 (let ((stub file)) | |
933 (setq return-list (list (concat stub ".cc") | |
934 (concat stub ".C"))) | |
935 )) | |
30816 | 936 (t |
10491 | 937 nil)) |
49588
37645a051842
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
48009
diff
changeset
|
938 |
10491 | 939 return-list)) |
940 | |
941 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
942 ;; This section offers an example of user defined function to place point. | |
943 ;; The regexps are Ada specific. | |
944 | |
945 (defvar ff-function-name nil "Name of the function we are in.") | |
946 | |
47354
27533450eb3b
(ff-pre-find-hook, ff-pre-load-hook, ff-post-load-hook)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44880
diff
changeset
|
947 ;; bind with (setq ff-pre-load-hook 'ff-which-function-are-we-in) |
10491 | 948 ;; |
64796
023827894687
(ada-procedure-start-regexp, ada-package-start-regexp): Add defvars.
Richard M. Stallman <rms@gnu.org>
parents:
64762
diff
changeset
|
949 (defvar ada-procedure-start-regexp) |
023827894687
(ada-procedure-start-regexp, ada-package-start-regexp): Add defvars.
Richard M. Stallman <rms@gnu.org>
parents:
64762
diff
changeset
|
950 (defvar ada-package-start-regexp) |
023827894687
(ada-procedure-start-regexp, ada-package-start-regexp): Add defvars.
Richard M. Stallman <rms@gnu.org>
parents:
64762
diff
changeset
|
951 |
10491 | 952 (defun ff-which-function-are-we-in () |
11272 | 953 "Return the name of the function whose definition/declaration point is in. |
954 Also remember that name in `ff-function-name'." | |
63921
8c8961dafdc6
(ff-which-function-are-we-in): Clean up.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
63505
diff
changeset
|
955 (setq ff-function-name |
8c8961dafdc6
(ff-which-function-are-we-in): Clean up.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
63505
diff
changeset
|
956 (save-excursion |
8c8961dafdc6
(ff-which-function-are-we-in): Clean up.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
63505
diff
changeset
|
957 (if (or (re-search-backward ada-procedure-start-regexp nil t) |
8c8961dafdc6
(ff-which-function-are-we-in): Clean up.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
63505
diff
changeset
|
958 (re-search-backward ada-package-start-regexp nil t)) |
8c8961dafdc6
(ff-which-function-are-we-in): Clean up.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
63505
diff
changeset
|
959 (match-string 0))))) |
10491 | 960 |
47354
27533450eb3b
(ff-pre-find-hook, ff-pre-load-hook, ff-post-load-hook)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
44880
diff
changeset
|
961 ;; bind with (setq ff-post-load-hook 'ff-set-point-accordingly) |
10491 | 962 ;; |
963 (defun ff-set-point-accordingly () | |
11272 | 964 "Find the function specified in `ff-function-name'. |
12567
7318536fb256
(ff-set-point-accordingly): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
11272
diff
changeset
|
965 That name was previously determined by `ff-which-function-are-we-in'." |
10491 | 966 (if ff-function-name |
967 (progn | |
968 (goto-char (point-min)) | |
969 (search-forward ff-function-name nil t)))) | |
970 | |
30816 | 971 (provide 'find-file) |
10491 | 972 |
63921
8c8961dafdc6
(ff-which-function-are-we-in): Clean up.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
63505
diff
changeset
|
973 ;; arch-tag: 5a2fc49e-3b0a-4708-9acf-fb14e471a97a |
30816 | 974 ;;; find-file.el ends here |