aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1998-10-16 19:20:55 +0000
committerRichard M. Stallman1998-10-16 19:20:55 +0000
commit5de148a204024e30ec19aeeac3d377fb2f098f4a (patch)
treefa460237ca00f5e4e9fdbf099a92c2b9403e5e46
parent8109154312363b497b63497b8785963cd0251cbf (diff)
downloademacs-5de148a204024e30ec19aeeac3d377fb2f098f4a.tar.gz
emacs-5de148a204024e30ec19aeeac3d377fb2f098f4a.zip
(find-file-wildcards): New option.
(find-file-noselect): Handle wild cards, if enabled. (file-expand-wildcards): New function.
-rw-r--r--lisp/files.el183
1 files changed, 101 insertions, 82 deletions
diff --git a/lisp/files.el b/lisp/files.el
index aac11fd6e32..aa0047bd937 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -860,6 +860,13 @@ If there is no such live buffer, return nil."
860 (setq list (cdr list)))) 860 (setq list (cdr list))))
861 found)))) 861 found))))
862 862
863(defcustom find-file-wildcards t
864 "*Non-nil means file-visiting commands should handle wildcards.
865For example, if you specify `*.c', that would visit all the files
866whose names match the pattern."
867 :group 'files
868 :type 'boolean)
869
863(defun find-file-noselect (filename &optional nowarn rawfile) 870(defun find-file-noselect (filename &optional nowarn rawfile)
864 "Read file FILENAME into a buffer and return the buffer. 871 "Read file FILENAME into a buffer and return the buffer.
865If a buffer exists visiting FILENAME, return that one, but 872If a buffer exists visiting FILENAME, return that one, but
@@ -876,91 +883,97 @@ Optional second arg RAWFILE non-nil means the file is read literally."
876 (abbreviate-file-name (file-truename filename)) 883 (abbreviate-file-name (file-truename filename))
877 filename)) 884 filename))
878 (error "%s is a directory" filename)) 885 (error "%s is a directory" filename))
879 (let* ((buf (get-file-buffer filename)) 886 (if (and find-file-wildcards
880 (truename (abbreviate-file-name (file-truename filename))) 887 (string-match "[[*?]" filename))
881 (number (nthcdr 10 (file-attributes truename))) 888 (let ((files (file-expand-wildcards filename t))
882 ;; Find any buffer for a file which has same truename. 889 (find-file-wildcards nil))
883 (other (and (not buf) (find-buffer-visiting filename)))) 890 (car (mapcar #'(lambda (fn) (find-file-noselect fn))
884 ;; Let user know if there is a buffer with the same truename. 891 files)))
885 (if other 892 (let* ((buf (get-file-buffer filename))
886 (progn 893 (truename (abbreviate-file-name (file-truename filename)))
887 (or nowarn 894 (number (nthcdr 10 (file-attributes truename)))
888 (string-equal filename (buffer-file-name other)) 895 ;; Find any buffer for a file which has same truename.
889 (message "%s and %s are the same file" 896 (other (and (not buf) (find-buffer-visiting filename))))
890 filename (buffer-file-name other))) 897 ;; Let user know if there is a buffer with the same truename.
891 ;; Optionally also find that buffer. 898 (if other
892 (if (or find-file-existing-other-name find-file-visit-truename) 899 (progn
893 (setq buf other)))) 900 (or nowarn
894 (if buf 901 (string-equal filename (buffer-file-name other))
895 ;; We are using an existing buffer. 902 (message "%s and %s are the same file"
896 (progn 903 filename (buffer-file-name other)))
897 (or nowarn 904 ;; Optionally also find that buffer.
898 (verify-visited-file-modtime buf) 905 (if (or find-file-existing-other-name find-file-visit-truename)
899 (cond ((not (file-exists-p filename)) 906 (setq buf other))))
900 (error "File %s no longer exists!" filename)) 907 (if buf
901 ;; Certain files should be reverted automatically 908 ;; We are using an existing buffer.
902 ;; if they have changed on disk and not in the buffer. 909 (progn
903 ((and (not (buffer-modified-p buf)) 910 (or nowarn
904 (let ((tail revert-without-query) 911 (verify-visited-file-modtime buf)
905 (found nil)) 912 (cond ((not (file-exists-p filename))
906 (while tail 913 (error "File %s no longer exists!" filename))
907 (if (string-match (car tail) filename) 914 ;; Certain files should be reverted automatically
908 (setq found t)) 915 ;; if they have changed on disk and not in the buffer.
909 (setq tail (cdr tail))) 916 ((and (not (buffer-modified-p buf))
910 found)) 917 (let ((tail revert-without-query)
911 (with-current-buffer buf 918 (found nil))
912 (message "Reverting file %s..." filename) 919 (while tail
913 (revert-buffer t t) 920 (if (string-match (car tail) filename)
914 (message "Reverting file %s...done" filename))) 921 (setq found t))
915 ((yes-or-no-p 922 (setq tail (cdr tail)))
916 (if (string= (file-name-nondirectory filename) 923 found))
917 (buffer-name buf)) 924 (with-current-buffer buf
925 (message "Reverting file %s..." filename)
926 (revert-buffer t t)
927 (message "Reverting file %s...done" filename)))
928 ((yes-or-no-p
929 (if (string= (file-name-nondirectory filename)
930 (buffer-name buf))
931 (format
932 (if (buffer-modified-p buf)
933 "File %s changed on disk. Discard your edits? "
934 "File %s changed on disk. Reread from disk? ")
935 (file-name-nondirectory filename))
918 (format 936 (format
919 (if (buffer-modified-p buf) 937 (if (buffer-modified-p buf)
920 "File %s changed on disk. Discard your edits? " 938 "File %s changed on disk. Discard your edits in %s? "
921 "File %s changed on disk. Reread from disk? ") 939 "File %s changed on disk. Reread from disk into %s? ")
922 (file-name-nondirectory filename)) 940 (file-name-nondirectory filename)
923 (format 941 (buffer-name buf))))
924 (if (buffer-modified-p buf) 942 (with-current-buffer buf
925 "File %s changed on disk. Discard your edits in %s? " 943 (revert-buffer t t)))))
926 "File %s changed on disk. Reread from disk into %s? ") 944 (with-current-buffer buf
927 (file-name-nondirectory filename) 945 (when (not (eq (not (null rawfile))
928 (buffer-name buf)))) 946 (not (null find-file-literally))))
929 (with-current-buffer buf 947 (if (buffer-modified-p)
930 (revert-buffer t t)))))
931 (with-current-buffer buf
932 (when (not (eq (not (null rawfile))
933 (not (null find-file-literally))))
934 (if (buffer-modified-p)
935 (if (y-or-n-p (if rawfile
936 "Save file and revisit literally? "
937 "Save file and revisit non-literally? "))
938 (progn
939 (save-buffer)
940 (find-file-noselect-1 buf filename nowarn
941 rawfile truename number))
942 (if (y-or-n-p (if rawfile 948 (if (y-or-n-p (if rawfile
943 "Discard your edits and revisit file literally? " 949 "Save file and revisit literally? "
944 "Discard your edits and revisit file non-literally? ")) 950 "Save file and revisit non-literally? "))
945 (find-file-noselect-1 buf filename nowarn 951 (progn
946 rawfile truename number) 952 (save-buffer)
947 (error (if rawfile "File already visited non-literally" 953 (find-file-noselect-1 buf filename nowarn
948 "File already visited literally")))) 954 rawfile truename number))
949 (if (y-or-n-p (if rawfile 955 (if (y-or-n-p (if rawfile
950 "Revisit file literally? " 956 "Discard your edits and revisit file literally? "
951 "Revisit file non-literally? ")) 957 "Discard your edits and revisit file non-literally? "))
952 (find-file-noselect-1 buf filename nowarn 958 (find-file-noselect-1 buf filename nowarn
953 rawfile truename number) 959 rawfile truename number)
954 (error (if rawfile "File already visited non-literally" 960 (error (if rawfile "File already visited non-literally"
955 "File already visited literally")))))) 961 "File already visited literally"))))
956 ;; Return the buffer we are using. 962 (if (y-or-n-p (if rawfile
957 buf) 963 "Revisit file literally? "
958 ;; Create a new buffer. 964 "Revisit file non-literally? "))
959 (setq buf (create-file-buffer filename)) 965 (find-file-noselect-1 buf filename nowarn
960 (set-buffer-major-mode buf) 966 rawfile truename number)
961 ;; find-file-noselect-1 may use a different buffer. 967 (error (if rawfile "File already visited non-literally"
962 (find-file-noselect-1 buf filename nowarn 968 "File already visited literally"))))))
963 rawfile truename number))))) 969 ;; Return the buffer we are using.
970 buf)
971 ;; Create a new buffer.
972 (setq buf (create-file-buffer filename))
973 (set-buffer-major-mode buf)
974 ;; find-file-noselect-1 may use a different buffer.
975 (find-file-noselect-1 buf filename nowarn
976 rawfile truename number))))))
964 977
965(defun find-file-noselect-1 (buf filename nowarn rawfile truename number) 978(defun find-file-noselect-1 (buf filename nowarn rawfile truename number)
966 (let ((inhibit-read-only t) 979 (let ((inhibit-read-only t)
@@ -3027,6 +3040,12 @@ by `sh' are supported."
3027 :type 'string 3040 :type 'string
3028 :group 'dired) 3041 :group 'dired)
3029 3042
3043(defun file-expand-wildcards (pattern &optional full)
3044 "Expand wildcard pattern PATTERN.
3045This returns a list of file names which match the pattern."
3046 (directory-files (file-name-directory pattern) full
3047 (wildcard-to-regexp (file-name-nondirectory pattern))))
3048
3030(defun list-directory (dirname &optional verbose) 3049(defun list-directory (dirname &optional verbose)
3031 "Display a list of files in or matching DIRNAME, a la `ls'. 3050 "Display a list of files in or matching DIRNAME, a la `ls'.
3032DIRNAME is globbed by the shell if necessary. 3051DIRNAME is globbed by the shell if necessary.