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