• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /macosx-10.9.5/emacs-92/emacs/lisp/

Lines Matching +defs:find +defs:file +defs:other +defs:window

0 ;;; find-file.el --- find a file corresponding to this one given a pattern
10 ;; This file is part of GNU Emacs.
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
30 ;; This package features a function called ff-find-other-file, which performs
33 ;; When in a .c file, find the first corresponding .h file in a set
34 ;; of directories and display it, and vice-versa from the .h file.
36 ;; Many people maintain their include file in a directory separate to their
37 ;; src directory, and very often you may be editing a file and have a need to
38 ;; visit the "other file". This package searches through a set of directories
39 ;; to find that file.
41 ;; THE "OTHER FILE", or "corresponding file", generally has the same basename,
42 ;; and just has a different extension as described by the ff-other-file-alist
48 ;; If the current file has a .cc extension, ff-find-other-file will attempt
49 ;; to look for a .hh file, and then a .h file in some directory as described
53 ;; Alternatively, there are situations where the filename of the other file
54 ;; cannot be determined easily with regexps. For example, a .c file may
56 ;; the filename for the .c file contains part of the pathname of the .h
57 ;; file, as between src/fooZap.cc and include/FOO/zap.hh. In that case, the
59 ;; current file matches the regexp:
65 ;; corresponding file, with or without path. There is no real need for more
66 ;; than one function, and one could imagine the following value for cc-other-
67 ;; file-alist:
69 ;; (setq cc-other-file-alist
75 ;; ff-cc-hh-converter is included at the end of this file as a reference.
82 ;; This means that the corresponding file will be searched for first in
89 ;; If the point is on a #include line, the file to be #included is searched
91 ;; variable, or by calling ff-get-other-file instead of ff-find-other-file.
93 ;; If the file was not found, ff-find-other-file will prompt you for where
94 ;; to create the new "corresponding file" (defaults to the current directory),
97 ;; GIVEN AN ARGUMENT (with the ^U prefix), ff-find-other-file will get the
98 ;; other file in another (the other?) window (see find-file-other-window and
99 ;; switch-to-buffer-other-window). This can be set on a more permanent basis
100 ;; by setting ff-always-in-other-window to t in which case the ^U prefix will
105 ;; - ff-pre-find-hook - called before the search for the other file starts
106 ;; - ff-not-found-hook - called when the other file could not be found
107 ;; - ff-pre-load-hook - called just before the other file is 'loaded'
108 ;; - ff-file-created-hook - called when the other file is created
109 ;; - ff-post-load-hook - called just after the other file is 'loaded'
111 ;; The *load-hook allow you to place point where you want it in the other
112 ;; file.
129 "Find a file corresponding to this one given a pattern."
131 :link '(emacs-commentary-link "find-file")
132 :group 'find-file)
134 (defcustom ff-pre-find-hook nil
135 "*List of functions to be called before the search for the file starts."
140 "*List of functions to be called before the other file is loaded."
145 "*List of functions to be called after the other file is loaded."
150 "*List of functions to be called if the other file could not be found."
154 (defcustom ff-file-created-hook nil
155 "*List of functions to be called if the other file needs to be created."
165 (defcustom ff-always-in-other-window nil
166 "*If non-nil, find the corresponding file in another window by default.
167 To override this, give an argument to `ff-find-other-file'."
177 "*If non-nil, always attempt to create the other file if it was not found."
195 ;; can make it available to be read prior to loading this file.
203 (defvaralias 'ff-related-file-alist 'ff-other-file-alist)
204 (defcustom ff-other-file-alist 'cc-other-file-alist
205 "*Alist of extensions to find given the current file's extension.
209 directory specified in `ff-search-directories'. If a file is not found,
217 "*List of directories to search for a specific file.
222 `ff-other-file-alist' that matches this file's extension. So the
223 longer the list, the longer it'll take to realize that a file
246 (defcustom cc-other-file-alist
267 "*Alist of extensions to find given the current file's extension.
271 specified in `ff-search-directories'. If a file is not found, a new one
276 (defcustom modula2-other-file-alist
290 (make-variable-buffer-local 'ff-pre-find-hook)
294 (make-variable-buffer-local 'ff-file-created-hook)
296 (make-variable-buffer-local 'ff-always-in-other-window)
299 (make-variable-buffer-local 'ff-other-file-alist)
306 (defun ff-get-other-file (&optional in-other-window)
307 "Find the header or source file corresponding to this file.
308 See also the documentation for `ff-find-other-file'.
310 If optional IN-OTHER-WINDOW is non-nil, find the file in another window."
314 (ff-find-the-other-file in-other-window)
318 (defalias 'ff-find-related-file 'ff-find-other-file)
321 (defun ff-find-other-file (&optional in-other-window ignore-include)
322 "Find the header or source file corresponding to this file.
323 Being on a `#include' line pulls in that file.
325 If optional IN-OTHER-WINDOW is non-nil, find the file in the other window.
334 - `ff-always-in-other-window'
335 If non-nil, always open the other file in another window, unless an
336 argument is given to `ff-find-other-file'.
342 If non-nil, always attempt to create the other file if it was not found.
352 - `ff-other-file-alist'
353 Alist of extensions to find given the current file's extension.
357 `ff-other-file-alist' that matches this file's extension.
359 - `ff-pre-find-hook'
360 List of functions to be called before the search for the file starts.
363 List of functions to be called before the other file is loaded.
366 List of functions to be called after the other file is loaded.
369 List of functions to be called if the other file could not be found.
371 - `ff-file-created-hook'
372 List of functions to be called if the other file has been created."
376 (ff-find-the-other-file in-other-window)
382 (defun ff-find-the-other-file (&optional in-other-window)
383 "Find the header or source file corresponding to the current file.
384 Being on a `#include' line pulls in that file, but see the help on
387 If optional IN-OTHER-WINDOW is non-nil, find the file in another window."
389 (let (match ;; matching regexp for this file
391 action ;; function to generate the names of the other files
392 fname ;; basename of this file
394 stub ;; name of the file without extension
395 alist ;; working copy of the list of file extensions
396 pathname ;; the pathname of the file or the #include line
397 default-name ;; file we should create if none found
399 found ;; name of the file or buffer found - nil if none
401 no-match) ;; whether we know about this kind of file
403 (run-hooks 'ff-pre-find-hook 'ff-pre-find-hooks)
417 (setq found (ff-get-file dirs fname nil in-other-window)))
419 ;; let's just get the corresponding file
421 (setq alist (if (symbolp ff-other-file-alist)
422 (symbol-value ff-other-file-alist)
423 ff-other-file-alist)
424 pathname (if (buffer-file-name)
425 (buffer-file-name)
428 (setq fname (file-name-nondirectory pathname)
432 ;; find the table entry corresponding to this file
449 ;; invoke it with the name of the current file
452 (setq suffixes (funcall action (buffer-file-name))
472 ;; if we find nothing, we should try to get a file like this one
476 ;; do the real work - find the file
478 (ff-get-file dirs
481 in-other-window)))))
484 (no-match ;; could not even determine the other file
490 ((not found) ;; could not find the other file
495 (ff-always-try-to-create ;; try to create the file
499 (expand-file-name
500 (read-file-name
505 (if (file-directory-p name)
506 (concat (file-name-as-directory name) default-name)
509 (ff-find-file pathname in-other-window t)))
511 (t ;; don't create the file, just whinge
512 (message "No file found for %s" fname))))
514 (t ;; matching file found
519 (defun ff-other-file-name ()
520 "Return name of the header or source file corresponding to the current file.
521 Being on a `#include' line pulls in that file, but see the help on
524 (let (match ;; matching regexp for this file
526 action ;; function to generate the names of the other files
527 fname ;; basename of this file
529 stub ;; name of the file without extension
530 alist ;; working copy of the list of file extensions
531 pathname ;; the pathname of the file or the #include line
532 default-name ;; file we should create if none found
534 found ;; name of the file or buffer found - nil if none
536 no-match) ;; whether we know about this kind of file
550 (setq found (ff-get-file-name dirs fname nil)))
552 ;; let's just get the corresponding file
554 (setq alist (if (symbolp ff-other-file-alist)
555 (symbol-value ff-other-file-alist)
556 ff-other-file-alist)
557 pathname (if (buffer-file-name)
558 (buffer-file-name)
561 (setq fname (file-name-nondirectory pathname)
565 ;; find the table entry corresponding to this file
582 ;; invoke it with the name of the current file
585 (setq suffixes (funcall action (buffer-file-name))
605 ;; if we find nothing, we should try to get a file like this one
609 ;; do the real work - find the file
611 (ff-get-file-name dirs stub suffixes)))))
614 (defun ff-get-file (search-dirs filename &optional suffix-list other-window)
615 "Find a file in the SEARCH-DIRS with the given FILENAME (or filename stub).
617 for fname with each of the given suffixes. Get the file or the buffer
618 corresponding to the name of the first file found, or nil."
619 (let ((filename (ff-get-file-name search-dirs filename suffix-list)))
625 ((bufferp (get-file-buffer filename))
626 (ff-switch-to-buffer (get-file-buffer filename) other-window)
629 ((file-exists-p filename)
630 (ff-find-file filename other-window nil)
636 (defun ff-get-file-name (search-dirs fname-stub &optional suffix-list)
637 "Find a file in SEARCH-DIRS with the given name (or stub) FNAME-STUB.
640 name of the first file found."
643 file ;; filename being looked for
654 ;; suffixes is nil => fname-stub is the file we are looking for
661 ;; find whether the file is in a buffer first
668 (if (bufferp (get-file-buffer filename))
669 (setq found (buffer-file-name (get-file-buffer filename))))
676 (setq found (buffer-file-name (car blist))))
684 ;; now look for the real file
691 ;; if dir does not contain '/*', look for the file
695 ;; suffixes is nil => fname-stub is the file we are looking for
705 (setq file (concat dir "/" filename))
708 (message "Finding %s..." file))
710 (if (file-exists-p file)
711 (setq found file))
738 (setq found (ff-get-file-name compl-dirs
773 "Return the file to look for if the construct was special, else nil.
800 (if (file-directory-p here)
805 file)
807 (setq file (car files))
809 (file-directory-p file)
810 (not (member (ff-basename file) exclude)))
811 (setq dirlist (cons file dirlist)))
817 (defun ff-switch-file (f1 f2 file &optional in-other-window new-file)
823 and on the global variable `ff-always-in-other-window'.
825 F1 and F2 are typically `find-file' / `find-file-other-window'
826 or `switch-to-buffer' / `switch-to-buffer-other-window' function pairs.
828 If optional NEW-FILE is t, then a special hook (`ff-file-created-hook') is
832 (and in-other-window (not ff-always-in-other-window))
833 (and (not in-other-window) ff-always-in-other-window))
834 (funcall f2 file)
835 (funcall f1 file))
836 (if new-file
837 (run-hooks 'ff-file-created-hook 'ff-file-created-hooks))
840 (defun ff-find-file (file &optional in-other-window new-file)
841 "Like `find-file', but may show the file in another window."
842 (ff-switch-file 'find-file
843 'find-file-other-window
844 file in-other-window new-file))
846 (defun ff-switch-to-buffer (buffer-or-name &optional in-other-window)
847 "Like `switch-to-buffer', but may show the buffer in another window."
849 (ff-switch-file 'switch-to-buffer
850 'switch-to-buffer-other-window
851 buffer-or-name in-other-window nil))
854 (defun ff-mouse-find-other-file (event)
855 "Visit the file you click on."
859 (ff-find-other-file nil)))
862 (defun ff-mouse-find-other-file-other-window (event)
863 "Visit the file you click on in another window."
867 (ff-find-other-file t)))
892 "Discriminate file extensions.
893 Build up a new file list based possibly on part of the directory name
894 and the name of the file passed in."
900 (file (if (match-beginning 3)
908 (ff-string-match "^\\([a-z]+\\)\\([A-Z].+\\)$" file))
909 (let ((stub (substring file (match-beginning 2) (match-end 2))))
910 (setq dire (upcase (substring file (match-beginning 1) (match-end 1))))
913 (concat file ".hh")
914 (concat file ".h")))
917 ((and (string= extn "hh") (ff-upcase-p dire) file)
918 (let ((stub (concat (downcase dire) file)))
921 (concat file ".cc")
922 (concat file ".C")))
926 (let ((stub file))
932 (let ((stub file))
971 (provide 'find-file)
974 ;;; find-file.el ends here