Mercurial > emacs
comparison lisp/files.el @ 17673:ba2c70d76b5b
Use defgroup and defcustom.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Mon, 05 May 1997 22:04:00 +0000 |
parents | ca11152dcad5 |
children | a08d96324d4f |
comparison
equal
deleted
inserted
replaced
17672:3e14521699ff | 17673:ba2c70d76b5b |
---|---|
28 ;; including basic file visiting, backup generation, link handling, | 28 ;; including basic file visiting, backup generation, link handling, |
29 ;; ITS-id version control, load- and write-hook handling, and the like. | 29 ;; ITS-id version control, load- and write-hook handling, and the like. |
30 | 30 |
31 ;;; Code: | 31 ;;; Code: |
32 | 32 |
33 (defvar delete-auto-save-files t | 33 (defgroup backup nil |
34 "*Non-nil means delete auto-save file when a buffer is saved or killed.") | 34 "Backups of edited data files." |
35 | 35 :group 'data) |
36 (defvar directory-abbrev-alist | 36 |
37 (defgroup find-file nil | |
38 "Finding and editing files." | |
39 :group 'data) | |
40 | |
41 | |
42 (defcustom delete-auto-save-files t | |
43 "*Non-nil means delete auto-save file when a buffer is saved or killed." | |
44 :type 'boolean | |
45 :group 'auto-save) | |
46 | |
47 (defcustom directory-abbrev-alist | |
37 nil | 48 nil |
38 "*Alist of abbreviations for file directories. | 49 "*Alist of abbreviations for file directories. |
39 A list of elements of the form (FROM . TO), each meaning to replace | 50 A list of elements of the form (FROM . TO), each meaning to replace |
40 FROM with TO when it appears in a directory name. This replacement is | 51 FROM with TO when it appears in a directory name. This replacement is |
41 done when setting up the default directory of a newly visited file. | 52 done when setting up the default directory of a newly visited file. |
44 Do not use `~' in the TO strings. | 55 Do not use `~' in the TO strings. |
45 They should be ordinary absolute directory names. | 56 They should be ordinary absolute directory names. |
46 | 57 |
47 Use this feature when you have directories which you normally refer to | 58 Use this feature when you have directories which you normally refer to |
48 via absolute symbolic links. Make TO the name of the link, and FROM | 59 via absolute symbolic links. Make TO the name of the link, and FROM |
49 the name it is linked to.") | 60 the name it is linked to." |
61 :type '(repeat (cons :format "%v" | |
62 :value ("" . "") | |
63 (regexp :tag "From") | |
64 (regexp :tag "To"))) | |
65 :group 'abbrev | |
66 :group 'find-file) | |
50 | 67 |
51 ;;; Turn off backup files on VMS since it has version numbers. | 68 ;;; Turn off backup files on VMS since it has version numbers. |
52 (defvar make-backup-files (not (eq system-type 'vax-vms)) | 69 (defcustom make-backup-files (not (eq system-type 'vax-vms)) |
53 "*Non-nil means make a backup of a file the first time it is saved. | 70 "*Non-nil means make a backup of a file the first time it is saved. |
54 This can be done by renaming the file or by copying. | 71 This can be done by renaming the file or by copying. |
55 | 72 |
56 Renaming means that Emacs renames the existing file so that it is a | 73 Renaming means that Emacs renames the existing file so that it is a |
57 backup file, then writes the buffer into a new file. Any other names | 74 backup file, then writes the buffer into a new file. Any other names |
63 names that the old file had will now refer to the new (edited) file. | 80 names that the old file had will now refer to the new (edited) file. |
64 The file's owner and group are unchanged. | 81 The file's owner and group are unchanged. |
65 | 82 |
66 The choice of renaming or copying is controlled by the variables | 83 The choice of renaming or copying is controlled by the variables |
67 `backup-by-copying', `backup-by-copying-when-linked' and | 84 `backup-by-copying', `backup-by-copying-when-linked' and |
68 `backup-by-copying-when-mismatch'. See also `backup-inhibited'.") | 85 `backup-by-copying-when-mismatch'. See also `backup-inhibited'." |
86 :type 'boolean | |
87 :group 'backup) | |
69 | 88 |
70 ;; Do this so that local variables based on the file name | 89 ;; Do this so that local variables based on the file name |
71 ;; are not overridden by the major mode. | 90 ;; are not overridden by the major mode. |
72 (defvar backup-inhibited nil | 91 (defvar backup-inhibited nil |
73 "Non-nil means don't make a backup, regardless of the other parameters. | 92 "Non-nil means don't make a backup, regardless of the other parameters. |
74 This variable is intended for use by making it local to a buffer. | 93 This variable is intended for use by making it local to a buffer. |
75 But it is local only if you make it local.") | 94 But it is local only if you make it local.") |
76 (put 'backup-inhibited 'permanent-local t) | 95 (put 'backup-inhibited 'permanent-local t) |
77 | 96 |
78 (defvar backup-by-copying nil | 97 (defcustom backup-by-copying nil |
79 "*Non-nil means always use copying to create backup files. | 98 "*Non-nil means always use copying to create backup files. |
80 See documentation of variable `make-backup-files'.") | 99 See documentation of variable `make-backup-files'." |
81 | 100 :type 'boolean |
82 (defvar backup-by-copying-when-linked nil | 101 :group 'backup) |
102 | |
103 (defcustom backup-by-copying-when-linked nil | |
83 "*Non-nil means use copying to create backups for files with multiple names. | 104 "*Non-nil means use copying to create backups for files with multiple names. |
84 This causes the alternate names to refer to the latest version as edited. | 105 This causes the alternate names to refer to the latest version as edited. |
85 This variable is relevant only if `backup-by-copying' is nil.") | 106 This variable is relevant only if `backup-by-copying' is nil." |
86 | 107 :type 'boolean |
87 (defvar backup-by-copying-when-mismatch nil | 108 :group 'backup) |
109 | |
110 (defcustom backup-by-copying-when-mismatch nil | |
88 "*Non-nil means create backups by copying if this preserves owner or group. | 111 "*Non-nil means create backups by copying if this preserves owner or group. |
89 Renaming may still be used (subject to control of other variables) | 112 Renaming may still be used (subject to control of other variables) |
90 when it would not result in changing the owner or group of the file; | 113 when it would not result in changing the owner or group of the file; |
91 that is, for files which are owned by you and whose group matches | 114 that is, for files which are owned by you and whose group matches |
92 the default for a new file created there by you. | 115 the default for a new file created there by you. |
93 This variable is relevant only if `backup-by-copying' is nil.") | 116 This variable is relevant only if `backup-by-copying' is nil." |
117 :type 'boolean | |
118 :group 'backup) | |
94 | 119 |
95 (defvar backup-enable-predicate | 120 (defvar backup-enable-predicate |
96 '(lambda (name) | 121 '(lambda (name) |
97 (or (< (length name) 5) | 122 (or (< (length name) 5) |
98 (not (string-equal "/tmp/" (substring name 0 5))))) | 123 (not (string-equal "/tmp/" (substring name 0 5))))) |
99 "Predicate that looks at a file name and decides whether to make backups. | 124 "Predicate that looks at a file name and decides whether to make backups. |
100 Called with an absolute file name as argument, it returns t to enable backup.") | 125 Called with an absolute file name as argument, it returns t to enable backup.") |
101 | 126 |
102 (defvar buffer-offer-save nil | 127 (defcustom buffer-offer-save nil |
103 "*Non-nil in a buffer means offer to save the buffer on exit | 128 "*Non-nil in a buffer means offer to save the buffer on exit |
104 even if the buffer is not visiting a file. | 129 even if the buffer is not visiting a file. |
105 Automatically local in all buffers.") | 130 Automatically local in all buffers." |
131 :type 'boolean | |
132 :group 'backup) | |
106 (make-variable-buffer-local 'buffer-offer-save) | 133 (make-variable-buffer-local 'buffer-offer-save) |
107 | 134 |
108 (defvar find-file-existing-other-name t | 135 (defcustom find-file-existing-other-name t |
109 "*Non-nil means find a file under alternative names, in existing buffers. | 136 "*Non-nil means find a file under alternative names, in existing buffers. |
110 This means if any existing buffer is visiting the file you want | 137 This means if any existing buffer is visiting the file you want |
111 under another name, you get the existing buffer instead of a new buffer.") | 138 under another name, you get the existing buffer instead of a new buffer." |
112 | 139 :type 'boolean |
113 (defvar find-file-visit-truename nil | 140 :group 'find-file) |
141 | |
142 (defcustom find-file-visit-truename nil | |
114 "*Non-nil means visit a file under its truename. | 143 "*Non-nil means visit a file under its truename. |
115 The truename of a file is found by chasing all links | 144 The truename of a file is found by chasing all links |
116 both at the file level and at the levels of the containing directories.") | 145 both at the file level and at the levels of the containing directories." |
117 | 146 :type 'boolean |
118 (defvar find-file-revert-without-query | 147 :group 'find-file) |
148 | |
149 (defcustom find-file-revert-without-query | |
119 nil | 150 nil |
120 "*Specify which files should be reverted without query. | 151 "*Specify which files should be reverted without query. |
121 The value is a list of regular expressions. | 152 The value is a list of regular expressions. |
122 If the file name matches one of these regular expressions, | 153 If the file name matches one of these regular expressions, |
123 then `find-file' reverts the file without querying | 154 then `find-file' reverts the file without querying |
124 if the file has changed on disk and you have not edited the buffer.") | 155 if the file has changed on disk and you have not edited the buffer." |
156 :type 'boolean | |
157 :group 'find-file) | |
125 | 158 |
126 (defvar buffer-file-number nil | 159 (defvar buffer-file-number nil |
127 "The device number and file number of the file visited in the current buffer. | 160 "The device number and file number of the file visited in the current buffer. |
128 The value is a list of the form (FILENUM DEVNUM). | 161 The value is a list of the form (FILENUM DEVNUM). |
129 This pair of numbers uniquely identifies the file. | 162 This pair of numbers uniquely identifies the file. |
132 (put 'buffer-file-number 'permanent-local t) | 165 (put 'buffer-file-number 'permanent-local t) |
133 | 166 |
134 (defvar buffer-file-numbers-unique (not (memq system-type '(windows-nt))) | 167 (defvar buffer-file-numbers-unique (not (memq system-type '(windows-nt))) |
135 "Non-nil means that buffer-file-number uniquely identifies files.") | 168 "Non-nil means that buffer-file-number uniquely identifies files.") |
136 | 169 |
137 (defvar file-precious-flag nil | 170 (defcustom file-precious-flag nil |
138 "*Non-nil means protect against I/O errors while saving files. | 171 "*Non-nil means protect against I/O errors while saving files. |
139 Some modes set this non-nil in particular buffers. | 172 Some modes set this non-nil in particular buffers. |
140 | 173 |
141 This feature works by writing the new contents into a temporary file | 174 This feature works by writing the new contents into a temporary file |
142 and then renaming the temporary file to replace the original. | 175 and then renaming the temporary file to replace the original. |
143 In this way, any I/O error in writing leaves the original untouched, | 176 In this way, any I/O error in writing leaves the original untouched, |
144 and there is never any instant where the file is nonexistent. | 177 and there is never any instant where the file is nonexistent. |
145 | 178 |
146 Note that this feature forces backups to be made by copying. | 179 Note that this feature forces backups to be made by copying. |
147 Yet, at the same time, saving a precious file | 180 Yet, at the same time, saving a precious file |
148 breaks any hard links between it and other files.") | 181 breaks any hard links between it and other files." |
149 | 182 :type 'boolean |
150 (defvar version-control nil | 183 :group 'backup) |
184 | |
185 (defcustom version-control nil | |
151 "*Control use of version numbers for backup files. | 186 "*Control use of version numbers for backup files. |
152 t means make numeric backup versions unconditionally. | 187 t means make numeric backup versions unconditionally. |
153 nil means make them for files that have some already. | 188 nil means make them for files that have some already. |
154 `never' means do not make them.") | 189 `never' means do not make them." |
155 | 190 :type 'boolean |
156 (defvar dired-kept-versions 2 | 191 :group 'backup |
157 "*When cleaning directory, number of versions to keep.") | 192 :group 'vc) |
158 | 193 |
159 (defvar delete-old-versions nil | 194 (defcustom dired-kept-versions 2 |
195 "*When cleaning directory, number of versions to keep." | |
196 :type 'integer | |
197 :group 'backup | |
198 :group 'dired) | |
199 | |
200 (defcustom delete-old-versions nil | |
160 "*If t, delete excess backup versions silently. | 201 "*If t, delete excess backup versions silently. |
161 If nil, ask confirmation. Any other value prevents any trimming.") | 202 If nil, ask confirmation. Any other value prevents any trimming." |
162 | 203 :type '(choice (const :tag "Delete" t) |
163 (defvar kept-old-versions 2 | 204 (const :tag "Ask" nil) |
164 "*Number of oldest versions to keep when a new numbered backup is made.") | 205 (sexp :tag "Leave" :format "%t\n" other)) |
165 | 206 :group 'backup) |
166 (defvar kept-new-versions 2 | 207 |
208 (defcustom kept-old-versions 2 | |
209 "*Number of oldest versions to keep when a new numbered backup is made." | |
210 :type 'integer | |
211 :group 'backup) | |
212 | |
213 (defcustom kept-new-versions 2 | |
167 "*Number of newest versions to keep when a new numbered backup is made. | 214 "*Number of newest versions to keep when a new numbered backup is made. |
168 Includes the new backup. Must be > 0") | 215 Includes the new backup. Must be > 0" |
169 | 216 :type 'integer |
170 (defvar require-final-newline nil | 217 :group 'backup) |
218 | |
219 (defcustom require-final-newline nil | |
171 "*Value of t says silently ensure a file ends in a newline when it is saved. | 220 "*Value of t says silently ensure a file ends in a newline when it is saved. |
172 Non-nil but not t says ask user whether to add a newline when there isn't one. | 221 Non-nil but not t says ask user whether to add a newline when there isn't one. |
173 nil means don't add newlines.") | 222 nil means don't add newlines." |
174 | 223 :type 'boolean |
175 (defvar auto-save-default t | 224 :group 'editing-basics) |
176 "*Non-nil says by default do auto-saving of every file-visiting buffer.") | 225 |
177 | 226 (defcustom auto-save-default t |
178 (defvar auto-save-visited-file-name nil | 227 "*Non-nil says by default do auto-saving of every file-visiting buffer." |
228 :type 'boolean | |
229 :group 'auto-save) | |
230 | |
231 (defcustom auto-save-visited-file-name nil | |
179 "*Non-nil says auto-save a buffer in the file it is visiting, when practical. | 232 "*Non-nil says auto-save a buffer in the file it is visiting, when practical. |
180 Normally auto-save files are written under other names.") | 233 Normally auto-save files are written under other names." |
181 | 234 :type 'boolean |
182 (defvar save-abbrevs nil | 235 :group 'auto-save) |
236 | |
237 (defcustom save-abbrevs nil | |
183 "*Non-nil means save word abbrevs too when files are saved. | 238 "*Non-nil means save word abbrevs too when files are saved. |
184 Loading an abbrev file sets this to t.") | 239 Loading an abbrev file sets this to t." |
185 | 240 :type 'boolean |
186 (defvar find-file-run-dired t | 241 :group 'abbrev) |
187 "*Non-nil says run dired if `find-file' is given the name of a directory.") | 242 |
243 (defcustom find-file-run-dired t | |
244 "*Non-nil says run dired if `find-file' is given the name of a directory." | |
245 :type 'boolean | |
246 :group 'find-file) | |
188 | 247 |
189 ;;;It is not useful to make this a local variable. | 248 ;;;It is not useful to make this a local variable. |
190 ;;;(put 'find-file-not-found-hooks 'permanent-local t) | 249 ;;;(put 'find-file-not-found-hooks 'permanent-local t) |
191 (defvar find-file-not-found-hooks nil | 250 (defvar find-file-not-found-hooks nil |
192 "List of functions to be called for `find-file' on nonexistent file. | 251 "List of functions to be called for `find-file' on nonexistent file. |
240 LOCAL argument. | 299 LOCAL argument. |
241 | 300 |
242 See also `write-file-hooks'.") | 301 See also `write-file-hooks'.") |
243 (make-variable-buffer-local 'write-contents-hooks) | 302 (make-variable-buffer-local 'write-contents-hooks) |
244 | 303 |
245 (defvar enable-local-variables t | 304 (defcustom enable-local-variables t |
246 "*Control use of local variables in files you visit. | 305 "*Control use of local variables in files you visit. |
247 The value can be t, nil or something else. | 306 The value can be t, nil or something else. |
248 A value of t means file local variables specifications are obeyed; | 307 A value of t means file local variables specifications are obeyed; |
249 nil means they are ignored; anything else means query. | 308 nil means they are ignored; anything else means query. |
250 | 309 |
251 The command \\[normal-mode] always obeys file local variable | 310 The command \\[normal-mode] always obeys file local variable |
252 specifications and ignores this variable.") | 311 specifications and ignores this variable." |
253 | 312 :type '(choice (const :tag "Obey" t) |
254 (defvar enable-local-eval 'maybe | 313 (const :tag "Ignore" nil) |
314 (sexp :tag "Query" :format "%t\n" other)) | |
315 :group 'find-file) | |
316 | |
317 (defcustom enable-local-eval 'maybe | |
255 "*Control processing of the \"variable\" `eval' in a file's local variables. | 318 "*Control processing of the \"variable\" `eval' in a file's local variables. |
256 The value can be t, nil or something else. | 319 The value can be t, nil or something else. |
257 A value of t means obey `eval' variables; | 320 A value of t means obey `eval' variables; |
258 nil means ignore them; anything else means query. | 321 nil means ignore them; anything else means query. |
259 | 322 |
260 The command \\[normal-mode] always obeys local-variables lists | 323 The command \\[normal-mode] always obeys local-variables lists |
261 and ignores this variable.") | 324 and ignores this variable." |
325 :type '(choice (const :tag "Obey" t) | |
326 (const :tag "Ignore" nil) | |
327 (sexp :tag "Query" :format "%t\n" other)) | |
328 :group 'find-file) | |
262 | 329 |
263 ;; Avoid losing in versions where CLASH_DETECTION is disabled. | 330 ;; Avoid losing in versions where CLASH_DETECTION is disabled. |
264 (or (fboundp 'lock-buffer) | 331 (or (fboundp 'lock-buffer) |
265 (defalias 'lock-buffer 'ignore)) | 332 (defalias 'lock-buffer 'ignore)) |
266 (or (fboundp 'unlock-buffer) | 333 (or (fboundp 'unlock-buffer) |
702 (concat "~" | 769 (concat "~" |
703 (substring filename (match-beginning 1) (match-end 1)) | 770 (substring filename (match-beginning 1) (match-end 1)) |
704 (substring filename (match-end 0))))) | 771 (substring filename (match-end 0))))) |
705 filename)) | 772 filename)) |
706 | 773 |
707 (defvar find-file-not-true-dirname-list nil | 774 (defcustom find-file-not-true-dirname-list nil |
708 "*List of logical names for which visiting shouldn't save the true dirname. | 775 "*List of logical names for which visiting shouldn't save the true dirname. |
709 On VMS, when you visit a file using a logical name that searches a path, | 776 On VMS, when you visit a file using a logical name that searches a path, |
710 you may or may not want the visited file name to record the specific | 777 you may or may not want the visited file name to record the specific |
711 directory where the file was found. If you *do not* want that, add the logical | 778 directory where the file was found. If you *do not* want that, add the logical |
712 name to this list as a string.") | 779 name to this list as a string." |
780 :type '(repeat (string :tag "Name")) | |
781 :group 'find-file) | |
713 | 782 |
714 (defun find-buffer-visiting (filename) | 783 (defun find-buffer-visiting (filename) |
715 "Return the buffer visiting file FILENAME (a string). | 784 "Return the buffer visiting file FILENAME (a string). |
716 This is like `get-file-buffer', except that it checks for any buffer | 785 This is like `get-file-buffer', except that it checks for any buffer |
717 visiting the same file, possibly under a different name. | 786 visiting the same file, possibly under a different name. |
1496 ;; Ordinary variable, really set it. | 1565 ;; Ordinary variable, really set it. |
1497 (t (make-local-variable var) | 1566 (t (make-local-variable var) |
1498 (set var val)))) | 1567 (set var val)))) |
1499 | 1568 |
1500 | 1569 |
1501 (defvar change-major-mode-with-file-name t | 1570 (defcustom change-major-mode-with-file-name t |
1502 "*Non-nil means \\[write-file] should set the major mode from the file name. | 1571 "*Non-nil means \\[write-file] should set the major mode from the file name. |
1503 However, the mode will not be changed if | 1572 However, the mode will not be changed if |
1504 \(1) a local variables list or the `-*-' line specifies a major mode, or | 1573 \(1) a local variables list or the `-*-' line specifies a major mode, or |
1505 \(2) the current major mode is a \"special\" mode, | 1574 \(2) the current major mode is a \"special\" mode, |
1506 \ not suitable for ordinary files, or | 1575 \ not suitable for ordinary files, or |
1507 \(3) the new file name does not particularly specify any mode.") | 1576 \(3) the new file name does not particularly specify any mode." |
1577 :type 'boolean | |
1578 :group 'editing-basics) | |
1508 | 1579 |
1509 (defun set-visited-file-name (filename &optional no-query along-with-file) | 1580 (defun set-visited-file-name (filename &optional no-query along-with-file) |
1510 "Change name of file visited in current buffer to FILENAME. | 1581 "Change name of file visited in current buffer to FILENAME. |
1511 The next time the buffer is saved it will go in the newly specified file. | 1582 The next time the buffer is saved it will go in the newly specified file. |
1512 nil or empty string as argument means make buffer not be visiting any file. | 1583 nil or empty string as argument means make buffer not be visiting any file. |
2719 (setq i (1+ i))))) | 2790 (setq i (1+ i))))) |
2720 ;; Shell wildcards should match the entire filename, | 2791 ;; Shell wildcards should match the entire filename, |
2721 ;; not its part. Make the regexp say so. | 2792 ;; not its part. Make the regexp say so. |
2722 (concat "\\`" result "\\'"))) | 2793 (concat "\\`" result "\\'"))) |
2723 | 2794 |
2724 (defvar list-directory-brief-switches | 2795 (defcustom list-directory-brief-switches |
2725 (if (eq system-type 'vax-vms) "" "-CF") | 2796 (if (eq system-type 'vax-vms) "" "-CF") |
2726 "*Switches for list-directory to pass to `ls' for brief listing,") | 2797 "*Switches for list-directory to pass to `ls' for brief listing," |
2727 | 2798 :type 'string |
2728 (defvar list-directory-verbose-switches | 2799 :group 'dired) |
2800 | |
2801 (defcustom list-directory-verbose-switches | |
2729 (if (eq system-type 'vax-vms) | 2802 (if (eq system-type 'vax-vms) |
2730 "/PROTECTION/SIZE/DATE/OWNER/WIDTH=(OWNER:10)" | 2803 "/PROTECTION/SIZE/DATE/OWNER/WIDTH=(OWNER:10)" |
2731 "-l") | 2804 "-l") |
2732 "*Switches for list-directory to pass to `ls' for verbose listing,") | 2805 "*Switches for list-directory to pass to `ls' for verbose listing," |
2806 :type 'string | |
2807 :group 'dired) | |
2733 | 2808 |
2734 (defun list-directory (dirname &optional verbose) | 2809 (defun list-directory (dirname &optional verbose) |
2735 "Display a list of files in or matching DIRNAME, a la `ls'. | 2810 "Display a list of files in or matching DIRNAME, a la `ls'. |
2736 DIRNAME is globbed by the shell if necessary. | 2811 DIRNAME is globbed by the shell if necessary. |
2737 Prefix arg (second arg if noninteractive) means supply -l switch to `ls'. | 2812 Prefix arg (second arg if noninteractive) means supply -l switch to `ls'. |