comparison lisp/prim/files.el @ 163:0132846995bd r20-3b8

Import from CVS: tag r20-3b8
author cvs
date Mon, 13 Aug 2007 09:43:35 +0200
parents 28f395d8dc7a
children 5a88923fcbfe
comparison
equal deleted inserted replaced
162:4de2936b4e77 163:0132846995bd
33 33
34 ;; XEmacs: Avoid compilation warnings. 34 ;; XEmacs: Avoid compilation warnings.
35 (defvar coding-system-for-read) 35 (defvar coding-system-for-read)
36 (defvar buffer-file-coding-system) 36 (defvar buffer-file-coding-system)
37 37
38 (defgroup backup nil
39 "Backups of edited data files."
40 :group 'data)
41
42 (defgroup find-file nil
43 "Finding and editing files."
44 :group 'data)
45
46
38 ;; XEmacs: In buffer.c 47 ;; XEmacs: In buffer.c
39 ;(defconst delete-auto-save-files t 48 ;(defconst delete-auto-save-files t
40 ; "*Non-nil means delete auto-save file when a buffer is saved or killed.") 49 ; "*Non-nil means delete auto-save file when a buffer is saved or killed.")
41 50
42 ;; FSF has automount-dir-prefix. Our directory-abbrev-alist is more general. 51 ;; FSF has automount-dir-prefix. Our directory-abbrev-alist is more general.
43 ;; note: tmp_mnt bogosity conversion is established in paths.el. 52 ;; note: tmp_mnt bogosity conversion is established in paths.el.
44 (defvar directory-abbrev-alist nil 53 (defcustom directory-abbrev-alist nil
45 "*Alist of abbreviations for file directories. 54 "*Alist of abbreviations for file directories.
46 A list of elements of the form (FROM . TO), each meaning to replace 55 A list of elements of the form (FROM . TO), each meaning to replace
47 FROM with TO when it appears in a directory name. 56 FROM with TO when it appears in a directory name.
48 This replacement is done when setting up the default directory of a 57 This replacement is done when setting up the default directory of a
49 newly visited file. *Every* FROM string should start with \\\\` or ^. 58 newly visited file. *Every* FROM string should start with \\\\` or ^.
50 59
51 Use this feature when you have directories which you normally refer to 60 Use this feature when you have directories which you normally refer to
52 via absolute symbolic links or to eliminate automounter mount points 61 via absolute symbolic links or to eliminate automounter mount points
53 from the beginning of your filenames. Make TO the name of the link, 62 from the beginning of your filenames. Make TO the name of the link,
54 and FROM the name it is linked to.") 63 and FROM the name it is linked to."
64 :type '(repeat (cons :format "%v"
65 :value ("\\`" . "")
66 (regexp :tag "From")
67 (regexp :tag "To")))
68 :group 'find-file)
55 69
56 ;;; Turn off backup files on VMS since it has version numbers. 70 ;;; Turn off backup files on VMS since it has version numbers.
57 (defconst make-backup-files (not (eq system-type 'vax-vms)) 71 (defcustom make-backup-files (not (eq system-type 'vax-vms))
58 "*Non-nil means make a backup of a file the first time it is saved. 72 "*Non-nil means make a backup of a file the first time it is saved.
59 This can be done by renaming the file or by copying. 73 This can be done by renaming the file or by copying.
60 74
61 Renaming means that XEmacs renames the existing file so that it is a 75 Renaming means that XEmacs renames the existing file so that it is a
62 backup file, then writes the buffer into a new file. Any other names 76 backup file, then writes the buffer into a new file. Any other names
68 names that the old file had will now refer to the new (edited) file. 82 names that the old file had will now refer to the new (edited) file.
69 The file's owner and group are unchanged. 83 The file's owner and group are unchanged.
70 84
71 The choice of renaming or copying is controlled by the variables 85 The choice of renaming or copying is controlled by the variables
72 `backup-by-copying', `backup-by-copying-when-linked' and 86 `backup-by-copying', `backup-by-copying-when-linked' and
73 `backup-by-copying-when-mismatch'. See also `backup-inhibited'.") 87 `backup-by-copying-when-mismatch'. See also `backup-inhibited'."
88 :type 'boolean
89 :group 'backup)
74 90
75 ;; Do this so that local variables based on the file name 91 ;; Do this so that local variables based on the file name
76 ;; are not overridden by the major mode. 92 ;; are not overridden by the major mode.
77 (defvar backup-inhibited nil 93 (defvar backup-inhibited nil
78 "Non-nil means don't make a backup, regardless of the other parameters. 94 "Non-nil means don't make a backup, regardless of the other parameters.
79 This variable is intended for use by making it local to a buffer. 95 This variable is intended for use by making it local to a buffer.
80 But it is local only if you make it local.") 96 But it is local only if you make it local.")
81 (put 'backup-inhibited 'permanent-local t) 97 (put 'backup-inhibited 'permanent-local t)
82 98
83 (defconst backup-by-copying nil 99 (defcustom backup-by-copying nil
84 "*Non-nil means always use copying to create backup files. 100 "*Non-nil means always use copying to create backup files.
85 See documentation of variable `make-backup-files'.") 101 See documentation of variable `make-backup-files'."
86 102 :type 'boolean
87 (defconst backup-by-copying-when-linked nil 103 :group 'backup)
104
105 (defcustom backup-by-copying-when-linked nil
88 "*Non-nil means use copying to create backups for files with multiple names. 106 "*Non-nil means use copying to create backups for files with multiple names.
89 This causes the alternate names to refer to the latest version as edited. 107 This causes the alternate names to refer to the latest version as edited.
90 This variable is relevant only if `backup-by-copying' is nil.") 108 This variable is relevant only if `backup-by-copying' is nil."
91 109 :type 'boolean
92 (defconst backup-by-copying-when-mismatch nil 110 :group 'backup)
111
112 (defcustom backup-by-copying-when-mismatch nil
93 "*Non-nil means create backups by copying if this preserves owner or group. 113 "*Non-nil means create backups by copying if this preserves owner or group.
94 Renaming may still be used (subject to control of other variables) 114 Renaming may still be used (subject to control of other variables)
95 when it would not result in changing the owner or group of the file; 115 when it would not result in changing the owner or group of the file;
96 that is, for files which are owned by you and whose group matches 116 that is, for files which are owned by you and whose group matches
97 the default for a new file created there by you. 117 the default for a new file created there by you.
98 This variable is relevant only if `backup-by-copying' is nil.") 118 This variable is relevant only if `backup-by-copying' is nil."
119 :type 'boolean
120 :group 'backup)
99 121
100 (defvar backup-enable-predicate 122 (defvar backup-enable-predicate
101 '(lambda (name) 123 '(lambda (name)
102 (or (< (length name) 5) 124 (or (< (length name) 5)
103 (not (string-equal "/tmp/" (substring name 0 5))))) 125 (not (string-equal "/tmp/" (substring name 0 5)))))
104 "Predicate that looks at a file name and decides whether to make backups. 126 "Predicate that looks at a file name and decides whether to make backups.
105 Called with an absolute file name as argument, it returns t to enable backup.") 127 Called with an absolute file name as argument, it returns t to enable backup.")
106 128
107 (defconst buffer-offer-save nil 129 (defcustom buffer-offer-save nil
108 "*Non-nil in a buffer means offer to save the buffer on exit 130 "*Non-nil in a buffer means offer to save the buffer on exit
109 even if the buffer is not visiting a file. 131 even if the buffer is not visiting a file.
110 Automatically local in all buffers.") 132 Automatically local in all buffers."
133 :type 'boolean
134 :group 'find-file)
111 (make-variable-buffer-local 'buffer-offer-save) 135 (make-variable-buffer-local 'buffer-offer-save)
112 136
113 ;; FSF uses normal defconst 137 ;; FSF uses normal defconst
114 (defvaralias 'find-file-visit-truename 'find-file-use-truenames) 138 (defvaralias 'find-file-visit-truename 'find-file-use-truenames)
115 (defvaralias 'find-file-existing-other-name 'find-file-compare-truenames) 139 (defvaralias 'find-file-existing-other-name 'find-file-compare-truenames)
123 (put 'buffer-file-number 'permanent-local t) 147 (put 'buffer-file-number 'permanent-local t)
124 148
125 (defvar buffer-file-numbers-unique (not (memq system-type '(windows-nt))) 149 (defvar buffer-file-numbers-unique (not (memq system-type '(windows-nt)))
126 "Non-nil means that buffer-file-number uniquely identifies files.") 150 "Non-nil means that buffer-file-number uniquely identifies files.")
127 151
128 (defconst file-precious-flag nil 152 (defcustom file-precious-flag nil
129 "*Non-nil means protect against I/O errors while saving files. 153 "*Non-nil means protect against I/O errors while saving files.
130 Some modes set this non-nil in particular buffers. 154 Some modes set this non-nil in particular buffers.
131 155
132 This feature works by writing the new contents into a temporary file 156 This feature works by writing the new contents into a temporary file
133 and then renaming the temporary file to replace the original. 157 and then renaming the temporary file to replace the original.
134 In this way, any I/O error in writing leaves the original untouched, 158 In this way, any I/O error in writing leaves the original untouched,
135 and there is never any instant where the file is nonexistent. 159 and there is never any instant where the file is nonexistent.
136 160
137 Note that this feature forces backups to be made by copying. 161 Note that this feature forces backups to be made by copying.
138 Yet, at the same time, saving a precious file 162 Yet, at the same time, saving a precious file
139 breaks any hard links between it and other files.") 163 breaks any hard links between it and other files."
140 164 :type 'boolean
141 (defvar version-control nil 165 :group 'backup)
166
167 (defcustom version-control nil
142 "*Control use of version numbers for backup files. 168 "*Control use of version numbers for backup files.
143 t means make numeric backup versions unconditionally. 169 t means make numeric backup versions unconditionally.
144 nil means make them for files that have some already. 170 nil means make them for files that have some already.
145 `never' means do not make them.") 171 `never' means do not make them."
172 :type 'boolean
173 :group 'backup
174 :group 'vc)
146 175
147 ;; This is now defined in efs. 176 ;; This is now defined in efs.
148 ;(defvar dired-kept-versions 2 177 ;(defvar dired-kept-versions 2
149 ; "*When cleaning directory, number of versions to keep.") 178 ; "*When cleaning directory, number of versions to keep.")
150 179
151 (defvar delete-old-versions nil 180 (defcustom delete-old-versions nil
152 "*If t, delete excess backup versions silently. 181 "*If t, delete excess backup versions silently.
153 If nil, ask confirmation. Any other value prevents any trimming.") 182 If nil, ask confirmation. Any other value prevents any trimming."
154 183 :type '(choice (const :tag "Delete" t)
155 (defvar kept-old-versions 2 184 (const :tag "Ask" nil)
156 "*Number of oldest versions to keep when a new numbered backup is made.") 185 (sexp :tag "Leave" :format "%t\n" other))
157 186 :group 'backup)
158 (defvar kept-new-versions 2 187
188 (defcustom kept-old-versions 2
189 "*Number of oldest versions to keep when a new numbered backup is made."
190 :type 'integer
191 :group 'backup)
192
193 (defcustom kept-new-versions 2
159 "*Number of newest versions to keep when a new numbered backup is made. 194 "*Number of newest versions to keep when a new numbered backup is made.
160 Includes the new backup. Must be > 0") 195 Includes the new backup. Must be > 0"
161 196 :type 'integer
162 (defconst require-final-newline nil 197 :group 'backup)
198
199 (defcustom require-final-newline nil
163 "*Value of t says silently ensure a file ends in a newline when it is saved. 200 "*Value of t says silently ensure a file ends in a newline when it is saved.
164 Non-nil but not t says ask user whether to add a newline when there isn't one. 201 Non-nil but not t says ask user whether to add a newline when there isn't one.
165 nil means don't add newlines.") 202 nil means don't add newlines."
166 203 :type '(choice (const :tag "Off" nil)
167 (defconst auto-save-default t 204 (const :tag "Add" t)
168 "*Non-nil says by default do auto-saving of every file-visiting buffer.") 205 (sexp :tag "Ask" :format "%t\n" ask))
169 206 :group 'editing-basics)
170 (defconst auto-save-visited-file-name nil 207
208 (defcustom auto-save-default t
209 "*Non-nil says by default do auto-saving of every file-visiting buffer."
210 :type 'boolean
211 :group 'auto-save)
212
213 (defcustom auto-save-visited-file-name nil
171 "*Non-nil says auto-save a buffer in the file it is visiting, when practical. 214 "*Non-nil says auto-save a buffer in the file it is visiting, when practical.
172 Normally auto-save files are written under other names.") 215 Normally auto-save files are written under other names."
173 216 :type 'boolean
174 (defconst save-abbrevs nil 217 :group 'auto-save)
218
219 (defcustom save-abbrevs nil
175 "*Non-nil means save word abbrevs too when files are saved. 220 "*Non-nil means save word abbrevs too when files are saved.
176 Loading an abbrev file sets this to t.") 221 Loading an abbrev file sets this to t."
177 222 :type 'boolean
178 (defconst find-file-run-dired t 223 :group 'abbrev)
179 "*Non-nil says run dired if `find-file' is given the name of a directory.") 224
225 (defcustom find-file-run-dired t
226 "*Non-nil says run dired if `find-file' is given the name of a directory."
227 :type 'boolean
228 :group 'find-file)
180 229
181 ;;;It is not useful to make this a local variable. 230 ;;;It is not useful to make this a local variable.
182 ;;;(put 'find-file-not-found-hooks 'permanent-local t) 231 ;;;(put 'find-file-not-found-hooks 'permanent-local t)
183 (defvar find-file-not-found-hooks nil 232 (defvar find-file-not-found-hooks nil
184 "List of functions to be called for `find-file' on nonexistent file. 233 "List of functions to be called for `find-file' on nonexistent file.
251 and the rest are not called. 300 and the rest are not called.
252 These hooks are considered to pertain to the visited file. 301 These hooks are considered to pertain to the visited file.
253 So this list is cleared if you change the visited file name. 302 So this list is cleared if you change the visited file name.
254 See also `write-file-hooks'.") 303 See also `write-file-hooks'.")
255 304
256 (defconst enable-local-variables t 305 (defcustom enable-local-variables t
257 "*Control use of local-variables lists in files you visit. 306 "*Control use of local-variables lists in files you visit.
258 The value can be t, nil or something else. 307 The value can be t, nil or something else.
259 A value of t means local-variables lists are obeyed; 308 A value of t means local-variables lists are obeyed;
260 nil means they are ignored; anything else means query. 309 nil means they are ignored; anything else means query.
261 310
262 The command \\[normal-mode] always obeys local-variables lists 311 The command \\[normal-mode] always obeys local-variables lists
263 and ignores this variable.") 312 and ignores this variable."
264 313 :type '(choice (const :tag "Obey" t)
265 (defconst enable-local-eval 'maybe 314 (const :tag "Ignore" nil)
315 (sexp :tag "Query" :format "%t\n" other))
316 :group 'find-file)
317
318 (defcustom enable-local-eval 'maybe
266 "*Control processing of the \"variable\" `eval' in a file's local variables. 319 "*Control processing of the \"variable\" `eval' in a file's local variables.
267 The value can be t, nil or something else. 320 The value can be t, nil or something else.
268 A value of t means obey `eval' variables; 321 A value of t means obey `eval' variables;
269 nil means ignore them; anything else means query. 322 nil means ignore them; anything else means query.
270 323
271 The command \\[normal-mode] always obeys local-variables lists 324 The command \\[normal-mode] always obeys local-variables lists
272 and ignores this variable.") 325 and ignores this variable."
326 :type '(choice (const :tag "Obey" t)
327 (const :tag "Ignore" nil)
328 (sexp :tag "Query" :format "%t\n" other))
329 :group 'find-file)
273 330
274 ;; Avoid losing in versions where CLASH_DETECTION is disabled. 331 ;; Avoid losing in versions where CLASH_DETECTION is disabled.
275 (or (fboundp 'lock-buffer) 332 (or (fboundp 'lock-buffer)
276 (defalias 'lock-buffer 'ignore)) 333 (defalias 'lock-buffer 'ignore))
277 (or (fboundp 'unlock-buffer) 334 (or (fboundp 'unlock-buffer)
815 (substring filename 872 (substring filename
816 (match-beginning 1) (match-end 1)) 873 (match-beginning 1) (match-end 1))
817 (substring filename (match-end 0))))))) 874 (substring filename (match-end 0)))))))
818 filename))) 875 filename)))
819 876
820 (defvar find-file-not-true-dirname-list nil 877 (defcustom find-file-not-true-dirname-list nil
821 "*List of logical names for which visiting shouldn't save the true dirname. 878 "*List of logical names for which visiting shouldn't save the true dirname.
822 On VMS, when you visit a file using a logical name that searches a path, 879 On VMS, when you visit a file using a logical name that searches a path,
823 you may or may not want the visited file name to record the specific 880 you may or may not want the visited file name to record the specific
824 directory where the file was found. If you *do not* want that, add the logical 881 directory where the file was found. If you *do not* want that, add the logical
825 name to this list as a string.") 882 name to this list as a string."
883 :type '(repeat (string :tag "Name"))
884 :group 'find-file)
826 885
827 ;; This function is needed by FSF vc.el. I hope somebody can make it 886 ;; This function is needed by FSF vc.el. I hope somebody can make it
828 ;; work for XEmacs. -sb. 887 ;; work for XEmacs. -sb.
829 (defun find-buffer-visiting (filename) 888 (defun find-buffer-visiting (filename)
830 "Return the buffer visiting file FILENAME (a string). 889 "Return the buffer visiting file FILENAME (a string).
1158 ("\\.m4\\'" . autoconf-mode) 1217 ("\\.m4\\'" . autoconf-mode)
1159 ("configure\\.in\\'" . autoconf-mode) 1218 ("configure\\.in\\'" . autoconf-mode)
1160 ("\\.ml\\'" . lisp-mode) 1219 ("\\.ml\\'" . lisp-mode)
1161 ("\\.ma?k\\'" . makefile-mode) 1220 ("\\.ma?k\\'" . makefile-mode)
1162 ("[Mm]akefile\\(\\.\\|\\'\\)" . makefile-mode) 1221 ("[Mm]akefile\\(\\.\\|\\'\\)" . makefile-mode)
1222 ("\\.X\\(defaults\\|environment\\|resources\\|modmap\\)\\'" . xrdb-mode)
1223 ("/app-defaults/" . xrdb-mode)
1163 ) 1224 )
1164 "Alist of filename patterns vs. corresponding major mode functions. 1225 "Alist of filename patterns vs. corresponding major mode functions.
1165 Each element looks like (REGEXP . FUNCTION) or (REGEXP FUNCTION NON-NIL). 1226 Each element looks like (REGEXP . FUNCTION) or (REGEXP FUNCTION NON-NIL).
1166 \(NON-NIL stands for anything that is not nil; the value does not matter.) 1227 \(NON-NIL stands for anything that is not nil; the value does not matter.)
1167 Visiting a file whose name matches REGEXP specifies FUNCTION as the 1228 Visiting a file whose name matches REGEXP specifies FUNCTION as the
2202 ;; If a hook returned t, file is already "written". 2263 ;; If a hook returned t, file is already "written".
2203 (if (not done) 2264 (if (not done)
2204 (basic-save-buffer-1)) 2265 (basic-save-buffer-1))
2205 'continue-save-buffer)) 2266 'continue-save-buffer))
2206 2267
2268 (defcustom save-some-buffers-query-display-buffer xemacs-betaname
2269 "*Non-nil makes `\\[save-some-buffers]' switch to the buffer offered for saving."
2270 :type 'boolean
2271 :group 'editing-basics)
2272
2207 (defun save-some-buffers (&optional arg exiting) 2273 (defun save-some-buffers (&optional arg exiting)
2208 "Save some modified file-visiting buffers. Asks user about each one. 2274 "Save some modified file-visiting buffers. Asks user about each one.
2209 Optional argument (the prefix) non-nil means save all with no questions. 2275 Optional argument (the prefix) non-nil means save all with no questions.
2210 Optional second argument EXITING means ask about certain non-file buffers 2276 Optional second argument EXITING means ask about certain non-file buffers
2211 as well as about file buffers." 2277 as well as about file buffers."
2212 (interactive "P") 2278 (interactive "P")
2213 (save-window-excursion 2279 (save-excursion
2280 (save-window-excursion
2281 ;; XEmacs - do not use queried flag
2214 (let ((files-done 2282 (let ((files-done
2215 (map-y-or-n-p 2283 (map-y-or-n-p
2216 (function 2284 (function
2217 (lambda (buffer) 2285 (lambda (buffer)
2218 (and (buffer-modified-p buffer) 2286 (and (buffer-modified-p buffer)
2225 (progn 2293 (progn
2226 (set-buffer buffer) 2294 (set-buffer buffer)
2227 (and buffer-offer-save (> (buffer-size) 0))))) 2295 (and buffer-offer-save (> (buffer-size) 0)))))
2228 (if arg 2296 (if arg
2229 t 2297 t
2298 (when save-some-buffers-query-display-buffer
2299 (when (condition-case nil
2300 (switch-to-buffer buffer t)
2301 (error nil))
2302 (delete-other-windows)))
2230 (if (buffer-file-name buffer) 2303 (if (buffer-file-name buffer)
2231 (format "Save file %s? " 2304 (format "Save file %s? "
2232 (buffer-file-name buffer)) 2305 (buffer-file-name buffer))
2233 (format "Save buffer %s? " 2306 (format "Save buffer %s? "
2234 (buffer-name buffer))))))) 2307 (buffer-name buffer)))))))
2265 (write-abbrev-file nil)) 2338 (write-abbrev-file nil))
2266 ;; Don't keep bothering user if he says no. 2339 ;; Don't keep bothering user if he says no.
2267 (setq abbrevs-changed nil) 2340 (setq abbrevs-changed nil)
2268 t)))) 2341 t))))
2269 (or (> files-done 0) abbrevs-done 2342 (or (> files-done 0) abbrevs-done
2270 (message "(No files need saving)"))))) 2343 (message "(No files need saving)"))))))
2271 2344
2272 2345
2273 (defun not-modified (&optional arg) 2346 (defun not-modified (&optional arg)
2274 "Mark current buffer as unmodified, not needing to be saved. 2347 "Mark current buffer as unmodified, not needing to be saved.
2275 With prefix arg, mark buffer as modified, so \\[save-buffer] will save. 2348 With prefix arg, mark buffer as modified, so \\[save-buffer] will save.
2780 "Return non-nil if FILENAME can be yielded by `make-auto-save-file-name'. 2853 "Return non-nil if FILENAME can be yielded by `make-auto-save-file-name'.
2781 FILENAME should lack slashes. 2854 FILENAME should lack slashes.
2782 You can redefine this for customization." 2855 You can redefine this for customization."
2783 (string-match "\\`#.*#\\'" filename)) 2856 (string-match "\\`#.*#\\'" filename))
2784 2857
2785 (defconst list-directory-brief-switches 2858 (defcustom list-directory-brief-switches
2786 (if (eq system-type 'vax-vms) "" "-CF") 2859 (if (eq system-type 'vax-vms) "" "-CF")
2787 "*Switches for list-directory to pass to `ls' for brief listing,") 2860 "*Switches for list-directory to pass to `ls' for brief listing."
2788 2861 :type 'string
2789 (defconst list-directory-verbose-switches 2862 :group 'dired)
2863
2864 (defcustom list-directory-verbose-switches
2790 (if (eq system-type 'vax-vms) 2865 (if (eq system-type 'vax-vms)
2791 "/PROTECTION/SIZE/DATE/OWNER/WIDTH=(OWNER:10)" 2866 "/PROTECTION/SIZE/DATE/OWNER/WIDTH=(OWNER:10)"
2792 "-l") 2867 "-l")
2793 "*Switches for list-directory to pass to `ls' for verbose listing,") 2868 "*Switches for list-directory to pass to `ls' for verbose listing,"
2869 :type 'string
2870 :group 'dired)
2794 2871
2795 (defun list-directory (dirname &optional verbose) 2872 (defun list-directory (dirname &optional verbose)
2796 "Display a list of files in or matching DIRNAME, a la `ls'. 2873 "Display a list of files in or matching DIRNAME, a la `ls'.
2797 DIRNAME is globbed by the shell if necessary. 2874 DIRNAME is globbed by the shell if necessary.
2798 Prefix arg (second arg if noninteractive) means supply -l switch to `ls'. 2875 Prefix arg (second arg if noninteractive) means supply -l switch to `ls'.