annotate lisp/prim/files.el @ 26:441bb1e64a06 r19-15b96

Import from CVS: tag r19-15b96
author cvs
date Mon, 13 Aug 2007 08:51:32 +0200
parents 4103f0995bd7
children 8b8b7f3559a2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; files.el --- file input and output commands for XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;; Copyright (C) 1985-1987, 1992-1995 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;; Copyright (C) 1995 Sun Microsystems.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;; XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;; under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; XEmacs is distributed in the hope that it will be useful, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;; along with XEmacs; see the file COPYING. If not, write to the Free
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
20 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
21 ;; 02111-1307, USA.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
23 ;;; Synched up with: FSF 19.34 [Partial].
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 ;;; Warning: Merging this file is tough. Beware.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 ;;; Commentary:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;; Defines most of XEmacs's file- and directory-handling functions,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;; including basic file visiting, backup generation, link handling,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;; ITS-id version control, load- and write-hook handling, and the like.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 ;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
34 ;; XEmacs: Avoid compilation warnings.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 (defvar overriding-file-coding-system)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 (defvar file-coding-system)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
38 ;; XEmacs: In buffer.c
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 ;(defconst delete-auto-save-files t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 ; "*Non-nil means delete auto-save file when a buffer is saved or killed.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
42 ;; FSF has automount-dir-prefix. Our directory-abbrev-alist is more general.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
43 ;; note: tmp_mnt bogosity conversion is established in paths.el.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
44 (defvar directory-abbrev-alist nil
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
45 "*Alist of abbreviations for file directories.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
46 A list of elements of the form (FROM . TO), each meaning to replace
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
47 FROM with TO when it appears in a directory name.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
48 This replacement is done when setting up the default directory of a
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
49 newly visited file. *Every* FROM string should start with \\\\` or ^.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
50
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
51 Use this feature when you have directories which you normally refer to
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
52 via absolute symbolic links or to eliminate automounter mount points
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
53 from the beginning of your filenames. Make TO the name of the link,
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
54 and FROM the name it is linked to.")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
55
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 ;;; Turn off backup files on VMS since it has version numbers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 (defconst make-backup-files (not (eq system-type 'vax-vms))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 "*Non-nil means make a backup of a file the first time it is saved.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 This can be done by renaming the file or by copying.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 Renaming means that XEmacs renames the existing file so that it is a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 backup file, then writes the buffer into a new file. Any other names
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 that the old file had will now refer to the backup file. The new file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 is owned by you and its group is defaulted.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 Copying means that XEmacs copies the existing file into the backup
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 file, then writes the buffer on top of the existing file. Any other
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 names that the old file had will now refer to the new (edited) file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 The file's owner and group are unchanged.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 The choice of renaming or copying is controlled by the variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 `backup-by-copying', `backup-by-copying-when-linked' and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 `backup-by-copying-when-mismatch'. See also `backup-inhibited'.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 ;; Do this so that local variables based on the file name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 ;; are not overridden by the major mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 (defvar backup-inhibited nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 "Non-nil means don't make a backup, regardless of the other parameters.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 This variable is intended for use by making it local to a buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 But it is local only if you make it local.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 (put 'backup-inhibited 'permanent-local t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 (defconst backup-by-copying nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 "*Non-nil means always use copying to create backup files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 See documentation of variable `make-backup-files'.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 (defconst backup-by-copying-when-linked nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 "*Non-nil means use copying to create backups for files with multiple names.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 This causes the alternate names to refer to the latest version as edited.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 This variable is relevant only if `backup-by-copying' is nil.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 (defconst backup-by-copying-when-mismatch nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 "*Non-nil means create backups by copying if this preserves owner or group.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 Renaming may still be used (subject to control of other variables)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 when it would not result in changing the owner or group of the file;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 that is, for files which are owned by you and whose group matches
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 the default for a new file created there by you.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 This variable is relevant only if `backup-by-copying' is nil.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 (defvar backup-enable-predicate
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 '(lambda (name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 (or (< (length name) 5)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 (not (string-equal "/tmp/" (substring name 0 5)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 "Predicate that looks at a file name and decides whether to make backups.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 Called with an absolute file name as argument, it returns t to enable backup.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 (defconst buffer-offer-save nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 "*Non-nil in a buffer means offer to save the buffer on exit
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 even if the buffer is not visiting a file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 Automatically local in all buffers.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (make-variable-buffer-local 'buffer-offer-save)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
113 ;; FSF uses normal defconst
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 (defvaralias 'find-file-visit-truename 'find-file-use-truenames)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 (defvaralias 'find-file-existing-other-name 'find-file-compare-truenames)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 (defvar buffer-file-number nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 "The device number and file number of the file visited in the current buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 The value is a list of the form (FILENUM DEVNUM).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 This pair of numbers uniquely identifies the file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 If the buffer is visiting a new file, the value is nil.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 (make-variable-buffer-local 'buffer-file-number)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (put 'buffer-file-number 'permanent-local t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
125 (defvar buffer-file-numbers-unique (not (memq system-type '(windows-nt)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
126 "Non-nil means that buffer-file-number uniquely identifies files.")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
127
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (defconst file-precious-flag nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 "*Non-nil means protect against I/O errors while saving files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 Some modes set this non-nil in particular buffers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 This feature works by writing the new contents into a temporary file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 and then renaming the temporary file to replace the original.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 In this way, any I/O error in writing leaves the original untouched,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 and there is never any instant where the file is nonexistent.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 Note that this feature forces backups to be made by copying.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 Yet, at the same time, saving a precious file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 breaks any hard links between it and other files.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 (defvar version-control nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 "*Control use of version numbers for backup files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 t means make numeric backup versions unconditionally.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 nil means make them for files that have some already.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 `never' means do not make them.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146
24
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
147 ;; This is now defined in efs.
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
148 ;(defvar dired-kept-versions 2
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
149 ; "*When cleaning directory, number of versions to keep.")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (defvar delete-old-versions nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 "*If t, delete excess backup versions silently.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 If nil, ask confirmation. Any other value prevents any trimming.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 (defvar kept-old-versions 2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 "*Number of oldest versions to keep when a new numbered backup is made.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 (defvar kept-new-versions 2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 "*Number of newest versions to keep when a new numbered backup is made.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 Includes the new backup. Must be > 0")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 (defconst require-final-newline nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 "*Value of t says silently ensure a file ends in a newline when it is saved.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 Non-nil but not t says ask user whether to add a newline when there isn't one.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 nil means don't add newlines.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 (defconst auto-save-default t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 "*Non-nil says by default do auto-saving of every file-visiting buffer.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 (defconst auto-save-visited-file-name nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 "*Non-nil says auto-save a buffer in the file it is visiting, when practical.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 Normally auto-save files are written under other names.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 (defconst save-abbrevs nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 "*Non-nil means save word abbrevs too when files are saved.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 Loading an abbrev file sets this to t.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 (defconst find-file-run-dired t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 "*Non-nil says run dired if `find-file' is given the name of a directory.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 ;;;It is not useful to make this a local variable.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 ;;;(put 'find-file-not-found-hooks 'permanent-local t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 (defvar find-file-not-found-hooks nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 "List of functions to be called for `find-file' on nonexistent file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 These functions are called as soon as the error is detected.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 `buffer-file-name' is already set up.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 The functions are called in the order given until one of them returns non-nil.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 ;;;It is not useful to make this a local variable.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 ;;;(put 'find-file-hooks 'permanent-local t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 (defvar find-file-hooks nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 "List of functions to be called after a buffer is loaded from a file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 The buffer's local variables (if any) will have been processed before the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 functions are called.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 (defvar write-file-hooks nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 "List of functions to be called before writing out a buffer to a file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 If one of them returns non-nil, the file is considered already written
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 and the rest are not called.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 These hooks are considered to pertain to the visited file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 So this list is cleared if you change the visited file name.
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
202
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
203 Don't make this variable buffer-local; instead, use `local-write-file-hooks'.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
204 See also `write-contents-hooks' and `continue-save-buffer'.")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 ;;; However, in case someone does make it local...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 (put 'write-file-hooks 'permanent-local t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 (defvar local-write-file-hooks nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 "Just like `write-file-hooks', except intended for per-buffer use.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 The functions in this list are called before the ones in
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
211 `write-file-hooks'.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
212
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
213 This variable is meant to be used for hooks that have to do with a
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
214 particular visited file. Therefore, it is a permanent local, so that
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
215 changing the major mode does not clear it. However, calling
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
216 `set-visited-file-name' does clear it.")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 (make-variable-buffer-local 'local-write-file-hooks)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 (put 'local-write-file-hooks 'permanent-local t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
221 ;; XEmacs: #### think about this (added by Sun).
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 (put 'after-set-visited-file-name-hooks 'permanent-local t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 (defvar after-set-visited-file-name-hooks nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 "List of functions to be called after \\[set-visited-file-name]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 or during \\[write-file].
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 You can use this hook to restore local values of write-file-hooks,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 after-save-hook, and revert-buffer-function, which pertain
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 to a specific file and therefore are normally killed by a rename.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 Put hooks pertaining to the buffer contents on write-contents-hooks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 and revert-buffer-insert-file-contents-function.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 (defvar write-contents-hooks nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 "List of functions to be called before writing out a buffer to a file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 If one of them returns non-nil, the file is considered already written
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 and the rest are not called.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 These hooks are considered to pertain to the buffer's contents,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 not to the particular visited file; thus, `set-visited-file-name' does
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 not clear this variable, but changing the major mode does clear it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 See also `write-file-hooks' and `continue-save-buffer'.")
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
240 ;(make-variable-buffer-local 'write-contents-hooks)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
242 ;; XEmacs addition
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 ;; Energize needed this to hook into save-buffer at a lower level; we need
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 ;; to provide a new output method, but don't want to have to duplicate all
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 ;; of the backup file and file modes logic.that does not occur if one uses
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 ;; a write-file-hook which returns non-nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 (put 'write-file-data-hooks 'permanent-local t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 (defvar write-file-data-hooks nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 "List of functions to be called to put the bytes on disk.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 These functions receive the name of the file to write to as argument.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 The default behavior is to call
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 (write-region (point-min) (point-max) filename nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 If one of them returns non-nil, the file is considered already written
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 and the rest are not called.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 These hooks are considered to pertain to the visited file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 So this list is cleared if you change the visited file name.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 See also `write-file-hooks'.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 (defconst enable-local-variables t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 "*Control use of local-variables lists in files you visit.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 The value can be t, nil or something else.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 A value of t means local-variables lists are obeyed;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 nil means they are ignored; anything else means query.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 The command \\[normal-mode] always obeys local-variables lists
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 and ignores this variable.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 (defconst enable-local-eval 'maybe
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 "*Control processing of the \"variable\" `eval' in a file's local variables.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 The value can be t, nil or something else.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 A value of t means obey `eval' variables;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 nil means ignore them; anything else means query.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 The command \\[normal-mode] always obeys local-variables lists
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 and ignores this variable.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 ;; Avoid losing in versions where CLASH_DETECTION is disabled.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 (or (fboundp 'lock-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 (defalias 'lock-buffer 'ignore))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 (or (fboundp 'unlock-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 (defalias 'unlock-buffer 'ignore))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 ;;FSFmacs bastardized ange-ftp cruft
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 ;; This hook function provides support for ange-ftp host name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 ;; completion. It runs the usual ange-ftp hook, but only for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 ;; completion operations. Having this here avoids the need
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 ;; to load ange-ftp when it's not really in use.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 ;(defun ange-ftp-completion-hook-function (op &rest args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 ; (if (memq op '(file-name-completion file-name-all-completions))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 ; (apply 'ange-ftp-hook-function op args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 ; (let ((inhibit-file-name-handlers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 ; (cons 'ange-ftp-completion-hook-function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 ; (and (eq inhibit-file-name-operation op)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 ; inhibit-file-name-handlers)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 ; (inhibit-file-name-operation op))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 ; (apply op args))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
297
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
298 (defun convert-standard-filename (filename)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
299 "Convert a standard file's name to something suitable for the current OS.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
300 This function's standard definition is trivial; it just returns the argument.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
301 However, on some systems, the function is redefined
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
302 with a definition that really does change some file names."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
303 filename)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 (defun pwd ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 "Show the current default directory."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 (interactive nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 (message "Directory %s" default-directory))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 (defvar cd-path nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 "Value of the CDPATH environment variable, as a list.
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
312 Not actually set up until the first time you use it.")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 (defvar path-separator ":"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 "Character used to separate concatenated paths.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 (defun parse-colon-path (cd-path)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 "Explode a colon-separated list of paths into a string list."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 (and cd-path
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
320 (let (cd-prefix cd-list (cd-start 0) cd-colon)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 (setq cd-path (concat cd-path path-separator))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 (while (setq cd-colon (string-match path-separator cd-path cd-start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 (setq cd-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 (nconc cd-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 (list (if (= cd-start cd-colon)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 (substitute-in-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 (file-name-as-directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 (substring cd-path cd-start cd-colon)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 (setq cd-start (+ cd-colon 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 cd-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 (defun cd-absolute (dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 "Change current directory to given absolute file name DIR."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 ;; Put the name into directory syntax now,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 ;; because otherwise expand-file-name may give some bad results.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 (if (not (eq system-type 'vax-vms))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 (setq dir (file-name-as-directory dir)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 ;; XEmacs change: stig@hackvan.com
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 (if find-file-use-truenames
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 (setq dir (file-truename dir)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 (setq dir (abbreviate-file-name (expand-file-name dir)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 (cond ((not (file-directory-p dir))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 (error "%s is not a directory" dir))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 ;; this breaks ange-ftp, which doesn't (can't?) overload `file-executable-p'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 ;;((not (file-executable-p dir))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 ;; (error "Cannot cd to %s: Permission denied" dir))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 (setq default-directory dir))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 (defun cd (dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 "Make DIR become the current buffer's default directory.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 If your environment includes a `CDPATH' variable, try each one of that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 colon-separated list of directories when resolving a relative directory name."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 (interactive
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
356 ;; XEmacs change? (read-file-name => read-directory-name)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 (list (read-directory-name "Change default directory: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 default-directory default-directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 (and (member cd-path '(nil ("./")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 (null (getenv "CDPATH"))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 (if (file-name-absolute-p dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 (cd-absolute (expand-file-name dir))
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
363 ;; XEmacs
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
364 (if (null cd-path)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
365 ;;#### Unix-specific
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
366 (let ((trypath (parse-colon-path (getenv "CDPATH"))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
367 (setq cd-path (or trypath (list "./")))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
368 (or (catch 'found
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
369 (mapcar #'(lambda (x)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 (let ((f (expand-file-name (concat x dir))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 (if (file-directory-p f)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 (cd-absolute f)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 (throw 'found t)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 cd-path)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 ;; jwz: give a better error message to those of us with the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 ;; good taste not to use a kludge like $CDPATH.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 (if (equal cd-path '("./"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 (error "No such directory: %s" (expand-file-name dir))
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
381 (error "Directory not found in $CDPATH: %s" dir)))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 (defun load-file (file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 "Load the Lisp file named FILE."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 (interactive "fLoad file: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 (load (expand-file-name file) nil nil t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
388 ; We now dump utils/lib-complete.el which has an improved version of this.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 ;(defun load-library (library)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 ; "Load the library named LIBRARY.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 ;This is an interface to the function `load'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 ; (interactive "sLoad library: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 ; (load library))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 (defun file-local-copy (file &optional buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 "Copy the file FILE into a temporary file on this machine.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 Returns the name of the local copy, or nil, if FILE is directly
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 accessible."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 (let ((handler (find-file-name-handler file 'file-local-copy)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 (if handler
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 (funcall handler 'file-local-copy file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
404 ;; XEmacs change block
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 ; We have this in C and use the realpath() system call.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 ;(defun file-truename (filename &optional counter prev-dirs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 ; "Return the truename of FILENAME, which should be absolute.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 ;The truename of a file name is found by chasing symbolic links
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 ;both at the level of the file and at the level of the directories
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 ;containing it, until no links are left at any level.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 ;The arguments COUNTER and PREV-DIRS are used only in recursive calls.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 ;Do not specify them in other calls."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 ; ;; COUNTER can be a cons cell whose car is the count of how many more links
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 ; ;; to chase before getting an error.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 ; ;; PREV-DIRS can be a cons cell whose car is an alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 ; ;; of truenames we've just recently computed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 ; ;; The last test looks dubious, maybe `+' is meant here? --simon.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 ; (if (or (string= filename "") (string= filename "~")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 ; (and (string= (substring filename 0 1) "~")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 ; (string-match "~[^/]*" filename)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 ; (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 ; (setq filename (expand-file-name filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 ; (if (string= filename "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 ; (setq filename "/"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 ; (or counter (setq counter (list 100)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 ; (let (done
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 ; ;; For speed, remove the ange-ftp completion handler from the list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 ; ;; We know it's not needed here.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 ; ;; For even more speed, do this only on the outermost call.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 ; (file-name-handler-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 ; (if prev-dirs file-name-handler-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 ; (let ((tem (copy-sequence file-name-handler-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 ; (delq (rassq 'ange-ftp-completion-hook-function tem) tem)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 ; (or prev-dirs (setq prev-dirs (list nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 ; ;; If this file directly leads to a link, process that iteratively
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 ; ;; so that we don't use lots of stack.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 ; (while (not done)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 ; (setcar counter (1- (car counter)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 ; (if (< (car counter) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 ; (error "Apparent cycle of symbolic links for %s" filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 ; (let ((handler (find-file-name-handler filename 'file-truename)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 ; ;; For file name that has a special handler, call handler.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 ; ;; This is so that ange-ftp can save time by doing a no-op.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 ; (if handler
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 ; (setq filename (funcall handler 'file-truename filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 ; done t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 ; (let ((dir (or (file-name-directory filename) default-directory))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 ; target dirfile)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 ; ;; Get the truename of the directory.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 ; (setq dirfile (directory-file-name dir))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 ; ;; If these are equal, we have the (or a) root directory.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 ; (or (string= dir dirfile)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 ; ;; If this is the same dir we last got the truename for,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 ; ;; save time--don't recalculate.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 ; (if (assoc dir (car prev-dirs))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 ; (setq dir (cdr (assoc dir (car prev-dirs))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 ; (let ((old dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 ; (new (file-name-as-directory (file-truename dirfile counter prev-dirs))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 ; (setcar prev-dirs (cons (cons old new) (car prev-dirs)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 ; (setq dir new))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 ; (if (equal ".." (file-name-nondirectory filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 ; (setq filename
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 ; (directory-file-name (file-name-directory (directory-file-name dir)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 ; done t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 ; (if (equal "." (file-name-nondirectory filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 ; (setq filename (directory-file-name dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 ; done t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 ; ;; Put it back on the file name.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 ; (setq filename (concat dir (file-name-nondirectory filename)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 ; ;; Is the file name the name of a link?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 ; (setq target (file-symlink-p filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 ; (if target
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 ; ;; Yes => chase that link, then start all over
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 ; ;; since the link may point to a directory name that uses links.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 ; ;; We can't safely use expand-file-name here
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 ; ;; since target might look like foo/../bar where foo
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 ; ;; is itself a link. Instead, we handle . and .. above.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 ; (setq filename
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 ; (if (file-name-absolute-p target)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 ; target
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 ; (concat dir target))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 ; done nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 ; ;; No, we are done!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 ; (setq done t))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 ; filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 ;; XEmacs addition. Called from `insert-file-contents-internal'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 ;; at the appropriate time.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 (defun compute-buffer-file-truename (&optional buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 "Recomputes BUFFER's value of `buffer-file-truename'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 based on the current value of `buffer-file-name'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 BUFFER defaults to the current buffer if unspecified."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 (set-buffer (or buffer (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 (cond ((null buffer-file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 (setq buffer-file-truename nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 ((setq buffer-file-truename (file-truename buffer-file-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 ;; it exists, we're done.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 ;; the file doesn't exist, but maybe the directory does.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 (let* ((dir (file-name-directory buffer-file-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 (truedir (file-truename dir)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 (if truedir (setq dir truedir))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 (setq buffer-file-truename
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 (expand-file-name (file-name-nondirectory buffer-file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 dir)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 (if (and find-file-use-truenames buffer-file-truename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 (setq buffer-file-name (abbreviate-file-name buffer-file-truename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 default-directory (file-name-directory buffer-file-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 buffer-file-truename))
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
514 ;; End XEmacs change block
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 (defun file-chase-links (filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 "Chase links in FILENAME until a name that is not a link.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 Does not examine containing directories for links,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 unlike `file-truename'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 (let (tem (count 100) (newname filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 (while (setq tem (file-symlink-p newname))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 (if (= count 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 (error "Apparent cycle of symbolic links for %s" filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 ;; In the context of a link, `//' doesn't mean what XEmacs thinks.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 (while (string-match "//+" tem)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 (setq tem (concat (substring tem 0 (1+ (match-beginning 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 (substring tem (match-end 0)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 ;; Handle `..' by hand, since it needs to work in the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 ;; target of any directory symlink.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 ;; This code is not quite complete; it does not handle
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 ;; embedded .. in some cases such as ./../foo and foo/bar/../../../lose.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 (while (string-match "\\`\\.\\./" tem) ;#### Unix specific
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 (setq tem (substring tem 3))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 (setq newname (file-name-as-directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 ;; Do the .. by hand.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 (directory-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 (file-name-directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 ;; Chase links in the default dir of the symlink.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 (file-chase-links
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 (directory-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 (file-name-directory newname))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 (setq newname (expand-file-name tem (file-name-directory newname)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 (setq count (1- count)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 newname))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 (defun switch-to-other-buffer (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 "Switch to the previous buffer. With a numeric arg, n, switch to the nth
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 most recent buffer. With an arg of 0, buries the current buffer at the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549 bottom of the buffer stack."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 (if (eq arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 (bury-buffer (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 (switch-to-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 (if (<= arg 1) (other-buffer (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 (nth (1+ arg) (buffer-list)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 (defun switch-to-buffer-other-window (buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 "Select buffer BUFFER in another window."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 (interactive "BSwitch to buffer in other window: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 (let ((pop-up-windows t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561 ;; XEmacs: this used to have (selected-frame) as the third argument,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562 ;; but this is obnoxious. If the user wants the buffer in a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 ;; different frame, then it should be this way.
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
564
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
565 ;; Change documented above undone --mrb
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
566 (pop-to-buffer buffer t (selected-frame))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 (defun switch-to-buffer-other-frame (buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 "Switch to buffer BUFFER in a newly-created frame."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570 (interactive "BSwitch to buffer in other frame: ")
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
571 ;; XEmacs guarantees a new frame
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572 (let* ((name (get-frame-name-for-buffer buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 (frame (make-frame (if name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574 (list (cons 'name (symbol-name name)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575 (pop-to-buffer buffer t frame)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576 (make-frame-visible frame)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 (defun find-file (filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 "Edit file FILENAME.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581 Switch to a buffer visiting file FILENAME,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582 creating one if none already exists."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 (interactive "FFind file: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584 (switch-to-buffer (find-file-noselect filename)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586 (defun find-file-other-window (filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 "Edit file FILENAME, in another window.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588 May create a new window, or reuse an existing one.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589 See the function `display-buffer'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 (interactive "FFind file in other window: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 (switch-to-buffer-other-window (find-file-noselect filename)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593 (defun find-file-other-frame (filename)
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
594 "Edit file FILENAME, in a newly-created frame.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
595 This function will create a new frame.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
596 See the function `display-buffer'."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 (interactive "FFind file in other frame: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598 (switch-to-buffer-other-frame (find-file-noselect filename)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600 (defun find-file-read-only (filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 "Edit file FILENAME but don't allow changes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 Like \\[find-file] but marks buffer as read-only.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603 Use \\[toggle-read-only] to permit editing."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 (interactive "fFind file read-only: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 (find-file filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 (setq buffer-read-only t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607 (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609 (defun find-file-read-only-other-window (filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 "Edit file FILENAME in another window but don't allow changes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611 Like \\[find-file-other-window] but marks buffer as read-only.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 Use \\[toggle-read-only] to permit editing."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613 (interactive "fFind file read-only other window: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 (find-file-other-window filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 (setq buffer-read-only t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 (defun find-file-read-only-other-frame (filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 "Edit file FILENAME in another frame but don't allow changes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620 Like \\[find-file-other-frame] but marks buffer as read-only.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621 Use \\[toggle-read-only] to permit editing."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622 (interactive "fFind file read-only other frame: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623 (find-file-other-frame filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624 (setq buffer-read-only t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625 (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627 (defun find-alternate-file-other-window (filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628 "Find file FILENAME as a replacement for the file in the next window.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 This command does not select that window."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631 (save-selected-window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632 (other-window 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633 (let ((file buffer-file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634 (file-name nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635 (file-dir nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636 (and file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637 (setq file-name (file-name-nondirectory file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638 file-dir (file-name-directory file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639 (list (read-file-name
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
640 "Find alternate file: " file-dir nil nil file-name)))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641 (if (one-window-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 (find-file-other-window filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643 (save-selected-window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644 (other-window 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645 (find-alternate-file filename))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 (defun find-alternate-file (filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648 "Find file FILENAME, select its buffer, kill previous buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649 If the current buffer now contains an empty file that you just visited
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650 \(presumably by mistake), use this command to visit the file you really want."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652 (let ((file buffer-file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653 (file-name nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654 (file-dir nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655 (and file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656 (setq file-name (file-name-nondirectory file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657 file-dir (file-name-directory file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658 (list (read-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 "Find alternate file: " file-dir nil nil file-name))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660 (and (buffer-modified-p) (buffer-file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661 ;; (not buffer-read-only)
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
662 (not (yes-or-no-p (format "Buffer %s is modified; kill anyway? "
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
663 (buffer-name))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664 (error "Aborted"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665 (let ((obuf (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666 (ofile buffer-file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667 (onum buffer-file-number)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668 (otrue buffer-file-truename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669 (oname (buffer-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670 (if (get-buffer " **lose**")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671 (kill-buffer " **lose**"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672 (rename-buffer " **lose**")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675 (unlock-buffer)
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
676 (setq buffer-file-name nil)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
677 (setq buffer-file-number nil)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
678 (setq buffer-file-truename nil)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679 (find-file filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680 (cond ((eq obuf (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681 (setq buffer-file-name ofile)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682 (setq buffer-file-number onum)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683 (setq buffer-file-truename otrue)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684 (lock-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
685 (rename-buffer oname))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
686 (or (eq (current-buffer) obuf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
687 (kill-buffer obuf))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
689 (defun create-file-buffer (filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690 "Create a suitably named buffer for visiting FILENAME, and return it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691 FILENAME (sans directory) is used unchanged if that name is free;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
692 otherwise a string <2> or <3> or ... is appended to get an unused name."
8
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
693 (let ((handler (find-file-name-handler filename 'create-file-buffer)))
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
694 (if handler
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
695 (funcall handler 'create-file-buffer filename)
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
696 (let ((lastname (file-name-nondirectory filename)))
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
697 (if (string= lastname "")
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
698 (setq lastname filename))
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
699 (generate-new-buffer lastname)))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701 (defun generate-new-buffer (name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702 "Create and return a buffer with a name based on NAME.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703 Choose the buffer's name using `generate-new-buffer-name'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704 (get-buffer-create (generate-new-buffer-name name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
705
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
706 ;(defconst automount-dir-prefix "^/tmp_mnt/"
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
707 ; "Regexp to match the automounter prefix in a directory name.")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
708
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
709 (defvar abbreviated-home-dir nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
710 "The user's homedir abbreviated according to `directory-abbrev-alist'.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
711
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
712 ;; XEmacs additional parameter
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
713 (defun abbreviate-file-name (filename &optional hack-homedir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
714 "Return a version of FILENAME shortened using `directory-abbrev-alist'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715 See documentation of variable `directory-abbrev-alist' for more information.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716 If optional argument HACK-HOMEDIR is non-nil, then this also substitutes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
717 \"~\" for the user's home directory."
8
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
718 (let ((handler (find-file-name-handler filename 'abbreviate-file-name)))
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
719 (if handler
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
720 (funcall handler 'abbreviate-file-name filename hack-homedir)
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
721 ;; Get rid of the prefixes added by the automounter.
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
722 ;;(if (and (string-match automount-dir-prefix filename)
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
723 ;; (file-exists-p (file-name-directory
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
724 ;; (substring filename (1- (match-end 0))))))
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
725 ;; (setq filename (substring filename (1- (match-end 0)))))
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
726 (let ((tail directory-abbrev-alist))
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
727 ;; If any elt of directory-abbrev-alist matches this name,
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
728 ;; abbreviate accordingly.
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
729 (while tail
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
730 (if (string-match (car (car tail)) filename)
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
731 (setq filename
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
732 (concat (cdr (car tail)) (substring filename (match-end 0)))))
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
733 (setq tail (cdr tail))))
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
734 (if hack-homedir
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
735 (progn
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
736 ;; Compute and save the abbreviated homedir name.
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
737 ;; We defer computing this until the first time it's needed, to
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
738 ;; give time for directory-abbrev-alist to be set properly.
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
739 ;; We include a slash at the end, to avoid spurious matches
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
740 ;; such as `/usr/foobar' when the home dir is `/usr/foo'.
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
741 (or abbreviated-home-dir
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
742 (setq abbreviated-home-dir
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
743 (let ((abbreviated-home-dir "$foo"))
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
744 (concat "\\`" (regexp-quote (abbreviate-file-name
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
745 (expand-file-name "~")))
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
746 "\\(/\\|\\'\\)"))))
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
747 ;; If FILENAME starts with the abbreviated homedir,
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
748 ;; make it start with `~' instead.
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
749 (if (and (string-match abbreviated-home-dir filename)
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
750 ;; If the home dir is just /, don't change it.
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
751 (not (and (= (match-end 0) 1) ;#### unix-specific
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
752 (= (aref filename 0) ?/)))
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
753 ;; MS-DOS root directories can come with a drive letter;
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
754 ;; Novell Netware allows drive letters beyond `Z:'.
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
755 (not (and (or (eq system-type 'ms-dos)
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
756 (eq system-type 'windows-nt))
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
757 (save-match-data
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
758 (string-match "^[a-zA-Z-`]:/$" filename)))))
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
759 (setq filename
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
760 (concat "~"
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
761 (substring filename
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
762 (match-beginning 1) (match-end 1))
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
763 (substring filename (match-end 0)))))))
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
764 filename)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
765
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
766 (defvar find-file-not-true-dirname-list nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
767 "*List of logical names for which visiting shouldn't save the true dirname.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
768 On VMS, when you visit a file using a logical name that searches a path,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
769 you may or may not want the visited file name to record the specific
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
770 directory where the file was found. If you *do not* want that, add the logical
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
771 name to this list as a string.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
772
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 8
diff changeset
773 ;; XEmacs -- why was this commented out?? -- Hrv
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 8
diff changeset
774 (defun find-buffer-visiting (filename)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 8
diff changeset
775 "Return the buffer visiting file FILENAME (a string).
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 8
diff changeset
776 This is like `get-file-buffer', except that it checks for any buffer
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 8
diff changeset
777 visiting the same file, possibly under a different name.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 8
diff changeset
778 If there is no such live buffer, return nil."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 8
diff changeset
779 (let ((buf (get-file-buffer filename))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 8
diff changeset
780 (truename (abbreviate-file-name (file-truename filename))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 8
diff changeset
781 (or buf
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 8
diff changeset
782 (let ((list (buffer-list)) found)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 8
diff changeset
783 (while (and (not found) list)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 8
diff changeset
784 (save-excursion
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 8
diff changeset
785 (set-buffer (car list))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 8
diff changeset
786 (if (and buffer-file-name
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 8
diff changeset
787 (string= buffer-file-truename truename))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 8
diff changeset
788 (setq found (car list))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 8
diff changeset
789 (setq list (cdr list)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 8
diff changeset
790 found)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 8
diff changeset
791 (let ((number (nthcdr 10 (file-attributes truename)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 8
diff changeset
792 (list (buffer-list)) found)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 8
diff changeset
793 (and buffer-file-numbers-unique
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 8
diff changeset
794 number
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 8
diff changeset
795 (while (and (not found) list)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 8
diff changeset
796 (save-excursion
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 8
diff changeset
797 (set-buffer (car list))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 8
diff changeset
798 (if (and buffer-file-name
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 8
diff changeset
799 (equal buffer-file-number number)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 8
diff changeset
800 ;; Verify this buffer's file number
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 8
diff changeset
801 ;; still belongs to its file.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 8
diff changeset
802 (file-exists-p buffer-file-name)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 8
diff changeset
803 (equal (nthcdr 10 (file-attributes buffer-file-name))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 8
diff changeset
804 number))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 8
diff changeset
805 (setq found (car list))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 8
diff changeset
806 (setq list (cdr list))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 8
diff changeset
807 found))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
808
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
809 (defun insert-file-contents-literally (filename &optional visit beg end replace)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
810 "Like `insert-file-contents', q.v., but only reads in the file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
811 A buffer may be modified in several ways after reading into the buffer due
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
812 to advanced Emacs features, such as file-name-handlers, format decoding,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
813 find-file-hooks, etc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
814 This function ensures that none of these modifications will take place."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
815 (let ((file-name-handler-alist nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
816 (format-alist nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
817 (after-insert-file-functions nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
818 (find-buffer-file-type-function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
819 (if (fboundp 'find-buffer-file-type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
820 (symbol-function 'find-buffer-file-type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
821 nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
822 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
823 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
824 (fset 'find-buffer-file-type (lambda (filename) t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
825 (insert-file-contents filename visit beg end replace))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
826 (if find-buffer-file-type-function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
827 (fset 'find-buffer-file-type find-buffer-file-type-function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
828 (fmakunbound 'find-buffer-file-type)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
829
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
830 (defun find-file-noselect (filename &optional nowarn rawfile)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
831 "Read file FILENAME into a buffer and return the buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
832 If a buffer exists visiting FILENAME, return that one, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
833 verify that the file has not changed since visited or saved.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
834 The buffer is not selected, just returned to the caller.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
835 If NOWARN is non-nil warning messages about several potential
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
836 problems will be suppressed."
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
837 (setq filename
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
838 (abbreviate-file-name
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
839 (expand-file-name filename)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
840 (if (file-directory-p filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
841 (if find-file-run-dired
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
842 (dired-noselect (if find-file-use-truenames ; XEmacs
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
843 (abbreviate-file-name (file-truename filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
844 filename))
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
845 (error "%s is a directory" filename))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
846 (let* ((buf (get-file-buffer filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
847 ; (truename (abbreviate-file-name (file-truename filename)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
848 ; (number (nthcdr 10 (file-attributes truename)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
849 (number (and buffer-file-truename
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
850 (nthcdr 10 (file-attributes buffer-file-truename))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
851 ; ;; Find any buffer for a file which has same truename.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
852 ; (other (and (not buf) (find-buffer-visiting filename)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
853 (error nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
854
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
855 ; ;; Let user know if there is a buffer with the same truename.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
856 ; (if other
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
857 ; (progn
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
858 ; (or nowarn
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
859 ; (string-equal filename (buffer-file-name other))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
860 ; (message "%s and %s are the same file"
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
861 ; filename (buffer-file-name other)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
862 ; ;; Optionally also find that buffer.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
863 ; (if (or find-file-existing-other-name find-file-visit-truename)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
864 ; (setq buf other))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
865
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
866 (if (and buf
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
867 (or find-file-compare-truenames find-file-use-truenames)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
868 (not nowarn))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
869 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
870 (set-buffer buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
871 (if (not (string-equal buffer-file-name filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
872 (message "%s and %s are the same file (%s)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
873 filename buffer-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
874 buffer-file-truename))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
875
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
876 (if buf
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
877 (or nowarn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
878 (verify-visited-file-modtime buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
879 (cond ((not (file-exists-p filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
880 (error "File %s no longer exists!" filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
881 ((yes-or-no-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
882 (if (string= (file-name-nondirectory filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
883 (buffer-name buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
884 (format
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
885 (if (buffer-modified-p buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
886 (gettext "File %s changed on disk. Discard your edits? ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
887 (gettext "File %s changed on disk. Reread from disk? "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
888 (file-name-nondirectory filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
889 (format
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
890 (if (buffer-modified-p buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
891 (gettext "File %s changed on disk. Discard your edits in %s? ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
892 (gettext "File %s changed on disk. Reread from disk into %s? "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
893 (file-name-nondirectory filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
894 (buffer-name buf))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
895 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
896 (set-buffer buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
897 (revert-buffer t t)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
898 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
899 ;;; The truename stuff makes this obsolete.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
900 ;;; (let* ((link-name (car (file-attributes filename)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
901 ;;; (linked-buf (and (stringp link-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
902 ;;; (get-file-buffer link-name))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
903 ;;; (if (bufferp linked-buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
904 ;;; (message "Symbolic link to file in buffer %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
905 ;;; (buffer-name linked-buf))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
906 (setq buf (create-file-buffer filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
907 (set-buffer-major-mode buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
908 (set-buffer buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
909 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
910 (if rawfile
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
911 (condition-case ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
912 (insert-file-contents-literally filename t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
913 (file-error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
914 ;; Unconditionally set error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
915 (setq error t)))
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
916 (condition-case e ; XEmacs - pass error through
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
917 (insert-file-contents filename t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
918 (file-error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
919 ;; Run find-file-not-found-hooks until one returns non-nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
920 (or (run-hook-with-args-until-success 'find-file-not-found-hooks)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
921 ;; If they fail too, set error.
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
922 (setq error e))))) ; XEmacs
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
923 ;; Find the file's truename, and maybe use that as visited name.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
924 ;; automatically computed in XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
925 ; (setq buffer-file-truename truename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
926 (setq buffer-file-number number)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
927 ;; On VMS, we may want to remember which directory in a search list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
928 ;; the file was found in.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
929 (and (eq system-type 'vax-vms)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
930 (let (logical)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
931 (if (string-match ":" (file-name-directory filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
932 (setq logical (substring (file-name-directory filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
933 0 (match-beginning 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
934 (not (member logical find-file-not-true-dirname-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
935 (setq buffer-file-name buffer-file-truename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
936 ; (if find-file-visit-truename
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
937 ; (setq buffer-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
938 ; (setq filename
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
939 ; (expand-file-name buffer-file-truename))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
940 (and find-file-use-truenames
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
941 ;; This should be in C. Put pathname abbreviations that have
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
942 ;; been explicitly requested back into the pathname. Most
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
943 ;; importantly, strip out automounter /tmp_mnt directories so
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
944 ;; that auto-save will work
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
945 (setq buffer-file-name (abbreviate-file-name buffer-file-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
946 ;; Set buffer's default directory to that of the file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
947 (setq default-directory (file-name-directory buffer-file-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
948 ;; Turn off backup files for certain file names. Since
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
949 ;; this is a permanent local, the major mode won't eliminate it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
950 (and (not (funcall backup-enable-predicate buffer-file-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
951 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
952 (make-local-variable 'backup-inhibited)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
953 (setq backup-inhibited t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
954 (if rawfile
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
955 nil
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
956 (after-find-file error (not nowarn))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
957 (setq buf (current-buffer)))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
958 buf)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
959
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
960 (defvar after-find-file-from-revert-buffer nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
961
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
962 (defun after-find-file (&optional error warn noauto
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
963 after-find-file-from-revert-buffer
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
964 nomodes)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
965 "Called after finding a file and by the default revert function.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
966 Sets buffer mode, parses local variables.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
967 Optional args ERROR, WARN, and NOAUTO: ERROR non-nil means there was an
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
968 error in reading the file. WARN non-nil means warn if there
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
969 exists an auto-save file more recent than the visited file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
970 NOAUTO means don't mess with auto-save mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
971 Fourth arg AFTER-FIND-FILE-FROM-REVERT-BUFFER non-nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
972 means this call was from `revert-buffer'.
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
973 Finishes by calling the functions in `find-file-hooks'.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
974 Fifth arg NOMODES non-nil means don't alter the file's modes.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
975 Finishes by calling the functions in `find-file-hooks'
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
976 unless NOMODES is non-nil."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
977 (setq buffer-read-only (not (file-writable-p buffer-file-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
978 (if noninteractive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
979 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
980 (let* (not-serious
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
981 (msg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
982 (cond ((and error (file-attributes buffer-file-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
983 (setq buffer-read-only t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
984 (gettext "File exists, but cannot be read."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
985 ((not buffer-read-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
986 (if (and warn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
987 (file-newer-than-file-p (make-auto-save-file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
988 buffer-file-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
989 (gettext "Auto save file is newer; consider M-x recover-file")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
990 (setq not-serious t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
991 (if error (gettext "(New file)") nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
992 ((not error)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
993 (setq not-serious t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
994 (gettext "Note: file is write protected"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
995 ((file-attributes (directory-file-name default-directory))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
996 (gettext "File not found and directory write-protected"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
997 ((file-exists-p (file-name-directory buffer-file-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
998 (setq buffer-read-only nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
999 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1000 ;; If the directory the buffer is in doesn't exist,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1001 ;; offer to create it. It's better to do this now
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1002 ;; than when we save the buffer, because we want
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1003 ;; autosaving to work.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1004 (setq buffer-read-only nil)
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1005 ;; XEmacs change
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1006 (or (file-exists-p (file-name-directory buffer-file-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1007 (if (yes-or-no-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1008 (format
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1009 "The directory containing %s does not exist. Create? "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1010 (abbreviate-file-name buffer-file-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1011 (make-directory (file-name-directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1012 buffer-file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1013 t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1014 nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1015 (if msg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1016 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1017 (message msg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1018 (or not-serious (sit-for 1 t)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1019 (if (and auto-save-default (not noauto))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1020 (auto-save-mode t)))
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1021 (unless nomodes
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1022 (normal-mode t)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1023 (run-hooks 'find-file-hooks)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1024
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1025 (defun normal-mode (&optional find-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1026 "Choose the major mode for this buffer automatically.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1027 Also sets up any specified local variables of the file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1028 Uses the visited file name, the -*- line, and the local variables spec.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1029
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1030 This function is called automatically from `find-file'. In that case,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1031 we may set up specified local variables depending on the value of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1032 `enable-local-variables': if it is t, we do; if it is nil, we don't;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1033 otherwise, we query. `enable-local-variables' is ignored if you
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1034 run `normal-mode' explicitly."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1035 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1036 (or find-file (funcall (or default-major-mode 'fundamental-mode)))
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1037 ;; XEmacs change
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1038 (and (condition-case err
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1039 (progn (set-auto-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1040 t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1041 (error (message "File mode specification error: %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1042 (prin1-to-string err))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1043 nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1044 (condition-case err
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1045 (hack-local-variables (not find-file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1046 (error (message "File local-variables error: %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1047 (prin1-to-string err))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1048
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1049 (defvar auto-mode-alist
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1050 (mapcar
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1051 'purecopy
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1052 '(("\\.te?xt\\'" . text-mode)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1053 ("\\.[ch]\\'" . c-mode)
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1054 ("\\.tex\\'" . tex-mode)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1055 ("\\.ltx\\'" . latex-mode)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1056 ("\\.el\\'" . emacs-lisp-mode)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1057 ("\\.l\\(i?sp\\)?\\'" . lisp-mode)
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 8
diff changeset
1058 ("\\.[Ff]\\(or\\)?\\'" . fortran-mode)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1059 ("\\.p\\(as\\)?\\'" . pascal-mode)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1060 ("\\.ad[abs]\\'" . ada-mode)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1061 ("\\.pl\\'" . perl-mode)
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 8
diff changeset
1062 ("\\.pm\\'" . perl-mode)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1063 ("\\.\\([CH]\\|cc\\|hh\\)\\'" . c++-mode)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1064 ("\\.[ch]\\(pp\\|xx\\|\\+\\+\\)\\'" . c++-mode)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1065 ("\\.java\\'" . java-mode)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1066 ("\\.ma?k\\'" . makefile-mode)
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 8
diff changeset
1067 ("\\(M\\|m\\|GNUm\\)akefile\\(.in\\)?\\(.in\\)?\\'" . makefile-mode)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1068 ;;; Less common extensions come here
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1069 ;;; so more common ones above are found faster.
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1070 ("\\.texi\\(nfo\\)?\\'" . texinfo-mode)
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 8
diff changeset
1071 ("\\.[Ss]\\'" . asm-mode)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 8
diff changeset
1072 ("\\.asm\\'" . asm-mode)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1073 ("[Cc]hange.?[Ll]og?\\(.[0-9]+\\)?\\'" . change-log-mode)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1074 ("\\$CHANGE_LOG\\$\\.TXT" . change-log-mode)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1075 ("\\.scm\\(\\.[0-9]*\\)?\\'" . scheme-mode)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1076 ("\\.py\\'" . python-mode)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1077 ("\\.e\\'" . eiffel-mode)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1078 ("\\.mss\\'" . scribe-mode)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1079 ("\\.m\\([mes]\\|an\\)\\'" . nroff-mode)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1080 ("\\.icn\\'" . icon-mode)
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1081 ("\\.[ck]?sh\\'\\|\\.shar\\'\\|/\\.z?profile\\'" . sh-mode)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1082 ("/\\.\\(bash_profile\\|z?login\\|bash_login\\|z?logout\\)\\'" . sh-mode)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1083 ("/\\.\\(bash_logout\\|[kz]shrc\\|bashrc\\|t?cshrc\\|esrc\\)\\'" . sh-mode)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1084 ("/\\.\\([kz]shenv\\|xinitrc\\|startxrc\\|xsession\\)\\'" . sh-mode)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1085 ;;; The following should come after the ChangeLog pattern
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1086 ;;; for the sake of ChangeLog.1, etc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1087 ;;; and after the .scm.[0-9] pattern too.
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1088 ("\\.[12345678]\\'" . nroff-mode)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1089 ("\\.[tT]e[xX]\\'" . tex-mode)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1090 ("\\.\\(sty\\|cls\\|bbl\\)\\'" . latex-mode)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1091 ("\\.bib\\'" . bibtex-mode)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1092 ("\\.article\\'" . text-mode)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1093 ("\\.letter\\'" . text-mode)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1094 ("\\.\\(tcl\\|exp\\)\\'" . tcl-mode)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1095 ("\\.wrl\\'" . vrml-mode)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1096 ("\\.f90\\'" . f90-mode)
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 8
diff changeset
1097 ("\\.lsp\\'" . lisp-mode)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1098 ("\\.awk\\'" . awk-mode)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1099 ("\\.prolog\\'" . prolog-mode)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1100 ("\\.tar\\'" . tar-mode)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1101 ("\\.\\(arc\\|zip\\|lzh\\|zoo\\)\\'" . archive-mode)
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 8
diff changeset
1102 ("\\.\\(ARC\\|ZIP\\|LZH\\|ZOO\\)\\'" . archive-mode)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1103 ;; Mailer puts message to be edited in
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1104 ;; /tmp/Re.... or Message
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1105 ("^/tmp/Re" . text-mode)
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1106 ("^/tmp/L[0-9]+TMP\\.html" . text-mode) ; Lynx mail mode
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1107 ("/Message[0-9]*\\'" . text-mode)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1108 ("/drafts/[0-9]+\\'" . mh-letter-mode)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1109 ;; some news reader is reported to use this
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1110 ("^/tmp/fol/" . text-mode)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1111 ("\\.y\\'" . c-mode)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1112 ("\\.lex\\'" . c-mode)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1113 ("\\.oak\\'" . scheme-mode)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1114 ("\\.s?html?\\'" . html-mode)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1115 ("\\.htm?l?3\\'" . html3-mode)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1116 ("\\.\\(sgml?\\|dtd\\)\\'" . sgml-mode)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1117 ("\\.c?ps\\'" . postscript-mode)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1118 ;; .emacs following a directory delimiter
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1119 ;; in either Unix or VMS syntax.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1120 ("[]>:/]\\..*emacs\\'" . emacs-lisp-mode)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1121 ;; _emacs following a directory delimiter
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1122 ;; in MsDos syntax
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1123 ("[:/]_emacs\\'" . emacs-lisp-mode)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1124 ("\\.ml\\'" . lisp-mode)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1125 "Alist of filename patterns vs. corresponding major mode functions.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1126 Each element looks like (REGEXP . FUNCTION) or (REGEXP FUNCTION NON-NIL).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1127 \(NON-NIL stands for anything that is not nil; the value does not matter.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1128 Visiting a file whose name matches REGEXP specifies FUNCTION as the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1129 mode function to use. FUNCTION will be called, unless it is nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1130
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1131 If the element has the form (REGEXP FUNCTION NON-NIL), then after
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1132 calling FUNCTION (if it's not nil), we delete the suffix that matched
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1133 REGEXP and search the list again for another match.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1134
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1135 (defconst interpreter-mode-alist
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1136 (mapcar 'purecopy
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 8
diff changeset
1137 '(("^#!.*[acjkwz]sh" . sh-mode)
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1138 ("^#!.*sh\\b" . sh-mode)
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 8
diff changeset
1139 ("^#!.*\\b\\(scope\\|wishx?\\|tcl\\|tclsh\\|expect\\)" . tcl-mode)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1140 ("python" . python-mode)
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 8
diff changeset
1141 ("[mng]?awk\\b" . awk-mode)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1142 ("rexx" . rexx-mode)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1143 ("scm" . scheme-mode)
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1144 ("^:" . sh-mode)
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 8
diff changeset
1145 ("tail" . text-mode)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 8
diff changeset
1146 ("more" . text-mode)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 8
diff changeset
1147 ("less" . text-mode)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 8
diff changeset
1148 ("pg" . text-mode)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1149 ))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1150 "Alist mapping interpreter names to major modes.
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1151 This alist is used to guess the major mode of a file based on the
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1152 contents of the first line. This line often contains something like:
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1153 #!/bin/sh
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1154 but may contain something more imaginative like
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1155 #! /bin/env python
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1156 or
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1157 eval 'exec perl -w -S $0 ${1+\"$@\"}'.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1158
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1159 Each alist element looks like (INTERPRETER . MODE).
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1160 The car of each element is a regular expression which is compared
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1161 with the name of the interpreter specified in the first line.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1162 If it matches, mode MODE is selected.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1163
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1164 (defconst inhibit-first-line-modes-regexps (purecopy '("\\.tar\\'"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1165 "List of regexps; if one matches a file name, don't look for `-*-'.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1166
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1167 (defconst inhibit-first-line-modes-suffixes nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1168 "List of regexps for what to ignore, for `inhibit-first-line-modes-regexps'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1169 When checking `inhibit-first-line-modes-regexps', we first discard
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1170 from the end of the file name anything that matches one of these regexps.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1171
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1172 (defvar user-init-file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1173 "" ; set by command-line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1174 "File name including directory of user's initialization file.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1175
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1176 ;; XEmacs (This function is not synched with FSF)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1177 (defun set-auto-mode ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1178 "Select major mode appropriate for current buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1179 This checks for a -*- mode tag in the buffer's text,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1180 compares the filename against the entries in `auto-mode-alist',
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1181 or checks the interpreter that runs this file against
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1182 `interpreter-mode-alist'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1183
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1184 It does not check for the `mode:' local variable in the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1185 Local Variables section of the file; for that, use `hack-local-variables'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1186
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1187 If `enable-local-variables' is nil, this function does not check for a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1188 -*- mode tag."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1189 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1190 ;; Look for -*-MODENAME-*- or -*- ... mode: MODENAME; ... -*-
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1191 ;; Do this by calling the hack-local-variables helper to avoid redundancy.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1192 ;; We bind enable-local-variables to nil this time because we're going to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1193 ;; call hack-local-variables-prop-line again later, "for real."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1194 (or (let ((enable-local-variables nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1195 (hack-local-variables-prop-line nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1196 ;; It's not in the -*- line, so check the auto-mode-alist, unless
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1197 ;; this buffer isn't associated with a file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1198 (null buffer-file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1199 (let ((name (file-name-sans-versions buffer-file-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1200 (keep-going t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1201 (while keep-going
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1202 (setq keep-going nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1203 (let ((alist auto-mode-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1204 (mode nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1205 ;; Find first matching alist entry.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1206 (let ((case-fold-search
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1207 (memq system-type '(vax-vms windows-nt))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1208 (while (and (not mode) alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1209 (if (string-match (car (car alist)) name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1210 (if (and (consp (cdr (car alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1211 (nth 2 (car alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1212 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1213 (setq mode (car (cdr (car alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1214 name (substring name 0 (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1215 keep-going t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1216 (setq mode (cdr (car alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1217 keep-going nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1218 (setq alist (cdr alist))))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1219 ;; If we can't deduce a mode from the file name,
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1220 ;; look for an interpreter specified in the first line.
6
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents: 4
diff changeset
1221 (if (and (null mode)
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents: 4
diff changeset
1222 (save-excursion ; XEmacs
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents: 4
diff changeset
1223 (goto-char (point-min))
27bc7f280385 Import from CVS: tag r19-15b4
cvs
parents: 4
diff changeset
1224 (looking-at "#!")))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1225 (let ((firstline
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1226 (buffer-substring
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1227 (point-min)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1228 (save-excursion
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1229 (goto-char (point-min)) (end-of-line) (point)))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1230 (setq alist interpreter-mode-alist)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1231 (while alist
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1232 (if (string-match (car (car alist)) firstline)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1233 (progn
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1234 (setq mode (cdr (car alist)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1235 (setq alist nil))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1236 (setq alist (cdr alist))))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1237 (if mode
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1238 (funcall mode))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1239 ))))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1240
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1241 ;; XEmacs: this function is not synched with FSF
24
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
1242 ;; jwz - New Version 20.1/19.15
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1243 (defun hack-local-variables-prop-line (&optional force)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1244 ;; Set local variables specified in the -*- line.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1245 ;; Returns t if mode was set.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1246 (let ((result nil))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1247 (save-excursion
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1248 (goto-char (point-min))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1249 (skip-chars-forward " \t\n\r")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1250 (let ((end (save-excursion
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1251 ;; If the file begins with "#!"
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1252 ;; (un*x exec interpreter magic), look
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1253 ;; for mode frobs in the first two
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1254 ;; lines. You cannot necessarily
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1255 ;; put them in the first line of
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1256 ;; such a file without screwing up
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1257 ;; the interpreter invocation.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1258 (end-of-line (and (looking-at "^#!") 2))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1259 (point))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1260 ;; Parse the -*- line into the `result' alist.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1261 (cond ((not (search-forward "-*-" end t))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1262 ;; doesn't have one.
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 24
diff changeset
1263 (setq force t))
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1264 ((looking-at "[ \t]*\\([^ \t\n\r:;]+\\)\\([ \t]*-\\*-\\)")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1265 ;; Antiquated form: "-*- ModeName -*-".
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1266 (setq result
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1267 (list (cons 'mode
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1268 (intern (buffer-substring
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1269 (match-beginning 1)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1270 (match-end 1)))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1271 ))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1272 (t
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1273 ;; Usual form: '-*-' [ <variable> ':' <value> ';' ]* '-*-'
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1274 ;; (last ";" is optional).
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1275 (save-excursion
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1276 (if (search-forward "-*-" end t)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1277 (setq end (- (point) 3))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1278 (error "-*- not terminated before end of line")))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1279 (while (< (point) end)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1280 (or (looking-at "[ \t]*\\([^ \t\n:]+\\)[ \t]*:[ \t]*")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1281 (error "malformed -*- line"))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1282 (goto-char (match-end 0))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1283 ;; There used to be a downcase here,
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1284 ;; but the manual didn't say so,
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1285 ;; and people want to set var names that aren't all lc.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1286 (let ((key (intern (buffer-substring
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1287 (match-beginning 1)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1288 (match-end 1))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1289 (val (save-restriction
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1290 (narrow-to-region (point) end)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1291 (read (current-buffer)))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1292 ;; Case sensitivity! Icepicks in my forehead!
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1293 (if (equal (downcase (symbol-name key)) "mode")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1294 (setq key 'mode))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1295 (setq result (cons (cons key val) result))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1296 (skip-chars-forward " \t;")))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1297 (setq result (nreverse result))))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1298
24
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
1299 (let ((set-any-p (or force (hack-local-variables-p t)))
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
1300 (mode-p nil))
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
1301 (while result
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
1302 (let ((key (car (car result)))
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
1303 (val (cdr (car result))))
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
1304 (cond ((eq key 'mode)
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
1305 (setq mode-p t)
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
1306 (funcall (intern (concat (downcase (symbol-name val))
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
1307 "-mode"))))
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
1308 (set-any-p
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
1309 (hack-one-local-variable key val))
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
1310 (t
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
1311 nil)))
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
1312 (setq result (cdr result)))
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
1313 mode-p)))
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1314
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1315 (defvar hack-local-variables-hook nil
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1316 "Normal hook run after processing a file's local variables specs.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1317 Major modes can use this to examine user-specified local variables
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1318 in order to initialize other data structure based on them.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1319
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1320 This hook runs even if there were no local variables or if their
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1321 evaluation was suppressed. See also `enable-local-variables' and
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1322 `enable-local-eval'.")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1323
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1324 ;; XEmacs this function is not synched with FSF
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1325 (defun hack-local-variables (&optional force)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1326 "Parse, and bind or evaluate as appropriate, any local variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1327 for current buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1328 ;; Don't look for -*- if this file name matches any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1329 ;; of the regexps in inhibit-first-line-modes-regexps.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1330 (if (or (null buffer-file-name) ; don't lose if buffer has no file!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1331 (not (let ((temp inhibit-first-line-modes-regexps)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1332 (name (if buffer-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1333 (file-name-sans-versions buffer-file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1334 (buffer-name))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1335 (while (let ((sufs inhibit-first-line-modes-suffixes))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1336 (while (and sufs (not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1337 (string-match (car sufs) name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1338 (setq sufs (cdr sufs)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1339 sufs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1340 (setq name (substring name 0 (match-beginning 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1341 (while (and temp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1342 (not (string-match (car temp) name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1343 (setq temp (cdr temp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1344 temp))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1345 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1346 ;; Look for variables in the -*- line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1347 (hack-local-variables-prop-line force)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1348 ;; Look for "Local variables:" block in last page.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1349 (hack-local-variables-last-page force)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1350 (run-hooks 'hack-local-variables-hook))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1351
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1352 ;;; Local variables may be specified in the last page of the file (within 3k
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1353 ;;; from the end of the file and after the last ^L) in the form
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1354 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1355 ;;; Local variables:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1356 ;;; variable-name: variable-value
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1357 ;;; end:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1358 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1359 ;;; The lines may begin with a common prefix, like ";;; " in the above
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1360 ;;; example. They may also have a common suffix (" */" for example). In
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1361 ;;; this form, the local variable "mode" can be used to change the major
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1362 ;;; mode, and the local variable "eval" can be used to evaluate an arbitrary
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1363 ;;; form.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1364 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1365 ;;; Local variables may also be specified in the first line of the file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1366 ;;; Embedded in this line are a pair of "-*-" sequences. What lies between
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1367 ;;; them are variable-name/variable-value pairs, like:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1368 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1369 ;;; -*- mode: emacs-lisp -*-
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1370 ;;; or -*- mode: postscript; version-control: never -*-
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1371 ;;; or -*- tags-file-name: "/foo/bar/TAGS" -*-
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1372 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1373 ;;; The local variable "eval" is not used with this form. For hysterical
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1374 ;;; reasons, the syntax "-*- modename -*-" is allowed as well.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1375 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1376
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1377 (defun hack-local-variables-p (modeline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1378 (or (eq enable-local-variables t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1379 (and enable-local-variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1380 (save-window-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1381 (condition-case nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1382 (switch-to-buffer (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1383 (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1384 ;; If we fail to switch in the selected window,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1385 ;; it is probably a minibuffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1386 ;; So try another window.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1387 (condition-case nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1388 (switch-to-buffer-other-window (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1389 (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1390 (switch-to-buffer-other-frame (current-buffer))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1391 (or modeline (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1392 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1393 (set-window-start (selected-window) (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1394 (y-or-n-p (format
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1395 "Set local variables as specified %s of %s? "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1396 (if modeline "in -*- line" "at end")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1397 (if buffer-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1398 (file-name-nondirectory buffer-file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1399 (concat "buffer " (buffer-name)))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1400
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1401 (defun hack-local-variables-last-page (&optional force)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1402 ;; Set local variables set in the "Local Variables:" block of the last page.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1403 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1404 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1405 (search-backward "\n\^L" (max (- (point-max) 3000) (point-min)) 'move)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1406 (if (let ((case-fold-search t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1407 (and (search-forward "Local Variables:" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1408 (or force
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1409 (hack-local-variables-p nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1410 (let ((continue t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1411 prefix prefixlen suffix beg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1412 (enable-local-eval enable-local-eval))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1413 ;; The prefix is what comes before "local variables:" in its line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1414 ;; The suffix is what comes after "local variables:" in its line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1415 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1416 (or (eolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1417 (setq suffix (buffer-substring (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1418 (progn (end-of-line) (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1419 (goto-char (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1420 (or (bolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1421 (setq prefix
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1422 (buffer-substring (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1423 (progn (beginning-of-line) (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1424 (if prefix (setq prefixlen (length prefix)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1425 prefix (regexp-quote prefix)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1426 (if suffix (setq suffix (concat (regexp-quote suffix) "$")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1427 (while continue
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1428 ;; Look at next local variable spec.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1429 (if selective-display (re-search-forward "[\n\C-m]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1430 (forward-line 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1431 ;; Skip the prefix, if any.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1432 (if prefix
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1433 (if (looking-at prefix)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1434 (forward-char prefixlen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1435 (error "Local variables entry is missing the prefix")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1436 ;; Find the variable name; strip whitespace.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1437 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1438 (setq beg (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1439 (skip-chars-forward "^:\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1440 (if (eolp) (error "Missing colon in local variables entry"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1441 (skip-chars-backward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1442 (let* ((str (buffer-substring beg (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1443 (var (read str))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1444 val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1445 ;; Setting variable named "end" means end of list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1446 (if (string-equal (downcase str) "end")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1447 (setq continue nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1448 ;; Otherwise read the variable value.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1449 (skip-chars-forward "^:")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1450 (forward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1451 (setq val (read (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1452 (skip-chars-backward "\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1453 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1454 (or (if suffix (looking-at suffix) (eolp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1455 (error "Local variables entry is terminated incorrectly"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1456 ;; Set the variable. "Variables" mode and eval are funny.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1457 (hack-one-local-variable var val))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1458
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1459
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1460
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1461 (defconst ignored-local-variables
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1462 '(enable-local-eval)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1463 "Variables to be ignored in a file's local variable spec.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1464
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1465 ;; Get confirmation before setting these variables as locals in a file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1466 (put 'debugger 'risky-local-variable t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1467 (put 'enable-local-eval 'risky-local-variable t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1468 (put 'ignored-local-variables 'risky-local-variable t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1469 (put 'eval 'risky-local-variable t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1470 (put 'file-name-handler-alist 'risky-local-variable t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1471 (put 'minor-mode-map-alist 'risky-local-variable t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1472 (put 'after-load-alist 'risky-local-variable t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1473 (put 'buffer-file-name 'risky-local-variable t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1474 (put 'buffer-auto-save-file-name 'risky-local-variable t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1475 (put 'buffer-file-truename 'risky-local-variable t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1476 (put 'exec-path 'risky-local-variable t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1477 (put 'load-path 'risky-local-variable t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1478 (put 'exec-directory 'risky-local-variable t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1479 (put 'process-environment 'risky-local-variable t)
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1480 (put 'dabbrev-case-fold-search 'risky-local-variable t)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1481 (put 'dabbrev-case-replace 'risky-local-variable t)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1482 ;; Don't wait for outline.el to be loaded, for the sake of outline-minor-mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1483 (put 'outline-level 'risky-local-variable t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1484 (put 'rmail-output-file-alist 'risky-local-variable t)
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1485
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1486 ;; This one is safe because the user gets to check it before it is used.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1487 (put 'compile-command 'safe-local-variable t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1488
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1489 ;(defun hack-one-local-variable-quotep (exp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1490 ; (and (consp exp) (eq (car exp) 'quote) (consp (cdr exp))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1491
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1492 ;; "Set" one variable in a local variables spec.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1493 ;; A few variable names are treated specially.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1494 (defun hack-one-local-variable (var val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1495 (cond ((eq var 'mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1496 (funcall (intern (concat (downcase (symbol-name val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1497 "-mode"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1498 ((memq var ignored-local-variables)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1499 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1500 ;; "Setting" eval means either eval it or do nothing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1501 ;; Likewise for setting hook variables.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1502 ((or (get var 'risky-local-variable)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1503 (and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1504 (string-match "-hooks?$\\|-functions?$\\|-forms?$\\|-program$\\|-command$"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1505 (symbol-name var))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1506 (not (get var 'safe-local-variable))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1507 ; ;; Permit evaling a put of a harmless property
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1508 ; ;; if the args do nothing tricky.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1509 ; (if (or (and (eq var 'eval)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1510 ; (consp val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1511 ; (eq (car val) 'put)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1512 ; (hack-one-local-variable-quotep (nth 1 val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1513 ; (hack-one-local-variable-quotep (nth 2 val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1514 ; ;; Only allow safe values of lisp-indent-hook;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1515 ; ;; not functions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1516 ; (or (numberp (nth 3 val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1517 ; (equal (nth 3 val) ''defun))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1518 ; (memq (nth 1 (nth 2 val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1519 ; '(lisp-indent-hook)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1520 (if (and (not (zerop (user-uid)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1521 (or (eq enable-local-eval t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1522 (and enable-local-eval
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1523 (save-window-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1524 (switch-to-buffer (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1525 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1526 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1527 (set-window-start (selected-window) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1528 (setq enable-local-eval
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1529 (y-or-n-p (format "Process `eval' or hook local variables in file %s? "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1530 (file-name-nondirectory buffer-file-name))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1531 (if (eq var 'eval)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1532 (save-excursion (eval val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1533 (make-local-variable var)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1534 (set var val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1535 (message "Ignoring `eval:' in file's local variables")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1536 ;; Ordinary variable, really set it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1537 (t (make-local-variable var)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1538 (set var val))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1539
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1540 (defun set-visited-file-name (filename &optional no-query)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1541 "Change name of file visited in current buffer to FILENAME.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1542 The next time the buffer is saved it will go in the newly specified file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1543 nil or empty string as argument means make buffer not be visiting any file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1544 Remember to delete the initial contents of the minibuffer
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1545 if you wish to pass an empty string as the argument.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1546
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1547 The optional second argument NO-QUERY, if non-nil, inhibits asking for
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1548 confirmation in the case where the file FILENAME already exists."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1549 (interactive "FSet visited file name: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1550 (if (buffer-base-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1551 (error "An indirect buffer cannot visit a file"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1552 (let (truename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1553 (if filename
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1554 (setq filename
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1555 (if (string-equal filename "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1556 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1557 (expand-file-name filename))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1558 (if filename
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1559 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1560 (setq truename (file-truename filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1561 ;; #### Do we need to check if truename is non-nil?
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1562 ;; XEmacs: FSF uses -visit-
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1563 (if find-file-use-truenames
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1564 (setq filename truename))))
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1565 ; (let ((buffer (and filename (find-buffer-visiting filename))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1566 ; (and buffer (not (eq buffer (current-buffer)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1567 ; (not no-query)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1568 ; (not (y-or-n-p (message "A buffer is visiting %s; proceed? "
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1569 ; filename)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1570 ; (error "Aborted")))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1571 (or (equal filename buffer-file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1572 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1573 (and filename (lock-buffer filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1574 (unlock-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1575 (setq buffer-file-name filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1576 (if filename ; make buffer name reflect filename.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1577 (let ((new-name (file-name-nondirectory buffer-file-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1578 (if (string= new-name "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1579 (error "Empty file name"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1580 (if (eq system-type 'vax-vms)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1581 (setq new-name (downcase new-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1582 (setq default-directory (file-name-directory buffer-file-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1583 (or (string= new-name (buffer-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1584 (rename-buffer new-name t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1585 (setq buffer-backed-up nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1586 (clear-visited-file-modtime)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1587 (compute-buffer-file-truename) ; insert-file-contents does this too.
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1588 ;; XEmacs deletion
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1589 ; ;; Abbreviate the file names of the buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1590 ; (if truename
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1591 ; (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1592 ; (setq buffer-file-truename (abbreviate-file-name truename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1593 ; (if find-file-visit-truename
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1594 ; (setq buffer-file-name buffer-file-truename))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1595 (setq buffer-file-number
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1596 (if filename
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1597 (nthcdr 10 (file-attributes buffer-file-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1598 nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1599 ;; write-file-hooks is normally used for things like ftp-find-file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1600 ;; that visit things that are not local files as if they were files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1601 ;; Changing to visit an ordinary local file instead should flush the hook.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1602 (kill-local-variable 'write-file-hooks)
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1603 (kill-local-variable 'after-save-hook) ; XEmacs
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1604 (kill-local-variable 'local-write-file-hooks)
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1605 (kill-local-variable 'write-file-data-hooks) ; XEmacs
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1606 (kill-local-variable 'revert-buffer-function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1607 (kill-local-variable 'backup-inhibited)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1608 ;; If buffer was read-only because of version control,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1609 ;; that reason is gone now, so make it writable.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1610 (if (and (boundp 'vc-mode) vc-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1611 (setq buffer-read-only nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1612 (kill-local-variable 'vc-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1613 ;; Turn off backup files for certain file names.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1614 ;; Since this is a permanent local, the major mode won't eliminate it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1615 (and (not (funcall backup-enable-predicate buffer-file-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1616 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1617 (make-local-variable 'backup-inhibited)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1618 (setq backup-inhibited t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1619 (let ((oauto buffer-auto-save-file-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1620 ;; If auto-save was not already on, turn it on if appropriate.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1621 (if (not buffer-auto-save-file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1622 (and buffer-file-name auto-save-default
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1623 (auto-save-mode t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1624 ;; If auto save is on, start using a new name.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1625 ;; We deliberately don't rename or delete the old auto save
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1626 ;; for the old visited file name. This is because perhaps
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1627 ;; the user wants to save the new state and then compare with the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1628 ;; previous state from the auto save file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1629 (setq buffer-auto-save-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1630 (make-auto-save-file-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1631 ;; Rename the old auto save file if any.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1632 (and oauto buffer-auto-save-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1633 (file-exists-p oauto)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1634 (rename-file oauto buffer-auto-save-file-name t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1635 (if buffer-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1636 (set-buffer-modified-p t))
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1637 ;; #### ?? (Not in FSF -sb)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1638 (run-hooks 'after-set-visited-file-name-hooks))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1639
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1640 (defun write-file (filename &optional confirm)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1641 "Write current buffer into file FILENAME.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1642 Makes buffer visit that file, and marks it not modified.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1643 If the buffer is already visiting a file, you can specify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1644 a directory name as FILENAME, to write a file of the same
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1645 old name in that directory.
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1646
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1647 If optional second arg CONFIRM is non-nil,
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1648 ask for confirmation for overwriting an existing file.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1649 Interactively, confirmation is required unless you supply a prefix argument."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1650 ;; (interactive "FWrite file: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1651 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1652 (list (if buffer-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1653 (read-file-name "Write file: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1654 nil nil nil nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1655 (read-file-name "Write file: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1656 (cdr (assq 'default-directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1657 (buffer-local-variables)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1658 nil nil (buffer-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1659 t))
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1660 ;; XEmacs
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1661 (and (eq (current-buffer) mouse-grabbed-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1662 (error "Can't write minibuffer window"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1663 (or (null filename) (string-equal filename "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1664 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1665 ;; If arg is just a directory,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1666 ;; use same file name, but in that directory.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1667 (if (and (file-directory-p filename) buffer-file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1668 (setq filename (concat (file-name-as-directory filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1669 (file-name-nondirectory buffer-file-name))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1670 (and confirm
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1671 (file-exists-p filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1672 (or (y-or-n-p (format "File `%s' exists; overwrite? " filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1673 (error "Canceled")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1674 (set-visited-file-name filename)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1675 (set-buffer-modified-p t)
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1676 (setq buffer-read-only nil) ; XEmacs
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1677 (save-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1678
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1679 (defun backup-buffer ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1680 "Make a backup of the disk file visited by the current buffer, if appropriate.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1681 This is normally done before saving the buffer the first time.
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1682 If the value is non-nil, it is the result of `file-modes' on the original
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1683 file; this means that the caller, after saving the buffer, should change
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1684 the modes of the new file to agree with the old modes."
8
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
1685 (if buffer-file-name
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
1686 (let ((handler (find-file-name-handler buffer-file-name 'backup-buffer)))
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
1687 (if handler
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
1688 (funcall handler 'backup-buffer)
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
1689 (if (and make-backup-files (not backup-inhibited)
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
1690 (not buffer-backed-up)
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
1691 (file-exists-p buffer-file-name)
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
1692 (memq (aref (elt (file-attributes buffer-file-name) 8) 0)
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
1693 '(?- ?l)))
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
1694 (let ((real-file-name buffer-file-name)
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
1695 backup-info backupname targets setmodes)
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
1696 ;; If specified name is a symbolic link, chase it to the target.
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
1697 ;; Thus we make the backups in the directory where the real file is.
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
1698 (setq real-file-name (file-chase-links real-file-name))
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
1699 (setq backup-info (find-backup-file-name real-file-name)
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
1700 backupname (car backup-info)
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
1701 targets (cdr backup-info))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1702 ;;; (if (file-directory-p buffer-file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1703 ;;; (error "Cannot save buffer in directory %s" buffer-file-name))
8
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
1704 (if backup-info
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
1705 (condition-case ()
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
1706 (let ((delete-old-versions
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
1707 ;; If have old versions to maybe delete,
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
1708 ;; ask the user to confirm now, before doing anything.
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
1709 ;; But don't actually delete til later.
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
1710 (and targets
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
1711 (or (eq delete-old-versions t)
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
1712 (eq delete-old-versions nil))
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
1713 (or delete-old-versions
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
1714 (y-or-n-p (format "Delete excess backup versions of %s? "
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
1715 real-file-name))))))
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
1716 ;; Actually write the back up file.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1717 (condition-case ()
8
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
1718 (if (or file-precious-flag
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
1719 ; (file-symlink-p buffer-file-name)
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
1720 backup-by-copying
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
1721 (and backup-by-copying-when-linked
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
1722 (> (file-nlinks real-file-name) 1))
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
1723 (and backup-by-copying-when-mismatch
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
1724 (let ((attr (file-attributes real-file-name)))
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
1725 (or (nth 9 attr)
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
1726 (not (file-ownership-preserved-p real-file-name))))))
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
1727 (condition-case ()
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
1728 (copy-file real-file-name backupname t t)
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
1729 (file-error
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
1730 ;; If copying fails because file BACKUPNAME
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
1731 ;; is not writable, delete that file and try again.
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
1732 (if (and (file-exists-p backupname)
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
1733 (not (file-writable-p backupname)))
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
1734 (delete-file backupname))
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
1735 (copy-file real-file-name backupname t t)))
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
1736 ;; rename-file should delete old backup.
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
1737 (rename-file real-file-name backupname t)
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
1738 (setq setmodes (file-modes backupname)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1739 (file-error
8
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
1740 ;; If trouble writing the backup, write it in ~.
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
1741 (setq backupname (expand-file-name
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
1742 (convert-standard-filename
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
1743 "~/%backup%~")))
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
1744 (message "Cannot write backup file; backing up in %s"
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
1745 (file-name-nondirectory backupname))
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
1746 (sleep-for 1)
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
1747 (condition-case ()
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
1748 (copy-file real-file-name backupname t t)
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
1749 (file-error
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
1750 ;; If copying fails because file BACKUPNAME
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
1751 ;; is not writable, delete that file and try again.
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
1752 (if (and (file-exists-p backupname)
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
1753 (not (file-writable-p backupname)))
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
1754 (delete-file backupname))
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
1755 (copy-file real-file-name backupname t t)))))
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
1756 (setq buffer-backed-up t)
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
1757 ;; Now delete the old versions, if desired.
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
1758 (if delete-old-versions
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
1759 (while targets
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
1760 (condition-case ()
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
1761 (delete-file (car targets))
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
1762 (file-error nil))
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
1763 (setq targets (cdr targets))))
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
1764 setmodes)
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
1765 (file-error nil)))))))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1766
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1767 (defun file-name-sans-versions (name &optional keep-backup-version)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1768 "Return FILENAME sans backup versions or strings.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1769 This is a separate procedure so your site-init or startup file can
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1770 redefine it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1771 If the optional argument KEEP-BACKUP-VERSION is non-nil,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1772 we do not remove backup version numbers, only true file version numbers."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1773 (let ((handler (find-file-name-handler name 'file-name-sans-versions)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1774 (if handler
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1775 (funcall handler 'file-name-sans-versions name keep-backup-version)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1776 (substring name 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1777 (if (eq system-type 'vax-vms)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1778 ;; VMS version number is (a) semicolon, optional
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1779 ;; sign, zero or more digits or (b) period, option
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1780 ;; sign, zero or more digits, provided this is the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1781 ;; second period encountered outside of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1782 ;; device/directory part of the file name.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1783 (or (string-match ";[-+]?[0-9]*\\'" name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1784 (if (string-match "\\.[^]>:]*\\(\\.[-+]?[0-9]*\\)\\'"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1785 name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1786 (match-beginning 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1787 (length name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1788 (if keep-backup-version
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1789 (length name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1790 (or (string-match "\\.~[0-9.]+~\\'" name)
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1791 ;; XEmacs - VC uses extensions like ".~tagname~"
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1792 ;; or ".~1.1.5.2~"
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1793 (let ((pos (string-match "\\.~\\([^.~ \t]+\\|[0-9.]+\\)~\\'" name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1794 (and pos
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1795 ;; #### - is this filesystem check too paranoid?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1796 (file-exists-p (substring name 0 pos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1797 pos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1798 (string-match "~\\'" name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1799 (length name))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1800
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1801 (defun file-ownership-preserved-p (file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1802 "Returns t if deleting FILE and rewriting it would preserve the owner."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1803 (let ((handler (find-file-name-handler file 'file-ownership-preserved-p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1804 (if handler
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1805 (funcall handler 'file-ownership-preserved-p file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1806 (let ((attributes (file-attributes file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1807 ;; Return t if the file doesn't exist, since it's true that no
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1808 ;; information would be lost by an (attempted) delete and create.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1809 (or (null attributes)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1810 (= (nth 2 attributes) (user-uid)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1811
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1812 (defun file-name-sans-extension (filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1813 "Return FILENAME sans final \"extension\".
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1814 The extension, in a file name, is the part that follows the last `.'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1815 (save-match-data
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1816 (let ((file (file-name-sans-versions (file-name-nondirectory filename)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1817 directory)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1818 (if (string-match "\\.[^.]*\\'" file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1819 (if (setq directory (file-name-directory filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1820 (expand-file-name (substring file 0 (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1821 directory)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1822 (substring file 0 (match-beginning 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1823 filename))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1824
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1825 (defun make-backup-file-name (file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1826 "Create the non-numeric backup file name for FILE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1827 This is a separate function so you can redefine it for customization."
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1828 (if (and (eq system-type 'ms-dos)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1829 (not (msdos-long-file-names)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1830 (let ((fn (file-name-nondirectory file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1831 (concat (file-name-directory file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1832 (if (string-match "\\([^.]*\\)\\(\\..*\\)?" fn)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1833 (substring fn 0 (match-end 1)))
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1834 ; (or
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1835 ; (and (string-match "\\`[^.]+\\'" fn)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1836 ; (concat (match-string 0 fn) ".~"))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1837 ; (and (string-match "\\`[^.]+\\.\\(..?\\)?" fn)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1838 ; (concat (match-string 0 fn) "~")))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1839 ".bak"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1840 (concat file "~")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1841
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1842 (defun backup-file-name-p (file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1843 "Return non-nil if FILE is a backup file name (numeric or not).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1844 This is a separate function so you can redefine it for customization.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1845 You may need to redefine `file-name-sans-versions' as well."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1846 (if (eq system-type 'ms-dos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1847 (string-match "\\.bak\\'" file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1848 (string-match "~\\'" file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1849
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1850 ;; This is used in various files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1851 ;; The usage of bv-length is not very clean,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1852 ;; but I can't see a good alternative,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1853 ;; so as of now I am leaving it alone.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1854 (defun backup-extract-version (fn)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1855 "Given the name of a numeric backup file, return the backup number.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1856 Uses the free variable `bv-length', whose value should be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1857 the index in the name where the version number begins."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1858 (if (and (string-match "[0-9]+~\\'" fn bv-length)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1859 (= (match-beginning 0) bv-length))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1860 (string-to-int (substring fn bv-length -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1861 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1862
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1863 ;; I believe there is no need to alter this behavior for VMS;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1864 ;; since backup files are not made on VMS, it should not get called.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1865 (defun find-backup-file-name (fn)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1866 "Find a file name for a backup file, and suggestions for deletions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1867 Value is a list whose car is the name for the backup file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1868 and whose cdr is a list of old versions to consider deleting now.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1869 If the value is nil, don't make a backup."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1870 (let ((handler (find-file-name-handler fn 'find-backup-file-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1871 ;; Run a handler for this function so that ange-ftp can refuse to do it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1872 (if handler
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1873 (funcall handler 'find-backup-file-name fn)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1874 (if (eq version-control 'never)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1875 (list (make-backup-file-name fn))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1876 (let* ((base-versions (concat (file-name-nondirectory fn) ".~"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1877 ;; used by backup-extract-version:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1878 (bv-length (length base-versions))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1879 possibilities
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1880 (versions nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1881 (high-water-mark 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1882 (deserve-versions-p nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1883 (number-to-delete 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1884 (condition-case ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1885 (setq possibilities (file-name-all-completions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1886 base-versions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1887 (file-name-directory fn))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1888 versions (sort (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1889 #'backup-extract-version
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1890 possibilities)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1891 '<)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1892 high-water-mark (apply #'max 0 versions)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1893 deserve-versions-p (or version-control
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1894 (> high-water-mark 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1895 number-to-delete (- (length versions)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1896 kept-old-versions kept-new-versions -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1897 (file-error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1898 (setq possibilities nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1899 (if (not deserve-versions-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1900 (list (make-backup-file-name fn))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1901 (cons (concat fn ".~" (int-to-string (1+ high-water-mark)) "~")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1902 (if (and (> number-to-delete 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1903 ;; Delete nothing if there is overflow
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1904 ;; in the number of versions to keep.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1905 (>= (+ kept-new-versions kept-old-versions -1) 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1906 (mapcar #'(lambda (n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1907 (concat fn ".~" (int-to-string n) "~"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1908 (let ((v (nthcdr kept-old-versions versions)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1909 (rplacd (nthcdr (1- number-to-delete) v) ())
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1910 v))))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1911
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1912 (defun file-nlinks (filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1913 "Return number of names file FILENAME has."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1914 (car (cdr (file-attributes filename))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1915
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1916 (defun file-relative-name (filename &optional directory)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1917 "Convert FILENAME to be relative to DIRECTORY (default: default-directory)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1918 (setq filename (expand-file-name filename)
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1919 directory (file-name-as-directory (expand-file-name
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1920 (or directory default-directory))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1921 (let ((ancestor ""))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1922 (while (not (string-match (concat "^" (regexp-quote directory)) filename))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1923 (setq directory (file-name-directory (substring directory 0 -1))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1924 ancestor (concat "../" ancestor)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1925 (concat ancestor (substring filename (match-end 0)))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1926
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1927 (defun save-buffer (&optional args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1928 "Save current buffer in visited file if modified. Versions described below.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1929
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1930 By default, makes the previous version into a backup file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1931 if previously requested or if this is the first save.
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1932 With 1 \\[universal-argument], marks this version
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1933 to become a backup when the next save is done.
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1934 With 2 \\[universal-argument]'s,
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1935 unconditionally makes the previous version into a backup file.
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1936 With 3 \\[universal-argument]'s, marks this version
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1937 to become a backup when the next save is done,
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1938 and unconditionally makes the previous version into a backup file.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1939
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1940 With argument of 0, never makes the previous version into a backup file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1941
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1942 If a file's name is FOO, the names of its numbered backup versions are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1943 FOO.~i~ for various integers i. A non-numbered backup file is called FOO~.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1944 Numeric backups (rather than FOO~) will be made if value of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1945 `version-control' is not the atom `never' and either there are already
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1946 numeric versions of the file being backed up, or `version-control' is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1947 non-nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1948 We don't want excessive versions piling up, so there are variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1949 `kept-old-versions', which tells XEmacs how many oldest versions to keep,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1950 and `kept-new-versions', which tells how many newest versions to keep.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1951 Defaults are 2 old versions and 2 new.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1952 `dired-kept-versions' controls dired's clean-directory (.) command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1953 If `delete-old-versions' is nil, system will query user
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1954 before trimming versions. Otherwise it does it silently."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1955 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1956 (let ((modp (buffer-modified-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1957 (large (> (buffer-size) 50000))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1958 (make-backup-files (or (and make-backup-files (not (eq args 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1959 (memq args '(16 64)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1960 (and modp (memq args '(16 64)) (setq buffer-backed-up nil))
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1961 (if (and modp large) (message "Saving file %s..." (buffer-file-name)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1962 (basic-save-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1963 (and modp (memq args '(4 64)) (setq buffer-backed-up nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1964
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1965 (defun delete-auto-save-file-if-necessary (&optional force)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1966 "Delete auto-save file for current buffer if `delete-auto-save-files' is t.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1967 Normally delete only if the file was written by this XEmacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1968 since the last real save, but optional arg FORCE non-nil means delete anyway."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1969 (and buffer-auto-save-file-name delete-auto-save-files
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1970 (not (string= buffer-file-name buffer-auto-save-file-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1971 (or force (recent-auto-save-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1972 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1973 (condition-case ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1974 (delete-file buffer-auto-save-file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1975 (file-error nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1976 (set-buffer-auto-saved))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1977
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1978 ;; XEmacs change (from Sun)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1979 ;; used to communicate with continue-save-buffer:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1980 (defvar continue-save-buffer-hooks-tail nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1981
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1982 ;; Not in FSFmacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1983 (defun basic-write-file-data (realname truename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1984 ;; call the hooks until the bytes are put
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1985 ;; call write-region as a last resort
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1986 (let ((region-written nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1987 (hooks write-file-data-hooks))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1988 (while (and hooks (not region-written))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1989 (setq region-written (funcall (car hooks) realname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1990 hooks (cdr hooks)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1991 (if (not region-written)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1992 (write-region (point-min) (point-max) realname nil t truename))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1993
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1994 (put 'after-save-hook 'permanent-local t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1995 (defvar after-save-hook nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1996 "Normal hook that is run after a buffer is saved to its file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1997 These hooks are considered to pertain to the visited file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1998 So this list is cleared if you change the visited file name.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1999
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2000 (defun files-fetch-hook-value (hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2001 (let ((localval (symbol-value hook))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2002 (globalval (default-value hook)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2003 (if (memq t localval)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2004 (setq localval (append (delq t localval) (delq t globalval))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2005 localval))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2006
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2007 (defun basic-save-buffer ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2008 "Save the current buffer in its visited file, if it has been modified.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2009 After saving the buffer, run `after-save-hook'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2010 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2011 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2012 ;; In an indirect buffer, save its base buffer instead.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2013 (if (buffer-base-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2014 (set-buffer (buffer-base-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2015 (if (buffer-modified-p)
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2016 (let ((recent-save (recent-auto-save-p))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2017 setmodes tempsetmodes)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2018 ;; On VMS, rename file and buffer to get rid of version number.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2019 (if (and (eq system-type 'vax-vms)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2020 (not (string= buffer-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2021 (file-name-sans-versions buffer-file-name))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2022 (let (buffer-new-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2023 ;; Strip VMS version number before save.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2024 (setq buffer-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2025 (file-name-sans-versions buffer-file-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2026 ;; Construct a (unique) buffer name to correspond.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2027 (let ((buf (create-file-buffer (downcase buffer-file-name))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2028 (setq buffer-new-name (buffer-name buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2029 (kill-buffer buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2030 (rename-buffer buffer-new-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2031 ;; If buffer has no file name, ask user for one.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2032 (or buffer-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2033 (let ((filename
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2034 (expand-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2035 (read-file-name "File to save in: ") nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2036 (and (file-exists-p filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2037 (or (y-or-n-p (format "File `%s' exists; overwrite? "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2038 filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2039 (error "Canceled")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2040 (set-visited-file-name filename)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2041 (or (verify-visited-file-modtime (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2042 (not (file-exists-p buffer-file-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2043 (yes-or-no-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2044 (format "%s has changed since visited or saved. Save anyway? "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2045 (file-name-nondirectory buffer-file-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2046 (error "Save not confirmed"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2047 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2048 (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2049 (and (> (point-max) 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2050 (/= (char-after (1- (point-max))) ?\n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2051 (not (and (eq selective-display t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2052 (= (char-after (1- (point-max))) ?\r)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2053 (or (eq require-final-newline t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2054 (and require-final-newline
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2055 (y-or-n-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2056 (format "Buffer %s does not end in newline. Add one? "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2057 (buffer-name)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2058 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2059 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2060 (insert ?\n)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2061 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2062 ;; Run the write-file-hooks until one returns non-null.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2063 ;; Bind after-save-hook to nil while running the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2064 ;; write-file-hooks so that if this function is called
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2065 ;; recursively (from inside a write-file-hook) the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2066 ;; after-hooks will only get run once (from the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2067 ;; outermost call).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2068 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2069 ;; Ugh, have to duplicate logic of run-hook-with-args-until-success
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2070 (let ((hooks (append (files-fetch-hook-value 'write-contents-hooks)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2071 (files-fetch-hook-value
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2072 'local-write-file-hooks)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2073 (files-fetch-hook-value 'write-file-hooks)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2074 (after-save-hook nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2075 (local-write-file-hooks nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2076 (write-contents-hooks nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2077 (write-file-hooks nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2078 done)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2079 (while (and hooks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2080 (let ((continue-save-buffer-hooks-tail hooks))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2081 (not (setq done (funcall (car hooks))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2082 (setq hooks (cdr hooks)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2083 ;; If a hook returned t, file is already "written".
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2084 ;; Otherwise, write it the usual way now.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2085 (if (not done)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2086 (basic-save-buffer-1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2087 ;; XEmacs: next two clauses (buffer-file-number setting and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2088 ;; set-file-modes) moved into basic-save-buffer-1.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2089 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2090 ;; If the auto-save file was recent before this command,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2091 ;; delete it now.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2092 (delete-auto-save-file-if-necessary recent-save)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2093 ;; Support VC `implicit' locking.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2094 (vc-after-save)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2095 (run-hooks 'after-save-hook))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2096 (message "(No changes need to be saved)"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2097
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2098 ;; This does the "real job" of writing a buffer into its visited file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2099 ;; and making a backup file. This is what is normally done
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2100 ;; but inhibited if one of write-file-hooks returns non-nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2101 ;; It returns a value to store in setmodes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2102 (defun basic-save-buffer-1 ()
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2103 (let (tempsetmodes setmodes)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2104 (if (not (file-writable-p buffer-file-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2105 (let ((dir (file-name-directory buffer-file-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2106 (if (not (file-directory-p dir))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2107 (error "%s is not a directory" dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2108 (if (not (file-exists-p buffer-file-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2109 (error "Directory %s write-protected" dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2110 (if (yes-or-no-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2111 (format "File %s is write-protected; try to save anyway? "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2112 (file-name-nondirectory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2113 buffer-file-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2114 (setq tempsetmodes t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2115 (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2116 "Attempt to save to a file which you aren't allowed to write"))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2117 (or buffer-backed-up
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2118 (setq setmodes (backup-buffer)))
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2119 (let ((dir (file-name-directory buffer-file-name)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2120 (if (and file-precious-flag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2121 (file-writable-p dir))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2122 ;; If file is precious, write temp name, then rename it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2123 ;; This requires write access to the containing dir,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2124 ;; which is why we don't try it if we don't have that access.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2125 (let ((realname buffer-file-name)
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2126 tempname temp nogood i succeed
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2127 (old-modtime (visited-file-modtime)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2128 (setq i 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2129 (setq nogood t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2130 ;; Find the temporary name to write under.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2131 (while nogood
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2132 (setq tempname (format
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2133 (if (and (eq system-type 'ms-dos)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2134 (not (msdos-long-file-names)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2135 "%s#%d.tm#" ; MSDOS limits files to 8+3
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2136 "%s#tmp#%d")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2137 dir i))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2138 (setq nogood (file-exists-p tempname))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2139 (setq i (1+ i)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2140 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2141 (progn (clear-visited-file-modtime)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2142 (write-region (point-min) (point-max)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2143 tempname nil realname
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2144 buffer-file-truename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2145 (setq succeed t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2146 ;; If writing the temp file fails,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2147 ;; delete the temp file.
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2148 (or succeed
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2149 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2150 (delete-file tempname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2151 (set-visited-file-modtime old-modtime))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2152 ;; Since we have created an entirely new file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2153 ;; and renamed it, make sure it gets the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2154 ;; right permission bits set.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2155 (setq setmodes (file-modes buffer-file-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2156 ;; We succeeded in writing the temp file,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2157 ;; so rename it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2158 (rename-file tempname buffer-file-name t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2159 ;; If file not writable, see if we can make it writable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2160 ;; temporarily while we write it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2161 ;; But no need to do so if we have just backed it up
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2162 ;; (setmodes is set) because that says we're superseding.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2163 (cond ((and tempsetmodes (not setmodes))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2164 ;; Change the mode back, after writing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2165 (setq setmodes (file-modes buffer-file-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2166 (set-file-modes buffer-file-name 511)))
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2167 ;; XEmacs change to end of function
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2168 (basic-write-file-data buffer-file-name buffer-file-truename)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2169 (setq buffer-file-number
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2170 (if buffer-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2171 (nth 10 (file-attributes buffer-file-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2172 nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2173 (if setmodes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2174 (condition-case ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2175 (set-file-modes buffer-file-name setmodes)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2176 (error nil)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2177
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2178 ;; XEmacs change, from Sun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2179 (defun continue-save-buffer ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2180 "Provide a clean way for a write-file-hook to wrap AROUND
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2181 the execution of the remaining hooks and writing to disk.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2182 Do not call this function except from a functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2183 on the write-file-hooks or write-contents-hooks list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2184 A hook that calls this function must return non-nil,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2185 to signal completion to its caller. continue-save-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2186 always returns non-nil."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2187 (let ((hooks (cdr (or continue-save-buffer-hooks-tail
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2188 (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2189 "continue-save-buffer called outside a write-file-hook!"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2190 (done nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2191 ;; Do something like this:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2192 ;; (let ((write-file-hooks hooks)) (basic-save-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2193 ;; First run the rest of the hooks.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2194 (while (and hooks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2195 (let ((continue-save-buffer-hooks-tail hooks))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2196 (not (setq done (funcall (car hooks))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2197 (setq hooks (cdr hooks)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2198 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2199 ;; If a hook returned t, file is already "written".
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2200 (if (not done)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2201 (basic-save-buffer-1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2202 'continue-save-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2203
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2204 (defun save-some-buffers (&optional arg exiting)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2205 "Save some modified file-visiting buffers. Asks user about each one.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2206 Optional argument (the prefix) non-nil means save all with no questions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2207 Optional second argument EXITING means ask about certain non-file buffers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2208 as well as about file buffers."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2209 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2210 (save-window-excursion
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2211 ;; XEmacs - do not use queried flag
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2212 (let ((files-done
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2213 (map-y-or-n-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2214 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2215 (lambda (buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2216 (and (buffer-modified-p buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2217 (not (buffer-base-buffer buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2218 ;; XEmacs addition:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2219 (not (symbol-value-in-buffer 'save-buffers-skip buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2220 (or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2221 (buffer-file-name buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2222 (and exiting
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2223 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2224 (set-buffer buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2225 (and buffer-offer-save (> (buffer-size) 0)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2226 (if arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2227 t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2228 (if (buffer-file-name buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2229 (format "Save file %s? "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2230 (buffer-file-name buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2231 (format "Save buffer %s? "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2232 (buffer-name buffer)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2233 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2234 (lambda (buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2235 (set-buffer buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2236 (condition-case ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2237 (save-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2238 (error nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2239 (buffer-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2240 '("buffer" "buffers" "save")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2241 ;instead of this we just say "yes all", "no all", etc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2242 ;"save all the rest"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2243 ;"save only this buffer" "save no more buffers")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2244 ; this is rather bogus. --ben
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2245 ; (it makes the dialog box too big, and you get an error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2246 ; "wrong type argument: framep, nil" when you hit q after
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2247 ; choosing the option from the dialog box)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2248 ; (list (list ?\C-r (lambda (buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2249 ; (view-buffer buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2250 ; (setq view-exit-action
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2251 ; '(lambda (ignore)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2252 ; (exit-recursive-edit)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2253 ; (recursive-edit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2254 ; ;; Return nil to ask about BUF again.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2255 ; nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2256 ; "display the current buffer"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2257 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2258 (abbrevs-done
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2259 (and save-abbrevs abbrevs-changed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2260 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2261 (if (or arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2262 (y-or-n-p (format "Save abbrevs in %s? " abbrev-file-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2263 (write-abbrev-file nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2264 ;; Don't keep bothering user if he says no.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2265 (setq abbrevs-changed nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2266 t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2267 (or (> files-done 0) abbrevs-done
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2268 (message "(No files need saving)")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2269
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2270
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2271 (defun not-modified (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2272 "Mark current buffer as unmodified, not needing to be saved.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2273 With prefix arg, mark buffer as modified, so \\[save-buffer] will save.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2274
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2275 It is not a good idea to use this function in Lisp programs, because it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2276 prints a message in the minibuffer. Instead, use `set-buffer-modified-p'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2277 (interactive "_P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2278 (if arg ;; rewritten for I18N3 snarfing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2279 (message "Modification-flag set")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2280 (message "Modification-flag cleared"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2281 (set-buffer-modified-p arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2282
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2283 (defun toggle-read-only (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2284 "Change whether this buffer is visiting its file read-only.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2285 With arg, set read-only iff arg is positive."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2286 (interactive "_P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2287 (setq buffer-read-only
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2288 (if (null arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2289 (not buffer-read-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2290 (> (prefix-numeric-value arg) 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2291 ;; Force modeline redisplay
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2292 (redraw-modeline))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2293
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2294 (defun insert-file (filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2295 "Insert contents of file FILENAME into buffer after point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2296 Set mark after the inserted text.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2297
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2298 This function is meant for the user to run interactively.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2299 Don't call it from programs! Use `insert-file-contents' instead.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2300 \(Its calling sequence is different; see its documentation)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2301 (interactive "*fInsert file: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2302 (if (file-directory-p filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2303 (signal 'file-error (list "Opening input file" "file is a directory"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2304 filename)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2305 (let ((tem (insert-file-contents filename)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2306 (push-mark (+ (point) (car (cdr tem))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2307
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2308 (defun append-to-file (start end filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2309 "Append the contents of the region to the end of file FILENAME.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2310 When called from a function, expects three arguments,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2311 START, END and FILENAME. START and END are buffer positions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2312 saying what text to write."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2313 (interactive "r\nFAppend to file: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2314 (write-region start end filename t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2315
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2316 (defun file-newest-backup (filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2317 "Return most recent backup file for FILENAME or nil if no backups exist."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2318 (let* ((filename (expand-file-name filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2319 (file (file-name-nondirectory filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2320 (dir (file-name-directory filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2321 (comp (file-name-all-completions file dir))
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2322 newest tem)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2323 (while comp
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2324 (setq tem (car comp)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2325 comp (cdr comp))
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2326 (cond ((and (backup-file-name-p tem)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2327 (string= (file-name-sans-versions tem) file))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2328 (setq tem (concat dir tem))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2329 (if (or (null newest)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2330 (file-newer-than-file-p tem newest))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2331 (setq newest tem)))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2332 newest))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2333
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2334 (defun rename-uniquely ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2335 "Rename current buffer to a similar name not already taken.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2336 This function is useful for creating multiple shell process buffers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2337 or multiple mail buffers, etc."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2338 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2339 (save-match-data
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2340 (let* ((base-name (if (and (string-match "<[0-9]+>\\'" (buffer-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2341 (not (and buffer-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2342 (string= (buffer-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2343 (file-name-nondirectory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2344 buffer-file-name)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2345 ;; If the existing buffer name has a <NNN>,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2346 ;; which isn't part of the file name (if any),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2347 ;; then get rid of that.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2348 (substring (buffer-name) 0 (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2349 (buffer-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2350 (new-buf (generate-new-buffer base-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2351 (name (buffer-name new-buf)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2352 (kill-buffer new-buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2353 (rename-buffer name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2354 (redraw-modeline))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2355
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2356 ;; XEmacs
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2357 (defun make-directory-path (path)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2358 "Create all the directories along path that don't exist yet."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2359 (interactive "Fdirectory path to create: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2360 (make-directory path t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2361
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2362 (defun make-directory (dir &optional parents)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2363 "Create the directory DIR and any nonexistent parent dirs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2364 Interactively, the default choice of directory to create
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2365 is the current default directory for file names.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2366 That is useful when you have visited a file in a nonexistent directory.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2367
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2368 Noninteractively, the second (optional) argument PARENTS says whether
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2369 to create parent directories if they don't exist."
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2370 ;; XEmacs
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2371 (interactive (list (let ((current-prefix-arg current-prefix-arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2372 (read-directory-name "Create directory: "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2373 current-prefix-arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2374 (let ((handler (find-file-name-handler dir 'make-directory)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2375 (if handler
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2376 (funcall handler 'make-directory dir parents)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2377 (if (not parents)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2378 (make-directory-internal dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2379 (let ((dir (directory-file-name (expand-file-name dir)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2380 create-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2381 (while (not (file-exists-p dir))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2382 (setq create-list (cons dir create-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2383 dir (directory-file-name (file-name-directory dir))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2384 (while create-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2385 (make-directory-internal (car create-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2386 (setq create-list (cdr create-list))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2387
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2388 (put 'revert-buffer-function 'permanent-local t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2389 (defvar revert-buffer-function nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2390 "Function to use to revert this buffer, or nil to do the default.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2391 The function receives two arguments IGNORE-AUTO and NOCONFIRM,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2392 which are the arguments that `revert-buffer' received.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2393
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2394 (put 'revert-buffer-insert-file-contents-function 'permanent-local t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2395 (defvar revert-buffer-insert-file-contents-function nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2396 "Function to use to insert contents when reverting this buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2397 Gets two args, first the nominal file name to use,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2398 and second, t if reading the auto-save file.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2399
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2400 (defvar before-revert-hook nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2401 "Normal hook for `revert-buffer' to run before reverting.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2402 If `revert-buffer-function' is used to override the normal revert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2403 mechanism, this hook is not used.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2404
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2405 (defvar after-revert-hook nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2406 "Normal hook for `revert-buffer' to run after reverting.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2407 Note that the hook value that it runs is the value that was in effect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2408 before reverting; that makes a difference if you have buffer-local
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2409 hook functions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2410
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2411 If `revert-buffer-function' is used to override the normal revert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2412 mechanism, this hook is not used.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2413
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2414 (defun revert-buffer (&optional ignore-auto noconfirm preserve-modes)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2415 "Replace the buffer text with the text of the visited file on disk.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2416 This undoes all changes since the file was visited or saved.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2417 With a prefix argument, offer to revert from latest auto-save file, if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2418 that is more recent than the visited file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2419 When called from Lisp, the first argument is IGNORE-AUTO; only offer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2420 to revert from the auto-save file when this is nil. Note that the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2421 sense of this argument is the reverse of the prefix argument, for the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2422 sake of backward compatibility. IGNORE-AUTO is optional, defaulting
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2423 to nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2424
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2425 Optional second argument NOCONFIRM means don't ask for confirmation at
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2426 all.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2427
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2428 If the value of `revert-buffer-function' is non-nil, it is called to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2429 do the work.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2430
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2431 The default revert function runs the hook `before-revert-hook' at the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2432 beginning and `after-revert-hook' at the end."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2433 ;; I admit it's odd to reverse the sense of the prefix argument, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2434 ;; there is a lot of code out there which assumes that the first
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2435 ;; argument should be t to avoid consulting the auto-save file, and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2436 ;; there's no straightforward way to encourage authors to notice a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2437 ;; reversal of the argument sense. So I'm just changing the user
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2438 ;; interface, but leaving the programmatic interface the same.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2439 (interactive (list (not current-prefix-arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2440 (if revert-buffer-function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2441 (funcall revert-buffer-function ignore-auto noconfirm)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2442 (let* ((opoint (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2443 (auto-save-p (and (not ignore-auto)
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2444 (recent-auto-save-p)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2445 buffer-auto-save-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2446 (file-readable-p buffer-auto-save-file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2447 (y-or-n-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2448 "Buffer has been auto-saved recently. Revert from auto-save file? ")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2449 (file-name (if auto-save-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2450 buffer-auto-save-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2451 buffer-file-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2452 (cond ((null file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2453 (error "Buffer does not seem to be associated with any file"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2454 ((or noconfirm
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2455 (yes-or-no-p (format "Revert buffer from file %s? "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2456 file-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2457 (run-hooks 'before-revert-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2458 ;; If file was backed up but has changed since,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2459 ;; we shd make another backup.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2460 (and (not auto-save-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2461 (not (verify-visited-file-modtime (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2462 (setq buffer-backed-up nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2463 ;; Get rid of all undo records for this buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2464 (or (eq buffer-undo-list t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2465 (setq buffer-undo-list nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2466 ;; Effectively copy the after-revert-hook status,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2467 ;; since after-find-file will clobber it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2468 (let ((global-hook (default-value 'after-revert-hook))
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2469 ;; XEmacs
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2470 (local-hook-p (local-variable-p 'after-revert-hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2471 (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2472 (local-hook (and (local-variable-p 'after-revert-hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2473 (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2474 after-revert-hook)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2475 (let (buffer-read-only
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2476 ;; Don't make undo records for the reversion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2477 (buffer-undo-list t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2478 (if revert-buffer-insert-file-contents-function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2479 (funcall revert-buffer-insert-file-contents-function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2480 file-name auto-save-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2481 (if (not (file-exists-p file-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2482 (error "File %s no longer exists!" file-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2483 ;; Bind buffer-file-name to nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2484 ;; so that we don't try to lock the file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2485 (let ((buffer-file-name nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2486 (or auto-save-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2487 (unlock-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2488 (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2489 (insert-file-contents file-name (not auto-save-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2490 nil nil t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2491 (goto-char (min opoint (point-max)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2492 ;; Recompute the truename in case changes in symlinks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2493 ;; have changed the truename.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2494 ;XEmacs: already done by insert-file-contents
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2495 ;(compute-buffer-file-truename)
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2496 (after-find-file nil nil t t preserve-modes)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2497 ;; Run after-revert-hook as it was before we reverted.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2498 (setq-default revert-buffer-internal-hook global-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2499 (if local-hook-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2500 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2501 (make-local-variable 'revert-buffer-internal-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2502 (setq revert-buffer-internal-hook local-hook))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2503 (kill-local-variable 'revert-buffer-internal-hook))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2504 (run-hooks 'revert-buffer-internal-hook))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2505 t)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2506
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2507 (defun recover-file (file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2508 "Visit file FILE, but get contents from its last auto-save file."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2509 ;; Actually putting the file name in the minibuffer should be used
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2510 ;; only rarely.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2511 ;; Not just because users often use the default.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2512 (interactive "FRecover file: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2513 (setq file (expand-file-name file))
8
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
2514 (let ((handler (or (find-file-name-handler file 'recover-file)
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
2515 (find-file-name-handler
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
2516 (let ((buffer-file-name file))
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
2517 (make-auto-save-file-name))
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
2518 'recover-file))))
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
2519 (if handler
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
2520 (funcall handler 'recover-file file)
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
2521 (if (auto-save-file-name-p (file-name-nondirectory file))
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
2522 (error "%s is an auto-save file" file))
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
2523 (let ((file-name (let ((buffer-file-name file))
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
2524 (make-auto-save-file-name))))
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
2525 (cond ((if (file-exists-p file)
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
2526 (not (file-newer-than-file-p file-name file))
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
2527 (not (file-exists-p file-name)))
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
2528 (error "Auto-save file %s not current" file-name))
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
2529 ((save-window-excursion
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
2530 (if (not (eq system-type 'vax-vms))
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
2531 (with-output-to-temp-buffer "*Directory*"
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
2532 (buffer-disable-undo standard-output)
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
2533 (call-process "ls" nil standard-output nil
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
2534 (if (file-symlink-p file) "-lL" "-l")
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
2535 file file-name)))
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
2536 (yes-or-no-p (format "Recover auto save file %s? " file-name)))
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
2537 (switch-to-buffer (find-file-noselect file t))
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
2538 (let ((buffer-read-only nil))
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
2539 (erase-buffer)
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
2540 (insert-file-contents file-name nil))
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
2541 (after-find-file nil nil t))
4b173ad71786 Import from CVS: tag r19-15b5
cvs
parents: 6
diff changeset
2542 (t (error "Recover-file cancelled.")))))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2543
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2544 (defun recover-session ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2545 "Recover auto save files from a previous Emacs session.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2546 This command first displays a Dired buffer showing you the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2547 previous sessions that you could recover from.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2548 To choose one, move point to the proper line and then type C-c C-c.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2549 Then you'll be asked about a number of files to recover."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2550 (interactive)
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2551 (let ((ls-lisp-support-shell-wildcards t))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2552 (dired (concat auto-save-list-file-prefix "*")))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2553 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2554 (or (looking-at "Move to the session you want to recover,")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2555 (let ((inhibit-read-only t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2556 (insert "Move to the session you want to recover,\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2557 "then type C-c C-c to select it.\n\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2558 "You can also delete some of these files;\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2559 "type d on a line to mark that file for deletion.\n\n")))
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2560 ;; XEmacs
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2561 (use-local-map (let ((map (make-sparse-keymap)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2562 (set-keymap-parents map (list (current-local-map)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2563 map))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2564 (define-key (current-local-map) "\C-c\C-c" 'recover-session-finish))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2565
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2566 (defun recover-session-finish ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2567 "Choose one saved session to recover auto-save files from.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2568 This command is used in the special Dired buffer created by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2569 \\[recover-session]."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2570 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2571 ;; Get the name of the session file to recover from.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2572 (let ((file (dired-get-filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2573 files
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2574 (buffer (get-buffer-create " *recover*")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2575 ;; #### dired-do-flagged-delete in FSF.
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents: 16
diff changeset
2576 ;; This version is for ange-ftp
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents: 16
diff changeset
2577 ;;(dired-do-deletions t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents: 16
diff changeset
2578 ;T This version is for efs
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents: 16
diff changeset
2579 (dired-expunge-deletions)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2580 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2581 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2582 ;; Read in the auto-save-list file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2583 (set-buffer buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2584 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2585 (insert-file-contents file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2586 ;; Loop thru the text of that file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2587 ;; and get out the names of the files to recover.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2588 (while (not (eobp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2589 (let (thisfile autofile)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2590 (if (eolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2591 ;; This is a pair of lines for a non-file-visiting buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2592 ;; Get the auto-save file name and manufacture
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2593 ;; a "visited file name" from that.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2594 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2595 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2596 (setq autofile
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2597 (buffer-substring-no-properties
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2598 (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2599 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2600 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2601 (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2602 (setq thisfile
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2603 (expand-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2604 (substring
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2605 (file-name-nondirectory autofile)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2606 1 -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2607 (file-name-directory autofile)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2608 (forward-line 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2609 ;; This pair of lines is a file-visiting
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2610 ;; buffer. Use the visited file name.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2611 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2612 (setq thisfile
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2613 (buffer-substring-no-properties
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2614 (point) (progn (end-of-line) (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2615 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2616 (setq autofile
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2617 (buffer-substring-no-properties
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2618 (point) (progn (end-of-line) (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2619 (forward-line 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2620 ;; Ignore a file if its auto-save file does not exist now.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2621 (if (file-exists-p autofile)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2622 (setq files (cons thisfile files)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2623 (setq files (nreverse files))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2624 ;; The file contains a pair of line for each auto-saved buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2625 ;; The first line of the pair contains the visited file name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2626 ;; or is empty if the buffer was not visiting a file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2627 ;; The second line is the auto-save file name.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2628 (if files
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2629 (map-y-or-n-p "Recover %s? "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2630 (lambda (file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2631 (condition-case nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2632 (save-excursion (recover-file file))
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2633 (error
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2634 "Failed to recover `%s'" file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2635 files
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2636 '("file" "files" "recover"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2637 (message "No files can be recovered from this session now")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2638 (kill-buffer buffer))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2639
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2640 (defun kill-some-buffers ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2641 "For each buffer, ask whether to kill it."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2642 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2643 (let ((list (buffer-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2644 (while list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2645 (let* ((buffer (car list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2646 (name (buffer-name buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2647 (and (not (string-equal name ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2648 (/= (aref name 0) ? )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2649 (yes-or-no-p
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2650 ;; XEmacs change
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2651 (format
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2652 (if (buffer-modified-p buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2653 (gettext "Buffer %s HAS BEEN EDITED. Kill? ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2654 (gettext "Buffer %s is unmodified. Kill? "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2655 name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2656 (kill-buffer buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2657 (setq list (cdr list)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2658
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2659 (defun auto-save-mode (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2660 "Toggle auto-saving of contents of current buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2661 With prefix argument ARG, turn auto-saving on if positive, else off."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2662 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2663 (setq buffer-auto-save-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2664 (and (if (null arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2665 (or (not buffer-auto-save-file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2666 ;; If autosave is off because buffer has shrunk,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2667 ;; then toggling should turn it on.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2668 (< buffer-saved-size 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2669 (or (eq arg t) (listp arg) (and (integerp arg) (> arg 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2670 (if (and buffer-file-name auto-save-visited-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2671 (not buffer-read-only))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2672 buffer-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2673 (make-auto-save-file-name))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2674 ;; If -1 was stored here, to temporarily turn off saving,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2675 ;; turn it back on.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2676 (and (< buffer-saved-size 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2677 (setq buffer-saved-size 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2678 (if (interactive-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2679 (if buffer-auto-save-file-name ;; rewritten for I18N3 snarfing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2680 (message "Auto-save on (in this buffer)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2681 (message "Auto-save off (in this buffer)")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2682 buffer-auto-save-file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2683
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2684 (defun rename-auto-save-file ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2685 "Adjust current buffer's auto save file name for current conditions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2686 Also rename any existing auto save file, if it was made in this session."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2687 (let ((osave buffer-auto-save-file-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2688 (setq buffer-auto-save-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2689 (make-auto-save-file-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2690 (if (and osave buffer-auto-save-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2691 (not (string= buffer-auto-save-file-name buffer-file-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2692 (not (string= buffer-auto-save-file-name osave))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2693 (file-exists-p osave)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2694 (recent-auto-save-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2695 (rename-file osave buffer-auto-save-file-name t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2696
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2697 ;; see also ../packages/auto-save.el
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2698 ;; XEmacs change
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2699 (defun make-auto-save-file-name (&optional filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2700 "Return file name to use for auto-saves of current buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2701 Does not consider `auto-save-visited-file-name' as that variable is checked
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2702 before calling this function. You can redefine this for customization.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2703 See also `auto-save-file-name-p'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2704 (let ((fname (or filename buffer-file-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2705 name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2706 (setq name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2707 (if fname
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2708 (concat (file-name-directory fname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2709 "#"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2710 (file-name-nondirectory fname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2711 "#")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2712
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2713 ;; Deal with buffers that don't have any associated files. (Mail
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2714 ;; mode tends to create a good number of these.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2715
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2716 (let ((buffer-name (buffer-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2717 (limit 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2718 ;; Use technique from Sebastian Kremer's auto-save
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2719 ;; package to turn slashes into \\!. This ensures that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2720 ;; the auto-save buffer name is unique.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2721
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2722 ;; #### - yuck! yuck! yuck! move this functionality
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2723 ;; somewhere else and make the name translation customizable.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2724 ;; Using "\!" as part of a filename on a UNIX filesystem is nearly
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2725 ;; IMPOSSIBLE to get past a shell parser. -stig
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2726
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2727 (while (string-match "[/\\]" buffer-name limit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2728 (setq buffer-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2729 (concat (substring buffer-name 0 (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2730 (if (string= (substring buffer-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2731 (match-beginning 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2732 (match-end 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2733 "/")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2734 "\\!"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2735 "\\\\")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2736 (substring buffer-name (match-end 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2737 (setq limit (1+ (match-end 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2738
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2739 ;; (expand-file-name (format "#%s#%s#" (buffer-name) (make-temp-name "")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2740
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2741 ;; jwz: putting the emacs PID in the auto-save file name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2742 ;; is bad news, because that defeats auto-save-recovery of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2743 ;; *mail* buffers -- the (sensible) code in sendmail.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2744 ;; calls (make-auto-save-file-name) to determine whether
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2745 ;; there is unsent, auto-saved mail to recover. If that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2746 ;; mail came from a previous emacs process (far and away
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2747 ;; the most likely case) then this can never succeed as
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2748 ;; the pid differs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2749
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2750 (expand-file-name (format "#%s#" buffer-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2751 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2752 ;; don't try to write auto-save files in unwritable places. Unless
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2753 ;; there's already an autosave file here, put ours somewhere safe. --Stig
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2754 (if (or (file-writable-p name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2755 (file-exists-p name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2756 name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2757 (expand-file-name (concat "~/" (file-name-nondirectory name))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2758
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2759 (defun auto-save-file-name-p (filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2760 "Return non-nil if FILENAME can be yielded by `make-auto-save-file-name'.
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2761 FILENAME should lack slashes. You can redefine this for customization."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2762 (string-match "\\`#.*#\\'" filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2763
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2764 (defun wildcard-to-regexp (wildcard)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2765 "Given a shell file name pattern WILDCARD, return an equivalent regexp.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2766 The generated regexp will match a filename iff the filename
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2767 matches that wildcard according to shell rules. Only wildcards known
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2768 by `sh' are supported."
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2769 (let* ((i (string-match "[[.*+\\^$?]" wildcard))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2770 ;; Copy the initial run of non-special characters.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2771 (result (substring wildcard 0 i))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2772 (len (length wildcard)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2773 ;; If no special characters, we're almost done.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2774 (if i
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2775 (while (< i len)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2776 (let ((ch (aref wildcard i))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2777 j)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2778 (setq
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2779 result
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2780 (concat result
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2781 (cond
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2782 ((eq ch ?\[) ; [...] maps to regexp char class
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2783 (progn
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2784 (setq i (1+ i))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2785 (concat
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2786 (cond
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2787 ((eq (aref wildcard i) ?!) ; [!...] -> [^...]
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2788 (progn
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2789 (setq i (1+ i))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2790 (if (eq (aref wildcard i) ?\])
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2791 (progn
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2792 (setq i (1+ i))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2793 "[^]")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2794 "[^")))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2795 ((eq (aref wildcard i) ?^)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2796 ;; Found "[^". Insert a `\0' character
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2797 ;; (which cannot happen in a filename)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2798 ;; into the character class, so that `^'
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2799 ;; is not the first character after `[',
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2800 ;; and thus non-special in a regexp.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2801 (progn
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2802 (setq i (1+ i))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2803 "[\000^"))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2804 ((eq (aref wildcard i) ?\])
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2805 ;; I don't think `]' can appear in a
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2806 ;; character class in a wildcard, but
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2807 ;; let's be general here.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2808 (progn
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2809 (setq i (1+ i))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2810 "[]"))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2811 (t "["))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2812 (prog1 ; copy everything upto next `]'.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2813 (substring wildcard
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2814 i
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2815 (setq j (string-match
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2816 "]" wildcard i)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2817 (setq i (if j (1- j) (1- len)))))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2818 ((eq ch ?.) "\\.")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2819 ((eq ch ?*) "[^\000]*")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2820 ((eq ch ?+) "\\+")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2821 ((eq ch ?^) "\\^")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2822 ((eq ch ?$) "\\$")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2823 ((eq ch ?\\) "\\\\") ; probably cannot happen...
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2824 ((eq ch ??) "[^\000]")
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2825 (t (char-to-string ch)))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2826 (setq i (1+ i)))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2827 ;; Shell wildcards should match the entire filename,
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2828 ;; not its part. Make the regexp say so.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2829 (concat "\\`" result "\\'")))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2830
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2831 (defconst list-directory-brief-switches
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2832 (if (eq system-type 'vax-vms) "" "-CF")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2833 "*Switches for list-directory to pass to `ls' for brief listing,")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2834
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2835 (defconst list-directory-verbose-switches
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2836 (if (eq system-type 'vax-vms)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2837 "/PROTECTION/SIZE/DATE/OWNER/WIDTH=(OWNER:10)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2838 "-l")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2839 "*Switches for list-directory to pass to `ls' for verbose listing,")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2840
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2841 (defun list-directory (dirname &optional verbose)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2842 "Display a list of files in or matching DIRNAME, a la `ls'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2843 DIRNAME is globbed by the shell if necessary.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2844 Prefix arg (second arg if noninteractive) means supply -l switch to `ls'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2845 Actions controlled by variables `list-directory-brief-switches'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2846 and `list-directory-verbose-switches'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2847 (interactive (let ((pfx current-prefix-arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2848 (list (read-file-name (if pfx (gettext "List directory (verbose): ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2849 (gettext "List directory (brief): "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2850 nil default-directory nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2851 pfx)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2852 (let ((switches (if verbose list-directory-verbose-switches
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2853 list-directory-brief-switches)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2854 (or dirname (setq dirname default-directory))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2855 (setq dirname (expand-file-name dirname))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2856 (with-output-to-temp-buffer "*Directory*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2857 (buffer-disable-undo standard-output)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2858 (princ "Directory ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2859 (princ dirname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2860 (terpri)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2861 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2862 (set-buffer "*Directory*")
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2863 (setq default-directory
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2864 (if (file-directory-p dirname)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2865 (file-name-as-directory dirname)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2866 (file-name-directory dirname)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2867 (let ((wildcard (not (file-directory-p dirname))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2868 (insert-directory dirname switches wildcard (not wildcard)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2869
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2870 (defvar insert-directory-program "ls"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2871 "Absolute or relative name of the `ls' program used by `insert-directory'.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2872
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2873 ;; insert-directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2874 ;; - must insert _exactly_one_line_ describing FILE if WILDCARD and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2875 ;; FULL-DIRECTORY-P is nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2876 ;; The single line of output must display FILE's name as it was
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2877 ;; given, namely, an absolute path name.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2878 ;; - must insert exactly one line for each file if WILDCARD or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2879 ;; FULL-DIRECTORY-P is t, plus one optional "total" line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2880 ;; before the file lines, plus optional text after the file lines.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2881 ;; Lines are delimited by "\n", so filenames containing "\n" are not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2882 ;; allowed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2883 ;; File lines should display the basename.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2884 ;; - must be consistent with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2885 ;; - functions dired-move-to-filename, (these two define what a file line is)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2886 ;; dired-move-to-end-of-filename,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2887 ;; dired-between-files, (shortcut for (not (dired-move-to-filename)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2888 ;; dired-insert-headerline
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2889 ;; dired-after-subdir-garbage (defines what a "total" line is)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2890 ;; - variable dired-subdir-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2891 (defun insert-directory (file switches &optional wildcard full-directory-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2892 "Insert directory listing for FILE, formatted according to SWITCHES.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2893 Leaves point after the inserted text.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2894 SWITCHES may be a string of options, or a list of strings.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2895 Optional third arg WILDCARD means treat FILE as shell wildcard.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2896 Optional fourth arg FULL-DIRECTORY-P means file is a directory and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2897 switches do not contain `d', so that a full listing is expected.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2898
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2899 This works by running a directory listing program
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2900 whose name is in the variable `insert-directory-program'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2901 If WILDCARD, it also runs the shell specified by `shell-file-name'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2902 ;; We need the directory in order to find the right handler.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2903 (let ((handler (find-file-name-handler (expand-file-name file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2904 'insert-directory)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2905 (if handler
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2906 (funcall handler 'insert-directory file switches
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2907 wildcard full-directory-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2908 (if (eq system-type 'vax-vms)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2909 (vms-read-directory file switches (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2910 (if wildcard
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2911 ;; Run ls in the directory of the file pattern we asked for.
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2912 (let ((default-directory
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2913 (if (file-name-absolute-p file)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2914 (file-name-directory file)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2915 (file-name-directory (expand-file-name file))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2916 (pattern (file-name-nondirectory file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2917 (beg 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2918 ;; Quote some characters that have special meanings in shells;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2919 ;; but don't quote the wildcards--we want them to be special.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2920 ;; We also currently don't quote the quoting characters
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2921 ;; in case people want to use them explicitly to quote
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2922 ;; wildcard characters.
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2923 ;;#### Unix-specific
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2924 (while (string-match "[ \t\n;<>&|()#$]" pattern beg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2925 (setq pattern
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2926 (concat (substring pattern 0 (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2927 "\\"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2928 (substring pattern (match-beginning 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2929 beg (1+ (match-end 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2930 (call-process shell-file-name nil t nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2931 "-c" (concat "\\" ;; Disregard shell aliases!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2932 insert-directory-program
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2933 " -d "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2934 (if (stringp switches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2935 switches
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2936 (mapconcat 'identity switches " "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2937 " "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2938 pattern)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2939 ;; SunOS 4.1.3, SVr4 and others need the "." to list the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2940 ;; directory if FILE is a symbolic link.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2941 (apply 'call-process
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2942 insert-directory-program nil t nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2943 (let (list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2944 (if (listp switches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2945 (setq list switches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2946 (if (not (equal switches ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2947 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2948 ;; Split the switches at any spaces
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2949 ;; so we can pass separate options as separate args.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2950 (while (string-match " " switches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2951 (setq list (cons (substring switches 0 (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2952 list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2953 switches (substring switches (match-end 0))))
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2954 (setq list (nreverse (cons switches list))))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2955 (append list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2956 (list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2957 (if full-directory-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2958 (concat (file-name-as-directory file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2959 ;;#### Unix-specific
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2960 ".")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2961 file))))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2962
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2963 (defvar kill-emacs-query-functions nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2964 "Functions to call with no arguments to query about killing XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2965 If any of these functions returns nil, killing Emacs is cancelled.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2966 `save-buffers-kill-emacs' (\\[save-buffers-kill-emacs]) calls these functions,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2967 but `kill-emacs', the low level primitive, does not.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2968 See also `kill-emacs-hook'.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2969
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2970 (defun save-buffers-kill-emacs (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2971 "Offer to save each buffer, then kill this XEmacs process.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2972 With prefix arg, silently save all file-visiting buffers, then kill."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2973 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2974 (save-some-buffers arg t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2975 (and (or (not (memq t (mapcar #'(lambda (buf) (and (buffer-file-name buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2976 (buffer-modified-p buf)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2977 (buffer-list))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2978 (yes-or-no-p "Modified buffers exist; exit anyway? "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2979 (or (not (fboundp 'process-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2980 ;; process-list is not defined on VMS.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2981 (let ((processes (process-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2982 active)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2983 (while processes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2984 (and (memq (process-status (car processes)) '(run stop open))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2985 (let ((val (process-kill-without-query (car processes))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2986 (process-kill-without-query (car processes) val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2987 val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2988 (setq active t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2989 (setq processes (cdr processes)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2990 (or (not active)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2991 (yes-or-no-p "Active processes exist; kill them and exit anyway? "))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2992 ;; Query the user for other things, perhaps.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2993 (run-hook-with-args-until-failure 'kill-emacs-query-functions)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2994 (kill-emacs)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2995
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2996 ;; XEmacs
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2997 (defun symlink-expand-file-name (filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2998 "If FILENAME is a symlink, return its non-symlink equivalent.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2999 Unlike `file-truename', this doesn't chase symlinks in directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3000 components of the file or expand a relative pathname into an
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3001 absolute one."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3002 (let ((count 20))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3003 (while (and (> count 0) (file-symlink-p filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3004 (setq filename (file-symlink-p filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3005 count (1- count)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3006 (if (> count 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3007 filename
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3008 (error "Apparently circular symlink path"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3009
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents: 16
diff changeset
3010 ;; Suggested by Michael Kifer <kifer@CS.SunySB.EDU>
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents: 16
diff changeset
3011 (defun file-remote-p (file)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents: 16
diff changeset
3012 "Test whether file resides on the local system.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents: 16
diff changeset
3013 The special value 'unknown is returned if no remote file access package
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents: 16
diff changeset
3014 has been loaded."
24
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
3015 (cond ((featurep 'ange-ftp) (ange-ftp-ftp-path file-name))
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
3016 (t (require 'efs)
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents: 22
diff changeset
3017 (efs-ftp-path file-name))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3018
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
3019 ;; Written in C in FSF
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3020 (defun insert-file-contents (filename &optional visit beg end replace)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3021 "Insert contents of file FILENAME after point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3022 Returns list of absolute file name and length of data inserted.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3023 If second argument VISIT is non-nil, the buffer's visited filename
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3024 and last save file modtime are set, and it is marked unmodified.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3025 If visiting and the file does not exist, visiting is completed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3026 before the error is signaled.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3027
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3028 The optional third and fourth arguments BEG and END
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3029 specify what portion of the file to insert.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3030 If VISIT is non-nil, BEG and END must be nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3031 If optional fifth argument REPLACE is non-nil,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3032 it means replace the current buffer contents (in the accessible portion)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3033 with the file contents. This is better than simply deleting and inserting
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3034 the whole thing because (1) it preserves some marker positions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3035 and (2) it puts less data in the undo list."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3036 (insert-file-contents-internal filename visit beg end replace))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3037
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
3038 ;; Written in C in FSF
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3039 (defun write-region (start end filename &optional append visit lockname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3040 "Write current region into specified file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3041 When called from a program, takes three arguments:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3042 START, END and FILENAME. START and END are buffer positions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3043 Optional fourth argument APPEND if non-nil means
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3044 append to existing file contents (if any).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3045 Optional fifth argument VISIT if t means
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3046 set the last-save-file-modtime of buffer to this file's modtime
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3047 and mark buffer not modified.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3048 If VISIT is a string, it is a second file name;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3049 the output goes to FILENAME, but the buffer is marked as visiting VISIT.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3050 VISIT is also the file name to lock and unlock for clash detection.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3051 If VISIT is neither t nor nil nor a string,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3052 that means do not print the \"Wrote file\" message.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3053 The optional sixth arg LOCKNAME, if non-nil, specifies the name to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3054 use for locking and unlocking, overriding FILENAME and VISIT.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3055 Kludgy feature: if START is a string, then that string is written
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3056 to the file, instead of any buffer contents, and END is ignored."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3057 (interactive "r\nFWrite region to file: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3058 (write-region-internal start end filename append visit lockname))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3059
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
3060 ;; Written in C in FSF
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3061 (defun load (file &optional noerror nomessage nosuffix)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3062 "Execute a file of Lisp code named FILE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3063 First try FILE with `.elc' appended, then try with `.el',
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3064 then try FILE unmodified.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3065 This function searches the directories in `load-path'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3066 If optional second arg NOERROR is non-nil,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3067 report no error if FILE doesn't exist.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3068 Print messages at start and end of loading unless
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3069 optional third arg NOMESSAGE is non-nil (ignored in -batch mode).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3070 If optional fourth arg NOSUFFIX is non-nil, don't try adding
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3071 suffixes `.elc' or `.el' to the specified name FILE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3072 Return t if file exists."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3073 (load-internal file noerror nomessage nosuffix))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3074
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
3075 ;(define-key ctl-x-map "\C-f" 'find-file)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
3076 ;(define-key ctl-x-map "\C-q" 'toggle-read-only)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
3077 ;(define-key ctl-x-map "\C-r" 'find-file-read-only)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
3078 ;(define-key ctl-x-map "\C-v" 'find-alternate-file)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
3079 ;(define-key ctl-x-map "\C-s" 'save-buffer)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
3080 ;(define-key ctl-x-map "s" 'save-some-buffers)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
3081 ;(define-key ctl-x-map "\C-w" 'write-file)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
3082 ;(define-key ctl-x-map "i" 'insert-file)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
3083 ;(define-key esc-map "~" 'not-modified)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
3084 ;(define-key ctl-x-map "\C-d" 'list-directory)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
3085 ;(define-key ctl-x-map "\C-c" 'save-buffers-kill-emacs)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
3086
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
3087 ;(define-key ctl-x-4-map "f" 'find-file-other-window)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
3088 ;(define-key ctl-x-4-map "r" 'find-file-read-only-other-window)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
3089 ;(define-key ctl-x-4-map "\C-f" 'find-file-other-window)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
3090 ;(define-key ctl-x-4-map "b" 'switch-to-buffer-other-window)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
3091 ;(define-key ctl-x-4-map "\C-o" 'display-buffer)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
3092
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
3093 ;(define-key ctl-x-5-map "b" 'switch-to-buffer-other-frame)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
3094 ;(define-key ctl-x-5-map "f" 'find-file-other-frame)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
3095 ;(define-key ctl-x-5-map "\C-f" 'find-file-other-frame)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
3096 ;(define-key ctl-x-5-map "r" 'find-file-read-only-other-frame)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
3097
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3098 ;;; files.el ends here