/[emacs]/emacs/lisp/find-file.el
ViewVC logotype

Diff of /emacs/lisp/find-file.el

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.18 by gerd, Fri Apr 26 14:40:21 2002 UTC revision 1.18.2.1 by miles, Fri Apr 4 06:20:05 2003 UTC
# Line 70  Line 70 
70  ;;          ("\\.hh$"  ff-cc-hh-converter)  ;;          ("\\.hh$"  ff-cc-hh-converter)
71  ;;          ("\\.c$"   (".h"))  ;;          ("\\.c$"   (".h"))
72  ;;          ("\\.h$"   (".c" ".cc" ".C" ".CC" ".cxx" ".cpp"))))  ;;          ("\\.h$"   (".c" ".cc" ".C" ".CC" ".cxx" ".cpp"))))
73  ;;  ;;
74  ;; ff-cc-hh-converter is included at the end of this file as a reference.  ;; ff-cc-hh-converter is included at the end of this file as a reference.
75  ;;  ;;
76  ;; SEARCHING is carried out in a set of directories specified by the  ;; SEARCHING is carried out in a set of directories specified by the
77  ;; ff-search-directories variable:  ;; ff-search-directories variable:
78  ;;  ;;
# Line 101  Line 101 
101  ;;  ;;
102  ;; THERE ARE FIVE AVAILABLE HOOKS, called in this order if non-nil:  ;; THERE ARE FIVE AVAILABLE HOOKS, called in this order if non-nil:
103  ;;  ;;
104  ;; - ff-pre-find-hooks     - called before the search for the other file starts  ;; - ff-pre-find-hook     - called before the search for the other file starts
105  ;; - ff-not-found-hooks    - called when the other file could not be found  ;; - ff-not-found-hook    - called when the other file could not be found
106  ;; - ff-pre-load-hooks     - called just before the other file is 'loaded'  ;; - ff-pre-load-hook     - called just before the other file is 'loaded'
107  ;; - ff-file-created-hooks - called when the other file is created  ;; - ff-file-created-hook - called when the other file is created
108  ;; - ff-post-load-hooks    - called just after the other file is 'loaded'  ;; - ff-post-load-hook    - called just after the other file is 'loaded'
109  ;;  ;;
110  ;; The *load-hooks allow you to place point where you want it in the other  ;; The *load-hook allow you to place point where you want it in the other
111  ;; file.  ;; file.
112    
113  ;; CREDITS:  ;; CREDITS:
# Line 130  Line 130 
130    :link '(emacs-commentary-link "find-file")    :link '(emacs-commentary-link "find-file")
131    :group 'find-file)    :group 'find-file)
132    
133  (defcustom ff-pre-find-hooks nil  (defcustom ff-pre-find-hook nil
134    "*List of functions to be called before the search for the file starts."    "*List of functions to be called before the search for the file starts."
135    :type 'hook    :type 'hook
136    :group 'ff)    :group 'ff)
137    
138  (defcustom ff-pre-load-hooks nil  (defcustom ff-pre-load-hook nil
139    "*List of functions to be called before the other file is loaded."    "*List of functions to be called before the other file is loaded."
140    :type 'hook    :type 'hook
141    :group 'ff)    :group 'ff)
142    
143  (defcustom ff-post-load-hooks nil  (defcustom ff-post-load-hook nil
144    "*List of functions to be called after the other file is loaded."    "*List of functions to be called after the other file is loaded."
145    :type 'hook    :type 'hook
146    :group 'ff)    :group 'ff)
147    
148  (defcustom ff-not-found-hooks nil  (defcustom ff-not-found-hook nil
149    "*List of functions to be called if the other file could not be found."    "*List of functions to be called if the other file could not be found."
150    :type 'hook    :type 'hook
151    :group 'ff)    :group 'ff)
152    
153  (defcustom ff-file-created-hooks nil  (defcustom ff-file-created-hook nil
154    "*List of functions to be called if the other file needs to be created."    "*List of functions to be called if the other file needs to be created."
155    :type 'hook    :type 'hook
156    :group 'ff)    :group 'ff)
# Line 202  Specifies how to recognise special const Line 202  Specifies how to recognise special const
202  etc. and an associated method for extracting the filename from that  etc. and an associated method for extracting the filename from that
203  construct.")  construct.")
204    
205    (defvaralias 'ff-related-file-alist 'ff-other-file-alist)
206  (defcustom ff-other-file-alist 'cc-other-file-alist  (defcustom ff-other-file-alist 'cc-other-file-alist
207    "*Alist of extensions to find given the current file's extension.    "*Alist of extensions to find given the current file's extension.
208    
# Line 284  is created with the first matching exten Line 285  is created with the first matching exten
285  ;; No user definable variables beyond this point!  ;; No user definable variables beyond this point!
286  ;; ==============================================  ;; ==============================================
287    
288  (make-variable-buffer-local 'ff-pre-find-hooks)  (make-variable-buffer-local 'ff-pre-find-hook)
289  (make-variable-buffer-local 'ff-pre-load-hooks)  (make-variable-buffer-local 'ff-pre-load-hook)
290  (make-variable-buffer-local 'ff-post-load-hooks)  (make-variable-buffer-local 'ff-post-load-hook)
291  (make-variable-buffer-local 'ff-not-found-hooks)  (make-variable-buffer-local 'ff-not-found-hook)
292  (make-variable-buffer-local 'ff-file-created-hooks)  (make-variable-buffer-local 'ff-file-created-hook)
293  (make-variable-buffer-local 'ff-case-fold-search)  (make-variable-buffer-local 'ff-case-fold-search)
294  (make-variable-buffer-local 'ff-always-in-other-window)  (make-variable-buffer-local 'ff-always-in-other-window)
295  (make-variable-buffer-local 'ff-ignore-include)  (make-variable-buffer-local 'ff-ignore-include)
# Line 312  If optional IN-OTHER-WINDOW is non-nil, Line 313  If optional IN-OTHER-WINDOW is non-nil,
313      (setq ff-ignore-include ignore)))      (setq ff-ignore-include ignore)))
314    
315  ;;;###autoload  ;;;###autoload
316    (defalias 'ff-find-related-file 'ff-find-other-file)
317    
318    ;;;###autoload
319  (defun ff-find-other-file (&optional in-other-window ignore-include)  (defun ff-find-other-file (&optional in-other-window ignore-include)
320    "Find the header or source file corresponding to this file.    "Find the header or source file corresponding to this file.
321  Being on a `#include' line pulls in that file.  Being on a `#include' line pulls in that file.
# Line 350  Variables of interest include: Line 354  Variables of interest include:
354     List of directories searched through with each extension specified in     List of directories searched through with each extension specified in
355     `ff-other-file-alist' that matches this file's extension.     `ff-other-file-alist' that matches this file's extension.
356    
357   - `ff-pre-find-hooks'   - `ff-pre-find-hook'
358     List of functions to be called before the search for the file starts.     List of functions to be called before the search for the file starts.
359    
360   - `ff-pre-load-hooks'   - `ff-pre-load-hook'
361     List of functions to be called before the other file is loaded.     List of functions to be called before the other file is loaded.
362    
363   - `ff-post-load-hooks'   - `ff-post-load-hook'
364     List of functions to be called after the other file is loaded.     List of functions to be called after the other file is loaded.
365    
366   - `ff-not-found-hooks'   - `ff-not-found-hook'
367     List of functions to be called if the other file could not be found.     List of functions to be called if the other file could not be found.
368    
369   - `ff-file-created-hooks'   - `ff-file-created-hook'
370     List of functions to be called if the other file has been created."     List of functions to be called if the other file has been created."
371    (interactive "P")    (interactive "P")
372    (let ((ignore ff-ignore-include))    (let ((ignore ff-ignore-include))
# Line 394  If optional IN-OTHER-WINDOW is non-nil, Line 398  If optional IN-OTHER-WINDOW is non-nil,
398          dirs            ;; local value of ff-search-directories          dirs            ;; local value of ff-search-directories
399          no-match)       ;; whether we know about this kind of file          no-match)       ;; whether we know about this kind of file
400    
401      (if ff-pre-find-hooks      (run-hooks 'ff-pre-find-hook 'ff-pre-find-hooks)
         (run-hooks 'ff-pre-find-hooks))  
402    
403      (message "Working...")      (message "Working...")
404    
# Line 486  If optional IN-OTHER-WINDOW is non-nil, Line 489  If optional IN-OTHER-WINDOW is non-nil,
489    
490         ((not found)                ;; could not find the other file         ((not found)                ;; could not find the other file
491    
492          (if ff-not-found-hooks     ;; run the hooks          (run-hooks 'ff-not-found-hook 'ff-not-found-hooks)
             (run-hooks 'ff-not-found-hooks))  
493    
494          (cond          (cond
495           (ff-always-try-to-create  ;; try to create the file           (ff-always-try-to-create  ;; try to create the file
# Line 498  If optional IN-OTHER-WINDOW is non-nil, Line 500  If optional IN-OTHER-WINDOW is non-nil,
500                     (read-file-name                     (read-file-name
501                      (format "Find or create %s in: " default-name)                      (format "Find or create %s in: " default-name)
502                      default-directory default-name nil)))                      default-directory default-name nil)))
503                
504              (setq pathname              (setq pathname
505                    (if (file-directory-p name)                    (if (file-directory-p name)
506                        (concat (file-name-as-directory name) default-name)                        (concat (file-name-as-directory name) default-name)
507                      (setq found name)))                      (setq found name)))
508                
509              (ff-find-file pathname in-other-window t)))              (ff-find-file pathname in-other-window t)))
510    
511           (t                        ;; don't create the file, just whinge           (t                        ;; don't create the file, just whinge
# Line 617  If (optional) SUFFIX-LIST is nil, search Line 619  If (optional) SUFFIX-LIST is nil, search
619  for fname with each of the given suffixes.  Get the file or the buffer  for fname with each of the given suffixes.  Get the file or the buffer
620  corresponding to the name of the first file found, or nil."  corresponding to the name of the first file found, or nil."
621    (let ((filename (ff-get-file-name search-dirs filename suffix-list)))    (let ((filename (ff-get-file-name search-dirs filename suffix-list)))
622                
623      (cond      (cond
624       ((not filename)       ((not filename)
625        nil)        nil)
# Line 625  corresponding to the name of the first f Line 627  corresponding to the name of the first f
627       ((bufferp (get-file-buffer filename))       ((bufferp (get-file-buffer filename))
628        (ff-switch-to-buffer (get-file-buffer filename) other-window)        (ff-switch-to-buffer (get-file-buffer filename) other-window)
629        filename)        filename)
630                  
631       ((file-exists-p filename)       ((file-exists-p filename)
632        (ff-find-file filename other-window nil)        (ff-find-file filename other-window nil)
633        filename)        filename)
# Line 657  name of the first file found." Line 659  name of the first file found."
659          (setq this-suffix (car suffixes))          (setq this-suffix (car suffixes))
660        (setq this-suffix "")        (setq this-suffix "")
661        (setq suffixes (list "")))        (setq suffixes (list "")))
662                
663      ;; find whether the file is in a buffer first      ;; find whether the file is in a buffer first
664      (while (and suffixes (not found))      (while (and suffixes (not found))
665        (setq filename (concat fname-stub this-suffix))        (setq filename (concat fname-stub this-suffix))
# Line 691  name of the first file found." Line 693  name of the first file found."
693        ;; if dir does not contain '/*', look for the file        ;; if dir does not contain '/*', look for the file
694        (if (and dir (not (string-match "\\([^*]*\\)/\\\*\\(/.*\\)*" dir)))        (if (and dir (not (string-match "\\([^*]*\\)/\\\*\\(/.*\\)*" dir)))
695            (progn            (progn
696                
697              ;; suffixes is nil => fname-stub is the file we are looking for              ;; suffixes is nil => fname-stub is the file we are looking for
698              ;; otherwise fname-stub is a stub, and we append a suffix              ;; otherwise fname-stub is a stub, and we append a suffix
699              (if suffixes              (if suffixes
700                  (setq this-suffix (car suffixes))                  (setq this-suffix (car suffixes))
701                (setq this-suffix "")                (setq this-suffix "")
702                (setq suffixes (list "")))                (setq suffixes (list "")))
703                
704              (while (and suffixes (not found))              (while (and suffixes (not found))
705    
706                (setq filename (concat fname-stub this-suffix))                (setq filename (concat fname-stub this-suffix))
707                (setq file (concat dir "/" filename))                (setq file (concat dir "/" filename))
708                  
709                (if (not ff-quiet-mode)                (if (not ff-quiet-mode)
710                    (message "Finding %s..." file))                    (message "Finding %s..." file))
711    
712                (if (file-exists-p file)                (if (file-exists-p file)
713                    (setq found file))                    (setq found file))
714                  
715                (setq suffixes (cdr suffixes))                (setq suffixes (cdr suffixes))
716                (setq this-suffix (car suffixes))))                (setq this-suffix (car suffixes))))
717    
# Line 823  and on the global variable `ff-always-in Line 825  and on the global variable `ff-always-in
825  F1 and F2 are typically `find-file' / `find-file-other-window'  F1 and F2 are typically `find-file' / `find-file-other-window'
826  or `switch-to-buffer' / `switch-to-buffer-other-window' function pairs.  or `switch-to-buffer' / `switch-to-buffer-other-window' function pairs.
827    
828  If optional NEW-FILE is t, then a special hook (`ff-file-created-hooks') is  If optional NEW-FILE is t, then a special hook (`ff-file-created-hook') is
829  called before `ff-post-load-hooks'."  called before `ff-post-load-hook'."
830    (if ff-pre-load-hooks    (run-hooks 'ff-pre-load-hook 'ff-pre-load-hooks)
       (run-hooks 'ff-pre-load-hooks))  
831    (if (or    (if (or
832         (and in-other-window (not ff-always-in-other-window))         (and in-other-window (not ff-always-in-other-window))
833         (and (not in-other-window) ff-always-in-other-window))         (and (not in-other-window) ff-always-in-other-window))
834        (funcall f2 file)        (funcall f2 file)
835      (funcall f1 file))      (funcall f1 file))
836    (if new-file    (if new-file
837        (if ff-file-created-hooks        (run-hooks 'ff-file-created-hook 'ff-file-created-hooks))
838            (run-hooks 'ff-file-created-hooks)))    (run-hooks 'ff-post-load-hook 'ff-post-load-hooks))
   (if ff-post-load-hooks  
       (run-hooks 'ff-post-load-hooks)))  
839    
840  (defun ff-find-file (file &optional in-other-window new-file)  (defun ff-find-file (file &optional in-other-window new-file)
841    "Like `find-file', but may show the file in another window."    "Like `find-file', but may show the file in another window."
# Line 936  and the name of the file passed in." Line 935  and the name of the file passed in."
935          ))          ))
936       (t       (t
937        nil))        nil))
938        
939      return-list))      return-list))
940    
941  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
# Line 947  and the name of the file passed in." Line 946  and the name of the file passed in."
946    
947  ;(eval-when-compile (require 'ada-mode))  ;(eval-when-compile (require 'ada-mode))
948    
949  ;; bind with (setq ff-pre-load-hooks 'ff-which-function-are-we-in)  ;; bind with (setq ff-pre-load-hook 'ff-which-function-are-we-in)
950  ;;  ;;
951  (defun ff-which-function-are-we-in ()  (defun ff-which-function-are-we-in ()
952    "Return the name of the function whose definition/declaration point is in.    "Return the name of the function whose definition/declaration point is in.
# Line 965  Also remember that name in `ff-function- Line 964  Also remember that name in `ff-function-
964                                                     (match-end 0)))                                                     (match-end 0)))
965          ))))          ))))
966    
967  ;; bind with (setq ff-post-load-hooks 'ff-set-point-accordingly)  ;; bind with (setq ff-post-load-hook 'ff-set-point-accordingly)
968  ;;  ;;
969  (defun ff-set-point-accordingly ()  (defun ff-set-point-accordingly ()
970    "Find the function specified in `ff-function-name'.    "Find the function specified in `ff-function-name'.

Legend:
Removed from v.1.18  
changed lines
  Added in v.1.18.2.1

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26