Merge from emacs--devo--0
[bpt/emacs.git] / lisp / find-file.el
index 4805d08..accf918 100644 (file)
@@ -4,13 +4,14 @@
 ;; Maintainer: FSF
 ;; Keywords: c, matching, tools
 
-;; Copyright (C) 1994, 1995, 2002, 2003 Free Software Foundation, Inc.
+;; Copyright (C) 1994, 1995, 2001, 2002, 2003, 2004,
+;;   2005, 2006, 2007 Free Software Foundation, Inc.
 
 ;; This file is part of GNU Emacs.
 
 ;; GNU Emacs is free software; you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 2, or (at your option)
+;; the Free Software Foundation; either version 3, or (at your option)
 ;; any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
@@ -20,8 +21,8 @@
 
 ;; You should have received a copy of the GNU General Public License
 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
-;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
 
 ;;; Commentary:
 
@@ -57,7 +58,7 @@
 ;; format above can be changed to include a function to be called when the
 ;; current file matches the regexp:
 ;;
-;;   '(("\\.cc$"  cc-function)
+;;   '(("\\.cc$"  cc--function)
 ;;     ("\\.hh$"  hh-function))
 ;;
 ;; These functions must return a list consisting of the possible names of the
@@ -188,12 +189,16 @@ To override this, give an argument to `ff-find-other-file'."
     ;; C/C++ include, for NeXTSTEP too
     ("^\#\\s *\\(include\\|import\\)\\s +[<\"]\\(.*\\)[>\"]" .
      (lambda ()
-       (setq fname (buffer-substring (match-beginning 2) (match-end 2)))))
+       (buffer-substring (match-beginning 2) (match-end 2))))
     )
-  "*A list of regular expressions for `ff-find-file'.
-Specifies how to recognise special constructs such as include files
-etc. and an associated method for extracting the filename from that
-construct.")
+  ;; We include `ff-treat-as-special' documentation here so that autoload
+  ;; can make it available to be read prior to loading this file.
+  "*List of special constructs for `ff-treat-as-special' to recognize.
+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
+filename that EXTRACT returned.")
 
 (defvaralias 'ff-related-file-alist 'ff-other-file-alist)
 (defcustom ff-other-file-alist 'cc-other-file-alist
@@ -215,7 +220,7 @@ Set by default to `cc-search-directories', expanded at run-time.
 
 This list is searched through with each extension specified in
 `ff-other-file-alist' that matches this file's extension.  So the
-longer the list, the longer it'll take to realise that a file
+longer the list, the longer it'll take to realize that a file
 may not exist.
 
 A typical format is
@@ -239,22 +244,26 @@ the preceding slash.  The star represents all the subdirectories except
   :group 'ff)
 
 (defcustom cc-other-file-alist
-  '(
-    ("\\.cc$"  (".hh" ".h"))
-    ("\\.hh$"  (".cc" ".C"))
+  '(("\\.cc\\'"  (".hh" ".h"))
+    ("\\.hh\\'"  (".cc" ".C"))
 
-    ("\\.c$"   (".h"))
-    ("\\.h$"   (".c" ".cc" ".C" ".CC" ".cxx" ".cpp"))
+    ("\\.c\\'"   (".h"))
+    ("\\.h\\'"   (".c" ".cc" ".C" ".CC" ".cxx" ".cpp"))
 
-    ("\\.C$"   (".H"  ".hh" ".h"))
-    ("\\.H$"   (".C"  ".CC"))
+    ("\\.C\\'"   (".H"  ".hh" ".h"))
+    ("\\.H\\'"   (".C"  ".CC"))
 
-    ("\\.CC$"  (".HH" ".H"  ".hh" ".h"))
-    ("\\.HH$"  (".CC"))
+    ("\\.CC\\'"  (".HH" ".H"  ".hh" ".h"))
+    ("\\.HH\\'"  (".CC"))
 
-    ("\\.cxx$" (".hh" ".h"))
-    ("\\.cpp$" (".hh" ".h"))
-    )
+    ("\\.c\\+\\+\\'" (".h++" ".hh" ".h"))
+    ("\\.h\\+\\+\\'" (".c++"))
+
+    ("\\.cpp\\'" (".hpp" ".hh" ".h"))
+    ("\\.hpp\\'" (".cpp"))
+
+    ("\\.cxx\\'" (".hxx" ".hh" ".h"))
+    ("\\.hxx\\'" (".cxx")))
   "*Alist of extensions to find given the current file's extension.
 
 This list should contain the most used extensions before the others,
@@ -336,7 +345,7 @@ Variables of interest include:
    If non-nil, traces which directories are being searched.
 
  - `ff-special-constructs'
-   A list of regular expressions specifying how to recognise special
+   A list of regular expressions specifying how to recognize special
    constructs such as include files etc, and an associated method for
    extracting the filename from that construct.
 
@@ -400,9 +409,7 @@ If optional IN-OTHER-WINDOW is non-nil, find the file in another window."
               (ff-list-replace-env-vars (symbol-value ff-search-directories))
             (ff-list-replace-env-vars ff-search-directories)))
 
-    (save-excursion
-      (beginning-of-line 1)
-      (setq fname (ff-treat-as-special)))
+    (setq fname (ff-treat-as-special))
 
     (cond
      ((and (not ff-ignore-include) fname)
@@ -535,9 +542,7 @@ the `ff-ignore-include' variable."
               (ff-list-replace-env-vars (symbol-value ff-search-directories))
             (ff-list-replace-env-vars ff-search-directories)))
 
-    (save-excursion
-      (beginning-of-line 1)
-      (setq fname (ff-treat-as-special)))
+    (setq fname (ff-treat-as-special))
 
     (cond
      ((and (not ff-ignore-include) fname)
@@ -766,20 +771,22 @@ The value used comes from `ff-case-fold-search'."
 
 (defun ff-treat-as-special ()
   "Return the file to look for if the construct was special, else nil.
-The construct is defined in the variable `ff-special-constructs'."
-  (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))
+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)))
 
 (defun ff-basename (string)
   "Return the basename of pathname STRING."
@@ -939,21 +946,17 @@ and the name of the file passed in."
 
 ;; bind with (setq ff-pre-load-hook 'ff-which-function-are-we-in)
 ;;
+(defvar ada-procedure-start-regexp)
+(defvar ada-package-start-regexp)
+
 (defun ff-which-function-are-we-in ()
   "Return the name of the function whose definition/declaration point is in.
 Also remember that name in `ff-function-name'."
-
-  (setq ff-function-name nil)
-
-  (save-excursion
-    (if (re-search-backward ada-procedure-start-regexp nil t)
-        (setq ff-function-name (buffer-substring (match-beginning 0)
-                                                 (match-end 0)))
-      ; we didn't find a procedure start, perhaps there is a package
-      (if (re-search-backward ada-package-start-regexp nil t)
-          (setq ff-function-name (buffer-substring (match-beginning 0)
-                                                   (match-end 0)))
-        ))))
+  (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)))))
 
 ;; bind with (setq ff-post-load-hook 'ff-set-point-accordingly)
 ;;
@@ -967,5 +970,5 @@ That name was previously determined by `ff-which-function-are-we-in'."
 
 (provide 'find-file)
 
-;;; arch-tag: 5a2fc49e-3b0a-4708-9acf-fb14e471a97a
+;; arch-tag: 5a2fc49e-3b0a-4708-9acf-fb14e471a97a
 ;;; find-file.el ends here