Mercurial > emacs
comparison lisp/files.el @ 85114:5039706521c9
Merge from emacs--rel--22
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-875
author | Miles Bader <miles@gnu.org> |
---|---|
date | Tue, 09 Oct 2007 08:52:57 +0000 |
parents | a570abcfe00a da3f83794d1f |
children | 591c29778a30 14c4a6aac623 |
comparison
equal
deleted
inserted
replaced
85113:82b4a12fd080 | 85114:5039706521c9 |
---|---|
1105 creating one if none already exists. | 1105 creating one if none already exists. |
1106 Interactively, the default if you just type RET is the current directory, | 1106 Interactively, the default if you just type RET is the current directory, |
1107 but the visited file name is available through the minibuffer history: | 1107 but the visited file name is available through the minibuffer history: |
1108 type M-n to pull it into the minibuffer. | 1108 type M-n to pull it into the minibuffer. |
1109 | 1109 |
1110 You can visit files on remote machines by specifying something | |
1111 like /ssh:SOME_REMOTE_MACHINE:FILE for the file name. You can | |
1112 also visit local files as a different user by specifying | |
1113 /sudo::FILE for the file name. | |
1114 See the Info node `(tramp)Filename Syntax' in the Tramp Info | |
1115 manual, for more about this. | |
1116 | |
1110 Interactively, or if WILDCARDS is non-nil in a call from Lisp, | 1117 Interactively, or if WILDCARDS is non-nil in a call from Lisp, |
1111 expand wildcards (if any) and visit multiple files. You can | 1118 expand wildcards (if any) and visit multiple files. You can |
1112 suppress wildcard expansion by setting `find-file-wildcards' to nil. | 1119 suppress wildcard expansion by setting `find-file-wildcards' to nil. |
1113 | 1120 |
1114 To visit a file without any kind of conversion and without | 1121 To visit a file without any kind of conversion and without |
1121 (mapcar 'switch-to-buffer (nreverse value)) | 1128 (mapcar 'switch-to-buffer (nreverse value)) |
1122 (switch-to-buffer value)))) | 1129 (switch-to-buffer value)))) |
1123 | 1130 |
1124 (defun find-file-other-window (filename &optional wildcards) | 1131 (defun find-file-other-window (filename &optional wildcards) |
1125 "Edit file FILENAME, in another window. | 1132 "Edit file FILENAME, in another window. |
1126 May create a new window, or reuse an existing one. | 1133 |
1127 See the function `display-buffer'. | 1134 Like \\[find-file] (which see), but creates a new window or reuses |
1135 an existing one. See the function `display-buffer'. | |
1128 | 1136 |
1129 Interactively, the default if you just type RET is the current directory, | 1137 Interactively, the default if you just type RET is the current directory, |
1130 but the visited file name is available through the minibuffer history: | 1138 but the visited file name is available through the minibuffer history: |
1131 type M-n to pull it into the minibuffer. | 1139 type M-n to pull it into the minibuffer. |
1132 | 1140 |
1143 (mapcar 'switch-to-buffer (cdr value)))) | 1151 (mapcar 'switch-to-buffer (cdr value)))) |
1144 (switch-to-buffer-other-window value)))) | 1152 (switch-to-buffer-other-window value)))) |
1145 | 1153 |
1146 (defun find-file-other-frame (filename &optional wildcards) | 1154 (defun find-file-other-frame (filename &optional wildcards) |
1147 "Edit file FILENAME, in another frame. | 1155 "Edit file FILENAME, in another frame. |
1148 May create a new frame, or reuse an existing one. | 1156 |
1149 See the function `display-buffer'. | 1157 Like \\[find-file] (which see), but creates a new frame or reuses |
1158 an existing one. See the function `display-buffer'. | |
1150 | 1159 |
1151 Interactively, the default if you just type RET is the current directory, | 1160 Interactively, the default if you just type RET is the current directory, |
1152 but the visited file name is available through the minibuffer history: | 1161 but the visited file name is available through the minibuffer history: |
1153 type M-n to pull it into the minibuffer. | 1162 type M-n to pull it into the minibuffer. |
1154 | 1163 |
1165 (mapcar 'switch-to-buffer (cdr value)))) | 1174 (mapcar 'switch-to-buffer (cdr value)))) |
1166 (switch-to-buffer-other-frame value)))) | 1175 (switch-to-buffer-other-frame value)))) |
1167 | 1176 |
1168 (defun find-file-existing (filename) | 1177 (defun find-file-existing (filename) |
1169 "Edit the existing file FILENAME. | 1178 "Edit the existing file FILENAME. |
1170 Like \\[find-file] but only allow a file that exists, and do not allow | 1179 Like \\[find-file], but only allow a file that exists, and do not allow |
1171 file names with wildcards." | 1180 file names with wildcards." |
1172 (interactive (nbutlast (find-file-read-args "Find existing file: " t))) | 1181 (interactive (nbutlast (find-file-read-args "Find existing file: " t))) |
1173 (if (and (not (interactive-p)) (not (file-exists-p filename))) | 1182 (if (and (not (interactive-p)) (not (file-exists-p filename))) |
1174 (error "%s does not exist" filename) | 1183 (error "%s does not exist" filename) |
1175 (find-file filename) | 1184 (find-file filename) |
1176 (current-buffer))) | 1185 (current-buffer))) |
1177 | 1186 |
1178 (defun find-file-read-only (filename &optional wildcards) | 1187 (defun find-file-read-only (filename &optional wildcards) |
1179 "Edit file FILENAME but don't allow changes. | 1188 "Edit file FILENAME but don't allow changes. |
1180 Like \\[find-file] but marks buffer as read-only. | 1189 Like \\[find-file], but marks buffer as read-only. |
1181 Use \\[toggle-read-only] to permit editing." | 1190 Use \\[toggle-read-only] to permit editing." |
1182 (interactive | 1191 (interactive |
1183 (find-file-read-args "Find file read-only: " | 1192 (find-file-read-args "Find file read-only: " |
1184 (if find-file-confirm-nonexistent-file 'confirm-only))) | 1193 (if find-file-confirm-nonexistent-file 'confirm-only))) |
1185 (unless (or (and wildcards find-file-wildcards | 1194 (unless (or (and wildcards find-file-wildcards |
1192 (if (listp value) value (list value))) | 1201 (if (listp value) value (list value))) |
1193 value)) | 1202 value)) |
1194 | 1203 |
1195 (defun find-file-read-only-other-window (filename &optional wildcards) | 1204 (defun find-file-read-only-other-window (filename &optional wildcards) |
1196 "Edit file FILENAME in another window but don't allow changes. | 1205 "Edit file FILENAME in another window but don't allow changes. |
1197 Like \\[find-file-other-window] but marks buffer as read-only. | 1206 Like \\[find-file-other-window], but marks buffer as read-only. |
1198 Use \\[toggle-read-only] to permit editing." | 1207 Use \\[toggle-read-only] to permit editing." |
1199 (interactive | 1208 (interactive |
1200 (find-file-read-args "Find file read-only other window: " | 1209 (find-file-read-args "Find file read-only other window: " |
1201 (if find-file-confirm-nonexistent-file 'confirm-only))) | 1210 (if find-file-confirm-nonexistent-file 'confirm-only))) |
1202 (unless (or (and wildcards find-file-wildcards | 1211 (unless (or (and wildcards find-file-wildcards |
1209 (if (listp value) value (list value))) | 1218 (if (listp value) value (list value))) |
1210 value)) | 1219 value)) |
1211 | 1220 |
1212 (defun find-file-read-only-other-frame (filename &optional wildcards) | 1221 (defun find-file-read-only-other-frame (filename &optional wildcards) |
1213 "Edit file FILENAME in another frame but don't allow changes. | 1222 "Edit file FILENAME in another frame but don't allow changes. |
1214 Like \\[find-file-other-frame] but marks buffer as read-only. | 1223 Like \\[find-file-other-frame], but marks buffer as read-only. |
1215 Use \\[toggle-read-only] to permit editing." | 1224 Use \\[toggle-read-only] to permit editing." |
1216 (interactive | 1225 (interactive |
1217 (find-file-read-args "Find file read-only other frame: " | 1226 (find-file-read-args "Find file read-only other frame: " |
1218 (if find-file-confirm-nonexistent-file 'confirm-only))) | 1227 (if find-file-confirm-nonexistent-file 'confirm-only))) |
1219 (unless (or (and wildcards find-file-wildcards | 1228 (unless (or (and wildcards find-file-wildcards |
1227 value)) | 1236 value)) |
1228 | 1237 |
1229 (defun find-alternate-file-other-window (filename &optional wildcards) | 1238 (defun find-alternate-file-other-window (filename &optional wildcards) |
1230 "Find file FILENAME as a replacement for the file in the next window. | 1239 "Find file FILENAME as a replacement for the file in the next window. |
1231 This command does not select that window. | 1240 This command does not select that window. |
1241 | |
1242 See \\[find-file] for the possible forms of the FILENAME argument. | |
1232 | 1243 |
1233 Interactively, or if WILDCARDS is non-nil in a call from Lisp, | 1244 Interactively, or if WILDCARDS is non-nil in a call from Lisp, |
1234 expand wildcards (if any) and replace the file with multiple files." | 1245 expand wildcards (if any) and replace the file with multiple files." |
1235 (interactive | 1246 (interactive |
1236 (save-selected-window | 1247 (save-selected-window |
1252 | 1263 |
1253 (defun find-alternate-file (filename &optional wildcards) | 1264 (defun find-alternate-file (filename &optional wildcards) |
1254 "Find file FILENAME, select its buffer, kill previous buffer. | 1265 "Find file FILENAME, select its buffer, kill previous buffer. |
1255 If the current buffer now contains an empty file that you just visited | 1266 If the current buffer now contains an empty file that you just visited |
1256 \(presumably by mistake), use this command to visit the file you really want. | 1267 \(presumably by mistake), use this command to visit the file you really want. |
1268 | |
1269 See \\[find-file] for the possible forms of the FILENAME argument. | |
1257 | 1270 |
1258 Interactively, or if WILDCARDS is non-nil in a call from Lisp, | 1271 Interactively, or if WILDCARDS is non-nil in a call from Lisp, |
1259 expand wildcards (if any) and replace the file with multiple files. | 1272 expand wildcards (if any) and replace the file with multiple files. |
1260 | 1273 |
1261 If the current buffer is an indirect buffer, or the base buffer | 1274 If the current buffer is an indirect buffer, or the base buffer |
2540 (tab-width . integerp) ;; C source code | 2553 (tab-width . integerp) ;; C source code |
2541 (truncate-lines . booleanp))) ;; C source code | 2554 (truncate-lines . booleanp))) ;; C source code |
2542 | 2555 |
2543 (put 'c-set-style 'safe-local-eval-function t) | 2556 (put 'c-set-style 'safe-local-eval-function t) |
2544 | 2557 |
2545 (defun hack-local-variables-confirm (vars unsafe-vars risky-vars) | 2558 (defun hack-local-variables-confirm (all-vars unsafe-vars risky-vars) |
2559 "Get confirmation before setting up local variable values. | |
2560 ALL-VARS is the list of all variables to be set up. | |
2561 UNSAFE-VARS is the list of those that aren't marked as safe or risky. | |
2562 RISKY-VARS is the list of those that are marked as risky." | |
2546 (if noninteractive | 2563 (if noninteractive |
2547 nil | 2564 nil |
2548 (let ((name (if buffer-file-name | 2565 (let ((name (if buffer-file-name |
2549 (file-name-nondirectory buffer-file-name) | 2566 (file-name-nondirectory buffer-file-name) |
2550 (concat "buffer " (buffer-name)))) | 2567 (concat "buffer " (buffer-name)))) |
2571 (if offer-save | 2588 (if offer-save |
2572 (insert " | 2589 (insert " |
2573 ! -- to apply the local variables list, and permanently mark these | 2590 ! -- to apply the local variables list, and permanently mark these |
2574 values (*) as safe (in the future, they will be set automatically.)\n\n") | 2591 values (*) as safe (in the future, they will be set automatically.)\n\n") |
2575 (insert "\n\n")) | 2592 (insert "\n\n")) |
2576 (dolist (elt vars) | 2593 (dolist (elt all-vars) |
2577 (cond ((member elt unsafe-vars) | 2594 (cond ((member elt unsafe-vars) |
2578 (insert " * ")) | 2595 (insert " * ")) |
2579 ((member elt risky-vars) | 2596 ((member elt risky-vars) |
2580 (insert " ** ")) | 2597 (insert " ** ")) |
2581 (t | 2598 (t |
3181 (progn | 3198 (progn |
3182 ;; Create temp files with strict access rights. It's easy to | 3199 ;; Create temp files with strict access rights. It's easy to |
3183 ;; loosen them later, whereas it's impossible to close the | 3200 ;; loosen them later, whereas it's impossible to close the |
3184 ;; time-window of loose permissions otherwise. | 3201 ;; time-window of loose permissions otherwise. |
3185 (set-default-file-modes ?\700) | 3202 (set-default-file-modes ?\700) |
3186 (while (condition-case () | 3203 (when (condition-case nil |
3187 (progn | 3204 ;; Try to overwrite old backup first. |
3188 (and (file-exists-p to-name) | 3205 (copy-file from-name to-name t t) |
3189 (delete-file to-name)) | 3206 (error t)) |
3190 (copy-file from-name to-name nil t) | 3207 (while (condition-case nil |
3191 nil) | 3208 (progn |
3192 (file-already-exists t)) | 3209 (when (file-exists-p to-name) |
3193 ;; The file was somehow created by someone else between | 3210 (delete-file to-name)) |
3194 ;; `delete-file' and `copy-file', so let's try again. | 3211 (copy-file from-name to-name nil t) |
3195 ;; rms says "I think there is also a possible race | 3212 nil) |
3196 ;; condition for making backup files" (emacs-devel 20070821). | 3213 (file-already-exists t)) |
3197 nil)) | 3214 ;; The file was somehow created by someone else between |
3215 ;; `delete-file' and `copy-file', so let's try again. | |
3216 ;; rms says "I think there is also a possible race | |
3217 ;; condition for making backup files" (emacs-devel 20070821). | |
3218 nil))) | |
3198 ;; Reset the umask. | 3219 ;; Reset the umask. |
3199 (set-default-file-modes umask))) | 3220 (set-default-file-modes umask))) |
3200 (and modes | 3221 (and modes |
3201 (set-file-modes to-name (logand modes #o1777)))) | 3222 (set-file-modes to-name (logand modes #o1777)))) |
3202 | 3223 |
3221 name) | 3242 name) |
3222 (match-beginning 1)) | 3243 (match-beginning 1)) |
3223 (length name)) | 3244 (length name)) |
3224 (if keep-backup-version | 3245 (if keep-backup-version |
3225 (length name) | 3246 (length name) |
3226 (or (string-match "\\.~[0-9.]+~\\'" name) | 3247 (or (string-match "\\.~[-[:alnum:]:#@^._]+~\\'" name) |
3227 (string-match "~\\'" name) | 3248 (string-match "~\\'" name) |
3228 (length name)))))))) | 3249 (length name)))))))) |
3229 | 3250 |
3230 (defun file-ownership-preserved-p (file) | 3251 (defun file-ownership-preserved-p (file) |
3231 "Return t if deleting FILE and rewriting it would preserve the owner." | 3252 "Return t if deleting FILE and rewriting it would preserve the owner." |