annotate lisp/prim/files.el @ 207:e45d5e7c476e r20-4b2

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