annotate lisp/find-file.el @ 16925:2b35e4ccbb32

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