annotate lisp/find-file.el @ 11141:6f6c571ad0c0

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