2021-04-06 20:28:50 +00:00
|
|
|
;;; find-file.el --- find a file corresponding to this one given a pattern -*- lexical-binding: t; -*-
|
1995-01-20 06:04:56 +00:00
|
|
|
|
1997-06-02 22:10:28 +00:00
|
|
|
;; Author: Henry Guillaume <henri@tibco.com, henry@c032.aone.net.au>
|
2019-05-25 20:43:06 +00:00
|
|
|
;; Maintainer: emacs-devel@gnu.org
|
1995-01-20 06:04:56 +00:00
|
|
|
;; Keywords: c, matching, tools
|
|
|
|
|
2024-01-02 01:47:10 +00:00
|
|
|
;; Copyright (C) 1994-1995, 2001-2024 Free Software Foundation, Inc.
|
1995-01-20 06:04:56 +00:00
|
|
|
|
1996-01-14 07:34:30 +00:00
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
|
2008-05-06 08:06:51 +00:00
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
1996-01-14 07:34:30 +00:00
|
|
|
;; it under the terms of the GNU General Public License as published by
|
2008-05-06 08:06:51 +00:00
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
;; (at your option) any later version.
|
1996-01-14 07:34:30 +00:00
|
|
|
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
2017-09-13 22:52:52 +00:00
|
|
|
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
|
1995-01-20 06:04:56 +00:00
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
|
|
;; PURPOSE:
|
2000-08-15 14:18:18 +00:00
|
|
|
;; This package features a function called ff-find-other-file, which performs
|
|
|
|
;; the following function:
|
1995-01-20 06:04:56 +00:00
|
|
|
;;
|
|
|
|
;; When in a .c file, find the first corresponding .h file in a set
|
|
|
|
;; of directories and display it, and vice-versa from the .h file.
|
|
|
|
;;
|
|
|
|
;; Many people maintain their include file in a directory separate to their
|
|
|
|
;; src directory, and very often you may be editing a file and have a need to
|
2021-09-14 06:43:18 +00:00
|
|
|
;; visit the "other file". This package searches through a set of directories
|
1995-01-20 06:04:56 +00:00
|
|
|
;; to find that file.
|
|
|
|
;;
|
|
|
|
;; THE "OTHER FILE", or "corresponding file", generally has the same basename,
|
2000-08-15 14:18:18 +00:00
|
|
|
;; and just has a different extension as described by the ff-other-file-alist
|
1995-01-20 06:04:56 +00:00
|
|
|
;; variable:
|
|
|
|
;;
|
2021-04-06 20:28:50 +00:00
|
|
|
;; '(("\\.cc\\'" (".hh" ".h"))
|
|
|
|
;; ("\\.hh\\'" (".cc" ".C" ".CC" ".cxx" ".cpp")))
|
1995-01-20 06:04:56 +00:00
|
|
|
;;
|
|
|
|
;; If the current file has a .cc extension, ff-find-other-file will attempt
|
|
|
|
;; to look for a .hh file, and then a .h file in some directory as described
|
2021-09-14 06:43:18 +00:00
|
|
|
;; below. The mechanism here is to replace the matched part of the original
|
1995-01-20 06:04:56 +00:00
|
|
|
;; filename with each of the corresponding extensions in turn.
|
|
|
|
;;
|
|
|
|
;; Alternatively, there are situations where the filename of the other file
|
2021-09-14 06:43:18 +00:00
|
|
|
;; cannot be determined easily with regexps. For example, a .c file may
|
1995-01-20 06:04:56 +00:00
|
|
|
;; have two corresponding .h files, for its public and private parts, or
|
|
|
|
;; the filename for the .c file contains part of the pathname of the .h
|
2021-09-14 06:43:18 +00:00
|
|
|
;; file, as between src/fooZap.cc and include/FOO/zap.hh. In that case, the
|
1995-01-20 06:04:56 +00:00
|
|
|
;; format above can be changed to include a function to be called when the
|
|
|
|
;; current file matches the regexp:
|
|
|
|
;;
|
2021-04-06 20:28:50 +00:00
|
|
|
;; '(("\\.cc\\'" cc--function)
|
|
|
|
;; ("\\.hh\\'" hh-function))
|
1995-01-20 06:04:56 +00:00
|
|
|
;;
|
2000-08-15 14:18:18 +00:00
|
|
|
;; These functions must return a list consisting of the possible names of the
|
2021-09-14 06:43:18 +00:00
|
|
|
;; corresponding file, with or without path. There is no real need for more
|
1995-01-20 06:04:56 +00:00
|
|
|
;; than one function, and one could imagine the following value for cc-other-
|
|
|
|
;; file-alist:
|
|
|
|
;;
|
|
|
|
;; (setq cc-other-file-alist
|
2021-04-06 20:28:50 +00:00
|
|
|
;; '(("\\.cc\\'" ff-cc-hh-converter)
|
|
|
|
;; ("\\.hh\\'" ff-cc-hh-converter)
|
|
|
|
;; ("\\.c\\'" (".h"))
|
|
|
|
;; ("\\.h\\'" (".c" ".cc" ".C" ".CC" ".cxx" ".cpp"))))
|
2003-02-04 11:26:42 +00:00
|
|
|
;;
|
1995-01-20 06:04:56 +00:00
|
|
|
;; ff-cc-hh-converter is included at the end of this file as a reference.
|
2003-02-04 11:26:42 +00:00
|
|
|
;;
|
1995-01-20 06:04:56 +00:00
|
|
|
;; SEARCHING is carried out in a set of directories specified by the
|
|
|
|
;; ff-search-directories variable:
|
|
|
|
;;
|
|
|
|
;; ("." "../../src" "../include/*" "/usr/local/*/src/*" "$PROJECT/src")
|
|
|
|
;;
|
|
|
|
;; This means that the corresponding file will be searched for first in
|
|
|
|
;; the current directory, then in ../../src, then in one of the directories
|
2021-09-14 06:43:18 +00:00
|
|
|
;; under ../include, and so on. The star is _not_ a general wildcard
|
1995-01-20 06:04:56 +00:00
|
|
|
;; character: it just indicates that the subdirectories of this directory
|
2021-09-14 06:43:18 +00:00
|
|
|
;; must each be searched in turn. Environment variables will be expanded in
|
1995-01-20 06:04:56 +00:00
|
|
|
;; the ff-search-directories variable.
|
|
|
|
;;
|
|
|
|
;; If the point is on a #include line, the file to be #included is searched
|
2021-09-14 06:43:18 +00:00
|
|
|
;; for in the same manner. This can be disabled with the ff-ignore-include
|
1995-01-20 06:04:56 +00:00
|
|
|
;; variable, or by calling ff-get-other-file instead of ff-find-other-file.
|
|
|
|
;;
|
|
|
|
;; If the file was not found, ff-find-other-file will prompt you for where
|
|
|
|
;; to create the new "corresponding file" (defaults to the current directory),
|
2000-08-15 14:18:18 +00:00
|
|
|
;; unless the variable ff-always-try-to-create is set to nil.
|
1995-01-20 06:04:56 +00:00
|
|
|
;;
|
2000-08-15 14:18:18 +00:00
|
|
|
;; GIVEN AN ARGUMENT (with the ^U prefix), ff-find-other-file will get the
|
|
|
|
;; other file in another (the other?) window (see find-file-other-window and
|
2024-07-20 00:22:49 +00:00
|
|
|
;; switch-to-buffer-other-window). This can be set on a more permanent basis
|
2000-08-15 14:18:18 +00:00
|
|
|
;; by setting ff-always-in-other-window to t in which case the ^U prefix will
|
1995-01-20 06:04:56 +00:00
|
|
|
;; do the opposite of what was described above.
|
|
|
|
;;
|
|
|
|
;; THERE ARE FIVE AVAILABLE HOOKS, called in this order if non-nil:
|
|
|
|
;;
|
2002-09-09 22:45:09 +00:00
|
|
|
;; - ff-pre-find-hook - called before the search for the other file starts
|
|
|
|
;; - ff-not-found-hook - called when the other file could not be found
|
|
|
|
;; - ff-pre-load-hook - called just before the other file is 'loaded'
|
|
|
|
;; - ff-file-created-hook - called when the other file is created
|
|
|
|
;; - ff-post-load-hook - called just after the other file is 'loaded'
|
1995-01-20 06:04:56 +00:00
|
|
|
;;
|
2002-09-09 22:45:09 +00:00
|
|
|
;; The *load-hook allow you to place point where you want it in the other
|
2000-08-15 14:18:18 +00:00
|
|
|
;; file.
|
1995-01-20 06:04:56 +00:00
|
|
|
|
|
|
|
;; CREDITS:
|
2020-10-02 16:02:51 +00:00
|
|
|
;; Many thanks go to TUSC Computer Systems Pty Ltd for providing an
|
|
|
|
;; environment that made the development of this package possible.
|
1995-01-20 06:04:56 +00:00
|
|
|
;;
|
|
|
|
;; Many thanks also go to all those who provided valuable feedback throughout
|
|
|
|
;; the development of this package:
|
|
|
|
;; Rolf Ebert in particular, Fritz Knabe, Heddy Boubaker, Sebastian Kremer,
|
2000-08-15 14:18:18 +00:00
|
|
|
;; Vasco Lopes Paulo, Mark A. Plaksin, Robert Lang, Trevor West, Kevin
|
1996-11-03 20:29:42 +00:00
|
|
|
;; Pereira, Benedict Lofstedt & Justin Vallon.
|
1995-01-20 06:04:56 +00:00
|
|
|
|
1996-11-03 20:29:42 +00:00
|
|
|
;;; Code:
|
1995-01-20 06:04:56 +00:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; User definable variables:
|
|
|
|
|
1998-03-07 15:27:01 +00:00
|
|
|
(defgroup ff nil
|
|
|
|
"Find a file corresponding to this one given a pattern."
|
|
|
|
:prefix "ff-"
|
2000-08-15 14:18:18 +00:00
|
|
|
:link '(emacs-commentary-link "find-file")
|
1998-03-07 15:27:01 +00:00
|
|
|
:group 'find-file)
|
|
|
|
|
2002-09-09 22:45:09 +00:00
|
|
|
(defcustom ff-pre-find-hook nil
|
* find-file.el (ff-get-file): Doc fix.
(ff-get-file-name): Use `let', not `let*'.
(ff-search-directories): Fix typo in docstring.
(ff-pre-find-hook, ff-pre-load-hook, ff-post-load-hook)
(ff-not-found-hook, ff-file-created-hook, ff-case-fold-search)
(ff-always-in-other-window, ff-ignore-include, ff-always-try-to-create)
(ff-quiet-mode, ff-other-file-alist, cc-search-directories)
(cc-other-file-alist, modula2-other-file-alist):
Remove spurious * in docstrings.
2008-10-15 15:32:21 +00:00
|
|
|
"List of functions to be called before the search for the file starts."
|
2021-04-06 20:28:50 +00:00
|
|
|
:type 'hook)
|
1998-03-07 15:27:01 +00:00
|
|
|
|
2002-09-09 22:45:09 +00:00
|
|
|
(defcustom ff-pre-load-hook nil
|
* find-file.el (ff-get-file): Doc fix.
(ff-get-file-name): Use `let', not `let*'.
(ff-search-directories): Fix typo in docstring.
(ff-pre-find-hook, ff-pre-load-hook, ff-post-load-hook)
(ff-not-found-hook, ff-file-created-hook, ff-case-fold-search)
(ff-always-in-other-window, ff-ignore-include, ff-always-try-to-create)
(ff-quiet-mode, ff-other-file-alist, cc-search-directories)
(cc-other-file-alist, modula2-other-file-alist):
Remove spurious * in docstrings.
2008-10-15 15:32:21 +00:00
|
|
|
"List of functions to be called before the other file is loaded."
|
2021-04-06 20:28:50 +00:00
|
|
|
:type 'hook)
|
1998-03-07 15:27:01 +00:00
|
|
|
|
2002-09-09 22:45:09 +00:00
|
|
|
(defcustom ff-post-load-hook nil
|
* find-file.el (ff-get-file): Doc fix.
(ff-get-file-name): Use `let', not `let*'.
(ff-search-directories): Fix typo in docstring.
(ff-pre-find-hook, ff-pre-load-hook, ff-post-load-hook)
(ff-not-found-hook, ff-file-created-hook, ff-case-fold-search)
(ff-always-in-other-window, ff-ignore-include, ff-always-try-to-create)
(ff-quiet-mode, ff-other-file-alist, cc-search-directories)
(cc-other-file-alist, modula2-other-file-alist):
Remove spurious * in docstrings.
2008-10-15 15:32:21 +00:00
|
|
|
"List of functions to be called after the other file is loaded."
|
2021-04-06 20:28:50 +00:00
|
|
|
:type 'hook)
|
1998-03-07 15:27:01 +00:00
|
|
|
|
2002-09-09 22:45:09 +00:00
|
|
|
(defcustom ff-not-found-hook nil
|
* find-file.el (ff-get-file): Doc fix.
(ff-get-file-name): Use `let', not `let*'.
(ff-search-directories): Fix typo in docstring.
(ff-pre-find-hook, ff-pre-load-hook, ff-post-load-hook)
(ff-not-found-hook, ff-file-created-hook, ff-case-fold-search)
(ff-always-in-other-window, ff-ignore-include, ff-always-try-to-create)
(ff-quiet-mode, ff-other-file-alist, cc-search-directories)
(cc-other-file-alist, modula2-other-file-alist):
Remove spurious * in docstrings.
2008-10-15 15:32:21 +00:00
|
|
|
"List of functions to be called if the other file could not be found."
|
2021-04-06 20:28:50 +00:00
|
|
|
:type 'hook)
|
1998-03-07 15:27:01 +00:00
|
|
|
|
2002-09-09 22:45:09 +00:00
|
|
|
(defcustom ff-file-created-hook nil
|
* find-file.el (ff-get-file): Doc fix.
(ff-get-file-name): Use `let', not `let*'.
(ff-search-directories): Fix typo in docstring.
(ff-pre-find-hook, ff-pre-load-hook, ff-post-load-hook)
(ff-not-found-hook, ff-file-created-hook, ff-case-fold-search)
(ff-always-in-other-window, ff-ignore-include, ff-always-try-to-create)
(ff-quiet-mode, ff-other-file-alist, cc-search-directories)
(cc-other-file-alist, modula2-other-file-alist):
Remove spurious * in docstrings.
2008-10-15 15:32:21 +00:00
|
|
|
"List of functions to be called if the other file needs to be created."
|
2021-04-06 20:28:50 +00:00
|
|
|
:type 'hook)
|
1998-03-07 15:27:01 +00:00
|
|
|
|
|
|
|
(defcustom ff-case-fold-search nil
|
* find-file.el (ff-get-file): Doc fix.
(ff-get-file-name): Use `let', not `let*'.
(ff-search-directories): Fix typo in docstring.
(ff-pre-find-hook, ff-pre-load-hook, ff-post-load-hook)
(ff-not-found-hook, ff-file-created-hook, ff-case-fold-search)
(ff-always-in-other-window, ff-ignore-include, ff-always-try-to-create)
(ff-quiet-mode, ff-other-file-alist, cc-search-directories)
(cc-other-file-alist, modula2-other-file-alist):
Remove spurious * in docstrings.
2008-10-15 15:32:21 +00:00
|
|
|
"Non-nil means ignore cases in matches (see `case-fold-search').
|
1998-03-07 15:27:01 +00:00
|
|
|
If you have extensions in different cases, you will want this to be nil."
|
2021-04-06 20:28:50 +00:00
|
|
|
:type 'boolean)
|
1995-01-20 06:04:56 +00:00
|
|
|
|
1998-03-07 15:27:01 +00:00
|
|
|
(defcustom ff-always-in-other-window nil
|
* find-file.el (ff-get-file): Doc fix.
(ff-get-file-name): Use `let', not `let*'.
(ff-search-directories): Fix typo in docstring.
(ff-pre-find-hook, ff-pre-load-hook, ff-post-load-hook)
(ff-not-found-hook, ff-file-created-hook, ff-case-fold-search)
(ff-always-in-other-window, ff-ignore-include, ff-always-try-to-create)
(ff-quiet-mode, ff-other-file-alist, cc-search-directories)
(cc-other-file-alist, modula2-other-file-alist):
Remove spurious * in docstrings.
2008-10-15 15:32:21 +00:00
|
|
|
"If non-nil, find the corresponding file in another window by default.
|
1998-03-07 15:27:01 +00:00
|
|
|
To override this, give an argument to `ff-find-other-file'."
|
2021-04-06 20:28:50 +00:00
|
|
|
:type 'boolean)
|
1995-01-20 06:04:56 +00:00
|
|
|
|
1998-03-07 15:27:01 +00:00
|
|
|
(defcustom ff-ignore-include nil
|
* find-file.el (ff-get-file): Doc fix.
(ff-get-file-name): Use `let', not `let*'.
(ff-search-directories): Fix typo in docstring.
(ff-pre-find-hook, ff-pre-load-hook, ff-post-load-hook)
(ff-not-found-hook, ff-file-created-hook, ff-case-fold-search)
(ff-always-in-other-window, ff-ignore-include, ff-always-try-to-create)
(ff-quiet-mode, ff-other-file-alist, cc-search-directories)
(cc-other-file-alist, modula2-other-file-alist):
Remove spurious * in docstrings.
2008-10-15 15:32:21 +00:00
|
|
|
"If non-nil, ignore `#include' lines."
|
2021-04-06 20:28:50 +00:00
|
|
|
:type 'boolean)
|
1995-01-20 06:04:56 +00:00
|
|
|
|
1998-03-07 15:27:01 +00:00
|
|
|
(defcustom ff-always-try-to-create t
|
* find-file.el (ff-get-file): Doc fix.
(ff-get-file-name): Use `let', not `let*'.
(ff-search-directories): Fix typo in docstring.
(ff-pre-find-hook, ff-pre-load-hook, ff-post-load-hook)
(ff-not-found-hook, ff-file-created-hook, ff-case-fold-search)
(ff-always-in-other-window, ff-ignore-include, ff-always-try-to-create)
(ff-quiet-mode, ff-other-file-alist, cc-search-directories)
(cc-other-file-alist, modula2-other-file-alist):
Remove spurious * in docstrings.
2008-10-15 15:32:21 +00:00
|
|
|
"If non-nil, always attempt to create the other file if it was not found."
|
2021-04-06 20:28:50 +00:00
|
|
|
:type 'boolean)
|
1995-01-20 06:04:56 +00:00
|
|
|
|
1998-03-07 15:27:01 +00:00
|
|
|
(defcustom ff-quiet-mode nil
|
2023-04-10 12:49:32 +00:00
|
|
|
"If non-nil, do not trace which directories are being searched."
|
2021-04-06 20:28:50 +00:00
|
|
|
:type 'boolean)
|
1995-01-20 06:04:56 +00:00
|
|
|
|
2003-09-28 16:11:45 +00:00
|
|
|
;;;###autoload
|
2012-05-04 05:14:14 +00:00
|
|
|
(defcustom ff-special-constructs
|
|
|
|
;; C/C++ include, for NeXTstep too
|
2015-09-17 23:08:20 +00:00
|
|
|
`((,(purecopy "^#\\s *\\(include\\|import\\)\\s +[<\"]\\(.*\\)[>\"]") .
|
2021-04-06 20:28:50 +00:00
|
|
|
,(lambda () (match-string 2))))
|
2006-07-16 21:08:28 +00:00
|
|
|
;; We include `ff-treat-as-special' documentation here so that autoload
|
|
|
|
;; can make it available to be read prior to loading this file.
|
2012-05-04 05:14:14 +00:00
|
|
|
"List of special constructs recognized by `ff-treat-as-special'.
|
2006-07-16 21:08:28 +00:00
|
|
|
Each element, tried in order, has the form (REGEXP . EXTRACT).
|
|
|
|
If REGEXP matches the current line (from the beginning of the line),
|
|
|
|
`ff-treat-as-special' calls function EXTRACT with no args.
|
|
|
|
If EXTRACT returns nil, keep trying. Otherwise, return the
|
2012-05-04 05:14:14 +00:00
|
|
|
filename that EXTRACT returned."
|
2021-04-06 20:28:50 +00:00
|
|
|
:type '(repeat (cons regexp function)))
|
1995-01-20 06:04:56 +00:00
|
|
|
|
2002-10-14 01:25:16 +00:00
|
|
|
(defvaralias 'ff-related-file-alist 'ff-other-file-alist)
|
1998-03-07 15:27:01 +00:00
|
|
|
(defcustom ff-other-file-alist 'cc-other-file-alist
|
* find-file.el (ff-get-file): Doc fix.
(ff-get-file-name): Use `let', not `let*'.
(ff-search-directories): Fix typo in docstring.
(ff-pre-find-hook, ff-pre-load-hook, ff-post-load-hook)
(ff-not-found-hook, ff-file-created-hook, ff-case-fold-search)
(ff-always-in-other-window, ff-ignore-include, ff-always-try-to-create)
(ff-quiet-mode, ff-other-file-alist, cc-search-directories)
(cc-other-file-alist, modula2-other-file-alist):
Remove spurious * in docstrings.
2008-10-15 15:32:21 +00:00
|
|
|
"Alist of extensions to find given the current file's extension.
|
1995-01-20 06:04:56 +00:00
|
|
|
|
2022-08-21 18:48:58 +00:00
|
|
|
The value could be an alist or a symbol whose value is an alist.
|
|
|
|
Each element of the alist has the form
|
|
|
|
|
2022-08-21 20:31:05 +00:00
|
|
|
(REGEXP (EXTENSION...))
|
2022-08-21 18:48:58 +00:00
|
|
|
|
|
|
|
where REGEXP is the regular expression matching a file's extension,
|
2022-08-30 12:42:34 +00:00
|
|
|
and EXTENSIONs is the list of literal file-name extensions to search
|
|
|
|
for. The list of extensions should contain the most used extensions
|
|
|
|
before the others, since the search algorithm searches sequentially
|
|
|
|
through each directory specified in `ff-search-directories'.
|
|
|
|
|
|
|
|
Alist elements can also be of the form
|
|
|
|
|
|
|
|
(REGEXP FUNCTION)
|
|
|
|
|
|
|
|
where FUNCTION is a function of one argument, the current file's name,
|
|
|
|
that returns the list of possible names of the corresponding files, with
|
|
|
|
or without leading directories. Note the difference: FUNCTION returns
|
|
|
|
the list of file names, not their extensions. This is for the case when
|
|
|
|
REGEXP is not enough to determine the file name of the other file.
|
|
|
|
|
|
|
|
If a file is not found, a new one is created with the first
|
|
|
|
matching extension or name (e.g., `.cc' yields `.hh').
|
|
|
|
|
2022-08-29 14:02:46 +00:00
|
|
|
This alist should be set by the major mode.
|
|
|
|
|
|
|
|
Note: if an element of the alist names a FUNCTION as its cdr, that
|
2022-08-30 16:09:00 +00:00
|
|
|
function must return a non-nil list of file-names. It cannot
|
2022-08-29 14:02:46 +00:00
|
|
|
return nil, nor can it signal in any way a failure to find a suitable
|
2022-08-30 16:09:00 +00:00
|
|
|
list of file names."
|
1998-03-07 15:27:01 +00:00
|
|
|
:type '(choice (repeat (list regexp (choice (repeat string) function)))
|
2021-04-06 20:28:50 +00:00
|
|
|
symbol))
|
1995-01-20 06:04:56 +00:00
|
|
|
|
1998-03-07 15:27:01 +00:00
|
|
|
(defcustom ff-search-directories 'cc-search-directories
|
* find-file.el (ff-get-file): Doc fix.
(ff-get-file-name): Use `let', not `let*'.
(ff-search-directories): Fix typo in docstring.
(ff-pre-find-hook, ff-pre-load-hook, ff-post-load-hook)
(ff-not-found-hook, ff-file-created-hook, ff-case-fold-search)
(ff-always-in-other-window, ff-ignore-include, ff-always-try-to-create)
(ff-quiet-mode, ff-other-file-alist, cc-search-directories)
(cc-other-file-alist, modula2-other-file-alist):
Remove spurious * in docstrings.
2008-10-15 15:32:21 +00:00
|
|
|
"List of directories to search for a specific file.
|
1995-01-20 06:04:56 +00:00
|
|
|
|
1995-04-07 21:51:51 +00:00
|
|
|
Set by default to `cc-search-directories', expanded at run-time.
|
1995-01-20 06:04:56 +00:00
|
|
|
|
|
|
|
This list is searched through with each extension specified in
|
1995-04-07 21:51:51 +00:00
|
|
|
`ff-other-file-alist' that matches this file's extension. So the
|
2005-06-16 16:09:00 +00:00
|
|
|
longer the list, the longer it'll take to realize that a file
|
1995-01-20 06:04:56 +00:00
|
|
|
may not exist.
|
|
|
|
|
2000-08-15 14:18:18 +00:00
|
|
|
A typical format is
|
1995-01-20 06:04:56 +00:00
|
|
|
|
2015-11-17 23:28:50 +00:00
|
|
|
(\".\" \"/usr/include\" \"$PROJECT/*/include\")
|
1995-01-20 06:04:56 +00:00
|
|
|
|
1995-04-07 21:51:51 +00:00
|
|
|
Environment variables can be inserted between slashes (`/').
|
* find-file.el (ff-get-file): Doc fix.
(ff-get-file-name): Use `let', not `let*'.
(ff-search-directories): Fix typo in docstring.
(ff-pre-find-hook, ff-pre-load-hook, ff-post-load-hook)
(ff-not-found-hook, ff-file-created-hook, ff-case-fold-search)
(ff-always-in-other-window, ff-ignore-include, ff-always-try-to-create)
(ff-quiet-mode, ff-other-file-alist, cc-search-directories)
(cc-other-file-alist, modula2-other-file-alist):
Remove spurious * in docstrings.
2008-10-15 15:32:21 +00:00
|
|
|
They will be replaced by their definition. If a variable does
|
1995-04-07 21:51:51 +00:00
|
|
|
not exist, it is replaced (silently) with an empty string.
|
1995-01-20 06:04:56 +00:00
|
|
|
|
1995-04-07 21:51:51 +00:00
|
|
|
The stars are *not* wildcards: they are searched for together with
|
|
|
|
the preceding slash. The star represents all the subdirectories except
|
1998-03-07 15:27:01 +00:00
|
|
|
`..', and each of these subdirectories will be searched in turn."
|
2021-04-06 20:28:50 +00:00
|
|
|
:type '(choice (repeat directory) symbol))
|
1995-01-20 06:04:56 +00:00
|
|
|
|
1998-03-07 15:27:01 +00:00
|
|
|
(defcustom cc-search-directories
|
1996-11-03 20:29:42 +00:00
|
|
|
'("." "/usr/include" "/usr/local/include/*")
|
* find-file.el (ff-get-file): Doc fix.
(ff-get-file-name): Use `let', not `let*'.
(ff-search-directories): Fix typo in docstring.
(ff-pre-find-hook, ff-pre-load-hook, ff-post-load-hook)
(ff-not-found-hook, ff-file-created-hook, ff-case-fold-search)
(ff-always-in-other-window, ff-ignore-include, ff-always-try-to-create)
(ff-quiet-mode, ff-other-file-alist, cc-search-directories)
(cc-other-file-alist, modula2-other-file-alist):
Remove spurious * in docstrings.
2008-10-15 15:32:21 +00:00
|
|
|
"See the description of the `ff-search-directories' variable."
|
2021-04-06 20:28:50 +00:00
|
|
|
:type '(repeat directory))
|
1995-01-20 06:04:56 +00:00
|
|
|
|
1998-03-07 15:27:01 +00:00
|
|
|
(defcustom cc-other-file-alist
|
2004-10-26 21:39:34 +00:00
|
|
|
'(("\\.cc\\'" (".hh" ".h"))
|
2015-03-24 19:53:08 +00:00
|
|
|
("\\.hh\\'" (".cc" ".C" ".CC" ".cxx" ".cpp" ".c++"))
|
1995-01-20 06:04:56 +00:00
|
|
|
|
2004-10-26 21:39:34 +00:00
|
|
|
("\\.c\\'" (".h"))
|
2013-05-06 07:40:58 +00:00
|
|
|
("\\.m\\'" (".h"))
|
2015-03-24 19:53:08 +00:00
|
|
|
("\\.h\\'" (".c" ".cc" ".C" ".CC" ".cxx" ".cpp" ".c++" ".m"))
|
1995-01-20 06:04:56 +00:00
|
|
|
|
2004-10-26 21:39:34 +00:00
|
|
|
("\\.C\\'" (".H" ".hh" ".h"))
|
|
|
|
("\\.H\\'" (".C" ".CC"))
|
1995-01-20 06:04:56 +00:00
|
|
|
|
2004-10-26 21:39:34 +00:00
|
|
|
("\\.CC\\'" (".HH" ".H" ".hh" ".h"))
|
|
|
|
("\\.HH\\'" (".CC"))
|
1995-01-20 06:04:56 +00:00
|
|
|
|
2004-10-26 21:39:34 +00:00
|
|
|
("\\.c\\+\\+\\'" (".h++" ".hh" ".h"))
|
|
|
|
("\\.h\\+\\+\\'" (".c++"))
|
|
|
|
|
|
|
|
("\\.cpp\\'" (".hpp" ".hh" ".h"))
|
|
|
|
("\\.hpp\\'" (".cpp"))
|
|
|
|
|
|
|
|
("\\.cxx\\'" (".hxx" ".hh" ".h"))
|
|
|
|
("\\.hxx\\'" (".cxx")))
|
* find-file.el (ff-get-file): Doc fix.
(ff-get-file-name): Use `let', not `let*'.
(ff-search-directories): Fix typo in docstring.
(ff-pre-find-hook, ff-pre-load-hook, ff-post-load-hook)
(ff-not-found-hook, ff-file-created-hook, ff-case-fold-search)
(ff-always-in-other-window, ff-ignore-include, ff-always-try-to-create)
(ff-quiet-mode, ff-other-file-alist, cc-search-directories)
(cc-other-file-alist, modula2-other-file-alist):
Remove spurious * in docstrings.
2008-10-15 15:32:21 +00:00
|
|
|
"Alist of extensions to find given the current file's extension.
|
1995-01-20 06:04:56 +00:00
|
|
|
|
|
|
|
This list should contain the most used extensions before the others,
|
|
|
|
since the search algorithm searches sequentially through each directory
|
1995-04-07 21:51:51 +00:00
|
|
|
specified in `ff-search-directories'. If a file is not found, a new one
|
1998-03-07 15:27:01 +00:00
|
|
|
is created with the first matching extension (`.cc' yields `.hh')."
|
2013-05-06 15:46:31 +00:00
|
|
|
:version "24.4" ; add .m
|
2021-04-06 20:28:50 +00:00
|
|
|
:type '(repeat (list regexp (choice (repeat string) function))))
|
1995-01-20 06:04:56 +00:00
|
|
|
|
1998-03-07 15:27:01 +00:00
|
|
|
(defcustom modula2-other-file-alist
|
1995-01-20 06:04:56 +00:00
|
|
|
'(
|
2021-04-06 20:28:50 +00:00
|
|
|
("\\.mi\\'" (".md")) ;; Modula-2 module definition
|
|
|
|
("\\.md\\'" (".mi")) ;; and implementation.
|
1995-01-20 06:04:56 +00:00
|
|
|
)
|
* find-file.el (ff-get-file): Doc fix.
(ff-get-file-name): Use `let', not `let*'.
(ff-search-directories): Fix typo in docstring.
(ff-pre-find-hook, ff-pre-load-hook, ff-post-load-hook)
(ff-not-found-hook, ff-file-created-hook, ff-case-fold-search)
(ff-always-in-other-window, ff-ignore-include, ff-always-try-to-create)
(ff-quiet-mode, ff-other-file-alist, cc-search-directories)
(cc-other-file-alist, modula2-other-file-alist):
Remove spurious * in docstrings.
2008-10-15 15:32:21 +00:00
|
|
|
"See the description for the `ff-search-directories' variable."
|
2021-04-06 20:28:50 +00:00
|
|
|
:type '(repeat (list regexp (choice (repeat string) function))))
|
1998-03-07 15:27:01 +00:00
|
|
|
|
1995-01-20 06:04:56 +00:00
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; No user definable variables beyond this point!
|
|
|
|
;; ==============================================
|
|
|
|
|
2002-09-09 22:45:09 +00:00
|
|
|
(make-variable-buffer-local 'ff-pre-find-hook)
|
|
|
|
(make-variable-buffer-local 'ff-pre-load-hook)
|
|
|
|
(make-variable-buffer-local 'ff-post-load-hook)
|
|
|
|
(make-variable-buffer-local 'ff-not-found-hook)
|
|
|
|
(make-variable-buffer-local 'ff-file-created-hook)
|
1995-01-20 06:04:56 +00:00
|
|
|
(make-variable-buffer-local 'ff-case-fold-search)
|
|
|
|
(make-variable-buffer-local 'ff-always-in-other-window)
|
|
|
|
(make-variable-buffer-local 'ff-ignore-include)
|
|
|
|
(make-variable-buffer-local 'ff-quiet-mode)
|
|
|
|
(make-variable-buffer-local 'ff-other-file-alist)
|
|
|
|
(make-variable-buffer-local 'ff-search-directories)
|
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; User entry points
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun ff-get-other-file (&optional in-other-window)
|
1995-04-07 21:51:51 +00:00
|
|
|
"Find the header or source file corresponding to this file.
|
2000-08-15 14:18:18 +00:00
|
|
|
See also the documentation for `ff-find-other-file'.
|
1995-01-20 06:04:56 +00:00
|
|
|
|
1995-04-07 21:51:51 +00:00
|
|
|
If optional IN-OTHER-WINDOW is non-nil, find the file in another window."
|
1995-01-20 06:04:56 +00:00
|
|
|
(interactive "P")
|
2021-04-06 20:28:50 +00:00
|
|
|
(let ((ff-ignore-include t))
|
|
|
|
(ff-find-the-other-file in-other-window)))
|
1995-01-20 06:04:56 +00:00
|
|
|
|
2002-10-26 22:35:16 +00:00
|
|
|
;;;###autoload
|
2021-04-06 20:28:50 +00:00
|
|
|
(defalias 'ff-find-related-file #'ff-find-other-file)
|
2002-10-14 01:25:16 +00:00
|
|
|
|
1995-01-20 06:04:56 +00:00
|
|
|
;;;###autoload
|
2021-04-06 21:06:07 +00:00
|
|
|
(defun ff-find-other-file (&optional in-other-window ignore-include event)
|
1995-04-07 21:51:51 +00:00
|
|
|
"Find the header or source file corresponding to this file.
|
|
|
|
Being on a `#include' line pulls in that file.
|
1995-01-20 06:04:56 +00:00
|
|
|
|
1995-04-07 21:51:51 +00:00
|
|
|
If optional IN-OTHER-WINDOW is non-nil, find the file in the other window.
|
|
|
|
If optional IGNORE-INCLUDE is non-nil, ignore being on `#include' lines.
|
1995-01-20 06:04:56 +00:00
|
|
|
|
2021-05-25 20:26:42 +00:00
|
|
|
If optional EVENT is non-nil (default `last-nonmenu-event', move
|
|
|
|
point to the end position of that event before calling the
|
|
|
|
various ff-* hooks.
|
|
|
|
|
1995-01-20 06:04:56 +00:00
|
|
|
Variables of interest include:
|
|
|
|
|
2000-08-15 14:18:18 +00:00
|
|
|
- `ff-case-fold-search'
|
|
|
|
Non-nil means ignore cases in matches (see `case-fold-search').
|
1995-01-20 06:04:56 +00:00
|
|
|
If you have extensions in different cases, you will want this to be nil.
|
|
|
|
|
2000-08-15 14:18:18 +00:00
|
|
|
- `ff-always-in-other-window'
|
1995-01-20 06:04:56 +00:00
|
|
|
If non-nil, always open the other file in another window, unless an
|
2000-08-15 14:18:18 +00:00
|
|
|
argument is given to `ff-find-other-file'.
|
1995-01-20 06:04:56 +00:00
|
|
|
|
2000-08-15 14:18:18 +00:00
|
|
|
- `ff-ignore-include'
|
1995-01-20 06:04:56 +00:00
|
|
|
If non-nil, ignores #include lines.
|
|
|
|
|
2000-08-15 14:18:18 +00:00
|
|
|
- `ff-always-try-to-create'
|
1995-01-20 06:04:56 +00:00
|
|
|
If non-nil, always attempt to create the other file if it was not found.
|
|
|
|
|
2000-08-15 14:18:18 +00:00
|
|
|
- `ff-quiet-mode'
|
2023-04-10 12:49:32 +00:00
|
|
|
If non-nil, does not trace which directories are being searched.
|
1995-01-20 06:04:56 +00:00
|
|
|
|
2000-08-15 14:18:18 +00:00
|
|
|
- `ff-special-constructs'
|
2005-06-16 16:09:00 +00:00
|
|
|
A list of regular expressions specifying how to recognize special
|
2000-08-15 14:18:18 +00:00
|
|
|
constructs such as include files etc, and an associated method for
|
1995-01-20 06:04:56 +00:00
|
|
|
extracting the filename from that construct.
|
|
|
|
|
2000-08-15 14:18:18 +00:00
|
|
|
- `ff-other-file-alist'
|
1995-01-20 06:04:56 +00:00
|
|
|
Alist of extensions to find given the current file's extension.
|
|
|
|
|
2000-08-15 14:18:18 +00:00
|
|
|
- `ff-search-directories'
|
1995-01-20 06:04:56 +00:00
|
|
|
List of directories searched through with each extension specified in
|
2000-08-15 14:18:18 +00:00
|
|
|
`ff-other-file-alist' that matches this file's extension.
|
1995-01-20 06:04:56 +00:00
|
|
|
|
2002-09-09 22:45:09 +00:00
|
|
|
- `ff-pre-find-hook'
|
1995-01-20 06:04:56 +00:00
|
|
|
List of functions to be called before the search for the file starts.
|
|
|
|
|
2002-09-09 22:45:09 +00:00
|
|
|
- `ff-pre-load-hook'
|
1995-01-20 06:04:56 +00:00
|
|
|
List of functions to be called before the other file is loaded.
|
|
|
|
|
2002-09-09 22:45:09 +00:00
|
|
|
- `ff-post-load-hook'
|
1995-01-20 06:04:56 +00:00
|
|
|
List of functions to be called after the other file is loaded.
|
|
|
|
|
2002-09-09 22:45:09 +00:00
|
|
|
- `ff-not-found-hook'
|
1995-01-20 06:04:56 +00:00
|
|
|
List of functions to be called if the other file could not be found.
|
|
|
|
|
2002-09-09 22:45:09 +00:00
|
|
|
- `ff-file-created-hook'
|
1995-01-20 06:04:56 +00:00
|
|
|
List of functions to be called if the other file has been created."
|
2021-04-06 21:06:07 +00:00
|
|
|
(interactive (list current-prefix-arg nil last-nonmenu-event))
|
2021-05-25 20:26:42 +00:00
|
|
|
;; We want to preserve point in the current buffer. But the point of
|
2021-09-24 12:18:57 +00:00
|
|
|
;; ff-find-the-other-file is to make the other file buffer
|
2021-05-25 20:26:42 +00:00
|
|
|
;; current, so we can't use save-excursion here (see bug 48535).
|
|
|
|
(let ((start-buffer (current-buffer))
|
|
|
|
(start-point (point)))
|
2021-04-06 21:06:07 +00:00
|
|
|
(posn-set-point (event-end event))
|
|
|
|
(let ((ff-ignore-include ignore-include))
|
2021-05-25 20:26:42 +00:00
|
|
|
(ff-find-the-other-file in-other-window))
|
|
|
|
(with-current-buffer start-buffer
|
|
|
|
(goto-char start-point))))
|
1995-01-20 06:04:56 +00:00
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; Support functions
|
|
|
|
|
2016-02-24 03:01:50 +00:00
|
|
|
(defun ff-buffer-file-name (&optional buf)
|
|
|
|
"Like `buffer-file-name' but works with indirect buffers as well.
|
|
|
|
If BUF is nil, uses the current buffer."
|
|
|
|
(unless buf
|
|
|
|
(setq buf (current-buffer)))
|
|
|
|
(or (buffer-file-name buf)
|
|
|
|
(when (buffer-base-buffer buf)
|
|
|
|
(buffer-file-name (buffer-base-buffer buf)))))
|
|
|
|
|
1995-01-20 06:04:56 +00:00
|
|
|
(defun ff-find-the-other-file (&optional in-other-window)
|
1995-04-07 21:51:51 +00:00
|
|
|
"Find the header or source file corresponding to the current file.
|
|
|
|
Being on a `#include' line pulls in that file, but see the help on
|
|
|
|
the `ff-ignore-include' variable.
|
1995-01-20 06:04:56 +00:00
|
|
|
|
1995-04-07 21:51:51 +00:00
|
|
|
If optional IN-OTHER-WINDOW is non-nil, find the file in another window."
|
1995-01-20 06:04:56 +00:00
|
|
|
|
|
|
|
(let (match ;; matching regexp for this file
|
|
|
|
suffixes ;; set of replacing regexps for the matching regexp
|
|
|
|
action ;; function to generate the names of the other files
|
|
|
|
fname ;; basename of this file
|
|
|
|
pos ;; where we start matching filenames
|
|
|
|
stub ;; name of the file without extension
|
|
|
|
alist ;; working copy of the list of file extensions
|
|
|
|
pathname ;; the pathname of the file or the #include line
|
|
|
|
default-name ;; file we should create if none found
|
2000-08-15 14:18:18 +00:00
|
|
|
format ;; what we have to match
|
|
|
|
found ;; name of the file or buffer found - nil if none
|
1995-01-20 06:04:56 +00:00
|
|
|
dirs ;; local value of ff-search-directories
|
|
|
|
no-match) ;; whether we know about this kind of file
|
|
|
|
|
2002-09-09 22:45:09 +00:00
|
|
|
(run-hooks 'ff-pre-find-hook 'ff-pre-find-hooks)
|
1995-01-20 06:04:56 +00:00
|
|
|
|
|
|
|
(message "Working...")
|
|
|
|
|
|
|
|
(setq dirs
|
2021-04-06 20:28:50 +00:00
|
|
|
(ff-list-replace-env-vars (if (symbolp ff-search-directories)
|
|
|
|
(symbol-value ff-search-directories)
|
|
|
|
ff-search-directories)))
|
1995-01-20 06:04:56 +00:00
|
|
|
|
2006-07-16 21:08:28 +00:00
|
|
|
(setq fname (ff-treat-as-special))
|
1995-01-20 06:04:56 +00:00
|
|
|
|
|
|
|
(cond
|
|
|
|
((and (not ff-ignore-include) fname)
|
|
|
|
(setq default-name fname)
|
|
|
|
(setq found (ff-get-file dirs fname nil in-other-window)))
|
|
|
|
|
|
|
|
;; let's just get the corresponding file
|
|
|
|
(t
|
|
|
|
(setq alist (if (symbolp ff-other-file-alist)
|
|
|
|
(symbol-value ff-other-file-alist)
|
|
|
|
ff-other-file-alist)
|
2016-02-24 03:01:50 +00:00
|
|
|
pathname (or (ff-buffer-file-name) "/none.none"))
|
1995-01-20 06:04:56 +00:00
|
|
|
|
2001-07-03 13:02:55 +00:00
|
|
|
(setq fname (file-name-nondirectory pathname)
|
1995-01-20 06:04:56 +00:00
|
|
|
no-match nil
|
|
|
|
match (car alist))
|
|
|
|
|
|
|
|
;; find the table entry corresponding to this file
|
|
|
|
(setq pos (ff-string-match (car match) fname))
|
|
|
|
(while (and match (if (and pos (>= pos 0)) nil (not pos)))
|
|
|
|
(setq alist (cdr alist))
|
|
|
|
(setq match (car alist))
|
|
|
|
(setq pos (ff-string-match (car match) fname)))
|
|
|
|
|
|
|
|
;; no point going on if we haven't found anything
|
|
|
|
(if (not match)
|
|
|
|
(setq no-match t)
|
|
|
|
|
|
|
|
;; otherwise, suffixes contains what we need
|
|
|
|
(setq suffixes (car (cdr match))
|
|
|
|
action (car (cdr match))
|
|
|
|
found nil)
|
|
|
|
|
2000-08-15 14:18:18 +00:00
|
|
|
;; if we have a function to generate new names,
|
1995-01-20 06:04:56 +00:00
|
|
|
;; invoke it with the name of the current file
|
|
|
|
(if (and (atom action) (fboundp action))
|
2021-04-06 20:28:50 +00:00
|
|
|
(setq suffixes (funcall action (ff-buffer-file-name))
|
|
|
|
match (cons (car match) (list suffixes))
|
|
|
|
stub nil
|
|
|
|
default-name (car suffixes))
|
1995-01-20 06:04:56 +00:00
|
|
|
|
|
|
|
;; otherwise build our filename stub
|
2000-08-15 14:18:18 +00:00
|
|
|
(cond
|
1995-01-20 06:04:56 +00:00
|
|
|
|
|
|
|
;; get around the problem that 0 and nil both mean false!
|
|
|
|
((= pos 0)
|
|
|
|
(setq format "")
|
|
|
|
(setq stub "")
|
|
|
|
)
|
|
|
|
|
|
|
|
(t
|
|
|
|
(setq format (concat "\\(.+\\)" (car match)))
|
|
|
|
(string-match format fname)
|
2021-04-06 20:28:50 +00:00
|
|
|
;; FIXME: What if `string-match' failed?
|
|
|
|
(setq stub (match-string 1 fname))
|
1995-01-20 06:04:56 +00:00
|
|
|
))
|
|
|
|
|
|
|
|
;; if we find nothing, we should try to get a file like this one
|
|
|
|
(setq default-name
|
|
|
|
(concat stub (car (car (cdr match))))))
|
|
|
|
|
|
|
|
;; do the real work - find the file
|
2000-08-15 14:18:18 +00:00
|
|
|
(setq found
|
1995-01-20 06:04:56 +00:00
|
|
|
(ff-get-file dirs
|
|
|
|
stub
|
2000-08-15 14:18:18 +00:00
|
|
|
suffixes
|
1995-01-20 06:04:56 +00:00
|
|
|
in-other-window)))))
|
|
|
|
|
|
|
|
(cond
|
|
|
|
(no-match ;; could not even determine the other file
|
|
|
|
(message ""))
|
|
|
|
|
2000-08-15 14:18:18 +00:00
|
|
|
(t
|
1995-01-20 06:04:56 +00:00
|
|
|
(cond
|
|
|
|
|
|
|
|
((not found) ;; could not find the other file
|
|
|
|
|
2002-09-09 22:45:09 +00:00
|
|
|
(run-hooks 'ff-not-found-hook 'ff-not-found-hooks)
|
1995-01-20 06:04:56 +00:00
|
|
|
|
2000-08-15 14:18:18 +00:00
|
|
|
(cond
|
1995-01-20 06:04:56 +00:00
|
|
|
(ff-always-try-to-create ;; try to create the file
|
|
|
|
(let (name pathname)
|
|
|
|
|
|
|
|
(setq name
|
|
|
|
(expand-file-name
|
2011-03-05 21:56:00 +00:00
|
|
|
(read-directory-name
|
1995-01-20 06:04:56 +00:00
|
|
|
(format "Find or create %s in: " default-name)
|
|
|
|
default-directory default-name nil)))
|
2003-02-04 11:26:42 +00:00
|
|
|
|
1995-01-20 06:04:56 +00:00
|
|
|
(setq pathname
|
|
|
|
(if (file-directory-p name)
|
|
|
|
(concat (file-name-as-directory name) default-name)
|
|
|
|
(setq found name)))
|
2003-02-04 11:26:42 +00:00
|
|
|
|
1995-01-20 06:04:56 +00:00
|
|
|
(ff-find-file pathname in-other-window t)))
|
|
|
|
|
|
|
|
(t ;; don't create the file, just whinge
|
1997-04-23 23:34:20 +00:00
|
|
|
(message "No file found for %s" fname))))
|
1995-01-20 06:04:56 +00:00
|
|
|
|
|
|
|
(t ;; matching file found
|
|
|
|
nil))))
|
|
|
|
|
|
|
|
found)) ;; return buffer-name or filename
|
|
|
|
|
2000-08-15 14:18:18 +00:00
|
|
|
(defun ff-get-file (search-dirs filename &optional suffix-list other-window)
|
|
|
|
"Find a file in the SEARCH-DIRS with the given FILENAME (or filename stub).
|
* find-file.el (ff-get-file): Doc fix.
(ff-get-file-name): Use `let', not `let*'.
(ff-search-directories): Fix typo in docstring.
(ff-pre-find-hook, ff-pre-load-hook, ff-post-load-hook)
(ff-not-found-hook, ff-file-created-hook, ff-case-fold-search)
(ff-always-in-other-window, ff-ignore-include, ff-always-try-to-create)
(ff-quiet-mode, ff-other-file-alist, cc-search-directories)
(cc-other-file-alist, modula2-other-file-alist):
Remove spurious * in docstrings.
2008-10-15 15:32:21 +00:00
|
|
|
If (optional) SUFFIX-LIST is nil, search for FILENAME, otherwise search
|
|
|
|
for FILENAME with each of the given suffixes. Get the file or the buffer
|
2000-08-15 14:18:18 +00:00
|
|
|
corresponding to the name of the first file found, or nil."
|
|
|
|
(let ((filename (ff-get-file-name search-dirs filename suffix-list)))
|
2003-02-04 11:26:42 +00:00
|
|
|
|
2000-08-15 14:18:18 +00:00
|
|
|
(cond
|
1995-01-20 06:04:56 +00:00
|
|
|
((not filename)
|
|
|
|
nil)
|
|
|
|
|
1995-12-31 00:10:18 +00:00
|
|
|
((bufferp (get-file-buffer filename))
|
|
|
|
(ff-switch-to-buffer (get-file-buffer filename) other-window)
|
1995-01-20 06:04:56 +00:00
|
|
|
filename)
|
2003-02-04 11:26:42 +00:00
|
|
|
|
1995-01-20 06:04:56 +00:00
|
|
|
((file-exists-p filename)
|
|
|
|
(ff-find-file filename other-window nil)
|
|
|
|
filename)
|
|
|
|
|
|
|
|
(t
|
|
|
|
nil))))
|
|
|
|
|
|
|
|
(defun ff-get-file-name (search-dirs fname-stub &optional suffix-list)
|
2000-08-15 14:18:18 +00:00
|
|
|
"Find a file in SEARCH-DIRS with the given name (or stub) FNAME-STUB.
|
|
|
|
If (optional) SUFFIX-LIST is nil, search for FNAME-STUB, otherwise
|
|
|
|
search for FNAME-STUB with each of the given suffixes. Return the
|
|
|
|
name of the first file found."
|
* find-file.el (ff-get-file): Doc fix.
(ff-get-file-name): Use `let', not `let*'.
(ff-search-directories): Fix typo in docstring.
(ff-pre-find-hook, ff-pre-load-hook, ff-post-load-hook)
(ff-not-found-hook, ff-file-created-hook, ff-case-fold-search)
(ff-always-in-other-window, ff-ignore-include, ff-always-try-to-create)
(ff-quiet-mode, ff-other-file-alist, cc-search-directories)
(cc-other-file-alist, modula2-other-file-alist):
Remove spurious * in docstrings.
2008-10-15 15:32:21 +00:00
|
|
|
(let (dirs ;; working copy of dirs to search
|
|
|
|
dir ;; the current dir considered
|
|
|
|
file ;; filename being looked for
|
|
|
|
rest ;; pathname after first /*
|
|
|
|
this-suffix ;; the suffix we are currently considering
|
|
|
|
suffixes ;; working copy of suffix-list
|
|
|
|
filename ;; built filename
|
|
|
|
blist ;; list of live buffers
|
|
|
|
buf ;; current buffer in blist
|
|
|
|
found) ;; whether we have found anything
|
1995-01-20 06:04:56 +00:00
|
|
|
|
|
|
|
(setq suffixes suffix-list)
|
|
|
|
|
|
|
|
;; suffixes is nil => fname-stub is the file we are looking for
|
|
|
|
;; otherwise fname-stub is a stub, and we append a suffix
|
|
|
|
(if suffixes
|
|
|
|
(setq this-suffix (car suffixes))
|
|
|
|
(setq this-suffix "")
|
|
|
|
(setq suffixes (list "")))
|
2003-02-04 11:26:42 +00:00
|
|
|
|
1995-01-20 06:04:56 +00:00
|
|
|
;; find whether the file is in a buffer first
|
|
|
|
(while (and suffixes (not found))
|
|
|
|
(setq filename (concat fname-stub this-suffix))
|
|
|
|
|
|
|
|
(if (not ff-quiet-mode)
|
1997-04-23 23:34:20 +00:00
|
|
|
(message "Finding buffer %s..." filename))
|
1995-01-20 06:04:56 +00:00
|
|
|
|
1997-04-23 23:34:20 +00:00
|
|
|
(if (bufferp (get-file-buffer filename))
|
2016-02-24 03:01:50 +00:00
|
|
|
(setq found (ff-buffer-file-name (get-file-buffer filename))))
|
1995-01-20 06:04:56 +00:00
|
|
|
|
|
|
|
(setq blist (buffer-list))
|
|
|
|
(setq buf (buffer-name (car blist)))
|
|
|
|
(while (and blist (not found))
|
|
|
|
|
lisp/*.el: Remove lexical-binding warnings; additional small cleanups.
* calculator.el (calculator): Mark unused argument.
(calculator-paste, calculator-quit, calculator-integer-p):
Use ignore-errors.
(calculator-string-to-number, calculator-decimal, calculator-exp)
(calculator-op-or-exp): Use string-match-p.
* dired-aux.el (dired-compress): Use ignore-errors.
(dired-do-chxxx, dired-do-chmod, dired-trample-file-versions)
(dired-do-async-shell-command, dired-do-shell-command)
(dired-shell-stuff-it, dired-compress-file, dired-insert-subdir)
(dired-insert-subdir-validate): Use string-match-p.
(dired-map-dired-file-lines, dired-subdir-hidden-p): Use looking-at-p.
(dired-add-entry): Use string-match-p, looking-at-p.
(dired-insert-subdir-newpos): Remove unused local variable.
* dired.el (dired-buffer-more-recently-used-p): Declare.
(dired-insert-set-properties, dired-insert-old-subdirs):
Use ignore-errors.
* filenotify.el (file-notify-callback): Remove unused local variable.
* filesets.el (filesets-error): Mark unused argument.
(filesets-which-command-p, filesets-filter-dir-names)
(filesets-directory-files, filesets-get-external-viewer)
(filesets-ingroup-get-data): Use string-match-p.
* find-file.el (ff-other-file-name, ff-other-file-name)
(ff-find-the-other-file, ff-cc-hh-converter):
Remove unused local variables.
(ff-get-file-name): Use string-match-p.
(ff-all-dirs-under): Use ignore-errors.
* follow.el (follow-comint-scroll-to-bottom): Mark unused argument.
(follow-select-if-visible): Remove unused local variable.
* forms.el (read-file-filter): Move declaration.
(forms--make-format, forms--make-parser, forms-insert-record):
Quote function with #'.
(forms--update): Use string-match-p. Quote function with #'.
* help-mode.el (help-dir-local-var-def): Mark unused argument.
(help-make-xrefs): Use looking-at-p.
(help-xref-on-pp): Use looking-at-p, ignore-errors.
* ibuffer.el (ibuffer-ext-visible-p): Declare.
(ibuffer-confirm-operation-on): Use string-match-p.
* msb.el (msb-item-handler, msb-dired-item-handler):
Mark unused arguments.
* ses.el (ses-decode-cell-symbol)
(ses-kill-override): Remove unused local variable.
(ses-create-cell-variable, ses-relocate-formula): Use string-match-p.
(ses-load): Use ignore-errors, looking-at-p.
(ses-jump-safe): Use ignore-errors.
(ses-export-tsv, ses-export-tsf, ses-unsafe): Mark unused arguments.
* tabify.el (untabify, tabify): Mark unused arguments.
* thingatpt.el (thing-at-point--bounds-of-well-formed-url):
Mark unused argument.
(bounds-of-thing-at-point, thing-at-point-bounds-of-list-at-point)
(thing-at-point-newsgroup-p, form-at-point): Use ignore-errors.
2013-08-10 15:17:29 +00:00
|
|
|
(if (string-match-p (concat filename "<[0-9]+>") buf)
|
2016-02-24 03:01:50 +00:00
|
|
|
(setq found (ff-buffer-file-name (car blist))))
|
1995-01-20 06:04:56 +00:00
|
|
|
|
|
|
|
(setq blist (cdr blist))
|
|
|
|
(setq buf (buffer-name (car blist))))
|
|
|
|
|
|
|
|
(setq suffixes (cdr suffixes))
|
|
|
|
(setq this-suffix (car suffixes)))
|
|
|
|
|
|
|
|
;; now look for the real file
|
|
|
|
(setq dirs search-dirs)
|
|
|
|
(setq dir (car dirs))
|
|
|
|
(while (and (not found) dirs)
|
|
|
|
|
|
|
|
(setq suffixes suffix-list)
|
|
|
|
|
|
|
|
;; if dir does not contain '/*', look for the file
|
2015-09-17 23:08:20 +00:00
|
|
|
(if (and dir (not (string-match "\\([^*]*\\)/\\*\\(/.*\\)*" dir)))
|
2000-08-15 14:18:18 +00:00
|
|
|
(progn
|
2003-02-04 11:26:42 +00:00
|
|
|
|
1995-01-20 06:04:56 +00:00
|
|
|
;; suffixes is nil => fname-stub is the file we are looking for
|
|
|
|
;; otherwise fname-stub is a stub, and we append a suffix
|
|
|
|
(if suffixes
|
|
|
|
(setq this-suffix (car suffixes))
|
|
|
|
(setq this-suffix "")
|
|
|
|
(setq suffixes (list "")))
|
2003-02-04 11:26:42 +00:00
|
|
|
|
1995-01-20 06:04:56 +00:00
|
|
|
(while (and suffixes (not found))
|
|
|
|
|
|
|
|
(setq filename (concat fname-stub this-suffix))
|
2022-08-30 16:09:00 +00:00
|
|
|
(setq file (expand-file-name filename dir))
|
2003-02-04 11:26:42 +00:00
|
|
|
|
1995-01-20 06:04:56 +00:00
|
|
|
(if (not ff-quiet-mode)
|
1997-04-23 23:34:20 +00:00
|
|
|
(message "Finding %s..." file))
|
1995-01-20 06:04:56 +00:00
|
|
|
|
|
|
|
(if (file-exists-p file)
|
|
|
|
(setq found file))
|
2003-02-04 11:26:42 +00:00
|
|
|
|
1995-01-20 06:04:56 +00:00
|
|
|
(setq suffixes (cdr suffixes))
|
|
|
|
(setq this-suffix (car suffixes))))
|
|
|
|
|
|
|
|
;; otherwise dir matches the '/*', so search each dir separately
|
|
|
|
(progn
|
2021-04-06 20:28:50 +00:00
|
|
|
(setq rest (if (match-beginning 2)
|
|
|
|
(match-string 2 dir)
|
|
|
|
""))
|
|
|
|
(setq dir (match-string 1 dir))
|
1995-01-20 06:04:56 +00:00
|
|
|
|
|
|
|
(let ((dirlist (ff-all-dirs-under dir '("..")))
|
|
|
|
this-dir compl-dirs)
|
|
|
|
|
|
|
|
(setq this-dir (car dirlist))
|
|
|
|
(while dirlist
|
|
|
|
(setq compl-dirs
|
|
|
|
(append
|
|
|
|
compl-dirs
|
|
|
|
(list (concat this-dir rest))
|
|
|
|
))
|
|
|
|
(setq dirlist (cdr dirlist))
|
|
|
|
(setq this-dir (car dirlist)))
|
|
|
|
|
|
|
|
(if compl-dirs
|
|
|
|
(setq found (ff-get-file-name compl-dirs
|
|
|
|
fname-stub
|
|
|
|
suffix-list))))))
|
|
|
|
(setq dirs (cdr dirs))
|
|
|
|
(setq dir (car dirs)))
|
|
|
|
|
|
|
|
(if found
|
|
|
|
(message "%s found" found))
|
|
|
|
|
|
|
|
found))
|
|
|
|
|
|
|
|
(defun ff-string-match (regexp string &optional start)
|
1995-12-31 00:10:18 +00:00
|
|
|
"Like `string-match', but set `case-fold-search' temporarily.
|
1995-04-07 21:51:51 +00:00
|
|
|
The value used comes from `ff-case-fold-search'."
|
2021-04-06 20:28:50 +00:00
|
|
|
(if regexp
|
|
|
|
(let ((case-fold-search ff-case-fold-search))
|
1995-04-07 21:51:51 +00:00
|
|
|
(string-match regexp string start))))
|
1995-01-20 06:04:56 +00:00
|
|
|
|
|
|
|
(defun ff-list-replace-env-vars (search-list)
|
|
|
|
"Replace environment variables (of the form $VARIABLE) in SEARCH-LIST."
|
|
|
|
(let (list
|
|
|
|
(var (car search-list)))
|
|
|
|
(while search-list
|
2021-04-06 20:28:50 +00:00
|
|
|
(if (string-match "\\(.*\\)\\$[({]*\\([[:alnum:]_]+\\)[)}]*\\(.*\\)" var)
|
1995-01-20 06:04:56 +00:00
|
|
|
(setq var
|
|
|
|
(concat
|
2021-04-06 20:28:50 +00:00
|
|
|
(match-string 1 var)
|
|
|
|
(getenv (match-string 2 var))
|
|
|
|
(match-string 3 var))))
|
1995-01-20 06:04:56 +00:00
|
|
|
(setq search-list (cdr search-list))
|
|
|
|
(setq list (cons var list))
|
|
|
|
(setq var (car search-list)))
|
|
|
|
(setq search-list (reverse list))))
|
|
|
|
|
|
|
|
(defun ff-treat-as-special ()
|
2000-08-15 14:18:18 +00:00
|
|
|
"Return the file to look for if the construct was special, else nil.
|
2006-07-16 21:08:28 +00:00
|
|
|
See variable `ff-special-constructs'."
|
|
|
|
(save-excursion
|
|
|
|
(beginning-of-line 1)
|
|
|
|
(let* (fname
|
|
|
|
(list ff-special-constructs)
|
|
|
|
(elem (car list))
|
|
|
|
(regexp (car elem))
|
|
|
|
(match (cdr elem)))
|
|
|
|
(while (and list (not fname))
|
|
|
|
(if (and (looking-at regexp) match)
|
|
|
|
(setq fname (funcall match)))
|
|
|
|
(setq list (cdr list))
|
|
|
|
(setq elem (car list))
|
|
|
|
(setq regexp (car elem))
|
|
|
|
(setq match (cdr elem)))
|
|
|
|
fname)))
|
1995-01-20 06:04:56 +00:00
|
|
|
|
2021-04-06 20:28:50 +00:00
|
|
|
(define-obsolete-function-alias 'ff-basename #'file-name-nondirectory "28.1")
|
1995-01-20 06:04:56 +00:00
|
|
|
|
|
|
|
(defun ff-all-dirs-under (here &optional exclude)
|
1995-04-07 21:51:51 +00:00
|
|
|
"Get all the directory files under directory HERE.
|
1995-01-20 06:04:56 +00:00
|
|
|
Exclude all files in the optional EXCLUDE list."
|
|
|
|
(if (file-directory-p here)
|
lisp/*.el: Remove lexical-binding warnings; additional small cleanups.
* calculator.el (calculator): Mark unused argument.
(calculator-paste, calculator-quit, calculator-integer-p):
Use ignore-errors.
(calculator-string-to-number, calculator-decimal, calculator-exp)
(calculator-op-or-exp): Use string-match-p.
* dired-aux.el (dired-compress): Use ignore-errors.
(dired-do-chxxx, dired-do-chmod, dired-trample-file-versions)
(dired-do-async-shell-command, dired-do-shell-command)
(dired-shell-stuff-it, dired-compress-file, dired-insert-subdir)
(dired-insert-subdir-validate): Use string-match-p.
(dired-map-dired-file-lines, dired-subdir-hidden-p): Use looking-at-p.
(dired-add-entry): Use string-match-p, looking-at-p.
(dired-insert-subdir-newpos): Remove unused local variable.
* dired.el (dired-buffer-more-recently-used-p): Declare.
(dired-insert-set-properties, dired-insert-old-subdirs):
Use ignore-errors.
* filenotify.el (file-notify-callback): Remove unused local variable.
* filesets.el (filesets-error): Mark unused argument.
(filesets-which-command-p, filesets-filter-dir-names)
(filesets-directory-files, filesets-get-external-viewer)
(filesets-ingroup-get-data): Use string-match-p.
* find-file.el (ff-other-file-name, ff-other-file-name)
(ff-find-the-other-file, ff-cc-hh-converter):
Remove unused local variables.
(ff-get-file-name): Use string-match-p.
(ff-all-dirs-under): Use ignore-errors.
* follow.el (follow-comint-scroll-to-bottom): Mark unused argument.
(follow-select-if-visible): Remove unused local variable.
* forms.el (read-file-filter): Move declaration.
(forms--make-format, forms--make-parser, forms-insert-record):
Quote function with #'.
(forms--update): Use string-match-p. Quote function with #'.
* help-mode.el (help-dir-local-var-def): Mark unused argument.
(help-make-xrefs): Use looking-at-p.
(help-xref-on-pp): Use looking-at-p, ignore-errors.
* ibuffer.el (ibuffer-ext-visible-p): Declare.
(ibuffer-confirm-operation-on): Use string-match-p.
* msb.el (msb-item-handler, msb-dired-item-handler):
Mark unused arguments.
* ses.el (ses-decode-cell-symbol)
(ses-kill-override): Remove unused local variable.
(ses-create-cell-variable, ses-relocate-formula): Use string-match-p.
(ses-load): Use ignore-errors, looking-at-p.
(ses-jump-safe): Use ignore-errors.
(ses-export-tsv, ses-export-tsf, ses-unsafe): Mark unused arguments.
* tabify.el (untabify, tabify): Mark unused arguments.
* thingatpt.el (thing-at-point--bounds-of-well-formed-url):
Mark unused argument.
(bounds-of-thing-at-point, thing-at-point-bounds-of-list-at-point)
(thing-at-point-newsgroup-p, form-at-point): Use ignore-errors.
2013-08-10 15:17:29 +00:00
|
|
|
(ignore-errors
|
|
|
|
(let ((files (directory-files here t))
|
|
|
|
(dirlist (list))
|
|
|
|
file)
|
|
|
|
(while files
|
|
|
|
(setq file (car files))
|
|
|
|
(if (and
|
|
|
|
(file-directory-p file)
|
2021-04-06 20:28:50 +00:00
|
|
|
(not (member (file-name-nondirectory file) exclude)))
|
lisp/*.el: Remove lexical-binding warnings; additional small cleanups.
* calculator.el (calculator): Mark unused argument.
(calculator-paste, calculator-quit, calculator-integer-p):
Use ignore-errors.
(calculator-string-to-number, calculator-decimal, calculator-exp)
(calculator-op-or-exp): Use string-match-p.
* dired-aux.el (dired-compress): Use ignore-errors.
(dired-do-chxxx, dired-do-chmod, dired-trample-file-versions)
(dired-do-async-shell-command, dired-do-shell-command)
(dired-shell-stuff-it, dired-compress-file, dired-insert-subdir)
(dired-insert-subdir-validate): Use string-match-p.
(dired-map-dired-file-lines, dired-subdir-hidden-p): Use looking-at-p.
(dired-add-entry): Use string-match-p, looking-at-p.
(dired-insert-subdir-newpos): Remove unused local variable.
* dired.el (dired-buffer-more-recently-used-p): Declare.
(dired-insert-set-properties, dired-insert-old-subdirs):
Use ignore-errors.
* filenotify.el (file-notify-callback): Remove unused local variable.
* filesets.el (filesets-error): Mark unused argument.
(filesets-which-command-p, filesets-filter-dir-names)
(filesets-directory-files, filesets-get-external-viewer)
(filesets-ingroup-get-data): Use string-match-p.
* find-file.el (ff-other-file-name, ff-other-file-name)
(ff-find-the-other-file, ff-cc-hh-converter):
Remove unused local variables.
(ff-get-file-name): Use string-match-p.
(ff-all-dirs-under): Use ignore-errors.
* follow.el (follow-comint-scroll-to-bottom): Mark unused argument.
(follow-select-if-visible): Remove unused local variable.
* forms.el (read-file-filter): Move declaration.
(forms--make-format, forms--make-parser, forms-insert-record):
Quote function with #'.
(forms--update): Use string-match-p. Quote function with #'.
* help-mode.el (help-dir-local-var-def): Mark unused argument.
(help-make-xrefs): Use looking-at-p.
(help-xref-on-pp): Use looking-at-p, ignore-errors.
* ibuffer.el (ibuffer-ext-visible-p): Declare.
(ibuffer-confirm-operation-on): Use string-match-p.
* msb.el (msb-item-handler, msb-dired-item-handler):
Mark unused arguments.
* ses.el (ses-decode-cell-symbol)
(ses-kill-override): Remove unused local variable.
(ses-create-cell-variable, ses-relocate-formula): Use string-match-p.
(ses-load): Use ignore-errors, looking-at-p.
(ses-jump-safe): Use ignore-errors.
(ses-export-tsv, ses-export-tsf, ses-unsafe): Mark unused arguments.
* tabify.el (untabify, tabify): Mark unused arguments.
* thingatpt.el (thing-at-point--bounds-of-well-formed-url):
Mark unused argument.
(bounds-of-thing-at-point, thing-at-point-bounds-of-list-at-point)
(thing-at-point-newsgroup-p, form-at-point): Use ignore-errors.
2013-08-10 15:17:29 +00:00
|
|
|
(setq dirlist (cons file dirlist)))
|
|
|
|
(setq files (cdr files)))
|
|
|
|
(setq dirlist (reverse dirlist))))
|
1995-01-20 06:04:56 +00:00
|
|
|
nil))
|
|
|
|
|
|
|
|
(defun ff-switch-file (f1 f2 file &optional in-other-window new-file)
|
1995-04-07 21:51:51 +00:00
|
|
|
"Call F1 or F2 on FILE, according to IN-OTHER-WINDOW.
|
|
|
|
In addition, this runs various hooks.
|
1995-01-20 06:04:56 +00:00
|
|
|
|
1995-04-07 21:51:51 +00:00
|
|
|
Either F1 or F2 receives FILE as the sole argument.
|
|
|
|
The decision of which one to call is based on IN-OTHER-WINDOW
|
|
|
|
and on the global variable `ff-always-in-other-window'.
|
1995-01-20 06:04:56 +00:00
|
|
|
|
1995-04-07 21:51:51 +00:00
|
|
|
F1 and F2 are typically `find-file' / `find-file-other-window'
|
|
|
|
or `switch-to-buffer' / `switch-to-buffer-other-window' function pairs.
|
|
|
|
|
2002-09-09 22:45:09 +00:00
|
|
|
If optional NEW-FILE is t, then a special hook (`ff-file-created-hook') is
|
|
|
|
called before `ff-post-load-hook'."
|
|
|
|
(run-hooks 'ff-pre-load-hook 'ff-pre-load-hooks)
|
2021-04-06 20:28:50 +00:00
|
|
|
(funcall (if (or
|
|
|
|
(and in-other-window (not ff-always-in-other-window))
|
|
|
|
(and (not in-other-window) ff-always-in-other-window))
|
|
|
|
f2 f1)
|
|
|
|
file)
|
1995-01-20 06:04:56 +00:00
|
|
|
(if new-file
|
2002-09-09 22:45:09 +00:00
|
|
|
(run-hooks 'ff-file-created-hook 'ff-file-created-hooks))
|
|
|
|
(run-hooks 'ff-post-load-hook 'ff-post-load-hooks))
|
1995-01-20 06:04:56 +00:00
|
|
|
|
|
|
|
(defun ff-find-file (file &optional in-other-window new-file)
|
1995-12-31 00:10:18 +00:00
|
|
|
"Like `find-file', but may show the file in another window."
|
2021-04-06 20:28:50 +00:00
|
|
|
(ff-switch-file #'find-file
|
|
|
|
#'find-file-other-window
|
1995-01-20 06:04:56 +00:00
|
|
|
file in-other-window new-file))
|
|
|
|
|
1995-12-31 00:10:18 +00:00
|
|
|
(defun ff-switch-to-buffer (buffer-or-name &optional in-other-window)
|
|
|
|
"Like `switch-to-buffer', but may show the buffer in another window."
|
1995-01-20 06:04:56 +00:00
|
|
|
|
2021-04-06 20:28:50 +00:00
|
|
|
(ff-switch-file #'switch-to-buffer
|
|
|
|
#'switch-to-buffer-other-window
|
1995-12-31 00:10:18 +00:00
|
|
|
buffer-or-name in-other-window nil))
|
1995-01-20 06:04:56 +00:00
|
|
|
|
1998-05-22 23:36:06 +00:00
|
|
|
;;;###autoload
|
2021-04-06 21:06:07 +00:00
|
|
|
(define-obsolete-function-alias
|
|
|
|
'ff-mouse-find-other-file #'ff-find-other-file "28.1")
|
1995-01-20 06:04:56 +00:00
|
|
|
|
1998-05-22 23:36:06 +00:00
|
|
|
;;;###autoload
|
2021-04-06 21:06:07 +00:00
|
|
|
(define-obsolete-function-alias
|
|
|
|
'ff-mouse-find-other-file-other-window #'ff-find-other-file-other-window "28.1")
|
|
|
|
;;;###autoload
|
|
|
|
(defun ff-find-other-file-other-window (event)
|
|
|
|
"Visit the file you point at in another window."
|
|
|
|
(interactive (list last-nonmenu-event))
|
|
|
|
(ff-find-other-file t nil event))
|
1995-01-20 06:04:56 +00:00
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; This section offers an example of user defined function to select files
|
|
|
|
|
2021-04-06 21:06:07 +00:00
|
|
|
(defun ff-upcase-p (string)
|
|
|
|
"Return t if STRING is all uppercase."
|
|
|
|
;; FIXME: Why `ff-string-match' since `[:upper:]' only makes
|
|
|
|
;; sense when `case-fold-search' is nil?
|
|
|
|
(ff-string-match "\\`[[:upper:]]*\\'" string))
|
1995-01-20 06:04:56 +00:00
|
|
|
|
|
|
|
(defun ff-cc-hh-converter (arg)
|
1995-04-07 21:51:51 +00:00
|
|
|
"Discriminate file extensions.
|
|
|
|
Build up a new file list based possibly on part of the directory name
|
|
|
|
and the name of the file passed in."
|
1995-01-20 06:04:56 +00:00
|
|
|
(ff-string-match "\\(.*\\)/\\([^/]+\\)/\\([^.]+\\).\\([^/]+\\)$" arg)
|
2021-04-06 20:28:50 +00:00
|
|
|
(let ((dire (match-string 2 arg))
|
|
|
|
(file (match-string 3 arg))
|
|
|
|
(extn (match-string 4 arg))
|
1995-01-20 06:04:56 +00:00
|
|
|
return-list)
|
|
|
|
(cond
|
|
|
|
;; fooZapJunk.cc => ZapJunk.{hh,h} or fooZapJunk.{hh,h}
|
2000-08-15 14:18:18 +00:00
|
|
|
((and (string= extn "cc")
|
2021-04-06 20:28:50 +00:00
|
|
|
(ff-string-match "^\\([[:lower:]]+\\)\\([[:upper:]].+\\)$" file))
|
|
|
|
(let ((stub (match-string 2 file)))
|
|
|
|
(setq dire (upcase (match-string 1 file)))
|
1995-01-20 06:04:56 +00:00
|
|
|
(setq return-list (list (concat stub ".hh")
|
|
|
|
(concat stub ".h")
|
|
|
|
(concat file ".hh")
|
|
|
|
(concat file ".h")))
|
|
|
|
))
|
|
|
|
;; FOO/ZapJunk.hh => fooZapJunk.{cc,C} or ZapJunk.{cc,C}
|
1995-04-07 21:51:51 +00:00
|
|
|
((and (string= extn "hh") (ff-upcase-p dire) file)
|
1995-01-20 06:04:56 +00:00
|
|
|
(let ((stub (concat (downcase dire) file)))
|
2000-08-15 14:18:18 +00:00
|
|
|
(setq return-list (list (concat stub ".cc")
|
1995-01-20 06:04:56 +00:00
|
|
|
(concat stub ".C")
|
|
|
|
(concat file ".cc")
|
|
|
|
(concat file ".C")))
|
|
|
|
))
|
|
|
|
;; zap.cc => zap.hh or zap.h
|
|
|
|
((string= extn "cc")
|
|
|
|
(let ((stub file))
|
|
|
|
(setq return-list (list (concat stub ".hh")
|
|
|
|
(concat stub ".h")))
|
|
|
|
))
|
|
|
|
;; zap.hh => zap.cc or zap.C
|
|
|
|
((string= extn "hh")
|
|
|
|
(let ((stub file))
|
|
|
|
(setq return-list (list (concat stub ".cc")
|
|
|
|
(concat stub ".C")))
|
|
|
|
))
|
2000-08-15 14:18:18 +00:00
|
|
|
(t
|
1995-01-20 06:04:56 +00:00
|
|
|
nil))
|
2003-02-04 11:26:42 +00:00
|
|
|
|
1995-01-20 06:04:56 +00:00
|
|
|
return-list))
|
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; This section offers an example of user defined function to place point.
|
|
|
|
;; The regexps are Ada specific.
|
|
|
|
|
|
|
|
(defvar ff-function-name nil "Name of the function we are in.")
|
|
|
|
|
2002-09-09 22:45:09 +00:00
|
|
|
;; bind with (setq ff-pre-load-hook 'ff-which-function-are-we-in)
|
1995-01-20 06:04:56 +00:00
|
|
|
;;
|
2005-08-09 02:53:00 +00:00
|
|
|
(defvar ada-procedure-start-regexp)
|
|
|
|
(defvar ada-package-start-regexp)
|
|
|
|
|
1995-01-20 06:04:56 +00:00
|
|
|
(defun ff-which-function-are-we-in ()
|
1995-04-07 21:51:51 +00:00
|
|
|
"Return the name of the function whose definition/declaration point is in.
|
|
|
|
Also remember that name in `ff-function-name'."
|
2005-07-02 19:11:52 +00:00
|
|
|
(setq ff-function-name
|
|
|
|
(save-excursion
|
|
|
|
(if (or (re-search-backward ada-procedure-start-regexp nil t)
|
|
|
|
(re-search-backward ada-package-start-regexp nil t))
|
|
|
|
(match-string 0)))))
|
1995-01-20 06:04:56 +00:00
|
|
|
|
2002-09-09 22:45:09 +00:00
|
|
|
;; bind with (setq ff-post-load-hook 'ff-set-point-accordingly)
|
1995-01-20 06:04:56 +00:00
|
|
|
;;
|
|
|
|
(defun ff-set-point-accordingly ()
|
1995-04-07 21:51:51 +00:00
|
|
|
"Find the function specified in `ff-function-name'.
|
1995-07-17 23:07:35 +00:00
|
|
|
That name was previously determined by `ff-which-function-are-we-in'."
|
1995-01-20 06:04:56 +00:00
|
|
|
(if ff-function-name
|
|
|
|
(progn
|
|
|
|
(goto-char (point-min))
|
|
|
|
(search-forward ff-function-name nil t))))
|
|
|
|
|
2000-08-15 14:18:18 +00:00
|
|
|
(provide 'find-file)
|
1995-01-20 06:04:56 +00:00
|
|
|
|
2000-08-15 14:18:18 +00:00
|
|
|
;;; find-file.el ends here
|