Mercurial > emacs
annotate lisp/files.el @ 34395:2f4a4d355834
(time-stamp-old-format-warn): reorder custom
choices to match documentation string.
author | Gerd Moellmann <gerd@gnu.org> |
---|---|
date | Sat, 09 Dec 2000 13:22:51 +0000 |
parents | 8d77a228ee8f |
children | 2d13cd63d492 |
rev | line source |
---|---|
662
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
638
diff
changeset
|
1 ;;; files.el --- file input and output commands for Emacs |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
638
diff
changeset
|
2 |
14734 | 3 ;; Copyright (C) 1985, 86, 87, 92, 93, |
32138 | 4 ;; 94, 95, 96, 97, 98, 99, 2000 Free Software Foundation, Inc. |
846
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
844
diff
changeset
|
5 |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
778
diff
changeset
|
6 ;; Maintainer: FSF |
337 | 7 |
8 ;; This file is part of GNU Emacs. | |
9 | |
10 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
11 ;; it under the terms of the GNU General Public License as published by | |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
778
diff
changeset
|
12 ;; the Free Software Foundation; either version 2, or (at your option) |
337 | 13 ;; any later version. |
14 | |
15 ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 ;; GNU General Public License for more details. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
14176
5e5779fa54cb
(auto-mode-alist): Add sgml-mode and html-mode.
Richard M. Stallman <rms@gnu.org>
parents:
14112
diff
changeset
|
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
5e5779fa54cb
(auto-mode-alist): Add sgml-mode and html-mode.
Richard M. Stallman <rms@gnu.org>
parents:
14112
diff
changeset
|
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
5e5779fa54cb
(auto-mode-alist): Add sgml-mode and html-mode.
Richard M. Stallman <rms@gnu.org>
parents:
14112
diff
changeset
|
23 ;; Boston, MA 02111-1307, USA. |
337 | 24 |
2307
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2108
diff
changeset
|
25 ;;; Commentary: |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2108
diff
changeset
|
26 |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2108
diff
changeset
|
27 ;; Defines most of Emacs's file- and directory-handling functions, |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2108
diff
changeset
|
28 ;; including basic file visiting, backup generation, link handling, |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2108
diff
changeset
|
29 ;; ITS-id version control, load- and write-hook handling, and the like. |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2108
diff
changeset
|
30 |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
778
diff
changeset
|
31 ;;; Code: |
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
778
diff
changeset
|
32 |
17673
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
33 (defgroup backup nil |
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
34 "Backups of edited data files." |
18316
1058f8684eca
(backup, find-file): Make `files' their parent.
Richard M. Stallman <rms@gnu.org>
parents:
18164
diff
changeset
|
35 :group 'files) |
17673
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
36 |
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
37 (defgroup find-file nil |
18316
1058f8684eca
(backup, find-file): Make `files' their parent.
Richard M. Stallman <rms@gnu.org>
parents:
18164
diff
changeset
|
38 "Finding files." |
1058f8684eca
(backup, find-file): Make `files' their parent.
Richard M. Stallman <rms@gnu.org>
parents:
18164
diff
changeset
|
39 :group 'files) |
337 | 40 |
17673
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
41 |
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
42 (defcustom delete-auto-save-files t |
20596
bda7ed815582
(delete-auto-save-files): Say in the doc string that
Eli Zaretskii <eliz@gnu.org>
parents:
20501
diff
changeset
|
43 "*Non-nil means delete auto-save file when a buffer is saved or killed. |
bda7ed815582
(delete-auto-save-files): Say in the doc string that
Eli Zaretskii <eliz@gnu.org>
parents:
20501
diff
changeset
|
44 |
bda7ed815582
(delete-auto-save-files): Say in the doc string that
Eli Zaretskii <eliz@gnu.org>
parents:
20501
diff
changeset
|
45 Note that auto-save file will not be deleted if the buffer is killed |
bda7ed815582
(delete-auto-save-files): Say in the doc string that
Eli Zaretskii <eliz@gnu.org>
parents:
20501
diff
changeset
|
46 when it has unsaved changes." |
17673
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
47 :type 'boolean |
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
48 :group 'auto-save) |
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
49 |
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
50 (defcustom directory-abbrev-alist |
337 | 51 nil |
52 "*Alist of abbreviations for file directories. | |
53 A list of elements of the form (FROM . TO), each meaning to replace | |
54 FROM with TO when it appears in a directory name. This replacement is | |
55 done when setting up the default directory of a newly visited file. | |
56 *Every* FROM string should start with `^'. | |
57 | |
4735
97c1e7309a2d
(directory-abbrev-alist): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
4699
diff
changeset
|
58 Do not use `~' in the TO strings. |
97c1e7309a2d
(directory-abbrev-alist): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
4699
diff
changeset
|
59 They should be ordinary absolute directory names. |
97c1e7309a2d
(directory-abbrev-alist): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
4699
diff
changeset
|
60 |
337 | 61 Use this feature when you have directories which you normally refer to |
62 via absolute symbolic links. Make TO the name of the link, and FROM | |
17673
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
63 the name it is linked to." |
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
64 :type '(repeat (cons :format "%v" |
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
65 :value ("" . "") |
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
66 (regexp :tag "From") |
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
67 (regexp :tag "To"))) |
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
68 :group 'abbrev |
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
69 :group 'find-file) |
337 | 70 |
71 ;;; Turn off backup files on VMS since it has version numbers. | |
17673
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
72 (defcustom make-backup-files (not (eq system-type 'vax-vms)) |
3634
1a0df59ac5fa
(make-backup-files): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
3630
diff
changeset
|
73 "*Non-nil means make a backup of a file the first time it is saved. |
337 | 74 This can be done by renaming the file or by copying. |
75 | |
76 Renaming means that Emacs renames the existing file so that it is a | |
77 backup file, then writes the buffer into a new file. Any other names | |
78 that the old file had will now refer to the backup file. The new file | |
79 is owned by you and its group is defaulted. | |
80 | |
81 Copying means that Emacs copies the existing file into the backup | |
82 file, then writes the buffer on top of the existing file. Any other | |
83 names that the old file had will now refer to the new (edited) file. | |
84 The file's owner and group are unchanged. | |
85 | |
86 The choice of renaming or copying is controlled by the variables | |
32138 | 87 `backup-by-copying', `backup-by-copying-when-linked', |
88 `backup-by-copying-when-mismatch' and | |
89 `backup-by-copying-when-privileged-mismatch'. See also `backup-inhibited'." | |
17673
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
90 :type 'boolean |
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
91 :group 'backup) |
337 | 92 |
93 ;; Do this so that local variables based on the file name | |
94 ;; are not overridden by the major mode. | |
95 (defvar backup-inhibited nil | |
4597
7ae2e83e40ea
(backup-inhibited): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
4466
diff
changeset
|
96 "Non-nil means don't make a backup, regardless of the other parameters. |
7ae2e83e40ea
(backup-inhibited): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
4466
diff
changeset
|
97 This variable is intended for use by making it local to a buffer. |
7ae2e83e40ea
(backup-inhibited): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
4466
diff
changeset
|
98 But it is local only if you make it local.") |
337 | 99 (put 'backup-inhibited 'permanent-local t) |
100 | |
17673
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
101 (defcustom backup-by-copying nil |
337 | 102 "*Non-nil means always use copying to create backup files. |
17673
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
103 See documentation of variable `make-backup-files'." |
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
104 :type 'boolean |
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
105 :group 'backup) |
337 | 106 |
17673
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
107 (defcustom backup-by-copying-when-linked nil |
337 | 108 "*Non-nil means use copying to create backups for files with multiple names. |
109 This causes the alternate names to refer to the latest version as edited. | |
17673
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
110 This variable is relevant only if `backup-by-copying' is nil." |
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
111 :type 'boolean |
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
112 :group 'backup) |
337 | 113 |
17673
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
114 (defcustom backup-by-copying-when-mismatch nil |
337 | 115 "*Non-nil means create backups by copying if this preserves owner or group. |
116 Renaming may still be used (subject to control of other variables) | |
117 when it would not result in changing the owner or group of the file; | |
118 that is, for files which are owned by you and whose group matches | |
119 the default for a new file created there by you. | |
17673
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
120 This variable is relevant only if `backup-by-copying' is nil." |
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
121 :type 'boolean |
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
122 :group 'backup) |
337 | 123 |
32138 | 124 (defcustom backup-by-copying-when-privileged-mismatch 200 |
125 "*Non-nil means create backups by copying to preserve a privileged owner. | |
126 Renaming may still be used (subject to control of other variables) | |
127 when it would not result in changing the owner of the file or if the owner | |
128 has a user id greater than the value of this variable. This is useful | |
129 when low-numbered uid's are used for special system users (such as root) | |
130 that must maintain ownership of certain files. | |
131 This variable is relevant only if `backup-by-copying' and | |
132 `backup-by-copying-when-mismatch' are nil." | |
133 :type '(choice (const nil) integer) | |
134 :group 'backup) | |
135 | |
136 (defun normal-backup-enable-predicate (name) | |
137 "Default `backup-enable-predicate' function. | |
138 Checks for files in `temporary-file-directory' or | |
139 `small-temporary-file-directory'." | |
140 (not (or (let ((comp (compare-strings temporary-file-directory 0 nil | |
141 name 0 nil))) | |
142 ;; Directory is under temporary-file-directory. | |
143 (and (not (eq comp t)) | |
144 (< comp (- (length temporary-file-directory))))) | |
145 (if small-temporary-file-directory | |
146 (let ((comp (compare-strings small-temporary-file-directory | |
147 0 nil | |
148 name 0 nil))) | |
149 ;; Directory is under small-temporary-file-directory. | |
150 (and (not (eq comp t)) | |
151 (< comp (- (length small-temporary-file-directory))))))))) | |
152 | |
153 (defvar backup-enable-predicate 'normal-backup-enable-predicate | |
337 | 154 "Predicate that looks at a file name and decides whether to make backups. |
29391
43abee1ebeca
(convert-standard-filename): Doc fix.
Dave Love <fx@gnu.org>
parents:
29111
diff
changeset
|
155 Called with an absolute file name as argument, it returns t to enable backup.") |
337 | 156 |
17673
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
157 (defcustom buffer-offer-save nil |
32138 | 158 "*Non-nil in a buffer means always offer to save buffer on exit. |
159 Do so even if the buffer is not visiting a file. | |
17673
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
160 Automatically local in all buffers." |
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
161 :type 'boolean |
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
162 :group 'backup) |
337 | 163 (make-variable-buffer-local 'buffer-offer-save) |
164 | |
17673
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
165 (defcustom find-file-existing-other-name t |
1395
f6f838c4a26e
(buffer-file-number): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1371
diff
changeset
|
166 "*Non-nil means find a file under alternative names, in existing buffers. |
f6f838c4a26e
(buffer-file-number): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1371
diff
changeset
|
167 This means if any existing buffer is visiting the file you want |
17673
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
168 under another name, you get the existing buffer instead of a new buffer." |
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
169 :type 'boolean |
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
170 :group 'find-file) |
1395
f6f838c4a26e
(buffer-file-number): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1371
diff
changeset
|
171 |
17673
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
172 (defcustom find-file-visit-truename nil |
1395
f6f838c4a26e
(buffer-file-number): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1371
diff
changeset
|
173 "*Non-nil means visit a file under its truename. |
f6f838c4a26e
(buffer-file-number): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1371
diff
changeset
|
174 The truename of a file is found by chasing all links |
17673
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
175 both at the file level and at the levels of the containing directories." |
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
176 :type 'boolean |
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
177 :group 'find-file) |
1395
f6f838c4a26e
(buffer-file-number): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1371
diff
changeset
|
178 |
17894
488536bc29c2
(path-separator, parse-colon-path): Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents:
17734
diff
changeset
|
179 (defcustom revert-without-query |
16687
049c87a96dca
Change defconsts to defvars.
Richard M. Stallman <rms@gnu.org>
parents:
16684
diff
changeset
|
180 nil |
16684
483a15efdf87
(find-file-revert-without-query): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
16614
diff
changeset
|
181 "*Specify which files should be reverted without query. |
483a15efdf87
(find-file-revert-without-query): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
16614
diff
changeset
|
182 The value is a list of regular expressions. |
483a15efdf87
(find-file-revert-without-query): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
16614
diff
changeset
|
183 If the file name matches one of these regular expressions, |
17894
488536bc29c2
(path-separator, parse-colon-path): Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents:
17734
diff
changeset
|
184 then `revert-buffer' reverts the file without querying |
17673
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
185 if the file has changed on disk and you have not edited the buffer." |
20018
eb109838909d
(revert-without-query): Fix customize type.
Karl Heuer <kwzh@gnu.org>
parents:
19812
diff
changeset
|
186 :type '(repeat regexp) |
17673
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
187 :group 'find-file) |
16684
483a15efdf87
(find-file-revert-without-query): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
16614
diff
changeset
|
188 |
1395
f6f838c4a26e
(buffer-file-number): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1371
diff
changeset
|
189 (defvar buffer-file-number nil |
f6f838c4a26e
(buffer-file-number): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1371
diff
changeset
|
190 "The device number and file number of the file visited in the current buffer. |
f6f838c4a26e
(buffer-file-number): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1371
diff
changeset
|
191 The value is a list of the form (FILENUM DEVNUM). |
f6f838c4a26e
(buffer-file-number): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1371
diff
changeset
|
192 This pair of numbers uniquely identifies the file. |
f6f838c4a26e
(buffer-file-number): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1371
diff
changeset
|
193 If the buffer is visiting a new file, the value is nil.") |
f6f838c4a26e
(buffer-file-number): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1371
diff
changeset
|
194 (make-variable-buffer-local 'buffer-file-number) |
f6f838c4a26e
(buffer-file-number): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1371
diff
changeset
|
195 (put 'buffer-file-number 'permanent-local t) |
f6f838c4a26e
(buffer-file-number): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1371
diff
changeset
|
196 |
15329
19008fd7774d
(buffer-file-numbers-unique): New variable;
Richard M. Stallman <rms@gnu.org>
parents:
15269
diff
changeset
|
197 (defvar buffer-file-numbers-unique (not (memq system-type '(windows-nt))) |
19008fd7774d
(buffer-file-numbers-unique): New variable;
Richard M. Stallman <rms@gnu.org>
parents:
15269
diff
changeset
|
198 "Non-nil means that buffer-file-number uniquely identifies files.") |
19008fd7774d
(buffer-file-numbers-unique): New variable;
Richard M. Stallman <rms@gnu.org>
parents:
15269
diff
changeset
|
199 |
22175
0a2e8ec2a766
(file-name-invalid-regexp): New variable, moved here from arc-mode.el
Eli Zaretskii <eliz@gnu.org>
parents:
22143
diff
changeset
|
200 (defvar file-name-invalid-regexp |
0a2e8ec2a766
(file-name-invalid-regexp): New variable, moved here from arc-mode.el
Eli Zaretskii <eliz@gnu.org>
parents:
22143
diff
changeset
|
201 (cond ((and (eq system-type 'ms-dos) (not (msdos-long-file-names))) |
22762
1de4d5771a8f
(file-name-invalid-regexp): Fix the part which handles colons in file names.
Eli Zaretskii <eliz@gnu.org>
parents:
22738
diff
changeset
|
202 (concat "^\\([^A-Z[-`a-z]\\|..+\\)?:\\|" ; colon except after drive |
22175
0a2e8ec2a766
(file-name-invalid-regexp): New variable, moved here from arc-mode.el
Eli Zaretskii <eliz@gnu.org>
parents:
22143
diff
changeset
|
203 "[+, ;=|<>\"?*]\\|\\[\\|\\]\\|" ; invalid characters |
23094
7099472e122b
(file-name-invalid-regexp): Fix regex for ms-dos without long file names.
Andreas Schwab <schwab@suse.de>
parents:
23000
diff
changeset
|
204 "[\000-\031]\\|" ; control characters |
22175
0a2e8ec2a766
(file-name-invalid-regexp): New variable, moved here from arc-mode.el
Eli Zaretskii <eliz@gnu.org>
parents:
22143
diff
changeset
|
205 "\\(/\\.\\.?[^/]\\)\\|" ; leading dots |
0a2e8ec2a766
(file-name-invalid-regexp): New variable, moved here from arc-mode.el
Eli Zaretskii <eliz@gnu.org>
parents:
22143
diff
changeset
|
206 "\\(/[^/.]+\\.[^/.]*\\.\\)")) ; more than a single dot |
0a2e8ec2a766
(file-name-invalid-regexp): New variable, moved here from arc-mode.el
Eli Zaretskii <eliz@gnu.org>
parents:
22143
diff
changeset
|
207 ((memq system-type '(ms-dos windows-nt)) |
22762
1de4d5771a8f
(file-name-invalid-regexp): Fix the part which handles colons in file names.
Eli Zaretskii <eliz@gnu.org>
parents:
22738
diff
changeset
|
208 (concat "^\\([^A-Z[-`a-z]\\|..+\\)?:\\|" ; colon except after drive |
22480
a85ad07a6e4b
(file-name-invalid-regexp): Add control characters for DOS/Windows
Eli Zaretskii <eliz@gnu.org>
parents:
22476
diff
changeset
|
209 "[|<>\"?*\000-\031]")) ; invalid characters |
22175
0a2e8ec2a766
(file-name-invalid-regexp): New variable, moved here from arc-mode.el
Eli Zaretskii <eliz@gnu.org>
parents:
22143
diff
changeset
|
210 (t "[\000]")) |
0a2e8ec2a766
(file-name-invalid-regexp): New variable, moved here from arc-mode.el
Eli Zaretskii <eliz@gnu.org>
parents:
22143
diff
changeset
|
211 "Regexp recognizing file names which aren't allowed by the filesystem.") |
0a2e8ec2a766
(file-name-invalid-regexp): New variable, moved here from arc-mode.el
Eli Zaretskii <eliz@gnu.org>
parents:
22143
diff
changeset
|
212 |
17673
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
213 (defcustom file-precious-flag nil |
337 | 214 "*Non-nil means protect against I/O errors while saving files. |
12105 | 215 Some modes set this non-nil in particular buffers. |
12145
bd3e59a5c0b3
(file-precious-flag): Doc clarification.
Karl Heuer <kwzh@gnu.org>
parents:
12105
diff
changeset
|
216 |
bd3e59a5c0b3
(file-precious-flag): Doc clarification.
Karl Heuer <kwzh@gnu.org>
parents:
12105
diff
changeset
|
217 This feature works by writing the new contents into a temporary file |
bd3e59a5c0b3
(file-precious-flag): Doc clarification.
Karl Heuer <kwzh@gnu.org>
parents:
12105
diff
changeset
|
218 and then renaming the temporary file to replace the original. |
bd3e59a5c0b3
(file-precious-flag): Doc clarification.
Karl Heuer <kwzh@gnu.org>
parents:
12105
diff
changeset
|
219 In this way, any I/O error in writing leaves the original untouched, |
bd3e59a5c0b3
(file-precious-flag): Doc clarification.
Karl Heuer <kwzh@gnu.org>
parents:
12105
diff
changeset
|
220 and there is never any instant where the file is nonexistent. |
bd3e59a5c0b3
(file-precious-flag): Doc clarification.
Karl Heuer <kwzh@gnu.org>
parents:
12105
diff
changeset
|
221 |
bd3e59a5c0b3
(file-precious-flag): Doc clarification.
Karl Heuer <kwzh@gnu.org>
parents:
12105
diff
changeset
|
222 Note that this feature forces backups to be made by copying. |
12105 | 223 Yet, at the same time, saving a precious file |
17673
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
224 breaks any hard links between it and other files." |
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
225 :type 'boolean |
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
226 :group 'backup) |
337 | 227 |
17673
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
228 (defcustom version-control nil |
337 | 229 "*Control use of version numbers for backup files. |
230 t means make numeric backup versions unconditionally. | |
231 nil means make them for files that have some already. | |
17673
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
232 `never' means do not make them." |
22582
122946298ba4
(version-control, delete-old-versions,
Andreas Schwab <schwab@suse.de>
parents:
22558
diff
changeset
|
233 :type '(choice (const :tag "Never" never) |
122946298ba4
(version-control, delete-old-versions,
Andreas Schwab <schwab@suse.de>
parents:
22558
diff
changeset
|
234 (const :tag "If existing" nil) |
122946298ba4
(version-control, delete-old-versions,
Andreas Schwab <schwab@suse.de>
parents:
22558
diff
changeset
|
235 (other :tag "Always" t)) |
17673
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
236 :group 'backup |
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
237 :group 'vc) |
337 | 238 |
17673
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
239 (defcustom dired-kept-versions 2 |
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
240 "*When cleaning directory, number of versions to keep." |
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
241 :type 'integer |
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
242 :group 'backup |
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
243 :group 'dired) |
337 | 244 |
17673
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
245 (defcustom delete-old-versions nil |
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
246 "*If t, delete excess backup versions silently. |
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
247 If nil, ask confirmation. Any other value prevents any trimming." |
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
248 :type '(choice (const :tag "Delete" t) |
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
249 (const :tag "Ask" nil) |
22582
122946298ba4
(version-control, delete-old-versions,
Andreas Schwab <schwab@suse.de>
parents:
22558
diff
changeset
|
250 (other :tag "Leave" other)) |
17673
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
251 :group 'backup) |
337 | 252 |
17673
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
253 (defcustom kept-old-versions 2 |
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
254 "*Number of oldest versions to keep when a new numbered backup is made." |
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
255 :type 'integer |
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
256 :group 'backup) |
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
257 |
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
258 (defcustom kept-new-versions 2 |
337 | 259 "*Number of newest versions to keep when a new numbered backup is made. |
17673
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
260 Includes the new backup. Must be > 0" |
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
261 :type 'integer |
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
262 :group 'backup) |
337 | 263 |
17673
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
264 (defcustom require-final-newline nil |
337 | 265 "*Value of t says silently ensure a file ends in a newline when it is saved. |
266 Non-nil but not t says ask user whether to add a newline when there isn't one. | |
17673
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
267 nil means don't add newlines." |
18340
f984a38eda06
(require-final-newline): Fix custom :type.
Richard M. Stallman <rms@gnu.org>
parents:
18317
diff
changeset
|
268 :type '(choice (const :tag "Off" nil) |
f984a38eda06
(require-final-newline): Fix custom :type.
Richard M. Stallman <rms@gnu.org>
parents:
18317
diff
changeset
|
269 (const :tag "Add" t) |
22582
122946298ba4
(version-control, delete-old-versions,
Andreas Schwab <schwab@suse.de>
parents:
22558
diff
changeset
|
270 (other :tag "Ask" ask)) |
17673
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
271 :group 'editing-basics) |
337 | 272 |
17673
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
273 (defcustom auto-save-default t |
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
274 "*Non-nil says by default do auto-saving of every file-visiting buffer." |
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
275 :type 'boolean |
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
276 :group 'auto-save) |
337 | 277 |
17673
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
278 (defcustom auto-save-visited-file-name nil |
337 | 279 "*Non-nil says auto-save a buffer in the file it is visiting, when practical. |
17673
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
280 Normally auto-save files are written under other names." |
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
281 :type 'boolean |
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
282 :group 'auto-save) |
337 | 283 |
32138 | 284 (defcustom auto-save-file-name-transforms |
285 '(("\\`/[^/]*:\\(.+/\\)*\\(.*\\)" "/tmp/\\2")) | |
286 "*Transforms to apply to buffer file name before making auto-save file name. | |
287 Each transform is a list (REGEXP REPLACEMENT): | |
288 REGEXP is a regular expression to match against the file name. | |
289 If it matches, `replace-match' is used to replace the | |
290 matching part with REPLACEMENT. | |
291 All the transforms in the list are tried, in the order they are listed. | |
292 When one transform applies, its result is final; | |
293 no further transforms are tried. | |
294 | |
295 The default value is set up to put the auto-save file into `/tmp' | |
296 for editing a remote file." | |
297 :group 'auto-save | |
298 :type '(repeat (list (string :tag "Regexp") (string :tag "Replacement"))) | |
299 :version "21.1") | |
300 | |
17673
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
301 (defcustom save-abbrevs nil |
337 | 302 "*Non-nil means save word abbrevs too when files are saved. |
17673
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
303 Loading an abbrev file sets this to t." |
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
304 :type 'boolean |
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
305 :group 'abbrev) |
337 | 306 |
17673
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
307 (defcustom find-file-run-dired t |
32138 | 308 "*Non-nil means allow `find-file' to visit directories. |
309 To visit the directory, `find-file' runs `find-directory-functions'." | |
17673
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
310 :type 'boolean |
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
311 :group 'find-file) |
337 | 312 |
32138 | 313 (defcustom find-directory-functions '(cvs-dired-noselect dired-noselect) |
314 "*List of functions to try in sequence to visit a directory. | |
315 Each function is called with the directory name as the sole argument | |
316 and should return either a buffer or nil." | |
317 :type '(hook :options (cvs-dired-noselect dired-noselect)) | |
318 :group 'find-file) | |
319 | |
1879
c9b4ece292cc
(find-file-hooks): Delete permanent-local property.
Richard M. Stallman <rms@gnu.org>
parents:
1799
diff
changeset
|
320 ;;;It is not useful to make this a local variable. |
c9b4ece292cc
(find-file-hooks): Delete permanent-local property.
Richard M. Stallman <rms@gnu.org>
parents:
1799
diff
changeset
|
321 ;;;(put 'find-file-not-found-hooks 'permanent-local t) |
337 | 322 (defvar find-file-not-found-hooks nil |
323 "List of functions to be called for `find-file' on nonexistent file. | |
324 These functions are called as soon as the error is detected. | |
32138 | 325 Variable `buffer-file-name' is already set up. |
337 | 326 The functions are called in the order given until one of them returns non-nil.") |
327 | |
1879
c9b4ece292cc
(find-file-hooks): Delete permanent-local property.
Richard M. Stallman <rms@gnu.org>
parents:
1799
diff
changeset
|
328 ;;;It is not useful to make this a local variable. |
c9b4ece292cc
(find-file-hooks): Delete permanent-local property.
Richard M. Stallman <rms@gnu.org>
parents:
1799
diff
changeset
|
329 ;;;(put 'find-file-hooks 'permanent-local t) |
337 | 330 (defvar find-file-hooks nil |
331 "List of functions to be called after a buffer is loaded from a file. | |
332 The buffer's local variables (if any) will have been processed before the | |
333 functions are called.") | |
334 | |
335 (defvar write-file-hooks nil | |
336 "List of functions to be called before writing out a buffer to a file. | |
337 If one of them returns non-nil, the file is considered already written | |
605 | 338 and the rest are not called. |
339 These hooks are considered to pertain to the visited file. | |
32138 | 340 So any buffer-local binding of `write-file-hooks' is |
341 discarded if you change the visited file name with \\[set-visited-file-name]. | |
14112
271075f54794
(write-contents-hooks): Call make-variable-buffer-local.
Karl Heuer <kwzh@gnu.org>
parents:
14025
diff
changeset
|
342 |
271075f54794
(write-contents-hooks): Call make-variable-buffer-local.
Karl Heuer <kwzh@gnu.org>
parents:
14025
diff
changeset
|
343 Don't make this variable buffer-local; instead, use `local-write-file-hooks'. |
271075f54794
(write-contents-hooks): Call make-variable-buffer-local.
Karl Heuer <kwzh@gnu.org>
parents:
14025
diff
changeset
|
344 See also `write-contents-hooks'.") |
4762
5eaa5d4eaaca
(local-write-file-hooks): Make this variable buffer-local.
Brian Fox <bfox@gnu.org>
parents:
4735
diff
changeset
|
345 ;;; However, in case someone does make it local... |
5eaa5d4eaaca
(local-write-file-hooks): Make this variable buffer-local.
Brian Fox <bfox@gnu.org>
parents:
4735
diff
changeset
|
346 (put 'write-file-hooks 'permanent-local t) |
2375
94e135f2d64d
(local-write-file-hooks): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
2335
diff
changeset
|
347 |
94e135f2d64d
(local-write-file-hooks): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
2335
diff
changeset
|
348 (defvar local-write-file-hooks nil |
94e135f2d64d
(local-write-file-hooks): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
2335
diff
changeset
|
349 "Just like `write-file-hooks', except intended for per-buffer use. |
94e135f2d64d
(local-write-file-hooks): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
2335
diff
changeset
|
350 The functions in this list are called before the ones in |
14112
271075f54794
(write-contents-hooks): Call make-variable-buffer-local.
Karl Heuer <kwzh@gnu.org>
parents:
14025
diff
changeset
|
351 `write-file-hooks'. |
271075f54794
(write-contents-hooks): Call make-variable-buffer-local.
Karl Heuer <kwzh@gnu.org>
parents:
14025
diff
changeset
|
352 |
271075f54794
(write-contents-hooks): Call make-variable-buffer-local.
Karl Heuer <kwzh@gnu.org>
parents:
14025
diff
changeset
|
353 This variable is meant to be used for hooks that have to do with a |
271075f54794
(write-contents-hooks): Call make-variable-buffer-local.
Karl Heuer <kwzh@gnu.org>
parents:
14025
diff
changeset
|
354 particular visited file. Therefore, it is a permanent local, so that |
271075f54794
(write-contents-hooks): Call make-variable-buffer-local.
Karl Heuer <kwzh@gnu.org>
parents:
14025
diff
changeset
|
355 changing the major mode does not clear it. However, calling |
271075f54794
(write-contents-hooks): Call make-variable-buffer-local.
Karl Heuer <kwzh@gnu.org>
parents:
14025
diff
changeset
|
356 `set-visited-file-name' does clear it.") |
4762
5eaa5d4eaaca
(local-write-file-hooks): Make this variable buffer-local.
Brian Fox <bfox@gnu.org>
parents:
4735
diff
changeset
|
357 (make-variable-buffer-local 'local-write-file-hooks) |
5eaa5d4eaaca
(local-write-file-hooks): Make this variable buffer-local.
Brian Fox <bfox@gnu.org>
parents:
4735
diff
changeset
|
358 (put 'local-write-file-hooks 'permanent-local t) |
605 | 359 |
360 (defvar write-contents-hooks nil | |
361 "List of functions to be called before writing out a buffer to a file. | |
362 If one of them returns non-nil, the file is considered already written | |
363 and the rest are not called. | |
14112
271075f54794
(write-contents-hooks): Call make-variable-buffer-local.
Karl Heuer <kwzh@gnu.org>
parents:
14025
diff
changeset
|
364 |
271075f54794
(write-contents-hooks): Call make-variable-buffer-local.
Karl Heuer <kwzh@gnu.org>
parents:
14025
diff
changeset
|
365 This variable is meant to be used for hooks that pertain to the |
271075f54794
(write-contents-hooks): Call make-variable-buffer-local.
Karl Heuer <kwzh@gnu.org>
parents:
14025
diff
changeset
|
366 buffer's contents, not to the particular visited file; thus, |
271075f54794
(write-contents-hooks): Call make-variable-buffer-local.
Karl Heuer <kwzh@gnu.org>
parents:
14025
diff
changeset
|
367 `set-visited-file-name' does not clear this variable; but changing the |
14176
5e5779fa54cb
(auto-mode-alist): Add sgml-mode and html-mode.
Richard M. Stallman <rms@gnu.org>
parents:
14112
diff
changeset
|
368 major mode does clear it. |
5e5779fa54cb
(auto-mode-alist): Add sgml-mode and html-mode.
Richard M. Stallman <rms@gnu.org>
parents:
14112
diff
changeset
|
369 |
5e5779fa54cb
(auto-mode-alist): Add sgml-mode and html-mode.
Richard M. Stallman <rms@gnu.org>
parents:
14112
diff
changeset
|
370 This variable automatically becomes buffer-local whenever it is set. |
16586
4176f951b342
(write-contents-hooks): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
16544
diff
changeset
|
371 If you use `add-hook' to add elements to the list, use nil for the |
14176
5e5779fa54cb
(auto-mode-alist): Add sgml-mode and html-mode.
Richard M. Stallman <rms@gnu.org>
parents:
14112
diff
changeset
|
372 LOCAL argument. |
14112
271075f54794
(write-contents-hooks): Call make-variable-buffer-local.
Karl Heuer <kwzh@gnu.org>
parents:
14025
diff
changeset
|
373 |
605 | 374 See also `write-file-hooks'.") |
14112
271075f54794
(write-contents-hooks): Call make-variable-buffer-local.
Karl Heuer <kwzh@gnu.org>
parents:
14025
diff
changeset
|
375 (make-variable-buffer-local 'write-contents-hooks) |
337 | 376 |
17673
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
377 (defcustom enable-local-variables t |
16440
e735290b9ebb
(hack-local-variables-prop-line):
Richard M. Stallman <rms@gnu.org>
parents:
16414
diff
changeset
|
378 "*Control use of local variables in files you visit. |
337 | 379 The value can be t, nil or something else. |
16440
e735290b9ebb
(hack-local-variables-prop-line):
Richard M. Stallman <rms@gnu.org>
parents:
16414
diff
changeset
|
380 A value of t means file local variables specifications are obeyed; |
337 | 381 nil means they are ignored; anything else means query. |
23657
7f5af9d1766d
(hack-local-variables): Test local-enable-local-variables.
Karl Heuer <kwzh@gnu.org>
parents:
23606
diff
changeset
|
382 This variable also controls use of major modes specified in |
7f5af9d1766d
(hack-local-variables): Test local-enable-local-variables.
Karl Heuer <kwzh@gnu.org>
parents:
23606
diff
changeset
|
383 a -*- line. |
337 | 384 |
23657
7f5af9d1766d
(hack-local-variables): Test local-enable-local-variables.
Karl Heuer <kwzh@gnu.org>
parents:
23606
diff
changeset
|
385 The command \\[normal-mode], when used interactively, |
7f5af9d1766d
(hack-local-variables): Test local-enable-local-variables.
Karl Heuer <kwzh@gnu.org>
parents:
23606
diff
changeset
|
386 always obeys file local variable specifications and the -*- line, |
7f5af9d1766d
(hack-local-variables): Test local-enable-local-variables.
Karl Heuer <kwzh@gnu.org>
parents:
23606
diff
changeset
|
387 and ignores this variable." |
17673
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
388 :type '(choice (const :tag "Obey" t) |
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
389 (const :tag "Ignore" nil) |
22582
122946298ba4
(version-control, delete-old-versions,
Andreas Schwab <schwab@suse.de>
parents:
22558
diff
changeset
|
390 (other :tag "Query" other)) |
17673
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
391 :group 'find-file) |
337 | 392 |
22476
f4871f285a9d
(user-init-file): Default value now nil.
Richard M. Stallman <rms@gnu.org>
parents:
22466
diff
changeset
|
393 (defvar local-enable-local-variables t |
f4871f285a9d
(user-init-file): Default value now nil.
Richard M. Stallman <rms@gnu.org>
parents:
22466
diff
changeset
|
394 "Like `enable-local-variables' but meant for buffer-local bindings. |
23657
7f5af9d1766d
(hack-local-variables): Test local-enable-local-variables.
Karl Heuer <kwzh@gnu.org>
parents:
23606
diff
changeset
|
395 The meaningful values are nil and non-nil. The default is non-nil. |
22476
f4871f285a9d
(user-init-file): Default value now nil.
Richard M. Stallman <rms@gnu.org>
parents:
22466
diff
changeset
|
396 If a major mode sets this to nil, buffer-locally, then any local |
23657
7f5af9d1766d
(hack-local-variables): Test local-enable-local-variables.
Karl Heuer <kwzh@gnu.org>
parents:
23606
diff
changeset
|
397 variables list in the file will be ignored. |
7f5af9d1766d
(hack-local-variables): Test local-enable-local-variables.
Karl Heuer <kwzh@gnu.org>
parents:
23606
diff
changeset
|
398 |
7f5af9d1766d
(hack-local-variables): Test local-enable-local-variables.
Karl Heuer <kwzh@gnu.org>
parents:
23606
diff
changeset
|
399 This variable does not affect the use of major modes |
7f5af9d1766d
(hack-local-variables): Test local-enable-local-variables.
Karl Heuer <kwzh@gnu.org>
parents:
23606
diff
changeset
|
400 specified in a -*- line.") |
22476
f4871f285a9d
(user-init-file): Default value now nil.
Richard M. Stallman <rms@gnu.org>
parents:
22466
diff
changeset
|
401 |
17673
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
402 (defcustom enable-local-eval 'maybe |
722
0a2391511b46
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
705
diff
changeset
|
403 "*Control processing of the \"variable\" `eval' in a file's local variables. |
0a2391511b46
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
705
diff
changeset
|
404 The value can be t, nil or something else. |
0a2391511b46
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
705
diff
changeset
|
405 A value of t means obey `eval' variables; |
0a2391511b46
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
705
diff
changeset
|
406 nil means ignore them; anything else means query. |
0a2391511b46
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
705
diff
changeset
|
407 |
0a2391511b46
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
705
diff
changeset
|
408 The command \\[normal-mode] always obeys local-variables lists |
17673
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
409 and ignores this variable." |
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
410 :type '(choice (const :tag "Obey" t) |
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
411 (const :tag "Ignore" nil) |
22582
122946298ba4
(version-control, delete-old-versions,
Andreas Schwab <schwab@suse.de>
parents:
22558
diff
changeset
|
412 (other :tag "Query" other)) |
17673
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
413 :group 'find-file) |
337 | 414 |
415 ;; Avoid losing in versions where CLASH_DETECTION is disabled. | |
416 (or (fboundp 'lock-buffer) | |
2575
1c5dca7628cb
(cd): Changed to use to resolve relative cd calls.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2553
diff
changeset
|
417 (defalias 'lock-buffer 'ignore)) |
337 | 418 (or (fboundp 'unlock-buffer) |
2575
1c5dca7628cb
(cd): Changed to use to resolve relative cd calls.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2553
diff
changeset
|
419 (defalias 'unlock-buffer 'ignore)) |
16214
fa8dbed4d40e
(file-locked-p): Alias to `ignore' if no file locking.
Richard M. Stallman <rms@gnu.org>
parents:
16187
diff
changeset
|
420 (or (fboundp 'file-locked-p) |
fa8dbed4d40e
(file-locked-p): Alias to `ignore' if no file locking.
Richard M. Stallman <rms@gnu.org>
parents:
16187
diff
changeset
|
421 (defalias 'file-locked-p 'ignore)) |
4186
45fc16fdf07e
(ange-ftp-completion-hook-function): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4148
diff
changeset
|
422 |
18316
1058f8684eca
(backup, find-file): Make `files' their parent.
Richard M. Stallman <rms@gnu.org>
parents:
18164
diff
changeset
|
423 (defvar view-read-only nil |
1058f8684eca
(backup, find-file): Make `files' their parent.
Richard M. Stallman <rms@gnu.org>
parents:
18164
diff
changeset
|
424 "*Non-nil means buffers visiting files read-only, do it in view mode.") |
1058f8684eca
(backup, find-file): Make `files' their parent.
Richard M. Stallman <rms@gnu.org>
parents:
18164
diff
changeset
|
425 |
22143
468e3489f1c0
(temporary-file-directory): Renamed from system-tmp-directory.
Richard M. Stallman <rms@gnu.org>
parents:
22084
diff
changeset
|
426 (defvar temporary-file-directory |
468e3489f1c0
(temporary-file-directory): Renamed from system-tmp-directory.
Richard M. Stallman <rms@gnu.org>
parents:
22084
diff
changeset
|
427 (file-name-as-directory |
22084
08f31e440c92
(system-tmp-directory): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
22026
diff
changeset
|
428 (cond ((memq system-type '(ms-dos windows-nt)) |
08f31e440c92
(system-tmp-directory): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
22026
diff
changeset
|
429 (or (getenv "TEMP") (getenv "TMPDIR") (getenv "TMP") "c:/temp")) |
08f31e440c92
(system-tmp-directory): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
22026
diff
changeset
|
430 ((memq system-type '(vax-vms axp-vms)) |
08f31e440c92
(system-tmp-directory): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
22026
diff
changeset
|
431 (or (getenv "TMPDIR") (getenv "TMP") (getenv "TEMP") "SYS$SCRATCH:")) |
08f31e440c92
(system-tmp-directory): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
22026
diff
changeset
|
432 (t |
08f31e440c92
(system-tmp-directory): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
22026
diff
changeset
|
433 (or (getenv "TMPDIR") (getenv "TMP") (getenv "TEMP") "/tmp")))) |
22143
468e3489f1c0
(temporary-file-directory): Renamed from system-tmp-directory.
Richard M. Stallman <rms@gnu.org>
parents:
22084
diff
changeset
|
434 "The directory for writing temporary files.") |
22084
08f31e440c92
(system-tmp-directory): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
22026
diff
changeset
|
435 |
32138 | 436 (defvar small-temporary-file-directory |
437 (if (eq system-type 'ms-dos) (getenv "TMPDIR")) | |
438 "The directory for writing small temporary files. | |
439 If non-nil, this directory is used instead of `temporary-file-directory' | |
440 by programs that create small temporary files. This is for systems that | |
441 have fast storage with limited space, such as a RAM disk.") | |
442 | |
22405
9a8440593987
(null-device): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
22403
diff
changeset
|
443 ;; The system null device. (Should reference NULL_DEVICE from C.) |
9a8440593987
(null-device): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
22403
diff
changeset
|
444 (defvar null-device "/dev/null" "The system null device.") |
9a8440593987
(null-device): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
22403
diff
changeset
|
445 |
4186
45fc16fdf07e
(ange-ftp-completion-hook-function): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4148
diff
changeset
|
446 (defun ange-ftp-completion-hook-function (op &rest args) |
32138 | 447 "Provides support for ange-ftp host name completion. |
448 Runs the usual ange-ftp hook, but only for completion operations." | |
449 ;; Having this here avoids the need to load ange-ftp when it's not | |
450 ;; really in use. | |
4186
45fc16fdf07e
(ange-ftp-completion-hook-function): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4148
diff
changeset
|
451 (if (memq op '(file-name-completion file-name-all-completions)) |
45fc16fdf07e
(ange-ftp-completion-hook-function): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4148
diff
changeset
|
452 (apply 'ange-ftp-hook-function op args) |
7142
2b445c15563e
(ange-ftp-completion-hook-function): Use new inhibit vars.
Richard M. Stallman <rms@gnu.org>
parents:
7036
diff
changeset
|
453 (let ((inhibit-file-name-handlers |
2b445c15563e
(ange-ftp-completion-hook-function): Use new inhibit vars.
Richard M. Stallman <rms@gnu.org>
parents:
7036
diff
changeset
|
454 (cons 'ange-ftp-completion-hook-function |
2b445c15563e
(ange-ftp-completion-hook-function): Use new inhibit vars.
Richard M. Stallman <rms@gnu.org>
parents:
7036
diff
changeset
|
455 (and (eq inhibit-file-name-operation op) |
2b445c15563e
(ange-ftp-completion-hook-function): Use new inhibit vars.
Richard M. Stallman <rms@gnu.org>
parents:
7036
diff
changeset
|
456 inhibit-file-name-handlers))) |
2b445c15563e
(ange-ftp-completion-hook-function): Use new inhibit vars.
Richard M. Stallman <rms@gnu.org>
parents:
7036
diff
changeset
|
457 (inhibit-file-name-operation op)) |
4186
45fc16fdf07e
(ange-ftp-completion-hook-function): New function.
Richard M. Stallman <rms@gnu.org>
parents:
4148
diff
changeset
|
458 (apply op args)))) |
13903
936c8364e15a
(abbrev-file-name): Drive letter can go beyond `Z' under MS-DOS/Novell.
Richard M. Stallman <rms@gnu.org>
parents:
13885
diff
changeset
|
459 |
936c8364e15a
(abbrev-file-name): Drive letter can go beyond `Z' under MS-DOS/Novell.
Richard M. Stallman <rms@gnu.org>
parents:
13885
diff
changeset
|
460 (defun convert-standard-filename (filename) |
936c8364e15a
(abbrev-file-name): Drive letter can go beyond `Z' under MS-DOS/Novell.
Richard M. Stallman <rms@gnu.org>
parents:
13885
diff
changeset
|
461 "Convert a standard file's name to something suitable for the current OS. |
936c8364e15a
(abbrev-file-name): Drive letter can go beyond `Z' under MS-DOS/Novell.
Richard M. Stallman <rms@gnu.org>
parents:
13885
diff
changeset
|
462 This function's standard definition is trivial; it just returns the argument. |
32138 | 463 However, on some systems, the function is redefined with a definition |
464 that really does change some file names to canonicalize certain | |
465 patterns and to guarantee valid names." | |
13903
936c8364e15a
(abbrev-file-name): Drive letter can go beyond `Z' under MS-DOS/Novell.
Richard M. Stallman <rms@gnu.org>
parents:
13885
diff
changeset
|
466 filename) |
337 | 467 |
468 (defun pwd () | |
469 "Show the current default directory." | |
470 (interactive nil) | |
471 (message "Directory %s" default-directory)) | |
472 | |
2575
1c5dca7628cb
(cd): Changed to use to resolve relative cd calls.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2553
diff
changeset
|
473 (defvar cd-path nil |
1c5dca7628cb
(cd): Changed to use to resolve relative cd calls.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2553
diff
changeset
|
474 "Value of the CDPATH environment variable, as a list. |
32240
f2a40beeddaa
(set-auto-mode): Ignore unknown -*- mode -*- rather than
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32138
diff
changeset
|
475 Not actually set up until the first time you use it.") |
2575
1c5dca7628cb
(cd): Changed to use to resolve relative cd calls.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2553
diff
changeset
|
476 |
1c5dca7628cb
(cd): Changed to use to resolve relative cd calls.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2553
diff
changeset
|
477 (defun parse-colon-path (cd-path) |
32138 | 478 "Explode a colon-separated search path into a list of directory names. |
479 \(For values of `colon' equal to `path-separator'.)" | |
480 ;; We could use split-string here. | |
2575
1c5dca7628cb
(cd): Changed to use to resolve relative cd calls.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2553
diff
changeset
|
481 (and cd-path |
1c5dca7628cb
(cd): Changed to use to resolve relative cd calls.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2553
diff
changeset
|
482 (let (cd-prefix cd-list (cd-start 0) cd-colon) |
11817
ba82c338bee3
(path-separator): Defined.
Richard M. Stallman <rms@gnu.org>
parents:
11739
diff
changeset
|
483 (setq cd-path (concat cd-path path-separator)) |
ba82c338bee3
(path-separator): Defined.
Richard M. Stallman <rms@gnu.org>
parents:
11739
diff
changeset
|
484 (while (setq cd-colon (string-match path-separator cd-path cd-start)) |
2575
1c5dca7628cb
(cd): Changed to use to resolve relative cd calls.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2553
diff
changeset
|
485 (setq cd-list |
3038
4bdac10d920a
(cd): Set cd-path to a list.
Richard M. Stallman <rms@gnu.org>
parents:
2896
diff
changeset
|
486 (nconc cd-list |
4216
6f940dcec978
(parse-colon-path): Really make nil, not ".", for empty path element.
Richard M. Stallman <rms@gnu.org>
parents:
4196
diff
changeset
|
487 (list (if (= cd-start cd-colon) |
6f940dcec978
(parse-colon-path): Really make nil, not ".", for empty path element.
Richard M. Stallman <rms@gnu.org>
parents:
4196
diff
changeset
|
488 nil |
6f940dcec978
(parse-colon-path): Really make nil, not ".", for empty path element.
Richard M. Stallman <rms@gnu.org>
parents:
4196
diff
changeset
|
489 (substitute-in-file-name |
4196
20f7ea2f83ef
(parse-colon-path): Turn empty substring into nil.
Richard M. Stallman <rms@gnu.org>
parents:
4186
diff
changeset
|
490 (file-name-as-directory |
20f7ea2f83ef
(parse-colon-path): Turn empty substring into nil.
Richard M. Stallman <rms@gnu.org>
parents:
4186
diff
changeset
|
491 (substring cd-path cd-start cd-colon))))))) |
2575
1c5dca7628cb
(cd): Changed to use to resolve relative cd calls.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2553
diff
changeset
|
492 (setq cd-start (+ cd-colon 1))) |
1c5dca7628cb
(cd): Changed to use to resolve relative cd calls.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2553
diff
changeset
|
493 cd-list))) |
1c5dca7628cb
(cd): Changed to use to resolve relative cd calls.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2553
diff
changeset
|
494 |
1c5dca7628cb
(cd): Changed to use to resolve relative cd calls.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2553
diff
changeset
|
495 (defun cd-absolute (dir) |
3652
31e55359fcdb
(cd): Use file-name-absolute-p.
Richard M. Stallman <rms@gnu.org>
parents:
3634
diff
changeset
|
496 "Change current directory to given absolute file name DIR." |
8362
87e1b76bbd6b
(set-auto-mode): Shorten scope of case-fold-search binding.
Richard M. Stallman <rms@gnu.org>
parents:
8251
diff
changeset
|
497 ;; Put the name into directory syntax now, |
87e1b76bbd6b
(set-auto-mode): Shorten scope of case-fold-search binding.
Richard M. Stallman <rms@gnu.org>
parents:
8251
diff
changeset
|
498 ;; because otherwise expand-file-name may give some bad results. |
337 | 499 (if (not (eq system-type 'vax-vms)) |
500 (setq dir (file-name-as-directory dir))) | |
8362
87e1b76bbd6b
(set-auto-mode): Shorten scope of case-fold-search binding.
Richard M. Stallman <rms@gnu.org>
parents:
8251
diff
changeset
|
501 (setq dir (abbreviate-file-name (expand-file-name dir))) |
337 | 502 (if (not (file-directory-p dir)) |
18819
881a46c98ddf
(set-auto-mode): If -*- line specifies a mode,
Richard M. Stallman <rms@gnu.org>
parents:
18676
diff
changeset
|
503 (if (file-exists-p dir) |
881a46c98ddf
(set-auto-mode): If -*- line specifies a mode,
Richard M. Stallman <rms@gnu.org>
parents:
18676
diff
changeset
|
504 (error "%s is not a directory" dir) |
19159
4bfebbf0f6a8
(cd-absolute): Add missing arg to `error'.
Richard M. Stallman <rms@gnu.org>
parents:
19145
diff
changeset
|
505 (error "%s: no such directory" dir)) |
337 | 506 (if (file-executable-p dir) |
507 (setq default-directory dir) | |
3038
4bdac10d920a
(cd): Set cd-path to a list.
Richard M. Stallman <rms@gnu.org>
parents:
2896
diff
changeset
|
508 (error "Cannot cd to %s: Permission denied" dir)))) |
337 | 509 |
2575
1c5dca7628cb
(cd): Changed to use to resolve relative cd calls.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2553
diff
changeset
|
510 (defun cd (dir) |
1c5dca7628cb
(cd): Changed to use to resolve relative cd calls.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2553
diff
changeset
|
511 "Make DIR become the current buffer's default directory. |
3652
31e55359fcdb
(cd): Use file-name-absolute-p.
Richard M. Stallman <rms@gnu.org>
parents:
3634
diff
changeset
|
512 If your environment includes a `CDPATH' variable, try each one of that |
31e55359fcdb
(cd): Use file-name-absolute-p.
Richard M. Stallman <rms@gnu.org>
parents:
3634
diff
changeset
|
513 colon-separated list of directories when resolving a relative directory name." |
12719
dde58f45b00a
(cd): When reading arg, use just directory as the default.
Richard M. Stallman <rms@gnu.org>
parents:
12591
diff
changeset
|
514 (interactive |
dde58f45b00a
(cd): When reading arg, use just directory as the default.
Richard M. Stallman <rms@gnu.org>
parents:
12591
diff
changeset
|
515 (list (read-file-name "Change default directory: " |
13095
8477c2dca6b0
(cd): Fix interactive spec to require match if there is no CDPATH.
Roland McGrath <roland@gnu.org>
parents:
13091
diff
changeset
|
516 default-directory default-directory |
8477c2dca6b0
(cd): Fix interactive spec to require match if there is no CDPATH.
Roland McGrath <roland@gnu.org>
parents:
13091
diff
changeset
|
517 (and (member cd-path '(nil ("./"))) |
8477c2dca6b0
(cd): Fix interactive spec to require match if there is no CDPATH.
Roland McGrath <roland@gnu.org>
parents:
13091
diff
changeset
|
518 (null (getenv "CDPATH")))))) |
3652
31e55359fcdb
(cd): Use file-name-absolute-p.
Richard M. Stallman <rms@gnu.org>
parents:
3634
diff
changeset
|
519 (if (file-name-absolute-p dir) |
31e55359fcdb
(cd): Use file-name-absolute-p.
Richard M. Stallman <rms@gnu.org>
parents:
3634
diff
changeset
|
520 (cd-absolute (expand-file-name dir)) |
31e55359fcdb
(cd): Use file-name-absolute-p.
Richard M. Stallman <rms@gnu.org>
parents:
3634
diff
changeset
|
521 (if (null cd-path) |
31e55359fcdb
(cd): Use file-name-absolute-p.
Richard M. Stallman <rms@gnu.org>
parents:
3634
diff
changeset
|
522 (let ((trypath (parse-colon-path (getenv "CDPATH")))) |
31e55359fcdb
(cd): Use file-name-absolute-p.
Richard M. Stallman <rms@gnu.org>
parents:
3634
diff
changeset
|
523 (setq cd-path (or trypath (list "./"))))) |
31e55359fcdb
(cd): Use file-name-absolute-p.
Richard M. Stallman <rms@gnu.org>
parents:
3634
diff
changeset
|
524 (if (not (catch 'found |
31e55359fcdb
(cd): Use file-name-absolute-p.
Richard M. Stallman <rms@gnu.org>
parents:
3634
diff
changeset
|
525 (mapcar |
31e55359fcdb
(cd): Use file-name-absolute-p.
Richard M. Stallman <rms@gnu.org>
parents:
3634
diff
changeset
|
526 (function (lambda (x) |
31e55359fcdb
(cd): Use file-name-absolute-p.
Richard M. Stallman <rms@gnu.org>
parents:
3634
diff
changeset
|
527 (let ((f (expand-file-name (concat x dir)))) |
31e55359fcdb
(cd): Use file-name-absolute-p.
Richard M. Stallman <rms@gnu.org>
parents:
3634
diff
changeset
|
528 (if (file-directory-p f) |
31e55359fcdb
(cd): Use file-name-absolute-p.
Richard M. Stallman <rms@gnu.org>
parents:
3634
diff
changeset
|
529 (progn |
31e55359fcdb
(cd): Use file-name-absolute-p.
Richard M. Stallman <rms@gnu.org>
parents:
3634
diff
changeset
|
530 (cd-absolute f) |
31e55359fcdb
(cd): Use file-name-absolute-p.
Richard M. Stallman <rms@gnu.org>
parents:
3634
diff
changeset
|
531 (throw 'found t)))))) |
31e55359fcdb
(cd): Use file-name-absolute-p.
Richard M. Stallman <rms@gnu.org>
parents:
3634
diff
changeset
|
532 cd-path) |
31e55359fcdb
(cd): Use file-name-absolute-p.
Richard M. Stallman <rms@gnu.org>
parents:
3634
diff
changeset
|
533 nil)) |
31e55359fcdb
(cd): Use file-name-absolute-p.
Richard M. Stallman <rms@gnu.org>
parents:
3634
diff
changeset
|
534 (error "No such directory found via CDPATH environment variable")))) |
2575
1c5dca7628cb
(cd): Changed to use to resolve relative cd calls.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2553
diff
changeset
|
535 |
337 | 536 (defun load-file (file) |
537 "Load the Lisp file named FILE." | |
34296
98daea465817
(load-file): Fix change of 2000-03-12.
Dave Love <fx@gnu.org>
parents:
34085
diff
changeset
|
538 ;; This is a case where .elc makes a lot of sense. |
98daea465817
(load-file): Fix change of 2000-03-12.
Dave Love <fx@gnu.org>
parents:
34085
diff
changeset
|
539 (interactive (list (let ((completion-ignored-extensions |
34368 | 540 (remove ".elc" completion-ignored-extensions))) |
34296
98daea465817
(load-file): Fix change of 2000-03-12.
Dave Love <fx@gnu.org>
parents:
34085
diff
changeset
|
541 (read-file-name "Load file: ")))) |
98daea465817
(load-file): Fix change of 2000-03-12.
Dave Love <fx@gnu.org>
parents:
34085
diff
changeset
|
542 (load (expand-file-name file) nil nil t)) |
337 | 543 |
544 (defun load-library (library) | |
545 "Load the library named LIBRARY. | |
546 This is an interface to the function `load'." | |
547 (interactive "sLoad library: ") | |
548 (load library)) | |
1134
05c961416bb5
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1109
diff
changeset
|
549 |
32138 | 550 (defun file-local-copy (file) |
1134
05c961416bb5
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1109
diff
changeset
|
551 "Copy the file FILE into a temporary file on this machine. |
05c961416bb5
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1109
diff
changeset
|
552 Returns the name of the local copy, or nil, if FILE is directly |
05c961416bb5
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1109
diff
changeset
|
553 accessible." |
32138 | 554 ;; This formerly had an optional BUFFER argument that wasn't used by |
555 ;; anything. | |
7030
9e51b51e8595
Pass operation to find-file-name-handler.
Karl Heuer <kwzh@gnu.org>
parents:
6899
diff
changeset
|
556 (let ((handler (find-file-name-handler file 'file-local-copy))) |
1134
05c961416bb5
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1109
diff
changeset
|
557 (if handler |
05c961416bb5
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1109
diff
changeset
|
558 (funcall handler 'file-local-copy file) |
05c961416bb5
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1109
diff
changeset
|
559 nil))) |
1395
f6f838c4a26e
(buffer-file-number): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1371
diff
changeset
|
560 |
8148
0035bfc4bc9d
(file-truename): Use iteration when possible.
Richard M. Stallman <rms@gnu.org>
parents:
8140
diff
changeset
|
561 (defun file-truename (filename &optional counter prev-dirs) |
1395
f6f838c4a26e
(buffer-file-number): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1371
diff
changeset
|
562 "Return the truename of FILENAME, which should be absolute. |
f6f838c4a26e
(buffer-file-number): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1371
diff
changeset
|
563 The truename of a file name is found by chasing symbolic links |
f6f838c4a26e
(buffer-file-number): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1371
diff
changeset
|
564 both at the level of the file and at the level of the directories |
8148
0035bfc4bc9d
(file-truename): Use iteration when possible.
Richard M. Stallman <rms@gnu.org>
parents:
8140
diff
changeset
|
565 containing it, until no links are left at any level. |
0035bfc4bc9d
(file-truename): Use iteration when possible.
Richard M. Stallman <rms@gnu.org>
parents:
8140
diff
changeset
|
566 |
0035bfc4bc9d
(file-truename): Use iteration when possible.
Richard M. Stallman <rms@gnu.org>
parents:
8140
diff
changeset
|
567 The arguments COUNTER and PREV-DIRS are used only in recursive calls. |
0035bfc4bc9d
(file-truename): Use iteration when possible.
Richard M. Stallman <rms@gnu.org>
parents:
8140
diff
changeset
|
568 Do not specify them in other calls." |
0035bfc4bc9d
(file-truename): Use iteration when possible.
Richard M. Stallman <rms@gnu.org>
parents:
8140
diff
changeset
|
569 ;; COUNTER can be a cons cell whose car is the count of how many more links |
0035bfc4bc9d
(file-truename): Use iteration when possible.
Richard M. Stallman <rms@gnu.org>
parents:
8140
diff
changeset
|
570 ;; to chase before getting an error. |
0035bfc4bc9d
(file-truename): Use iteration when possible.
Richard M. Stallman <rms@gnu.org>
parents:
8140
diff
changeset
|
571 ;; PREV-DIRS can be a cons cell whose car is an alist |
0035bfc4bc9d
(file-truename): Use iteration when possible.
Richard M. Stallman <rms@gnu.org>
parents:
8140
diff
changeset
|
572 ;; of truenames we've just recently computed. |
12202
0bd2831dff40
Test for "" too; let it go to expand-file-name if it is equal.
Simon Marshall <simon@gnu.org>
parents:
12145
diff
changeset
|
573 |
0bd2831dff40
Test for "" too; let it go to expand-file-name if it is equal.
Simon Marshall <simon@gnu.org>
parents:
12145
diff
changeset
|
574 ;; The last test looks dubious, maybe `+' is meant here? --simon. |
0bd2831dff40
Test for "" too; let it go to expand-file-name if it is equal.
Simon Marshall <simon@gnu.org>
parents:
12145
diff
changeset
|
575 (if (or (string= filename "") (string= filename "~") |
4965
dad86ab54e36
(find-backup-file-name): Don't fatal-error on
Richard M. Stallman <rms@gnu.org>
parents:
4847
diff
changeset
|
576 (and (string= (substring filename 0 1) "~") |
dad86ab54e36
(find-backup-file-name): Don't fatal-error on
Richard M. Stallman <rms@gnu.org>
parents:
4847
diff
changeset
|
577 (string-match "~[^/]*" filename))) |
2613
709f672f450e
(find-file-noselect): Do set buffer-file-name
Richard M. Stallman <rms@gnu.org>
parents:
2600
diff
changeset
|
578 (progn |
709f672f450e
(find-file-noselect): Do set buffer-file-name
Richard M. Stallman <rms@gnu.org>
parents:
2600
diff
changeset
|
579 (setq filename (expand-file-name filename)) |
709f672f450e
(find-file-noselect): Do set buffer-file-name
Richard M. Stallman <rms@gnu.org>
parents:
2600
diff
changeset
|
580 (if (string= filename "") |
709f672f450e
(find-file-noselect): Do set buffer-file-name
Richard M. Stallman <rms@gnu.org>
parents:
2600
diff
changeset
|
581 (setq filename "/")))) |
8148
0035bfc4bc9d
(file-truename): Use iteration when possible.
Richard M. Stallman <rms@gnu.org>
parents:
8140
diff
changeset
|
582 (or counter (setq counter (list 100))) |
8374
4c6590fc242e
(file-truename): Temporarily get rid of the
Richard M. Stallman <rms@gnu.org>
parents:
8362
diff
changeset
|
583 (let (done |
4c6590fc242e
(file-truename): Temporarily get rid of the
Richard M. Stallman <rms@gnu.org>
parents:
8362
diff
changeset
|
584 ;; For speed, remove the ange-ftp completion handler from the list. |
4c6590fc242e
(file-truename): Temporarily get rid of the
Richard M. Stallman <rms@gnu.org>
parents:
8362
diff
changeset
|
585 ;; We know it's not needed here. |
4c6590fc242e
(file-truename): Temporarily get rid of the
Richard M. Stallman <rms@gnu.org>
parents:
8362
diff
changeset
|
586 ;; For even more speed, do this only on the outermost call. |
4c6590fc242e
(file-truename): Temporarily get rid of the
Richard M. Stallman <rms@gnu.org>
parents:
8362
diff
changeset
|
587 (file-name-handler-alist |
4c6590fc242e
(file-truename): Temporarily get rid of the
Richard M. Stallman <rms@gnu.org>
parents:
8362
diff
changeset
|
588 (if prev-dirs file-name-handler-alist |
4c6590fc242e
(file-truename): Temporarily get rid of the
Richard M. Stallman <rms@gnu.org>
parents:
8362
diff
changeset
|
589 (let ((tem (copy-sequence file-name-handler-alist))) |
4c6590fc242e
(file-truename): Temporarily get rid of the
Richard M. Stallman <rms@gnu.org>
parents:
8362
diff
changeset
|
590 (delq (rassq 'ange-ftp-completion-hook-function tem) tem))))) |
4c6590fc242e
(file-truename): Temporarily get rid of the
Richard M. Stallman <rms@gnu.org>
parents:
8362
diff
changeset
|
591 (or prev-dirs (setq prev-dirs (list nil))) |
19680
90127e640713
(file-truename) [windows-nt]: Use the canonicalized
Geoff Voelker <voelker@cs.washington.edu>
parents:
19663
diff
changeset
|
592 |
90127e640713
(file-truename) [windows-nt]: Use the canonicalized
Geoff Voelker <voelker@cs.washington.edu>
parents:
19663
diff
changeset
|
593 ;; andrewi@harlequin.co.uk - none of the following code (except for |
90127e640713
(file-truename) [windows-nt]: Use the canonicalized
Geoff Voelker <voelker@cs.washington.edu>
parents:
19663
diff
changeset
|
594 ;; invoking the file-name handler) currently applies on Windows |
90127e640713
(file-truename) [windows-nt]: Use the canonicalized
Geoff Voelker <voelker@cs.washington.edu>
parents:
19663
diff
changeset
|
595 ;; (ie. there are no native symlinks), but there is an issue with |
90127e640713
(file-truename) [windows-nt]: Use the canonicalized
Geoff Voelker <voelker@cs.washington.edu>
parents:
19663
diff
changeset
|
596 ;; case differences being ignored by the OS, and short "8.3 DOS" |
90127e640713
(file-truename) [windows-nt]: Use the canonicalized
Geoff Voelker <voelker@cs.washington.edu>
parents:
19663
diff
changeset
|
597 ;; name aliases existing for all files. (The short names are not |
90127e640713
(file-truename) [windows-nt]: Use the canonicalized
Geoff Voelker <voelker@cs.washington.edu>
parents:
19663
diff
changeset
|
598 ;; reported by directory-files, but can be used to refer to files.) |
90127e640713
(file-truename) [windows-nt]: Use the canonicalized
Geoff Voelker <voelker@cs.washington.edu>
parents:
19663
diff
changeset
|
599 ;; It seems appropriate for file-truename to resolve these issues in |
90127e640713
(file-truename) [windows-nt]: Use the canonicalized
Geoff Voelker <voelker@cs.washington.edu>
parents:
19663
diff
changeset
|
600 ;; the most natural way, which on Windows is to call the function |
90127e640713
(file-truename) [windows-nt]: Use the canonicalized
Geoff Voelker <voelker@cs.washington.edu>
parents:
19663
diff
changeset
|
601 ;; `w32-long-file-name' - this returns the exact name of a file as |
90127e640713
(file-truename) [windows-nt]: Use the canonicalized
Geoff Voelker <voelker@cs.washington.edu>
parents:
19663
diff
changeset
|
602 ;; it is stored on disk (expanding short name aliases with the full |
90127e640713
(file-truename) [windows-nt]: Use the canonicalized
Geoff Voelker <voelker@cs.washington.edu>
parents:
19663
diff
changeset
|
603 ;; name in the process). |
90127e640713
(file-truename) [windows-nt]: Use the canonicalized
Geoff Voelker <voelker@cs.washington.edu>
parents:
19663
diff
changeset
|
604 (if (eq system-type 'windows-nt) |
90127e640713
(file-truename) [windows-nt]: Use the canonicalized
Geoff Voelker <voelker@cs.washington.edu>
parents:
19663
diff
changeset
|
605 (let ((handler (find-file-name-handler filename 'file-truename)) |
90127e640713
(file-truename) [windows-nt]: Use the canonicalized
Geoff Voelker <voelker@cs.washington.edu>
parents:
19663
diff
changeset
|
606 newname) |
90127e640713
(file-truename) [windows-nt]: Use the canonicalized
Geoff Voelker <voelker@cs.washington.edu>
parents:
19663
diff
changeset
|
607 ;; For file name that has a special handler, call handler. |
90127e640713
(file-truename) [windows-nt]: Use the canonicalized
Geoff Voelker <voelker@cs.washington.edu>
parents:
19663
diff
changeset
|
608 ;; This is so that ange-ftp can save time by doing a no-op. |
90127e640713
(file-truename) [windows-nt]: Use the canonicalized
Geoff Voelker <voelker@cs.washington.edu>
parents:
19663
diff
changeset
|
609 (if handler |
90127e640713
(file-truename) [windows-nt]: Use the canonicalized
Geoff Voelker <voelker@cs.washington.edu>
parents:
19663
diff
changeset
|
610 (setq filename (funcall handler 'file-truename filename)) |
90127e640713
(file-truename) [windows-nt]: Use the canonicalized
Geoff Voelker <voelker@cs.washington.edu>
parents:
19663
diff
changeset
|
611 ;; If filename contains a wildcard, newname will be the old name. |
32138 | 612 (if (string-match "[[*?]" filename) |
19680
90127e640713
(file-truename) [windows-nt]: Use the canonicalized
Geoff Voelker <voelker@cs.washington.edu>
parents:
19663
diff
changeset
|
613 (setq newname filename) |
90127e640713
(file-truename) [windows-nt]: Use the canonicalized
Geoff Voelker <voelker@cs.washington.edu>
parents:
19663
diff
changeset
|
614 ;; If filename doesn't exist, newname will be nil. |
90127e640713
(file-truename) [windows-nt]: Use the canonicalized
Geoff Voelker <voelker@cs.washington.edu>
parents:
19663
diff
changeset
|
615 (setq newname (w32-long-file-name filename))) |
90127e640713
(file-truename) [windows-nt]: Use the canonicalized
Geoff Voelker <voelker@cs.washington.edu>
parents:
19663
diff
changeset
|
616 (setq filename (or newname filename))) |
90127e640713
(file-truename) [windows-nt]: Use the canonicalized
Geoff Voelker <voelker@cs.washington.edu>
parents:
19663
diff
changeset
|
617 (setq done t))) |
90127e640713
(file-truename) [windows-nt]: Use the canonicalized
Geoff Voelker <voelker@cs.washington.edu>
parents:
19663
diff
changeset
|
618 |
8148
0035bfc4bc9d
(file-truename): Use iteration when possible.
Richard M. Stallman <rms@gnu.org>
parents:
8140
diff
changeset
|
619 ;; If this file directly leads to a link, process that iteratively |
0035bfc4bc9d
(file-truename): Use iteration when possible.
Richard M. Stallman <rms@gnu.org>
parents:
8140
diff
changeset
|
620 ;; so that we don't use lots of stack. |
0035bfc4bc9d
(file-truename): Use iteration when possible.
Richard M. Stallman <rms@gnu.org>
parents:
8140
diff
changeset
|
621 (while (not done) |
0035bfc4bc9d
(file-truename): Use iteration when possible.
Richard M. Stallman <rms@gnu.org>
parents:
8140
diff
changeset
|
622 (setcar counter (1- (car counter))) |
0035bfc4bc9d
(file-truename): Use iteration when possible.
Richard M. Stallman <rms@gnu.org>
parents:
8140
diff
changeset
|
623 (if (< (car counter) 0) |
0035bfc4bc9d
(file-truename): Use iteration when possible.
Richard M. Stallman <rms@gnu.org>
parents:
8140
diff
changeset
|
624 (error "Apparent cycle of symbolic links for %s" filename)) |
0035bfc4bc9d
(file-truename): Use iteration when possible.
Richard M. Stallman <rms@gnu.org>
parents:
8140
diff
changeset
|
625 (let ((handler (find-file-name-handler filename 'file-truename))) |
0035bfc4bc9d
(file-truename): Use iteration when possible.
Richard M. Stallman <rms@gnu.org>
parents:
8140
diff
changeset
|
626 ;; For file name that has a special handler, call handler. |
0035bfc4bc9d
(file-truename): Use iteration when possible.
Richard M. Stallman <rms@gnu.org>
parents:
8140
diff
changeset
|
627 ;; This is so that ange-ftp can save time by doing a no-op. |
0035bfc4bc9d
(file-truename): Use iteration when possible.
Richard M. Stallman <rms@gnu.org>
parents:
8140
diff
changeset
|
628 (if handler |
0035bfc4bc9d
(file-truename): Use iteration when possible.
Richard M. Stallman <rms@gnu.org>
parents:
8140
diff
changeset
|
629 (setq filename (funcall handler 'file-truename filename) |
0035bfc4bc9d
(file-truename): Use iteration when possible.
Richard M. Stallman <rms@gnu.org>
parents:
8140
diff
changeset
|
630 done t) |
9234
da491f38518c
(file-truename): If name has no dir, use default-directory.
Richard M. Stallman <rms@gnu.org>
parents:
9212
diff
changeset
|
631 (let ((dir (or (file-name-directory filename) default-directory)) |
8148
0035bfc4bc9d
(file-truename): Use iteration when possible.
Richard M. Stallman <rms@gnu.org>
parents:
8140
diff
changeset
|
632 target dirfile) |
0035bfc4bc9d
(file-truename): Use iteration when possible.
Richard M. Stallman <rms@gnu.org>
parents:
8140
diff
changeset
|
633 ;; Get the truename of the directory. |
0035bfc4bc9d
(file-truename): Use iteration when possible.
Richard M. Stallman <rms@gnu.org>
parents:
8140
diff
changeset
|
634 (setq dirfile (directory-file-name dir)) |
0035bfc4bc9d
(file-truename): Use iteration when possible.
Richard M. Stallman <rms@gnu.org>
parents:
8140
diff
changeset
|
635 ;; If these are equal, we have the (or a) root directory. |
0035bfc4bc9d
(file-truename): Use iteration when possible.
Richard M. Stallman <rms@gnu.org>
parents:
8140
diff
changeset
|
636 (or (string= dir dirfile) |
0035bfc4bc9d
(file-truename): Use iteration when possible.
Richard M. Stallman <rms@gnu.org>
parents:
8140
diff
changeset
|
637 ;; If this is the same dir we last got the truename for, |
0035bfc4bc9d
(file-truename): Use iteration when possible.
Richard M. Stallman <rms@gnu.org>
parents:
8140
diff
changeset
|
638 ;; save time--don't recalculate. |
0035bfc4bc9d
(file-truename): Use iteration when possible.
Richard M. Stallman <rms@gnu.org>
parents:
8140
diff
changeset
|
639 (if (assoc dir (car prev-dirs)) |
0035bfc4bc9d
(file-truename): Use iteration when possible.
Richard M. Stallman <rms@gnu.org>
parents:
8140
diff
changeset
|
640 (setq dir (cdr (assoc dir (car prev-dirs)))) |
0035bfc4bc9d
(file-truename): Use iteration when possible.
Richard M. Stallman <rms@gnu.org>
parents:
8140
diff
changeset
|
641 (let ((old dir) |
0035bfc4bc9d
(file-truename): Use iteration when possible.
Richard M. Stallman <rms@gnu.org>
parents:
8140
diff
changeset
|
642 (new (file-name-as-directory (file-truename dirfile counter prev-dirs)))) |
0035bfc4bc9d
(file-truename): Use iteration when possible.
Richard M. Stallman <rms@gnu.org>
parents:
8140
diff
changeset
|
643 (setcar prev-dirs (cons (cons old new) (car prev-dirs))) |
0035bfc4bc9d
(file-truename): Use iteration when possible.
Richard M. Stallman <rms@gnu.org>
parents:
8140
diff
changeset
|
644 (setq dir new)))) |
0035bfc4bc9d
(file-truename): Use iteration when possible.
Richard M. Stallman <rms@gnu.org>
parents:
8140
diff
changeset
|
645 (if (equal ".." (file-name-nondirectory filename)) |
0035bfc4bc9d
(file-truename): Use iteration when possible.
Richard M. Stallman <rms@gnu.org>
parents:
8140
diff
changeset
|
646 (setq filename |
0035bfc4bc9d
(file-truename): Use iteration when possible.
Richard M. Stallman <rms@gnu.org>
parents:
8140
diff
changeset
|
647 (directory-file-name (file-name-directory (directory-file-name dir))) |
0035bfc4bc9d
(file-truename): Use iteration when possible.
Richard M. Stallman <rms@gnu.org>
parents:
8140
diff
changeset
|
648 done t) |
0035bfc4bc9d
(file-truename): Use iteration when possible.
Richard M. Stallman <rms@gnu.org>
parents:
8140
diff
changeset
|
649 (if (equal "." (file-name-nondirectory filename)) |
0035bfc4bc9d
(file-truename): Use iteration when possible.
Richard M. Stallman <rms@gnu.org>
parents:
8140
diff
changeset
|
650 (setq filename (directory-file-name dir) |
0035bfc4bc9d
(file-truename): Use iteration when possible.
Richard M. Stallman <rms@gnu.org>
parents:
8140
diff
changeset
|
651 done t) |
0035bfc4bc9d
(file-truename): Use iteration when possible.
Richard M. Stallman <rms@gnu.org>
parents:
8140
diff
changeset
|
652 ;; Put it back on the file name. |
0035bfc4bc9d
(file-truename): Use iteration when possible.
Richard M. Stallman <rms@gnu.org>
parents:
8140
diff
changeset
|
653 (setq filename (concat dir (file-name-nondirectory filename))) |
0035bfc4bc9d
(file-truename): Use iteration when possible.
Richard M. Stallman <rms@gnu.org>
parents:
8140
diff
changeset
|
654 ;; Is the file name the name of a link? |
0035bfc4bc9d
(file-truename): Use iteration when possible.
Richard M. Stallman <rms@gnu.org>
parents:
8140
diff
changeset
|
655 (setq target (file-symlink-p filename)) |
0035bfc4bc9d
(file-truename): Use iteration when possible.
Richard M. Stallman <rms@gnu.org>
parents:
8140
diff
changeset
|
656 (if target |
0035bfc4bc9d
(file-truename): Use iteration when possible.
Richard M. Stallman <rms@gnu.org>
parents:
8140
diff
changeset
|
657 ;; Yes => chase that link, then start all over |
0035bfc4bc9d
(file-truename): Use iteration when possible.
Richard M. Stallman <rms@gnu.org>
parents:
8140
diff
changeset
|
658 ;; since the link may point to a directory name that uses links. |
0035bfc4bc9d
(file-truename): Use iteration when possible.
Richard M. Stallman <rms@gnu.org>
parents:
8140
diff
changeset
|
659 ;; We can't safely use expand-file-name here |
0035bfc4bc9d
(file-truename): Use iteration when possible.
Richard M. Stallman <rms@gnu.org>
parents:
8140
diff
changeset
|
660 ;; since target might look like foo/../bar where foo |
0035bfc4bc9d
(file-truename): Use iteration when possible.
Richard M. Stallman <rms@gnu.org>
parents:
8140
diff
changeset
|
661 ;; is itself a link. Instead, we handle . and .. above. |
0035bfc4bc9d
(file-truename): Use iteration when possible.
Richard M. Stallman <rms@gnu.org>
parents:
8140
diff
changeset
|
662 (setq filename |
0035bfc4bc9d
(file-truename): Use iteration when possible.
Richard M. Stallman <rms@gnu.org>
parents:
8140
diff
changeset
|
663 (if (file-name-absolute-p target) |
0035bfc4bc9d
(file-truename): Use iteration when possible.
Richard M. Stallman <rms@gnu.org>
parents:
8140
diff
changeset
|
664 target |
0035bfc4bc9d
(file-truename): Use iteration when possible.
Richard M. Stallman <rms@gnu.org>
parents:
8140
diff
changeset
|
665 (concat dir target)) |
0035bfc4bc9d
(file-truename): Use iteration when possible.
Richard M. Stallman <rms@gnu.org>
parents:
8140
diff
changeset
|
666 done nil) |
0035bfc4bc9d
(file-truename): Use iteration when possible.
Richard M. Stallman <rms@gnu.org>
parents:
8140
diff
changeset
|
667 ;; No, we are done! |
0035bfc4bc9d
(file-truename): Use iteration when possible.
Richard M. Stallman <rms@gnu.org>
parents:
8140
diff
changeset
|
668 (setq done t)))))))) |
0035bfc4bc9d
(file-truename): Use iteration when possible.
Richard M. Stallman <rms@gnu.org>
parents:
8140
diff
changeset
|
669 filename)) |
1672
ecf43116a845
The find-file-name-handler function in ../src/fileio.c is now
Jim Blandy <jimb@redhat.com>
parents:
1537
diff
changeset
|
670 |
3260
eecf2c0ca9b9
(file-chase-links): New function.
Richard M. Stallman <rms@gnu.org>
parents:
3240
diff
changeset
|
671 (defun file-chase-links (filename) |
eecf2c0ca9b9
(file-chase-links): New function.
Richard M. Stallman <rms@gnu.org>
parents:
3240
diff
changeset
|
672 "Chase links in FILENAME until a name that is not a link. |
eecf2c0ca9b9
(file-chase-links): New function.
Richard M. Stallman <rms@gnu.org>
parents:
3240
diff
changeset
|
673 Does not examine containing directories for links, |
eecf2c0ca9b9
(file-chase-links): New function.
Richard M. Stallman <rms@gnu.org>
parents:
3240
diff
changeset
|
674 unlike `file-truename'." |
eecf2c0ca9b9
(file-chase-links): New function.
Richard M. Stallman <rms@gnu.org>
parents:
3240
diff
changeset
|
675 (let (tem (count 100) (newname filename)) |
eecf2c0ca9b9
(file-chase-links): New function.
Richard M. Stallman <rms@gnu.org>
parents:
3240
diff
changeset
|
676 (while (setq tem (file-symlink-p newname)) |
18466
535a18a6b623
(file-chase-links): When handling .., make newname absolute.
Richard M. Stallman <rms@gnu.org>
parents:
18340
diff
changeset
|
677 (save-match-data |
535a18a6b623
(file-chase-links): When handling .., make newname absolute.
Richard M. Stallman <rms@gnu.org>
parents:
18340
diff
changeset
|
678 (if (= count 0) |
535a18a6b623
(file-chase-links): When handling .., make newname absolute.
Richard M. Stallman <rms@gnu.org>
parents:
18340
diff
changeset
|
679 (error "Apparent cycle of symbolic links for %s" filename)) |
535a18a6b623
(file-chase-links): When handling .., make newname absolute.
Richard M. Stallman <rms@gnu.org>
parents:
18340
diff
changeset
|
680 ;; In the context of a link, `//' doesn't mean what Emacs thinks. |
535a18a6b623
(file-chase-links): When handling .., make newname absolute.
Richard M. Stallman <rms@gnu.org>
parents:
18340
diff
changeset
|
681 (while (string-match "//+" tem) |
535a18a6b623
(file-chase-links): When handling .., make newname absolute.
Richard M. Stallman <rms@gnu.org>
parents:
18340
diff
changeset
|
682 (setq tem (replace-match "/" nil nil tem))) |
535a18a6b623
(file-chase-links): When handling .., make newname absolute.
Richard M. Stallman <rms@gnu.org>
parents:
18340
diff
changeset
|
683 ;; Handle `..' by hand, since it needs to work in the |
535a18a6b623
(file-chase-links): When handling .., make newname absolute.
Richard M. Stallman <rms@gnu.org>
parents:
18340
diff
changeset
|
684 ;; target of any directory symlink. |
535a18a6b623
(file-chase-links): When handling .., make newname absolute.
Richard M. Stallman <rms@gnu.org>
parents:
18340
diff
changeset
|
685 ;; This code is not quite complete; it does not handle |
535a18a6b623
(file-chase-links): When handling .., make newname absolute.
Richard M. Stallman <rms@gnu.org>
parents:
18340
diff
changeset
|
686 ;; embedded .. in some cases such as ./../foo and foo/bar/../../../lose. |
535a18a6b623
(file-chase-links): When handling .., make newname absolute.
Richard M. Stallman <rms@gnu.org>
parents:
18340
diff
changeset
|
687 (while (string-match "\\`\\.\\./" tem) |
535a18a6b623
(file-chase-links): When handling .., make newname absolute.
Richard M. Stallman <rms@gnu.org>
parents:
18340
diff
changeset
|
688 (setq tem (substring tem 3)) |
535a18a6b623
(file-chase-links): When handling .., make newname absolute.
Richard M. Stallman <rms@gnu.org>
parents:
18340
diff
changeset
|
689 (setq newname (expand-file-name newname)) |
535a18a6b623
(file-chase-links): When handling .., make newname absolute.
Richard M. Stallman <rms@gnu.org>
parents:
18340
diff
changeset
|
690 ;; Chase links in the default dir of the symlink. |
535a18a6b623
(file-chase-links): When handling .., make newname absolute.
Richard M. Stallman <rms@gnu.org>
parents:
18340
diff
changeset
|
691 (setq newname |
535a18a6b623
(file-chase-links): When handling .., make newname absolute.
Richard M. Stallman <rms@gnu.org>
parents:
18340
diff
changeset
|
692 (file-chase-links |
535a18a6b623
(file-chase-links): When handling .., make newname absolute.
Richard M. Stallman <rms@gnu.org>
parents:
18340
diff
changeset
|
693 (directory-file-name (file-name-directory newname)))) |
535a18a6b623
(file-chase-links): When handling .., make newname absolute.
Richard M. Stallman <rms@gnu.org>
parents:
18340
diff
changeset
|
694 ;; Now find the parent of that dir. |
535a18a6b623
(file-chase-links): When handling .., make newname absolute.
Richard M. Stallman <rms@gnu.org>
parents:
18340
diff
changeset
|
695 (setq newname (file-name-directory newname))) |
535a18a6b623
(file-chase-links): When handling .., make newname absolute.
Richard M. Stallman <rms@gnu.org>
parents:
18340
diff
changeset
|
696 (setq newname (expand-file-name tem (file-name-directory newname))) |
535a18a6b623
(file-chase-links): When handling .., make newname absolute.
Richard M. Stallman <rms@gnu.org>
parents:
18340
diff
changeset
|
697 (setq count (1- count)))) |
3260
eecf2c0ca9b9
(file-chase-links): New function.
Richard M. Stallman <rms@gnu.org>
parents:
3240
diff
changeset
|
698 newname)) |
337 | 699 |
16831
3626b6cd2ad1
(switch-to-buffer-other-frame)
Richard M. Stallman <rms@gnu.org>
parents:
16792
diff
changeset
|
700 (defun switch-to-buffer-other-window (buffer &optional norecord) |
3626b6cd2ad1
(switch-to-buffer-other-frame)
Richard M. Stallman <rms@gnu.org>
parents:
16792
diff
changeset
|
701 "Select buffer BUFFER in another window. |
3626b6cd2ad1
(switch-to-buffer-other-frame)
Richard M. Stallman <rms@gnu.org>
parents:
16792
diff
changeset
|
702 Optional second arg NORECORD non-nil means |
3626b6cd2ad1
(switch-to-buffer-other-frame)
Richard M. Stallman <rms@gnu.org>
parents:
16792
diff
changeset
|
703 do not put this buffer at the front of the list of recently selected ones." |
337 | 704 (interactive "BSwitch to buffer in other window: ") |
705 (let ((pop-up-windows t)) | |
16831
3626b6cd2ad1
(switch-to-buffer-other-frame)
Richard M. Stallman <rms@gnu.org>
parents:
16792
diff
changeset
|
706 (pop-to-buffer buffer t norecord))) |
337 | 707 |
16831
3626b6cd2ad1
(switch-to-buffer-other-frame)
Richard M. Stallman <rms@gnu.org>
parents:
16792
diff
changeset
|
708 (defun switch-to-buffer-other-frame (buffer &optional norecord) |
3626b6cd2ad1
(switch-to-buffer-other-frame)
Richard M. Stallman <rms@gnu.org>
parents:
16792
diff
changeset
|
709 "Switch to buffer BUFFER in another frame. |
3626b6cd2ad1
(switch-to-buffer-other-frame)
Richard M. Stallman <rms@gnu.org>
parents:
16792
diff
changeset
|
710 Optional second arg NORECORD non-nil means |
3626b6cd2ad1
(switch-to-buffer-other-frame)
Richard M. Stallman <rms@gnu.org>
parents:
16792
diff
changeset
|
711 do not put this buffer at the front of the list of recently selected ones." |
778 | 712 (interactive "BSwitch to buffer in other frame: ") |
713 (let ((pop-up-frames t)) | |
16831
3626b6cd2ad1
(switch-to-buffer-other-frame)
Richard M. Stallman <rms@gnu.org>
parents:
16792
diff
changeset
|
714 (pop-to-buffer buffer t norecord) |
8165
02ee07034f11
(switch-to-buffer-other-frame): Raise the frame.
Richard M. Stallman <rms@gnu.org>
parents:
8160
diff
changeset
|
715 (raise-frame (window-frame (selected-window))))) |
423 | 716 |
24166
3d25e1fc71aa
(find-file-noselect): Do wildcard processing only
Richard M. Stallman <rms@gnu.org>
parents:
24061
diff
changeset
|
717 (defun find-file (filename &optional wildcards) |
337 | 718 "Edit file FILENAME. |
719 Switch to a buffer visiting file FILENAME, | |
24166
3d25e1fc71aa
(find-file-noselect): Do wildcard processing only
Richard M. Stallman <rms@gnu.org>
parents:
24061
diff
changeset
|
720 creating one if none already exists. |
3d25e1fc71aa
(find-file-noselect): Do wildcard processing only
Richard M. Stallman <rms@gnu.org>
parents:
24061
diff
changeset
|
721 Interactively, or if WILDCARDS is non-nil in a call from Lisp, |
32138 | 722 expand wildcards (if any) and visit multiple files. Wildcard expansion |
723 can be suppressed by setting `find-file-wildcards'." | |
24166
3d25e1fc71aa
(find-file-noselect): Do wildcard processing only
Richard M. Stallman <rms@gnu.org>
parents:
24061
diff
changeset
|
724 (interactive "FFind file: \np") |
24167
6b14770eb944
(find-file): If find-file-noselect returns a list,
Richard M. Stallman <rms@gnu.org>
parents:
24166
diff
changeset
|
725 (let ((value (find-file-noselect filename nil nil wildcards))) |
6b14770eb944
(find-file): If find-file-noselect returns a list,
Richard M. Stallman <rms@gnu.org>
parents:
24166
diff
changeset
|
726 (if (listp value) |
6b14770eb944
(find-file): If find-file-noselect returns a list,
Richard M. Stallman <rms@gnu.org>
parents:
24166
diff
changeset
|
727 (mapcar 'switch-to-buffer (nreverse value)) |
6b14770eb944
(find-file): If find-file-noselect returns a list,
Richard M. Stallman <rms@gnu.org>
parents:
24166
diff
changeset
|
728 (switch-to-buffer value)))) |
337 | 729 |
24166
3d25e1fc71aa
(find-file-noselect): Do wildcard processing only
Richard M. Stallman <rms@gnu.org>
parents:
24061
diff
changeset
|
730 (defun find-file-other-window (filename &optional wildcards) |
337 | 731 "Edit file FILENAME, in another window. |
732 May create a new window, or reuse an existing one. | |
24166
3d25e1fc71aa
(find-file-noselect): Do wildcard processing only
Richard M. Stallman <rms@gnu.org>
parents:
24061
diff
changeset
|
733 See the function `display-buffer'. |
3d25e1fc71aa
(find-file-noselect): Do wildcard processing only
Richard M. Stallman <rms@gnu.org>
parents:
24061
diff
changeset
|
734 Interactively, or if WILDCARDS is non-nil in a call from Lisp, |
3d25e1fc71aa
(find-file-noselect): Do wildcard processing only
Richard M. Stallman <rms@gnu.org>
parents:
24061
diff
changeset
|
735 expand wildcards (if any) and visit multiple files." |
3d25e1fc71aa
(find-file-noselect): Do wildcard processing only
Richard M. Stallman <rms@gnu.org>
parents:
24061
diff
changeset
|
736 (interactive "FFind file in other window: \np") |
24167
6b14770eb944
(find-file): If find-file-noselect returns a list,
Richard M. Stallman <rms@gnu.org>
parents:
24166
diff
changeset
|
737 (let ((value (find-file-noselect filename nil nil wildcards))) |
6b14770eb944
(find-file): If find-file-noselect returns a list,
Richard M. Stallman <rms@gnu.org>
parents:
24166
diff
changeset
|
738 (if (listp value) |
6b14770eb944
(find-file): If find-file-noselect returns a list,
Richard M. Stallman <rms@gnu.org>
parents:
24166
diff
changeset
|
739 (progn |
6b14770eb944
(find-file): If find-file-noselect returns a list,
Richard M. Stallman <rms@gnu.org>
parents:
24166
diff
changeset
|
740 (setq value (nreverse value)) |
6b14770eb944
(find-file): If find-file-noselect returns a list,
Richard M. Stallman <rms@gnu.org>
parents:
24166
diff
changeset
|
741 (switch-to-buffer-other-window (car value)) |
6b14770eb944
(find-file): If find-file-noselect returns a list,
Richard M. Stallman <rms@gnu.org>
parents:
24166
diff
changeset
|
742 (mapcar 'switch-to-buffer (cdr value))) |
6b14770eb944
(find-file): If find-file-noselect returns a list,
Richard M. Stallman <rms@gnu.org>
parents:
24166
diff
changeset
|
743 (switch-to-buffer-other-window value)))) |
337 | 744 |
24166
3d25e1fc71aa
(find-file-noselect): Do wildcard processing only
Richard M. Stallman <rms@gnu.org>
parents:
24061
diff
changeset
|
745 (defun find-file-other-frame (filename &optional wildcards) |
778 | 746 "Edit file FILENAME, in another frame. |
747 May create a new frame, or reuse an existing one. | |
24166
3d25e1fc71aa
(find-file-noselect): Do wildcard processing only
Richard M. Stallman <rms@gnu.org>
parents:
24061
diff
changeset
|
748 See the function `display-buffer'. |
3d25e1fc71aa
(find-file-noselect): Do wildcard processing only
Richard M. Stallman <rms@gnu.org>
parents:
24061
diff
changeset
|
749 Interactively, or if WILDCARDS is non-nil in a call from Lisp, |
3d25e1fc71aa
(find-file-noselect): Do wildcard processing only
Richard M. Stallman <rms@gnu.org>
parents:
24061
diff
changeset
|
750 expand wildcards (if any) and visit multiple files." |
3d25e1fc71aa
(find-file-noselect): Do wildcard processing only
Richard M. Stallman <rms@gnu.org>
parents:
24061
diff
changeset
|
751 (interactive "FFind file in other frame: \np") |
24167
6b14770eb944
(find-file): If find-file-noselect returns a list,
Richard M. Stallman <rms@gnu.org>
parents:
24166
diff
changeset
|
752 (let ((value (find-file-noselect filename nil nil wildcards))) |
6b14770eb944
(find-file): If find-file-noselect returns a list,
Richard M. Stallman <rms@gnu.org>
parents:
24166
diff
changeset
|
753 (if (listp value) |
6b14770eb944
(find-file): If find-file-noselect returns a list,
Richard M. Stallman <rms@gnu.org>
parents:
24166
diff
changeset
|
754 (progn |
6b14770eb944
(find-file): If find-file-noselect returns a list,
Richard M. Stallman <rms@gnu.org>
parents:
24166
diff
changeset
|
755 (setq value (nreverse value)) |
6b14770eb944
(find-file): If find-file-noselect returns a list,
Richard M. Stallman <rms@gnu.org>
parents:
24166
diff
changeset
|
756 (switch-to-buffer-other-frame (car value)) |
6b14770eb944
(find-file): If find-file-noselect returns a list,
Richard M. Stallman <rms@gnu.org>
parents:
24166
diff
changeset
|
757 (mapcar 'switch-to-buffer (cdr value))) |
6b14770eb944
(find-file): If find-file-noselect returns a list,
Richard M. Stallman <rms@gnu.org>
parents:
24166
diff
changeset
|
758 (switch-to-buffer-other-frame value)))) |
423 | 759 |
24166
3d25e1fc71aa
(find-file-noselect): Do wildcard processing only
Richard M. Stallman <rms@gnu.org>
parents:
24061
diff
changeset
|
760 (defun find-file-read-only (filename &optional wildcards) |
337 | 761 "Edit file FILENAME but don't allow changes. |
32138 | 762 Like `find-file' but marks buffer as read-only. |
337 | 763 Use \\[toggle-read-only] to permit editing." |
24166
3d25e1fc71aa
(find-file-noselect): Do wildcard processing only
Richard M. Stallman <rms@gnu.org>
parents:
24061
diff
changeset
|
764 (interactive "fFind file read-only: \np") |
3d25e1fc71aa
(find-file-noselect): Do wildcard processing only
Richard M. Stallman <rms@gnu.org>
parents:
24061
diff
changeset
|
765 (find-file filename wildcards) |
18316
1058f8684eca
(backup, find-file): Make `files' their parent.
Richard M. Stallman <rms@gnu.org>
parents:
18164
diff
changeset
|
766 (toggle-read-only 1) |
3280
3b3717164db0
(find-file-run-dired): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
3263
diff
changeset
|
767 (current-buffer)) |
337 | 768 |
24166
3d25e1fc71aa
(find-file-noselect): Do wildcard processing only
Richard M. Stallman <rms@gnu.org>
parents:
24061
diff
changeset
|
769 (defun find-file-read-only-other-window (filename &optional wildcards) |
337 | 770 "Edit file FILENAME in another window but don't allow changes. |
771 Like \\[find-file-other-window] but marks buffer as read-only. | |
772 Use \\[toggle-read-only] to permit editing." | |
24166
3d25e1fc71aa
(find-file-noselect): Do wildcard processing only
Richard M. Stallman <rms@gnu.org>
parents:
24061
diff
changeset
|
773 (interactive "fFind file read-only other window: \np") |
3d25e1fc71aa
(find-file-noselect): Do wildcard processing only
Richard M. Stallman <rms@gnu.org>
parents:
24061
diff
changeset
|
774 (find-file-other-window filename wildcards) |
18316
1058f8684eca
(backup, find-file): Make `files' their parent.
Richard M. Stallman <rms@gnu.org>
parents:
18164
diff
changeset
|
775 (toggle-read-only 1) |
3280
3b3717164db0
(find-file-run-dired): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
3263
diff
changeset
|
776 (current-buffer)) |
337 | 777 |
24166
3d25e1fc71aa
(find-file-noselect): Do wildcard processing only
Richard M. Stallman <rms@gnu.org>
parents:
24061
diff
changeset
|
778 (defun find-file-read-only-other-frame (filename &optional wildcards) |
778 | 779 "Edit file FILENAME in another frame but don't allow changes. |
780 Like \\[find-file-other-frame] but marks buffer as read-only. | |
423 | 781 Use \\[toggle-read-only] to permit editing." |
24166
3d25e1fc71aa
(find-file-noselect): Do wildcard processing only
Richard M. Stallman <rms@gnu.org>
parents:
24061
diff
changeset
|
782 (interactive "fFind file read-only other frame: \np") |
3d25e1fc71aa
(find-file-noselect): Do wildcard processing only
Richard M. Stallman <rms@gnu.org>
parents:
24061
diff
changeset
|
783 (find-file-other-frame filename wildcards) |
18316
1058f8684eca
(backup, find-file): Make `files' their parent.
Richard M. Stallman <rms@gnu.org>
parents:
18164
diff
changeset
|
784 (toggle-read-only 1) |
3280
3b3717164db0
(find-file-run-dired): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
3263
diff
changeset
|
785 (current-buffer)) |
423 | 786 |
17987
2d9818a04c36
(find-file): Delete the facility of handling a prefix
Kenichi Handa <handa@m17n.org>
parents:
17894
diff
changeset
|
787 (defun find-alternate-file-other-window (filename) |
13182
55c6e0f3c2f4
(find-alternate-file-other-window): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13118
diff
changeset
|
788 "Find file FILENAME as a replacement for the file in the next window. |
17987
2d9818a04c36
(find-file): Delete the facility of handling a prefix
Kenichi Handa <handa@m17n.org>
parents:
17894
diff
changeset
|
789 This command does not select that window." |
13182
55c6e0f3c2f4
(find-alternate-file-other-window): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13118
diff
changeset
|
790 (interactive |
55c6e0f3c2f4
(find-alternate-file-other-window): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13118
diff
changeset
|
791 (save-selected-window |
55c6e0f3c2f4
(find-alternate-file-other-window): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13118
diff
changeset
|
792 (other-window 1) |
55c6e0f3c2f4
(find-alternate-file-other-window): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13118
diff
changeset
|
793 (let ((file buffer-file-name) |
55c6e0f3c2f4
(find-alternate-file-other-window): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13118
diff
changeset
|
794 (file-name nil) |
55c6e0f3c2f4
(find-alternate-file-other-window): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13118
diff
changeset
|
795 (file-dir nil)) |
55c6e0f3c2f4
(find-alternate-file-other-window): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13118
diff
changeset
|
796 (and file |
55c6e0f3c2f4
(find-alternate-file-other-window): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13118
diff
changeset
|
797 (setq file-name (file-name-nondirectory file) |
55c6e0f3c2f4
(find-alternate-file-other-window): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13118
diff
changeset
|
798 file-dir (file-name-directory file))) |
55c6e0f3c2f4
(find-alternate-file-other-window): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13118
diff
changeset
|
799 (list (read-file-name |
17987
2d9818a04c36
(find-file): Delete the facility of handling a prefix
Kenichi Handa <handa@m17n.org>
parents:
17894
diff
changeset
|
800 "Find alternate file: " file-dir nil nil file-name))))) |
13182
55c6e0f3c2f4
(find-alternate-file-other-window): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13118
diff
changeset
|
801 (if (one-window-p) |
17987
2d9818a04c36
(find-file): Delete the facility of handling a prefix
Kenichi Handa <handa@m17n.org>
parents:
17894
diff
changeset
|
802 (find-file-other-window filename) |
13182
55c6e0f3c2f4
(find-alternate-file-other-window): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13118
diff
changeset
|
803 (save-selected-window |
55c6e0f3c2f4
(find-alternate-file-other-window): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13118
diff
changeset
|
804 (other-window 1) |
17987
2d9818a04c36
(find-file): Delete the facility of handling a prefix
Kenichi Handa <handa@m17n.org>
parents:
17894
diff
changeset
|
805 (find-alternate-file filename)))) |
13182
55c6e0f3c2f4
(find-alternate-file-other-window): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13118
diff
changeset
|
806 |
17987
2d9818a04c36
(find-file): Delete the facility of handling a prefix
Kenichi Handa <handa@m17n.org>
parents:
17894
diff
changeset
|
807 (defun find-alternate-file (filename) |
337 | 808 "Find file FILENAME, select its buffer, kill previous buffer. |
809 If the current buffer now contains an empty file that you just visited | |
17987
2d9818a04c36
(find-file): Delete the facility of handling a prefix
Kenichi Handa <handa@m17n.org>
parents:
17894
diff
changeset
|
810 \(presumably by mistake), use this command to visit the file you really want." |
337 | 811 (interactive |
812 (let ((file buffer-file-name) | |
813 (file-name nil) | |
814 (file-dir nil)) | |
815 (and file | |
816 (setq file-name (file-name-nondirectory file) | |
817 file-dir (file-name-directory file))) | |
941 | 818 (list (read-file-name |
17987
2d9818a04c36
(find-file): Delete the facility of handling a prefix
Kenichi Handa <handa@m17n.org>
parents:
17894
diff
changeset
|
819 "Find alternate file: " file-dir nil nil file-name)))) |
9048
dc5a9c83dc35
(find-alternate-file): Confirm killing buffer only if it is visiting a file.
Richard M. Stallman <rms@gnu.org>
parents:
8987
diff
changeset
|
820 (and (buffer-modified-p) (buffer-file-name) |
337 | 821 ;; (not buffer-read-only) |
822 (not (yes-or-no-p (format "Buffer %s is modified; kill anyway? " | |
823 (buffer-name)))) | |
824 (error "Aborted")) | |
825 (let ((obuf (current-buffer)) | |
826 (ofile buffer-file-name) | |
3191
d96fd9315996
(find-alternate-file): Hide truename and inode number
Richard M. Stallman <rms@gnu.org>
parents:
3151
diff
changeset
|
827 (onum buffer-file-number) |
d96fd9315996
(find-alternate-file): Hide truename and inode number
Richard M. Stallman <rms@gnu.org>
parents:
3151
diff
changeset
|
828 (otrue buffer-file-truename) |
337 | 829 (oname (buffer-name))) |
13037
3946c18462c8
(find-alternate-file): Kill any preexisting ` **lose**' buf.
Richard M. Stallman <rms@gnu.org>
parents:
13032
diff
changeset
|
830 (if (get-buffer " **lose**") |
3946c18462c8
(find-alternate-file): Kill any preexisting ` **lose**' buf.
Richard M. Stallman <rms@gnu.org>
parents:
13032
diff
changeset
|
831 (kill-buffer " **lose**")) |
337 | 832 (rename-buffer " **lose**") |
833 (unwind-protect | |
834 (progn | |
835 (unlock-buffer) | |
15410
559d91fe836a
(find-alternate-file): Don't clear buffer-file-truename
Richard M. Stallman <rms@gnu.org>
parents:
15365
diff
changeset
|
836 (setq buffer-file-name nil) |
559d91fe836a
(find-alternate-file): Don't clear buffer-file-truename
Richard M. Stallman <rms@gnu.org>
parents:
15365
diff
changeset
|
837 (setq buffer-file-number nil) |
559d91fe836a
(find-alternate-file): Don't clear buffer-file-truename
Richard M. Stallman <rms@gnu.org>
parents:
15365
diff
changeset
|
838 (setq buffer-file-truename nil) |
17987
2d9818a04c36
(find-file): Delete the facility of handling a prefix
Kenichi Handa <handa@m17n.org>
parents:
17894
diff
changeset
|
839 (find-file filename)) |
337 | 840 (cond ((eq obuf (current-buffer)) |
841 (setq buffer-file-name ofile) | |
3191
d96fd9315996
(find-alternate-file): Hide truename and inode number
Richard M. Stallman <rms@gnu.org>
parents:
3151
diff
changeset
|
842 (setq buffer-file-number onum) |
d96fd9315996
(find-alternate-file): Hide truename and inode number
Richard M. Stallman <rms@gnu.org>
parents:
3151
diff
changeset
|
843 (setq buffer-file-truename otrue) |
337 | 844 (lock-buffer) |
845 (rename-buffer oname)))) | |
846 (or (eq (current-buffer) obuf) | |
847 (kill-buffer obuf)))) | |
19305
030c40d12288
(insert-file-literally): New command.
Richard M. Stallman <rms@gnu.org>
parents:
19199
diff
changeset
|
848 |
337 | 849 (defun create-file-buffer (filename) |
850 "Create a suitably named buffer for visiting FILENAME, and return it. | |
851 FILENAME (sans directory) is used unchanged if that name is free; | |
852 otherwise a string <2> or <3> or ... is appended to get an unused name." | |
853 (let ((lastname (file-name-nondirectory filename))) | |
854 (if (string= lastname "") | |
855 (setq lastname filename)) | |
856 (generate-new-buffer lastname))) | |
857 | |
423 | 858 (defun generate-new-buffer (name) |
859 "Create and return a buffer with a name based on NAME. | |
1461 | 860 Choose the buffer's name using `generate-new-buffer-name'." |
423 | 861 (get-buffer-create (generate-new-buffer-name name))) |
862 | |
32138 | 863 (defcustom automount-dir-prefix "^/tmp_mnt/" |
864 "Regexp to match the automounter prefix in a directory name." | |
865 :group 'files | |
866 :type 'regexp) | |
817 | 867 |
1725
ac890f97e78b
(abbreviated-home-dir): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1672
diff
changeset
|
868 (defvar abbreviated-home-dir nil |
32138 | 869 "The user's homedir abbreviated according to `directory-abbrev-alist'.") |
1725
ac890f97e78b
(abbreviated-home-dir): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1672
diff
changeset
|
870 |
423 | 871 (defun abbreviate-file-name (filename) |
1461 | 872 "Return a version of FILENAME shortened using `directory-abbrev-alist'. |
423 | 873 This also substitutes \"~\" for the user's home directory. |
1461 | 874 Type \\[describe-variable] directory-abbrev-alist RET for more information." |
817 | 875 ;; Get rid of the prefixes added by the automounter. |
15548
ec7e7b99c680
(abbreviate-file-name): Ignore automount-dir-prefix if nil.
Richard M. Stallman <rms@gnu.org>
parents:
15545
diff
changeset
|
876 (if (and automount-dir-prefix |
ec7e7b99c680
(abbreviate-file-name): Ignore automount-dir-prefix if nil.
Richard M. Stallman <rms@gnu.org>
parents:
15545
diff
changeset
|
877 (string-match automount-dir-prefix filename) |
817 | 878 (file-exists-p (file-name-directory |
879 (substring filename (1- (match-end 0)))))) | |
880 (setq filename (substring filename (1- (match-end 0))))) | |
423 | 881 (let ((tail directory-abbrev-alist)) |
1725
ac890f97e78b
(abbreviated-home-dir): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1672
diff
changeset
|
882 ;; If any elt of directory-abbrev-alist matches this name, |
ac890f97e78b
(abbreviated-home-dir): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1672
diff
changeset
|
883 ;; abbreviate accordingly. |
423 | 884 (while tail |
885 (if (string-match (car (car tail)) filename) | |
886 (setq filename | |
887 (concat (cdr (car tail)) (substring filename (match-end 0))))) | |
888 (setq tail (cdr tail))) | |
1725
ac890f97e78b
(abbreviated-home-dir): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1672
diff
changeset
|
889 ;; Compute and save the abbreviated homedir name. |
ac890f97e78b
(abbreviated-home-dir): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1672
diff
changeset
|
890 ;; We defer computing this until the first time it's needed, to |
ac890f97e78b
(abbreviated-home-dir): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1672
diff
changeset
|
891 ;; give time for directory-abbrev-alist to be set properly. |
3624
386094c1a569
(abbreviate-file-name): Make abbreviated-home-dir
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
892 ;; We include a slash at the end, to avoid spurious matches |
386094c1a569
(abbreviate-file-name): Make abbreviated-home-dir
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
893 ;; such as `/usr/foobar' when the home dir is `/usr/foo'. |
1725
ac890f97e78b
(abbreviated-home-dir): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1672
diff
changeset
|
894 (or abbreviated-home-dir |
ac890f97e78b
(abbreviated-home-dir): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1672
diff
changeset
|
895 (setq abbreviated-home-dir |
ac890f97e78b
(abbreviated-home-dir): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1672
diff
changeset
|
896 (let ((abbreviated-home-dir "$foo")) |
3709
09e961c82be8
(abbreviate-file-name): Match home dir with no / if nothing else follows.
Richard M. Stallman <rms@gnu.org>
parents:
3672
diff
changeset
|
897 (concat "^" (abbreviate-file-name (expand-file-name "~")) |
09e961c82be8
(abbreviate-file-name): Match home dir with no / if nothing else follows.
Richard M. Stallman <rms@gnu.org>
parents:
3672
diff
changeset
|
898 "\\(/\\|$\\)")))) |
13832
44e936e550ae
(save-some-buffers): Don't give message if we queried.
Roland McGrath <roland@gnu.org>
parents:
13823
diff
changeset
|
899 |
1725
ac890f97e78b
(abbreviated-home-dir): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1672
diff
changeset
|
900 ;; If FILENAME starts with the abbreviated homedir, |
ac890f97e78b
(abbreviated-home-dir): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1672
diff
changeset
|
901 ;; make it start with `~' instead. |
5582
cc4892ee6807
(abbreviate-file-name): Don't convert / to ~/ when the home dir is /.
Richard M. Stallman <rms@gnu.org>
parents:
5468
diff
changeset
|
902 (if (and (string-match abbreviated-home-dir filename) |
cc4892ee6807
(abbreviate-file-name): Don't convert / to ~/ when the home dir is /.
Richard M. Stallman <rms@gnu.org>
parents:
5468
diff
changeset
|
903 ;; If the home dir is just /, don't change it. |
cc4892ee6807
(abbreviate-file-name): Don't convert / to ~/ when the home dir is /.
Richard M. Stallman <rms@gnu.org>
parents:
5468
diff
changeset
|
904 (not (and (= (match-end 0) 1) |
7440
1c0885a92832
(abbreviate-file-name): Add special case for ms-dos.
Richard M. Stallman <rms@gnu.org>
parents:
7430
diff
changeset
|
905 (= (aref filename 0) ?/))) |
13903
936c8364e15a
(abbrev-file-name): Drive letter can go beyond `Z' under MS-DOS/Novell.
Richard M. Stallman <rms@gnu.org>
parents:
13885
diff
changeset
|
906 ;; MS-DOS root directories can come with a drive letter; |
936c8364e15a
(abbrev-file-name): Drive letter can go beyond `Z' under MS-DOS/Novell.
Richard M. Stallman <rms@gnu.org>
parents:
13885
diff
changeset
|
907 ;; Novell Netware allows drive letters beyond `Z:'. |
13832
44e936e550ae
(save-some-buffers): Don't give message if we queried.
Roland McGrath <roland@gnu.org>
parents:
13823
diff
changeset
|
908 (not (and (or (eq system-type 'ms-dos) |
9777
178a3bf170f3
(abbreviate-file-name): Handle drive letters on windows-nt as on ms-dos.
Richard M. Stallman <rms@gnu.org>
parents:
9731
diff
changeset
|
909 (eq system-type 'windows-nt)) |
7440
1c0885a92832
(abbreviate-file-name): Add special case for ms-dos.
Richard M. Stallman <rms@gnu.org>
parents:
7430
diff
changeset
|
910 (save-match-data |
13903
936c8364e15a
(abbrev-file-name): Drive letter can go beyond `Z' under MS-DOS/Novell.
Richard M. Stallman <rms@gnu.org>
parents:
13885
diff
changeset
|
911 (string-match "^[a-zA-`]:/$" filename))))) |
423 | 912 (setq filename |
2630
47cf3a387530
* files.el (insert-directory): Undo change of March 23;
Jim Blandy <jimb@redhat.com>
parents:
2622
diff
changeset
|
913 (concat "~" |
3709
09e961c82be8
(abbreviate-file-name): Match home dir with no / if nothing else follows.
Richard M. Stallman <rms@gnu.org>
parents:
3672
diff
changeset
|
914 (substring filename (match-beginning 1) (match-end 1)) |
2630
47cf3a387530
* files.el (insert-directory): Undo change of March 23;
Jim Blandy <jimb@redhat.com>
parents:
2622
diff
changeset
|
915 (substring filename (match-end 0))))) |
423 | 916 filename)) |
917 | |
17673
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
918 (defcustom find-file-not-true-dirname-list nil |
2622
15cb6ba42da3
(find-file-noselect): On VMS, maybe set buffer-file-name
Richard M. Stallman <rms@gnu.org>
parents:
2613
diff
changeset
|
919 "*List of logical names for which visiting shouldn't save the true dirname. |
15cb6ba42da3
(find-file-noselect): On VMS, maybe set buffer-file-name
Richard M. Stallman <rms@gnu.org>
parents:
2613
diff
changeset
|
920 On VMS, when you visit a file using a logical name that searches a path, |
15cb6ba42da3
(find-file-noselect): On VMS, maybe set buffer-file-name
Richard M. Stallman <rms@gnu.org>
parents:
2613
diff
changeset
|
921 you may or may not want the visited file name to record the specific |
15cb6ba42da3
(find-file-noselect): On VMS, maybe set buffer-file-name
Richard M. Stallman <rms@gnu.org>
parents:
2613
diff
changeset
|
922 directory where the file was found. If you *do not* want that, add the logical |
17673
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
923 name to this list as a string." |
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
924 :type '(repeat (string :tag "Name")) |
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
925 :group 'find-file) |
2622
15cb6ba42da3
(find-file-noselect): On VMS, maybe set buffer-file-name
Richard M. Stallman <rms@gnu.org>
parents:
2613
diff
changeset
|
926 |
6265
f901b6091821
(find-buffer-visiting): New function to look for another buffer visiting the
Karl Heuer <kwzh@gnu.org>
parents:
6168
diff
changeset
|
927 (defun find-buffer-visiting (filename) |
f901b6091821
(find-buffer-visiting): New function to look for another buffer visiting the
Karl Heuer <kwzh@gnu.org>
parents:
6168
diff
changeset
|
928 "Return the buffer visiting file FILENAME (a string). |
f901b6091821
(find-buffer-visiting): New function to look for another buffer visiting the
Karl Heuer <kwzh@gnu.org>
parents:
6168
diff
changeset
|
929 This is like `get-file-buffer', except that it checks for any buffer |
f901b6091821
(find-buffer-visiting): New function to look for another buffer visiting the
Karl Heuer <kwzh@gnu.org>
parents:
6168
diff
changeset
|
930 visiting the same file, possibly under a different name. |
f901b6091821
(find-buffer-visiting): New function to look for another buffer visiting the
Karl Heuer <kwzh@gnu.org>
parents:
6168
diff
changeset
|
931 If there is no such live buffer, return nil." |
f901b6091821
(find-buffer-visiting): New function to look for another buffer visiting the
Karl Heuer <kwzh@gnu.org>
parents:
6168
diff
changeset
|
932 (let ((buf (get-file-buffer filename)) |
f901b6091821
(find-buffer-visiting): New function to look for another buffer visiting the
Karl Heuer <kwzh@gnu.org>
parents:
6168
diff
changeset
|
933 (truename (abbreviate-file-name (file-truename filename)))) |
f901b6091821
(find-buffer-visiting): New function to look for another buffer visiting the
Karl Heuer <kwzh@gnu.org>
parents:
6168
diff
changeset
|
934 (or buf |
f901b6091821
(find-buffer-visiting): New function to look for another buffer visiting the
Karl Heuer <kwzh@gnu.org>
parents:
6168
diff
changeset
|
935 (let ((list (buffer-list)) found) |
f901b6091821
(find-buffer-visiting): New function to look for another buffer visiting the
Karl Heuer <kwzh@gnu.org>
parents:
6168
diff
changeset
|
936 (while (and (not found) list) |
f901b6091821
(find-buffer-visiting): New function to look for another buffer visiting the
Karl Heuer <kwzh@gnu.org>
parents:
6168
diff
changeset
|
937 (save-excursion |
f901b6091821
(find-buffer-visiting): New function to look for another buffer visiting the
Karl Heuer <kwzh@gnu.org>
parents:
6168
diff
changeset
|
938 (set-buffer (car list)) |
f901b6091821
(find-buffer-visiting): New function to look for another buffer visiting the
Karl Heuer <kwzh@gnu.org>
parents:
6168
diff
changeset
|
939 (if (and buffer-file-name |
f901b6091821
(find-buffer-visiting): New function to look for another buffer visiting the
Karl Heuer <kwzh@gnu.org>
parents:
6168
diff
changeset
|
940 (string= buffer-file-truename truename)) |
f901b6091821
(find-buffer-visiting): New function to look for another buffer visiting the
Karl Heuer <kwzh@gnu.org>
parents:
6168
diff
changeset
|
941 (setq found (car list)))) |
f901b6091821
(find-buffer-visiting): New function to look for another buffer visiting the
Karl Heuer <kwzh@gnu.org>
parents:
6168
diff
changeset
|
942 (setq list (cdr list))) |
f901b6091821
(find-buffer-visiting): New function to look for another buffer visiting the
Karl Heuer <kwzh@gnu.org>
parents:
6168
diff
changeset
|
943 found) |
33703
af0f3f3533e8
(find-buffer-visiting): Compare all attributes before
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33558
diff
changeset
|
944 (let* ((attributes (file-attributes truename)) |
af0f3f3533e8
(find-buffer-visiting): Compare all attributes before
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33558
diff
changeset
|
945 (number (nthcdr 10 attributes)) |
af0f3f3533e8
(find-buffer-visiting): Compare all attributes before
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33558
diff
changeset
|
946 (list (buffer-list)) found) |
15329
19008fd7774d
(buffer-file-numbers-unique): New variable;
Richard M. Stallman <rms@gnu.org>
parents:
15269
diff
changeset
|
947 (and buffer-file-numbers-unique |
19008fd7774d
(buffer-file-numbers-unique): New variable;
Richard M. Stallman <rms@gnu.org>
parents:
15269
diff
changeset
|
948 number |
6294
6044f2615082
(find-buffer-visiting): Don't compare NUMBER if it is nil.
Richard M. Stallman <rms@gnu.org>
parents:
6272
diff
changeset
|
949 (while (and (not found) list) |
33703
af0f3f3533e8
(find-buffer-visiting): Compare all attributes before
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33558
diff
changeset
|
950 (with-current-buffer (car list) |
6866
47bed999969a
(find-buffer-visiting): Don't check buffer-file-number
Richard M. Stallman <rms@gnu.org>
parents:
6780
diff
changeset
|
951 (if (and buffer-file-name |
47bed999969a
(find-buffer-visiting): Don't check buffer-file-number
Richard M. Stallman <rms@gnu.org>
parents:
6780
diff
changeset
|
952 (equal buffer-file-number number) |
6294
6044f2615082
(find-buffer-visiting): Don't compare NUMBER if it is nil.
Richard M. Stallman <rms@gnu.org>
parents:
6272
diff
changeset
|
953 ;; Verify this buffer's file number |
6044f2615082
(find-buffer-visiting): Don't compare NUMBER if it is nil.
Richard M. Stallman <rms@gnu.org>
parents:
6272
diff
changeset
|
954 ;; still belongs to its file. |
6044f2615082
(find-buffer-visiting): Don't compare NUMBER if it is nil.
Richard M. Stallman <rms@gnu.org>
parents:
6272
diff
changeset
|
955 (file-exists-p buffer-file-name) |
33703
af0f3f3533e8
(find-buffer-visiting): Compare all attributes before
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33558
diff
changeset
|
956 (equal (file-attributes buffer-file-name) |
af0f3f3533e8
(find-buffer-visiting): Compare all attributes before
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33558
diff
changeset
|
957 attributes)) |
6294
6044f2615082
(find-buffer-visiting): Don't compare NUMBER if it is nil.
Richard M. Stallman <rms@gnu.org>
parents:
6272
diff
changeset
|
958 (setq found (car list)))) |
6044f2615082
(find-buffer-visiting): Don't compare NUMBER if it is nil.
Richard M. Stallman <rms@gnu.org>
parents:
6272
diff
changeset
|
959 (setq list (cdr list)))) |
6265
f901b6091821
(find-buffer-visiting): New function to look for another buffer visiting the
Karl Heuer <kwzh@gnu.org>
parents:
6168
diff
changeset
|
960 found)))) |
19305
030c40d12288
(insert-file-literally): New command.
Richard M. Stallman <rms@gnu.org>
parents:
19199
diff
changeset
|
961 |
23473
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
962 (defcustom find-file-wildcards t |
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
963 "*Non-nil means file-visiting commands should handle wildcards. |
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
964 For example, if you specify `*.c', that would visit all the files |
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
965 whose names match the pattern." |
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
966 :group 'files |
28325 | 967 :version "20.4" |
23473
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
968 :type 'boolean) |
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
969 |
32138 | 970 (defcustom find-file-suppress-same-file-warnings nil |
971 "*Non-nil means suppress warning messages for symlinked files. | |
972 When nil, Emacs prints a warning when visiting a file that is already | |
973 visited, but with a different name. Setting this option to t | |
974 suppresses this warning." | |
975 :group 'files | |
976 :version "21.1" | |
977 :type 'boolean) | |
978 | |
24166
3d25e1fc71aa
(find-file-noselect): Do wildcard processing only
Richard M. Stallman <rms@gnu.org>
parents:
24061
diff
changeset
|
979 (defun find-file-noselect (filename &optional nowarn rawfile wildcards) |
337 | 980 "Read file FILENAME into a buffer and return the buffer. |
981 If a buffer exists visiting FILENAME, return that one, but | |
982 verify that the file has not changed since visited or saved. | |
17004
cd1d930a2c98
(find-file, find-file-other-window,
Karl Heuer <kwzh@gnu.org>
parents:
16976
diff
changeset
|
983 The buffer is not selected, just returned to the caller. |
cd1d930a2c98
(find-file, find-file-other-window,
Karl Heuer <kwzh@gnu.org>
parents:
16976
diff
changeset
|
984 Optional first arg NOWARN non-nil means suppress any warning messages. |
24166
3d25e1fc71aa
(find-file-noselect): Do wildcard processing only
Richard M. Stallman <rms@gnu.org>
parents:
24061
diff
changeset
|
985 Optional second arg RAWFILE non-nil means the file is read literally. |
3d25e1fc71aa
(find-file-noselect): Do wildcard processing only
Richard M. Stallman <rms@gnu.org>
parents:
24061
diff
changeset
|
986 Optional third arg WILDCARDS non-nil means do wildcard processing |
24167
6b14770eb944
(find-file): If find-file-noselect returns a list,
Richard M. Stallman <rms@gnu.org>
parents:
24166
diff
changeset
|
987 and visit all the matching files. When wildcards are actually |
6b14770eb944
(find-file): If find-file-noselect returns a list,
Richard M. Stallman <rms@gnu.org>
parents:
24166
diff
changeset
|
988 used and expanded, the value is a list of buffers |
6b14770eb944
(find-file): If find-file-noselect returns a list,
Richard M. Stallman <rms@gnu.org>
parents:
24166
diff
changeset
|
989 that are visiting the various files." |
817 | 990 (setq filename |
991 (abbreviate-file-name | |
992 (expand-file-name filename))) | |
337 | 993 (if (file-directory-p filename) |
32138 | 994 (or (and find-file-run-dired |
995 (run-hook-with-args-until-success | |
996 'find-directory-functions | |
997 (if find-file-visit-truename | |
998 (abbreviate-file-name (file-truename filename)) | |
999 filename))) | |
1000 (error "%s is a directory" filename)) | |
24166
3d25e1fc71aa
(find-file-noselect): Do wildcard processing only
Richard M. Stallman <rms@gnu.org>
parents:
24061
diff
changeset
|
1001 (if (and wildcards |
3d25e1fc71aa
(find-file-noselect): Do wildcard processing only
Richard M. Stallman <rms@gnu.org>
parents:
24061
diff
changeset
|
1002 find-file-wildcards |
23983
f81108c27669
(find-file-noselect): Let /: suppress wildcard matching.
Richard M. Stallman <rms@gnu.org>
parents:
23942
diff
changeset
|
1003 (not (string-match "\\`/:" filename)) |
23473
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
1004 (string-match "[[*?]" filename)) |
32138 | 1005 (let ((files (condition-case nil |
1006 (file-expand-wildcards filename t) | |
1007 (error (list filename)))) | |
23473
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
1008 (find-file-wildcards nil)) |
23983
f81108c27669
(find-file-noselect): Let /: suppress wildcard matching.
Richard M. Stallman <rms@gnu.org>
parents:
23942
diff
changeset
|
1009 (if (null files) |
32138 | 1010 (find-file-noselect filename) |
33105
dd4bceb945d3
(find-file-noselect): When we expand a wildcard, return
Gerd Moellmann <gerd@gnu.org>
parents:
32830
diff
changeset
|
1011 (mapcar #'find-file-noselect files))) |
23473
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
1012 (let* ((buf (get-file-buffer filename)) |
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
1013 (truename (abbreviate-file-name (file-truename filename))) |
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
1014 (number (nthcdr 10 (file-attributes truename))) |
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
1015 ;; Find any buffer for a file which has same truename. |
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
1016 (other (and (not buf) (find-buffer-visiting filename)))) |
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
1017 ;; Let user know if there is a buffer with the same truename. |
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
1018 (if other |
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
1019 (progn |
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
1020 (or nowarn |
32138 | 1021 find-file-suppress-same-file-warnings |
23473
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
1022 (string-equal filename (buffer-file-name other)) |
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
1023 (message "%s and %s are the same file" |
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
1024 filename (buffer-file-name other))) |
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
1025 ;; Optionally also find that buffer. |
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
1026 (if (or find-file-existing-other-name find-file-visit-truename) |
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
1027 (setq buf other)))) |
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
1028 (if buf |
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
1029 ;; We are using an existing buffer. |
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
1030 (progn |
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
1031 (or nowarn |
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
1032 (verify-visited-file-modtime buf) |
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
1033 (cond ((not (file-exists-p filename)) |
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
1034 (error "File %s no longer exists!" filename)) |
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
1035 ;; Certain files should be reverted automatically |
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
1036 ;; if they have changed on disk and not in the buffer. |
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
1037 ((and (not (buffer-modified-p buf)) |
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
1038 (let ((tail revert-without-query) |
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
1039 (found nil)) |
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
1040 (while tail |
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
1041 (if (string-match (car tail) filename) |
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
1042 (setq found t)) |
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
1043 (setq tail (cdr tail))) |
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
1044 found)) |
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
1045 (with-current-buffer buf |
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
1046 (message "Reverting file %s..." filename) |
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
1047 (revert-buffer t t) |
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
1048 (message "Reverting file %s...done" filename))) |
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
1049 ((yes-or-no-p |
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
1050 (if (string= (file-name-nondirectory filename) |
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
1051 (buffer-name buf)) |
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
1052 (format |
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
1053 (if (buffer-modified-p buf) |
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
1054 "File %s changed on disk. Discard your edits? " |
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
1055 "File %s changed on disk. Reread from disk? ") |
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
1056 (file-name-nondirectory filename)) |
22403
4b5a49aa186a
(find-file-noselect-1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22338
diff
changeset
|
1057 (format |
4b5a49aa186a
(find-file-noselect-1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22338
diff
changeset
|
1058 (if (buffer-modified-p buf) |
23473
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
1059 "File %s changed on disk. Discard your edits in %s? " |
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
1060 "File %s changed on disk. Reread from disk into %s? ") |
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
1061 (file-name-nondirectory filename) |
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
1062 (buffer-name buf)))) |
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
1063 (with-current-buffer buf |
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
1064 (revert-buffer t t))))) |
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
1065 (with-current-buffer buf |
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
1066 (when (not (eq (not (null rawfile)) |
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
1067 (not (null find-file-literally)))) |
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
1068 (if (buffer-modified-p) |
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
1069 (if (y-or-n-p (if rawfile |
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
1070 "Save file and revisit literally? " |
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
1071 "Save file and revisit non-literally? ")) |
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
1072 (progn |
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
1073 (save-buffer) |
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
1074 (find-file-noselect-1 buf filename nowarn |
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
1075 rawfile truename number)) |
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
1076 (if (y-or-n-p (if rawfile |
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
1077 "Discard your edits and revisit file literally? " |
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
1078 "Discard your edits and revisit file non-literally? ")) |
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
1079 (find-file-noselect-1 buf filename nowarn |
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
1080 rawfile truename number) |
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
1081 (error (if rawfile "File already visited non-literally" |
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
1082 "File already visited literally")))) |
22403
4b5a49aa186a
(find-file-noselect-1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22338
diff
changeset
|
1083 (if (y-or-n-p (if rawfile |
23473
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
1084 "Revisit file literally? " |
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
1085 "Revisit file non-literally? ")) |
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
1086 (find-file-noselect-1 buf filename nowarn |
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
1087 rawfile truename number) |
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
1088 (error (if rawfile "File already visited non-literally" |
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
1089 "File already visited literally")))))) |
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
1090 ;; Return the buffer we are using. |
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
1091 buf) |
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
1092 ;; Create a new buffer. |
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
1093 (setq buf (create-file-buffer filename)) |
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
1094 (set-buffer-major-mode buf) |
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
1095 ;; find-file-noselect-1 may use a different buffer. |
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
1096 (find-file-noselect-1 buf filename nowarn |
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
1097 rawfile truename number)))))) |
22403
4b5a49aa186a
(find-file-noselect-1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22338
diff
changeset
|
1098 |
4b5a49aa186a
(find-file-noselect-1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22338
diff
changeset
|
1099 (defun find-file-noselect-1 (buf filename nowarn rawfile truename number) |
22466
7e79814e7263
(find-file-noselect): Delete unused local var `error'.
Richard M. Stallman <rms@gnu.org>
parents:
22465
diff
changeset
|
1100 (let ((inhibit-read-only t) |
7e79814e7263
(find-file-noselect): Delete unused local var `error'.
Richard M. Stallman <rms@gnu.org>
parents:
22465
diff
changeset
|
1101 error) |
22403
4b5a49aa186a
(find-file-noselect-1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22338
diff
changeset
|
1102 (with-current-buffer buf |
4b5a49aa186a
(find-file-noselect-1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22338
diff
changeset
|
1103 (kill-local-variable 'find-file-literally) |
22555
318d69b6292c
(find-file-noselect-1): Init buffer-file-coding-system
Richard M. Stallman <rms@gnu.org>
parents:
22480
diff
changeset
|
1104 ;; Needed in case we are re-visiting the file with a different |
318d69b6292c
(find-file-noselect-1): Init buffer-file-coding-system
Richard M. Stallman <rms@gnu.org>
parents:
22480
diff
changeset
|
1105 ;; text representation. |
22738
d35510185a2d
(find-file-noselect-1): Use kill-local-variable on
Richard M. Stallman <rms@gnu.org>
parents:
22582
diff
changeset
|
1106 (kill-local-variable 'buffer-file-coding-system) |
22403
4b5a49aa186a
(find-file-noselect-1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22338
diff
changeset
|
1107 (erase-buffer) |
4b5a49aa186a
(find-file-noselect-1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22338
diff
changeset
|
1108 (and (default-value 'enable-multibyte-characters) |
4b5a49aa186a
(find-file-noselect-1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22338
diff
changeset
|
1109 (not rawfile) |
4b5a49aa186a
(find-file-noselect-1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22338
diff
changeset
|
1110 (set-buffer-multibyte t)) |
4b5a49aa186a
(find-file-noselect-1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22338
diff
changeset
|
1111 (if rawfile |
4b5a49aa186a
(find-file-noselect-1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22338
diff
changeset
|
1112 (condition-case () |
4b5a49aa186a
(find-file-noselect-1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22338
diff
changeset
|
1113 (insert-file-contents-literally filename t) |
4b5a49aa186a
(find-file-noselect-1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22338
diff
changeset
|
1114 (file-error |
4b5a49aa186a
(find-file-noselect-1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22338
diff
changeset
|
1115 (when (and (file-exists-p filename) |
4b5a49aa186a
(find-file-noselect-1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22338
diff
changeset
|
1116 (not (file-readable-p filename))) |
4b5a49aa186a
(find-file-noselect-1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22338
diff
changeset
|
1117 (kill-buffer buf) |
4b5a49aa186a
(find-file-noselect-1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22338
diff
changeset
|
1118 (signal 'file-error (list "File is not readable" |
4b5a49aa186a
(find-file-noselect-1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22338
diff
changeset
|
1119 filename))) |
4b5a49aa186a
(find-file-noselect-1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22338
diff
changeset
|
1120 ;; Unconditionally set error |
4b5a49aa186a
(find-file-noselect-1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22338
diff
changeset
|
1121 (setq error t))) |
4b5a49aa186a
(find-file-noselect-1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22338
diff
changeset
|
1122 (condition-case () |
4b5a49aa186a
(find-file-noselect-1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22338
diff
changeset
|
1123 (insert-file-contents filename t) |
4b5a49aa186a
(find-file-noselect-1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22338
diff
changeset
|
1124 (file-error |
4b5a49aa186a
(find-file-noselect-1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22338
diff
changeset
|
1125 (when (and (file-exists-p filename) |
4b5a49aa186a
(find-file-noselect-1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22338
diff
changeset
|
1126 (not (file-readable-p filename))) |
4b5a49aa186a
(find-file-noselect-1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22338
diff
changeset
|
1127 (kill-buffer buf) |
4b5a49aa186a
(find-file-noselect-1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22338
diff
changeset
|
1128 (signal 'file-error (list "File is not readable" |
4b5a49aa186a
(find-file-noselect-1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22338
diff
changeset
|
1129 filename))) |
4b5a49aa186a
(find-file-noselect-1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22338
diff
changeset
|
1130 ;; Run find-file-not-found-hooks until one returns non-nil. |
4b5a49aa186a
(find-file-noselect-1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22338
diff
changeset
|
1131 (or (run-hook-with-args-until-success 'find-file-not-found-hooks) |
4b5a49aa186a
(find-file-noselect-1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22338
diff
changeset
|
1132 ;; If they fail too, set error. |
4b5a49aa186a
(find-file-noselect-1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22338
diff
changeset
|
1133 (setq error t))))) |
24653
0d75a033fceb
(find-file-noselect-1): If buffer-file-name has changed
Karl Heuer <kwzh@gnu.org>
parents:
24217
diff
changeset
|
1134 ;; Record the file's truename, and maybe use that as visited name. |
0d75a033fceb
(find-file-noselect-1): If buffer-file-name has changed
Karl Heuer <kwzh@gnu.org>
parents:
24217
diff
changeset
|
1135 (if (equal filename buffer-file-name) |
0d75a033fceb
(find-file-noselect-1): If buffer-file-name has changed
Karl Heuer <kwzh@gnu.org>
parents:
24217
diff
changeset
|
1136 (setq buffer-file-truename truename) |
24727 | 1137 (setq buffer-file-truename |
1138 (abbreviate-file-name (file-truename buffer-file-name)))) | |
22403
4b5a49aa186a
(find-file-noselect-1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22338
diff
changeset
|
1139 (setq buffer-file-number number) |
4b5a49aa186a
(find-file-noselect-1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22338
diff
changeset
|
1140 ;; On VMS, we may want to remember which directory in a search list |
4b5a49aa186a
(find-file-noselect-1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22338
diff
changeset
|
1141 ;; the file was found in. |
4b5a49aa186a
(find-file-noselect-1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22338
diff
changeset
|
1142 (and (eq system-type 'vax-vms) |
4b5a49aa186a
(find-file-noselect-1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22338
diff
changeset
|
1143 (let (logical) |
4b5a49aa186a
(find-file-noselect-1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22338
diff
changeset
|
1144 (if (string-match ":" (file-name-directory filename)) |
4b5a49aa186a
(find-file-noselect-1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22338
diff
changeset
|
1145 (setq logical (substring (file-name-directory filename) |
4b5a49aa186a
(find-file-noselect-1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22338
diff
changeset
|
1146 0 (match-beginning 0)))) |
4b5a49aa186a
(find-file-noselect-1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22338
diff
changeset
|
1147 (not (member logical find-file-not-true-dirname-list))) |
4b5a49aa186a
(find-file-noselect-1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22338
diff
changeset
|
1148 (setq buffer-file-name buffer-file-truename)) |
4b5a49aa186a
(find-file-noselect-1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22338
diff
changeset
|
1149 (if find-file-visit-truename |
4b5a49aa186a
(find-file-noselect-1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22338
diff
changeset
|
1150 (setq buffer-file-name |
4b5a49aa186a
(find-file-noselect-1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22338
diff
changeset
|
1151 (setq filename |
4b5a49aa186a
(find-file-noselect-1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22338
diff
changeset
|
1152 (expand-file-name buffer-file-truename)))) |
4b5a49aa186a
(find-file-noselect-1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22338
diff
changeset
|
1153 ;; Set buffer's default directory to that of the file. |
24653
0d75a033fceb
(find-file-noselect-1): If buffer-file-name has changed
Karl Heuer <kwzh@gnu.org>
parents:
24217
diff
changeset
|
1154 (setq default-directory (file-name-directory buffer-file-name)) |
22403
4b5a49aa186a
(find-file-noselect-1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22338
diff
changeset
|
1155 ;; Turn off backup files for certain file names. Since |
4b5a49aa186a
(find-file-noselect-1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22338
diff
changeset
|
1156 ;; this is a permanent local, the major mode won't eliminate it. |
4b5a49aa186a
(find-file-noselect-1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22338
diff
changeset
|
1157 (and (not (funcall backup-enable-predicate buffer-file-name)) |
4b5a49aa186a
(find-file-noselect-1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22338
diff
changeset
|
1158 (progn |
4b5a49aa186a
(find-file-noselect-1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22338
diff
changeset
|
1159 (make-local-variable 'backup-inhibited) |
4b5a49aa186a
(find-file-noselect-1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22338
diff
changeset
|
1160 (setq backup-inhibited t))) |
4b5a49aa186a
(find-file-noselect-1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22338
diff
changeset
|
1161 (if rawfile |
4b5a49aa186a
(find-file-noselect-1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22338
diff
changeset
|
1162 (progn |
4b5a49aa186a
(find-file-noselect-1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22338
diff
changeset
|
1163 (set-buffer-multibyte nil) |
4b5a49aa186a
(find-file-noselect-1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22338
diff
changeset
|
1164 (setq buffer-file-coding-system 'no-conversion) |
4b5a49aa186a
(find-file-noselect-1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22338
diff
changeset
|
1165 (make-local-variable 'find-file-literally) |
4b5a49aa186a
(find-file-noselect-1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22338
diff
changeset
|
1166 (setq find-file-literally t)) |
22555
318d69b6292c
(find-file-noselect-1): Init buffer-file-coding-system
Richard M. Stallman <rms@gnu.org>
parents:
22480
diff
changeset
|
1167 (after-find-file error (not nowarn))) |
318d69b6292c
(find-file-noselect-1): Init buffer-file-coding-system
Richard M. Stallman <rms@gnu.org>
parents:
22480
diff
changeset
|
1168 (current-buffer)))) |
19305
030c40d12288
(insert-file-literally): New command.
Richard M. Stallman <rms@gnu.org>
parents:
19199
diff
changeset
|
1169 |
030c40d12288
(insert-file-literally): New command.
Richard M. Stallman <rms@gnu.org>
parents:
19199
diff
changeset
|
1170 (defun insert-file-contents-literally (filename &optional visit beg end replace) |
030c40d12288
(insert-file-literally): New command.
Richard M. Stallman <rms@gnu.org>
parents:
19199
diff
changeset
|
1171 "Like `insert-file-contents', but only reads in the file literally. |
030c40d12288
(insert-file-literally): New command.
Richard M. Stallman <rms@gnu.org>
parents:
19199
diff
changeset
|
1172 A buffer may be modified in several ways after reading into the buffer, |
030c40d12288
(insert-file-literally): New command.
Richard M. Stallman <rms@gnu.org>
parents:
19199
diff
changeset
|
1173 to Emacs features such as format decoding, character code |
33703
af0f3f3533e8
(find-buffer-visiting): Compare all attributes before
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33558
diff
changeset
|
1174 conversion, `find-file-hooks', automatic uncompression, etc. |
19305
030c40d12288
(insert-file-literally): New command.
Richard M. Stallman <rms@gnu.org>
parents:
19199
diff
changeset
|
1175 |
030c40d12288
(insert-file-literally): New command.
Richard M. Stallman <rms@gnu.org>
parents:
19199
diff
changeset
|
1176 This function ensures that none of these modifications will take place." |
030c40d12288
(insert-file-literally): New command.
Richard M. Stallman <rms@gnu.org>
parents:
19199
diff
changeset
|
1177 (let ((format-alist nil) |
030c40d12288
(insert-file-literally): New command.
Richard M. Stallman <rms@gnu.org>
parents:
19199
diff
changeset
|
1178 (after-insert-file-functions nil) |
030c40d12288
(insert-file-literally): New command.
Richard M. Stallman <rms@gnu.org>
parents:
19199
diff
changeset
|
1179 (coding-system-for-read 'no-conversion) |
030c40d12288
(insert-file-literally): New command.
Richard M. Stallman <rms@gnu.org>
parents:
19199
diff
changeset
|
1180 (coding-system-for-write 'no-conversion) |
030c40d12288
(insert-file-literally): New command.
Richard M. Stallman <rms@gnu.org>
parents:
19199
diff
changeset
|
1181 (jka-compr-compression-info-list nil) |
030c40d12288
(insert-file-literally): New command.
Richard M. Stallman <rms@gnu.org>
parents:
19199
diff
changeset
|
1182 (find-buffer-file-type-function |
030c40d12288
(insert-file-literally): New command.
Richard M. Stallman <rms@gnu.org>
parents:
19199
diff
changeset
|
1183 (if (fboundp 'find-buffer-file-type) |
030c40d12288
(insert-file-literally): New command.
Richard M. Stallman <rms@gnu.org>
parents:
19199
diff
changeset
|
1184 (symbol-function 'find-buffer-file-type) |
030c40d12288
(insert-file-literally): New command.
Richard M. Stallman <rms@gnu.org>
parents:
19199
diff
changeset
|
1185 nil))) |
030c40d12288
(insert-file-literally): New command.
Richard M. Stallman <rms@gnu.org>
parents:
19199
diff
changeset
|
1186 (unwind-protect |
030c40d12288
(insert-file-literally): New command.
Richard M. Stallman <rms@gnu.org>
parents:
19199
diff
changeset
|
1187 (progn |
030c40d12288
(insert-file-literally): New command.
Richard M. Stallman <rms@gnu.org>
parents:
19199
diff
changeset
|
1188 (fset 'find-buffer-file-type (lambda (filename) t)) |
030c40d12288
(insert-file-literally): New command.
Richard M. Stallman <rms@gnu.org>
parents:
19199
diff
changeset
|
1189 (insert-file-contents filename visit beg end replace)) |
030c40d12288
(insert-file-literally): New command.
Richard M. Stallman <rms@gnu.org>
parents:
19199
diff
changeset
|
1190 (if find-buffer-file-type-function |
030c40d12288
(insert-file-literally): New command.
Richard M. Stallman <rms@gnu.org>
parents:
19199
diff
changeset
|
1191 (fset 'find-buffer-file-type find-buffer-file-type-function) |
030c40d12288
(insert-file-literally): New command.
Richard M. Stallman <rms@gnu.org>
parents:
19199
diff
changeset
|
1192 (fmakunbound 'find-buffer-file-type))))) |
030c40d12288
(insert-file-literally): New command.
Richard M. Stallman <rms@gnu.org>
parents:
19199
diff
changeset
|
1193 |
030c40d12288
(insert-file-literally): New command.
Richard M. Stallman <rms@gnu.org>
parents:
19199
diff
changeset
|
1194 (defun insert-file-literally (filename) |
030c40d12288
(insert-file-literally): New command.
Richard M. Stallman <rms@gnu.org>
parents:
19199
diff
changeset
|
1195 "Insert contents of file FILENAME into buffer after point with no conversion. |
030c40d12288
(insert-file-literally): New command.
Richard M. Stallman <rms@gnu.org>
parents:
19199
diff
changeset
|
1196 |
030c40d12288
(insert-file-literally): New command.
Richard M. Stallman <rms@gnu.org>
parents:
19199
diff
changeset
|
1197 This function is meant for the user to run interactively. |
030c40d12288
(insert-file-literally): New command.
Richard M. Stallman <rms@gnu.org>
parents:
19199
diff
changeset
|
1198 Don't call it from programs! Use `insert-file-contents-literally' instead. |
030c40d12288
(insert-file-literally): New command.
Richard M. Stallman <rms@gnu.org>
parents:
19199
diff
changeset
|
1199 \(Its calling sequence is different; see its documentation)." |
030c40d12288
(insert-file-literally): New command.
Richard M. Stallman <rms@gnu.org>
parents:
19199
diff
changeset
|
1200 (interactive "*fInsert file literally: ") |
030c40d12288
(insert-file-literally): New command.
Richard M. Stallman <rms@gnu.org>
parents:
19199
diff
changeset
|
1201 (if (file-directory-p filename) |
030c40d12288
(insert-file-literally): New command.
Richard M. Stallman <rms@gnu.org>
parents:
19199
diff
changeset
|
1202 (signal 'file-error (list "Opening input file" "file is a directory" |
030c40d12288
(insert-file-literally): New command.
Richard M. Stallman <rms@gnu.org>
parents:
19199
diff
changeset
|
1203 filename))) |
030c40d12288
(insert-file-literally): New command.
Richard M. Stallman <rms@gnu.org>
parents:
19199
diff
changeset
|
1204 (let ((tem (insert-file-contents-literally filename))) |
030c40d12288
(insert-file-literally): New command.
Richard M. Stallman <rms@gnu.org>
parents:
19199
diff
changeset
|
1205 (push-mark (+ (point) (car (cdr tem)))))) |
030c40d12288
(insert-file-literally): New command.
Richard M. Stallman <rms@gnu.org>
parents:
19199
diff
changeset
|
1206 |
030c40d12288
(insert-file-literally): New command.
Richard M. Stallman <rms@gnu.org>
parents:
19199
diff
changeset
|
1207 (defvar find-file-literally nil |
030c40d12288
(insert-file-literally): New command.
Richard M. Stallman <rms@gnu.org>
parents:
19199
diff
changeset
|
1208 "Non-nil if this buffer was made by `find-file-literally' or equivalent. |
030c40d12288
(insert-file-literally): New command.
Richard M. Stallman <rms@gnu.org>
parents:
19199
diff
changeset
|
1209 This is a permanent local.") |
030c40d12288
(insert-file-literally): New command.
Richard M. Stallman <rms@gnu.org>
parents:
19199
diff
changeset
|
1210 (put 'find-file-literally 'permanent-local t) |
18676
3980293d3bbd
(find-file-literally): New function.
Richard M. Stallman <rms@gnu.org>
parents:
18466
diff
changeset
|
1211 |
32138 | 1212 (defun find-file-literally (filename) |
18676
3980293d3bbd
(find-file-literally): New function.
Richard M. Stallman <rms@gnu.org>
parents:
18466
diff
changeset
|
1213 "Visit file FILENAME with no conversion of any kind. |
3980293d3bbd
(find-file-literally): New function.
Richard M. Stallman <rms@gnu.org>
parents:
18466
diff
changeset
|
1214 Format conversion and character code conversion are both disabled, |
3980293d3bbd
(find-file-literally): New function.
Richard M. Stallman <rms@gnu.org>
parents:
18466
diff
changeset
|
1215 and multibyte characters are disabled in the resulting buffer. |
19122
e18ca4290312
(insert-file-contents-literally):
Richard M. Stallman <rms@gnu.org>
parents:
18923
diff
changeset
|
1216 The major mode used is Fundamental mode regardless of the file name, |
e18ca4290312
(insert-file-contents-literally):
Richard M. Stallman <rms@gnu.org>
parents:
18923
diff
changeset
|
1217 and local variable specifications in the file are ignored. |
33558
786f1533a10f
(basic-save-buffer): Don't add a newline if
Gerd Moellmann <gerd@gnu.org>
parents:
33105
diff
changeset
|
1218 Automatic uncompression and adding a newline at the end of the |
786f1533a10f
(basic-save-buffer): Don't add a newline if
Gerd Moellmann <gerd@gnu.org>
parents:
33105
diff
changeset
|
1219 file due to `require-final-newline' is also disabled. |
19305
030c40d12288
(insert-file-literally): New command.
Richard M. Stallman <rms@gnu.org>
parents:
19199
diff
changeset
|
1220 |
030c40d12288
(insert-file-literally): New command.
Richard M. Stallman <rms@gnu.org>
parents:
19199
diff
changeset
|
1221 You cannot absolutely rely on this function to result in |
19575
d5de4cc3f899
(find-file-literally): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
19552
diff
changeset
|
1222 visiting the file literally. If Emacs already has a buffer |
19305
030c40d12288
(insert-file-literally): New command.
Richard M. Stallman <rms@gnu.org>
parents:
19199
diff
changeset
|
1223 which is visiting the file, you get the existing buffer, |
030c40d12288
(insert-file-literally): New command.
Richard M. Stallman <rms@gnu.org>
parents:
19199
diff
changeset
|
1224 regardless of whether it was created literally or not. |
030c40d12288
(insert-file-literally): New command.
Richard M. Stallman <rms@gnu.org>
parents:
19199
diff
changeset
|
1225 |
030c40d12288
(insert-file-literally): New command.
Richard M. Stallman <rms@gnu.org>
parents:
19199
diff
changeset
|
1226 In a Lisp program, if you want to be sure of accessing a file's |
030c40d12288
(insert-file-literally): New command.
Richard M. Stallman <rms@gnu.org>
parents:
19199
diff
changeset
|
1227 contents literally, you should create a temporary buffer and then read |
030c40d12288
(insert-file-literally): New command.
Richard M. Stallman <rms@gnu.org>
parents:
19199
diff
changeset
|
1228 the file contents into it using `insert-file-contents-literally'." |
18676
3980293d3bbd
(find-file-literally): New function.
Richard M. Stallman <rms@gnu.org>
parents:
18466
diff
changeset
|
1229 (interactive "FFind file literally: ") |
19305
030c40d12288
(insert-file-literally): New command.
Richard M. Stallman <rms@gnu.org>
parents:
19199
diff
changeset
|
1230 (switch-to-buffer (find-file-noselect filename nil t))) |
337 | 1231 |
8650
deb008af7049
(after-find-file-from-revert-buffer): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents:
8618
diff
changeset
|
1232 (defvar after-find-file-from-revert-buffer nil) |
deb008af7049
(after-find-file-from-revert-buffer): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents:
8618
diff
changeset
|
1233 |
8556
04a87d0e4a62
(after-find-file): New arg renamed to after-find-file-from-revert-buffer.
Richard M. Stallman <rms@gnu.org>
parents:
8554
diff
changeset
|
1234 (defun after-find-file (&optional error warn noauto |
13857
aa5e493a867d
(revert-buffer): New arg preserve-modes.
Richard M. Stallman <rms@gnu.org>
parents:
13832
diff
changeset
|
1235 after-find-file-from-revert-buffer |
aa5e493a867d
(revert-buffer): New arg preserve-modes.
Richard M. Stallman <rms@gnu.org>
parents:
13832
diff
changeset
|
1236 nomodes) |
337 | 1237 "Called after finding a file and by the default revert function. |
1238 Sets buffer mode, parses local variables. | |
1212
de70f50101c0
(after-find-file): New arg NOAUTO.
Richard M. Stallman <rms@gnu.org>
parents:
1182
diff
changeset
|
1239 Optional args ERROR, WARN, and NOAUTO: ERROR non-nil means there was an |
337 | 1240 error in reading the file. WARN non-nil means warn if there |
1241 exists an auto-save file more recent than the visited file. | |
1212
de70f50101c0
(after-find-file): New arg NOAUTO.
Richard M. Stallman <rms@gnu.org>
parents:
1182
diff
changeset
|
1242 NOAUTO means don't mess with auto-save mode. |
8556
04a87d0e4a62
(after-find-file): New arg renamed to after-find-file-from-revert-buffer.
Richard M. Stallman <rms@gnu.org>
parents:
8554
diff
changeset
|
1243 Fourth arg AFTER-FIND-FILE-FROM-REVERT-BUFFER non-nil |
04a87d0e4a62
(after-find-file): New arg renamed to after-find-file-from-revert-buffer.
Richard M. Stallman <rms@gnu.org>
parents:
8554
diff
changeset
|
1244 means this call was from `revert-buffer'. |
13857
aa5e493a867d
(revert-buffer): New arg preserve-modes.
Richard M. Stallman <rms@gnu.org>
parents:
13832
diff
changeset
|
1245 Fifth arg NOMODES non-nil means don't alter the file's modes. |
aa5e493a867d
(revert-buffer): New arg preserve-modes.
Richard M. Stallman <rms@gnu.org>
parents:
13832
diff
changeset
|
1246 Finishes by calling the functions in `find-file-hooks' |
aa5e493a867d
(revert-buffer): New arg preserve-modes.
Richard M. Stallman <rms@gnu.org>
parents:
13832
diff
changeset
|
1247 unless NOMODES is non-nil." |
337 | 1248 (setq buffer-read-only (not (file-writable-p buffer-file-name))) |
1249 (if noninteractive | |
1250 nil | |
1251 (let* (not-serious | |
1252 (msg | |
32830
1e6c5cca37db
(after-find-file): Don't print any warnings if
Gerd Moellmann <gerd@gnu.org>
parents:
32828
diff
changeset
|
1253 (cond |
1e6c5cca37db
(after-find-file): Don't print any warnings if
Gerd Moellmann <gerd@gnu.org>
parents:
32828
diff
changeset
|
1254 ((not warn) nil) |
1e6c5cca37db
(after-find-file): Don't print any warnings if
Gerd Moellmann <gerd@gnu.org>
parents:
32828
diff
changeset
|
1255 ((and error (file-attributes buffer-file-name)) |
1e6c5cca37db
(after-find-file): Don't print any warnings if
Gerd Moellmann <gerd@gnu.org>
parents:
32828
diff
changeset
|
1256 (setq buffer-read-only t) |
1e6c5cca37db
(after-find-file): Don't print any warnings if
Gerd Moellmann <gerd@gnu.org>
parents:
32828
diff
changeset
|
1257 "File exists, but cannot be read") |
1e6c5cca37db
(after-find-file): Don't print any warnings if
Gerd Moellmann <gerd@gnu.org>
parents:
32828
diff
changeset
|
1258 ((not buffer-read-only) |
1e6c5cca37db
(after-find-file): Don't print any warnings if
Gerd Moellmann <gerd@gnu.org>
parents:
32828
diff
changeset
|
1259 (if (and warn |
1e6c5cca37db
(after-find-file): Don't print any warnings if
Gerd Moellmann <gerd@gnu.org>
parents:
32828
diff
changeset
|
1260 ;; No need to warn if buffer is auto-saved |
1e6c5cca37db
(after-find-file): Don't print any warnings if
Gerd Moellmann <gerd@gnu.org>
parents:
32828
diff
changeset
|
1261 ;; under the name of the visited file. |
1e6c5cca37db
(after-find-file): Don't print any warnings if
Gerd Moellmann <gerd@gnu.org>
parents:
32828
diff
changeset
|
1262 (not (and buffer-file-name |
1e6c5cca37db
(after-find-file): Don't print any warnings if
Gerd Moellmann <gerd@gnu.org>
parents:
32828
diff
changeset
|
1263 auto-save-visited-file-name)) |
1e6c5cca37db
(after-find-file): Don't print any warnings if
Gerd Moellmann <gerd@gnu.org>
parents:
32828
diff
changeset
|
1264 (file-newer-than-file-p (or buffer-auto-save-file-name |
1e6c5cca37db
(after-find-file): Don't print any warnings if
Gerd Moellmann <gerd@gnu.org>
parents:
32828
diff
changeset
|
1265 (make-auto-save-file-name)) |
1e6c5cca37db
(after-find-file): Don't print any warnings if
Gerd Moellmann <gerd@gnu.org>
parents:
32828
diff
changeset
|
1266 buffer-file-name)) |
1e6c5cca37db
(after-find-file): Don't print any warnings if
Gerd Moellmann <gerd@gnu.org>
parents:
32828
diff
changeset
|
1267 (format "%s has auto save data; consider M-x recover-file" |
1e6c5cca37db
(after-find-file): Don't print any warnings if
Gerd Moellmann <gerd@gnu.org>
parents:
32828
diff
changeset
|
1268 (file-name-nondirectory buffer-file-name)) |
1e6c5cca37db
(after-find-file): Don't print any warnings if
Gerd Moellmann <gerd@gnu.org>
parents:
32828
diff
changeset
|
1269 (setq not-serious t) |
1e6c5cca37db
(after-find-file): Don't print any warnings if
Gerd Moellmann <gerd@gnu.org>
parents:
32828
diff
changeset
|
1270 (if error "(New file)" nil))) |
1e6c5cca37db
(after-find-file): Don't print any warnings if
Gerd Moellmann <gerd@gnu.org>
parents:
32828
diff
changeset
|
1271 ((not error) |
1e6c5cca37db
(after-find-file): Don't print any warnings if
Gerd Moellmann <gerd@gnu.org>
parents:
32828
diff
changeset
|
1272 (setq not-serious t) |
1e6c5cca37db
(after-find-file): Don't print any warnings if
Gerd Moellmann <gerd@gnu.org>
parents:
32828
diff
changeset
|
1273 "Note: file is write protected") |
1e6c5cca37db
(after-find-file): Don't print any warnings if
Gerd Moellmann <gerd@gnu.org>
parents:
32828
diff
changeset
|
1274 ((file-attributes (directory-file-name default-directory)) |
1e6c5cca37db
(after-find-file): Don't print any warnings if
Gerd Moellmann <gerd@gnu.org>
parents:
32828
diff
changeset
|
1275 "File not found and directory write-protected") |
1e6c5cca37db
(after-find-file): Don't print any warnings if
Gerd Moellmann <gerd@gnu.org>
parents:
32828
diff
changeset
|
1276 ((file-exists-p (file-name-directory buffer-file-name)) |
1e6c5cca37db
(after-find-file): Don't print any warnings if
Gerd Moellmann <gerd@gnu.org>
parents:
32828
diff
changeset
|
1277 (setq buffer-read-only nil)) |
1e6c5cca37db
(after-find-file): Don't print any warnings if
Gerd Moellmann <gerd@gnu.org>
parents:
32828
diff
changeset
|
1278 (t |
1e6c5cca37db
(after-find-file): Don't print any warnings if
Gerd Moellmann <gerd@gnu.org>
parents:
32828
diff
changeset
|
1279 (setq buffer-read-only nil) |
1e6c5cca37db
(after-find-file): Don't print any warnings if
Gerd Moellmann <gerd@gnu.org>
parents:
32828
diff
changeset
|
1280 (if (file-exists-p (file-name-directory (directory-file-name (file-name-directory buffer-file-name)))) |
1e6c5cca37db
(after-find-file): Don't print any warnings if
Gerd Moellmann <gerd@gnu.org>
parents:
32828
diff
changeset
|
1281 "Use M-x make-directory RET RET to create the directory" |
1e6c5cca37db
(after-find-file): Don't print any warnings if
Gerd Moellmann <gerd@gnu.org>
parents:
32828
diff
changeset
|
1282 "Use C-u M-x make-directory RET RET to create directory and its parents"))))) |
1e6c5cca37db
(after-find-file): Don't print any warnings if
Gerd Moellmann <gerd@gnu.org>
parents:
32828
diff
changeset
|
1283 (when msg |
1e6c5cca37db
(after-find-file): Don't print any warnings if
Gerd Moellmann <gerd@gnu.org>
parents:
32828
diff
changeset
|
1284 (message msg) |
1e6c5cca37db
(after-find-file): Don't print any warnings if
Gerd Moellmann <gerd@gnu.org>
parents:
32828
diff
changeset
|
1285 (or not-serious (sit-for 1 nil t)))) |
1e6c5cca37db
(after-find-file): Don't print any warnings if
Gerd Moellmann <gerd@gnu.org>
parents:
32828
diff
changeset
|
1286 (when (and auto-save-default (not noauto)) |
1e6c5cca37db
(after-find-file): Don't print any warnings if
Gerd Moellmann <gerd@gnu.org>
parents:
32828
diff
changeset
|
1287 (auto-save-mode t))) |
32138 | 1288 ;; Make people do a little extra work (C-x C-q) |
1289 ;; before altering a backup file. | |
32830
1e6c5cca37db
(after-find-file): Don't print any warnings if
Gerd Moellmann <gerd@gnu.org>
parents:
32828
diff
changeset
|
1290 (when (backup-file-name-p buffer-file-name) |
1e6c5cca37db
(after-find-file): Don't print any warnings if
Gerd Moellmann <gerd@gnu.org>
parents:
32828
diff
changeset
|
1291 (setq buffer-read-only t)) |
1e6c5cca37db
(after-find-file): Don't print any warnings if
Gerd Moellmann <gerd@gnu.org>
parents:
32828
diff
changeset
|
1292 (unless nomodes |
1e6c5cca37db
(after-find-file): Don't print any warnings if
Gerd Moellmann <gerd@gnu.org>
parents:
32828
diff
changeset
|
1293 (when (and view-read-only view-mode) |
1e6c5cca37db
(after-find-file): Don't print any warnings if
Gerd Moellmann <gerd@gnu.org>
parents:
32828
diff
changeset
|
1294 (view-mode-disable)) |
13857
aa5e493a867d
(revert-buffer): New arg preserve-modes.
Richard M. Stallman <rms@gnu.org>
parents:
13832
diff
changeset
|
1295 (normal-mode t) |
32830
1e6c5cca37db
(after-find-file): Don't print any warnings if
Gerd Moellmann <gerd@gnu.org>
parents:
32828
diff
changeset
|
1296 (when (and buffer-read-only |
1e6c5cca37db
(after-find-file): Don't print any warnings if
Gerd Moellmann <gerd@gnu.org>
parents:
32828
diff
changeset
|
1297 view-read-only |
1e6c5cca37db
(after-find-file): Don't print any warnings if
Gerd Moellmann <gerd@gnu.org>
parents:
32828
diff
changeset
|
1298 (not (eq (get major-mode 'mode-class) 'special))) |
1e6c5cca37db
(after-find-file): Don't print any warnings if
Gerd Moellmann <gerd@gnu.org>
parents:
32828
diff
changeset
|
1299 (view-mode-enter)) |
13857
aa5e493a867d
(revert-buffer): New arg preserve-modes.
Richard M. Stallman <rms@gnu.org>
parents:
13832
diff
changeset
|
1300 (run-hooks 'find-file-hooks))) |
337 | 1301 |
1302 (defun normal-mode (&optional find-file) | |
1303 "Choose the major mode for this buffer automatically. | |
1304 Also sets up any specified local variables of the file. | |
1305 Uses the visited file name, the -*- line, and the local variables spec. | |
1306 | |
1307 This function is called automatically from `find-file'. In that case, | |
23657
7f5af9d1766d
(hack-local-variables): Test local-enable-local-variables.
Karl Heuer <kwzh@gnu.org>
parents:
23606
diff
changeset
|
1308 we may set up the file-specified mode and local variables, |
7f5af9d1766d
(hack-local-variables): Test local-enable-local-variables.
Karl Heuer <kwzh@gnu.org>
parents:
23606
diff
changeset
|
1309 depending on the value of `enable-local-variables': if it is t, we do; |
7f5af9d1766d
(hack-local-variables): Test local-enable-local-variables.
Karl Heuer <kwzh@gnu.org>
parents:
23606
diff
changeset
|
1310 if it is nil, we don't; otherwise, we query. |
7f5af9d1766d
(hack-local-variables): Test local-enable-local-variables.
Karl Heuer <kwzh@gnu.org>
parents:
23606
diff
changeset
|
1311 In addition, if `local-enable-local-variables' is nil, we do |
7f5af9d1766d
(hack-local-variables): Test local-enable-local-variables.
Karl Heuer <kwzh@gnu.org>
parents:
23606
diff
changeset
|
1312 not set local variables (though we do notice a mode specified with -*-.) |
7f5af9d1766d
(hack-local-variables): Test local-enable-local-variables.
Karl Heuer <kwzh@gnu.org>
parents:
23606
diff
changeset
|
1313 |
7f5af9d1766d
(hack-local-variables): Test local-enable-local-variables.
Karl Heuer <kwzh@gnu.org>
parents:
23606
diff
changeset
|
1314 `enable-local-variables' is ignored if you run `normal-mode' interactively, |
7f5af9d1766d
(hack-local-variables): Test local-enable-local-variables.
Karl Heuer <kwzh@gnu.org>
parents:
23606
diff
changeset
|
1315 or from Lisp without specifying the optional argument FIND-FILE; |
7f5af9d1766d
(hack-local-variables): Test local-enable-local-variables.
Karl Heuer <kwzh@gnu.org>
parents:
23606
diff
changeset
|
1316 in that case, this function acts as if `enable-local-variables' were t." |
337 | 1317 (interactive) |
1318 (or find-file (funcall (or default-major-mode 'fundamental-mode))) | |
1319 (condition-case err | |
1320 (set-auto-mode) | |
1321 (error (message "File mode specification error: %s" | |
1322 (prin1-to-string err)))) | |
1323 (condition-case err | |
566 | 1324 (let ((enable-local-variables (or (not find-file) |
1325 enable-local-variables))) | |
1326 (hack-local-variables)) | |
337 | 1327 (error (message "File local-variables error: %s" |
1328 (prin1-to-string err))))) | |
1329 | |
13662
cb0496b98829
(auto-mode-alist): Don't purecopy the alist elts.
Richard M. Stallman <rms@gnu.org>
parents:
13497
diff
changeset
|
1330 (defvar auto-mode-alist |
32138 | 1331 (mapc |
1332 (lambda (elt) | |
1333 (cons (purecopy (car elt)) (cdr elt))) | |
1334 '(("\\.te?xt\\'" . text-mode) | |
1335 ("\\.c\\'" . c-mode) | |
1336 ("\\.h\\'" . c-mode) | |
1337 ("\\.tex\\'" . tex-mode) | |
1338 ("\\.ltx\\'" . latex-mode) | |
1339 ("\\.el\\'" . emacs-lisp-mode) | |
1340 ("\\.scm\\'" . scheme-mode) | |
1341 ("\\.l\\'" . lisp-mode) | |
1342 ("\\.lisp\\'" . lisp-mode) | |
1343 ("\\.f\\'" . fortran-mode) | |
1344 ("\\.F\\'" . fortran-mode) | |
1345 ("\\.for\\'" . fortran-mode) | |
1346 ("\\.p\\'" . pascal-mode) | |
1347 ("\\.pas\\'" . pascal-mode) | |
1348 ("\\.ad[abs]\\'" . ada-mode) | |
1349 ("\\.\\([pP][Llm]\\|al\\)\\'" . perl-mode) | |
1350 ("\\.s?html?\\'" . html-mode) | |
1351 ("\\.cc\\'" . c++-mode) | |
1352 ("\\.hh\\'" . c++-mode) | |
1353 ("\\.hpp\\'" . c++-mode) | |
1354 ("\\.C\\'" . c++-mode) | |
1355 ("\\.H\\'" . c++-mode) | |
1356 ("\\.cpp\\'" . c++-mode) | |
1357 ("\\.cxx\\'" . c++-mode) | |
1358 ("\\.hxx\\'" . c++-mode) | |
1359 ("\\.c\\+\\+\\'" . c++-mode) | |
1360 ("\\.h\\+\\+\\'" . c++-mode) | |
1361 ("\\.m\\'" . objc-mode) | |
1362 ("\\.java\\'" . java-mode) | |
1363 ("\\.mk\\'" . makefile-mode) | |
1364 ("\\(M\\|m\\|GNUm\\)akefile\\(\\.in\\)?\\'" . makefile-mode) | |
1365 ("\\.am\\'" . makefile-mode) ;For Automake. | |
566 | 1366 ;;; Less common extensions come here |
1367 ;;; so more common ones above are found faster. | |
32138 | 1368 ("\\.texinfo\\'" . texinfo-mode) |
1369 ("\\.te?xi\\'" . texinfo-mode) | |
1370 ("\\.s\\'" . asm-mode) | |
1371 ("\\.S\\'" . asm-mode) | |
1372 ("\\.asm\\'" . asm-mode) | |
1373 ("ChangeLog\\'" . change-log-mode) | |
1374 ("change\\.log\\'" . change-log-mode) | |
1375 ("changelo\\'" . change-log-mode) | |
1376 ("ChangeLog\\.[0-9]+\\'" . change-log-mode) | |
1377 ;; for MSDOS and MS-Windows (which are case-insensitive) | |
1378 ("changelog\\'" . change-log-mode) | |
1379 ("changelog\\.[0-9]+\\'" . change-log-mode) | |
1380 ("\\$CHANGE_LOG\\$\\.TXT" . change-log-mode) | |
1381 ("\\.scm\\.[0-9]*\\'" . scheme-mode) | |
1382 ("\\.[ck]?sh\\'\\|\\.shar\\'\\|/\\.z?profile\\'" . sh-mode) | |
1383 ("\\(/\\|\\`\\)\\.\\(bash_profile\\|z?login\\|bash_login\\|z?logout\\)\\'" . sh-mode) | |
1384 ("\\(/\\|\\`\\)\\.\\(bash_logout\\|shrc\\|[kz]shrc\\|bashrc\\|t?cshrc\\|esrc\\)\\'" . sh-mode) | |
1385 ("\\(/\\|\\`\\)\\.\\([kz]shenv\\|xinitrc\\|startxrc\\|xsession\\)\\'" . sh-mode) | |
33703
af0f3f3533e8
(find-buffer-visiting): Compare all attributes before
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33558
diff
changeset
|
1386 ("\\.m?spec\\'" . sh-mode) |
32138 | 1387 ("\\.mm\\'" . nroff-mode) |
1388 ("\\.me\\'" . nroff-mode) | |
1389 ("\\.ms\\'" . nroff-mode) | |
1390 ("\\.man\\'" . nroff-mode) | |
1391 ("\\.\\(u?lpc\\|pike\\|pmod\\)\\'" . pike-mode) | |
1392 ("\\.TeX\\'" . tex-mode) | |
1393 ("\\.sty\\'" . latex-mode) | |
1394 ("\\.cls\\'" . latex-mode) ;LaTeX 2e class | |
1395 ("\\.clo\\'" . latex-mode) ;LaTeX 2e class option | |
1396 ("\\.bbl\\'" . latex-mode) | |
1397 ("\\.bib\\'" . bibtex-mode) | |
1398 ("\\.sql\\'" . sql-mode) | |
1399 ("\\.m4\\'" . m4-mode) | |
1400 ("\\.mc\\'" . m4-mode) | |
1401 ("\\.mf\\'" . metafont-mode) | |
1402 ("\\.mp\\'" . metapost-mode) | |
1403 ("\\.vhdl?\\'" . vhdl-mode) | |
1404 ("\\.article\\'" . text-mode) | |
1405 ("\\.letter\\'" . text-mode) | |
1406 ("\\.tcl\\'" . tcl-mode) | |
1407 ("\\.exp\\'" . tcl-mode) | |
1408 ("\\.itcl\\'" . tcl-mode) | |
1409 ("\\.itk\\'" . tcl-mode) | |
1410 ("\\.icn\\'" . icon-mode) | |
1411 ("\\.sim\\'" . simula-mode) | |
1412 ("\\.mss\\'" . scribe-mode) | |
1413 ("\\.f90\\'" . f90-mode) | |
1414 ("\\.pro\\'" . idlwave-mode) | |
1415 ("\\.lsp\\'" . lisp-mode) | |
1416 ("\\.awk\\'" . awk-mode) | |
1417 ("\\.prolog\\'" . prolog-mode) | |
1418 ("\\.tar\\'" . tar-mode) | |
1419 ("\\.\\(arc\\|zip\\|lzh\\|zoo\\|jar\\)\\'" . archive-mode) | |
1420 ("\\.\\(ARC\\|ZIP\\|LZH\\|ZOO\\|JAR\\)\\'" . archive-mode) | |
1421 ;; Mailer puts message to be edited in | |
1422 ;; /tmp/Re.... or Message | |
1423 ("\\`/tmp/Re" . text-mode) | |
1424 ("/Message[0-9]*\\'" . text-mode) | |
1425 ("/drafts/[0-9]+\\'" . mh-letter-mode) | |
1426 ("\\.zone\\'" . zone-mode) | |
1427 ;; some news reader is reported to use this | |
1428 ("\\`/tmp/fol/" . text-mode) | |
1429 ("\\.y\\'" . c-mode) | |
1430 ("\\.lex\\'" . c-mode) | |
1431 ("\\.oak\\'" . scheme-mode) | |
1432 ("\\.sgml?\\'" . sgml-mode) | |
1433 ("\\.xml\\'" . sgml-mode) | |
1434 ("\\.dtd\\'" . sgml-mode) | |
1435 ("\\.ds\\(ss\\)?l\\'" . dsssl-mode) | |
1436 ("\\.idl\\'" . idl-mode) | |
1437 ;; .emacs following a directory delimiter | |
1438 ;; in Unix, MSDOG or VMS syntax. | |
1439 ("[]>:/\\]\\..*emacs\\'" . emacs-lisp-mode) | |
1440 ("\\`\\..*emacs\\'" . emacs-lisp-mode) | |
1441 ;; _emacs following a directory delimiter | |
1442 ;; in MsDos syntax | |
1443 ("[:/]_emacs\\'" . emacs-lisp-mode) | |
1444 ("/crontab\\.X*[0-9]+\\'" . shell-script-mode) | |
1445 ("\\.ml\\'" . lisp-mode) | |
33703
af0f3f3533e8
(find-buffer-visiting): Compare all attributes before
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33558
diff
changeset
|
1446 ("\\.\\(asn\\|mib\\|smi\\)\\'" . snmp-mode) |
af0f3f3533e8
(find-buffer-visiting): Compare all attributes before
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33558
diff
changeset
|
1447 ("\\.\\(as\\|mi\\|sm\\)2\\'" . snmpv2-mode) |
32138 | 1448 ("\\.\\(diffs?\\|patch\\|rej\\)\\'" . diff-mode) |
32579
d06fc5f25d6c
(auto-mode-alist): Add .dif and .pat as diff-mode extensions, for MS-DOS.
Eli Zaretskii <eliz@gnu.org>
parents:
32253
diff
changeset
|
1449 ("\\.\\(dif\\|pat\\)\\'" . diff-mode) ; for MSDOG |
33703
af0f3f3533e8
(find-buffer-visiting): Compare all attributes before
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33558
diff
changeset
|
1450 ("\\.[eE]?[pP][sS]\\'" . ps-mode) |
32138 | 1451 ("configure\\.in\\'" . autoconf-mode) |
1452 ("BROWSE\\'" . ebrowse-tree-mode) | |
1453 ("\\.ebrowse\\'" . ebrowse-tree-mode) | |
32240
f2a40beeddaa
(set-auto-mode): Ignore unknown -*- mode -*- rather than
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32138
diff
changeset
|
1454 ("#\\*mail\\*" . mail-mode) |
f2a40beeddaa
(set-auto-mode): Ignore unknown -*- mode -*- rather than
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32138
diff
changeset
|
1455 ;; Get rid of any trailing .n.m and try again. |
f2a40beeddaa
(set-auto-mode): Ignore unknown -*- mode -*- rather than
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32138
diff
changeset
|
1456 ;; This is for files saved by cvs-merge that look like .#<file>.<rev> |
f2a40beeddaa
(set-auto-mode): Ignore unknown -*- mode -*- rather than
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32138
diff
changeset
|
1457 ;; or .#<file>.<rev>-<rev> or VC's <file>.~<rev>~ |
f2a40beeddaa
(set-auto-mode): Ignore unknown -*- mode -*- rather than
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32138
diff
changeset
|
1458 ("\\.~?[0-9]+\\.[0-9][-.0-9]*~?\\'" nil t) |
f2a40beeddaa
(set-auto-mode): Ignore unknown -*- mode -*- rather than
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32138
diff
changeset
|
1459 ;;; The following should come after the ChangeLog pattern |
f2a40beeddaa
(set-auto-mode): Ignore unknown -*- mode -*- rather than
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32138
diff
changeset
|
1460 ;;; for the sake of ChangeLog.1, etc. |
f2a40beeddaa
(set-auto-mode): Ignore unknown -*- mode -*- rather than
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32138
diff
changeset
|
1461 ;;; and after the .scm.[0-9] and CVS' <file>.<rev> patterns too. |
34009
8091ba37be87
(auto-mode-alist): Add an entry for antlr-mode.
Gerd Moellmann <gerd@gnu.org>
parents:
33703
diff
changeset
|
1462 ("\\.[12345678]\\'" . nroff-mode) |
8091ba37be87
(auto-mode-alist): Add an entry for antlr-mode.
Gerd Moellmann <gerd@gnu.org>
parents:
33703
diff
changeset
|
1463 ("\\.g\\'" . antlr-mode))) |
32138 | 1464 "Alist of filename patterns vs corresponding major mode functions. |
9602
13106af26190
(auto-mode-alist): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
9601
diff
changeset
|
1465 Each element looks like (REGEXP . FUNCTION) or (REGEXP FUNCTION NON-NIL). |
13106af26190
(auto-mode-alist): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
9601
diff
changeset
|
1466 \(NON-NIL stands for anything that is not nil; the value does not matter.) |
13106af26190
(auto-mode-alist): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
9601
diff
changeset
|
1467 Visiting a file whose name matches REGEXP specifies FUNCTION as the |
13106af26190
(auto-mode-alist): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
9601
diff
changeset
|
1468 mode function to use. FUNCTION will be called, unless it is nil. |
13106af26190
(auto-mode-alist): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
9601
diff
changeset
|
1469 |
13106af26190
(auto-mode-alist): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
9601
diff
changeset
|
1470 If the element has the form (REGEXP FUNCTION NON-NIL), then after |
13106af26190
(auto-mode-alist): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
9601
diff
changeset
|
1471 calling FUNCTION (if it's not nil), we delete the suffix that matched |
13106af26190
(auto-mode-alist): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
9601
diff
changeset
|
1472 REGEXP and search the list again for another match.") |
566 | 1473 |
21069
e99cb5736904
(auto-mode-alist): Recognize zone-mode.
Richard M. Stallman <rms@gnu.org>
parents:
21046
diff
changeset
|
1474 |
16687
049c87a96dca
Change defconsts to defvars.
Richard M. Stallman <rms@gnu.org>
parents:
16684
diff
changeset
|
1475 (defvar interpreter-mode-alist |
32138 | 1476 (mapc |
1477 (lambda (l) | |
1478 (cons (purecopy (car l)) (cdr l))) | |
1479 '(("perl" . perl-mode) | |
1480 ("perl5" . perl-mode) | |
1481 ("miniperl" . perl-mode) | |
1482 ("wish" . tcl-mode) | |
1483 ("wishx" . tcl-mode) | |
1484 ("tcl" . tcl-mode) | |
1485 ("tclsh" . tcl-mode) | |
1486 ("awk" . awk-mode) | |
1487 ("mawk" . awk-mode) | |
1488 ("nawk" . awk-mode) | |
1489 ("gawk" . awk-mode) | |
1490 ("scm" . scheme-mode) | |
1491 ("ash" . sh-mode) | |
1492 ("bash" . sh-mode) | |
1493 ("bash2" . sh-mode) | |
1494 ("csh" . sh-mode) | |
1495 ("dtksh" . sh-mode) | |
1496 ("es" . sh-mode) | |
1497 ("itcsh" . sh-mode) | |
1498 ("jsh" . sh-mode) | |
1499 ("ksh" . sh-mode) | |
1500 ("oash" . sh-mode) | |
1501 ("pdksh" . sh-mode) | |
1502 ("rc" . sh-mode) | |
1503 ("rpm" . sh-mode) | |
1504 ("sh" . sh-mode) | |
1505 ("sh5" . sh-mode) | |
1506 ("tcsh" . sh-mode) | |
1507 ("wksh" . sh-mode) | |
1508 ("wsh" . sh-mode) | |
1509 ("zsh" . sh-mode) | |
1510 ("tail" . text-mode) | |
1511 ("more" . text-mode) | |
1512 ("less" . text-mode) | |
1513 ("pg" . text-mode) | |
1514 ("make" . makefile-mode) ; Debian uses this | |
1515 ("guile" . scheme-mode) | |
1516 ("clisp" . lisp-mode))) | |
5956
586a37656a31
(interpreter-mode-alist): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
5804
diff
changeset
|
1517 "Alist mapping interpreter names to major modes. |
586a37656a31
(interpreter-mode-alist): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
5804
diff
changeset
|
1518 This alist applies to files whose first line starts with `#!'. |
586a37656a31
(interpreter-mode-alist): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
5804
diff
changeset
|
1519 Each element looks like (INTERPRETER . MODE). |
586a37656a31
(interpreter-mode-alist): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
5804
diff
changeset
|
1520 The car of each element is compared with |
586a37656a31
(interpreter-mode-alist): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
5804
diff
changeset
|
1521 the name of the interpreter specified in the first line. |
586a37656a31
(interpreter-mode-alist): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
5804
diff
changeset
|
1522 If it matches, mode MODE is selected.") |
586a37656a31
(interpreter-mode-alist): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
5804
diff
changeset
|
1523 |
16687
049c87a96dca
Change defconsts to defvars.
Richard M. Stallman <rms@gnu.org>
parents:
16684
diff
changeset
|
1524 (defvar inhibit-first-line-modes-regexps '("\\.tar\\'" "\\.tgz\\'") |
6780
06eb068ba329
(inhibit-first-line-modes-regexps): Renamed from
Richard M. Stallman <rms@gnu.org>
parents:
6734
diff
changeset
|
1525 "List of regexps; if one matches a file name, don't look for `-*-'.") |
3364
3dd9b89c6a17
(inhibit-local-variables-regexps): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
3280
diff
changeset
|
1526 |
16687
049c87a96dca
Change defconsts to defvars.
Richard M. Stallman <rms@gnu.org>
parents:
16684
diff
changeset
|
1527 (defvar inhibit-first-line-modes-suffixes nil |
11180
7a9dceb0fb96
(inhibit-first-line-modes-suffixes): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
11160
diff
changeset
|
1528 "List of regexps for what to ignore, for `inhibit-first-line-modes-regexps'. |
7a9dceb0fb96
(inhibit-first-line-modes-suffixes): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
11160
diff
changeset
|
1529 When checking `inhibit-first-line-modes-regexps', we first discard |
7a9dceb0fb96
(inhibit-first-line-modes-suffixes): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
11160
diff
changeset
|
1530 from the end of the file name anything that matches one of these regexps.") |
7a9dceb0fb96
(inhibit-first-line-modes-suffixes): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
11160
diff
changeset
|
1531 |
32138 | 1532 (defvar auto-mode-interpreter-regexp |
1533 "#![ \t]?\\([^ \t\n]*\ | |
1534 /bin/env[ \t]\\)?\\([^ \t\n]+\\)" | |
1535 "Regular expression matching interpreters, for file mode determination. | |
1536 This regular expression is matched against the first line of a file | |
1537 to determine the file's mode in `set-auto-mode' when Emacs can't deduce | |
1538 a mode from the file's name. If it matches, the file is assumed to | |
1539 be interpreted by the interpreter matched by the second group of the | |
1540 regular expression. The mode is then determined as the mode associated | |
1541 with that interpreter in `interpreter-mode-alist'.") | |
30689
194b7f43b959
(auto-mode-interpreter-regexp): New variable.
Gerd Moellmann <gerd@gnu.org>
parents:
30630
diff
changeset
|
1542 |
17660
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1543 (defun set-auto-mode (&optional just-from-file-name) |
337 | 1544 "Select major mode appropriate for current buffer. |
7662
25cf7bc3b8c5
(interpreter-mode-alist): Add wishx, tclsh.
Richard M. Stallman <rms@gnu.org>
parents:
7643
diff
changeset
|
1545 This checks for a -*- mode tag in the buffer's text, |
25cf7bc3b8c5
(interpreter-mode-alist): Add wishx, tclsh.
Richard M. Stallman <rms@gnu.org>
parents:
7643
diff
changeset
|
1546 compares the filename against the entries in `auto-mode-alist', |
25cf7bc3b8c5
(interpreter-mode-alist): Add wishx, tclsh.
Richard M. Stallman <rms@gnu.org>
parents:
7643
diff
changeset
|
1547 or checks the interpreter that runs this file against |
25cf7bc3b8c5
(interpreter-mode-alist): Add wishx, tclsh.
Richard M. Stallman <rms@gnu.org>
parents:
7643
diff
changeset
|
1548 `interpreter-mode-alist'. |
25cf7bc3b8c5
(interpreter-mode-alist): Add wishx, tclsh.
Richard M. Stallman <rms@gnu.org>
parents:
7643
diff
changeset
|
1549 |
25cf7bc3b8c5
(interpreter-mode-alist): Add wishx, tclsh.
Richard M. Stallman <rms@gnu.org>
parents:
7643
diff
changeset
|
1550 It does not check for the `mode:' local variable in the |
25cf7bc3b8c5
(interpreter-mode-alist): Add wishx, tclsh.
Richard M. Stallman <rms@gnu.org>
parents:
7643
diff
changeset
|
1551 Local Variables section of the file; for that, use `hack-local-variables'. |
566 | 1552 |
1395
f6f838c4a26e
(buffer-file-number): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1371
diff
changeset
|
1553 If `enable-local-variables' is nil, this function does not check for a |
17660
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1554 -*- mode tag. |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1555 |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1556 If the optional argument JUST-FROM-FILE-NAME is non-nil, |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1557 then we do not set anything but the major mode, |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1558 and we don't even do that unless it would come from the file name." |
337 | 1559 ;; Look for -*-MODENAME-*- or -*- ... mode: MODENAME; ... -*- |
13496
1bd9f5d576ce
(set-auto-mode): If mode cmds move point, obey them.
Richard M. Stallman <rms@gnu.org>
parents:
13326
diff
changeset
|
1560 (let (beg end done modes) |
337 | 1561 (save-excursion |
1562 (goto-char (point-min)) | |
1563 (skip-chars-forward " \t\n") | |
4699
f57fe6dbf4a0
(hack-local-variables-prop-line): Ignore any specification
Richard M. Stallman <rms@gnu.org>
parents:
4645
diff
changeset
|
1564 (and enable-local-variables |
f57fe6dbf4a0
(hack-local-variables-prop-line): Ignore any specification
Richard M. Stallman <rms@gnu.org>
parents:
4645
diff
changeset
|
1565 ;; Don't look for -*- if this file name matches any |
6780
06eb068ba329
(inhibit-first-line-modes-regexps): Renamed from
Richard M. Stallman <rms@gnu.org>
parents:
6734
diff
changeset
|
1566 ;; of the regexps in inhibit-first-line-modes-regexps. |
9251
2ecfcd3f778c
(set-auto-mode): Discard versions from file name before
Richard M. Stallman <rms@gnu.org>
parents:
9234
diff
changeset
|
1567 (let ((temp inhibit-first-line-modes-regexps) |
11636
919ac497342e
(set-auto-mode): If buffer has no file, use buffer name.
Richard M. Stallman <rms@gnu.org>
parents:
11630
diff
changeset
|
1568 (name (if buffer-file-name |
919ac497342e
(set-auto-mode): If buffer has no file, use buffer name.
Richard M. Stallman <rms@gnu.org>
parents:
11630
diff
changeset
|
1569 (file-name-sans-versions buffer-file-name) |
919ac497342e
(set-auto-mode): If buffer has no file, use buffer name.
Richard M. Stallman <rms@gnu.org>
parents:
11630
diff
changeset
|
1570 (buffer-name)))) |
11189
a2a85a29cdd6
(set-auto-mode): Fix previous change.
Karl Heuer <kwzh@gnu.org>
parents:
11180
diff
changeset
|
1571 (while (let ((sufs inhibit-first-line-modes-suffixes)) |
a2a85a29cdd6
(set-auto-mode): Fix previous change.
Karl Heuer <kwzh@gnu.org>
parents:
11180
diff
changeset
|
1572 (while (and sufs (not (string-match (car sufs) name))) |
a2a85a29cdd6
(set-auto-mode): Fix previous change.
Karl Heuer <kwzh@gnu.org>
parents:
11180
diff
changeset
|
1573 (setq sufs (cdr sufs))) |
a2a85a29cdd6
(set-auto-mode): Fix previous change.
Karl Heuer <kwzh@gnu.org>
parents:
11180
diff
changeset
|
1574 sufs) |
a2a85a29cdd6
(set-auto-mode): Fix previous change.
Karl Heuer <kwzh@gnu.org>
parents:
11180
diff
changeset
|
1575 (setq name (substring name 0 (match-beginning 0)))) |
4699
f57fe6dbf4a0
(hack-local-variables-prop-line): Ignore any specification
Richard M. Stallman <rms@gnu.org>
parents:
4645
diff
changeset
|
1576 (while (and temp |
11180
7a9dceb0fb96
(inhibit-first-line-modes-suffixes): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
11160
diff
changeset
|
1577 (not (string-match (car temp) name))) |
4699
f57fe6dbf4a0
(hack-local-variables-prop-line): Ignore any specification
Richard M. Stallman <rms@gnu.org>
parents:
4645
diff
changeset
|
1578 (setq temp (cdr temp))) |
f57fe6dbf4a0
(hack-local-variables-prop-line): Ignore any specification
Richard M. Stallman <rms@gnu.org>
parents:
4645
diff
changeset
|
1579 (not temp)) |
f57fe6dbf4a0
(hack-local-variables-prop-line): Ignore any specification
Richard M. Stallman <rms@gnu.org>
parents:
4645
diff
changeset
|
1580 (search-forward "-*-" (save-excursion |
f57fe6dbf4a0
(hack-local-variables-prop-line): Ignore any specification
Richard M. Stallman <rms@gnu.org>
parents:
4645
diff
changeset
|
1581 ;; If the file begins with "#!" |
f57fe6dbf4a0
(hack-local-variables-prop-line): Ignore any specification
Richard M. Stallman <rms@gnu.org>
parents:
4645
diff
changeset
|
1582 ;; (exec interpreter magic), look |
f57fe6dbf4a0
(hack-local-variables-prop-line): Ignore any specification
Richard M. Stallman <rms@gnu.org>
parents:
4645
diff
changeset
|
1583 ;; for mode frobs in the first two |
f57fe6dbf4a0
(hack-local-variables-prop-line): Ignore any specification
Richard M. Stallman <rms@gnu.org>
parents:
4645
diff
changeset
|
1584 ;; lines. You cannot necessarily |
f57fe6dbf4a0
(hack-local-variables-prop-line): Ignore any specification
Richard M. Stallman <rms@gnu.org>
parents:
4645
diff
changeset
|
1585 ;; put them in the first line of |
f57fe6dbf4a0
(hack-local-variables-prop-line): Ignore any specification
Richard M. Stallman <rms@gnu.org>
parents:
4645
diff
changeset
|
1586 ;; such a file without screwing up |
f57fe6dbf4a0
(hack-local-variables-prop-line): Ignore any specification
Richard M. Stallman <rms@gnu.org>
parents:
4645
diff
changeset
|
1587 ;; the interpreter invocation. |
f57fe6dbf4a0
(hack-local-variables-prop-line): Ignore any specification
Richard M. Stallman <rms@gnu.org>
parents:
4645
diff
changeset
|
1588 (end-of-line (and (looking-at "^#!") 2)) |
f57fe6dbf4a0
(hack-local-variables-prop-line): Ignore any specification
Richard M. Stallman <rms@gnu.org>
parents:
4645
diff
changeset
|
1589 (point)) t) |
f57fe6dbf4a0
(hack-local-variables-prop-line): Ignore any specification
Richard M. Stallman <rms@gnu.org>
parents:
4645
diff
changeset
|
1590 (progn |
f57fe6dbf4a0
(hack-local-variables-prop-line): Ignore any specification
Richard M. Stallman <rms@gnu.org>
parents:
4645
diff
changeset
|
1591 (skip-chars-forward " \t") |
f57fe6dbf4a0
(hack-local-variables-prop-line): Ignore any specification
Richard M. Stallman <rms@gnu.org>
parents:
4645
diff
changeset
|
1592 (setq beg (point)) |
f57fe6dbf4a0
(hack-local-variables-prop-line): Ignore any specification
Richard M. Stallman <rms@gnu.org>
parents:
4645
diff
changeset
|
1593 (search-forward "-*-" |
f57fe6dbf4a0
(hack-local-variables-prop-line): Ignore any specification
Richard M. Stallman <rms@gnu.org>
parents:
4645
diff
changeset
|
1594 (save-excursion (end-of-line) (point)) |
f57fe6dbf4a0
(hack-local-variables-prop-line): Ignore any specification
Richard M. Stallman <rms@gnu.org>
parents:
4645
diff
changeset
|
1595 t)) |
f57fe6dbf4a0
(hack-local-variables-prop-line): Ignore any specification
Richard M. Stallman <rms@gnu.org>
parents:
4645
diff
changeset
|
1596 (progn |
f57fe6dbf4a0
(hack-local-variables-prop-line): Ignore any specification
Richard M. Stallman <rms@gnu.org>
parents:
4645
diff
changeset
|
1597 (forward-char -3) |
f57fe6dbf4a0
(hack-local-variables-prop-line): Ignore any specification
Richard M. Stallman <rms@gnu.org>
parents:
4645
diff
changeset
|
1598 (skip-chars-backward " \t") |
f57fe6dbf4a0
(hack-local-variables-prop-line): Ignore any specification
Richard M. Stallman <rms@gnu.org>
parents:
4645
diff
changeset
|
1599 (setq end (point)) |
f57fe6dbf4a0
(hack-local-variables-prop-line): Ignore any specification
Richard M. Stallman <rms@gnu.org>
parents:
4645
diff
changeset
|
1600 (goto-char beg) |
f57fe6dbf4a0
(hack-local-variables-prop-line): Ignore any specification
Richard M. Stallman <rms@gnu.org>
parents:
4645
diff
changeset
|
1601 (if (save-excursion (search-forward ":" end t)) |
f57fe6dbf4a0
(hack-local-variables-prop-line): Ignore any specification
Richard M. Stallman <rms@gnu.org>
parents:
4645
diff
changeset
|
1602 ;; Find all specifications for the `mode:' variable |
6322 | 1603 ;; and execute them left to right. |
4699
f57fe6dbf4a0
(hack-local-variables-prop-line): Ignore any specification
Richard M. Stallman <rms@gnu.org>
parents:
4645
diff
changeset
|
1604 (while (let ((case-fold-search t)) |
10132
d6ab8efcd2ff
(set-auto-mode): Don't get confused by anything ending in "mode:" which isn't
Karl Heuer <kwzh@gnu.org>
parents:
9995
diff
changeset
|
1605 (or (and (looking-at "mode:") |
d6ab8efcd2ff
(set-auto-mode): Don't get confused by anything ending in "mode:" which isn't
Karl Heuer <kwzh@gnu.org>
parents:
9995
diff
changeset
|
1606 (goto-char (match-end 0))) |
d6ab8efcd2ff
(set-auto-mode): Don't get confused by anything ending in "mode:" which isn't
Karl Heuer <kwzh@gnu.org>
parents:
9995
diff
changeset
|
1607 (re-search-forward "[ \t;]mode:" end t))) |
4699
f57fe6dbf4a0
(hack-local-variables-prop-line): Ignore any specification
Richard M. Stallman <rms@gnu.org>
parents:
4645
diff
changeset
|
1608 (skip-chars-forward " \t") |
f57fe6dbf4a0
(hack-local-variables-prop-line): Ignore any specification
Richard M. Stallman <rms@gnu.org>
parents:
4645
diff
changeset
|
1609 (setq beg (point)) |
f57fe6dbf4a0
(hack-local-variables-prop-line): Ignore any specification
Richard M. Stallman <rms@gnu.org>
parents:
4645
diff
changeset
|
1610 (if (search-forward ";" end t) |
f57fe6dbf4a0
(hack-local-variables-prop-line): Ignore any specification
Richard M. Stallman <rms@gnu.org>
parents:
4645
diff
changeset
|
1611 (forward-char -1) |
f57fe6dbf4a0
(hack-local-variables-prop-line): Ignore any specification
Richard M. Stallman <rms@gnu.org>
parents:
4645
diff
changeset
|
1612 (goto-char end)) |
f57fe6dbf4a0
(hack-local-variables-prop-line): Ignore any specification
Richard M. Stallman <rms@gnu.org>
parents:
4645
diff
changeset
|
1613 (skip-chars-backward " \t") |
32240
f2a40beeddaa
(set-auto-mode): Ignore unknown -*- mode -*- rather than
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32138
diff
changeset
|
1614 (push (intern (concat (downcase (buffer-substring beg (point))) "-mode")) |
f2a40beeddaa
(set-auto-mode): Ignore unknown -*- mode -*- rather than
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32138
diff
changeset
|
1615 modes)) |
4699
f57fe6dbf4a0
(hack-local-variables-prop-line): Ignore any specification
Richard M. Stallman <rms@gnu.org>
parents:
4645
diff
changeset
|
1616 ;; Simple -*-MODE-*- case. |
32240
f2a40beeddaa
(set-auto-mode): Ignore unknown -*- mode -*- rather than
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32138
diff
changeset
|
1617 (push (intern (concat (downcase (buffer-substring beg end)) |
f2a40beeddaa
(set-auto-mode): Ignore unknown -*- mode -*- rather than
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32138
diff
changeset
|
1618 "-mode")) |
f2a40beeddaa
(set-auto-mode): Ignore unknown -*- mode -*- rather than
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32138
diff
changeset
|
1619 modes))))) |
13496
1bd9f5d576ce
(set-auto-mode): If mode cmds move point, obey them.
Richard M. Stallman <rms@gnu.org>
parents:
13326
diff
changeset
|
1620 ;; If we found modes to use, invoke them now, |
1bd9f5d576ce
(set-auto-mode): If mode cmds move point, obey them.
Richard M. Stallman <rms@gnu.org>
parents:
13326
diff
changeset
|
1621 ;; outside the save-excursion. |
32240
f2a40beeddaa
(set-auto-mode): Ignore unknown -*- mode -*- rather than
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32138
diff
changeset
|
1622 (unless just-from-file-name |
f2a40beeddaa
(set-auto-mode): Ignore unknown -*- mode -*- rather than
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32138
diff
changeset
|
1623 (dolist (mode (nreverse modes)) |
f2a40beeddaa
(set-auto-mode): Ignore unknown -*- mode -*- rather than
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32138
diff
changeset
|
1624 (if (not (functionp mode)) |
f2a40beeddaa
(set-auto-mode): Ignore unknown -*- mode -*- rather than
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32138
diff
changeset
|
1625 (message "Ignoring unknown mode `%s'" mode) |
f2a40beeddaa
(set-auto-mode): Ignore unknown -*- mode -*- rather than
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32138
diff
changeset
|
1626 (setq done t) |
f2a40beeddaa
(set-auto-mode): Ignore unknown -*- mode -*- rather than
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
32138
diff
changeset
|
1627 (funcall mode)))) |
13496
1bd9f5d576ce
(set-auto-mode): If mode cmds move point, obey them.
Richard M. Stallman <rms@gnu.org>
parents:
13326
diff
changeset
|
1628 ;; If we didn't find a mode from a -*- line, try using the file name. |
1bd9f5d576ce
(set-auto-mode): If mode cmds move point, obey them.
Richard M. Stallman <rms@gnu.org>
parents:
13326
diff
changeset
|
1629 (if (and (not done) buffer-file-name) |
1bd9f5d576ce
(set-auto-mode): If mode cmds move point, obey them.
Richard M. Stallman <rms@gnu.org>
parents:
13326
diff
changeset
|
1630 (let ((name buffer-file-name) |
1bd9f5d576ce
(set-auto-mode): If mode cmds move point, obey them.
Richard M. Stallman <rms@gnu.org>
parents:
13326
diff
changeset
|
1631 (keep-going t)) |
1bd9f5d576ce
(set-auto-mode): If mode cmds move point, obey them.
Richard M. Stallman <rms@gnu.org>
parents:
13326
diff
changeset
|
1632 ;; Remove backup-suffixes from file name. |
1bd9f5d576ce
(set-auto-mode): If mode cmds move point, obey them.
Richard M. Stallman <rms@gnu.org>
parents:
13326
diff
changeset
|
1633 (setq name (file-name-sans-versions name)) |
1bd9f5d576ce
(set-auto-mode): If mode cmds move point, obey them.
Richard M. Stallman <rms@gnu.org>
parents:
13326
diff
changeset
|
1634 (while keep-going |
1bd9f5d576ce
(set-auto-mode): If mode cmds move point, obey them.
Richard M. Stallman <rms@gnu.org>
parents:
13326
diff
changeset
|
1635 (setq keep-going nil) |
1bd9f5d576ce
(set-auto-mode): If mode cmds move point, obey them.
Richard M. Stallman <rms@gnu.org>
parents:
13326
diff
changeset
|
1636 (let ((alist auto-mode-alist) |
1bd9f5d576ce
(set-auto-mode): If mode cmds move point, obey them.
Richard M. Stallman <rms@gnu.org>
parents:
13326
diff
changeset
|
1637 (mode nil)) |
1bd9f5d576ce
(set-auto-mode): If mode cmds move point, obey them.
Richard M. Stallman <rms@gnu.org>
parents:
13326
diff
changeset
|
1638 ;; Find first matching alist entry. |
13832
44e936e550ae
(save-some-buffers): Don't give message if we queried.
Roland McGrath <roland@gnu.org>
parents:
13823
diff
changeset
|
1639 (let ((case-fold-search |
13496
1bd9f5d576ce
(set-auto-mode): If mode cmds move point, obey them.
Richard M. Stallman <rms@gnu.org>
parents:
13326
diff
changeset
|
1640 (memq system-type '(vax-vms windows-nt)))) |
1bd9f5d576ce
(set-auto-mode): If mode cmds move point, obey them.
Richard M. Stallman <rms@gnu.org>
parents:
13326
diff
changeset
|
1641 (while (and (not mode) alist) |
1bd9f5d576ce
(set-auto-mode): If mode cmds move point, obey them.
Richard M. Stallman <rms@gnu.org>
parents:
13326
diff
changeset
|
1642 (if (string-match (car (car alist)) name) |
1bd9f5d576ce
(set-auto-mode): If mode cmds move point, obey them.
Richard M. Stallman <rms@gnu.org>
parents:
13326
diff
changeset
|
1643 (if (and (consp (cdr (car alist))) |
1bd9f5d576ce
(set-auto-mode): If mode cmds move point, obey them.
Richard M. Stallman <rms@gnu.org>
parents:
13326
diff
changeset
|
1644 (nth 2 (car alist))) |
32138 | 1645 (setq mode (car (cdr (car alist))) |
1646 name (substring name 0 (match-beginning 0)) | |
1647 keep-going t) | |
13496
1bd9f5d576ce
(set-auto-mode): If mode cmds move point, obey them.
Richard M. Stallman <rms@gnu.org>
parents:
13326
diff
changeset
|
1648 (setq mode (cdr (car alist)) |
1bd9f5d576ce
(set-auto-mode): If mode cmds move point, obey them.
Richard M. Stallman <rms@gnu.org>
parents:
13326
diff
changeset
|
1649 keep-going nil))) |
1bd9f5d576ce
(set-auto-mode): If mode cmds move point, obey them.
Richard M. Stallman <rms@gnu.org>
parents:
13326
diff
changeset
|
1650 (setq alist (cdr alist)))) |
1bd9f5d576ce
(set-auto-mode): If mode cmds move point, obey them.
Richard M. Stallman <rms@gnu.org>
parents:
13326
diff
changeset
|
1651 (if mode |
21773
c718d675ee93
(set-auto-mode): When just-from-file-name is set, don't
Richard M. Stallman <rms@gnu.org>
parents:
21619
diff
changeset
|
1652 ;; When JUST-FROM-FILE-NAME is set, |
c718d675ee93
(set-auto-mode): When just-from-file-name is set, don't
Richard M. Stallman <rms@gnu.org>
parents:
21619
diff
changeset
|
1653 ;; we are working on behalf of set-visited-file-name. |
c718d675ee93
(set-auto-mode): When just-from-file-name is set, don't
Richard M. Stallman <rms@gnu.org>
parents:
21619
diff
changeset
|
1654 ;; In that case, if the major mode specified is the |
c718d675ee93
(set-auto-mode): When just-from-file-name is set, don't
Richard M. Stallman <rms@gnu.org>
parents:
21619
diff
changeset
|
1655 ;; same one we already have, don't actually reset it. |
c718d675ee93
(set-auto-mode): When just-from-file-name is set, don't
Richard M. Stallman <rms@gnu.org>
parents:
21619
diff
changeset
|
1656 ;; We don't want to lose minor modes such as Font Lock. |
c718d675ee93
(set-auto-mode): When just-from-file-name is set, don't
Richard M. Stallman <rms@gnu.org>
parents:
21619
diff
changeset
|
1657 (unless (and just-from-file-name (eq mode major-mode)) |
c718d675ee93
(set-auto-mode): When just-from-file-name is set, don't
Richard M. Stallman <rms@gnu.org>
parents:
21619
diff
changeset
|
1658 (funcall mode)) |
13496
1bd9f5d576ce
(set-auto-mode): If mode cmds move point, obey them.
Richard M. Stallman <rms@gnu.org>
parents:
13326
diff
changeset
|
1659 ;; If we can't deduce a mode from the file name, |
1bd9f5d576ce
(set-auto-mode): If mode cmds move point, obey them.
Richard M. Stallman <rms@gnu.org>
parents:
13326
diff
changeset
|
1660 ;; look for an interpreter specified in the first line. |
13737
3902b2781a8f
(set-auto-mode): Recognize `#!/bin/env INTERPRETER' hack.
Karl Heuer <kwzh@gnu.org>
parents:
13693
diff
changeset
|
1661 ;; As a special case, allow for things like "#!/bin/env perl", |
3902b2781a8f
(set-auto-mode): Recognize `#!/bin/env INTERPRETER' hack.
Karl Heuer <kwzh@gnu.org>
parents:
13693
diff
changeset
|
1662 ;; which finds the interpreter anywhere in $PATH. |
13496
1bd9f5d576ce
(set-auto-mode): If mode cmds move point, obey them.
Richard M. Stallman <rms@gnu.org>
parents:
13326
diff
changeset
|
1663 (let ((interpreter |
1bd9f5d576ce
(set-auto-mode): If mode cmds move point, obey them.
Richard M. Stallman <rms@gnu.org>
parents:
13326
diff
changeset
|
1664 (save-excursion |
1bd9f5d576ce
(set-auto-mode): If mode cmds move point, obey them.
Richard M. Stallman <rms@gnu.org>
parents:
13326
diff
changeset
|
1665 (goto-char (point-min)) |
32138 | 1666 (if (looking-at auto-mode-interpreter-regexp) |
1667 (match-string 2) | |
13496
1bd9f5d576ce
(set-auto-mode): If mode cmds move point, obey them.
Richard M. Stallman <rms@gnu.org>
parents:
13326
diff
changeset
|
1668 ""))) |
1bd9f5d576ce
(set-auto-mode): If mode cmds move point, obey them.
Richard M. Stallman <rms@gnu.org>
parents:
13326
diff
changeset
|
1669 elt) |
1bd9f5d576ce
(set-auto-mode): If mode cmds move point, obey them.
Richard M. Stallman <rms@gnu.org>
parents:
13326
diff
changeset
|
1670 ;; Map interpreter name to a mode. |
1bd9f5d576ce
(set-auto-mode): If mode cmds move point, obey them.
Richard M. Stallman <rms@gnu.org>
parents:
13326
diff
changeset
|
1671 (setq elt (assoc (file-name-nondirectory interpreter) |
1bd9f5d576ce
(set-auto-mode): If mode cmds move point, obey them.
Richard M. Stallman <rms@gnu.org>
parents:
13326
diff
changeset
|
1672 interpreter-mode-alist)) |
17660
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1673 (unless just-from-file-name |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1674 (if elt |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1675 (funcall (cdr elt)))))))))))) |
337 | 1676 |
1395
f6f838c4a26e
(buffer-file-number): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1371
diff
changeset
|
1677 (defun hack-local-variables-prop-line () |
32138 | 1678 "Set local variables specified in the -*- line. |
1679 Ignore any specification for `mode:' and `coding:'; | |
1680 `set-auto-mode' should already have handled `mode:', | |
1681 `set-auto-coding' should already have handled `coding:'." | |
1395
f6f838c4a26e
(buffer-file-number): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1371
diff
changeset
|
1682 (save-excursion |
f6f838c4a26e
(buffer-file-number): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1371
diff
changeset
|
1683 (goto-char (point-min)) |
6575
9aba6be8e460
(hack-local-variables-prop-line): Search two lines if "#!".
Karl Heuer <kwzh@gnu.org>
parents:
6574
diff
changeset
|
1684 (let ((result nil) |
23657
7f5af9d1766d
(hack-local-variables): Test local-enable-local-variables.
Karl Heuer <kwzh@gnu.org>
parents:
23606
diff
changeset
|
1685 (end (save-excursion (end-of-line (and (looking-at "^#!") 2)) (point))) |
7f5af9d1766d
(hack-local-variables): Test local-enable-local-variables.
Karl Heuer <kwzh@gnu.org>
parents:
23606
diff
changeset
|
1686 (enable-local-variables |
7f5af9d1766d
(hack-local-variables): Test local-enable-local-variables.
Karl Heuer <kwzh@gnu.org>
parents:
23606
diff
changeset
|
1687 (and local-enable-local-variables enable-local-variables))) |
1395
f6f838c4a26e
(buffer-file-number): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1371
diff
changeset
|
1688 ;; Parse the -*- line into the `result' alist. |
f6f838c4a26e
(buffer-file-number): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1371
diff
changeset
|
1689 (cond ((not (search-forward "-*-" end t)) |
f6f838c4a26e
(buffer-file-number): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1371
diff
changeset
|
1690 ;; doesn't have one. |
f6f838c4a26e
(buffer-file-number): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1371
diff
changeset
|
1691 nil) |
f6f838c4a26e
(buffer-file-number): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1371
diff
changeset
|
1692 ((looking-at "[ \t]*\\([^ \t\n\r:;]+\\)\\([ \t]*-\\*-\\)") |
6575
9aba6be8e460
(hack-local-variables-prop-line): Search two lines if "#!".
Karl Heuer <kwzh@gnu.org>
parents:
6574
diff
changeset
|
1693 ;; Simple form: "-*- MODENAME -*-". Already handled. |
9aba6be8e460
(hack-local-variables-prop-line): Search two lines if "#!".
Karl Heuer <kwzh@gnu.org>
parents:
6574
diff
changeset
|
1694 nil) |
1395
f6f838c4a26e
(buffer-file-number): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1371
diff
changeset
|
1695 (t |
f6f838c4a26e
(buffer-file-number): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1371
diff
changeset
|
1696 ;; Hairy form: '-*-' [ <variable> ':' <value> ';' ]* '-*-' |
f6f838c4a26e
(buffer-file-number): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1371
diff
changeset
|
1697 ;; (last ";" is optional). |
f6f838c4a26e
(buffer-file-number): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1371
diff
changeset
|
1698 (save-excursion |
f6f838c4a26e
(buffer-file-number): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1371
diff
changeset
|
1699 (if (search-forward "-*-" end t) |
f6f838c4a26e
(buffer-file-number): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1371
diff
changeset
|
1700 (setq end (- (point) 3)) |
f6f838c4a26e
(buffer-file-number): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1371
diff
changeset
|
1701 (error "-*- not terminated before end of line"))) |
f6f838c4a26e
(buffer-file-number): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1371
diff
changeset
|
1702 (while (< (point) end) |
f6f838c4a26e
(buffer-file-number): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1371
diff
changeset
|
1703 (or (looking-at "[ \t]*\\([^ \t\n:]+\\)[ \t]*:[ \t]*") |
32138 | 1704 (error "Malformed -*- line")) |
1395
f6f838c4a26e
(buffer-file-number): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1371
diff
changeset
|
1705 (goto-char (match-end 0)) |
12068
5d44c48f3b7b
(hack-local-variables-prop-line): Don't downcase var name.
Karl Heuer <kwzh@gnu.org>
parents:
12050
diff
changeset
|
1706 ;; There used to be a downcase here, |
5d44c48f3b7b
(hack-local-variables-prop-line): Don't downcase var name.
Karl Heuer <kwzh@gnu.org>
parents:
12050
diff
changeset
|
1707 ;; but the manual didn't say so, |
5d44c48f3b7b
(hack-local-variables-prop-line): Don't downcase var name.
Karl Heuer <kwzh@gnu.org>
parents:
12050
diff
changeset
|
1708 ;; and people want to set var names that aren't all lc. |
5d44c48f3b7b
(hack-local-variables-prop-line): Don't downcase var name.
Karl Heuer <kwzh@gnu.org>
parents:
12050
diff
changeset
|
1709 (let ((key (intern (buffer-substring |
5d44c48f3b7b
(hack-local-variables-prop-line): Don't downcase var name.
Karl Heuer <kwzh@gnu.org>
parents:
12050
diff
changeset
|
1710 (match-beginning 1) |
5d44c48f3b7b
(hack-local-variables-prop-line): Don't downcase var name.
Karl Heuer <kwzh@gnu.org>
parents:
12050
diff
changeset
|
1711 (match-end 1)))) |
1395
f6f838c4a26e
(buffer-file-number): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1371
diff
changeset
|
1712 (val (save-restriction |
f6f838c4a26e
(buffer-file-number): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1371
diff
changeset
|
1713 (narrow-to-region (point) end) |
f6f838c4a26e
(buffer-file-number): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1371
diff
changeset
|
1714 (read (current-buffer))))) |
16440
e735290b9ebb
(hack-local-variables-prop-line):
Richard M. Stallman <rms@gnu.org>
parents:
16414
diff
changeset
|
1715 ;; It is traditional to ignore |
e735290b9ebb
(hack-local-variables-prop-line):
Richard M. Stallman <rms@gnu.org>
parents:
16414
diff
changeset
|
1716 ;; case when checking for `mode' in set-auto-mode, |
e735290b9ebb
(hack-local-variables-prop-line):
Richard M. Stallman <rms@gnu.org>
parents:
16414
diff
changeset
|
1717 ;; so we must do that here as well. |
e735290b9ebb
(hack-local-variables-prop-line):
Richard M. Stallman <rms@gnu.org>
parents:
16414
diff
changeset
|
1718 ;; That is inconsistent, but we're stuck with it. |
19645
df1911293a5e
(hack-local-variables-prop-line): Ignore coding: tag.
Kenichi Handa <handa@m17n.org>
parents:
19575
diff
changeset
|
1719 ;; The same can be said for `coding' in set-auto-coding. |
16440
e735290b9ebb
(hack-local-variables-prop-line):
Richard M. Stallman <rms@gnu.org>
parents:
16414
diff
changeset
|
1720 (or (equal (downcase (symbol-name key)) "mode") |
19645
df1911293a5e
(hack-local-variables-prop-line): Ignore coding: tag.
Kenichi Handa <handa@m17n.org>
parents:
19575
diff
changeset
|
1721 (equal (downcase (symbol-name key)) "coding") |
6575
9aba6be8e460
(hack-local-variables-prop-line): Search two lines if "#!".
Karl Heuer <kwzh@gnu.org>
parents:
6574
diff
changeset
|
1722 (setq result (cons (cons key val) result))) |
1395
f6f838c4a26e
(buffer-file-number): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1371
diff
changeset
|
1723 (skip-chars-forward " \t;"))) |
f6f838c4a26e
(buffer-file-number): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1371
diff
changeset
|
1724 (setq result (nreverse result)))) |
13832
44e936e550ae
(save-some-buffers): Don't give message if we queried.
Roland McGrath <roland@gnu.org>
parents:
13823
diff
changeset
|
1725 |
1395
f6f838c4a26e
(buffer-file-number): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1371
diff
changeset
|
1726 (if (and result |
f6f838c4a26e
(buffer-file-number): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1371
diff
changeset
|
1727 (or (eq enable-local-variables t) |
f6f838c4a26e
(buffer-file-number): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1371
diff
changeset
|
1728 (and enable-local-variables |
f6f838c4a26e
(buffer-file-number): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1371
diff
changeset
|
1729 (save-window-excursion |
5292
4b1f2e4dcf34
(hack-local-variables-prop-line): If we can't switch-to-buffer
Richard M. Stallman <rms@gnu.org>
parents:
4965
diff
changeset
|
1730 (condition-case nil |
4b1f2e4dcf34
(hack-local-variables-prop-line): If we can't switch-to-buffer
Richard M. Stallman <rms@gnu.org>
parents:
4965
diff
changeset
|
1731 (switch-to-buffer (current-buffer)) |
4b1f2e4dcf34
(hack-local-variables-prop-line): If we can't switch-to-buffer
Richard M. Stallman <rms@gnu.org>
parents:
4965
diff
changeset
|
1732 (error |
4b1f2e4dcf34
(hack-local-variables-prop-line): If we can't switch-to-buffer
Richard M. Stallman <rms@gnu.org>
parents:
4965
diff
changeset
|
1733 ;; If we fail to switch in the selected window, |
4b1f2e4dcf34
(hack-local-variables-prop-line): If we can't switch-to-buffer
Richard M. Stallman <rms@gnu.org>
parents:
4965
diff
changeset
|
1734 ;; it is probably a minibuffer. |
4b1f2e4dcf34
(hack-local-variables-prop-line): If we can't switch-to-buffer
Richard M. Stallman <rms@gnu.org>
parents:
4965
diff
changeset
|
1735 ;; So try another window. |
4b1f2e4dcf34
(hack-local-variables-prop-line): If we can't switch-to-buffer
Richard M. Stallman <rms@gnu.org>
parents:
4965
diff
changeset
|
1736 (condition-case nil |
4b1f2e4dcf34
(hack-local-variables-prop-line): If we can't switch-to-buffer
Richard M. Stallman <rms@gnu.org>
parents:
4965
diff
changeset
|
1737 (switch-to-buffer-other-window (current-buffer)) |
4b1f2e4dcf34
(hack-local-variables-prop-line): If we can't switch-to-buffer
Richard M. Stallman <rms@gnu.org>
parents:
4965
diff
changeset
|
1738 (error |
4b1f2e4dcf34
(hack-local-variables-prop-line): If we can't switch-to-buffer
Richard M. Stallman <rms@gnu.org>
parents:
4965
diff
changeset
|
1739 (switch-to-buffer-other-frame (current-buffer)))))) |
1395
f6f838c4a26e
(buffer-file-number): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1371
diff
changeset
|
1740 (y-or-n-p (format "Set local variables as specified in -*- line of %s? " |
f6f838c4a26e
(buffer-file-number): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1371
diff
changeset
|
1741 (file-name-nondirectory buffer-file-name))))))) |
15365
104a97493dcc
(hack-local-variables-prop-line): Bind enable-local-eval.
Richard M. Stallman <rms@gnu.org>
parents:
15329
diff
changeset
|
1742 (let ((enable-local-eval enable-local-eval)) |
104a97493dcc
(hack-local-variables-prop-line): Bind enable-local-eval.
Richard M. Stallman <rms@gnu.org>
parents:
15329
diff
changeset
|
1743 (while result |
104a97493dcc
(hack-local-variables-prop-line): Bind enable-local-eval.
Richard M. Stallman <rms@gnu.org>
parents:
15329
diff
changeset
|
1744 (hack-one-local-variable (car (car result)) (cdr (car result))) |
104a97493dcc
(hack-local-variables-prop-line): Bind enable-local-eval.
Richard M. Stallman <rms@gnu.org>
parents:
15329
diff
changeset
|
1745 (setq result (cdr result)))))))) |
1395
f6f838c4a26e
(buffer-file-number): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1371
diff
changeset
|
1746 |
10169
04425b872c5b
(hack-local-variables): Run hack-local-variables-hook.
Richard M. Stallman <rms@gnu.org>
parents:
10149
diff
changeset
|
1747 (defvar hack-local-variables-hook nil |
04425b872c5b
(hack-local-variables): Run hack-local-variables-hook.
Richard M. Stallman <rms@gnu.org>
parents:
10149
diff
changeset
|
1748 "Normal hook run after processing a file's local variables specs. |
04425b872c5b
(hack-local-variables): Run hack-local-variables-hook.
Richard M. Stallman <rms@gnu.org>
parents:
10149
diff
changeset
|
1749 Major modes can use this to examine user-specified local variables |
04425b872c5b
(hack-local-variables): Run hack-local-variables-hook.
Richard M. Stallman <rms@gnu.org>
parents:
10149
diff
changeset
|
1750 in order to initialize other data structure based on them.") |
04425b872c5b
(hack-local-variables): Run hack-local-variables-hook.
Richard M. Stallman <rms@gnu.org>
parents:
10149
diff
changeset
|
1751 |
17660
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1752 (defun hack-local-variables (&optional mode-only) |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1753 "Parse and put into effect this buffer's local variables spec. |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1754 If MODE-ONLY is non-nil, all we do is check whether the major mode |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1755 is specified, returning t if it is specified." |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1756 (unless mode-only |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1757 (hack-local-variables-prop-line)) |
337 | 1758 ;; Look for "Local variables:" line in last page. |
23657
7f5af9d1766d
(hack-local-variables): Test local-enable-local-variables.
Karl Heuer <kwzh@gnu.org>
parents:
23606
diff
changeset
|
1759 (let (mode-specified |
7f5af9d1766d
(hack-local-variables): Test local-enable-local-variables.
Karl Heuer <kwzh@gnu.org>
parents:
23606
diff
changeset
|
1760 (enable-local-variables |
7f5af9d1766d
(hack-local-variables): Test local-enable-local-variables.
Karl Heuer <kwzh@gnu.org>
parents:
23606
diff
changeset
|
1761 (and local-enable-local-variables enable-local-variables))) |
17660
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1762 (save-excursion |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1763 (goto-char (point-max)) |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1764 (search-backward "\n\^L" (max (- (point-max) 3000) (point-min)) 'move) |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1765 (if (let ((case-fold-search t)) |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1766 (and (search-forward "Local Variables:" nil t) |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1767 (or (eq enable-local-variables t) |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1768 mode-only |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1769 (and enable-local-variables |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1770 (save-window-excursion |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1771 (switch-to-buffer (current-buffer)) |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1772 (save-excursion |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1773 (beginning-of-line) |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1774 (set-window-start (selected-window) (point))) |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1775 (y-or-n-p (format "Set local variables as specified at end of %s? " |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1776 (if buffer-file-name |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1777 (file-name-nondirectory |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1778 buffer-file-name) |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1779 (concat "buffer " |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1780 (buffer-name)))))))))) |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1781 (let ((continue t) |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1782 prefix prefixlen suffix beg |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1783 mode-specified |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1784 (enable-local-eval enable-local-eval)) |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1785 ;; The prefix is what comes before "local variables:" in its line. |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1786 ;; The suffix is what comes after "local variables:" in its line. |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1787 (skip-chars-forward " \t") |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1788 (or (eolp) |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1789 (setq suffix (buffer-substring (point) |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1790 (progn (end-of-line) (point))))) |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1791 (goto-char (match-beginning 0)) |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1792 (or (bolp) |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1793 (setq prefix |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1794 (buffer-substring (point) |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1795 (progn (beginning-of-line) (point))))) |
566 | 1796 |
17660
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1797 (if prefix (setq prefixlen (length prefix) |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1798 prefix (regexp-quote prefix))) |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1799 (if suffix (setq suffix (concat (regexp-quote suffix) "$"))) |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1800 (while continue |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1801 ;; Look at next local variable spec. |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1802 (if selective-display (re-search-forward "[\n\C-m]") |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1803 (forward-line 1)) |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1804 ;; Skip the prefix, if any. |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1805 (if prefix |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1806 (if (looking-at prefix) |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1807 (forward-char prefixlen) |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1808 (error "Local variables entry is missing the prefix"))) |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1809 ;; Find the variable name; strip whitespace. |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1810 (skip-chars-forward " \t") |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1811 (setq beg (point)) |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1812 (skip-chars-forward "^:\n") |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1813 (if (eolp) (error "Missing colon in local variables entry")) |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1814 (skip-chars-backward " \t") |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1815 (let* ((str (buffer-substring beg (point))) |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1816 (var (read str)) |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1817 val) |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1818 ;; Setting variable named "end" means end of list. |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1819 (if (string-equal (downcase str) "end") |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1820 (setq continue nil) |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1821 ;; Otherwise read the variable value. |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1822 (skip-chars-forward "^:") |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1823 (forward-char 1) |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1824 (setq val (read (current-buffer))) |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1825 (skip-chars-backward "\n") |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1826 (skip-chars-forward " \t") |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1827 (or (if suffix (looking-at suffix) (eolp)) |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1828 (error "Local variables entry is terminated incorrectly")) |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1829 (if mode-only |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1830 (if (eq var 'mode) |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1831 (setq mode-specified t)) |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1832 ;; Set the variable. "Variables" mode and eval are funny. |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1833 (hack-one-local-variable var val)))))))) |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1834 (unless mode-only |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1835 (run-hooks 'hack-local-variables-hook)) |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1836 mode-specified)) |
1395
f6f838c4a26e
(buffer-file-number): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1371
diff
changeset
|
1837 |
16687
049c87a96dca
Change defconsts to defvars.
Richard M. Stallman <rms@gnu.org>
parents:
16684
diff
changeset
|
1838 (defvar ignored-local-variables |
1395
f6f838c4a26e
(buffer-file-number): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1371
diff
changeset
|
1839 '(enable-local-eval) |
f6f838c4a26e
(buffer-file-number): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1371
diff
changeset
|
1840 "Variables to be ignored in a file's local variable spec.") |
f6f838c4a26e
(buffer-file-number): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1371
diff
changeset
|
1841 |
6734
6e61dbbfce80
(hack-one-local-variable): Test for risky-local-variable property.
Richard M. Stallman <rms@gnu.org>
parents:
6733
diff
changeset
|
1842 ;; Get confirmation before setting these variables as locals in a file. |
8148
0035bfc4bc9d
(file-truename): Use iteration when possible.
Richard M. Stallman <rms@gnu.org>
parents:
8140
diff
changeset
|
1843 (put 'debugger 'risky-local-variable t) |
7682
ce09b4fd6cc8
Add more risky-local-variable properties.
Richard M. Stallman <rms@gnu.org>
parents:
7662
diff
changeset
|
1844 (put 'enable-local-eval 'risky-local-variable t) |
10149
c1704135914f
(ignored-local-variables): Mark it risky.
Richard M. Stallman <rms@gnu.org>
parents:
10132
diff
changeset
|
1845 (put 'ignored-local-variables 'risky-local-variable t) |
6734
6e61dbbfce80
(hack-one-local-variable): Test for risky-local-variable property.
Richard M. Stallman <rms@gnu.org>
parents:
6733
diff
changeset
|
1846 (put 'eval 'risky-local-variable t) |
6e61dbbfce80
(hack-one-local-variable): Test for risky-local-variable property.
Richard M. Stallman <rms@gnu.org>
parents:
6733
diff
changeset
|
1847 (put 'file-name-handler-alist 'risky-local-variable t) |
6e61dbbfce80
(hack-one-local-variable): Test for risky-local-variable property.
Richard M. Stallman <rms@gnu.org>
parents:
6733
diff
changeset
|
1848 (put 'minor-mode-map-alist 'risky-local-variable t) |
6e61dbbfce80
(hack-one-local-variable): Test for risky-local-variable property.
Richard M. Stallman <rms@gnu.org>
parents:
6733
diff
changeset
|
1849 (put 'after-load-alist 'risky-local-variable t) |
7682
ce09b4fd6cc8
Add more risky-local-variable properties.
Richard M. Stallman <rms@gnu.org>
parents:
7662
diff
changeset
|
1850 (put 'buffer-file-name 'risky-local-variable t) |
ce09b4fd6cc8
Add more risky-local-variable properties.
Richard M. Stallman <rms@gnu.org>
parents:
7662
diff
changeset
|
1851 (put 'buffer-auto-save-file-name 'risky-local-variable t) |
ce09b4fd6cc8
Add more risky-local-variable properties.
Richard M. Stallman <rms@gnu.org>
parents:
7662
diff
changeset
|
1852 (put 'buffer-file-truename 'risky-local-variable t) |
8171
750282040c17
(process-environment, exec-path, load-path,exec-directory):
Richard M. Stallman <rms@gnu.org>
parents:
8165
diff
changeset
|
1853 (put 'exec-path 'risky-local-variable t) |
750282040c17
(process-environment, exec-path, load-path,exec-directory):
Richard M. Stallman <rms@gnu.org>
parents:
8165
diff
changeset
|
1854 (put 'load-path 'risky-local-variable t) |
750282040c17
(process-environment, exec-path, load-path,exec-directory):
Richard M. Stallman <rms@gnu.org>
parents:
8165
diff
changeset
|
1855 (put 'exec-directory 'risky-local-variable t) |
750282040c17
(process-environment, exec-path, load-path,exec-directory):
Richard M. Stallman <rms@gnu.org>
parents:
8165
diff
changeset
|
1856 (put 'process-environment 'risky-local-variable t) |
15753
4d76ffbc2be1
(dabbrev-case-fold-search, dabbrev-case-replace): Set
Richard M. Stallman <rms@gnu.org>
parents:
15611
diff
changeset
|
1857 (put 'dabbrev-case-fold-search 'risky-local-variable t) |
4d76ffbc2be1
(dabbrev-case-fold-search, dabbrev-case-replace): Set
Richard M. Stallman <rms@gnu.org>
parents:
15611
diff
changeset
|
1858 (put 'dabbrev-case-replace 'risky-local-variable t) |
8177
defefddf88db
(outline-level): Mark it risky.
Richard M. Stallman <rms@gnu.org>
parents:
8171
diff
changeset
|
1859 ;; Don't wait for outline.el to be loaded, for the sake of outline-minor-mode. |
defefddf88db
(outline-level): Mark it risky.
Richard M. Stallman <rms@gnu.org>
parents:
8171
diff
changeset
|
1860 (put 'outline-level 'risky-local-variable t) |
8251
6f692cc01d52
(rmail-output-file-alist): Mark it risky.
Richard M. Stallman <rms@gnu.org>
parents:
8232
diff
changeset
|
1861 (put 'rmail-output-file-alist 'risky-local-variable t) |
7682
ce09b4fd6cc8
Add more risky-local-variable properties.
Richard M. Stallman <rms@gnu.org>
parents:
7662
diff
changeset
|
1862 |
9162
53d02761f5b7
(hack-one-local-variable): Support safe-local-variable property.
Richard M. Stallman <rms@gnu.org>
parents:
9068
diff
changeset
|
1863 ;; This one is safe because the user gets to check it before it is used. |
53d02761f5b7
(hack-one-local-variable): Support safe-local-variable property.
Richard M. Stallman <rms@gnu.org>
parents:
9068
diff
changeset
|
1864 (put 'compile-command 'safe-local-variable t) |
53d02761f5b7
(hack-one-local-variable): Support safe-local-variable property.
Richard M. Stallman <rms@gnu.org>
parents:
9068
diff
changeset
|
1865 |
7217
c35a4919c161
(hack-one-local-variable): Silently execute eval
Richard M. Stallman <rms@gnu.org>
parents:
7215
diff
changeset
|
1866 (defun hack-one-local-variable-quotep (exp) |
c35a4919c161
(hack-one-local-variable): Silently execute eval
Richard M. Stallman <rms@gnu.org>
parents:
7215
diff
changeset
|
1867 (and (consp exp) (eq (car exp) 'quote) (consp (cdr exp)))) |
c35a4919c161
(hack-one-local-variable): Silently execute eval
Richard M. Stallman <rms@gnu.org>
parents:
7215
diff
changeset
|
1868 |
1395
f6f838c4a26e
(buffer-file-number): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1371
diff
changeset
|
1869 (defun hack-one-local-variable (var val) |
32138 | 1870 "\"Set\" one variable in a local variables spec. |
1871 A few variable names are treated specially." | |
1395
f6f838c4a26e
(buffer-file-number): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1371
diff
changeset
|
1872 (cond ((eq var 'mode) |
f6f838c4a26e
(buffer-file-number): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1371
diff
changeset
|
1873 (funcall (intern (concat (downcase (symbol-name val)) |
f6f838c4a26e
(buffer-file-number): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1371
diff
changeset
|
1874 "-mode")))) |
19645
df1911293a5e
(hack-local-variables-prop-line): Ignore coding: tag.
Kenichi Handa <handa@m17n.org>
parents:
19575
diff
changeset
|
1875 ((eq var 'coding) |
df1911293a5e
(hack-local-variables-prop-line): Ignore coding: tag.
Kenichi Handa <handa@m17n.org>
parents:
19575
diff
changeset
|
1876 ;; We have already handled coding: tag in set-auto-coding. |
df1911293a5e
(hack-local-variables-prop-line): Ignore coding: tag.
Kenichi Handa <handa@m17n.org>
parents:
19575
diff
changeset
|
1877 nil) |
1395
f6f838c4a26e
(buffer-file-number): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1371
diff
changeset
|
1878 ((memq var ignored-local-variables) |
f6f838c4a26e
(buffer-file-number): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1371
diff
changeset
|
1879 nil) |
f6f838c4a26e
(buffer-file-number): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1371
diff
changeset
|
1880 ;; "Setting" eval means either eval it or do nothing. |
3626
ae0389767674
(hack-one-local-variable): Treat ...-hook(s) and ..-function(s)
Richard M. Stallman <rms@gnu.org>
parents:
3624
diff
changeset
|
1881 ;; Likewise for setting hook variables. |
6734
6e61dbbfce80
(hack-one-local-variable): Test for risky-local-variable property.
Richard M. Stallman <rms@gnu.org>
parents:
6733
diff
changeset
|
1882 ((or (get var 'risky-local-variable) |
9162
53d02761f5b7
(hack-one-local-variable): Support safe-local-variable property.
Richard M. Stallman <rms@gnu.org>
parents:
9068
diff
changeset
|
1883 (and |
21327
01870b9b4f2a
(hack-one-local-variable): Variables named ...-predicate are treated as risky.
Richard M. Stallman <rms@gnu.org>
parents:
21263
diff
changeset
|
1884 (string-match "-hooks?$\\|-functions?$\\|-forms?$\\|-program$\\|-command$\\|-predicate$" |
9162
53d02761f5b7
(hack-one-local-variable): Support safe-local-variable property.
Richard M. Stallman <rms@gnu.org>
parents:
9068
diff
changeset
|
1885 (symbol-name var)) |
53d02761f5b7
(hack-one-local-variable): Support safe-local-variable property.
Richard M. Stallman <rms@gnu.org>
parents:
9068
diff
changeset
|
1886 (not (get var 'safe-local-variable)))) |
13980 | 1887 ;; Permit evalling a put of a harmless property. |
7217
c35a4919c161
(hack-one-local-variable): Silently execute eval
Richard M. Stallman <rms@gnu.org>
parents:
7215
diff
changeset
|
1888 ;; if the args do nothing tricky. |
c35a4919c161
(hack-one-local-variable): Silently execute eval
Richard M. Stallman <rms@gnu.org>
parents:
7215
diff
changeset
|
1889 (if (or (and (eq var 'eval) |
c35a4919c161
(hack-one-local-variable): Silently execute eval
Richard M. Stallman <rms@gnu.org>
parents:
7215
diff
changeset
|
1890 (consp val) |
c35a4919c161
(hack-one-local-variable): Silently execute eval
Richard M. Stallman <rms@gnu.org>
parents:
7215
diff
changeset
|
1891 (eq (car val) 'put) |
c35a4919c161
(hack-one-local-variable): Silently execute eval
Richard M. Stallman <rms@gnu.org>
parents:
7215
diff
changeset
|
1892 (hack-one-local-variable-quotep (nth 1 val)) |
c35a4919c161
(hack-one-local-variable): Silently execute eval
Richard M. Stallman <rms@gnu.org>
parents:
7215
diff
changeset
|
1893 (hack-one-local-variable-quotep (nth 2 val)) |
c35a4919c161
(hack-one-local-variable): Silently execute eval
Richard M. Stallman <rms@gnu.org>
parents:
7215
diff
changeset
|
1894 ;; Only allow safe values of lisp-indent-hook; |
c35a4919c161
(hack-one-local-variable): Silently execute eval
Richard M. Stallman <rms@gnu.org>
parents:
7215
diff
changeset
|
1895 ;; not functions. |
c35a4919c161
(hack-one-local-variable): Silently execute eval
Richard M. Stallman <rms@gnu.org>
parents:
7215
diff
changeset
|
1896 (or (numberp (nth 3 val)) |
7643
86001e904ef3
(hack-one-local-variable): Check properly for `defun.
Richard M. Stallman <rms@gnu.org>
parents:
7440
diff
changeset
|
1897 (equal (nth 3 val) ''defun)) |
7217
c35a4919c161
(hack-one-local-variable): Silently execute eval
Richard M. Stallman <rms@gnu.org>
parents:
7215
diff
changeset
|
1898 (memq (nth 1 (nth 2 val)) |
c35a4919c161
(hack-one-local-variable): Silently execute eval
Richard M. Stallman <rms@gnu.org>
parents:
7215
diff
changeset
|
1899 '(lisp-indent-hook))) |
c35a4919c161
(hack-one-local-variable): Silently execute eval
Richard M. Stallman <rms@gnu.org>
parents:
7215
diff
changeset
|
1900 ;; Permit eval if not root and user says ok. |
8181
a5c67d37141b
(hack-one-local-variable): Check for root using user-uid.
Richard M. Stallman <rms@gnu.org>
parents:
8177
diff
changeset
|
1901 (and (not (zerop (user-uid))) |
7217
c35a4919c161
(hack-one-local-variable): Silently execute eval
Richard M. Stallman <rms@gnu.org>
parents:
7215
diff
changeset
|
1902 (or (eq enable-local-eval t) |
c35a4919c161
(hack-one-local-variable): Silently execute eval
Richard M. Stallman <rms@gnu.org>
parents:
7215
diff
changeset
|
1903 (and enable-local-eval |
c35a4919c161
(hack-one-local-variable): Silently execute eval
Richard M. Stallman <rms@gnu.org>
parents:
7215
diff
changeset
|
1904 (save-window-excursion |
c35a4919c161
(hack-one-local-variable): Silently execute eval
Richard M. Stallman <rms@gnu.org>
parents:
7215
diff
changeset
|
1905 (switch-to-buffer (current-buffer)) |
c35a4919c161
(hack-one-local-variable): Silently execute eval
Richard M. Stallman <rms@gnu.org>
parents:
7215
diff
changeset
|
1906 (save-excursion |
c35a4919c161
(hack-one-local-variable): Silently execute eval
Richard M. Stallman <rms@gnu.org>
parents:
7215
diff
changeset
|
1907 (beginning-of-line) |
c35a4919c161
(hack-one-local-variable): Silently execute eval
Richard M. Stallman <rms@gnu.org>
parents:
7215
diff
changeset
|
1908 (set-window-start (selected-window) (point))) |
c35a4919c161
(hack-one-local-variable): Silently execute eval
Richard M. Stallman <rms@gnu.org>
parents:
7215
diff
changeset
|
1909 (setq enable-local-eval |
23779
68c3d9e82bb7
(hack-one-local-variable): Cope with non-file buffers.
Richard M. Stallman <rms@gnu.org>
parents:
23657
diff
changeset
|
1910 (y-or-n-p (format "Process `eval' or hook local variables in %s? " |
68c3d9e82bb7
(hack-one-local-variable): Cope with non-file buffers.
Richard M. Stallman <rms@gnu.org>
parents:
23657
diff
changeset
|
1911 (if buffer-file-name |
68c3d9e82bb7
(hack-one-local-variable): Cope with non-file buffers.
Richard M. Stallman <rms@gnu.org>
parents:
23657
diff
changeset
|
1912 (concat "file " (file-name-nondirectory buffer-file-name)) |
68c3d9e82bb7
(hack-one-local-variable): Cope with non-file buffers.
Richard M. Stallman <rms@gnu.org>
parents:
23657
diff
changeset
|
1913 (concat "buffer " (buffer-name))))))))))) |
3626
ae0389767674
(hack-one-local-variable): Treat ...-hook(s) and ..-function(s)
Richard M. Stallman <rms@gnu.org>
parents:
3624
diff
changeset
|
1914 (if (eq var 'eval) |
ae0389767674
(hack-one-local-variable): Treat ...-hook(s) and ..-function(s)
Richard M. Stallman <rms@gnu.org>
parents:
3624
diff
changeset
|
1915 (save-excursion (eval val)) |
ae0389767674
(hack-one-local-variable): Treat ...-hook(s) and ..-function(s)
Richard M. Stallman <rms@gnu.org>
parents:
3624
diff
changeset
|
1916 (make-local-variable var) |
ae0389767674
(hack-one-local-variable): Treat ...-hook(s) and ..-function(s)
Richard M. Stallman <rms@gnu.org>
parents:
3624
diff
changeset
|
1917 (set var val)) |
23779
68c3d9e82bb7
(hack-one-local-variable): Cope with non-file buffers.
Richard M. Stallman <rms@gnu.org>
parents:
23657
diff
changeset
|
1918 (message "Ignoring `eval:' in the local variables list"))) |
1395
f6f838c4a26e
(buffer-file-number): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1371
diff
changeset
|
1919 ;; Ordinary variable, really set it. |
f6f838c4a26e
(buffer-file-number): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1371
diff
changeset
|
1920 (t (make-local-variable var) |
f6f838c4a26e
(buffer-file-number): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1371
diff
changeset
|
1921 (set var val)))) |
f6f838c4a26e
(buffer-file-number): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1371
diff
changeset
|
1922 |
337 | 1923 |
17673
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
1924 (defcustom change-major-mode-with-file-name t |
17660
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1925 "*Non-nil means \\[write-file] should set the major mode from the file name. |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1926 However, the mode will not be changed if |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1927 \(1) a local variables list or the `-*-' line specifies a major mode, or |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1928 \(2) the current major mode is a \"special\" mode, |
17666 | 1929 \ not suitable for ordinary files, or |
17673
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
1930 \(3) the new file name does not particularly specify any mode." |
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
1931 :type 'boolean |
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
1932 :group 'editing-basics) |
17660
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
1933 |
16971
c1b9bc4c525b
(set-visited-file-name): New arg ALONG-WITH-FILE.
Richard M. Stallman <rms@gnu.org>
parents:
16831
diff
changeset
|
1934 (defun set-visited-file-name (filename &optional no-query along-with-file) |
337 | 1935 "Change name of file visited in current buffer to FILENAME. |
1936 The next time the buffer is saved it will go in the newly specified file. | |
1937 nil or empty string as argument means make buffer not be visiting any file. | |
1938 Remember to delete the initial contents of the minibuffer | |
15570
6ec32e968edb
(set-visited-file-name): New optional arg NO-QUERY.
Richard M. Stallman <rms@gnu.org>
parents:
15548
diff
changeset
|
1939 if you wish to pass an empty string as the argument. |
6ec32e968edb
(set-visited-file-name): New optional arg NO-QUERY.
Richard M. Stallman <rms@gnu.org>
parents:
15548
diff
changeset
|
1940 |
6ec32e968edb
(set-visited-file-name): New optional arg NO-QUERY.
Richard M. Stallman <rms@gnu.org>
parents:
15548
diff
changeset
|
1941 The optional second argument NO-QUERY, if non-nil, inhibits asking for |
16971
c1b9bc4c525b
(set-visited-file-name): New arg ALONG-WITH-FILE.
Richard M. Stallman <rms@gnu.org>
parents:
16831
diff
changeset
|
1942 confirmation in the case where another buffer is already visiting FILENAME. |
c1b9bc4c525b
(set-visited-file-name): New arg ALONG-WITH-FILE.
Richard M. Stallman <rms@gnu.org>
parents:
16831
diff
changeset
|
1943 |
c1b9bc4c525b
(set-visited-file-name): New arg ALONG-WITH-FILE.
Richard M. Stallman <rms@gnu.org>
parents:
16831
diff
changeset
|
1944 The optional third argument ALONG-WITH-FILE, if non-nil, means that |
c1b9bc4c525b
(set-visited-file-name): New arg ALONG-WITH-FILE.
Richard M. Stallman <rms@gnu.org>
parents:
16831
diff
changeset
|
1945 the old visited file has been renamed to the new name FILENAME." |
337 | 1946 (interactive "FSet visited file name: ") |
10298
4b66ac3460df
(auto-mode-alist): Add entries for .cls files,
Richard M. Stallman <rms@gnu.org>
parents:
10236
diff
changeset
|
1947 (if (buffer-base-buffer) |
4b66ac3460df
(auto-mode-alist): Add entries for .cls files,
Richard M. Stallman <rms@gnu.org>
parents:
10236
diff
changeset
|
1948 (error "An indirect buffer cannot visit a file")) |
8140
ed2ac2e85eef
(set-visited-file-name): Handle find-file-visit-truename
Richard M. Stallman <rms@gnu.org>
parents:
7993
diff
changeset
|
1949 (let (truename) |
ed2ac2e85eef
(set-visited-file-name): Handle find-file-visit-truename
Richard M. Stallman <rms@gnu.org>
parents:
7993
diff
changeset
|
1950 (if filename |
ed2ac2e85eef
(set-visited-file-name): Handle find-file-visit-truename
Richard M. Stallman <rms@gnu.org>
parents:
7993
diff
changeset
|
1951 (setq filename |
ed2ac2e85eef
(set-visited-file-name): Handle find-file-visit-truename
Richard M. Stallman <rms@gnu.org>
parents:
7993
diff
changeset
|
1952 (if (string-equal filename "") |
ed2ac2e85eef
(set-visited-file-name): Handle find-file-visit-truename
Richard M. Stallman <rms@gnu.org>
parents:
7993
diff
changeset
|
1953 nil |
ed2ac2e85eef
(set-visited-file-name): Handle find-file-visit-truename
Richard M. Stallman <rms@gnu.org>
parents:
7993
diff
changeset
|
1954 (expand-file-name filename)))) |
ed2ac2e85eef
(set-visited-file-name): Handle find-file-visit-truename
Richard M. Stallman <rms@gnu.org>
parents:
7993
diff
changeset
|
1955 (if filename |
ed2ac2e85eef
(set-visited-file-name): Handle find-file-visit-truename
Richard M. Stallman <rms@gnu.org>
parents:
7993
diff
changeset
|
1956 (progn |
ed2ac2e85eef
(set-visited-file-name): Handle find-file-visit-truename
Richard M. Stallman <rms@gnu.org>
parents:
7993
diff
changeset
|
1957 (setq truename (file-truename filename)) |
ed2ac2e85eef
(set-visited-file-name): Handle find-file-visit-truename
Richard M. Stallman <rms@gnu.org>
parents:
7993
diff
changeset
|
1958 (if find-file-visit-truename |
ed2ac2e85eef
(set-visited-file-name): Handle find-file-visit-truename
Richard M. Stallman <rms@gnu.org>
parents:
7993
diff
changeset
|
1959 (setq filename truename)))) |
14883
f8a7a08fb9dd
(set-visited-file-name): Don't call find-buffer-visiting if filename is nil.
Richard M. Stallman <rms@gnu.org>
parents:
14734
diff
changeset
|
1960 (let ((buffer (and filename (find-buffer-visiting filename)))) |
14731
3682b5e64ce3
(set-visited-file-name): Query if there's already another
Richard M. Stallman <rms@gnu.org>
parents:
14636
diff
changeset
|
1961 (and buffer (not (eq buffer (current-buffer))) |
15570
6ec32e968edb
(set-visited-file-name): New optional arg NO-QUERY.
Richard M. Stallman <rms@gnu.org>
parents:
15548
diff
changeset
|
1962 (not no-query) |
14731
3682b5e64ce3
(set-visited-file-name): Query if there's already another
Richard M. Stallman <rms@gnu.org>
parents:
14636
diff
changeset
|
1963 (not (y-or-n-p (message "A buffer is visiting %s; proceed? " |
3682b5e64ce3
(set-visited-file-name): Query if there's already another
Richard M. Stallman <rms@gnu.org>
parents:
14636
diff
changeset
|
1964 filename))) |
3682b5e64ce3
(set-visited-file-name): Query if there's already another
Richard M. Stallman <rms@gnu.org>
parents:
14636
diff
changeset
|
1965 (error "Aborted"))) |
8140
ed2ac2e85eef
(set-visited-file-name): Handle find-file-visit-truename
Richard M. Stallman <rms@gnu.org>
parents:
7993
diff
changeset
|
1966 (or (equal filename buffer-file-name) |
ed2ac2e85eef
(set-visited-file-name): Handle find-file-visit-truename
Richard M. Stallman <rms@gnu.org>
parents:
7993
diff
changeset
|
1967 (progn |
ed2ac2e85eef
(set-visited-file-name): Handle find-file-visit-truename
Richard M. Stallman <rms@gnu.org>
parents:
7993
diff
changeset
|
1968 (and filename (lock-buffer filename)) |
ed2ac2e85eef
(set-visited-file-name): Handle find-file-visit-truename
Richard M. Stallman <rms@gnu.org>
parents:
7993
diff
changeset
|
1969 (unlock-buffer))) |
ed2ac2e85eef
(set-visited-file-name): Handle find-file-visit-truename
Richard M. Stallman <rms@gnu.org>
parents:
7993
diff
changeset
|
1970 (setq buffer-file-name filename) |
ed2ac2e85eef
(set-visited-file-name): Handle find-file-visit-truename
Richard M. Stallman <rms@gnu.org>
parents:
7993
diff
changeset
|
1971 (if filename ; make buffer name reflect filename. |
ed2ac2e85eef
(set-visited-file-name): Handle find-file-visit-truename
Richard M. Stallman <rms@gnu.org>
parents:
7993
diff
changeset
|
1972 (let ((new-name (file-name-nondirectory buffer-file-name))) |
ed2ac2e85eef
(set-visited-file-name): Handle find-file-visit-truename
Richard M. Stallman <rms@gnu.org>
parents:
7993
diff
changeset
|
1973 (if (string= new-name "") |
ed2ac2e85eef
(set-visited-file-name): Handle find-file-visit-truename
Richard M. Stallman <rms@gnu.org>
parents:
7993
diff
changeset
|
1974 (error "Empty file name")) |
ed2ac2e85eef
(set-visited-file-name): Handle find-file-visit-truename
Richard M. Stallman <rms@gnu.org>
parents:
7993
diff
changeset
|
1975 (if (eq system-type 'vax-vms) |
ed2ac2e85eef
(set-visited-file-name): Handle find-file-visit-truename
Richard M. Stallman <rms@gnu.org>
parents:
7993
diff
changeset
|
1976 (setq new-name (downcase new-name))) |
ed2ac2e85eef
(set-visited-file-name): Handle find-file-visit-truename
Richard M. Stallman <rms@gnu.org>
parents:
7993
diff
changeset
|
1977 (setq default-directory (file-name-directory buffer-file-name)) |
ed2ac2e85eef
(set-visited-file-name): Handle find-file-visit-truename
Richard M. Stallman <rms@gnu.org>
parents:
7993
diff
changeset
|
1978 (or (string= new-name (buffer-name)) |
ed2ac2e85eef
(set-visited-file-name): Handle find-file-visit-truename
Richard M. Stallman <rms@gnu.org>
parents:
7993
diff
changeset
|
1979 (rename-buffer new-name t)))) |
ed2ac2e85eef
(set-visited-file-name): Handle find-file-visit-truename
Richard M. Stallman <rms@gnu.org>
parents:
7993
diff
changeset
|
1980 (setq buffer-backed-up nil) |
16971
c1b9bc4c525b
(set-visited-file-name): New arg ALONG-WITH-FILE.
Richard M. Stallman <rms@gnu.org>
parents:
16831
diff
changeset
|
1981 (or along-with-file |
c1b9bc4c525b
(set-visited-file-name): New arg ALONG-WITH-FILE.
Richard M. Stallman <rms@gnu.org>
parents:
16831
diff
changeset
|
1982 (clear-visited-file-modtime)) |
13289
c4f93bb943b7
(set-visited-file-name): Abbreviate buffer-file-name.
Richard M. Stallman <rms@gnu.org>
parents:
13182
diff
changeset
|
1983 ;; Abbreviate the file names of the buffer. |
8151
2ac4479dd0ff
(set-visited-file-name): Avoid crash if TRUENAME is nil.
Richard M. Stallman <rms@gnu.org>
parents:
8148
diff
changeset
|
1984 (if truename |
13289
c4f93bb943b7
(set-visited-file-name): Abbreviate buffer-file-name.
Richard M. Stallman <rms@gnu.org>
parents:
13182
diff
changeset
|
1985 (progn |
c4f93bb943b7
(set-visited-file-name): Abbreviate buffer-file-name.
Richard M. Stallman <rms@gnu.org>
parents:
13182
diff
changeset
|
1986 (setq buffer-file-truename (abbreviate-file-name truename)) |
c4f93bb943b7
(set-visited-file-name): Abbreviate buffer-file-name.
Richard M. Stallman <rms@gnu.org>
parents:
13182
diff
changeset
|
1987 (if find-file-visit-truename |
c4f93bb943b7
(set-visited-file-name): Abbreviate buffer-file-name.
Richard M. Stallman <rms@gnu.org>
parents:
13182
diff
changeset
|
1988 (setq buffer-file-name buffer-file-truename)))) |
8140
ed2ac2e85eef
(set-visited-file-name): Handle find-file-visit-truename
Richard M. Stallman <rms@gnu.org>
parents:
7993
diff
changeset
|
1989 (setq buffer-file-number |
ed2ac2e85eef
(set-visited-file-name): Handle find-file-visit-truename
Richard M. Stallman <rms@gnu.org>
parents:
7993
diff
changeset
|
1990 (if filename |
13326
4e1b078121ad
(set-visited-file-name, basic-save-buffer):
Richard M. Stallman <rms@gnu.org>
parents:
13289
diff
changeset
|
1991 (nthcdr 10 (file-attributes buffer-file-name)) |
8140
ed2ac2e85eef
(set-visited-file-name): Handle find-file-visit-truename
Richard M. Stallman <rms@gnu.org>
parents:
7993
diff
changeset
|
1992 nil))) |
337 | 1993 ;; write-file-hooks is normally used for things like ftp-find-file |
1994 ;; that visit things that are not local files as if they were files. | |
1995 ;; Changing to visit an ordinary local file instead should flush the hook. | |
1996 (kill-local-variable 'write-file-hooks) | |
2375
94e135f2d64d
(local-write-file-hooks): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
2335
diff
changeset
|
1997 (kill-local-variable 'local-write-file-hooks) |
337 | 1998 (kill-local-variable 'revert-buffer-function) |
1999 (kill-local-variable 'backup-inhibited) | |
6546
8eb722515c31
(set-visited-file-name): Kill local var vc-mode.
Richard M. Stallman <rms@gnu.org>
parents:
6454
diff
changeset
|
2000 ;; If buffer was read-only because of version control, |
8eb722515c31
(set-visited-file-name): Kill local var vc-mode.
Richard M. Stallman <rms@gnu.org>
parents:
6454
diff
changeset
|
2001 ;; that reason is gone now, so make it writable. |
8eb722515c31
(set-visited-file-name): Kill local var vc-mode.
Richard M. Stallman <rms@gnu.org>
parents:
6454
diff
changeset
|
2002 (if vc-mode |
8eb722515c31
(set-visited-file-name): Kill local var vc-mode.
Richard M. Stallman <rms@gnu.org>
parents:
6454
diff
changeset
|
2003 (setq buffer-read-only nil)) |
8eb722515c31
(set-visited-file-name): Kill local var vc-mode.
Richard M. Stallman <rms@gnu.org>
parents:
6454
diff
changeset
|
2004 (kill-local-variable 'vc-mode) |
337 | 2005 ;; Turn off backup files for certain file names. |
2006 ;; Since this is a permanent local, the major mode won't eliminate it. | |
21001
88e63a96a2d4
(set-visited-file-name): Don't call backup-enable-predicate
Karl Heuer <kwzh@gnu.org>
parents:
20660
diff
changeset
|
2007 (and buffer-file-name |
88e63a96a2d4
(set-visited-file-name): Don't call backup-enable-predicate
Karl Heuer <kwzh@gnu.org>
parents:
20660
diff
changeset
|
2008 (not (funcall backup-enable-predicate buffer-file-name)) |
337 | 2009 (progn |
2010 (make-local-variable 'backup-inhibited) | |
2011 (setq backup-inhibited t))) | |
3944
5e740ac08e39
(set-visited-file-name): Rename the old auto save file.
Richard M. Stallman <rms@gnu.org>
parents:
3835
diff
changeset
|
2012 (let ((oauto buffer-auto-save-file-name)) |
5e740ac08e39
(set-visited-file-name): Rename the old auto save file.
Richard M. Stallman <rms@gnu.org>
parents:
3835
diff
changeset
|
2013 ;; If auto-save was not already on, turn it on if appropriate. |
5e740ac08e39
(set-visited-file-name): Rename the old auto save file.
Richard M. Stallman <rms@gnu.org>
parents:
3835
diff
changeset
|
2014 (if (not buffer-auto-save-file-name) |
5e740ac08e39
(set-visited-file-name): Rename the old auto save file.
Richard M. Stallman <rms@gnu.org>
parents:
3835
diff
changeset
|
2015 (and buffer-file-name auto-save-default |
5e740ac08e39
(set-visited-file-name): Rename the old auto save file.
Richard M. Stallman <rms@gnu.org>
parents:
3835
diff
changeset
|
2016 (auto-save-mode t)) |
5e740ac08e39
(set-visited-file-name): Rename the old auto save file.
Richard M. Stallman <rms@gnu.org>
parents:
3835
diff
changeset
|
2017 ;; If auto save is on, start using a new name. |
5e740ac08e39
(set-visited-file-name): Rename the old auto save file.
Richard M. Stallman <rms@gnu.org>
parents:
3835
diff
changeset
|
2018 ;; We deliberately don't rename or delete the old auto save |
5e740ac08e39
(set-visited-file-name): Rename the old auto save file.
Richard M. Stallman <rms@gnu.org>
parents:
3835
diff
changeset
|
2019 ;; for the old visited file name. This is because perhaps |
5e740ac08e39
(set-visited-file-name): Rename the old auto save file.
Richard M. Stallman <rms@gnu.org>
parents:
3835
diff
changeset
|
2020 ;; the user wants to save the new state and then compare with the |
5e740ac08e39
(set-visited-file-name): Rename the old auto save file.
Richard M. Stallman <rms@gnu.org>
parents:
3835
diff
changeset
|
2021 ;; previous state from the auto save file. |
5e740ac08e39
(set-visited-file-name): Rename the old auto save file.
Richard M. Stallman <rms@gnu.org>
parents:
3835
diff
changeset
|
2022 (setq buffer-auto-save-file-name |
5e740ac08e39
(set-visited-file-name): Rename the old auto save file.
Richard M. Stallman <rms@gnu.org>
parents:
3835
diff
changeset
|
2023 (make-auto-save-file-name))) |
5e740ac08e39
(set-visited-file-name): Rename the old auto save file.
Richard M. Stallman <rms@gnu.org>
parents:
3835
diff
changeset
|
2024 ;; Rename the old auto save file if any. |
5e740ac08e39
(set-visited-file-name): Rename the old auto save file.
Richard M. Stallman <rms@gnu.org>
parents:
3835
diff
changeset
|
2025 (and oauto buffer-auto-save-file-name |
3946
535f1f575d04
(set-visited-file-name): Rename auto-save file only if it exists.
Richard M. Stallman <rms@gnu.org>
parents:
3944
diff
changeset
|
2026 (file-exists-p oauto) |
3944
5e740ac08e39
(set-visited-file-name): Rename the old auto save file.
Richard M. Stallman <rms@gnu.org>
parents:
3835
diff
changeset
|
2027 (rename-file oauto buffer-auto-save-file-name t))) |
16971
c1b9bc4c525b
(set-visited-file-name): New arg ALONG-WITH-FILE.
Richard M. Stallman <rms@gnu.org>
parents:
16831
diff
changeset
|
2028 (and buffer-file-name |
c1b9bc4c525b
(set-visited-file-name): New arg ALONG-WITH-FILE.
Richard M. Stallman <rms@gnu.org>
parents:
16831
diff
changeset
|
2029 (not along-with-file) |
17660
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
2030 (set-buffer-modified-p t)) |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
2031 ;; Update the major mode, if the file name determines it. |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
2032 (condition-case nil |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
2033 ;; Don't change the mode if it is special. |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
2034 (or (not change-major-mode-with-file-name) |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
2035 (get major-mode 'mode-class) |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
2036 ;; Don't change the mode if the local variable list specifies it. |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
2037 (hack-local-variables t) |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
2038 (set-auto-mode t)) |
473ee9294c31
(set-auto-mode): New arg JUST-FROM-FILE-NAME.
Richard M. Stallman <rms@gnu.org>
parents:
17525
diff
changeset
|
2039 (error nil))) |
337 | 2040 |
17987
2d9818a04c36
(find-file): Delete the facility of handling a prefix
Kenichi Handa <handa@m17n.org>
parents:
17894
diff
changeset
|
2041 (defun write-file (filename &optional confirm) |
337 | 2042 "Write current buffer into file FILENAME. |
24832
b772f629b45b
(write-file): When buffer is not already visiting a file,
Karl Heuer <kwzh@gnu.org>
parents:
24764
diff
changeset
|
2043 This makes the buffer visit that file, and marks it as not modified. |
b772f629b45b
(write-file): When buffer is not already visiting a file,
Karl Heuer <kwzh@gnu.org>
parents:
24764
diff
changeset
|
2044 |
b772f629b45b
(write-file): When buffer is not already visiting a file,
Karl Heuer <kwzh@gnu.org>
parents:
24764
diff
changeset
|
2045 If you specify just a directory name as FILENAME, that means to use |
b772f629b45b
(write-file): When buffer is not already visiting a file,
Karl Heuer <kwzh@gnu.org>
parents:
24764
diff
changeset
|
2046 the default file name but in that directory. You can also yank |
b772f629b45b
(write-file): When buffer is not already visiting a file,
Karl Heuer <kwzh@gnu.org>
parents:
24764
diff
changeset
|
2047 the default file name into the minibuffer to edit it, using M-n. |
14469
713f9bf02e20
(auto-mode-alist): .ksh suffix means sh-mode.
Richard M. Stallman <rms@gnu.org>
parents:
14401
diff
changeset
|
2048 |
24832
b772f629b45b
(write-file): When buffer is not already visiting a file,
Karl Heuer <kwzh@gnu.org>
parents:
24764
diff
changeset
|
2049 If the buffer is not already visiting a file, the default file name |
b772f629b45b
(write-file): When buffer is not already visiting a file,
Karl Heuer <kwzh@gnu.org>
parents:
24764
diff
changeset
|
2050 for the output file is the buffer name. |
b772f629b45b
(write-file): When buffer is not already visiting a file,
Karl Heuer <kwzh@gnu.org>
parents:
24764
diff
changeset
|
2051 |
b772f629b45b
(write-file): When buffer is not already visiting a file,
Karl Heuer <kwzh@gnu.org>
parents:
24764
diff
changeset
|
2052 If optional second arg CONFIRM is non-nil, this function |
b772f629b45b
(write-file): When buffer is not already visiting a file,
Karl Heuer <kwzh@gnu.org>
parents:
24764
diff
changeset
|
2053 asks for confirmation before overwriting an existing file. |
17987
2d9818a04c36
(find-file): Delete the facility of handling a prefix
Kenichi Handa <handa@m17n.org>
parents:
17894
diff
changeset
|
2054 Interactively, confirmation is required unless you supply a prefix argument." |
337 | 2055 ;; (interactive "FWrite file: ") |
2056 (interactive | |
2057 (list (if buffer-file-name | |
2058 (read-file-name "Write file: " | |
2059 nil nil nil nil) | |
24832
b772f629b45b
(write-file): When buffer is not already visiting a file,
Karl Heuer <kwzh@gnu.org>
parents:
24764
diff
changeset
|
2060 (read-file-name "Write file: " default-directory |
b772f629b45b
(write-file): When buffer is not already visiting a file,
Karl Heuer <kwzh@gnu.org>
parents:
24764
diff
changeset
|
2061 (expand-file-name |
b772f629b45b
(write-file): When buffer is not already visiting a file,
Karl Heuer <kwzh@gnu.org>
parents:
24764
diff
changeset
|
2062 (file-name-nondirectory (buffer-name)) |
b772f629b45b
(write-file): When buffer is not already visiting a file,
Karl Heuer <kwzh@gnu.org>
parents:
24764
diff
changeset
|
2063 default-directory) |
b772f629b45b
(write-file): When buffer is not already visiting a file,
Karl Heuer <kwzh@gnu.org>
parents:
24764
diff
changeset
|
2064 nil nil)) |
17987
2d9818a04c36
(find-file): Delete the facility of handling a prefix
Kenichi Handa <handa@m17n.org>
parents:
17894
diff
changeset
|
2065 (not current-prefix-arg))) |
337 | 2066 (or (null filename) (string-equal filename "") |
2003
bff31af6c721
(write-file): Handle directory name as arg.
Richard M. Stallman <rms@gnu.org>
parents:
1905
diff
changeset
|
2067 (progn |
bff31af6c721
(write-file): Handle directory name as arg.
Richard M. Stallman <rms@gnu.org>
parents:
1905
diff
changeset
|
2068 ;; If arg is just a directory, |
24832
b772f629b45b
(write-file): When buffer is not already visiting a file,
Karl Heuer <kwzh@gnu.org>
parents:
24764
diff
changeset
|
2069 ;; use the default file name, but in that directory. |
b772f629b45b
(write-file): When buffer is not already visiting a file,
Karl Heuer <kwzh@gnu.org>
parents:
24764
diff
changeset
|
2070 (if (file-directory-p filename) |
2003
bff31af6c721
(write-file): Handle directory name as arg.
Richard M. Stallman <rms@gnu.org>
parents:
1905
diff
changeset
|
2071 (setq filename (concat (file-name-as-directory filename) |
24832
b772f629b45b
(write-file): When buffer is not already visiting a file,
Karl Heuer <kwzh@gnu.org>
parents:
24764
diff
changeset
|
2072 (file-name-nondirectory |
b772f629b45b
(write-file): When buffer is not already visiting a file,
Karl Heuer <kwzh@gnu.org>
parents:
24764
diff
changeset
|
2073 (or buffer-file-name (buffer-name)))))) |
11340
5c97fabe0ab9
(write-file): Default is ask for confirmation only interactively.
Richard M. Stallman <rms@gnu.org>
parents:
11222
diff
changeset
|
2074 (and confirm |
5c97fabe0ab9
(write-file): Default is ask for confirmation only interactively.
Richard M. Stallman <rms@gnu.org>
parents:
11222
diff
changeset
|
2075 (file-exists-p filename) |
5c97fabe0ab9
(write-file): Default is ask for confirmation only interactively.
Richard M. Stallman <rms@gnu.org>
parents:
11222
diff
changeset
|
2076 (or (y-or-n-p (format "File `%s' exists; overwrite? " filename)) |
5c97fabe0ab9
(write-file): Default is ask for confirmation only interactively.
Richard M. Stallman <rms@gnu.org>
parents:
11222
diff
changeset
|
2077 (error "Canceled"))) |
16470
b050d980c422
(set-visited-file-name): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
16440
diff
changeset
|
2078 (set-visited-file-name filename (not confirm)))) |
337 | 2079 (set-buffer-modified-p t) |
20291
96eee1e730a1
(write-file): Make buffer writable if the new file is.
Karl Heuer <kwzh@gnu.org>
parents:
20218
diff
changeset
|
2080 ;; Make buffer writable if file is writable. |
96eee1e730a1
(write-file): Make buffer writable if the new file is.
Karl Heuer <kwzh@gnu.org>
parents:
20218
diff
changeset
|
2081 (and buffer-file-name |
96eee1e730a1
(write-file): Make buffer writable if the new file is.
Karl Heuer <kwzh@gnu.org>
parents:
20218
diff
changeset
|
2082 (file-writable-p buffer-file-name) |
96eee1e730a1
(write-file): Make buffer writable if the new file is.
Karl Heuer <kwzh@gnu.org>
parents:
20218
diff
changeset
|
2083 (setq buffer-read-only nil)) |
17987
2d9818a04c36
(find-file): Delete the facility of handling a prefix
Kenichi Handa <handa@m17n.org>
parents:
17894
diff
changeset
|
2084 (save-buffer)) |
337 | 2085 |
2086 (defun backup-buffer () | |
2087 "Make a backup of the disk file visited by the current buffer, if appropriate. | |
2088 This is normally done before saving the buffer the first time. | |
2089 If the value is non-nil, it is the result of `file-modes' on the original | |
2090 file; this means that the caller, after saving the buffer, should change | |
16614 | 2091 the modes of the new file to agree with the old modes. |
2092 | |
2093 A backup may be done by renaming or by copying; see documentation of | |
2094 variable `make-backup-files'. If it's done by renaming, then the file is | |
2095 no longer accessible under its old name." | |
337 | 2096 (if (and make-backup-files (not backup-inhibited) |
2097 (not buffer-backed-up) | |
2098 (file-exists-p buffer-file-name) | |
2099 (memq (aref (elt (file-attributes buffer-file-name) 8) 0) | |
2100 '(?- ?l))) | |
2101 (let ((real-file-name buffer-file-name) | |
2102 backup-info backupname targets setmodes) | |
2103 ;; If specified name is a symbolic link, chase it to the target. | |
2104 ;; Thus we make the backups in the directory where the real file is. | |
3260
eecf2c0ca9b9
(file-chase-links): New function.
Richard M. Stallman <rms@gnu.org>
parents:
3240
diff
changeset
|
2105 (setq real-file-name (file-chase-links real-file-name)) |
337 | 2106 (setq backup-info (find-backup-file-name real-file-name) |
2107 backupname (car backup-info) | |
2108 targets (cdr backup-info)) | |
2109 ;;; (if (file-directory-p buffer-file-name) | |
2110 ;;; (error "Cannot save buffer in directory %s" buffer-file-name)) | |
10408
c79720be7bd7
(find-backup-file-name): Run a file name handler.
Richard M. Stallman <rms@gnu.org>
parents:
10338
diff
changeset
|
2111 (if backup-info |
c79720be7bd7
(find-backup-file-name): Run a file name handler.
Richard M. Stallman <rms@gnu.org>
parents:
10338
diff
changeset
|
2112 (condition-case () |
c79720be7bd7
(find-backup-file-name): Run a file name handler.
Richard M. Stallman <rms@gnu.org>
parents:
10338
diff
changeset
|
2113 (let ((delete-old-versions |
c79720be7bd7
(find-backup-file-name): Run a file name handler.
Richard M. Stallman <rms@gnu.org>
parents:
10338
diff
changeset
|
2114 ;; If have old versions to maybe delete, |
c79720be7bd7
(find-backup-file-name): Run a file name handler.
Richard M. Stallman <rms@gnu.org>
parents:
10338
diff
changeset
|
2115 ;; ask the user to confirm now, before doing anything. |
c79720be7bd7
(find-backup-file-name): Run a file name handler.
Richard M. Stallman <rms@gnu.org>
parents:
10338
diff
changeset
|
2116 ;; But don't actually delete til later. |
c79720be7bd7
(find-backup-file-name): Run a file name handler.
Richard M. Stallman <rms@gnu.org>
parents:
10338
diff
changeset
|
2117 (and targets |
c79720be7bd7
(find-backup-file-name): Run a file name handler.
Richard M. Stallman <rms@gnu.org>
parents:
10338
diff
changeset
|
2118 (or (eq delete-old-versions t) (eq delete-old-versions nil)) |
c79720be7bd7
(find-backup-file-name): Run a file name handler.
Richard M. Stallman <rms@gnu.org>
parents:
10338
diff
changeset
|
2119 (or delete-old-versions |
c79720be7bd7
(find-backup-file-name): Run a file name handler.
Richard M. Stallman <rms@gnu.org>
parents:
10338
diff
changeset
|
2120 (y-or-n-p (format "Delete excess backup versions of %s? " |
c79720be7bd7
(find-backup-file-name): Run a file name handler.
Richard M. Stallman <rms@gnu.org>
parents:
10338
diff
changeset
|
2121 real-file-name)))))) |
c79720be7bd7
(find-backup-file-name): Run a file name handler.
Richard M. Stallman <rms@gnu.org>
parents:
10338
diff
changeset
|
2122 ;; Actually write the back up file. |
c79720be7bd7
(find-backup-file-name): Run a file name handler.
Richard M. Stallman <rms@gnu.org>
parents:
10338
diff
changeset
|
2123 (condition-case () |
c79720be7bd7
(find-backup-file-name): Run a file name handler.
Richard M. Stallman <rms@gnu.org>
parents:
10338
diff
changeset
|
2124 (if (or file-precious-flag |
32138 | 2125 ; (file-symlink-p buffer-file-name) |
10408
c79720be7bd7
(find-backup-file-name): Run a file name handler.
Richard M. Stallman <rms@gnu.org>
parents:
10338
diff
changeset
|
2126 backup-by-copying |
c79720be7bd7
(find-backup-file-name): Run a file name handler.
Richard M. Stallman <rms@gnu.org>
parents:
10338
diff
changeset
|
2127 (and backup-by-copying-when-linked |
c79720be7bd7
(find-backup-file-name): Run a file name handler.
Richard M. Stallman <rms@gnu.org>
parents:
10338
diff
changeset
|
2128 (> (file-nlinks real-file-name) 1)) |
32138 | 2129 (and (or backup-by-copying-when-mismatch |
2130 (integerp backup-by-copying-when-privileged-mismatch)) | |
10408
c79720be7bd7
(find-backup-file-name): Run a file name handler.
Richard M. Stallman <rms@gnu.org>
parents:
10338
diff
changeset
|
2131 (let ((attr (file-attributes real-file-name))) |
32138 | 2132 (and (or backup-by-copying-when-mismatch |
2133 (and (integerp (nth 2 attr)) | |
2134 (integerp backup-by-copying-when-privileged-mismatch) | |
2135 (<= (nth 2 attr) backup-by-copying-when-privileged-mismatch))) | |
2136 (or (nth 9 attr) | |
2137 (not (file-ownership-preserved-p real-file-name))))))) | |
10408
c79720be7bd7
(find-backup-file-name): Run a file name handler.
Richard M. Stallman <rms@gnu.org>
parents:
10338
diff
changeset
|
2138 (condition-case () |
c79720be7bd7
(find-backup-file-name): Run a file name handler.
Richard M. Stallman <rms@gnu.org>
parents:
10338
diff
changeset
|
2139 (copy-file real-file-name backupname t t) |
c79720be7bd7
(find-backup-file-name): Run a file name handler.
Richard M. Stallman <rms@gnu.org>
parents:
10338
diff
changeset
|
2140 (file-error |
c79720be7bd7
(find-backup-file-name): Run a file name handler.
Richard M. Stallman <rms@gnu.org>
parents:
10338
diff
changeset
|
2141 ;; If copying fails because file BACKUPNAME |
c79720be7bd7
(find-backup-file-name): Run a file name handler.
Richard M. Stallman <rms@gnu.org>
parents:
10338
diff
changeset
|
2142 ;; is not writable, delete that file and try again. |
c79720be7bd7
(find-backup-file-name): Run a file name handler.
Richard M. Stallman <rms@gnu.org>
parents:
10338
diff
changeset
|
2143 (if (and (file-exists-p backupname) |
c79720be7bd7
(find-backup-file-name): Run a file name handler.
Richard M. Stallman <rms@gnu.org>
parents:
10338
diff
changeset
|
2144 (not (file-writable-p backupname))) |
c79720be7bd7
(find-backup-file-name): Run a file name handler.
Richard M. Stallman <rms@gnu.org>
parents:
10338
diff
changeset
|
2145 (delete-file backupname)) |
c79720be7bd7
(find-backup-file-name): Run a file name handler.
Richard M. Stallman <rms@gnu.org>
parents:
10338
diff
changeset
|
2146 (copy-file real-file-name backupname t t))) |
c79720be7bd7
(find-backup-file-name): Run a file name handler.
Richard M. Stallman <rms@gnu.org>
parents:
10338
diff
changeset
|
2147 ;; rename-file should delete old backup. |
c79720be7bd7
(find-backup-file-name): Run a file name handler.
Richard M. Stallman <rms@gnu.org>
parents:
10338
diff
changeset
|
2148 (rename-file real-file-name backupname t) |
c79720be7bd7
(find-backup-file-name): Run a file name handler.
Richard M. Stallman <rms@gnu.org>
parents:
10338
diff
changeset
|
2149 (setq setmodes (file-modes backupname))) |
c79720be7bd7
(find-backup-file-name): Run a file name handler.
Richard M. Stallman <rms@gnu.org>
parents:
10338
diff
changeset
|
2150 (file-error |
c79720be7bd7
(find-backup-file-name): Run a file name handler.
Richard M. Stallman <rms@gnu.org>
parents:
10338
diff
changeset
|
2151 ;; If trouble writing the backup, write it in ~. |
13903
936c8364e15a
(abbrev-file-name): Drive letter can go beyond `Z' under MS-DOS/Novell.
Richard M. Stallman <rms@gnu.org>
parents:
13885
diff
changeset
|
2152 (setq backupname (expand-file-name |
936c8364e15a
(abbrev-file-name): Drive letter can go beyond `Z' under MS-DOS/Novell.
Richard M. Stallman <rms@gnu.org>
parents:
13885
diff
changeset
|
2153 (convert-standard-filename |
936c8364e15a
(abbrev-file-name): Drive letter can go beyond `Z' under MS-DOS/Novell.
Richard M. Stallman <rms@gnu.org>
parents:
13885
diff
changeset
|
2154 "~/%backup%~"))) |
936c8364e15a
(abbrev-file-name): Drive letter can go beyond `Z' under MS-DOS/Novell.
Richard M. Stallman <rms@gnu.org>
parents:
13885
diff
changeset
|
2155 (message "Cannot write backup file; backing up in %s" |
936c8364e15a
(abbrev-file-name): Drive letter can go beyond `Z' under MS-DOS/Novell.
Richard M. Stallman <rms@gnu.org>
parents:
13885
diff
changeset
|
2156 (file-name-nondirectory backupname)) |
10408
c79720be7bd7
(find-backup-file-name): Run a file name handler.
Richard M. Stallman <rms@gnu.org>
parents:
10338
diff
changeset
|
2157 (sleep-for 1) |
c79720be7bd7
(find-backup-file-name): Run a file name handler.
Richard M. Stallman <rms@gnu.org>
parents:
10338
diff
changeset
|
2158 (condition-case () |
c79720be7bd7
(find-backup-file-name): Run a file name handler.
Richard M. Stallman <rms@gnu.org>
parents:
10338
diff
changeset
|
2159 (copy-file real-file-name backupname t t) |
c79720be7bd7
(find-backup-file-name): Run a file name handler.
Richard M. Stallman <rms@gnu.org>
parents:
10338
diff
changeset
|
2160 (file-error |
c79720be7bd7
(find-backup-file-name): Run a file name handler.
Richard M. Stallman <rms@gnu.org>
parents:
10338
diff
changeset
|
2161 ;; If copying fails because file BACKUPNAME |
c79720be7bd7
(find-backup-file-name): Run a file name handler.
Richard M. Stallman <rms@gnu.org>
parents:
10338
diff
changeset
|
2162 ;; is not writable, delete that file and try again. |
c79720be7bd7
(find-backup-file-name): Run a file name handler.
Richard M. Stallman <rms@gnu.org>
parents:
10338
diff
changeset
|
2163 (if (and (file-exists-p backupname) |
c79720be7bd7
(find-backup-file-name): Run a file name handler.
Richard M. Stallman <rms@gnu.org>
parents:
10338
diff
changeset
|
2164 (not (file-writable-p backupname))) |
c79720be7bd7
(find-backup-file-name): Run a file name handler.
Richard M. Stallman <rms@gnu.org>
parents:
10338
diff
changeset
|
2165 (delete-file backupname)) |
c79720be7bd7
(find-backup-file-name): Run a file name handler.
Richard M. Stallman <rms@gnu.org>
parents:
10338
diff
changeset
|
2166 (copy-file real-file-name backupname t t))))) |
c79720be7bd7
(find-backup-file-name): Run a file name handler.
Richard M. Stallman <rms@gnu.org>
parents:
10338
diff
changeset
|
2167 (setq buffer-backed-up t) |
c79720be7bd7
(find-backup-file-name): Run a file name handler.
Richard M. Stallman <rms@gnu.org>
parents:
10338
diff
changeset
|
2168 ;; Now delete the old versions, if desired. |
c79720be7bd7
(find-backup-file-name): Run a file name handler.
Richard M. Stallman <rms@gnu.org>
parents:
10338
diff
changeset
|
2169 (if delete-old-versions |
c79720be7bd7
(find-backup-file-name): Run a file name handler.
Richard M. Stallman <rms@gnu.org>
parents:
10338
diff
changeset
|
2170 (while targets |
c79720be7bd7
(find-backup-file-name): Run a file name handler.
Richard M. Stallman <rms@gnu.org>
parents:
10338
diff
changeset
|
2171 (condition-case () |
c79720be7bd7
(find-backup-file-name): Run a file name handler.
Richard M. Stallman <rms@gnu.org>
parents:
10338
diff
changeset
|
2172 (delete-file (car targets)) |
c79720be7bd7
(find-backup-file-name): Run a file name handler.
Richard M. Stallman <rms@gnu.org>
parents:
10338
diff
changeset
|
2173 (file-error nil)) |
c79720be7bd7
(find-backup-file-name): Run a file name handler.
Richard M. Stallman <rms@gnu.org>
parents:
10338
diff
changeset
|
2174 (setq targets (cdr targets)))) |
c79720be7bd7
(find-backup-file-name): Run a file name handler.
Richard M. Stallman <rms@gnu.org>
parents:
10338
diff
changeset
|
2175 setmodes) |
c79720be7bd7
(find-backup-file-name): Run a file name handler.
Richard M. Stallman <rms@gnu.org>
parents:
10338
diff
changeset
|
2176 (file-error nil)))))) |
337 | 2177 |
1109
c9feb3e64805
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1103
diff
changeset
|
2178 (defun file-name-sans-versions (name &optional keep-backup-version) |
32138 | 2179 "Return file NAME sans backup versions or strings. |
337 | 2180 This is a separate procedure so your site-init or startup file can |
1109
c9feb3e64805
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1103
diff
changeset
|
2181 redefine it. |
c9feb3e64805
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1103
diff
changeset
|
2182 If the optional argument KEEP-BACKUP-VERSION is non-nil, |
c9feb3e64805
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1103
diff
changeset
|
2183 we do not remove backup version numbers, only true file version numbers." |
7030
9e51b51e8595
Pass operation to find-file-name-handler.
Karl Heuer <kwzh@gnu.org>
parents:
6899
diff
changeset
|
2184 (let ((handler (find-file-name-handler name 'file-name-sans-versions))) |
1109
c9feb3e64805
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1103
diff
changeset
|
2185 (if handler |
c9feb3e64805
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1103
diff
changeset
|
2186 (funcall handler 'file-name-sans-versions name keep-backup-version) |
c9feb3e64805
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1103
diff
changeset
|
2187 (substring name 0 |
c9feb3e64805
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1103
diff
changeset
|
2188 (if (eq system-type 'vax-vms) |
c9feb3e64805
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1103
diff
changeset
|
2189 ;; VMS version number is (a) semicolon, optional |
c9feb3e64805
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1103
diff
changeset
|
2190 ;; sign, zero or more digits or (b) period, option |
c9feb3e64805
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1103
diff
changeset
|
2191 ;; sign, zero or more digits, provided this is the |
c9feb3e64805
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1103
diff
changeset
|
2192 ;; second period encountered outside of the |
c9feb3e64805
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1103
diff
changeset
|
2193 ;; device/directory part of the file name. |
6309
9217f29851c2
Don't use triple-hyphen in a character class.
Karl Heuer <kwzh@gnu.org>
parents:
6294
diff
changeset
|
2194 (or (string-match ";[-+]?[0-9]*\\'" name) |
9217f29851c2
Don't use triple-hyphen in a character class.
Karl Heuer <kwzh@gnu.org>
parents:
6294
diff
changeset
|
2195 (if (string-match "\\.[^]>:]*\\(\\.[-+]?[0-9]*\\)\\'" |
1109
c9feb3e64805
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1103
diff
changeset
|
2196 name) |
c9feb3e64805
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1103
diff
changeset
|
2197 (match-beginning 1)) |
c9feb3e64805
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1103
diff
changeset
|
2198 (length name)) |
c9feb3e64805
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1103
diff
changeset
|
2199 (if keep-backup-version |
c9feb3e64805
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1103
diff
changeset
|
2200 (length name) |
12591
7caa97ba6a7b
(file-name-sans-versions): Recognize version control version numbers.
Richard M. Stallman <rms@gnu.org>
parents:
12587
diff
changeset
|
2201 (or (string-match "\\.~[0-9.]+~\\'" name) |
1109
c9feb3e64805
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1103
diff
changeset
|
2202 (string-match "~\\'" name) |
c9feb3e64805
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1103
diff
changeset
|
2203 (length name)))))))) |
337 | 2204 |
8987
1db2285cec99
(file-ownership-preserved-p): New function.
Richard M. Stallman <rms@gnu.org>
parents:
8937
diff
changeset
|
2205 (defun file-ownership-preserved-p (file) |
32138 | 2206 "Return t if deleting FILE and rewriting it would preserve the owner." |
8987
1db2285cec99
(file-ownership-preserved-p): New function.
Richard M. Stallman <rms@gnu.org>
parents:
8937
diff
changeset
|
2207 (let ((handler (find-file-name-handler file 'file-ownership-preserved-p))) |
1db2285cec99
(file-ownership-preserved-p): New function.
Richard M. Stallman <rms@gnu.org>
parents:
8937
diff
changeset
|
2208 (if handler |
1db2285cec99
(file-ownership-preserved-p): New function.
Richard M. Stallman <rms@gnu.org>
parents:
8937
diff
changeset
|
2209 (funcall handler 'file-ownership-preserved-p file) |
11867
b00d51017e13
(file-ownership-preserved-p): Fix typo in previous change.
Karl Heuer <kwzh@gnu.org>
parents:
11817
diff
changeset
|
2210 (let ((attributes (file-attributes file))) |
11817
ba82c338bee3
(path-separator): Defined.
Richard M. Stallman <rms@gnu.org>
parents:
11739
diff
changeset
|
2211 ;; Return t if the file doesn't exist, since it's true that no |
ba82c338bee3
(path-separator): Defined.
Richard M. Stallman <rms@gnu.org>
parents:
11739
diff
changeset
|
2212 ;; information would be lost by an (attempted) delete and create. |
ba82c338bee3
(path-separator): Defined.
Richard M. Stallman <rms@gnu.org>
parents:
11739
diff
changeset
|
2213 (or (null attributes) |
ba82c338bee3
(path-separator): Defined.
Richard M. Stallman <rms@gnu.org>
parents:
11739
diff
changeset
|
2214 (= (nth 2 attributes) (user-uid))))))) |
8987
1db2285cec99
(file-ownership-preserved-p): New function.
Richard M. Stallman <rms@gnu.org>
parents:
8937
diff
changeset
|
2215 |
8908
25d8b804abd3
(file-name-sans-extension): New function.
Richard M. Stallman <rms@gnu.org>
parents:
8650
diff
changeset
|
2216 (defun file-name-sans-extension (filename) |
25d8b804abd3
(file-name-sans-extension): New function.
Richard M. Stallman <rms@gnu.org>
parents:
8650
diff
changeset
|
2217 "Return FILENAME sans final \"extension\". |
25d8b804abd3
(file-name-sans-extension): New function.
Richard M. Stallman <rms@gnu.org>
parents:
8650
diff
changeset
|
2218 The extension, in a file name, is the part that follows the last `.'." |
25d8b804abd3
(file-name-sans-extension): New function.
Richard M. Stallman <rms@gnu.org>
parents:
8650
diff
changeset
|
2219 (save-match-data |
25d8b804abd3
(file-name-sans-extension): New function.
Richard M. Stallman <rms@gnu.org>
parents:
8650
diff
changeset
|
2220 (let ((file (file-name-sans-versions (file-name-nondirectory filename))) |
25d8b804abd3
(file-name-sans-extension): New function.
Richard M. Stallman <rms@gnu.org>
parents:
8650
diff
changeset
|
2221 directory) |
25d8b804abd3
(file-name-sans-extension): New function.
Richard M. Stallman <rms@gnu.org>
parents:
8650
diff
changeset
|
2222 (if (string-match "\\.[^.]*\\'" file) |
25d8b804abd3
(file-name-sans-extension): New function.
Richard M. Stallman <rms@gnu.org>
parents:
8650
diff
changeset
|
2223 (if (setq directory (file-name-directory filename)) |
25d8b804abd3
(file-name-sans-extension): New function.
Richard M. Stallman <rms@gnu.org>
parents:
8650
diff
changeset
|
2224 (expand-file-name (substring file 0 (match-beginning 0)) |
25d8b804abd3
(file-name-sans-extension): New function.
Richard M. Stallman <rms@gnu.org>
parents:
8650
diff
changeset
|
2225 directory) |
25d8b804abd3
(file-name-sans-extension): New function.
Richard M. Stallman <rms@gnu.org>
parents:
8650
diff
changeset
|
2226 (substring file 0 (match-beginning 0))) |
25d8b804abd3
(file-name-sans-extension): New function.
Richard M. Stallman <rms@gnu.org>
parents:
8650
diff
changeset
|
2227 filename)))) |
25d8b804abd3
(file-name-sans-extension): New function.
Richard M. Stallman <rms@gnu.org>
parents:
8650
diff
changeset
|
2228 |
16440
e735290b9ebb
(hack-local-variables-prop-line):
Richard M. Stallman <rms@gnu.org>
parents:
16414
diff
changeset
|
2229 (defun file-name-extension (filename &optional period) |
e735290b9ebb
(hack-local-variables-prop-line):
Richard M. Stallman <rms@gnu.org>
parents:
16414
diff
changeset
|
2230 "Return FILENAME's final \"extension\". |
e735290b9ebb
(hack-local-variables-prop-line):
Richard M. Stallman <rms@gnu.org>
parents:
16414
diff
changeset
|
2231 The extension, in a file name, is the part that follows the last `.'. |
e735290b9ebb
(hack-local-variables-prop-line):
Richard M. Stallman <rms@gnu.org>
parents:
16414
diff
changeset
|
2232 Return nil for extensionless file names such as `foo'. |
e735290b9ebb
(hack-local-variables-prop-line):
Richard M. Stallman <rms@gnu.org>
parents:
16414
diff
changeset
|
2233 Return the empty string for file names such as `foo.'. |
e735290b9ebb
(hack-local-variables-prop-line):
Richard M. Stallman <rms@gnu.org>
parents:
16414
diff
changeset
|
2234 |
e735290b9ebb
(hack-local-variables-prop-line):
Richard M. Stallman <rms@gnu.org>
parents:
16414
diff
changeset
|
2235 If PERIOD is non-nil, then the returned value includes the period |
e735290b9ebb
(hack-local-variables-prop-line):
Richard M. Stallman <rms@gnu.org>
parents:
16414
diff
changeset
|
2236 that delimits the extension, and if FILENAME has no extension, |
e735290b9ebb
(hack-local-variables-prop-line):
Richard M. Stallman <rms@gnu.org>
parents:
16414
diff
changeset
|
2237 the value is \"\"." |
e735290b9ebb
(hack-local-variables-prop-line):
Richard M. Stallman <rms@gnu.org>
parents:
16414
diff
changeset
|
2238 (save-match-data |
e735290b9ebb
(hack-local-variables-prop-line):
Richard M. Stallman <rms@gnu.org>
parents:
16414
diff
changeset
|
2239 (let ((file (file-name-sans-versions (file-name-nondirectory filename)))) |
e735290b9ebb
(hack-local-variables-prop-line):
Richard M. Stallman <rms@gnu.org>
parents:
16414
diff
changeset
|
2240 (if (string-match "\\.[^.]*\\'" file) |
e735290b9ebb
(hack-local-variables-prop-line):
Richard M. Stallman <rms@gnu.org>
parents:
16414
diff
changeset
|
2241 (substring file (+ (match-beginning 0) (if period 0 1))) |
e735290b9ebb
(hack-local-variables-prop-line):
Richard M. Stallman <rms@gnu.org>
parents:
16414
diff
changeset
|
2242 (if period |
e735290b9ebb
(hack-local-variables-prop-line):
Richard M. Stallman <rms@gnu.org>
parents:
16414
diff
changeset
|
2243 ""))))) |
e735290b9ebb
(hack-local-variables-prop-line):
Richard M. Stallman <rms@gnu.org>
parents:
16414
diff
changeset
|
2244 |
32138 | 2245 (defcustom make-backup-file-name-function nil |
2246 "A function to use instead of the default `make-backup-file-name'. | |
2247 A value of nil gives the default `make-backup-file-name' behaviour. | |
2248 | |
33703
af0f3f3533e8
(find-buffer-visiting): Compare all attributes before
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
33558
diff
changeset
|
2249 This could be buffer-local to do something special for specific |
32138 | 2250 files. If you define it, you may need to change `backup-file-name-p' |
2251 and `file-name-sans-versions' too. | |
2252 | |
2253 See also `backup-directory-alist'." | |
2254 :group 'backup | |
2255 :type '(choice (const :tag "Default" nil) | |
2256 (function :tag "Your function"))) | |
2257 | |
2258 (defcustom backup-directory-alist nil | |
2259 "Alist of filename patterns and backup directory names. | |
2260 Each element looks like (REGEXP . DIRECTORY). Backups of files with | |
2261 names matching REGEXP will be made in DIRECTORY. DIRECTORY may be | |
2262 relative or absolute. If it is absolute, so that all matching files | |
2263 are backed up into the same directory, the file names in this | |
2264 directory will be the full name of the file backed up with all | |
2265 directory separators changed to `!' to prevent clashes. This will not | |
2266 work correctly if your filesystem truncates the resulting name. | |
2267 | |
2268 For the common case of all backups going into one directory, the alist | |
2269 should contain a single element pairing \".\" with the appropriate | |
2270 directory name. | |
2271 | |
2272 If this variable is nil, or it fails to match a filename, the backup | |
2273 is made in the original file's directory. | |
2274 | |
2275 On MS-DOS filesystems without long names this variable is always | |
2276 ignored." | |
2277 :group 'backup | |
2278 :type '(repeat (cons (regexp :tag "Regexp macthing filename") | |
2279 (directory :tag "Backup directory name")))) | |
2280 | |
337 | 2281 (defun make-backup-file-name (file) |
2282 "Create the non-numeric backup file name for FILE. | |
32138 | 2283 Normally this will just be the file's name with `~' appended. |
2284 Customization hooks are provided as follows. | |
2285 | |
2286 If the variable `make-backup-file-name-function' is non-nil, its value | |
2287 should be a function which will be called with FILE as its argument; | |
2288 the resulting name is used. | |
2289 | |
2290 Otherwise a match for FILE is sought in `backup-directory-alist'; see | |
2291 the documentation of that variable. If the directory for the backup | |
2292 doesn't exist, it is created." | |
2293 (if make-backup-file-name-function | |
2294 (funcall make-backup-file-name-function file) | |
2295 (if (and (eq system-type 'ms-dos) | |
2296 (not (msdos-long-file-names))) | |
2297 (let ((fn (file-name-nondirectory file))) | |
2298 (concat (file-name-directory file) | |
2299 (or (and (string-match "\\`[^.]+\\'" fn) | |
2300 (concat (match-string 0 fn) ".~")) | |
2301 (and (string-match "\\`[^.]+\\.\\(..?\\)?" fn) | |
2302 (concat (match-string 0 fn) "~"))))) | |
2303 (concat (make-backup-file-name-1 file) "~")))) | |
2304 | |
2305 (defun make-backup-file-name-1 (file) | |
2306 "Subroutine of `make-backup-file-name' and `find-backup-file-name'." | |
2307 (let ((alist backup-directory-alist) | |
2308 elt backup-directory dir-sep-string) | |
2309 (while alist | |
2310 (setq elt (pop alist)) | |
2311 (if (string-match (car elt) file) | |
2312 (setq backup-directory (cdr elt) | |
2313 alist nil))) | |
2314 (if (null backup-directory) | |
2315 file | |
2316 (unless (file-exists-p backup-directory) | |
2317 (condition-case nil | |
2318 (make-directory backup-directory 'parents) | |
2319 (file-error file))) | |
2320 (if (file-name-absolute-p backup-directory) | |
2321 (progn | |
2322 (when (memq system-type '(windows-nt ms-dos)) | |
2323 ;; Normalize DOSish file names: convert all slashes to | |
2324 ;; directory-sep-char, downcase the drive letter, if any, | |
2325 ;; and replace the leading "x:" with "/drive_x". | |
2326 (or (file-name-absolute-p file) | |
2327 (setq file (expand-file-name file))) ; make defaults explicit | |
2328 ;; Replace any invalid file-name characters (for the | |
2329 ;; case of backing up remote files). | |
32783
9eb5cd921a28
(make-backup-file-name-1) [windowsnt, ms-dos]: Remove
Andrew Innes <andrewi@gnu.org>
parents:
32579
diff
changeset
|
2330 (setq file (expand-file-name (convert-standard-filename file))) |
32138 | 2331 (setq dir-sep-string (char-to-string directory-sep-char)) |
2332 (if (eq (aref file 1) ?:) | |
2333 (setq file (concat dir-sep-string | |
2334 "drive_" | |
2335 (char-to-string (downcase (aref file 0))) | |
2336 (if (eq (aref file 2) directory-sep-char) | |
2337 "" | |
2338 dir-sep-string) | |
2339 (substring file 2))))) | |
2340 ;; Make the name unique by substituting directory | |
2341 ;; separators. It may not really be worth bothering about | |
2342 ;; doubling `!'s in the original name... | |
2343 (expand-file-name | |
2344 (subst-char-in-string | |
2345 directory-sep-char ?! | |
2346 (replace-regexp-in-string "!" "!!" file)) | |
2347 backup-directory)) | |
2348 (expand-file-name (file-name-nondirectory file) | |
2349 (file-name-as-directory | |
2350 (expand-file-name backup-directory | |
2351 (file-name-directory file)))))))) | |
337 | 2352 |
2353 (defun backup-file-name-p (file) | |
2354 "Return non-nil if FILE is a backup file name (numeric or not). | |
2355 This is a separate function so you can redefine it for customization. | |
2356 You may need to redefine `file-name-sans-versions' as well." | |
13749
2015901ab992
(make-backup-file-name, backup-file-name-p): Use ~ even
Karl Heuer <kwzh@gnu.org>
parents:
13743
diff
changeset
|
2357 (string-match "~\\'" file)) |
337 | 2358 |
17734
bd60d4318daf
(backup-extract-version-start): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
17731
diff
changeset
|
2359 (defvar backup-extract-version-start) |
bd60d4318daf
(backup-extract-version-start): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
17731
diff
changeset
|
2360 |
890
bad1b9af86a1
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
854
diff
changeset
|
2361 ;; This is used in various files. |
24945 | 2362 ;; The usage of backup-extract-version-start is not very clean, |
2363 ;; but I can't see a good alternative, so as of now I am leaving it alone. | |
890
bad1b9af86a1
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
854
diff
changeset
|
2364 (defun backup-extract-version (fn) |
32138 | 2365 "Given the name of a numeric backup file, FN, return the backup number. |
17734
bd60d4318daf
(backup-extract-version-start): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
17731
diff
changeset
|
2366 Uses the free variable `backup-extract-version-start', whose value should be |
890
bad1b9af86a1
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
854
diff
changeset
|
2367 the index in the name where the version number begins." |
17734
bd60d4318daf
(backup-extract-version-start): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
17731
diff
changeset
|
2368 (if (and (string-match "[0-9]+~$" fn backup-extract-version-start) |
bd60d4318daf
(backup-extract-version-start): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
17731
diff
changeset
|
2369 (= (match-beginning 0) backup-extract-version-start)) |
bd60d4318daf
(backup-extract-version-start): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
17731
diff
changeset
|
2370 (string-to-int (substring fn backup-extract-version-start -1)) |
890
bad1b9af86a1
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
854
diff
changeset
|
2371 0)) |
bad1b9af86a1
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
854
diff
changeset
|
2372 |
337 | 2373 ;; I believe there is no need to alter this behavior for VMS; |
2374 ;; since backup files are not made on VMS, it should not get called. | |
2375 (defun find-backup-file-name (fn) | |
32138 | 2376 "Find a file name for a backup file FN, and suggestions for deletions. |
337 | 2377 Value is a list whose car is the name for the backup file |
32138 | 2378 and whose cdr is a list of old versions to consider deleting now. |
2379 If the value is nil, don't make a backup. | |
2380 Uses `backup-directory-alist' in the same way as does | |
2381 `make-backup-file-name'." | |
10408
c79720be7bd7
(find-backup-file-name): Run a file name handler.
Richard M. Stallman <rms@gnu.org>
parents:
10338
diff
changeset
|
2382 (let ((handler (find-file-name-handler fn 'find-backup-file-name))) |
c79720be7bd7
(find-backup-file-name): Run a file name handler.
Richard M. Stallman <rms@gnu.org>
parents:
10338
diff
changeset
|
2383 ;; Run a handler for this function so that ange-ftp can refuse to do it. |
c79720be7bd7
(find-backup-file-name): Run a file name handler.
Richard M. Stallman <rms@gnu.org>
parents:
10338
diff
changeset
|
2384 (if handler |
c79720be7bd7
(find-backup-file-name): Run a file name handler.
Richard M. Stallman <rms@gnu.org>
parents:
10338
diff
changeset
|
2385 (funcall handler 'find-backup-file-name fn) |
32253
e3c97d8f7a7e
(find-backup-file-name) [ms-dos]: If support for long
Eli Zaretskii <eliz@gnu.org>
parents:
32240
diff
changeset
|
2386 (if (or (eq version-control 'never) |
e3c97d8f7a7e
(find-backup-file-name) [ms-dos]: If support for long
Eli Zaretskii <eliz@gnu.org>
parents:
32240
diff
changeset
|
2387 ;; We don't support numbered backups on plain MS-DOS |
e3c97d8f7a7e
(find-backup-file-name) [ms-dos]: If support for long
Eli Zaretskii <eliz@gnu.org>
parents:
32240
diff
changeset
|
2388 ;; when long file names are unavailable. |
e3c97d8f7a7e
(find-backup-file-name) [ms-dos]: If support for long
Eli Zaretskii <eliz@gnu.org>
parents:
32240
diff
changeset
|
2389 (and (eq system-type 'ms-dos) |
e3c97d8f7a7e
(find-backup-file-name) [ms-dos]: If support for long
Eli Zaretskii <eliz@gnu.org>
parents:
32240
diff
changeset
|
2390 (not (msdos-long-file-names)))) |
337 | 2391 (list (make-backup-file-name fn)) |
32138 | 2392 (let* ((basic-name (make-backup-file-name-1 fn)) |
2393 (base-versions (concat (file-name-nondirectory basic-name) | |
2394 ".~")) | |
17734
bd60d4318daf
(backup-extract-version-start): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
17731
diff
changeset
|
2395 (backup-extract-version-start (length base-versions)) |
10408
c79720be7bd7
(find-backup-file-name): Run a file name handler.
Richard M. Stallman <rms@gnu.org>
parents:
10338
diff
changeset
|
2396 (high-water-mark 0) |
32138 | 2397 (number-to-delete 0) |
2398 possibilities deserve-versions-p versions) | |
10408
c79720be7bd7
(find-backup-file-name): Run a file name handler.
Richard M. Stallman <rms@gnu.org>
parents:
10338
diff
changeset
|
2399 (condition-case () |
c79720be7bd7
(find-backup-file-name): Run a file name handler.
Richard M. Stallman <rms@gnu.org>
parents:
10338
diff
changeset
|
2400 (setq possibilities (file-name-all-completions |
c79720be7bd7
(find-backup-file-name): Run a file name handler.
Richard M. Stallman <rms@gnu.org>
parents:
10338
diff
changeset
|
2401 base-versions |
32138 | 2402 (file-name-directory basic-name)) |
2403 versions (sort (mapcar #'backup-extract-version | |
2404 possibilities) | |
2405 #'<) | |
10408
c79720be7bd7
(find-backup-file-name): Run a file name handler.
Richard M. Stallman <rms@gnu.org>
parents:
10338
diff
changeset
|
2406 high-water-mark (apply 'max 0 versions) |
c79720be7bd7
(find-backup-file-name): Run a file name handler.
Richard M. Stallman <rms@gnu.org>
parents:
10338
diff
changeset
|
2407 deserve-versions-p (or version-control |
c79720be7bd7
(find-backup-file-name): Run a file name handler.
Richard M. Stallman <rms@gnu.org>
parents:
10338
diff
changeset
|
2408 (> high-water-mark 0)) |
c79720be7bd7
(find-backup-file-name): Run a file name handler.
Richard M. Stallman <rms@gnu.org>
parents:
10338
diff
changeset
|
2409 number-to-delete (- (length versions) |
32138 | 2410 kept-old-versions |
2411 kept-new-versions | |
2412 -1)) | |
2413 (file-error (setq possibilities nil))) | |
10408
c79720be7bd7
(find-backup-file-name): Run a file name handler.
Richard M. Stallman <rms@gnu.org>
parents:
10338
diff
changeset
|
2414 (if (not deserve-versions-p) |
32138 | 2415 (list (concat basic-name "~")) |
2416 (cons (format "%s.~%d~" basic-name (1+ high-water-mark)) | |
10408
c79720be7bd7
(find-backup-file-name): Run a file name handler.
Richard M. Stallman <rms@gnu.org>
parents:
10338
diff
changeset
|
2417 (if (and (> number-to-delete 0) |
c79720be7bd7
(find-backup-file-name): Run a file name handler.
Richard M. Stallman <rms@gnu.org>
parents:
10338
diff
changeset
|
2418 ;; Delete nothing if there is overflow |
c79720be7bd7
(find-backup-file-name): Run a file name handler.
Richard M. Stallman <rms@gnu.org>
parents:
10338
diff
changeset
|
2419 ;; in the number of versions to keep. |
c79720be7bd7
(find-backup-file-name): Run a file name handler.
Richard M. Stallman <rms@gnu.org>
parents:
10338
diff
changeset
|
2420 (>= (+ kept-new-versions kept-old-versions -1) 0)) |
32138 | 2421 (mapcar (lambda (n) |
2422 (format "%s.~%d~" basic-name n)) | |
10408
c79720be7bd7
(find-backup-file-name): Run a file name handler.
Richard M. Stallman <rms@gnu.org>
parents:
10338
diff
changeset
|
2423 (let ((v (nthcdr kept-old-versions versions))) |
c79720be7bd7
(find-backup-file-name): Run a file name handler.
Richard M. Stallman <rms@gnu.org>
parents:
10338
diff
changeset
|
2424 (rplacd (nthcdr (1- number-to-delete) v) ()) |
c79720be7bd7
(find-backup-file-name): Run a file name handler.
Richard M. Stallman <rms@gnu.org>
parents:
10338
diff
changeset
|
2425 v)))))))))) |
337 | 2426 |
2427 (defun file-nlinks (filename) | |
2428 "Return number of names file FILENAME has." | |
2429 (car (cdr (file-attributes filename)))) | |
1229
d4324e885a41
(file-relative-name): New function.
Roland McGrath <roland@gnu.org>
parents:
1212
diff
changeset
|
2430 |
d4324e885a41
(file-relative-name): New function.
Roland McGrath <roland@gnu.org>
parents:
1212
diff
changeset
|
2431 (defun file-relative-name (filename &optional directory) |
32138 | 2432 "Convert FILENAME to be relative to DIRECTORY (default: `default-directory'). |
17379
3147024a8918
(file-relative-name): Expand both args before
Richard M. Stallman <rms@gnu.org>
parents:
17256
diff
changeset
|
2433 This function returns a relative file name which is equivalent to FILENAME |
3147024a8918
(file-relative-name): Expand both args before
Richard M. Stallman <rms@gnu.org>
parents:
17256
diff
changeset
|
2434 when used with that default directory as the default. |
3147024a8918
(file-relative-name): Expand both args before
Richard M. Stallman <rms@gnu.org>
parents:
17256
diff
changeset
|
2435 If this is impossible (which can happen on MSDOS and Windows |
3147024a8918
(file-relative-name): Expand both args before
Richard M. Stallman <rms@gnu.org>
parents:
17256
diff
changeset
|
2436 when the file name and directory use different drive names) |
3147024a8918
(file-relative-name): Expand both args before
Richard M. Stallman <rms@gnu.org>
parents:
17256
diff
changeset
|
2437 then it returns FILENAME." |
16976
c7683cba14c7
(file-relative-name): Protect the match-data.
Erik Naggum <erik@naggum.no>
parents:
16971
diff
changeset
|
2438 (save-match-data |
17734
bd60d4318daf
(backup-extract-version-start): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
17731
diff
changeset
|
2439 (let ((fname (expand-file-name filename))) |
bd60d4318daf
(backup-extract-version-start): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
17731
diff
changeset
|
2440 (setq directory (file-name-as-directory |
bd60d4318daf
(backup-extract-version-start): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
17731
diff
changeset
|
2441 (expand-file-name (or directory default-directory)))) |
bd60d4318daf
(backup-extract-version-start): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
17731
diff
changeset
|
2442 ;; On Microsoft OSes, if FILENAME and DIRECTORY have different |
bd60d4318daf
(backup-extract-version-start): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
17731
diff
changeset
|
2443 ;; drive names, they can't be relative, so return the absolute name. |
bd60d4318daf
(backup-extract-version-start): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
17731
diff
changeset
|
2444 (if (and (or (eq system-type 'ms-dos) |
bd60d4318daf
(backup-extract-version-start): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
17731
diff
changeset
|
2445 (eq system-type 'windows-nt)) |
bd60d4318daf
(backup-extract-version-start): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
17731
diff
changeset
|
2446 (not (string-equal (substring fname 0 2) |
bd60d4318daf
(backup-extract-version-start): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
17731
diff
changeset
|
2447 (substring directory 0 2)))) |
bd60d4318daf
(backup-extract-version-start): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
17731
diff
changeset
|
2448 filename |
18466
535a18a6b623
(file-chase-links): When handling .., make newname absolute.
Richard M. Stallman <rms@gnu.org>
parents:
18340
diff
changeset
|
2449 (let ((ancestor ".") |
535a18a6b623
(file-chase-links): When handling .., make newname absolute.
Richard M. Stallman <rms@gnu.org>
parents:
18340
diff
changeset
|
2450 (fname-dir (file-name-as-directory fname))) |
535a18a6b623
(file-chase-links): When handling .., make newname absolute.
Richard M. Stallman <rms@gnu.org>
parents:
18340
diff
changeset
|
2451 (while (and (not (string-match (concat "^" (regexp-quote directory)) fname-dir)) |
535a18a6b623
(file-chase-links): When handling .., make newname absolute.
Richard M. Stallman <rms@gnu.org>
parents:
18340
diff
changeset
|
2452 (not (string-match (concat "^" (regexp-quote directory)) fname))) |
17734
bd60d4318daf
(backup-extract-version-start): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
17731
diff
changeset
|
2453 (setq directory (file-name-directory (substring directory 0 -1)) |
18466
535a18a6b623
(file-chase-links): When handling .., make newname absolute.
Richard M. Stallman <rms@gnu.org>
parents:
18340
diff
changeset
|
2454 ancestor (if (equal ancestor ".") |
535a18a6b623
(file-chase-links): When handling .., make newname absolute.
Richard M. Stallman <rms@gnu.org>
parents:
18340
diff
changeset
|
2455 ".." |
535a18a6b623
(file-chase-links): When handling .., make newname absolute.
Richard M. Stallman <rms@gnu.org>
parents:
18340
diff
changeset
|
2456 (concat "../" ancestor)))) |
535a18a6b623
(file-chase-links): When handling .., make newname absolute.
Richard M. Stallman <rms@gnu.org>
parents:
18340
diff
changeset
|
2457 ;; Now ancestor is empty, or .., or ../.., etc. |
535a18a6b623
(file-chase-links): When handling .., make newname absolute.
Richard M. Stallman <rms@gnu.org>
parents:
18340
diff
changeset
|
2458 (if (string-match (concat "^" (regexp-quote directory)) fname) |
535a18a6b623
(file-chase-links): When handling .., make newname absolute.
Richard M. Stallman <rms@gnu.org>
parents:
18340
diff
changeset
|
2459 ;; We matched within FNAME's directory part. |
535a18a6b623
(file-chase-links): When handling .., make newname absolute.
Richard M. Stallman <rms@gnu.org>
parents:
18340
diff
changeset
|
2460 ;; Add the rest of FNAME onto ANCESTOR. |
535a18a6b623
(file-chase-links): When handling .., make newname absolute.
Richard M. Stallman <rms@gnu.org>
parents:
18340
diff
changeset
|
2461 (let ((rest (substring fname (match-end 0)))) |
535a18a6b623
(file-chase-links): When handling .., make newname absolute.
Richard M. Stallman <rms@gnu.org>
parents:
18340
diff
changeset
|
2462 (if (and (equal ancestor ".") |
535a18a6b623
(file-chase-links): When handling .., make newname absolute.
Richard M. Stallman <rms@gnu.org>
parents:
18340
diff
changeset
|
2463 (not (equal rest ""))) |
535a18a6b623
(file-chase-links): When handling .., make newname absolute.
Richard M. Stallman <rms@gnu.org>
parents:
18340
diff
changeset
|
2464 ;; But don't bother with ANCESTOR if it would give us `./'. |
535a18a6b623
(file-chase-links): When handling .., make newname absolute.
Richard M. Stallman <rms@gnu.org>
parents:
18340
diff
changeset
|
2465 rest |
535a18a6b623
(file-chase-links): When handling .., make newname absolute.
Richard M. Stallman <rms@gnu.org>
parents:
18340
diff
changeset
|
2466 (concat (file-name-as-directory ancestor) rest))) |
535a18a6b623
(file-chase-links): When handling .., make newname absolute.
Richard M. Stallman <rms@gnu.org>
parents:
18340
diff
changeset
|
2467 ;; We matched FNAME's directory equivalent. |
535a18a6b623
(file-chase-links): When handling .., make newname absolute.
Richard M. Stallman <rms@gnu.org>
parents:
18340
diff
changeset
|
2468 ancestor)))))) |
337 | 2469 |
2470 (defun save-buffer (&optional args) | |
2471 "Save current buffer in visited file if modified. Versions described below. | |
2472 By default, makes the previous version into a backup file | |
2473 if previously requested or if this is the first save. | |
13823
881e5c4a01cb
(save-buffer): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
13749
diff
changeset
|
2474 With 1 \\[universal-argument], marks this version |
337 | 2475 to become a backup when the next save is done. |
13823
881e5c4a01cb
(save-buffer): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
13749
diff
changeset
|
2476 With 2 \\[universal-argument]'s, |
337 | 2477 unconditionally makes the previous version into a backup file. |
13823
881e5c4a01cb
(save-buffer): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
13749
diff
changeset
|
2478 With 3 \\[universal-argument]'s, marks this version |
881e5c4a01cb
(save-buffer): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
13749
diff
changeset
|
2479 to become a backup when the next save is done, |
881e5c4a01cb
(save-buffer): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
13749
diff
changeset
|
2480 and unconditionally makes the previous version into a backup file. |
881e5c4a01cb
(save-buffer): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
13749
diff
changeset
|
2481 |
23396
24d9060befa8
(save-buffer): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
23385
diff
changeset
|
2482 With argument of 0, never make the previous version into a backup file. |
337 | 2483 |
2484 If a file's name is FOO, the names of its numbered backup versions are | |
2485 FOO.~i~ for various integers i. A non-numbered backup file is called FOO~. | |
2486 Numeric backups (rather than FOO~) will be made if value of | |
2487 `version-control' is not the atom `never' and either there are already | |
2488 numeric versions of the file being backed up, or `version-control' is | |
2489 non-nil. | |
2490 We don't want excessive versions piling up, so there are variables | |
2491 `kept-old-versions', which tells Emacs how many oldest versions to keep, | |
2492 and `kept-new-versions', which tells how many newest versions to keep. | |
2493 Defaults are 2 old versions and 2 new. | |
2494 `dired-kept-versions' controls dired's clean-directory (.) command. | |
8157
14766204c0fe
(delete-old-versions): Var renamed from trim-versions-without-asking.
Richard M. Stallman <rms@gnu.org>
parents:
8151
diff
changeset
|
2495 If `delete-old-versions' is nil, system will query user |
22738
d35510185a2d
(find-file-noselect-1): Use kill-local-variable on
Richard M. Stallman <rms@gnu.org>
parents:
22582
diff
changeset
|
2496 before trimming versions. Otherwise it does it silently. |
d35510185a2d
(find-file-noselect-1): Use kill-local-variable on
Richard M. Stallman <rms@gnu.org>
parents:
22582
diff
changeset
|
2497 |
23396
24d9060befa8
(save-buffer): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
23385
diff
changeset
|
2498 If `vc-make-backup-files' is nil, which is the default, |
24d9060befa8
(save-buffer): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
23385
diff
changeset
|
2499 no backup files are made for files managed by version control. |
24d9060befa8
(save-buffer): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
23385
diff
changeset
|
2500 (This is because the version control system itself records previous versions.) |
24d9060befa8
(save-buffer): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
23385
diff
changeset
|
2501 |
22738
d35510185a2d
(find-file-noselect-1): Use kill-local-variable on
Richard M. Stallman <rms@gnu.org>
parents:
22582
diff
changeset
|
2502 See the subroutine `basic-save-buffer' for more information." |
337 | 2503 (interactive "p") |
2504 (let ((modp (buffer-modified-p)) | |
2505 (large (> (buffer-size) 50000)) | |
8462
c281b470d633
(save-buffer): Unconditionally make a backup with 2 or
Richard M. Stallman <rms@gnu.org>
parents:
8374
diff
changeset
|
2506 (make-backup-files (or (and make-backup-files (not (eq args 0))) |
c281b470d633
(save-buffer): Unconditionally make a backup with 2 or
Richard M. Stallman <rms@gnu.org>
parents:
8374
diff
changeset
|
2507 (memq args '(16 64))))) |
337 | 2508 (and modp (memq args '(16 64)) (setq buffer-backed-up nil)) |
2509 (if (and modp large) (message "Saving file %s..." (buffer-file-name))) | |
2510 (basic-save-buffer) | |
2511 (and modp (memq args '(4 64)) (setq buffer-backed-up nil)))) | |
2512 | |
2513 (defun delete-auto-save-file-if-necessary (&optional force) | |
2514 "Delete auto-save file for current buffer if `delete-auto-save-files' is t. | |
2515 Normally delete only if the file was written by this Emacs since | |
2516 the last real save, but optional arg FORCE non-nil means delete anyway." | |
2517 (and buffer-auto-save-file-name delete-auto-save-files | |
2518 (not (string= buffer-file-name buffer-auto-save-file-name)) | |
2519 (or force (recent-auto-save-p)) | |
2520 (progn | |
2521 (condition-case () | |
2522 (delete-file buffer-auto-save-file-name) | |
2523 (file-error nil)) | |
2524 (set-buffer-auto-saved)))) | |
2525 | |
24061 | 2526 (defvar auto-save-hook nil |
2527 "Normal hook run just before auto-saving.") | |
2528 | |
32138 | 2529 (defcustom after-save-hook nil |
2530 "Normal hook that is run after a buffer is saved to its file." | |
2531 :options '(executable-make-buffer-file-executable-if-script-p) | |
2532 :type 'hook | |
2533 :group 'files) | |
12963
337ba86981f5
(basic-save-buffer): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
12930
diff
changeset
|
2534 |
22026
237140fdea76
(save-buffer-coding-system): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
21773
diff
changeset
|
2535 (defvar save-buffer-coding-system nil |
237140fdea76
(save-buffer-coding-system): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
21773
diff
changeset
|
2536 "If non-nil, use this coding system for saving the buffer. |
237140fdea76
(save-buffer-coding-system): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
21773
diff
changeset
|
2537 More precisely, use this coding system in place of the |
237140fdea76
(save-buffer-coding-system): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
21773
diff
changeset
|
2538 value of `buffer-file-coding-system', when saving the buffer. |
237140fdea76
(save-buffer-coding-system): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
21773
diff
changeset
|
2539 Calling `write-region' for any purpose other than saving the buffer |
237140fdea76
(save-buffer-coding-system): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
21773
diff
changeset
|
2540 will still use `buffer-file-coding-system'; this variable has no effect |
237140fdea76
(save-buffer-coding-system): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
21773
diff
changeset
|
2541 in such cases.") |
237140fdea76
(save-buffer-coding-system): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
21773
diff
changeset
|
2542 |
22807
ff685e4dce0b
(basic-save-buffer-2): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22806
diff
changeset
|
2543 (make-variable-buffer-local 'save-buffer-coding-system) |
ff685e4dce0b
(basic-save-buffer-2): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22806
diff
changeset
|
2544 (put 'save-buffer-coding-system 'permanent-local t) |
ff685e4dce0b
(basic-save-buffer-2): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22806
diff
changeset
|
2545 |
337 | 2546 (defun basic-save-buffer () |
12963
337ba86981f5
(basic-save-buffer): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
12930
diff
changeset
|
2547 "Save the current buffer in its visited file, if it has been modified. |
22738
d35510185a2d
(find-file-noselect-1): Use kill-local-variable on
Richard M. Stallman <rms@gnu.org>
parents:
22582
diff
changeset
|
2548 The hooks `write-contents-hooks', `local-write-file-hooks' and |
d35510185a2d
(find-file-noselect-1): Use kill-local-variable on
Richard M. Stallman <rms@gnu.org>
parents:
22582
diff
changeset
|
2549 `write-file-hooks' get a chance to do the job of saving; if they do not, |
d35510185a2d
(find-file-noselect-1): Use kill-local-variable on
Richard M. Stallman <rms@gnu.org>
parents:
22582
diff
changeset
|
2550 then the buffer is saved in the visited file file in the usual way. |
d35510185a2d
(find-file-noselect-1): Use kill-local-variable on
Richard M. Stallman <rms@gnu.org>
parents:
22582
diff
changeset
|
2551 After saving the buffer, this function runs `after-save-hook'." |
337 | 2552 (interactive) |
21071
39d081df3643
(basic-save-buffer): Use save-current-buffer not save-excursion.
Richard M. Stallman <rms@gnu.org>
parents:
21069
diff
changeset
|
2553 (save-current-buffer |
10298
4b66ac3460df
(auto-mode-alist): Add entries for .cls files,
Richard M. Stallman <rms@gnu.org>
parents:
10236
diff
changeset
|
2554 ;; In an indirect buffer, save its base buffer instead. |
4b66ac3460df
(auto-mode-alist): Add entries for .cls files,
Richard M. Stallman <rms@gnu.org>
parents:
10236
diff
changeset
|
2555 (if (buffer-base-buffer) |
4b66ac3460df
(auto-mode-alist): Add entries for .cls files,
Richard M. Stallman <rms@gnu.org>
parents:
10236
diff
changeset
|
2556 (set-buffer (buffer-base-buffer))) |
4b66ac3460df
(auto-mode-alist): Add entries for .cls files,
Richard M. Stallman <rms@gnu.org>
parents:
10236
diff
changeset
|
2557 (if (buffer-modified-p) |
4b66ac3460df
(auto-mode-alist): Add entries for .cls files,
Richard M. Stallman <rms@gnu.org>
parents:
10236
diff
changeset
|
2558 (let ((recent-save (recent-auto-save-p)) |
4b66ac3460df
(auto-mode-alist): Add entries for .cls files,
Richard M. Stallman <rms@gnu.org>
parents:
10236
diff
changeset
|
2559 setmodes tempsetmodes) |
4b66ac3460df
(auto-mode-alist): Add entries for .cls files,
Richard M. Stallman <rms@gnu.org>
parents:
10236
diff
changeset
|
2560 ;; On VMS, rename file and buffer to get rid of version number. |
4b66ac3460df
(auto-mode-alist): Add entries for .cls files,
Richard M. Stallman <rms@gnu.org>
parents:
10236
diff
changeset
|
2561 (if (and (eq system-type 'vax-vms) |
4b66ac3460df
(auto-mode-alist): Add entries for .cls files,
Richard M. Stallman <rms@gnu.org>
parents:
10236
diff
changeset
|
2562 (not (string= buffer-file-name |
4b66ac3460df
(auto-mode-alist): Add entries for .cls files,
Richard M. Stallman <rms@gnu.org>
parents:
10236
diff
changeset
|
2563 (file-name-sans-versions buffer-file-name)))) |
4b66ac3460df
(auto-mode-alist): Add entries for .cls files,
Richard M. Stallman <rms@gnu.org>
parents:
10236
diff
changeset
|
2564 (let (buffer-new-name) |
4b66ac3460df
(auto-mode-alist): Add entries for .cls files,
Richard M. Stallman <rms@gnu.org>
parents:
10236
diff
changeset
|
2565 ;; Strip VMS version number before save. |
4b66ac3460df
(auto-mode-alist): Add entries for .cls files,
Richard M. Stallman <rms@gnu.org>
parents:
10236
diff
changeset
|
2566 (setq buffer-file-name |
4b66ac3460df
(auto-mode-alist): Add entries for .cls files,
Richard M. Stallman <rms@gnu.org>
parents:
10236
diff
changeset
|
2567 (file-name-sans-versions buffer-file-name)) |
4b66ac3460df
(auto-mode-alist): Add entries for .cls files,
Richard M. Stallman <rms@gnu.org>
parents:
10236
diff
changeset
|
2568 ;; Construct a (unique) buffer name to correspond. |
4b66ac3460df
(auto-mode-alist): Add entries for .cls files,
Richard M. Stallman <rms@gnu.org>
parents:
10236
diff
changeset
|
2569 (let ((buf (create-file-buffer (downcase buffer-file-name)))) |
4b66ac3460df
(auto-mode-alist): Add entries for .cls files,
Richard M. Stallman <rms@gnu.org>
parents:
10236
diff
changeset
|
2570 (setq buffer-new-name (buffer-name buf)) |
4b66ac3460df
(auto-mode-alist): Add entries for .cls files,
Richard M. Stallman <rms@gnu.org>
parents:
10236
diff
changeset
|
2571 (kill-buffer buf)) |
4b66ac3460df
(auto-mode-alist): Add entries for .cls files,
Richard M. Stallman <rms@gnu.org>
parents:
10236
diff
changeset
|
2572 (rename-buffer buffer-new-name))) |
4b66ac3460df
(auto-mode-alist): Add entries for .cls files,
Richard M. Stallman <rms@gnu.org>
parents:
10236
diff
changeset
|
2573 ;; If buffer has no file name, ask user for one. |
4b66ac3460df
(auto-mode-alist): Add entries for .cls files,
Richard M. Stallman <rms@gnu.org>
parents:
10236
diff
changeset
|
2574 (or buffer-file-name |
12895
4dbac3df0ec7
(basic-save-buffer): Confirm for overwriting old file
Richard M. Stallman <rms@gnu.org>
parents:
12852
diff
changeset
|
2575 (let ((filename |
4dbac3df0ec7
(basic-save-buffer): Confirm for overwriting old file
Richard M. Stallman <rms@gnu.org>
parents:
12852
diff
changeset
|
2576 (expand-file-name |
4dbac3df0ec7
(basic-save-buffer): Confirm for overwriting old file
Richard M. Stallman <rms@gnu.org>
parents:
12852
diff
changeset
|
2577 (read-file-name "File to save in: ") nil))) |
4dbac3df0ec7
(basic-save-buffer): Confirm for overwriting old file
Richard M. Stallman <rms@gnu.org>
parents:
12852
diff
changeset
|
2578 (and (file-exists-p filename) |
4dbac3df0ec7
(basic-save-buffer): Confirm for overwriting old file
Richard M. Stallman <rms@gnu.org>
parents:
12852
diff
changeset
|
2579 (or (y-or-n-p (format "File `%s' exists; overwrite? " |
4dbac3df0ec7
(basic-save-buffer): Confirm for overwriting old file
Richard M. Stallman <rms@gnu.org>
parents:
12852
diff
changeset
|
2580 filename)) |
4dbac3df0ec7
(basic-save-buffer): Confirm for overwriting old file
Richard M. Stallman <rms@gnu.org>
parents:
12852
diff
changeset
|
2581 (error "Canceled"))) |
4dbac3df0ec7
(basic-save-buffer): Confirm for overwriting old file
Richard M. Stallman <rms@gnu.org>
parents:
12852
diff
changeset
|
2582 (set-visited-file-name filename))) |
10298
4b66ac3460df
(auto-mode-alist): Add entries for .cls files,
Richard M. Stallman <rms@gnu.org>
parents:
10236
diff
changeset
|
2583 (or (verify-visited-file-modtime (current-buffer)) |
4b66ac3460df
(auto-mode-alist): Add entries for .cls files,
Richard M. Stallman <rms@gnu.org>
parents:
10236
diff
changeset
|
2584 (not (file-exists-p buffer-file-name)) |
4b66ac3460df
(auto-mode-alist): Add entries for .cls files,
Richard M. Stallman <rms@gnu.org>
parents:
10236
diff
changeset
|
2585 (yes-or-no-p |
4b66ac3460df
(auto-mode-alist): Add entries for .cls files,
Richard M. Stallman <rms@gnu.org>
parents:
10236
diff
changeset
|
2586 (format "%s has changed since visited or saved. Save anyway? " |
4b66ac3460df
(auto-mode-alist): Add entries for .cls files,
Richard M. Stallman <rms@gnu.org>
parents:
10236
diff
changeset
|
2587 (file-name-nondirectory buffer-file-name))) |
4b66ac3460df
(auto-mode-alist): Add entries for .cls files,
Richard M. Stallman <rms@gnu.org>
parents:
10236
diff
changeset
|
2588 (error "Save not confirmed")) |
4b66ac3460df
(auto-mode-alist): Add entries for .cls files,
Richard M. Stallman <rms@gnu.org>
parents:
10236
diff
changeset
|
2589 (save-restriction |
4b66ac3460df
(auto-mode-alist): Add entries for .cls files,
Richard M. Stallman <rms@gnu.org>
parents:
10236
diff
changeset
|
2590 (widen) |
21071
39d081df3643
(basic-save-buffer): Use save-current-buffer not save-excursion.
Richard M. Stallman <rms@gnu.org>
parents:
21069
diff
changeset
|
2591 (save-excursion |
39d081df3643
(basic-save-buffer): Use save-current-buffer not save-excursion.
Richard M. Stallman <rms@gnu.org>
parents:
21069
diff
changeset
|
2592 (and (> (point-max) 1) |
33558
786f1533a10f
(basic-save-buffer): Don't add a newline if
Gerd Moellmann <gerd@gnu.org>
parents:
33105
diff
changeset
|
2593 (not find-file-literally) |
21071
39d081df3643
(basic-save-buffer): Use save-current-buffer not save-excursion.
Richard M. Stallman <rms@gnu.org>
parents:
21069
diff
changeset
|
2594 (/= (char-after (1- (point-max))) ?\n) |
39d081df3643
(basic-save-buffer): Use save-current-buffer not save-excursion.
Richard M. Stallman <rms@gnu.org>
parents:
21069
diff
changeset
|
2595 (not (and (eq selective-display t) |
39d081df3643
(basic-save-buffer): Use save-current-buffer not save-excursion.
Richard M. Stallman <rms@gnu.org>
parents:
21069
diff
changeset
|
2596 (= (char-after (1- (point-max))) ?\r))) |
39d081df3643
(basic-save-buffer): Use save-current-buffer not save-excursion.
Richard M. Stallman <rms@gnu.org>
parents:
21069
diff
changeset
|
2597 (or (eq require-final-newline t) |
39d081df3643
(basic-save-buffer): Use save-current-buffer not save-excursion.
Richard M. Stallman <rms@gnu.org>
parents:
21069
diff
changeset
|
2598 (and require-final-newline |
39d081df3643
(basic-save-buffer): Use save-current-buffer not save-excursion.
Richard M. Stallman <rms@gnu.org>
parents:
21069
diff
changeset
|
2599 (y-or-n-p |
39d081df3643
(basic-save-buffer): Use save-current-buffer not save-excursion.
Richard M. Stallman <rms@gnu.org>
parents:
21069
diff
changeset
|
2600 (format "Buffer %s does not end in newline. Add one? " |
39d081df3643
(basic-save-buffer): Use save-current-buffer not save-excursion.
Richard M. Stallman <rms@gnu.org>
parents:
21069
diff
changeset
|
2601 (buffer-name))))) |
39d081df3643
(basic-save-buffer): Use save-current-buffer not save-excursion.
Richard M. Stallman <rms@gnu.org>
parents:
21069
diff
changeset
|
2602 (save-excursion |
39d081df3643
(basic-save-buffer): Use save-current-buffer not save-excursion.
Richard M. Stallman <rms@gnu.org>
parents:
21069
diff
changeset
|
2603 (goto-char (point-max)) |
39d081df3643
(basic-save-buffer): Use save-current-buffer not save-excursion.
Richard M. Stallman <rms@gnu.org>
parents:
21069
diff
changeset
|
2604 (insert ?\n)))) |
32129
3cd2e815deaa
(basic-save-buffer): Call vc-before-save before saving.
André Spiegel <spiegel@gnu.org>
parents:
32030
diff
changeset
|
2605 ;; Support VC version backups. |
3cd2e815deaa
(basic-save-buffer): Call vc-before-save before saving.
André Spiegel <spiegel@gnu.org>
parents:
32030
diff
changeset
|
2606 (vc-before-save) |
10298
4b66ac3460df
(auto-mode-alist): Add entries for .cls files,
Richard M. Stallman <rms@gnu.org>
parents:
10236
diff
changeset
|
2607 (or (run-hook-with-args-until-success 'write-contents-hooks) |
4b66ac3460df
(auto-mode-alist): Add entries for .cls files,
Richard M. Stallman <rms@gnu.org>
parents:
10236
diff
changeset
|
2608 (run-hook-with-args-until-success 'local-write-file-hooks) |
4b66ac3460df
(auto-mode-alist): Add entries for .cls files,
Richard M. Stallman <rms@gnu.org>
parents:
10236
diff
changeset
|
2609 (run-hook-with-args-until-success 'write-file-hooks) |
4b66ac3460df
(auto-mode-alist): Add entries for .cls files,
Richard M. Stallman <rms@gnu.org>
parents:
10236
diff
changeset
|
2610 ;; If a hook returned t, file is already "written". |
4b66ac3460df
(auto-mode-alist): Add entries for .cls files,
Richard M. Stallman <rms@gnu.org>
parents:
10236
diff
changeset
|
2611 ;; Otherwise, write it the usual way now. |
4b66ac3460df
(auto-mode-alist): Add entries for .cls files,
Richard M. Stallman <rms@gnu.org>
parents:
10236
diff
changeset
|
2612 (setq setmodes (basic-save-buffer-1))) |
20093
c8448efca727
(basic-save-buffer): Set buffer-file-coding-system to
Karl Heuer <kwzh@gnu.org>
parents:
20018
diff
changeset
|
2613 ;; Now we have saved the current buffer. Let's make sure |
c8448efca727
(basic-save-buffer): Set buffer-file-coding-system to
Karl Heuer <kwzh@gnu.org>
parents:
20018
diff
changeset
|
2614 ;; that buffer-file-coding-system is fixed to what |
c8448efca727
(basic-save-buffer): Set buffer-file-coding-system to
Karl Heuer <kwzh@gnu.org>
parents:
20018
diff
changeset
|
2615 ;; actually used for saving by binding it locally. |
22026
237140fdea76
(save-buffer-coding-system): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
21773
diff
changeset
|
2616 (if save-buffer-coding-system |
237140fdea76
(save-buffer-coding-system): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
21773
diff
changeset
|
2617 (setq save-buffer-coding-system last-coding-system-used) |
237140fdea76
(save-buffer-coding-system): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
21773
diff
changeset
|
2618 (setq buffer-file-coding-system last-coding-system-used)) |
13326
4e1b078121ad
(set-visited-file-name, basic-save-buffer):
Richard M. Stallman <rms@gnu.org>
parents:
13289
diff
changeset
|
2619 (setq buffer-file-number |
4e1b078121ad
(set-visited-file-name, basic-save-buffer):
Richard M. Stallman <rms@gnu.org>
parents:
13289
diff
changeset
|
2620 (nthcdr 10 (file-attributes buffer-file-name))) |
10298
4b66ac3460df
(auto-mode-alist): Add entries for .cls files,
Richard M. Stallman <rms@gnu.org>
parents:
10236
diff
changeset
|
2621 (if setmodes |
4b66ac3460df
(auto-mode-alist): Add entries for .cls files,
Richard M. Stallman <rms@gnu.org>
parents:
10236
diff
changeset
|
2622 (condition-case () |
4b66ac3460df
(auto-mode-alist): Add entries for .cls files,
Richard M. Stallman <rms@gnu.org>
parents:
10236
diff
changeset
|
2623 (set-file-modes buffer-file-name setmodes) |
4b66ac3460df
(auto-mode-alist): Add entries for .cls files,
Richard M. Stallman <rms@gnu.org>
parents:
10236
diff
changeset
|
2624 (error nil)))) |
4b66ac3460df
(auto-mode-alist): Add entries for .cls files,
Richard M. Stallman <rms@gnu.org>
parents:
10236
diff
changeset
|
2625 ;; If the auto-save file was recent before this command, |
4b66ac3460df
(auto-mode-alist): Add entries for .cls files,
Richard M. Stallman <rms@gnu.org>
parents:
10236
diff
changeset
|
2626 ;; delete it now. |
4b66ac3460df
(auto-mode-alist): Add entries for .cls files,
Richard M. Stallman <rms@gnu.org>
parents:
10236
diff
changeset
|
2627 (delete-auto-save-file-if-necessary recent-save) |
12930
0fac64b0452e
(basic-save-buffer): Call vc-after-save.
Richard M. Stallman <rms@gnu.org>
parents:
12929
diff
changeset
|
2628 ;; Support VC `implicit' locking. |
0fac64b0452e
(basic-save-buffer): Call vc-after-save.
Richard M. Stallman <rms@gnu.org>
parents:
12929
diff
changeset
|
2629 (vc-after-save) |
10298
4b66ac3460df
(auto-mode-alist): Add entries for .cls files,
Richard M. Stallman <rms@gnu.org>
parents:
10236
diff
changeset
|
2630 (run-hooks 'after-save-hook)) |
4b66ac3460df
(auto-mode-alist): Add entries for .cls files,
Richard M. Stallman <rms@gnu.org>
parents:
10236
diff
changeset
|
2631 (message "(No changes need to be saved)")))) |
337 | 2632 |
6574
f0e1ed0e82a7
(basic-save-buffer-1): New subroutine, broken out of basic-save-buffer.
Richard M. Stallman <rms@gnu.org>
parents:
6546
diff
changeset
|
2633 ;; This does the "real job" of writing a buffer into its visited file |
f0e1ed0e82a7
(basic-save-buffer-1): New subroutine, broken out of basic-save-buffer.
Richard M. Stallman <rms@gnu.org>
parents:
6546
diff
changeset
|
2634 ;; and making a backup file. This is what is normally done |
f0e1ed0e82a7
(basic-save-buffer-1): New subroutine, broken out of basic-save-buffer.
Richard M. Stallman <rms@gnu.org>
parents:
6546
diff
changeset
|
2635 ;; but inhibited if one of write-file-hooks returns non-nil. |
f0e1ed0e82a7
(basic-save-buffer-1): New subroutine, broken out of basic-save-buffer.
Richard M. Stallman <rms@gnu.org>
parents:
6546
diff
changeset
|
2636 ;; It returns a value to store in setmodes. |
f0e1ed0e82a7
(basic-save-buffer-1): New subroutine, broken out of basic-save-buffer.
Richard M. Stallman <rms@gnu.org>
parents:
6546
diff
changeset
|
2637 (defun basic-save-buffer-1 () |
22807
ff685e4dce0b
(basic-save-buffer-2): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22806
diff
changeset
|
2638 (if save-buffer-coding-system |
ff685e4dce0b
(basic-save-buffer-2): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22806
diff
changeset
|
2639 (let ((coding-system-for-write save-buffer-coding-system)) |
ff685e4dce0b
(basic-save-buffer-2): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22806
diff
changeset
|
2640 (basic-save-buffer-2)) |
ff685e4dce0b
(basic-save-buffer-2): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22806
diff
changeset
|
2641 (basic-save-buffer-2))) |
ff685e4dce0b
(basic-save-buffer-2): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22806
diff
changeset
|
2642 |
ff685e4dce0b
(basic-save-buffer-2): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22806
diff
changeset
|
2643 (defun basic-save-buffer-2 () |
ff685e4dce0b
(basic-save-buffer-2): New function.
Richard M. Stallman <rms@gnu.org>
parents:
22806
diff
changeset
|
2644 (let (tempsetmodes setmodes) |
6574
f0e1ed0e82a7
(basic-save-buffer-1): New subroutine, broken out of basic-save-buffer.
Richard M. Stallman <rms@gnu.org>
parents:
6546
diff
changeset
|
2645 (if (not (file-writable-p buffer-file-name)) |
f0e1ed0e82a7
(basic-save-buffer-1): New subroutine, broken out of basic-save-buffer.
Richard M. Stallman <rms@gnu.org>
parents:
6546
diff
changeset
|
2646 (let ((dir (file-name-directory buffer-file-name))) |
f0e1ed0e82a7
(basic-save-buffer-1): New subroutine, broken out of basic-save-buffer.
Richard M. Stallman <rms@gnu.org>
parents:
6546
diff
changeset
|
2647 (if (not (file-directory-p dir)) |
18819
881a46c98ddf
(set-auto-mode): If -*- line specifies a mode,
Richard M. Stallman <rms@gnu.org>
parents:
18676
diff
changeset
|
2648 (if (file-exists-p dir) |
881a46c98ddf
(set-auto-mode): If -*- line specifies a mode,
Richard M. Stallman <rms@gnu.org>
parents:
18676
diff
changeset
|
2649 (error "%s is not a directory" dir) |
19145
68b212facca8
(basic-save-buffer-1): Add missing argument for error.
Richard M. Stallman <rms@gnu.org>
parents:
19122
diff
changeset
|
2650 (error "%s: no such directory" buffer-file-name)) |
6574
f0e1ed0e82a7
(basic-save-buffer-1): New subroutine, broken out of basic-save-buffer.
Richard M. Stallman <rms@gnu.org>
parents:
6546
diff
changeset
|
2651 (if (not (file-exists-p buffer-file-name)) |
f0e1ed0e82a7
(basic-save-buffer-1): New subroutine, broken out of basic-save-buffer.
Richard M. Stallman <rms@gnu.org>
parents:
6546
diff
changeset
|
2652 (error "Directory %s write-protected" dir) |
f0e1ed0e82a7
(basic-save-buffer-1): New subroutine, broken out of basic-save-buffer.
Richard M. Stallman <rms@gnu.org>
parents:
6546
diff
changeset
|
2653 (if (yes-or-no-p |
f0e1ed0e82a7
(basic-save-buffer-1): New subroutine, broken out of basic-save-buffer.
Richard M. Stallman <rms@gnu.org>
parents:
6546
diff
changeset
|
2654 (format "File %s is write-protected; try to save anyway? " |
f0e1ed0e82a7
(basic-save-buffer-1): New subroutine, broken out of basic-save-buffer.
Richard M. Stallman <rms@gnu.org>
parents:
6546
diff
changeset
|
2655 (file-name-nondirectory |
f0e1ed0e82a7
(basic-save-buffer-1): New subroutine, broken out of basic-save-buffer.
Richard M. Stallman <rms@gnu.org>
parents:
6546
diff
changeset
|
2656 buffer-file-name))) |
f0e1ed0e82a7
(basic-save-buffer-1): New subroutine, broken out of basic-save-buffer.
Richard M. Stallman <rms@gnu.org>
parents:
6546
diff
changeset
|
2657 (setq tempsetmodes t) |
f0e1ed0e82a7
(basic-save-buffer-1): New subroutine, broken out of basic-save-buffer.
Richard M. Stallman <rms@gnu.org>
parents:
6546
diff
changeset
|
2658 (error "Attempt to save to a file which you aren't allowed to write")))))) |
f0e1ed0e82a7
(basic-save-buffer-1): New subroutine, broken out of basic-save-buffer.
Richard M. Stallman <rms@gnu.org>
parents:
6546
diff
changeset
|
2659 (or buffer-backed-up |
f0e1ed0e82a7
(basic-save-buffer-1): New subroutine, broken out of basic-save-buffer.
Richard M. Stallman <rms@gnu.org>
parents:
6546
diff
changeset
|
2660 (setq setmodes (backup-buffer))) |
13832
44e936e550ae
(save-some-buffers): Don't give message if we queried.
Roland McGrath <roland@gnu.org>
parents:
13823
diff
changeset
|
2661 (let ((dir (file-name-directory buffer-file-name))) |
8362
87e1b76bbd6b
(set-auto-mode): Shorten scope of case-fold-search binding.
Richard M. Stallman <rms@gnu.org>
parents:
8251
diff
changeset
|
2662 (if (and file-precious-flag |
87e1b76bbd6b
(set-auto-mode): Shorten scope of case-fold-search binding.
Richard M. Stallman <rms@gnu.org>
parents:
8251
diff
changeset
|
2663 (file-writable-p dir)) |
87e1b76bbd6b
(set-auto-mode): Shorten scope of case-fold-search binding.
Richard M. Stallman <rms@gnu.org>
parents:
8251
diff
changeset
|
2664 ;; If file is precious, write temp name, then rename it. |
87e1b76bbd6b
(set-auto-mode): Shorten scope of case-fold-search binding.
Richard M. Stallman <rms@gnu.org>
parents:
8251
diff
changeset
|
2665 ;; This requires write access to the containing dir, |
87e1b76bbd6b
(set-auto-mode): Shorten scope of case-fold-search binding.
Richard M. Stallman <rms@gnu.org>
parents:
8251
diff
changeset
|
2666 ;; which is why we don't try it if we don't have that access. |
87e1b76bbd6b
(set-auto-mode): Shorten scope of case-fold-search binding.
Richard M. Stallman <rms@gnu.org>
parents:
8251
diff
changeset
|
2667 (let ((realname buffer-file-name) |
8937
065d01c10c78
(basic-save-buffer-1): If writing temp file fails
Richard M. Stallman <rms@gnu.org>
parents:
8908
diff
changeset
|
2668 tempname temp nogood i succeed |
065d01c10c78
(basic-save-buffer-1): If writing temp file fails
Richard M. Stallman <rms@gnu.org>
parents:
8908
diff
changeset
|
2669 (old-modtime (visited-file-modtime))) |
8362
87e1b76bbd6b
(set-auto-mode): Shorten scope of case-fold-search binding.
Richard M. Stallman <rms@gnu.org>
parents:
8251
diff
changeset
|
2670 (setq i 0) |
87e1b76bbd6b
(set-auto-mode): Shorten scope of case-fold-search binding.
Richard M. Stallman <rms@gnu.org>
parents:
8251
diff
changeset
|
2671 (setq nogood t) |
87e1b76bbd6b
(set-auto-mode): Shorten scope of case-fold-search binding.
Richard M. Stallman <rms@gnu.org>
parents:
8251
diff
changeset
|
2672 ;; Find the temporary name to write under. |
87e1b76bbd6b
(set-auto-mode): Shorten scope of case-fold-search binding.
Richard M. Stallman <rms@gnu.org>
parents:
8251
diff
changeset
|
2673 (while nogood |
13903
936c8364e15a
(abbrev-file-name): Drive letter can go beyond `Z' under MS-DOS/Novell.
Richard M. Stallman <rms@gnu.org>
parents:
13885
diff
changeset
|
2674 (setq tempname (format |
15269
b6381b3a6c99
(make-backup-file-name): Check msdos-long-file-names.
Karl Heuer <kwzh@gnu.org>
parents:
15056
diff
changeset
|
2675 (if (and (eq system-type 'ms-dos) |
b6381b3a6c99
(make-backup-file-name): Check msdos-long-file-names.
Karl Heuer <kwzh@gnu.org>
parents:
15056
diff
changeset
|
2676 (not (msdos-long-file-names))) |
13903
936c8364e15a
(abbrev-file-name): Drive letter can go beyond `Z' under MS-DOS/Novell.
Richard M. Stallman <rms@gnu.org>
parents:
13885
diff
changeset
|
2677 "%s#%d.tm#" ; MSDOS limits files to 8+3 |
32138 | 2678 (if (memq system-type '(vax-vms axp-vms)) |
2679 "%s$tmp$%d" | |
2680 "%s#tmp#%d")) | |
13903
936c8364e15a
(abbrev-file-name): Drive letter can go beyond `Z' under MS-DOS/Novell.
Richard M. Stallman <rms@gnu.org>
parents:
13885
diff
changeset
|
2681 dir i)) |
8362
87e1b76bbd6b
(set-auto-mode): Shorten scope of case-fold-search binding.
Richard M. Stallman <rms@gnu.org>
parents:
8251
diff
changeset
|
2682 (setq nogood (file-exists-p tempname)) |
87e1b76bbd6b
(set-auto-mode): Shorten scope of case-fold-search binding.
Richard M. Stallman <rms@gnu.org>
parents:
8251
diff
changeset
|
2683 (setq i (1+ i))) |
87e1b76bbd6b
(set-auto-mode): Shorten scope of case-fold-search binding.
Richard M. Stallman <rms@gnu.org>
parents:
8251
diff
changeset
|
2684 (unwind-protect |
87e1b76bbd6b
(set-auto-mode): Shorten scope of case-fold-search binding.
Richard M. Stallman <rms@gnu.org>
parents:
8251
diff
changeset
|
2685 (progn (clear-visited-file-modtime) |
87e1b76bbd6b
(set-auto-mode): Shorten scope of case-fold-search binding.
Richard M. Stallman <rms@gnu.org>
parents:
8251
diff
changeset
|
2686 (write-region (point-min) (point-max) |
12852
0b04a441c06d
(basic-save-buffer-1): Pass new arg to write-region.
Richard M. Stallman <rms@gnu.org>
parents:
12850
diff
changeset
|
2687 tempname nil realname |
0b04a441c06d
(basic-save-buffer-1): Pass new arg to write-region.
Richard M. Stallman <rms@gnu.org>
parents:
12850
diff
changeset
|
2688 buffer-file-truename) |
8362
87e1b76bbd6b
(set-auto-mode): Shorten scope of case-fold-search binding.
Richard M. Stallman <rms@gnu.org>
parents:
8251
diff
changeset
|
2689 (setq succeed t)) |
87e1b76bbd6b
(set-auto-mode): Shorten scope of case-fold-search binding.
Richard M. Stallman <rms@gnu.org>
parents:
8251
diff
changeset
|
2690 ;; If writing the temp file fails, |
87e1b76bbd6b
(set-auto-mode): Shorten scope of case-fold-search binding.
Richard M. Stallman <rms@gnu.org>
parents:
8251
diff
changeset
|
2691 ;; delete the temp file. |
13832
44e936e550ae
(save-some-buffers): Don't give message if we queried.
Roland McGrath <roland@gnu.org>
parents:
13823
diff
changeset
|
2692 (or succeed |
8937
065d01c10c78
(basic-save-buffer-1): If writing temp file fails
Richard M. Stallman <rms@gnu.org>
parents:
8908
diff
changeset
|
2693 (progn |
065d01c10c78
(basic-save-buffer-1): If writing temp file fails
Richard M. Stallman <rms@gnu.org>
parents:
8908
diff
changeset
|
2694 (delete-file tempname) |
065d01c10c78
(basic-save-buffer-1): If writing temp file fails
Richard M. Stallman <rms@gnu.org>
parents:
8908
diff
changeset
|
2695 (set-visited-file-modtime old-modtime)))) |
8362
87e1b76bbd6b
(set-auto-mode): Shorten scope of case-fold-search binding.
Richard M. Stallman <rms@gnu.org>
parents:
8251
diff
changeset
|
2696 ;; Since we have created an entirely new file |
87e1b76bbd6b
(set-auto-mode): Shorten scope of case-fold-search binding.
Richard M. Stallman <rms@gnu.org>
parents:
8251
diff
changeset
|
2697 ;; and renamed it, make sure it gets the |
87e1b76bbd6b
(set-auto-mode): Shorten scope of case-fold-search binding.
Richard M. Stallman <rms@gnu.org>
parents:
8251
diff
changeset
|
2698 ;; right permission bits set. |
87e1b76bbd6b
(set-auto-mode): Shorten scope of case-fold-search binding.
Richard M. Stallman <rms@gnu.org>
parents:
8251
diff
changeset
|
2699 (setq setmodes (file-modes buffer-file-name)) |
87e1b76bbd6b
(set-auto-mode): Shorten scope of case-fold-search binding.
Richard M. Stallman <rms@gnu.org>
parents:
8251
diff
changeset
|
2700 ;; We succeeded in writing the temp file, |
87e1b76bbd6b
(set-auto-mode): Shorten scope of case-fold-search binding.
Richard M. Stallman <rms@gnu.org>
parents:
8251
diff
changeset
|
2701 ;; so rename it. |
87e1b76bbd6b
(set-auto-mode): Shorten scope of case-fold-search binding.
Richard M. Stallman <rms@gnu.org>
parents:
8251
diff
changeset
|
2702 (rename-file tempname buffer-file-name t)) |
87e1b76bbd6b
(set-auto-mode): Shorten scope of case-fold-search binding.
Richard M. Stallman <rms@gnu.org>
parents:
8251
diff
changeset
|
2703 ;; If file not writable, see if we can make it writable |
87e1b76bbd6b
(set-auto-mode): Shorten scope of case-fold-search binding.
Richard M. Stallman <rms@gnu.org>
parents:
8251
diff
changeset
|
2704 ;; temporarily while we write it. |
87e1b76bbd6b
(set-auto-mode): Shorten scope of case-fold-search binding.
Richard M. Stallman <rms@gnu.org>
parents:
8251
diff
changeset
|
2705 ;; But no need to do so if we have just backed it up |
87e1b76bbd6b
(set-auto-mode): Shorten scope of case-fold-search binding.
Richard M. Stallman <rms@gnu.org>
parents:
8251
diff
changeset
|
2706 ;; (setmodes is set) because that says we're superseding. |
87e1b76bbd6b
(set-auto-mode): Shorten scope of case-fold-search binding.
Richard M. Stallman <rms@gnu.org>
parents:
8251
diff
changeset
|
2707 (cond ((and tempsetmodes (not setmodes)) |
87e1b76bbd6b
(set-auto-mode): Shorten scope of case-fold-search binding.
Richard M. Stallman <rms@gnu.org>
parents:
8251
diff
changeset
|
2708 ;; Change the mode back, after writing. |
87e1b76bbd6b
(set-auto-mode): Shorten scope of case-fold-search binding.
Richard M. Stallman <rms@gnu.org>
parents:
8251
diff
changeset
|
2709 (setq setmodes (file-modes buffer-file-name)) |
32138 | 2710 (set-file-modes buffer-file-name (logior setmodes 128)))) |
8362
87e1b76bbd6b
(set-auto-mode): Shorten scope of case-fold-search binding.
Richard M. Stallman <rms@gnu.org>
parents:
8251
diff
changeset
|
2711 (write-region (point-min) (point-max) |
12852
0b04a441c06d
(basic-save-buffer-1): Pass new arg to write-region.
Richard M. Stallman <rms@gnu.org>
parents:
12850
diff
changeset
|
2712 buffer-file-name nil t buffer-file-truename))) |
6574
f0e1ed0e82a7
(basic-save-buffer-1): New subroutine, broken out of basic-save-buffer.
Richard M. Stallman <rms@gnu.org>
parents:
6546
diff
changeset
|
2713 setmodes)) |
f0e1ed0e82a7
(basic-save-buffer-1): New subroutine, broken out of basic-save-buffer.
Richard M. Stallman <rms@gnu.org>
parents:
6546
diff
changeset
|
2714 |
32138 | 2715 (defun save-some-buffers (&optional arg pred) |
337 | 2716 "Save some modified file-visiting buffers. Asks user about each one. |
423 | 2717 Optional argument (the prefix) non-nil means save all with no questions. |
32138 | 2718 Optional second argument PRED determines which buffers are considered: |
2719 If PRED is nil, all the file-visiting buffers are considered. | |
2720 If PRED is t, then certain non-file buffers will also be considered. | |
2721 If PRED is a zero-argument function, it indicates for each buffer whether | |
2722 to consider it or not when called with that buffer current." | |
337 | 2723 (interactive "P") |
891 | 2724 (save-window-excursion |
13832
44e936e550ae
(save-some-buffers): Don't give message if we queried.
Roland McGrath <roland@gnu.org>
parents:
13823
diff
changeset
|
2725 (let* ((queried nil) |
44e936e550ae
(save-some-buffers): Don't give message if we queried.
Roland McGrath <roland@gnu.org>
parents:
13823
diff
changeset
|
2726 (files-done |
44e936e550ae
(save-some-buffers): Don't give message if we queried.
Roland McGrath <roland@gnu.org>
parents:
13823
diff
changeset
|
2727 (map-y-or-n-p |
44e936e550ae
(save-some-buffers): Don't give message if we queried.
Roland McGrath <roland@gnu.org>
parents:
13823
diff
changeset
|
2728 (function |
44e936e550ae
(save-some-buffers): Don't give message if we queried.
Roland McGrath <roland@gnu.org>
parents:
13823
diff
changeset
|
2729 (lambda (buffer) |
44e936e550ae
(save-some-buffers): Don't give message if we queried.
Roland McGrath <roland@gnu.org>
parents:
13823
diff
changeset
|
2730 (and (buffer-modified-p buffer) |
44e936e550ae
(save-some-buffers): Don't give message if we queried.
Roland McGrath <roland@gnu.org>
parents:
13823
diff
changeset
|
2731 (not (buffer-base-buffer buffer)) |
44e936e550ae
(save-some-buffers): Don't give message if we queried.
Roland McGrath <roland@gnu.org>
parents:
13823
diff
changeset
|
2732 (or |
44e936e550ae
(save-some-buffers): Don't give message if we queried.
Roland McGrath <roland@gnu.org>
parents:
13823
diff
changeset
|
2733 (buffer-file-name buffer) |
32138 | 2734 (and pred |
13832
44e936e550ae
(save-some-buffers): Don't give message if we queried.
Roland McGrath <roland@gnu.org>
parents:
13823
diff
changeset
|
2735 (progn |
44e936e550ae
(save-some-buffers): Don't give message if we queried.
Roland McGrath <roland@gnu.org>
parents:
13823
diff
changeset
|
2736 (set-buffer buffer) |
44e936e550ae
(save-some-buffers): Don't give message if we queried.
Roland McGrath <roland@gnu.org>
parents:
13823
diff
changeset
|
2737 (and buffer-offer-save (> (buffer-size) 0))))) |
32138 | 2738 (or (not (functionp pred)) |
2739 (with-current-buffer buffer (funcall pred))) | |
13832
44e936e550ae
(save-some-buffers): Don't give message if we queried.
Roland McGrath <roland@gnu.org>
parents:
13823
diff
changeset
|
2740 (if arg |
44e936e550ae
(save-some-buffers): Don't give message if we queried.
Roland McGrath <roland@gnu.org>
parents:
13823
diff
changeset
|
2741 t |
44e936e550ae
(save-some-buffers): Don't give message if we queried.
Roland McGrath <roland@gnu.org>
parents:
13823
diff
changeset
|
2742 (setq queried t) |
44e936e550ae
(save-some-buffers): Don't give message if we queried.
Roland McGrath <roland@gnu.org>
parents:
13823
diff
changeset
|
2743 (if (buffer-file-name buffer) |
44e936e550ae
(save-some-buffers): Don't give message if we queried.
Roland McGrath <roland@gnu.org>
parents:
13823
diff
changeset
|
2744 (format "Save file %s? " |
44e936e550ae
(save-some-buffers): Don't give message if we queried.
Roland McGrath <roland@gnu.org>
parents:
13823
diff
changeset
|
2745 (buffer-file-name buffer)) |
44e936e550ae
(save-some-buffers): Don't give message if we queried.
Roland McGrath <roland@gnu.org>
parents:
13823
diff
changeset
|
2746 (format "Save buffer %s? " |
44e936e550ae
(save-some-buffers): Don't give message if we queried.
Roland McGrath <roland@gnu.org>
parents:
13823
diff
changeset
|
2747 (buffer-name buffer))))))) |
44e936e550ae
(save-some-buffers): Don't give message if we queried.
Roland McGrath <roland@gnu.org>
parents:
13823
diff
changeset
|
2748 (function |
44e936e550ae
(save-some-buffers): Don't give message if we queried.
Roland McGrath <roland@gnu.org>
parents:
13823
diff
changeset
|
2749 (lambda (buffer) |
44e936e550ae
(save-some-buffers): Don't give message if we queried.
Roland McGrath <roland@gnu.org>
parents:
13823
diff
changeset
|
2750 (set-buffer buffer) |
44e936e550ae
(save-some-buffers): Don't give message if we queried.
Roland McGrath <roland@gnu.org>
parents:
13823
diff
changeset
|
2751 (save-buffer))) |
44e936e550ae
(save-some-buffers): Don't give message if we queried.
Roland McGrath <roland@gnu.org>
parents:
13823
diff
changeset
|
2752 (buffer-list) |
44e936e550ae
(save-some-buffers): Don't give message if we queried.
Roland McGrath <roland@gnu.org>
parents:
13823
diff
changeset
|
2753 '("buffer" "buffers" "save") |
44e936e550ae
(save-some-buffers): Don't give message if we queried.
Roland McGrath <roland@gnu.org>
parents:
13823
diff
changeset
|
2754 (list (list ?\C-r (lambda (buf) |
18316
1058f8684eca
(backup, find-file): Make `files' their parent.
Richard M. Stallman <rms@gnu.org>
parents:
18164
diff
changeset
|
2755 (view-buffer buf |
1058f8684eca
(backup, find-file): Make `files' their parent.
Richard M. Stallman <rms@gnu.org>
parents:
18164
diff
changeset
|
2756 (function |
1058f8684eca
(backup, find-file): Make `files' their parent.
Richard M. Stallman <rms@gnu.org>
parents:
18164
diff
changeset
|
2757 (lambda (ignore) |
1058f8684eca
(backup, find-file): Make `files' their parent.
Richard M. Stallman <rms@gnu.org>
parents:
18164
diff
changeset
|
2758 (exit-recursive-edit)))) |
13832
44e936e550ae
(save-some-buffers): Don't give message if we queried.
Roland McGrath <roland@gnu.org>
parents:
13823
diff
changeset
|
2759 (recursive-edit) |
44e936e550ae
(save-some-buffers): Don't give message if we queried.
Roland McGrath <roland@gnu.org>
parents:
13823
diff
changeset
|
2760 ;; Return nil to ask about BUF again. |
44e936e550ae
(save-some-buffers): Don't give message if we queried.
Roland McGrath <roland@gnu.org>
parents:
13823
diff
changeset
|
2761 nil) |
44e936e550ae
(save-some-buffers): Don't give message if we queried.
Roland McGrath <roland@gnu.org>
parents:
13823
diff
changeset
|
2762 "display the current buffer")))) |
44e936e550ae
(save-some-buffers): Don't give message if we queried.
Roland McGrath <roland@gnu.org>
parents:
13823
diff
changeset
|
2763 (abbrevs-done |
44e936e550ae
(save-some-buffers): Don't give message if we queried.
Roland McGrath <roland@gnu.org>
parents:
13823
diff
changeset
|
2764 (and save-abbrevs abbrevs-changed |
44e936e550ae
(save-some-buffers): Don't give message if we queried.
Roland McGrath <roland@gnu.org>
parents:
13823
diff
changeset
|
2765 (progn |
44e936e550ae
(save-some-buffers): Don't give message if we queried.
Roland McGrath <roland@gnu.org>
parents:
13823
diff
changeset
|
2766 (if (or arg |
44e936e550ae
(save-some-buffers): Don't give message if we queried.
Roland McGrath <roland@gnu.org>
parents:
13823
diff
changeset
|
2767 (y-or-n-p (format "Save abbrevs in %s? " |
44e936e550ae
(save-some-buffers): Don't give message if we queried.
Roland McGrath <roland@gnu.org>
parents:
13823
diff
changeset
|
2768 abbrev-file-name))) |
44e936e550ae
(save-some-buffers): Don't give message if we queried.
Roland McGrath <roland@gnu.org>
parents:
13823
diff
changeset
|
2769 (write-abbrev-file nil)) |
44e936e550ae
(save-some-buffers): Don't give message if we queried.
Roland McGrath <roland@gnu.org>
parents:
13823
diff
changeset
|
2770 ;; Don't keep bothering user if he says no. |
44e936e550ae
(save-some-buffers): Don't give message if we queried.
Roland McGrath <roland@gnu.org>
parents:
13823
diff
changeset
|
2771 (setq abbrevs-changed nil) |
44e936e550ae
(save-some-buffers): Don't give message if we queried.
Roland McGrath <roland@gnu.org>
parents:
13823
diff
changeset
|
2772 t)))) |
44e936e550ae
(save-some-buffers): Don't give message if we queried.
Roland McGrath <roland@gnu.org>
parents:
13823
diff
changeset
|
2773 (or queried (> files-done 0) abbrevs-done |
5398
499f25507242
(save-some-buffers): Fix previous change.
Richard M. Stallman <rms@gnu.org>
parents:
5389
diff
changeset
|
2774 (message "(No files need saving)"))))) |
337 | 2775 |
2776 (defun not-modified (&optional arg) | |
2777 "Mark current buffer as unmodified, not needing to be saved. | |
10430 | 2778 With prefix arg, mark buffer as modified, so \\[save-buffer] will save. |
2779 | |
2780 It is not a good idea to use this function in Lisp programs, because it | |
2781 prints a message in the minibuffer. Instead, use `set-buffer-modified-p'." | |
337 | 2782 (interactive "P") |
2783 (message (if arg "Modification-flag set" | |
2784 "Modification-flag cleared")) | |
2785 (set-buffer-modified-p arg)) | |
2786 | |
2787 (defun toggle-read-only (&optional arg) | |
2788 "Change whether this buffer is visiting its file read-only. | |
18316
1058f8684eca
(backup, find-file): Make `files' their parent.
Richard M. Stallman <rms@gnu.org>
parents:
18164
diff
changeset
|
2789 With arg, set read-only iff arg is positive. |
1058f8684eca
(backup, find-file): Make `files' their parent.
Richard M. Stallman <rms@gnu.org>
parents:
18164
diff
changeset
|
2790 If visiting file read-only and `view-read-only' is non-nil, enter view mode." |
337 | 2791 (interactive "P") |
18316
1058f8684eca
(backup, find-file): Make `files' their parent.
Richard M. Stallman <rms@gnu.org>
parents:
18164
diff
changeset
|
2792 (cond |
1058f8684eca
(backup, find-file): Make `files' their parent.
Richard M. Stallman <rms@gnu.org>
parents:
18164
diff
changeset
|
2793 ((and arg (if (> (prefix-numeric-value arg) 0) buffer-read-only |
1058f8684eca
(backup, find-file): Make `files' their parent.
Richard M. Stallman <rms@gnu.org>
parents:
18164
diff
changeset
|
2794 (not buffer-read-only))) ; If buffer-read-only is set correctly, |
1058f8684eca
(backup, find-file): Make `files' their parent.
Richard M. Stallman <rms@gnu.org>
parents:
18164
diff
changeset
|
2795 nil) ; do nothing. |
1058f8684eca
(backup, find-file): Make `files' their parent.
Richard M. Stallman <rms@gnu.org>
parents:
18164
diff
changeset
|
2796 ;; Toggle. |
1058f8684eca
(backup, find-file): Make `files' their parent.
Richard M. Stallman <rms@gnu.org>
parents:
18164
diff
changeset
|
2797 ((and buffer-read-only view-mode) |
22338
746adedbb6ba
(toggle-read-only): When exiting View mode, locally
Karl Heuer <kwzh@gnu.org>
parents:
22179
diff
changeset
|
2798 (View-exit-and-edit) |
746adedbb6ba
(toggle-read-only): When exiting View mode, locally
Karl Heuer <kwzh@gnu.org>
parents:
22179
diff
changeset
|
2799 (make-local-variable 'view-read-only) |
746adedbb6ba
(toggle-read-only): When exiting View mode, locally
Karl Heuer <kwzh@gnu.org>
parents:
22179
diff
changeset
|
2800 (setq view-read-only t)) ; Must leave view mode. |
18316
1058f8684eca
(backup, find-file): Make `files' their parent.
Richard M. Stallman <rms@gnu.org>
parents:
18164
diff
changeset
|
2801 ((and (not buffer-read-only) view-read-only |
1058f8684eca
(backup, find-file): Make `files' their parent.
Richard M. Stallman <rms@gnu.org>
parents:
18164
diff
changeset
|
2802 (not (eq (get major-mode 'mode-class) 'special))) |
1058f8684eca
(backup, find-file): Make `files' their parent.
Richard M. Stallman <rms@gnu.org>
parents:
18164
diff
changeset
|
2803 (view-mode-enter)) |
1058f8684eca
(backup, find-file): Make `files' their parent.
Richard M. Stallman <rms@gnu.org>
parents:
18164
diff
changeset
|
2804 (t (setq buffer-read-only (not buffer-read-only)) |
1058f8684eca
(backup, find-file): Make `files' their parent.
Richard M. Stallman <rms@gnu.org>
parents:
18164
diff
changeset
|
2805 (force-mode-line-update)))) |
337 | 2806 |
17987
2d9818a04c36
(find-file): Delete the facility of handling a prefix
Kenichi Handa <handa@m17n.org>
parents:
17894
diff
changeset
|
2807 (defun insert-file (filename) |
337 | 2808 "Insert contents of file FILENAME into buffer after point. |
2809 Set mark after the inserted text. | |
2810 | |
2811 This function is meant for the user to run interactively. | |
2812 Don't call it from programs! Use `insert-file-contents' instead. | |
2813 \(Its calling sequence is different; see its documentation)." | |
17987
2d9818a04c36
(find-file): Delete the facility of handling a prefix
Kenichi Handa <handa@m17n.org>
parents:
17894
diff
changeset
|
2814 (interactive "*fInsert file: ") |
3835
e3a00a940cf4
(insert-file): Report error if file is directory.
Richard M. Stallman <rms@gnu.org>
parents:
3709
diff
changeset
|
2815 (if (file-directory-p filename) |
e3a00a940cf4
(insert-file): Report error if file is directory.
Richard M. Stallman <rms@gnu.org>
parents:
3709
diff
changeset
|
2816 (signal 'file-error (list "Opening input file" "file is a directory" |
e3a00a940cf4
(insert-file): Report error if file is directory.
Richard M. Stallman <rms@gnu.org>
parents:
3709
diff
changeset
|
2817 filename))) |
17987
2d9818a04c36
(find-file): Delete the facility of handling a prefix
Kenichi Handa <handa@m17n.org>
parents:
17894
diff
changeset
|
2818 (let ((tem (insert-file-contents filename))) |
337 | 2819 (push-mark (+ (point) (car (cdr tem)))))) |
2820 | |
17987
2d9818a04c36
(find-file): Delete the facility of handling a prefix
Kenichi Handa <handa@m17n.org>
parents:
17894
diff
changeset
|
2821 (defun append-to-file (start end filename) |
337 | 2822 "Append the contents of the region to the end of file FILENAME. |
2823 When called from a function, expects three arguments, | |
2824 START, END and FILENAME. START and END are buffer positions | |
19435
608acf74b95b
(append-to-file): Doc-string fixed.
Kenichi Handa <handa@m17n.org>
parents:
19305
diff
changeset
|
2825 saying what text to write." |
17987
2d9818a04c36
(find-file): Delete the facility of handling a prefix
Kenichi Handa <handa@m17n.org>
parents:
17894
diff
changeset
|
2826 (interactive "r\nFAppend to file: ") |
2d9818a04c36
(find-file): Delete the facility of handling a prefix
Kenichi Handa <handa@m17n.org>
parents:
17894
diff
changeset
|
2827 (write-region start end filename t)) |
337 | 2828 |
2829 (defun file-newest-backup (filename) | |
2830 "Return most recent backup file for FILENAME or nil if no backups exist." | |
32138 | 2831 ;; `make-backup-file-name' will get us the right directory for |
2832 ;; ordinary or numeric backups. It might create a directory for | |
2833 ;; backups as a side-effect, according to `backup-directory-alist'. | |
2834 (let* ((filename (file-name-sans-versions | |
2835 (make-backup-file-name filename))) | |
337 | 2836 (file (file-name-nondirectory filename)) |
2837 (dir (file-name-directory filename)) | |
2838 (comp (file-name-all-completions file dir)) | |
14927
645493140921
(file-newest-backup): Return the newest backup for the
Richard M. Stallman <rms@gnu.org>
parents:
14883
diff
changeset
|
2839 (newest nil) |
645493140921
(file-newest-backup): Return the newest backup for the
Richard M. Stallman <rms@gnu.org>
parents:
14883
diff
changeset
|
2840 tem) |
337 | 2841 (while comp |
32138 | 2842 (setq tem (pop comp)) |
14927
645493140921
(file-newest-backup): Return the newest backup for the
Richard M. Stallman <rms@gnu.org>
parents:
14883
diff
changeset
|
2843 (cond ((and (backup-file-name-p tem) |
645493140921
(file-newest-backup): Return the newest backup for the
Richard M. Stallman <rms@gnu.org>
parents:
14883
diff
changeset
|
2844 (string= (file-name-sans-versions tem) file)) |
645493140921
(file-newest-backup): Return the newest backup for the
Richard M. Stallman <rms@gnu.org>
parents:
14883
diff
changeset
|
2845 (setq tem (concat dir tem)) |
645493140921
(file-newest-backup): Return the newest backup for the
Richard M. Stallman <rms@gnu.org>
parents:
14883
diff
changeset
|
2846 (if (or (null newest) |
645493140921
(file-newest-backup): Return the newest backup for the
Richard M. Stallman <rms@gnu.org>
parents:
14883
diff
changeset
|
2847 (file-newer-than-file-p tem newest)) |
645493140921
(file-newest-backup): Return the newest backup for the
Richard M. Stallman <rms@gnu.org>
parents:
14883
diff
changeset
|
2848 (setq newest tem))))) |
337 | 2849 newest)) |
2850 | |
2851 (defun rename-uniquely () | |
2852 "Rename current buffer to a similar name not already taken. | |
2853 This function is useful for creating multiple shell process buffers | |
2854 or multiple mail buffers, etc." | |
2855 (interactive) | |
11522
5177611e8e4d
(rename-uniquely): Strip suffix before rename.
Richard M. Stallman <rms@gnu.org>
parents:
11463
diff
changeset
|
2856 (save-match-data |
20218 | 2857 (let ((base-name (buffer-name))) |
2858 (and (string-match "<[0-9]+>\\'" base-name) | |
2859 (not (and buffer-file-name | |
2860 (string= base-name | |
2861 (file-name-nondirectory buffer-file-name)))) | |
2862 ;; If the existing buffer name has a <NNN>, | |
2863 ;; which isn't part of the file name (if any), | |
2864 ;; then get rid of that. | |
2865 (setq base-name (substring base-name 0 (match-beginning 0)))) | |
2866 (rename-buffer (generate-new-buffer-name base-name)) | |
11563
63215d2a1e3f
(toggle-read-only, rename-uniquely): Use force-mode-line-update.
Karl Heuer <kwzh@gnu.org>
parents:
11553
diff
changeset
|
2867 (force-mode-line-update)))) |
423 | 2868 |
1537
8531c6d96e5c
(make-directory): Renamed from make-directory-path.
Richard M. Stallman <rms@gnu.org>
parents:
1471
diff
changeset
|
2869 (defun make-directory (dir &optional parents) |
3672
3eaec128c91e
(make-directory): By default create dir default-dir.
Richard M. Stallman <rms@gnu.org>
parents:
3670
diff
changeset
|
2870 "Create the directory DIR and any nonexistent parent dirs. |
3eaec128c91e
(make-directory): By default create dir default-dir.
Richard M. Stallman <rms@gnu.org>
parents:
3670
diff
changeset
|
2871 Interactively, the default choice of directory to create |
3eaec128c91e
(make-directory): By default create dir default-dir.
Richard M. Stallman <rms@gnu.org>
parents:
3670
diff
changeset
|
2872 is the current default directory for file names. |
13980 | 2873 That is useful when you have visited a file in a nonexistent directory. |
3672
3eaec128c91e
(make-directory): By default create dir default-dir.
Richard M. Stallman <rms@gnu.org>
parents:
3670
diff
changeset
|
2874 |
3eaec128c91e
(make-directory): By default create dir default-dir.
Richard M. Stallman <rms@gnu.org>
parents:
3670
diff
changeset
|
2875 Noninteractively, the second (optional) argument PARENTS says whether |
3eaec128c91e
(make-directory): By default create dir default-dir.
Richard M. Stallman <rms@gnu.org>
parents:
3670
diff
changeset
|
2876 to create parent directories if they don't exist." |
3eaec128c91e
(make-directory): By default create dir default-dir.
Richard M. Stallman <rms@gnu.org>
parents:
3670
diff
changeset
|
2877 (interactive |
3eaec128c91e
(make-directory): By default create dir default-dir.
Richard M. Stallman <rms@gnu.org>
parents:
3670
diff
changeset
|
2878 (list (read-file-name "Make directory: " default-directory default-directory |
3eaec128c91e
(make-directory): By default create dir default-dir.
Richard M. Stallman <rms@gnu.org>
parents:
3670
diff
changeset
|
2879 nil nil) |
3eaec128c91e
(make-directory): By default create dir default-dir.
Richard M. Stallman <rms@gnu.org>
parents:
3670
diff
changeset
|
2880 t)) |
7030
9e51b51e8595
Pass operation to find-file-name-handler.
Karl Heuer <kwzh@gnu.org>
parents:
6899
diff
changeset
|
2881 (let ((handler (find-file-name-handler dir 'make-directory))) |
1537
8531c6d96e5c
(make-directory): Renamed from make-directory-path.
Richard M. Stallman <rms@gnu.org>
parents:
1471
diff
changeset
|
2882 (if handler |
8531c6d96e5c
(make-directory): Renamed from make-directory-path.
Richard M. Stallman <rms@gnu.org>
parents:
1471
diff
changeset
|
2883 (funcall handler 'make-directory dir parents) |
8531c6d96e5c
(make-directory): Renamed from make-directory-path.
Richard M. Stallman <rms@gnu.org>
parents:
1471
diff
changeset
|
2884 (if (not parents) |
8531c6d96e5c
(make-directory): Renamed from make-directory-path.
Richard M. Stallman <rms@gnu.org>
parents:
1471
diff
changeset
|
2885 (make-directory-internal dir) |
8531c6d96e5c
(make-directory): Renamed from make-directory-path.
Richard M. Stallman <rms@gnu.org>
parents:
1471
diff
changeset
|
2886 (let ((dir (directory-file-name (expand-file-name dir))) |
8531c6d96e5c
(make-directory): Renamed from make-directory-path.
Richard M. Stallman <rms@gnu.org>
parents:
1471
diff
changeset
|
2887 create-list) |
8531c6d96e5c
(make-directory): Renamed from make-directory-path.
Richard M. Stallman <rms@gnu.org>
parents:
1471
diff
changeset
|
2888 (while (not (file-exists-p dir)) |
13832
44e936e550ae
(save-some-buffers): Don't give message if we queried.
Roland McGrath <roland@gnu.org>
parents:
13823
diff
changeset
|
2889 (setq create-list (cons dir create-list) |
1537
8531c6d96e5c
(make-directory): Renamed from make-directory-path.
Richard M. Stallman <rms@gnu.org>
parents:
1471
diff
changeset
|
2890 dir (directory-file-name (file-name-directory dir)))) |
8531c6d96e5c
(make-directory): Renamed from make-directory-path.
Richard M. Stallman <rms@gnu.org>
parents:
1471
diff
changeset
|
2891 (while create-list |
8531c6d96e5c
(make-directory): Renamed from make-directory-path.
Richard M. Stallman <rms@gnu.org>
parents:
1471
diff
changeset
|
2892 (make-directory-internal (car create-list)) |
8531c6d96e5c
(make-directory): Renamed from make-directory-path.
Richard M. Stallman <rms@gnu.org>
parents:
1471
diff
changeset
|
2893 (setq create-list (cdr create-list)))))))) |
337 | 2894 |
2895 (put 'revert-buffer-function 'permanent-local t) | |
2896 (defvar revert-buffer-function nil | |
8160
1013d56a1133
(revert-buffer-function): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
8158
diff
changeset
|
2897 "Function to use to revert this buffer, or nil to do the default. |
1013d56a1133
(revert-buffer-function): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
8158
diff
changeset
|
2898 The function receives two arguments IGNORE-AUTO and NOCONFIRM, |
1013d56a1133
(revert-buffer-function): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
8158
diff
changeset
|
2899 which are the arguments that `revert-buffer' received.") |
337 | 2900 |
2901 (put 'revert-buffer-insert-file-contents-function 'permanent-local t) | |
2902 (defvar revert-buffer-insert-file-contents-function nil | |
2903 "Function to use to insert contents when reverting this buffer. | |
2904 Gets two args, first the nominal file name to use, | |
24925
5169ebe70135
(revert-buffer): Don't preserve point here.
Richard M. Stallman <rms@gnu.org>
parents:
24874
diff
changeset
|
2905 and second, t if reading the auto-save file. |
5169ebe70135
(revert-buffer): Don't preserve point here.
Richard M. Stallman <rms@gnu.org>
parents:
24874
diff
changeset
|
2906 |
5169ebe70135
(revert-buffer): Don't preserve point here.
Richard M. Stallman <rms@gnu.org>
parents:
24874
diff
changeset
|
2907 The function you specify is responsible for updating (or preserving) point.") |
337 | 2908 |
11995
ea774a7c610c
(after-revert-hook, before-revert-hook): Add defvars.
Karl Heuer <kwzh@gnu.org>
parents:
11982
diff
changeset
|
2909 (defvar before-revert-hook nil |
ea774a7c610c
(after-revert-hook, before-revert-hook): Add defvars.
Karl Heuer <kwzh@gnu.org>
parents:
11982
diff
changeset
|
2910 "Normal hook for `revert-buffer' to run before reverting. |
ea774a7c610c
(after-revert-hook, before-revert-hook): Add defvars.
Karl Heuer <kwzh@gnu.org>
parents:
11982
diff
changeset
|
2911 If `revert-buffer-function' is used to override the normal revert |
ea774a7c610c
(after-revert-hook, before-revert-hook): Add defvars.
Karl Heuer <kwzh@gnu.org>
parents:
11982
diff
changeset
|
2912 mechanism, this hook is not used.") |
ea774a7c610c
(after-revert-hook, before-revert-hook): Add defvars.
Karl Heuer <kwzh@gnu.org>
parents:
11982
diff
changeset
|
2913 |
ea774a7c610c
(after-revert-hook, before-revert-hook): Add defvars.
Karl Heuer <kwzh@gnu.org>
parents:
11982
diff
changeset
|
2914 (defvar after-revert-hook nil |
ea774a7c610c
(after-revert-hook, before-revert-hook): Add defvars.
Karl Heuer <kwzh@gnu.org>
parents:
11982
diff
changeset
|
2915 "Normal hook for `revert-buffer' to run after reverting. |
ea774a7c610c
(after-revert-hook, before-revert-hook): Add defvars.
Karl Heuer <kwzh@gnu.org>
parents:
11982
diff
changeset
|
2916 Note that the hook value that it runs is the value that was in effect |
ea774a7c610c
(after-revert-hook, before-revert-hook): Add defvars.
Karl Heuer <kwzh@gnu.org>
parents:
11982
diff
changeset
|
2917 before reverting; that makes a difference if you have buffer-local |
ea774a7c610c
(after-revert-hook, before-revert-hook): Add defvars.
Karl Heuer <kwzh@gnu.org>
parents:
11982
diff
changeset
|
2918 hook functions. |
ea774a7c610c
(after-revert-hook, before-revert-hook): Add defvars.
Karl Heuer <kwzh@gnu.org>
parents:
11982
diff
changeset
|
2919 |
ea774a7c610c
(after-revert-hook, before-revert-hook): Add defvars.
Karl Heuer <kwzh@gnu.org>
parents:
11982
diff
changeset
|
2920 If `revert-buffer-function' is used to override the normal revert |
ea774a7c610c
(after-revert-hook, before-revert-hook): Add defvars.
Karl Heuer <kwzh@gnu.org>
parents:
11982
diff
changeset
|
2921 mechanism, this hook is not used.") |
ea774a7c610c
(after-revert-hook, before-revert-hook): Add defvars.
Karl Heuer <kwzh@gnu.org>
parents:
11982
diff
changeset
|
2922 |
23500
8f220d8d170d
(auto-mode-alist): Recognize .rpm files.
Richard M. Stallman <rms@gnu.org>
parents:
23473
diff
changeset
|
2923 (defvar revert-buffer-internal-hook) |
8f220d8d170d
(auto-mode-alist): Recognize .rpm files.
Richard M. Stallman <rms@gnu.org>
parents:
23473
diff
changeset
|
2924 |
13857
aa5e493a867d
(revert-buffer): New arg preserve-modes.
Richard M. Stallman <rms@gnu.org>
parents:
13832
diff
changeset
|
2925 (defun revert-buffer (&optional ignore-auto noconfirm preserve-modes) |
16544
9fffc9e5fc42
(revert-buffer): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
16477
diff
changeset
|
2926 "Replace current buffer text with the text of the visited file on disk. |
337 | 2927 This undoes all changes since the file was visited or saved. |
605 | 2928 With a prefix argument, offer to revert from latest auto-save file, if |
2929 that is more recent than the visited file. | |
1905
494dd05d460c
* files.el (revert-buffer): Reverse the sense of the first
Jim Blandy <jimb@redhat.com>
parents:
1892
diff
changeset
|
2930 |
16544
9fffc9e5fc42
(revert-buffer): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
16477
diff
changeset
|
2931 This command also works for special buffers that contain text which |
9fffc9e5fc42
(revert-buffer): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
16477
diff
changeset
|
2932 doesn't come from a file, but reflects some other data base instead: |
9fffc9e5fc42
(revert-buffer): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
16477
diff
changeset
|
2933 for example, Dired buffers and buffer-list buffers. In these cases, |
9fffc9e5fc42
(revert-buffer): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
16477
diff
changeset
|
2934 it reconstructs the buffer contents from the appropriate data base. |
9fffc9e5fc42
(revert-buffer): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
16477
diff
changeset
|
2935 |
10942
3f77513d0a77
(revert-buffer): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
10901
diff
changeset
|
2936 When called from Lisp, the first argument is IGNORE-AUTO; only offer |
1905
494dd05d460c
* files.el (revert-buffer): Reverse the sense of the first
Jim Blandy <jimb@redhat.com>
parents:
1892
diff
changeset
|
2937 to revert from the auto-save file when this is nil. Note that the |
494dd05d460c
* files.el (revert-buffer): Reverse the sense of the first
Jim Blandy <jimb@redhat.com>
parents:
1892
diff
changeset
|
2938 sense of this argument is the reverse of the prefix argument, for the |
494dd05d460c
* files.el (revert-buffer): Reverse the sense of the first
Jim Blandy <jimb@redhat.com>
parents:
1892
diff
changeset
|
2939 sake of backward compatibility. IGNORE-AUTO is optional, defaulting |
494dd05d460c
* files.el (revert-buffer): Reverse the sense of the first
Jim Blandy <jimb@redhat.com>
parents:
1892
diff
changeset
|
2940 to nil. |
494dd05d460c
* files.el (revert-buffer): Reverse the sense of the first
Jim Blandy <jimb@redhat.com>
parents:
1892
diff
changeset
|
2941 |
494dd05d460c
* files.el (revert-buffer): Reverse the sense of the first
Jim Blandy <jimb@redhat.com>
parents:
1892
diff
changeset
|
2942 Optional second argument NOCONFIRM means don't ask for confirmation at |
32138 | 2943 all. (The local variable `revert-without-query', if non-nil, prevents |
23606
57e437a51073
(revert-buffer): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
23500
diff
changeset
|
2944 confirmation.) |
337 | 2945 |
15890
c2ef756791fe
(revert-buffer): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
15753
diff
changeset
|
2946 Optional third argument PRESERVE-MODES non-nil means don't alter |
c2ef756791fe
(revert-buffer): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
15753
diff
changeset
|
2947 the files modes. Normally we reinitialize them using `normal-mode'. |
c2ef756791fe
(revert-buffer): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
15753
diff
changeset
|
2948 |
605 | 2949 If the value of `revert-buffer-function' is non-nil, it is called to |
16544
9fffc9e5fc42
(revert-buffer): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
16477
diff
changeset
|
2950 do all the work for this command. Otherwise, the hooks |
9fffc9e5fc42
(revert-buffer): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
16477
diff
changeset
|
2951 `before-revert-hook' and `after-revert-hook' are run at the beginning |
9fffc9e5fc42
(revert-buffer): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
16477
diff
changeset
|
2952 and the end, and if `revert-buffer-insert-file-contents-function' is |
9fffc9e5fc42
(revert-buffer): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
16477
diff
changeset
|
2953 non-nil, it is called instead of rereading visited file contents." |
5624
76f618230217
(revert-buffer): Run after-revert-hook.
Richard M. Stallman <rms@gnu.org>
parents:
5621
diff
changeset
|
2954 |
1905
494dd05d460c
* files.el (revert-buffer): Reverse the sense of the first
Jim Blandy <jimb@redhat.com>
parents:
1892
diff
changeset
|
2955 ;; I admit it's odd to reverse the sense of the prefix argument, but |
494dd05d460c
* files.el (revert-buffer): Reverse the sense of the first
Jim Blandy <jimb@redhat.com>
parents:
1892
diff
changeset
|
2956 ;; there is a lot of code out there which assumes that the first |
494dd05d460c
* files.el (revert-buffer): Reverse the sense of the first
Jim Blandy <jimb@redhat.com>
parents:
1892
diff
changeset
|
2957 ;; argument should be t to avoid consulting the auto-save file, and |
494dd05d460c
* files.el (revert-buffer): Reverse the sense of the first
Jim Blandy <jimb@redhat.com>
parents:
1892
diff
changeset
|
2958 ;; there's no straightforward way to encourage authors to notice a |
494dd05d460c
* files.el (revert-buffer): Reverse the sense of the first
Jim Blandy <jimb@redhat.com>
parents:
1892
diff
changeset
|
2959 ;; reversal of the argument sense. So I'm just changing the user |
494dd05d460c
* files.el (revert-buffer): Reverse the sense of the first
Jim Blandy <jimb@redhat.com>
parents:
1892
diff
changeset
|
2960 ;; interface, but leaving the programmatic interface the same. |
10847
c79a2dca8f75
(revert-buffer): Use current-prefix-arg, not prefix-arg.
Karl Heuer <kwzh@gnu.org>
parents:
10735
diff
changeset
|
2961 (interactive (list (not current-prefix-arg))) |
337 | 2962 (if revert-buffer-function |
1905
494dd05d460c
* files.el (revert-buffer): Reverse the sense of the first
Jim Blandy <jimb@redhat.com>
parents:
1892
diff
changeset
|
2963 (funcall revert-buffer-function ignore-auto noconfirm) |
24925
5169ebe70135
(revert-buffer): Don't preserve point here.
Richard M. Stallman <rms@gnu.org>
parents:
24874
diff
changeset
|
2964 (let* ((auto-save-p (and (not ignore-auto) |
1905
494dd05d460c
* files.el (revert-buffer): Reverse the sense of the first
Jim Blandy <jimb@redhat.com>
parents:
1892
diff
changeset
|
2965 (recent-auto-save-p) |
337 | 2966 buffer-auto-save-file-name |
2967 (file-readable-p buffer-auto-save-file-name) | |
2968 (y-or-n-p | |
2969 "Buffer has been auto-saved recently. Revert from auto-save file? "))) | |
2970 (file-name (if auto-save-p | |
2971 buffer-auto-save-file-name | |
2972 buffer-file-name))) | |
2973 (cond ((null file-name) | |
2974 (error "Buffer does not seem to be associated with any file")) | |
2975 ((or noconfirm | |
17894
488536bc29c2
(path-separator, parse-colon-path): Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents:
17734
diff
changeset
|
2976 (and (not (buffer-modified-p)) |
488536bc29c2
(path-separator, parse-colon-path): Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents:
17734
diff
changeset
|
2977 (let ((tail revert-without-query) |
488536bc29c2
(path-separator, parse-colon-path): Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents:
17734
diff
changeset
|
2978 (found nil)) |
488536bc29c2
(path-separator, parse-colon-path): Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents:
17734
diff
changeset
|
2979 (while tail |
488536bc29c2
(path-separator, parse-colon-path): Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents:
17734
diff
changeset
|
2980 (if (string-match (car tail) file-name) |
488536bc29c2
(path-separator, parse-colon-path): Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents:
17734
diff
changeset
|
2981 (setq found t)) |
488536bc29c2
(path-separator, parse-colon-path): Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents:
17734
diff
changeset
|
2982 (setq tail (cdr tail))) |
488536bc29c2
(path-separator, parse-colon-path): Doc fixes.
Richard M. Stallman <rms@gnu.org>
parents:
17734
diff
changeset
|
2983 found)) |
337 | 2984 (yes-or-no-p (format "Revert buffer from file %s? " |
2985 file-name))) | |
5716
82588f97d478
(revert-buffer): reposition after-revert-hook, and add before-revert-hook.
Karl Heuer <kwzh@gnu.org>
parents:
5624
diff
changeset
|
2986 (run-hooks 'before-revert-hook) |
337 | 2987 ;; If file was backed up but has changed since, |
2988 ;; we shd make another backup. | |
2989 (and (not auto-save-p) | |
423 | 2990 (not (verify-visited-file-modtime (current-buffer))) |
337 | 2991 (setq buffer-backed-up nil)) |
2992 ;; Get rid of all undo records for this buffer. | |
2993 (or (eq buffer-undo-list t) | |
2994 (setq buffer-undo-list nil)) | |
11982
a88f862b3927
(revert-buffer): Save after-revert-hook (both local and
Karl Heuer <kwzh@gnu.org>
parents:
11981
diff
changeset
|
2995 ;; Effectively copy the after-revert-hook status, |
a88f862b3927
(revert-buffer): Save after-revert-hook (both local and
Karl Heuer <kwzh@gnu.org>
parents:
11981
diff
changeset
|
2996 ;; since after-find-file will clobber it. |
a88f862b3927
(revert-buffer): Save after-revert-hook (both local and
Karl Heuer <kwzh@gnu.org>
parents:
11981
diff
changeset
|
2997 (let ((global-hook (default-value 'after-revert-hook)) |
a88f862b3927
(revert-buffer): Save after-revert-hook (both local and
Karl Heuer <kwzh@gnu.org>
parents:
11981
diff
changeset
|
2998 (local-hook-p (local-variable-p 'after-revert-hook)) |
a88f862b3927
(revert-buffer): Save after-revert-hook (both local and
Karl Heuer <kwzh@gnu.org>
parents:
11981
diff
changeset
|
2999 (local-hook (and (local-variable-p 'after-revert-hook) |
a88f862b3927
(revert-buffer): Save after-revert-hook (both local and
Karl Heuer <kwzh@gnu.org>
parents:
11981
diff
changeset
|
3000 after-revert-hook))) |
a88f862b3927
(revert-buffer): Save after-revert-hook (both local and
Karl Heuer <kwzh@gnu.org>
parents:
11981
diff
changeset
|
3001 (let (buffer-read-only |
a88f862b3927
(revert-buffer): Save after-revert-hook (both local and
Karl Heuer <kwzh@gnu.org>
parents:
11981
diff
changeset
|
3002 ;; Don't make undo records for the reversion. |
a88f862b3927
(revert-buffer): Save after-revert-hook (both local and
Karl Heuer <kwzh@gnu.org>
parents:
11981
diff
changeset
|
3003 (buffer-undo-list t)) |
a88f862b3927
(revert-buffer): Save after-revert-hook (both local and
Karl Heuer <kwzh@gnu.org>
parents:
11981
diff
changeset
|
3004 (if revert-buffer-insert-file-contents-function |
a88f862b3927
(revert-buffer): Save after-revert-hook (both local and
Karl Heuer <kwzh@gnu.org>
parents:
11981
diff
changeset
|
3005 (funcall revert-buffer-insert-file-contents-function |
a88f862b3927
(revert-buffer): Save after-revert-hook (both local and
Karl Heuer <kwzh@gnu.org>
parents:
11981
diff
changeset
|
3006 file-name auto-save-p) |
a88f862b3927
(revert-buffer): Save after-revert-hook (both local and
Karl Heuer <kwzh@gnu.org>
parents:
11981
diff
changeset
|
3007 (if (not (file-exists-p file-name)) |
a88f862b3927
(revert-buffer): Save after-revert-hook (both local and
Karl Heuer <kwzh@gnu.org>
parents:
11981
diff
changeset
|
3008 (error "File %s no longer exists!" file-name)) |
a88f862b3927
(revert-buffer): Save after-revert-hook (both local and
Karl Heuer <kwzh@gnu.org>
parents:
11981
diff
changeset
|
3009 ;; Bind buffer-file-name to nil |
a88f862b3927
(revert-buffer): Save after-revert-hook (both local and
Karl Heuer <kwzh@gnu.org>
parents:
11981
diff
changeset
|
3010 ;; so that we don't try to lock the file. |
a88f862b3927
(revert-buffer): Save after-revert-hook (both local and
Karl Heuer <kwzh@gnu.org>
parents:
11981
diff
changeset
|
3011 (let ((buffer-file-name nil)) |
a88f862b3927
(revert-buffer): Save after-revert-hook (both local and
Karl Heuer <kwzh@gnu.org>
parents:
11981
diff
changeset
|
3012 (or auto-save-p |
a88f862b3927
(revert-buffer): Save after-revert-hook (both local and
Karl Heuer <kwzh@gnu.org>
parents:
11981
diff
changeset
|
3013 (unlock-buffer))) |
a88f862b3927
(revert-buffer): Save after-revert-hook (both local and
Karl Heuer <kwzh@gnu.org>
parents:
11981
diff
changeset
|
3014 (widen) |
19552
c8a5bd70b9cd
(revert-buffer): Read a file without any code
Kenichi Handa <handa@m17n.org>
parents:
19435
diff
changeset
|
3015 (let ((coding-system-for-read |
c8a5bd70b9cd
(revert-buffer): Read a file without any code
Kenichi Handa <handa@m17n.org>
parents:
19435
diff
changeset
|
3016 ;; Auto-saved file shoule be read without |
c8a5bd70b9cd
(revert-buffer): Read a file without any code
Kenichi Handa <handa@m17n.org>
parents:
19435
diff
changeset
|
3017 ;; any code conversion. |
34085
da2a5d1550b7
(revert-buffer, recover-file): Bind
Eli Zaretskii <eliz@gnu.org>
parents:
34009
diff
changeset
|
3018 (if auto-save-p 'emacs-mule-unix |
19552
c8a5bd70b9cd
(revert-buffer): Read a file without any code
Kenichi Handa <handa@m17n.org>
parents:
19435
diff
changeset
|
3019 coding-system-for-read))) |
24925
5169ebe70135
(revert-buffer): Don't preserve point here.
Richard M. Stallman <rms@gnu.org>
parents:
24874
diff
changeset
|
3020 ;; Note that this preserves point in an intelligent way. |
19552
c8a5bd70b9cd
(revert-buffer): Read a file without any code
Kenichi Handa <handa@m17n.org>
parents:
19435
diff
changeset
|
3021 (insert-file-contents file-name (not auto-save-p) |
c8a5bd70b9cd
(revert-buffer): Read a file without any code
Kenichi Handa <handa@m17n.org>
parents:
19435
diff
changeset
|
3022 nil nil t)))) |
11982
a88f862b3927
(revert-buffer): Save after-revert-hook (both local and
Karl Heuer <kwzh@gnu.org>
parents:
11981
diff
changeset
|
3023 ;; Recompute the truename in case changes in symlinks |
a88f862b3927
(revert-buffer): Save after-revert-hook (both local and
Karl Heuer <kwzh@gnu.org>
parents:
11981
diff
changeset
|
3024 ;; have changed the truename. |
a88f862b3927
(revert-buffer): Save after-revert-hook (both local and
Karl Heuer <kwzh@gnu.org>
parents:
11981
diff
changeset
|
3025 (setq buffer-file-truename |
a88f862b3927
(revert-buffer): Save after-revert-hook (both local and
Karl Heuer <kwzh@gnu.org>
parents:
11981
diff
changeset
|
3026 (abbreviate-file-name (file-truename buffer-file-name))) |
13857
aa5e493a867d
(revert-buffer): New arg preserve-modes.
Richard M. Stallman <rms@gnu.org>
parents:
13832
diff
changeset
|
3027 (after-find-file nil nil t t preserve-modes) |
11982
a88f862b3927
(revert-buffer): Save after-revert-hook (both local and
Karl Heuer <kwzh@gnu.org>
parents:
11981
diff
changeset
|
3028 ;; Run after-revert-hook as it was before we reverted. |
a88f862b3927
(revert-buffer): Save after-revert-hook (both local and
Karl Heuer <kwzh@gnu.org>
parents:
11981
diff
changeset
|
3029 (setq-default revert-buffer-internal-hook global-hook) |
a88f862b3927
(revert-buffer): Save after-revert-hook (both local and
Karl Heuer <kwzh@gnu.org>
parents:
11981
diff
changeset
|
3030 (if local-hook-p |
a88f862b3927
(revert-buffer): Save after-revert-hook (both local and
Karl Heuer <kwzh@gnu.org>
parents:
11981
diff
changeset
|
3031 (progn |
a88f862b3927
(revert-buffer): Save after-revert-hook (both local and
Karl Heuer <kwzh@gnu.org>
parents:
11981
diff
changeset
|
3032 (make-local-variable 'revert-buffer-internal-hook) |
a88f862b3927
(revert-buffer): Save after-revert-hook (both local and
Karl Heuer <kwzh@gnu.org>
parents:
11981
diff
changeset
|
3033 (setq revert-buffer-internal-hook local-hook)) |
a88f862b3927
(revert-buffer): Save after-revert-hook (both local and
Karl Heuer <kwzh@gnu.org>
parents:
11981
diff
changeset
|
3034 (kill-local-variable 'revert-buffer-internal-hook)) |
a88f862b3927
(revert-buffer): Save after-revert-hook (both local and
Karl Heuer <kwzh@gnu.org>
parents:
11981
diff
changeset
|
3035 (run-hooks 'revert-buffer-internal-hook)) |
5716
82588f97d478
(revert-buffer): reposition after-revert-hook, and add before-revert-hook.
Karl Heuer <kwzh@gnu.org>
parents:
5624
diff
changeset
|
3036 t))))) |
337 | 3037 |
3038 (defun recover-file (file) | |
3039 "Visit file FILE, but get contents from its last auto-save file." | |
10712
5b86ce0cddb5
(recover-file): Use ordinary `f' to read file name.
Richard M. Stallman <rms@gnu.org>
parents:
10430
diff
changeset
|
3040 ;; Actually putting the file name in the minibuffer should be used |
5b86ce0cddb5
(recover-file): Use ordinary `f' to read file name.
Richard M. Stallman <rms@gnu.org>
parents:
10430
diff
changeset
|
3041 ;; only rarely. |
5b86ce0cddb5
(recover-file): Use ordinary `f' to read file name.
Richard M. Stallman <rms@gnu.org>
parents:
10430
diff
changeset
|
3042 ;; Not just because users often use the default. |
13693
40766c32c127
(recover-file): Also recover new, unsaved files.
Erik Naggum <erik@naggum.no>
parents:
13662
diff
changeset
|
3043 (interactive "FRecover file: ") |
337 | 3044 (setq file (expand-file-name file)) |
5958
64fa4e0f3fce
(recover-file): Call auto-save-file-name-p correctly.
Richard M. Stallman <rms@gnu.org>
parents:
5956
diff
changeset
|
3045 (if (auto-save-file-name-p (file-name-nondirectory file)) |
64fa4e0f3fce
(recover-file): Call auto-save-file-name-p correctly.
Richard M. Stallman <rms@gnu.org>
parents:
5956
diff
changeset
|
3046 (error "%s is an auto-save file" file)) |
337 | 3047 (let ((file-name (let ((buffer-file-name file)) |
3048 (make-auto-save-file-name)))) | |
12846
fc74ffbce5a9
(recover-file): It's ok if the visited file doesn't exist.
Richard M. Stallman <rms@gnu.org>
parents:
12740
diff
changeset
|
3049 (cond ((if (file-exists-p file) |
fc74ffbce5a9
(recover-file): It's ok if the visited file doesn't exist.
Richard M. Stallman <rms@gnu.org>
parents:
12740
diff
changeset
|
3050 (not (file-newer-than-file-p file-name file)) |
fc74ffbce5a9
(recover-file): It's ok if the visited file doesn't exist.
Richard M. Stallman <rms@gnu.org>
parents:
12740
diff
changeset
|
3051 (not (file-exists-p file-name))) |
337 | 3052 (error "Auto-save file %s not current" file-name)) |
3053 ((save-window-excursion | |
32138 | 3054 (with-output-to-temp-buffer "*Directory*" |
3055 (buffer-disable-undo standard-output) | |
3056 (save-excursion | |
3057 (let ((switches dired-listing-switches)) | |
3058 (if (file-symlink-p file) | |
3059 (setq switches (concat switches "L"))) | |
3060 (set-buffer standard-output) | |
3061 (insert-directory file switches) | |
3062 (insert-directory file-name switches)))) | |
337 | 3063 (yes-or-no-p (format "Recover auto save file %s? " file-name))) |
3064 (switch-to-buffer (find-file-noselect file t)) | |
17004
cd1d930a2c98
(find-file, find-file-other-window,
Karl Heuer <kwzh@gnu.org>
parents:
16976
diff
changeset
|
3065 (let ((buffer-read-only nil) |
24764
ece1961bd955
(recover-file): Recover buffer-file-coding-system.
Kenichi Handa <handa@m17n.org>
parents:
24727
diff
changeset
|
3066 ;; Keep the current buffer-file-coding-system. |
ece1961bd955
(recover-file): Recover buffer-file-coding-system.
Kenichi Handa <handa@m17n.org>
parents:
24727
diff
changeset
|
3067 (coding-system buffer-file-coding-system) |
17004
cd1d930a2c98
(find-file, find-file-other-window,
Karl Heuer <kwzh@gnu.org>
parents:
16976
diff
changeset
|
3068 ;; Auto-saved file shoule be read without any code conversion. |
34085
da2a5d1550b7
(revert-buffer, recover-file): Bind
Eli Zaretskii <eliz@gnu.org>
parents:
34009
diff
changeset
|
3069 (coding-system-for-read 'emacs-mule-unix)) |
337 | 3070 (erase-buffer) |
24764
ece1961bd955
(recover-file): Recover buffer-file-coding-system.
Kenichi Handa <handa@m17n.org>
parents:
24727
diff
changeset
|
3071 (insert-file-contents file-name nil) |
ece1961bd955
(recover-file): Recover buffer-file-coding-system.
Kenichi Handa <handa@m17n.org>
parents:
24727
diff
changeset
|
3072 (set-buffer-file-coding-system coding-system)) |
1212
de70f50101c0
(after-find-file): New arg NOAUTO.
Richard M. Stallman <rms@gnu.org>
parents:
1182
diff
changeset
|
3073 (after-find-file nil nil t)) |
17525
a92a4702711a
(recover-file): Fix error message.
Richard M. Stallman <rms@gnu.org>
parents:
17421
diff
changeset
|
3074 (t (error "Recover-file cancelled"))))) |
337 | 3075 |
11739
a9614b779859
(recover-session): Renamed from multiple-recover.
Richard M. Stallman <rms@gnu.org>
parents:
11636
diff
changeset
|
3076 (defun recover-session () |
11630
d18ae33bb3b6
(multiple-recover, multiple-recover-finish): New commands.
Richard M. Stallman <rms@gnu.org>
parents:
11563
diff
changeset
|
3077 "Recover auto save files from a previous Emacs session. |
d18ae33bb3b6
(multiple-recover, multiple-recover-finish): New commands.
Richard M. Stallman <rms@gnu.org>
parents:
11563
diff
changeset
|
3078 This command first displays a Dired buffer showing you the |
d18ae33bb3b6
(multiple-recover, multiple-recover-finish): New commands.
Richard M. Stallman <rms@gnu.org>
parents:
11563
diff
changeset
|
3079 previous sessions that you could recover from. |
d18ae33bb3b6
(multiple-recover, multiple-recover-finish): New commands.
Richard M. Stallman <rms@gnu.org>
parents:
11563
diff
changeset
|
3080 To choose one, move point to the proper line and then type C-c C-c. |
d18ae33bb3b6
(multiple-recover, multiple-recover-finish): New commands.
Richard M. Stallman <rms@gnu.org>
parents:
11563
diff
changeset
|
3081 Then you'll be asked about a number of files to recover." |
d18ae33bb3b6
(multiple-recover, multiple-recover-finish): New commands.
Richard M. Stallman <rms@gnu.org>
parents:
11563
diff
changeset
|
3082 (interactive) |
16372
e311d5372d8c
(recover-session): Error if session files turned off.
Richard M. Stallman <rms@gnu.org>
parents:
16334
diff
changeset
|
3083 (if (null auto-save-list-file-prefix) |
e311d5372d8c
(recover-session): Error if session files turned off.
Richard M. Stallman <rms@gnu.org>
parents:
16334
diff
changeset
|
3084 (error "You set `auto-save-list-file-prefix' to disable making session files")) |
32138 | 3085 (let ((dir (file-name-directory auto-save-list-file-prefix))) |
3086 (unless (file-directory-p dir) | |
3087 (make-directory dir t))) | |
13879
4888716715e0
(wildcard-to-regexp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13857
diff
changeset
|
3088 (let ((ls-lisp-support-shell-wildcards t)) |
17208
67515c200d09
(recover-session): Add `t' to switches.
Richard M. Stallman <rms@gnu.org>
parents:
17004
diff
changeset
|
3089 (dired (concat auto-save-list-file-prefix "*") |
67515c200d09
(recover-session): Add `t' to switches.
Richard M. Stallman <rms@gnu.org>
parents:
17004
diff
changeset
|
3090 (concat dired-listing-switches "t"))) |
23989
38295026616a
(recover-session): Preserve point when inserting
Andreas Schwab <schwab@suse.de>
parents:
23983
diff
changeset
|
3091 (save-excursion |
38295026616a
(recover-session): Preserve point when inserting
Andreas Schwab <schwab@suse.de>
parents:
23983
diff
changeset
|
3092 (goto-char (point-min)) |
38295026616a
(recover-session): Preserve point when inserting
Andreas Schwab <schwab@suse.de>
parents:
23983
diff
changeset
|
3093 (or (looking-at " Move to the session you want to recover,") |
38295026616a
(recover-session): Preserve point when inserting
Andreas Schwab <schwab@suse.de>
parents:
23983
diff
changeset
|
3094 (let ((inhibit-read-only t)) |
38295026616a
(recover-session): Preserve point when inserting
Andreas Schwab <schwab@suse.de>
parents:
23983
diff
changeset
|
3095 ;; Each line starts with a space |
38295026616a
(recover-session): Preserve point when inserting
Andreas Schwab <schwab@suse.de>
parents:
23983
diff
changeset
|
3096 ;; so that Font Lock mode won't highlight the first character. |
38295026616a
(recover-session): Preserve point when inserting
Andreas Schwab <schwab@suse.de>
parents:
23983
diff
changeset
|
3097 (insert " Move to the session you want to recover,\n" |
38295026616a
(recover-session): Preserve point when inserting
Andreas Schwab <schwab@suse.de>
parents:
23983
diff
changeset
|
3098 " then type C-c C-c to select it.\n\n" |
38295026616a
(recover-session): Preserve point when inserting
Andreas Schwab <schwab@suse.de>
parents:
23983
diff
changeset
|
3099 " You can also delete some of these files;\n" |
38295026616a
(recover-session): Preserve point when inserting
Andreas Schwab <schwab@suse.de>
parents:
23983
diff
changeset
|
3100 " type d on a line to mark that file for deletion.\n\n")))) |
11630
d18ae33bb3b6
(multiple-recover, multiple-recover-finish): New commands.
Richard M. Stallman <rms@gnu.org>
parents:
11563
diff
changeset
|
3101 (use-local-map (nconc (make-sparse-keymap) (current-local-map))) |
12050
b740095d6a47
(multiple-recover-finish): Renamed to recover-session-finish.
Roland McGrath <roland@gnu.org>
parents:
11995
diff
changeset
|
3102 (define-key (current-local-map) "\C-c\C-c" 'recover-session-finish)) |
11630
d18ae33bb3b6
(multiple-recover, multiple-recover-finish): New commands.
Richard M. Stallman <rms@gnu.org>
parents:
11563
diff
changeset
|
3103 |
12050
b740095d6a47
(multiple-recover-finish): Renamed to recover-session-finish.
Roland McGrath <roland@gnu.org>
parents:
11995
diff
changeset
|
3104 (defun recover-session-finish () |
11630
d18ae33bb3b6
(multiple-recover, multiple-recover-finish): New commands.
Richard M. Stallman <rms@gnu.org>
parents:
11563
diff
changeset
|
3105 "Choose one saved session to recover auto-save files from. |
d18ae33bb3b6
(multiple-recover, multiple-recover-finish): New commands.
Richard M. Stallman <rms@gnu.org>
parents:
11563
diff
changeset
|
3106 This command is used in the special Dired buffer created by |
12050
b740095d6a47
(multiple-recover-finish): Renamed to recover-session-finish.
Roland McGrath <roland@gnu.org>
parents:
11995
diff
changeset
|
3107 \\[recover-session]." |
11630
d18ae33bb3b6
(multiple-recover, multiple-recover-finish): New commands.
Richard M. Stallman <rms@gnu.org>
parents:
11563
diff
changeset
|
3108 (interactive) |
d18ae33bb3b6
(multiple-recover, multiple-recover-finish): New commands.
Richard M. Stallman <rms@gnu.org>
parents:
11563
diff
changeset
|
3109 ;; Get the name of the session file to recover from. |
d18ae33bb3b6
(multiple-recover, multiple-recover-finish): New commands.
Richard M. Stallman <rms@gnu.org>
parents:
11563
diff
changeset
|
3110 (let ((file (dired-get-filename)) |
13115
b4601a8c1e5c
(recover-session-finish): Ask only about files that
Richard M. Stallman <rms@gnu.org>
parents:
13095
diff
changeset
|
3111 files |
11630
d18ae33bb3b6
(multiple-recover, multiple-recover-finish): New commands.
Richard M. Stallman <rms@gnu.org>
parents:
11563
diff
changeset
|
3112 (buffer (get-buffer-create " *recover*"))) |
22084
08f31e440c92
(system-tmp-directory): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
22026
diff
changeset
|
3113 (dired-unmark 1) |
12740
8b44b70e655d
(recover-session): Mention deletion is possible.
Richard M. Stallman <rms@gnu.org>
parents:
12719
diff
changeset
|
3114 (dired-do-flagged-delete t) |
11630
d18ae33bb3b6
(multiple-recover, multiple-recover-finish): New commands.
Richard M. Stallman <rms@gnu.org>
parents:
11563
diff
changeset
|
3115 (unwind-protect |
d18ae33bb3b6
(multiple-recover, multiple-recover-finish): New commands.
Richard M. Stallman <rms@gnu.org>
parents:
11563
diff
changeset
|
3116 (save-excursion |
d18ae33bb3b6
(multiple-recover, multiple-recover-finish): New commands.
Richard M. Stallman <rms@gnu.org>
parents:
11563
diff
changeset
|
3117 ;; Read in the auto-save-list file. |
d18ae33bb3b6
(multiple-recover, multiple-recover-finish): New commands.
Richard M. Stallman <rms@gnu.org>
parents:
11563
diff
changeset
|
3118 (set-buffer buffer) |
d18ae33bb3b6
(multiple-recover, multiple-recover-finish): New commands.
Richard M. Stallman <rms@gnu.org>
parents:
11563
diff
changeset
|
3119 (erase-buffer) |
d18ae33bb3b6
(multiple-recover, multiple-recover-finish): New commands.
Richard M. Stallman <rms@gnu.org>
parents:
11563
diff
changeset
|
3120 (insert-file-contents file) |
13115
b4601a8c1e5c
(recover-session-finish): Ask only about files that
Richard M. Stallman <rms@gnu.org>
parents:
13095
diff
changeset
|
3121 ;; Loop thru the text of that file |
b4601a8c1e5c
(recover-session-finish): Ask only about files that
Richard M. Stallman <rms@gnu.org>
parents:
13095
diff
changeset
|
3122 ;; and get out the names of the files to recover. |
b4601a8c1e5c
(recover-session-finish): Ask only about files that
Richard M. Stallman <rms@gnu.org>
parents:
13095
diff
changeset
|
3123 (while (not (eobp)) |
b4601a8c1e5c
(recover-session-finish): Ask only about files that
Richard M. Stallman <rms@gnu.org>
parents:
13095
diff
changeset
|
3124 (let (thisfile autofile) |
b4601a8c1e5c
(recover-session-finish): Ask only about files that
Richard M. Stallman <rms@gnu.org>
parents:
13095
diff
changeset
|
3125 (if (eolp) |
b4601a8c1e5c
(recover-session-finish): Ask only about files that
Richard M. Stallman <rms@gnu.org>
parents:
13095
diff
changeset
|
3126 ;; This is a pair of lines for a non-file-visiting buffer. |
b4601a8c1e5c
(recover-session-finish): Ask only about files that
Richard M. Stallman <rms@gnu.org>
parents:
13095
diff
changeset
|
3127 ;; Get the auto-save file name and manufacture |
b4601a8c1e5c
(recover-session-finish): Ask only about files that
Richard M. Stallman <rms@gnu.org>
parents:
13095
diff
changeset
|
3128 ;; a "visited file name" from that. |
b4601a8c1e5c
(recover-session-finish): Ask only about files that
Richard M. Stallman <rms@gnu.org>
parents:
13095
diff
changeset
|
3129 (progn |
b4601a8c1e5c
(recover-session-finish): Ask only about files that
Richard M. Stallman <rms@gnu.org>
parents:
13095
diff
changeset
|
3130 (forward-line 1) |
b4601a8c1e5c
(recover-session-finish): Ask only about files that
Richard M. Stallman <rms@gnu.org>
parents:
13095
diff
changeset
|
3131 (setq autofile |
b4601a8c1e5c
(recover-session-finish): Ask only about files that
Richard M. Stallman <rms@gnu.org>
parents:
13095
diff
changeset
|
3132 (buffer-substring-no-properties |
b4601a8c1e5c
(recover-session-finish): Ask only about files that
Richard M. Stallman <rms@gnu.org>
parents:
13095
diff
changeset
|
3133 (point) |
b4601a8c1e5c
(recover-session-finish): Ask only about files that
Richard M. Stallman <rms@gnu.org>
parents:
13095
diff
changeset
|
3134 (save-excursion |
b4601a8c1e5c
(recover-session-finish): Ask only about files that
Richard M. Stallman <rms@gnu.org>
parents:
13095
diff
changeset
|
3135 (end-of-line) |
b4601a8c1e5c
(recover-session-finish): Ask only about files that
Richard M. Stallman <rms@gnu.org>
parents:
13095
diff
changeset
|
3136 (point)))) |
b4601a8c1e5c
(recover-session-finish): Ask only about files that
Richard M. Stallman <rms@gnu.org>
parents:
13095
diff
changeset
|
3137 (setq thisfile |
b4601a8c1e5c
(recover-session-finish): Ask only about files that
Richard M. Stallman <rms@gnu.org>
parents:
13095
diff
changeset
|
3138 (expand-file-name |
b4601a8c1e5c
(recover-session-finish): Ask only about files that
Richard M. Stallman <rms@gnu.org>
parents:
13095
diff
changeset
|
3139 (substring |
b4601a8c1e5c
(recover-session-finish): Ask only about files that
Richard M. Stallman <rms@gnu.org>
parents:
13095
diff
changeset
|
3140 (file-name-nondirectory autofile) |
b4601a8c1e5c
(recover-session-finish): Ask only about files that
Richard M. Stallman <rms@gnu.org>
parents:
13095
diff
changeset
|
3141 1 -1) |
b4601a8c1e5c
(recover-session-finish): Ask only about files that
Richard M. Stallman <rms@gnu.org>
parents:
13095
diff
changeset
|
3142 (file-name-directory autofile))) |
b4601a8c1e5c
(recover-session-finish): Ask only about files that
Richard M. Stallman <rms@gnu.org>
parents:
13095
diff
changeset
|
3143 (forward-line 1)) |
b4601a8c1e5c
(recover-session-finish): Ask only about files that
Richard M. Stallman <rms@gnu.org>
parents:
13095
diff
changeset
|
3144 ;; This pair of lines is a file-visiting |
b4601a8c1e5c
(recover-session-finish): Ask only about files that
Richard M. Stallman <rms@gnu.org>
parents:
13095
diff
changeset
|
3145 ;; buffer. Use the visited file name. |
b4601a8c1e5c
(recover-session-finish): Ask only about files that
Richard M. Stallman <rms@gnu.org>
parents:
13095
diff
changeset
|
3146 (progn |
b4601a8c1e5c
(recover-session-finish): Ask only about files that
Richard M. Stallman <rms@gnu.org>
parents:
13095
diff
changeset
|
3147 (setq thisfile |
b4601a8c1e5c
(recover-session-finish): Ask only about files that
Richard M. Stallman <rms@gnu.org>
parents:
13095
diff
changeset
|
3148 (buffer-substring-no-properties |
b4601a8c1e5c
(recover-session-finish): Ask only about files that
Richard M. Stallman <rms@gnu.org>
parents:
13095
diff
changeset
|
3149 (point) (progn (end-of-line) (point)))) |
b4601a8c1e5c
(recover-session-finish): Ask only about files that
Richard M. Stallman <rms@gnu.org>
parents:
13095
diff
changeset
|
3150 (forward-line 1) |
b4601a8c1e5c
(recover-session-finish): Ask only about files that
Richard M. Stallman <rms@gnu.org>
parents:
13095
diff
changeset
|
3151 (setq autofile |
b4601a8c1e5c
(recover-session-finish): Ask only about files that
Richard M. Stallman <rms@gnu.org>
parents:
13095
diff
changeset
|
3152 (buffer-substring-no-properties |
b4601a8c1e5c
(recover-session-finish): Ask only about files that
Richard M. Stallman <rms@gnu.org>
parents:
13095
diff
changeset
|
3153 (point) (progn (end-of-line) (point)))) |
b4601a8c1e5c
(recover-session-finish): Ask only about files that
Richard M. Stallman <rms@gnu.org>
parents:
13095
diff
changeset
|
3154 (forward-line 1))) |
b4601a8c1e5c
(recover-session-finish): Ask only about files that
Richard M. Stallman <rms@gnu.org>
parents:
13095
diff
changeset
|
3155 ;; Ignore a file if its auto-save file does not exist now. |
b4601a8c1e5c
(recover-session-finish): Ask only about files that
Richard M. Stallman <rms@gnu.org>
parents:
13095
diff
changeset
|
3156 (if (file-exists-p autofile) |
b4601a8c1e5c
(recover-session-finish): Ask only about files that
Richard M. Stallman <rms@gnu.org>
parents:
13095
diff
changeset
|
3157 (setq files (cons thisfile files))))) |
b4601a8c1e5c
(recover-session-finish): Ask only about files that
Richard M. Stallman <rms@gnu.org>
parents:
13095
diff
changeset
|
3158 (setq files (nreverse files)) |
12846
fc74ffbce5a9
(recover-file): It's ok if the visited file doesn't exist.
Richard M. Stallman <rms@gnu.org>
parents:
12740
diff
changeset
|
3159 ;; The file contains a pair of line for each auto-saved buffer. |
fc74ffbce5a9
(recover-file): It's ok if the visited file doesn't exist.
Richard M. Stallman <rms@gnu.org>
parents:
12740
diff
changeset
|
3160 ;; The first line of the pair contains the visited file name |
fc74ffbce5a9
(recover-file): It's ok if the visited file doesn't exist.
Richard M. Stallman <rms@gnu.org>
parents:
12740
diff
changeset
|
3161 ;; or is empty if the buffer was not visiting a file. |
fc74ffbce5a9
(recover-file): It's ok if the visited file doesn't exist.
Richard M. Stallman <rms@gnu.org>
parents:
12740
diff
changeset
|
3162 ;; The second line is the auto-save file name. |
13115
b4601a8c1e5c
(recover-session-finish): Ask only about files that
Richard M. Stallman <rms@gnu.org>
parents:
13095
diff
changeset
|
3163 (if files |
b4601a8c1e5c
(recover-session-finish): Ask only about files that
Richard M. Stallman <rms@gnu.org>
parents:
13095
diff
changeset
|
3164 (map-y-or-n-p "Recover %s? " |
b4601a8c1e5c
(recover-session-finish): Ask only about files that
Richard M. Stallman <rms@gnu.org>
parents:
13095
diff
changeset
|
3165 (lambda (file) |
b4601a8c1e5c
(recover-session-finish): Ask only about files that
Richard M. Stallman <rms@gnu.org>
parents:
13095
diff
changeset
|
3166 (condition-case nil |
b4601a8c1e5c
(recover-session-finish): Ask only about files that
Richard M. Stallman <rms@gnu.org>
parents:
13095
diff
changeset
|
3167 (save-excursion (recover-file file)) |
13832
44e936e550ae
(save-some-buffers): Don't give message if we queried.
Roland McGrath <roland@gnu.org>
parents:
13823
diff
changeset
|
3168 (error |
13115
b4601a8c1e5c
(recover-session-finish): Ask only about files that
Richard M. Stallman <rms@gnu.org>
parents:
13095
diff
changeset
|
3169 "Failed to recover `%s'" file))) |
b4601a8c1e5c
(recover-session-finish): Ask only about files that
Richard M. Stallman <rms@gnu.org>
parents:
13095
diff
changeset
|
3170 files |
b4601a8c1e5c
(recover-session-finish): Ask only about files that
Richard M. Stallman <rms@gnu.org>
parents:
13095
diff
changeset
|
3171 '("file" "files" "recover")) |
b4601a8c1e5c
(recover-session-finish): Ask only about files that
Richard M. Stallman <rms@gnu.org>
parents:
13095
diff
changeset
|
3172 (message "No files can be recovered from this session now"))) |
11630
d18ae33bb3b6
(multiple-recover, multiple-recover-finish): New commands.
Richard M. Stallman <rms@gnu.org>
parents:
11563
diff
changeset
|
3173 (kill-buffer buffer)))) |
d18ae33bb3b6
(multiple-recover, multiple-recover-finish): New commands.
Richard M. Stallman <rms@gnu.org>
parents:
11563
diff
changeset
|
3174 |
15963
5b10dc4cd791
(kill-some-buffers): New arg LIST says buffers to maybe kill.
Richard M. Stallman <rms@gnu.org>
parents:
15890
diff
changeset
|
3175 (defun kill-some-buffers (&optional list) |
5b10dc4cd791
(kill-some-buffers): New arg LIST says buffers to maybe kill.
Richard M. Stallman <rms@gnu.org>
parents:
15890
diff
changeset
|
3176 "For each buffer in LIST, ask whether to kill it. |
5b10dc4cd791
(kill-some-buffers): New arg LIST says buffers to maybe kill.
Richard M. Stallman <rms@gnu.org>
parents:
15890
diff
changeset
|
3177 LIST defaults to all existing live buffers." |
337 | 3178 (interactive) |
15963
5b10dc4cd791
(kill-some-buffers): New arg LIST says buffers to maybe kill.
Richard M. Stallman <rms@gnu.org>
parents:
15890
diff
changeset
|
3179 (if (null list) |
5b10dc4cd791
(kill-some-buffers): New arg LIST says buffers to maybe kill.
Richard M. Stallman <rms@gnu.org>
parents:
15890
diff
changeset
|
3180 (setq list (buffer-list))) |
5b10dc4cd791
(kill-some-buffers): New arg LIST says buffers to maybe kill.
Richard M. Stallman <rms@gnu.org>
parents:
15890
diff
changeset
|
3181 (while list |
5b10dc4cd791
(kill-some-buffers): New arg LIST says buffers to maybe kill.
Richard M. Stallman <rms@gnu.org>
parents:
15890
diff
changeset
|
3182 (let* ((buffer (car list)) |
5b10dc4cd791
(kill-some-buffers): New arg LIST says buffers to maybe kill.
Richard M. Stallman <rms@gnu.org>
parents:
15890
diff
changeset
|
3183 (name (buffer-name buffer))) |
5b10dc4cd791
(kill-some-buffers): New arg LIST says buffers to maybe kill.
Richard M. Stallman <rms@gnu.org>
parents:
15890
diff
changeset
|
3184 (and (not (string-equal name "")) |
5b10dc4cd791
(kill-some-buffers): New arg LIST says buffers to maybe kill.
Richard M. Stallman <rms@gnu.org>
parents:
15890
diff
changeset
|
3185 (/= (aref name 0) ? ) |
5b10dc4cd791
(kill-some-buffers): New arg LIST says buffers to maybe kill.
Richard M. Stallman <rms@gnu.org>
parents:
15890
diff
changeset
|
3186 (yes-or-no-p |
5b10dc4cd791
(kill-some-buffers): New arg LIST says buffers to maybe kill.
Richard M. Stallman <rms@gnu.org>
parents:
15890
diff
changeset
|
3187 (format "Buffer %s %s. Kill? " |
5b10dc4cd791
(kill-some-buffers): New arg LIST says buffers to maybe kill.
Richard M. Stallman <rms@gnu.org>
parents:
15890
diff
changeset
|
3188 name |
5b10dc4cd791
(kill-some-buffers): New arg LIST says buffers to maybe kill.
Richard M. Stallman <rms@gnu.org>
parents:
15890
diff
changeset
|
3189 (if (buffer-modified-p buffer) |
5b10dc4cd791
(kill-some-buffers): New arg LIST says buffers to maybe kill.
Richard M. Stallman <rms@gnu.org>
parents:
15890
diff
changeset
|
3190 "HAS BEEN EDITED" "is unmodified"))) |
5b10dc4cd791
(kill-some-buffers): New arg LIST says buffers to maybe kill.
Richard M. Stallman <rms@gnu.org>
parents:
15890
diff
changeset
|
3191 (kill-buffer buffer))) |
5b10dc4cd791
(kill-some-buffers): New arg LIST says buffers to maybe kill.
Richard M. Stallman <rms@gnu.org>
parents:
15890
diff
changeset
|
3192 (setq list (cdr list)))) |
337 | 3193 |
3194 (defun auto-save-mode (arg) | |
3195 "Toggle auto-saving of contents of current buffer. | |
1395
f6f838c4a26e
(buffer-file-number): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
1371
diff
changeset
|
3196 With prefix argument ARG, turn auto-saving on if positive, else off." |
337 | 3197 (interactive "P") |
3198 (setq buffer-auto-save-file-name | |
3199 (and (if (null arg) | |
8158
a6fa25ffa764
(auto-save-mode): If autosave is off because buffer has
Richard M. Stallman <rms@gnu.org>
parents:
8157
diff
changeset
|
3200 (or (not buffer-auto-save-file-name) |
23382 | 3201 ;; If auto-save is off because buffer has shrunk, |
8158
a6fa25ffa764
(auto-save-mode): If autosave is off because buffer has
Richard M. Stallman <rms@gnu.org>
parents:
8157
diff
changeset
|
3202 ;; then toggling should turn it on. |
a6fa25ffa764
(auto-save-mode): If autosave is off because buffer has
Richard M. Stallman <rms@gnu.org>
parents:
8157
diff
changeset
|
3203 (< buffer-saved-size 0)) |
337 | 3204 (or (eq arg t) (listp arg) (and (integerp arg) (> arg 0)))) |
3205 (if (and buffer-file-name auto-save-visited-file-name | |
3206 (not buffer-read-only)) | |
3207 buffer-file-name | |
3208 (make-auto-save-file-name)))) | |
6677
3c7e3d1cc3ad
(auto-save-mode): Don't let buffer-saved-size stay negative.
Richard M. Stallman <rms@gnu.org>
parents:
6664
diff
changeset
|
3209 ;; If -1 was stored here, to temporarily turn off saving, |
3c7e3d1cc3ad
(auto-save-mode): Don't let buffer-saved-size stay negative.
Richard M. Stallman <rms@gnu.org>
parents:
6664
diff
changeset
|
3210 ;; turn it back on. |
3c7e3d1cc3ad
(auto-save-mode): Don't let buffer-saved-size stay negative.
Richard M. Stallman <rms@gnu.org>
parents:
6664
diff
changeset
|
3211 (and (< buffer-saved-size 0) |
3c7e3d1cc3ad
(auto-save-mode): Don't let buffer-saved-size stay negative.
Richard M. Stallman <rms@gnu.org>
parents:
6664
diff
changeset
|
3212 (setq buffer-saved-size 0)) |
337 | 3213 (if (interactive-p) |
3214 (message "Auto-save %s (in this buffer)" | |
3215 (if buffer-auto-save-file-name "on" "off"))) | |
3216 buffer-auto-save-file-name) | |
3217 | |
3218 (defun rename-auto-save-file () | |
3219 "Adjust current buffer's auto save file name for current conditions. | |
3220 Also rename any existing auto save file, if it was made in this session." | |
3221 (let ((osave buffer-auto-save-file-name)) | |
3222 (setq buffer-auto-save-file-name | |
3223 (make-auto-save-file-name)) | |
3224 (if (and osave buffer-auto-save-file-name | |
3225 (not (string= buffer-auto-save-file-name buffer-file-name)) | |
3226 (not (string= buffer-auto-save-file-name osave)) | |
3227 (file-exists-p osave) | |
3228 (recent-auto-save-p)) | |
3229 (rename-file osave buffer-auto-save-file-name t)))) | |
3230 | |
3231 (defun make-auto-save-file-name () | |
3232 "Return file name to use for auto-saves of current buffer. | |
3233 Does not consider `auto-save-visited-file-name' as that variable is checked | |
3234 before calling this function. You can redefine this for customization. | |
3235 See also `auto-save-file-name-p'." | |
3236 (if buffer-file-name | |
32138 | 3237 (let ((list auto-save-file-name-transforms) |
3238 (filename buffer-file-name) | |
3239 result) | |
3240 ;; Apply user-specified translations | |
3241 ;; to the file name. | |
3242 (while (and list (not result)) | |
3243 (if (string-match (car (car list)) filename) | |
3244 (setq result (replace-match (cadr (car list)) t nil | |
3245 filename))) | |
3246 (setq list (cdr list))) | |
3247 (if result (setq filename result)) | |
3248 | |
3249 (if (and (eq system-type 'ms-dos) | |
3250 (not (msdos-long-file-names))) | |
3251 (let ((fn (file-name-nondirectory buffer-file-name))) | |
3252 (string-match "\\`\\([^.]+\\)\\(\\.\\(..?\\)?.?\\|\\)\\'" fn) | |
3253 (concat (file-name-directory buffer-file-name) | |
3254 "#" (match-string 1 fn) | |
3255 "." (match-string 3 fn) "#")) | |
3256 (concat (file-name-directory filename) | |
3257 "#" | |
3258 (file-name-nondirectory filename) | |
3259 "#"))) | |
7944
a114bbe9a63c
(make-auto-save-file-name): Convert slashes to \! and double the backslashes.
Richard M. Stallman <rms@gnu.org>
parents:
7895
diff
changeset
|
3260 |
a114bbe9a63c
(make-auto-save-file-name): Convert slashes to \! and double the backslashes.
Richard M. Stallman <rms@gnu.org>
parents:
7895
diff
changeset
|
3261 ;; Deal with buffers that don't have any associated files. (Mail |
a114bbe9a63c
(make-auto-save-file-name): Convert slashes to \! and double the backslashes.
Richard M. Stallman <rms@gnu.org>
parents:
7895
diff
changeset
|
3262 ;; mode tends to create a good number of these.) |
a114bbe9a63c
(make-auto-save-file-name): Convert slashes to \! and double the backslashes.
Richard M. Stallman <rms@gnu.org>
parents:
7895
diff
changeset
|
3263 |
7895
fac7ff0a7aeb
(make-auto-save-file-name): Don't use slashes in autosave name for a non-file
Karl Heuer <kwzh@gnu.org>
parents:
7730
diff
changeset
|
3264 (let ((buffer-name (buffer-name)) |
7944
a114bbe9a63c
(make-auto-save-file-name): Convert slashes to \! and double the backslashes.
Richard M. Stallman <rms@gnu.org>
parents:
7895
diff
changeset
|
3265 (limit 0)) |
17256
d8e38cfca028
(make-auto-save-file-name): Replace both / and \
Richard M. Stallman <rms@gnu.org>
parents:
17208
diff
changeset
|
3266 ;; Eliminate all slashes and backslashes by |
d8e38cfca028
(make-auto-save-file-name): Replace both / and \
Richard M. Stallman <rms@gnu.org>
parents:
17208
diff
changeset
|
3267 ;; replacing them with sequences that start with %. |
d8e38cfca028
(make-auto-save-file-name): Replace both / and \
Richard M. Stallman <rms@gnu.org>
parents:
17208
diff
changeset
|
3268 ;; Quote % also, to keep distinct names distinct. |
d8e38cfca028
(make-auto-save-file-name): Replace both / and \
Richard M. Stallman <rms@gnu.org>
parents:
17208
diff
changeset
|
3269 (while (string-match "[/\\%]" buffer-name limit) |
d8e38cfca028
(make-auto-save-file-name): Replace both / and \
Richard M. Stallman <rms@gnu.org>
parents:
17208
diff
changeset
|
3270 (let* ((character (aref buffer-name (match-beginning 0))) |
d8e38cfca028
(make-auto-save-file-name): Replace both / and \
Richard M. Stallman <rms@gnu.org>
parents:
17208
diff
changeset
|
3271 (replacement |
d8e38cfca028
(make-auto-save-file-name): Replace both / and \
Richard M. Stallman <rms@gnu.org>
parents:
17208
diff
changeset
|
3272 (cond ((eq character ?%) "%%") |
d8e38cfca028
(make-auto-save-file-name): Replace both / and \
Richard M. Stallman <rms@gnu.org>
parents:
17208
diff
changeset
|
3273 ((eq character ?/) "%+") |
d8e38cfca028
(make-auto-save-file-name): Replace both / and \
Richard M. Stallman <rms@gnu.org>
parents:
17208
diff
changeset
|
3274 ((eq character ?\\) "%-")))) |
d8e38cfca028
(make-auto-save-file-name): Replace both / and \
Richard M. Stallman <rms@gnu.org>
parents:
17208
diff
changeset
|
3275 (setq buffer-name (replace-match replacement t t buffer-name)) |
d8e38cfca028
(make-auto-save-file-name): Replace both / and \
Richard M. Stallman <rms@gnu.org>
parents:
17208
diff
changeset
|
3276 (setq limit (1+ (match-end 0))))) |
16015
f51aa92862ac
(make-auto-save-file-name): Try a few directories
Richard M. Stallman <rms@gnu.org>
parents:
15963
diff
changeset
|
3277 ;; Generate the file name. |
f51aa92862ac
(make-auto-save-file-name): Try a few directories
Richard M. Stallman <rms@gnu.org>
parents:
15963
diff
changeset
|
3278 (expand-file-name |
f51aa92862ac
(make-auto-save-file-name): Try a few directories
Richard M. Stallman <rms@gnu.org>
parents:
15963
diff
changeset
|
3279 (format "#%s#%s#" buffer-name (make-temp-name "")) |
f51aa92862ac
(make-auto-save-file-name): Try a few directories
Richard M. Stallman <rms@gnu.org>
parents:
15963
diff
changeset
|
3280 ;; Try a few alternative directories, to get one we can write it. |
f51aa92862ac
(make-auto-save-file-name): Try a few directories
Richard M. Stallman <rms@gnu.org>
parents:
15963
diff
changeset
|
3281 (cond |
f51aa92862ac
(make-auto-save-file-name): Try a few directories
Richard M. Stallman <rms@gnu.org>
parents:
15963
diff
changeset
|
3282 ((file-writable-p default-directory) default-directory) |
f51aa92862ac
(make-auto-save-file-name): Try a few directories
Richard M. Stallman <rms@gnu.org>
parents:
15963
diff
changeset
|
3283 ((file-writable-p "/var/tmp/") "/var/tmp/") |
f51aa92862ac
(make-auto-save-file-name): Try a few directories
Richard M. Stallman <rms@gnu.org>
parents:
15963
diff
changeset
|
3284 ("~/")))))) |
337 | 3285 |
3286 (defun auto-save-file-name-p (filename) | |
3287 "Return non-nil if FILENAME can be yielded by `make-auto-save-file-name'. | |
3288 FILENAME should lack slashes. You can redefine this for customization." | |
3289 (string-match "^#.*#$" filename)) | |
3290 | |
13879
4888716715e0
(wildcard-to-regexp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13857
diff
changeset
|
3291 (defun wildcard-to-regexp (wildcard) |
4888716715e0
(wildcard-to-regexp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13857
diff
changeset
|
3292 "Given a shell file name pattern WILDCARD, return an equivalent regexp. |
4888716715e0
(wildcard-to-regexp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13857
diff
changeset
|
3293 The generated regexp will match a filename iff the filename |
4888716715e0
(wildcard-to-regexp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13857
diff
changeset
|
3294 matches that wildcard according to shell rules. Only wildcards known |
4888716715e0
(wildcard-to-regexp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13857
diff
changeset
|
3295 by `sh' are supported." |
4888716715e0
(wildcard-to-regexp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13857
diff
changeset
|
3296 (let* ((i (string-match "[[.*+\\^$?]" wildcard)) |
4888716715e0
(wildcard-to-regexp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13857
diff
changeset
|
3297 ;; Copy the initial run of non-special characters. |
4888716715e0
(wildcard-to-regexp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13857
diff
changeset
|
3298 (result (substring wildcard 0 i)) |
4888716715e0
(wildcard-to-regexp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13857
diff
changeset
|
3299 (len (length wildcard))) |
4888716715e0
(wildcard-to-regexp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13857
diff
changeset
|
3300 ;; If no special characters, we're almost done. |
4888716715e0
(wildcard-to-regexp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13857
diff
changeset
|
3301 (if i |
4888716715e0
(wildcard-to-regexp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13857
diff
changeset
|
3302 (while (< i len) |
4888716715e0
(wildcard-to-regexp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13857
diff
changeset
|
3303 (let ((ch (aref wildcard i)) |
4888716715e0
(wildcard-to-regexp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13857
diff
changeset
|
3304 j) |
4888716715e0
(wildcard-to-regexp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13857
diff
changeset
|
3305 (setq |
4888716715e0
(wildcard-to-regexp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13857
diff
changeset
|
3306 result |
4888716715e0
(wildcard-to-regexp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13857
diff
changeset
|
3307 (concat result |
4888716715e0
(wildcard-to-regexp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13857
diff
changeset
|
3308 (cond |
16544
9fffc9e5fc42
(revert-buffer): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
16477
diff
changeset
|
3309 ((and (eq ch ?\[) |
9fffc9e5fc42
(revert-buffer): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
16477
diff
changeset
|
3310 (< (1+ i) len) |
9fffc9e5fc42
(revert-buffer): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
16477
diff
changeset
|
3311 (eq (aref wildcard (1+ i)) ?\])) |
9fffc9e5fc42
(revert-buffer): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
16477
diff
changeset
|
3312 "\\[") |
13879
4888716715e0
(wildcard-to-regexp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13857
diff
changeset
|
3313 ((eq ch ?\[) ; [...] maps to regexp char class |
4888716715e0
(wildcard-to-regexp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13857
diff
changeset
|
3314 (progn |
4888716715e0
(wildcard-to-regexp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13857
diff
changeset
|
3315 (setq i (1+ i)) |
4888716715e0
(wildcard-to-regexp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13857
diff
changeset
|
3316 (concat |
4888716715e0
(wildcard-to-regexp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13857
diff
changeset
|
3317 (cond |
4888716715e0
(wildcard-to-regexp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13857
diff
changeset
|
3318 ((eq (aref wildcard i) ?!) ; [!...] -> [^...] |
4888716715e0
(wildcard-to-regexp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13857
diff
changeset
|
3319 (progn |
4888716715e0
(wildcard-to-regexp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13857
diff
changeset
|
3320 (setq i (1+ i)) |
4888716715e0
(wildcard-to-regexp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13857
diff
changeset
|
3321 (if (eq (aref wildcard i) ?\]) |
4888716715e0
(wildcard-to-regexp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13857
diff
changeset
|
3322 (progn |
4888716715e0
(wildcard-to-regexp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13857
diff
changeset
|
3323 (setq i (1+ i)) |
4888716715e0
(wildcard-to-regexp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13857
diff
changeset
|
3324 "[^]") |
4888716715e0
(wildcard-to-regexp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13857
diff
changeset
|
3325 "[^"))) |
4888716715e0
(wildcard-to-regexp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13857
diff
changeset
|
3326 ((eq (aref wildcard i) ?^) |
4888716715e0
(wildcard-to-regexp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13857
diff
changeset
|
3327 ;; Found "[^". Insert a `\0' character |
4888716715e0
(wildcard-to-regexp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13857
diff
changeset
|
3328 ;; (which cannot happen in a filename) |
4888716715e0
(wildcard-to-regexp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13857
diff
changeset
|
3329 ;; into the character class, so that `^' |
4888716715e0
(wildcard-to-regexp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13857
diff
changeset
|
3330 ;; is not the first character after `[', |
4888716715e0
(wildcard-to-regexp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13857
diff
changeset
|
3331 ;; and thus non-special in a regexp. |
4888716715e0
(wildcard-to-regexp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13857
diff
changeset
|
3332 (progn |
4888716715e0
(wildcard-to-regexp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13857
diff
changeset
|
3333 (setq i (1+ i)) |
4888716715e0
(wildcard-to-regexp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13857
diff
changeset
|
3334 "[\000^")) |
4888716715e0
(wildcard-to-regexp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13857
diff
changeset
|
3335 ((eq (aref wildcard i) ?\]) |
4888716715e0
(wildcard-to-regexp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13857
diff
changeset
|
3336 ;; I don't think `]' can appear in a |
4888716715e0
(wildcard-to-regexp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13857
diff
changeset
|
3337 ;; character class in a wildcard, but |
4888716715e0
(wildcard-to-regexp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13857
diff
changeset
|
3338 ;; let's be general here. |
4888716715e0
(wildcard-to-regexp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13857
diff
changeset
|
3339 (progn |
4888716715e0
(wildcard-to-regexp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13857
diff
changeset
|
3340 (setq i (1+ i)) |
4888716715e0
(wildcard-to-regexp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13857
diff
changeset
|
3341 "[]")) |
4888716715e0
(wildcard-to-regexp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13857
diff
changeset
|
3342 (t "[")) |
4888716715e0
(wildcard-to-regexp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13857
diff
changeset
|
3343 (prog1 ; copy everything upto next `]'. |
4888716715e0
(wildcard-to-regexp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13857
diff
changeset
|
3344 (substring wildcard |
4888716715e0
(wildcard-to-regexp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13857
diff
changeset
|
3345 i |
4888716715e0
(wildcard-to-regexp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13857
diff
changeset
|
3346 (setq j (string-match |
4888716715e0
(wildcard-to-regexp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13857
diff
changeset
|
3347 "]" wildcard i))) |
4888716715e0
(wildcard-to-regexp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13857
diff
changeset
|
3348 (setq i (if j (1- j) (1- len))))))) |
4888716715e0
(wildcard-to-regexp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13857
diff
changeset
|
3349 ((eq ch ?.) "\\.") |
4888716715e0
(wildcard-to-regexp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13857
diff
changeset
|
3350 ((eq ch ?*) "[^\000]*") |
4888716715e0
(wildcard-to-regexp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13857
diff
changeset
|
3351 ((eq ch ?+) "\\+") |
4888716715e0
(wildcard-to-regexp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13857
diff
changeset
|
3352 ((eq ch ?^) "\\^") |
4888716715e0
(wildcard-to-regexp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13857
diff
changeset
|
3353 ((eq ch ?$) "\\$") |
4888716715e0
(wildcard-to-regexp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13857
diff
changeset
|
3354 ((eq ch ?\\) "\\\\") ; probably cannot happen... |
4888716715e0
(wildcard-to-regexp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13857
diff
changeset
|
3355 ((eq ch ??) "[^\000]") |
4888716715e0
(wildcard-to-regexp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13857
diff
changeset
|
3356 (t (char-to-string ch))))) |
4888716715e0
(wildcard-to-regexp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13857
diff
changeset
|
3357 (setq i (1+ i))))) |
4888716715e0
(wildcard-to-regexp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13857
diff
changeset
|
3358 ;; Shell wildcards should match the entire filename, |
4888716715e0
(wildcard-to-regexp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13857
diff
changeset
|
3359 ;; not its part. Make the regexp say so. |
4888716715e0
(wildcard-to-regexp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13857
diff
changeset
|
3360 (concat "\\`" result "\\'"))) |
4888716715e0
(wildcard-to-regexp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
13857
diff
changeset
|
3361 |
17673
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
3362 (defcustom list-directory-brief-switches |
337 | 3363 (if (eq system-type 'vax-vms) "" "-CF") |
32138 | 3364 "*Switches for `list-directory' to pass to `ls' for brief listing." |
17673
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
3365 :type 'string |
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
3366 :group 'dired) |
337 | 3367 |
17673
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
3368 (defcustom list-directory-verbose-switches |
337 | 3369 (if (eq system-type 'vax-vms) |
3370 "/PROTECTION/SIZE/DATE/OWNER/WIDTH=(OWNER:10)" | |
3371 "-l") | |
32138 | 3372 "*Switches for `list-directory' to pass to `ls' for verbose listing." |
17673
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
3373 :type 'string |
ba2c70d76b5b
Use defgroup and defcustom.
Richard M. Stallman <rms@gnu.org>
parents:
17666
diff
changeset
|
3374 :group 'dired) |
337 | 3375 |
23473
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
3376 (defun file-expand-wildcards (pattern &optional full) |
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
3377 "Expand wildcard pattern PATTERN. |
23942
8fa87eee9ae5
(file-expand-wildcards): Handle wildcards in directory name.
Richard M. Stallman <rms@gnu.org>
parents:
23842
diff
changeset
|
3378 This returns a list of file names which match the pattern. |
8fa87eee9ae5
(file-expand-wildcards): Handle wildcards in directory name.
Richard M. Stallman <rms@gnu.org>
parents:
23842
diff
changeset
|
3379 |
8fa87eee9ae5
(file-expand-wildcards): Handle wildcards in directory name.
Richard M. Stallman <rms@gnu.org>
parents:
23842
diff
changeset
|
3380 If PATTERN is written as an absolute relative file name, |
8fa87eee9ae5
(file-expand-wildcards): Handle wildcards in directory name.
Richard M. Stallman <rms@gnu.org>
parents:
23842
diff
changeset
|
3381 the values are absolute also. |
8fa87eee9ae5
(file-expand-wildcards): Handle wildcards in directory name.
Richard M. Stallman <rms@gnu.org>
parents:
23842
diff
changeset
|
3382 |
8fa87eee9ae5
(file-expand-wildcards): Handle wildcards in directory name.
Richard M. Stallman <rms@gnu.org>
parents:
23842
diff
changeset
|
3383 If PATTERN is written as a relative file name, it is interpreted |
8fa87eee9ae5
(file-expand-wildcards): Handle wildcards in directory name.
Richard M. Stallman <rms@gnu.org>
parents:
23842
diff
changeset
|
3384 relative to the current default directory, `default-directory'. |
8fa87eee9ae5
(file-expand-wildcards): Handle wildcards in directory name.
Richard M. Stallman <rms@gnu.org>
parents:
23842
diff
changeset
|
3385 The file names returned are normally also relative to the current |
8fa87eee9ae5
(file-expand-wildcards): Handle wildcards in directory name.
Richard M. Stallman <rms@gnu.org>
parents:
23842
diff
changeset
|
3386 default directory. However, if FULL is non-nil, they are absolute." |
8fa87eee9ae5
(file-expand-wildcards): Handle wildcards in directory name.
Richard M. Stallman <rms@gnu.org>
parents:
23842
diff
changeset
|
3387 (let* ((nondir (file-name-nondirectory pattern)) |
8fa87eee9ae5
(file-expand-wildcards): Handle wildcards in directory name.
Richard M. Stallman <rms@gnu.org>
parents:
23842
diff
changeset
|
3388 (dirpart (file-name-directory pattern)) |
8fa87eee9ae5
(file-expand-wildcards): Handle wildcards in directory name.
Richard M. Stallman <rms@gnu.org>
parents:
23842
diff
changeset
|
3389 ;; A list of all dirs that DIRPART specifies. |
8fa87eee9ae5
(file-expand-wildcards): Handle wildcards in directory name.
Richard M. Stallman <rms@gnu.org>
parents:
23842
diff
changeset
|
3390 ;; This can be more than one dir |
8fa87eee9ae5
(file-expand-wildcards): Handle wildcards in directory name.
Richard M. Stallman <rms@gnu.org>
parents:
23842
diff
changeset
|
3391 ;; if DIRPART contains wildcards. |
24217
37a08636670b
(file-expand-wildcards): Never consider `.' and `..' a
Andreas Schwab <schwab@suse.de>
parents:
24167
diff
changeset
|
3392 (dirs (if (and dirpart (string-match "[[*?]" dirpart)) |
23942
8fa87eee9ae5
(file-expand-wildcards): Handle wildcards in directory name.
Richard M. Stallman <rms@gnu.org>
parents:
23842
diff
changeset
|
3393 (mapcar 'file-name-as-directory |
8fa87eee9ae5
(file-expand-wildcards): Handle wildcards in directory name.
Richard M. Stallman <rms@gnu.org>
parents:
23842
diff
changeset
|
3394 (file-expand-wildcards (directory-file-name dirpart))) |
8fa87eee9ae5
(file-expand-wildcards): Handle wildcards in directory name.
Richard M. Stallman <rms@gnu.org>
parents:
23842
diff
changeset
|
3395 (list dirpart))) |
8fa87eee9ae5
(file-expand-wildcards): Handle wildcards in directory name.
Richard M. Stallman <rms@gnu.org>
parents:
23842
diff
changeset
|
3396 contents) |
8fa87eee9ae5
(file-expand-wildcards): Handle wildcards in directory name.
Richard M. Stallman <rms@gnu.org>
parents:
23842
diff
changeset
|
3397 (while dirs |
8fa87eee9ae5
(file-expand-wildcards): Handle wildcards in directory name.
Richard M. Stallman <rms@gnu.org>
parents:
23842
diff
changeset
|
3398 (when (or (null (car dirs)) ; Possible if DIRPART is not wild. |
8fa87eee9ae5
(file-expand-wildcards): Handle wildcards in directory name.
Richard M. Stallman <rms@gnu.org>
parents:
23842
diff
changeset
|
3399 (file-directory-p (directory-file-name (car dirs)))) |
8fa87eee9ae5
(file-expand-wildcards): Handle wildcards in directory name.
Richard M. Stallman <rms@gnu.org>
parents:
23842
diff
changeset
|
3400 (let ((this-dir-contents |
24217
37a08636670b
(file-expand-wildcards): Never consider `.' and `..' a
Andreas Schwab <schwab@suse.de>
parents:
24167
diff
changeset
|
3401 ;; Filter out "." and ".." |
37a08636670b
(file-expand-wildcards): Never consider `.' and `..' a
Andreas Schwab <schwab@suse.de>
parents:
24167
diff
changeset
|
3402 (delq nil |
37a08636670b
(file-expand-wildcards): Never consider `.' and `..' a
Andreas Schwab <schwab@suse.de>
parents:
24167
diff
changeset
|
3403 (mapcar #'(lambda (name) |
37a08636670b
(file-expand-wildcards): Never consider `.' and `..' a
Andreas Schwab <schwab@suse.de>
parents:
24167
diff
changeset
|
3404 (unless (string-match "\\`\\.\\.?\\'" |
37a08636670b
(file-expand-wildcards): Never consider `.' and `..' a
Andreas Schwab <schwab@suse.de>
parents:
24167
diff
changeset
|
3405 (file-name-nondirectory name)) |
37a08636670b
(file-expand-wildcards): Never consider `.' and `..' a
Andreas Schwab <schwab@suse.de>
parents:
24167
diff
changeset
|
3406 name)) |
37a08636670b
(file-expand-wildcards): Never consider `.' and `..' a
Andreas Schwab <schwab@suse.de>
parents:
24167
diff
changeset
|
3407 (directory-files (or (car dirs) ".") full |
37a08636670b
(file-expand-wildcards): Never consider `.' and `..' a
Andreas Schwab <schwab@suse.de>
parents:
24167
diff
changeset
|
3408 (wildcard-to-regexp nondir)))))) |
23942
8fa87eee9ae5
(file-expand-wildcards): Handle wildcards in directory name.
Richard M. Stallman <rms@gnu.org>
parents:
23842
diff
changeset
|
3409 (setq contents |
8fa87eee9ae5
(file-expand-wildcards): Handle wildcards in directory name.
Richard M. Stallman <rms@gnu.org>
parents:
23842
diff
changeset
|
3410 (nconc |
8fa87eee9ae5
(file-expand-wildcards): Handle wildcards in directory name.
Richard M. Stallman <rms@gnu.org>
parents:
23842
diff
changeset
|
3411 (if (and (car dirs) (not full)) |
8fa87eee9ae5
(file-expand-wildcards): Handle wildcards in directory name.
Richard M. Stallman <rms@gnu.org>
parents:
23842
diff
changeset
|
3412 (mapcar (function (lambda (name) (concat (car dirs) name))) |
8fa87eee9ae5
(file-expand-wildcards): Handle wildcards in directory name.
Richard M. Stallman <rms@gnu.org>
parents:
23842
diff
changeset
|
3413 this-dir-contents) |
8fa87eee9ae5
(file-expand-wildcards): Handle wildcards in directory name.
Richard M. Stallman <rms@gnu.org>
parents:
23842
diff
changeset
|
3414 this-dir-contents) |
8fa87eee9ae5
(file-expand-wildcards): Handle wildcards in directory name.
Richard M. Stallman <rms@gnu.org>
parents:
23842
diff
changeset
|
3415 contents)))) |
8fa87eee9ae5
(file-expand-wildcards): Handle wildcards in directory name.
Richard M. Stallman <rms@gnu.org>
parents:
23842
diff
changeset
|
3416 (setq dirs (cdr dirs))) |
8fa87eee9ae5
(file-expand-wildcards): Handle wildcards in directory name.
Richard M. Stallman <rms@gnu.org>
parents:
23842
diff
changeset
|
3417 contents)) |
23473
4c242b09e413
(find-file-wildcards): New option.
Richard M. Stallman <rms@gnu.org>
parents:
23396
diff
changeset
|
3418 |
337 | 3419 (defun list-directory (dirname &optional verbose) |
3420 "Display a list of files in or matching DIRNAME, a la `ls'. | |
3421 DIRNAME is globbed by the shell if necessary. | |
3422 Prefix arg (second arg if noninteractive) means supply -l switch to `ls'. | |
3423 Actions controlled by variables `list-directory-brief-switches' | |
3424 and `list-directory-verbose-switches'." | |
3425 (interactive (let ((pfx current-prefix-arg)) | |
3426 (list (read-file-name (if pfx "List directory (verbose): " | |
3427 "List directory (brief): ") | |
3428 nil default-directory nil) | |
3429 pfx))) | |
3430 (let ((switches (if verbose list-directory-verbose-switches | |
3431 list-directory-brief-switches))) | |
3432 (or dirname (setq dirname default-directory)) | |
3433 (setq dirname (expand-file-name dirname)) | |
3434 (with-output-to-temp-buffer "*Directory*" | |
3435 (buffer-disable-undo standard-output) | |
3436 (princ "Directory ") | |
3437 (princ dirname) | |
3438 (terpri) | |
1109
c9feb3e64805
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1103
diff
changeset
|
3439 (save-excursion |
c9feb3e64805
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1103
diff
changeset
|
3440 (set-buffer "*Directory*") |
14401
83e1b1f5ce8f
(list-directory): Set default-directory better if the
Richard M. Stallman <rms@gnu.org>
parents:
14287
diff
changeset
|
3441 (setq default-directory |
83e1b1f5ce8f
(list-directory): Set default-directory better if the
Richard M. Stallman <rms@gnu.org>
parents:
14287
diff
changeset
|
3442 (if (file-directory-p dirname) |
83e1b1f5ce8f
(list-directory): Set default-directory better if the
Richard M. Stallman <rms@gnu.org>
parents:
14287
diff
changeset
|
3443 (file-name-as-directory dirname) |
83e1b1f5ce8f
(list-directory): Set default-directory better if the
Richard M. Stallman <rms@gnu.org>
parents:
14287
diff
changeset
|
3444 (file-name-directory dirname))) |
1109
c9feb3e64805
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1103
diff
changeset
|
3445 (let ((wildcard (not (file-directory-p dirname)))) |
c9feb3e64805
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1103
diff
changeset
|
3446 (insert-directory dirname switches wildcard (not wildcard))))))) |
c9feb3e64805
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1103
diff
changeset
|
3447 |
32138 | 3448 (defun shell-quote-wildcard-pattern (pattern) |
3449 "Quote characters special to the shell in PATTERN, leave wildcards alone. | |
3450 | |
3451 PATTERN is assumed to represent a file-name wildcard suitable for the | |
3452 underlying filesystem. For Unix and GNU/Linux, the characters from the | |
3453 set [ \\t\\n;<>&|()#$] are quoted with a backslash; for DOS/Windows, all | |
3454 the parts of the pattern which don't include wildcard characters are | |
3455 quoted with double quotes. | |
3456 Existing quote characters in PATTERN are left alone, so you can pass | |
3457 PATTERN that already quotes some of the special characters." | |
3458 (save-match-data | |
3459 (cond | |
3460 ((memq system-type '(ms-dos windows-nt)) | |
3461 ;; DOS/Windows don't allow `"' in file names. So if the | |
3462 ;; argument has quotes, we can safely assume it is already | |
3463 ;; quoted by the caller. | |
3464 (if (or (string-match "[\"]" pattern) | |
3465 ;; We quote [&()#$'] in case their shell is a port of a | |
3466 ;; Unixy shell. We quote [,=+] because stock DOS and | |
3467 ;; Windows shells require that in some cases, such as | |
3468 ;; passing arguments to batch files that use positional | |
3469 ;; arguments like %1. | |
3470 (not (string-match "[ \t;&()#$',=+]" pattern))) | |
3471 pattern | |
3472 (let ((result "\"") | |
3473 (beg 0) | |
3474 end) | |
3475 (while (string-match "[*?]+" pattern beg) | |
3476 (setq end (match-beginning 0) | |
3477 result (concat result (substring pattern beg end) | |
3478 "\"" | |
3479 (substring pattern end (match-end 0)) | |
3480 "\"") | |
3481 beg (match-end 0))) | |
3482 (concat result (substring pattern beg) "\"")))) | |
3483 (t | |
3484 (let ((beg 0)) | |
3485 (while (string-match "[ \t\n;<>&|()#$]" pattern beg) | |
3486 (setq pattern | |
3487 (concat (substring pattern 0 (match-beginning 0)) | |
3488 "\\" | |
3489 (substring pattern (match-beginning 0))) | |
3490 beg (1+ (match-end 0))))) | |
3491 pattern)))) | |
3492 | |
3493 | |
1109
c9feb3e64805
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1103
diff
changeset
|
3494 (defvar insert-directory-program "ls" |
c9feb3e64805
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1103
diff
changeset
|
3495 "Absolute or relative name of the `ls' program used by `insert-directory'.") |
c9feb3e64805
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1103
diff
changeset
|
3496 |
c9feb3e64805
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1103
diff
changeset
|
3497 ;; insert-directory |
c9feb3e64805
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1103
diff
changeset
|
3498 ;; - must insert _exactly_one_line_ describing FILE if WILDCARD and |
c9feb3e64805
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1103
diff
changeset
|
3499 ;; FULL-DIRECTORY-P is nil. |
c9feb3e64805
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1103
diff
changeset
|
3500 ;; The single line of output must display FILE's name as it was |
c9feb3e64805
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1103
diff
changeset
|
3501 ;; given, namely, an absolute path name. |
c9feb3e64805
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1103
diff
changeset
|
3502 ;; - must insert exactly one line for each file if WILDCARD or |
c9feb3e64805
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1103
diff
changeset
|
3503 ;; FULL-DIRECTORY-P is t, plus one optional "total" line |
c9feb3e64805
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1103
diff
changeset
|
3504 ;; before the file lines, plus optional text after the file lines. |
c9feb3e64805
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1103
diff
changeset
|
3505 ;; Lines are delimited by "\n", so filenames containing "\n" are not |
c9feb3e64805
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1103
diff
changeset
|
3506 ;; allowed. |
c9feb3e64805
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1103
diff
changeset
|
3507 ;; File lines should display the basename. |
c9feb3e64805
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1103
diff
changeset
|
3508 ;; - must be consistent with |
c9feb3e64805
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1103
diff
changeset
|
3509 ;; - functions dired-move-to-filename, (these two define what a file line is) |
c9feb3e64805
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1103
diff
changeset
|
3510 ;; dired-move-to-end-of-filename, |
c9feb3e64805
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1103
diff
changeset
|
3511 ;; dired-between-files, (shortcut for (not (dired-move-to-filename))) |
c9feb3e64805
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1103
diff
changeset
|
3512 ;; dired-insert-headerline |
c9feb3e64805
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1103
diff
changeset
|
3513 ;; dired-after-subdir-garbage (defines what a "total" line is) |
c9feb3e64805
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1103
diff
changeset
|
3514 ;; - variable dired-subdir-regexp |
c9feb3e64805
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1103
diff
changeset
|
3515 (defun insert-directory (file switches &optional wildcard full-directory-p) |
4148
6b065ebb9090
* files.el (insert-directory): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
4032
diff
changeset
|
3516 "Insert directory listing for FILE, formatted according to SWITCHES. |
1109
c9feb3e64805
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1103
diff
changeset
|
3517 Leaves point after the inserted text. |
8207
96e6518c209b
(insert-directory): Allow list for SWITCHES.
Richard M. Stallman <rms@gnu.org>
parents:
8181
diff
changeset
|
3518 SWITCHES may be a string of options, or a list of strings. |
1109
c9feb3e64805
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1103
diff
changeset
|
3519 Optional third arg WILDCARD means treat FILE as shell wildcard. |
c9feb3e64805
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1103
diff
changeset
|
3520 Optional fourth arg FULL-DIRECTORY-P means file is a directory and |
c9feb3e64805
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1103
diff
changeset
|
3521 switches do not contain `d', so that a full listing is expected. |
c9feb3e64805
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1103
diff
changeset
|
3522 |
c9feb3e64805
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1103
diff
changeset
|
3523 This works by running a directory listing program |
1892
c4ff65277bb3
(insert-directory): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
1879
diff
changeset
|
3524 whose name is in the variable `insert-directory-program'. |
1109
c9feb3e64805
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1103
diff
changeset
|
3525 If WILDCARD, it also runs the shell specified by `shell-file-name'." |
7730
3846302b9c9c
(insert-directory): Use expanded file name to find handler.
Richard M. Stallman <rms@gnu.org>
parents:
7686
diff
changeset
|
3526 ;; We need the directory in order to find the right handler. |
30907
46752ce55a92
(insert-directory): Don't lose original file name,
Andreas Schwab <schwab@suse.de>
parents:
30733
diff
changeset
|
3527 (let ((handler (find-file-name-handler (expand-file-name file) |
46752ce55a92
(insert-directory): Don't lose original file name,
Andreas Schwab <schwab@suse.de>
parents:
30733
diff
changeset
|
3528 'insert-directory))) |
32138 | 3529 (if handler |
1109
c9feb3e64805
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1103
diff
changeset
|
3530 (funcall handler 'insert-directory file switches |
c9feb3e64805
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1103
diff
changeset
|
3531 wildcard full-directory-p) |
337 | 3532 (if (eq system-type 'vax-vms) |
1109
c9feb3e64805
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1103
diff
changeset
|
3533 (vms-read-directory file switches (current-buffer)) |
21041
a7526e76aac9
(insert-directory): Bind coding-system-for-read to
Kenichi Handa <handa@m17n.org>
parents:
21001
diff
changeset
|
3534 (let* ((coding-system-for-read |
a7526e76aac9
(insert-directory): Bind coding-system-for-read to
Kenichi Handa <handa@m17n.org>
parents:
21001
diff
changeset
|
3535 (and enable-multibyte-characters |
a7526e76aac9
(insert-directory): Bind coding-system-for-read to
Kenichi Handa <handa@m17n.org>
parents:
21001
diff
changeset
|
3536 (or file-name-coding-system |
a7526e76aac9
(insert-directory): Bind coding-system-for-read to
Kenichi Handa <handa@m17n.org>
parents:
21001
diff
changeset
|
3537 default-file-name-coding-system))) |
22179
edc72bb3a3ff
(insert-directory): When WILDCARD is nil, expand ~ if necessary.
Richard M. Stallman <rms@gnu.org>
parents:
22175
diff
changeset
|
3538 ;; This is to control encoding the arguments in call-process. |
21046
390b026f483d
(insert-directory): Bind coding-system-for-write.
Kenichi Handa <handa@m17n.org>
parents:
21041
diff
changeset
|
3539 (coding-system-for-write coding-system-for-read) |
21041
a7526e76aac9
(insert-directory): Bind coding-system-for-read to
Kenichi Handa <handa@m17n.org>
parents:
21001
diff
changeset
|
3540 (result |
a7526e76aac9
(insert-directory): Bind coding-system-for-read to
Kenichi Handa <handa@m17n.org>
parents:
21001
diff
changeset
|
3541 (if wildcard |
32138 | 3542 ;; Run ls in the directory of the file pattern we asked for |
30907
46752ce55a92
(insert-directory): Don't lose original file name,
Andreas Schwab <schwab@suse.de>
parents:
30733
diff
changeset
|
3543 (let ((default-directory |
46752ce55a92
(insert-directory): Don't lose original file name,
Andreas Schwab <schwab@suse.de>
parents:
30733
diff
changeset
|
3544 (if (file-name-absolute-p file) |
46752ce55a92
(insert-directory): Don't lose original file name,
Andreas Schwab <schwab@suse.de>
parents:
30733
diff
changeset
|
3545 (file-name-directory file) |
46752ce55a92
(insert-directory): Don't lose original file name,
Andreas Schwab <schwab@suse.de>
parents:
30733
diff
changeset
|
3546 (file-name-directory (expand-file-name file)))) |
32138 | 3547 (pattern (file-name-nondirectory file))) |
3548 (call-process | |
3549 shell-file-name nil t nil | |
3550 "-c" (concat (if (memq system-type '(ms-dos windows-nt)) | |
3551 "" | |
3552 "\\") ; Disregard Unix shell aliases! | |
3553 insert-directory-program | |
3554 " -d " | |
3555 (if (stringp switches) | |
3556 switches | |
3557 (mapconcat 'identity switches " ")) | |
3558 " -- " | |
3559 ;; Quote some characters that have | |
3560 ;; special meanings in shells; but | |
3561 ;; don't quote the wildcards--we | |
3562 ;; want them to be special. We | |
3563 ;; also currently don't quote the | |
3564 ;; quoting characters in case | |
3565 ;; people want to use them | |
3566 ;; explicitly to quote wildcard | |
3567 ;; characters. | |
3568 (shell-quote-wildcard-pattern pattern)))) | |
21041
a7526e76aac9
(insert-directory): Bind coding-system-for-read to
Kenichi Handa <handa@m17n.org>
parents:
21001
diff
changeset
|
3569 ;; SunOS 4.1.3, SVr4 and others need the "." to list the |
a7526e76aac9
(insert-directory): Bind coding-system-for-read to
Kenichi Handa <handa@m17n.org>
parents:
21001
diff
changeset
|
3570 ;; directory if FILE is a symbolic link. |
a7526e76aac9
(insert-directory): Bind coding-system-for-read to
Kenichi Handa <handa@m17n.org>
parents:
21001
diff
changeset
|
3571 (apply 'call-process |
32138 | 3572 insert-directory-program nil t nil |
3573 (append | |
3574 (if (listp switches) switches | |
3575 (unless (equal switches "") | |
3576 ;; Split the switches at any spaces so we can | |
3577 ;; pass separate options as separate args. | |
3578 (split-string switches))) | |
3579 ;; Avoid lossage if FILE starts with `-'. | |
3580 '("--") | |
3581 (progn | |
3582 (if (string-match "\\`~" file) | |
3583 (setq file (expand-file-name file))) | |
3584 (list | |
3585 (if full-directory-p | |
3586 (concat (file-name-as-directory file) ".") | |
3587 file)))))))) | |
21041
a7526e76aac9
(insert-directory): Bind coding-system-for-read to
Kenichi Handa <handa@m17n.org>
parents:
21001
diff
changeset
|
3588 (if (/= result 0) |
32138 | 3589 ;; We get here if `insert-directory-program' failed. |
3590 ;; On non-Posix systems, we cannot open a directory, so | |
3591 ;; don't even try, because that will always result in | |
3592 ;; the ubiquitous "Access denied". Instead, show them | |
3593 ;; the `ls' command line and let them guess what went | |
3594 ;; wrong. | |
3595 (if (and (file-directory-p file) | |
3596 (memq system-type '(ms-dos windows-nt))) | |
3597 (error | |
3598 "Reading directory: \"%s %s -- %s\" exited with status %s" | |
3599 insert-directory-program | |
3600 (if (listp switches) (concat switches) switches) | |
3601 file result) | |
3602 ;; Unix. Access the file to get a suitable error. | |
3603 (access-file file "Reading directory")) | |
3604 ;; Replace "total" with "used", to avoid confusion. | |
3605 ;; Add in the amount of free space. | |
3606 (save-excursion | |
3607 (goto-char (point-min)) | |
3608 (when (re-search-forward "^total" nil t) | |
3609 (replace-match "used") | |
3610 (end-of-line) | |
3611 (let (available) | |
3612 (with-temp-buffer | |
3613 (call-process "df" nil t nil ".") | |
3614 (goto-char (point-min)) | |
3615 (forward-line 1) | |
3616 (skip-chars-forward "^ \t") | |
3617 (forward-word 3) | |
3618 (let ((end (point))) | |
3619 (forward-word -1) | |
3620 (setq available (buffer-substring (point) end)))) | |
3621 (insert " available " available)))))))))) | |
30291
062625598798
insert-directory: use split-string
Sam Steingold <sds@gnu.org>
parents:
29887
diff
changeset
|
3622 |
6050
afc731c614d3
(kill-emacs-query-functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
5974
diff
changeset
|
3623 (defvar kill-emacs-query-functions nil |
7686
814e18e2d3d4
(kill-emacs-query-functions): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
7682
diff
changeset
|
3624 "Functions to call with no arguments to query about killing Emacs. |
10901
218400c0a4a7
(kill-emacs-query-functions): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
10847
diff
changeset
|
3625 If any of these functions returns nil, killing Emacs is cancelled. |
218400c0a4a7
(kill-emacs-query-functions): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
10847
diff
changeset
|
3626 `save-buffers-kill-emacs' (\\[save-buffers-kill-emacs]) calls these functions, |
218400c0a4a7
(kill-emacs-query-functions): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
10847
diff
changeset
|
3627 but `kill-emacs', the low level primitive, does not. |
218400c0a4a7
(kill-emacs-query-functions): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
10847
diff
changeset
|
3628 See also `kill-emacs-hook'.") |
6050
afc731c614d3
(kill-emacs-query-functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
5974
diff
changeset
|
3629 |
337 | 3630 (defun save-buffers-kill-emacs (&optional arg) |
3631 "Offer to save each buffer, then kill this Emacs process. | |
3632 With prefix arg, silently save all file-visiting buffers, then kill." | |
3633 (interactive "P") | |
3634 (save-some-buffers arg t) | |
3635 (and (or (not (memq t (mapcar (function | |
3636 (lambda (buf) (and (buffer-file-name buf) | |
3637 (buffer-modified-p buf)))) | |
3638 (buffer-list)))) | |
3639 (yes-or-no-p "Modified buffers exist; exit anyway? ")) | |
3640 (or (not (fboundp 'process-list)) | |
3641 ;; process-list is not defined on VMS. | |
3642 (let ((processes (process-list)) | |
3643 active) | |
3644 (while processes | |
739
0bb85f26b79c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
736
diff
changeset
|
3645 (and (memq (process-status (car processes)) '(run stop open)) |
337 | 3646 (let ((val (process-kill-without-query (car processes)))) |
3647 (process-kill-without-query (car processes) val) | |
3648 val) | |
3649 (setq active t)) | |
3650 (setq processes (cdr processes))) | |
3651 (or (not active) | |
24017
d6ab8dbc44f2
(save-buffers-kill-emacs): Show the list of current
Richard M. Stallman <rms@gnu.org>
parents:
23989
diff
changeset
|
3652 (list-processes) |
337 | 3653 (yes-or-no-p "Active processes exist; kill them and exit anyway? ")))) |
6050
afc731c614d3
(kill-emacs-query-functions): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
5974
diff
changeset
|
3654 ;; Query the user for other things, perhaps. |
10236
013842475608
(save-buffers-kill-emacs): Fix backward test of value of
Richard M. Stallman <rms@gnu.org>
parents:
10169
diff
changeset
|
3655 (run-hook-with-args-until-failure 'kill-emacs-query-functions) |
337 | 3656 (kill-emacs))) |
3657 | |
32138 | 3658 ;; We use /: as a prefix to "quote" a file name |
16387
8c72a338e436
(file-name-non-special): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16372
diff
changeset
|
3659 ;; so that magic file name handlers will not apply to it. |
8c72a338e436
(file-name-non-special): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16372
diff
changeset
|
3660 |
8c72a338e436
(file-name-non-special): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16372
diff
changeset
|
3661 (setq file-name-handler-alist |
8c72a338e436
(file-name-non-special): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16372
diff
changeset
|
3662 (cons '("\\`/:" . file-name-non-special) |
8c72a338e436
(file-name-non-special): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16372
diff
changeset
|
3663 file-name-handler-alist)) |
8c72a338e436
(file-name-non-special): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16372
diff
changeset
|
3664 |
8c72a338e436
(file-name-non-special): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16372
diff
changeset
|
3665 ;; We depend on being the last handler on the list, |
8c72a338e436
(file-name-non-special): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16372
diff
changeset
|
3666 ;; so that anything else which does need handling |
8c72a338e436
(file-name-non-special): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16372
diff
changeset
|
3667 ;; has been handled already. |
8c72a338e436
(file-name-non-special): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16372
diff
changeset
|
3668 ;; So it is safe for us to inhibit *all* magic file name handlers. |
8c72a338e436
(file-name-non-special): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16372
diff
changeset
|
3669 |
8c72a338e436
(file-name-non-special): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16372
diff
changeset
|
3670 (defun file-name-non-special (operation &rest arguments) |
8c72a338e436
(file-name-non-special): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16372
diff
changeset
|
3671 (let ((file-name-handler-alist nil) |
20095
496ecb0c5e68
(file-name-non-special): For insert-directory operation,
Karl Heuer <kwzh@gnu.org>
parents:
20094
diff
changeset
|
3672 (default-directory |
496ecb0c5e68
(file-name-non-special): For insert-directory operation,
Karl Heuer <kwzh@gnu.org>
parents:
20094
diff
changeset
|
3673 (if (eq operation 'insert-directory) |
496ecb0c5e68
(file-name-non-special): For insert-directory operation,
Karl Heuer <kwzh@gnu.org>
parents:
20094
diff
changeset
|
3674 (directory-file-name |
32138 | 3675 (expand-file-name |
20095
496ecb0c5e68
(file-name-non-special): For insert-directory operation,
Karl Heuer <kwzh@gnu.org>
parents:
20094
diff
changeset
|
3676 (unhandled-file-name-directory default-directory))) |
496ecb0c5e68
(file-name-non-special): For insert-directory operation,
Karl Heuer <kwzh@gnu.org>
parents:
20094
diff
changeset
|
3677 default-directory)) |
16387
8c72a338e436
(file-name-non-special): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16372
diff
changeset
|
3678 ;; Get a list of the indices of the args which are file names. |
8c72a338e436
(file-name-non-special): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16372
diff
changeset
|
3679 (file-arg-indices |
8c72a338e436
(file-name-non-special): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16372
diff
changeset
|
3680 (cdr (or (assq operation |
8c72a338e436
(file-name-non-special): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16372
diff
changeset
|
3681 ;; The first four are special because they |
8c72a338e436
(file-name-non-special): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16372
diff
changeset
|
3682 ;; return a file name. We want to include the /: |
8c72a338e436
(file-name-non-special): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16372
diff
changeset
|
3683 ;; in the return value. |
8c72a338e436
(file-name-non-special): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16372
diff
changeset
|
3684 ;; So just avoid stripping it in the first place. |
8c72a338e436
(file-name-non-special): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16372
diff
changeset
|
3685 '((expand-file-name . nil) |
18040
89969b579beb
(file-name-non-special): Special handling for
Richard M. Stallman <rms@gnu.org>
parents:
17987
diff
changeset
|
3686 ;; `identity' means just return the first arg |
89969b579beb
(file-name-non-special): Special handling for
Richard M. Stallman <rms@gnu.org>
parents:
17987
diff
changeset
|
3687 ;; as stripped of its quoting. |
89969b579beb
(file-name-non-special): Special handling for
Richard M. Stallman <rms@gnu.org>
parents:
17987
diff
changeset
|
3688 (substitute-in-file-name . identity) |
16387
8c72a338e436
(file-name-non-special): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16372
diff
changeset
|
3689 (file-name-directory . nil) |
8c72a338e436
(file-name-non-special): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16372
diff
changeset
|
3690 (file-name-as-directory . nil) |
8c72a338e436
(file-name-non-special): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16372
diff
changeset
|
3691 (directory-file-name . nil) |
18164
33e7093070f8
(file-name-non-special): Handle
Richard M. Stallman <rms@gnu.org>
parents:
18040
diff
changeset
|
3692 (file-name-completion 0 1) |
33e7093070f8
(file-name-non-special): Handle
Richard M. Stallman <rms@gnu.org>
parents:
18040
diff
changeset
|
3693 (file-name-all-completions 0 1) |
16387
8c72a338e436
(file-name-non-special): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16372
diff
changeset
|
3694 (rename-file 0 1) |
8c72a338e436
(file-name-non-special): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16372
diff
changeset
|
3695 (copy-file 0 1) |
8c72a338e436
(file-name-non-special): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16372
diff
changeset
|
3696 (make-symbolic-link 0 1) |
8c72a338e436
(file-name-non-special): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16372
diff
changeset
|
3697 (add-name-to-file 0 1))) |
8c72a338e436
(file-name-non-special): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16372
diff
changeset
|
3698 ;; For all other operations, treat the first argument only |
8c72a338e436
(file-name-non-special): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16372
diff
changeset
|
3699 ;; as the file name. |
8c72a338e436
(file-name-non-special): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16372
diff
changeset
|
3700 '(nil 0)))) |
8c72a338e436
(file-name-non-special): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16372
diff
changeset
|
3701 ;; Copy ARGUMENTS so we can replace elements in it. |
8c72a338e436
(file-name-non-special): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16372
diff
changeset
|
3702 (arguments (copy-sequence arguments))) |
8c72a338e436
(file-name-non-special): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16372
diff
changeset
|
3703 ;; Strip off the /: from the file names that have this handler. |
8c72a338e436
(file-name-non-special): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16372
diff
changeset
|
3704 (save-match-data |
18040
89969b579beb
(file-name-non-special): Special handling for
Richard M. Stallman <rms@gnu.org>
parents:
17987
diff
changeset
|
3705 (while (consp file-arg-indices) |
20094
583c3ace07bf
(file-name-non-special): If "/:" is the entire file
Karl Heuer <kwzh@gnu.org>
parents:
20093
diff
changeset
|
3706 (let ((pair (nthcdr (car file-arg-indices) arguments))) |
583c3ace07bf
(file-name-non-special): If "/:" is the entire file
Karl Heuer <kwzh@gnu.org>
parents:
20093
diff
changeset
|
3707 (and (car pair) |
583c3ace07bf
(file-name-non-special): If "/:" is the entire file
Karl Heuer <kwzh@gnu.org>
parents:
20093
diff
changeset
|
3708 (string-match "\\`/:" (car pair)) |
583c3ace07bf
(file-name-non-special): If "/:" is the entire file
Karl Heuer <kwzh@gnu.org>
parents:
20093
diff
changeset
|
3709 (setcar pair |
583c3ace07bf
(file-name-non-special): If "/:" is the entire file
Karl Heuer <kwzh@gnu.org>
parents:
20093
diff
changeset
|
3710 (if (= (length (car pair)) 2) |
583c3ace07bf
(file-name-non-special): If "/:" is the entire file
Karl Heuer <kwzh@gnu.org>
parents:
20093
diff
changeset
|
3711 "/" |
583c3ace07bf
(file-name-non-special): If "/:" is the entire file
Karl Heuer <kwzh@gnu.org>
parents:
20093
diff
changeset
|
3712 (substring (car pair) 2))))) |
16387
8c72a338e436
(file-name-non-special): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16372
diff
changeset
|
3713 (setq file-arg-indices (cdr file-arg-indices)))) |
18040
89969b579beb
(file-name-non-special): Special handling for
Richard M. Stallman <rms@gnu.org>
parents:
17987
diff
changeset
|
3714 (if (eq file-arg-indices 'identity) |
89969b579beb
(file-name-non-special): Special handling for
Richard M. Stallman <rms@gnu.org>
parents:
17987
diff
changeset
|
3715 (car arguments) |
89969b579beb
(file-name-non-special): Special handling for
Richard M. Stallman <rms@gnu.org>
parents:
17987
diff
changeset
|
3716 (apply operation arguments)))) |
16387
8c72a338e436
(file-name-non-special): New function.
Richard M. Stallman <rms@gnu.org>
parents:
16372
diff
changeset
|
3717 |
337 | 3718 (define-key ctl-x-map "\C-f" 'find-file) |
3719 (define-key ctl-x-map "\C-r" 'find-file-read-only) | |
3720 (define-key ctl-x-map "\C-v" 'find-alternate-file) | |
3721 (define-key ctl-x-map "\C-s" 'save-buffer) | |
3722 (define-key ctl-x-map "s" 'save-some-buffers) | |
3723 (define-key ctl-x-map "\C-w" 'write-file) | |
3724 (define-key ctl-x-map "i" 'insert-file) | |
3725 (define-key esc-map "~" 'not-modified) | |
3726 (define-key ctl-x-map "\C-d" 'list-directory) | |
3727 (define-key ctl-x-map "\C-c" 'save-buffers-kill-emacs) | |
3728 | |
3729 (define-key ctl-x-4-map "f" 'find-file-other-window) | |
3730 (define-key ctl-x-4-map "r" 'find-file-read-only-other-window) | |
3731 (define-key ctl-x-4-map "\C-f" 'find-file-other-window) | |
3732 (define-key ctl-x-4-map "b" 'switch-to-buffer-other-window) | |
854
0b4f3a91f207
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
3733 (define-key ctl-x-4-map "\C-o" 'display-buffer) |
423 | 3734 |
778 | 3735 (define-key ctl-x-5-map "b" 'switch-to-buffer-other-frame) |
3736 (define-key ctl-x-5-map "f" 'find-file-other-frame) | |
3737 (define-key ctl-x-5-map "\C-f" 'find-file-other-frame) | |
3738 (define-key ctl-x-5-map "r" 'find-file-read-only-other-frame) | |
662
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
638
diff
changeset
|
3739 |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
638
diff
changeset
|
3740 ;;; files.el ends here |