aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorStefan Monnier2013-08-01 19:18:37 -0400
committerStefan Monnier2013-08-01 19:18:37 -0400
commit76dc5996b48e65d992e85e5836dcec38955407d5 (patch)
tree50be1b591e59d14b39f64fd82d2b8a81fa81e579 /lisp
parent7d7e9a7314a07a690f19ad4baff93e99445db005 (diff)
downloademacs-76dc5996b48e65d992e85e5836dcec38955407d5.tar.gz
emacs-76dc5996b48e65d992e85e5836dcec38955407d5.zip
* lisp/files.el: Use lexical-binding.
(dir-locals-read-from-file): Remove unused `err' variable. (hack-dir-local-variables--warned-coding): New var. (hack-dir-local-variables): Use it to avoid repeated warnings. (make-backup-file-name--default-function): New function. (make-backup-file-name-function): Use it as default. (buffer-stale--default-function): New function. (buffer-stale-function): Use it as default. (revert-buffer-insert-file-contents--default-function): New function. (revert-buffer-insert-file-contents-function): Use it as default. (insert-directory): Avoid add-to-list. * lisp/autorevert.el (auto-revert-handler): Simplify. Use buffer-stale--default-function.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/ChangeLog17
-rw-r--r--lisp/autorevert.el12
-rw-r--r--lisp/files.el204
3 files changed, 130 insertions, 103 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 1cd1e29e493..3a4fc9fba91 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,20 @@
12013-08-01 Stefan Monnier <monnier@iro.umontreal.ca>
2
3 * files.el: Use lexical-binding.
4 (dir-locals-read-from-file): Remove unused `err' variable.
5 (hack-dir-local-variables--warned-coding): New var.
6 (hack-dir-local-variables): Use it to avoid repeated warnings.
7 (make-backup-file-name--default-function): New function.
8 (make-backup-file-name-function): Use it as default.
9 (buffer-stale--default-function): New function.
10 (buffer-stale-function): Use it as default.
11 (revert-buffer-insert-file-contents--default-function): New function.
12 (revert-buffer-insert-file-contents-function): Use it as default.
13 (insert-directory): Avoid add-to-list.
14
15 * autorevert.el (auto-revert-handler): Simplify.
16 Use buffer-stale--default-function.
17
12013-08-01 Tassilo Horn <tsdh@gnu.org> 182013-08-01 Tassilo Horn <tsdh@gnu.org>
2 19
3 * speedbar.el (speedbar-query-confirmation-method): Doc fix. 20 * speedbar.el (speedbar-query-confirmation-method): Doc fix.
diff --git a/lisp/autorevert.el b/lisp/autorevert.el
index 1617a31cd82..978a834cb4c 100644
--- a/lisp/autorevert.el
+++ b/lisp/autorevert.el
@@ -595,14 +595,14 @@ This is an internal function used by Auto-Revert Mode."
595 (setq size 595 (setq size
596 (nth 7 (file-attributes 596 (nth 7 (file-attributes
597 buffer-file-name))))) 597 buffer-file-name)))))
598 (and (file-readable-p buffer-file-name) 598 (funcall (or buffer-stale-function
599 (not (verify-visited-file-modtime buffer))))) 599 #'buffer-stale--default-function)
600 t)))
600 (and (or auto-revert-mode 601 (and (or auto-revert-mode
601 global-auto-revert-non-file-buffers) 602 global-auto-revert-non-file-buffers)
602 revert-buffer-function 603 (funcall (or buffer-stale-function
603 (boundp 'buffer-stale-function) 604 #'buffer-stale--default-function)
604 (functionp buffer-stale-function) 605 t))))
605 (funcall buffer-stale-function t))))
606 eob eoblist) 606 eob eoblist)
607 (setq auto-revert-notify-modified-p nil) 607 (setq auto-revert-notify-modified-p nil)
608 (when revert 608 (when revert
diff --git a/lisp/files.el b/lisp/files.el
index 1be0304302f..526c535450b 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -1,4 +1,4 @@
1;;; files.el --- file input and output commands for Emacs 1;;; files.el --- file input and output commands for Emacs -*- lexical-binding:t -*-
2 2
3;; Copyright (C) 1985-1987, 1992-2013 Free Software Foundation, Inc. 3;; Copyright (C) 1985-1987, 1992-2013 Free Software Foundation, Inc.
4 4
@@ -3645,20 +3645,19 @@ is found. Returns the new class name."
3645 (with-temp-buffer 3645 (with-temp-buffer
3646 ;; This is with-demoted-errors, but we want to mention dir-locals 3646 ;; This is with-demoted-errors, but we want to mention dir-locals
3647 ;; in any error message. 3647 ;; in any error message.
3648 (let (err) 3648 (condition-case err
3649 (condition-case err 3649 (progn
3650 (progn 3650 (insert-file-contents file)
3651 (insert-file-contents file) 3651 (unless (zerop (buffer-size))
3652 (unless (zerop (buffer-size)) 3652 (let* ((dir-name (file-name-directory file))
3653 (let* ((dir-name (file-name-directory file)) 3653 (class-name (intern dir-name))
3654 (class-name (intern dir-name)) 3654 (variables (let ((read-circle nil))
3655 (variables (let ((read-circle nil)) 3655 (read (current-buffer)))))
3656 (read (current-buffer))))) 3656 (dir-locals-set-class-variables class-name variables)
3657 (dir-locals-set-class-variables class-name variables) 3657 (dir-locals-set-directory-class dir-name class-name
3658 (dir-locals-set-directory-class dir-name class-name 3658 (nth 5 (file-attributes file)))
3659 (nth 5 (file-attributes file))) 3659 class-name)))
3660 class-name))) 3660 (error (message "Error reading dir-locals: %S" err) nil))))
3661 (error (message "Error reading dir-locals: %S" err) nil)))))
3662 3661
3663(defcustom enable-remote-dir-locals nil 3662(defcustom enable-remote-dir-locals nil
3664 "Non-nil means dir-local variables will be applied to remote files." 3663 "Non-nil means dir-local variables will be applied to remote files."
@@ -3666,6 +3665,8 @@ is found. Returns the new class name."
3666 :type 'boolean 3665 :type 'boolean
3667 :group 'find-file) 3666 :group 'find-file)
3668 3667
3668(defvar hack-dir-local-variables--warned-coding nil)
3669
3669(defun hack-dir-local-variables () 3670(defun hack-dir-local-variables ()
3670 "Read per-directory local variables for the current buffer. 3671 "Read per-directory local variables for the current buffer.
3671Store the directory-local variables in `dir-local-variables-alist' 3672Store the directory-local variables in `dir-local-variables-alist'
@@ -3697,8 +3698,10 @@ This does nothing if either `enable-local-variables' or
3697 (when variables 3698 (when variables
3698 (dolist (elt variables) 3699 (dolist (elt variables)
3699 (if (eq (car elt) 'coding) 3700 (if (eq (car elt) 'coding)
3700 (display-warning :warning 3701 (unless hack-dir-local-variables--warned-coding
3701 "Coding cannot be specified by dir-locals") 3702 (setq hack-dir-local-variables--warned-coding t)
3703 (display-warning :warning
3704 "Coding cannot be specified by dir-locals"))
3702 (unless (memq (car elt) '(eval mode)) 3705 (unless (memq (car elt) '(eval mode))
3703 (setq dir-local-variables-alist 3706 (setq dir-local-variables-alist
3704 (assq-delete-all (car elt) dir-local-variables-alist))) 3707 (assq-delete-all (car elt) dir-local-variables-alist)))
@@ -4145,9 +4148,9 @@ FILENAME defaults to `buffer-file-name'."
4145 (file-name-sans-extension 4148 (file-name-sans-extension
4146 (file-name-nondirectory (or filename (buffer-file-name))))) 4149 (file-name-nondirectory (or filename (buffer-file-name)))))
4147 4150
4148(defcustom make-backup-file-name-function nil 4151(defcustom make-backup-file-name-function
4152 #'make-backup-file-name--default-function
4149 "A function to use instead of the default `make-backup-file-name'. 4153 "A function to use instead of the default `make-backup-file-name'.
4150A value of nil gives the default `make-backup-file-name' behavior.
4151 4154
4152This could be buffer-local to do something special for specific 4155This could be buffer-local to do something special for specific
4153files. If you define it, you may need to change `backup-file-name-p' 4156files. If you define it, you may need to change `backup-file-name-p'
@@ -4155,8 +4158,7 @@ and `file-name-sans-versions' too.
4155 4158
4156See also `backup-directory-alist'." 4159See also `backup-directory-alist'."
4157 :group 'backup 4160 :group 'backup
4158 :type '(choice (const :tag "Default" nil) 4161 :type '(function :tag "Your function"))
4159 (function :tag "Your function")))
4160 4162
4161(defcustom backup-directory-alist nil 4163(defcustom backup-directory-alist nil
4162 "Alist of filename patterns and backup directory names. 4164 "Alist of filename patterns and backup directory names.
@@ -4216,24 +4218,26 @@ Checks for files in `temporary-file-directory',
4216Normally this will just be the file's name with `~' appended. 4218Normally this will just be the file's name with `~' appended.
4217Customization hooks are provided as follows. 4219Customization hooks are provided as follows.
4218 4220
4219If the variable `make-backup-file-name-function' is non-nil, its value 4221The value of `make-backup-file-name-function' should be a function which
4220should be a function which will be called with FILE as its argument; 4222will be called with FILE as its argument; the resulting name is used.
4221the resulting name is used.
4222 4223
4223Otherwise a match for FILE is sought in `backup-directory-alist'; see 4224By default, a match for FILE is sought in `backup-directory-alist'; see
4224the documentation of that variable. If the directory for the backup 4225the documentation of that variable. If the directory for the backup
4225doesn't exist, it is created." 4226doesn't exist, it is created."
4226 (if make-backup-file-name-function 4227 (funcall (or make-backup-file-name-function
4227 (funcall make-backup-file-name-function file) 4228 #'make-backup-file-name--default-function)
4228 (if (and (eq system-type 'ms-dos) 4229 file))
4229 (not (msdos-long-file-names))) 4230
4230 (let ((fn (file-name-nondirectory file))) 4231(defun make-backup-file-name--default-function (file)
4231 (concat (file-name-directory file) 4232 (if (and (eq system-type 'ms-dos)
4232 (or (and (string-match "\\`[^.]+\\'" fn) 4233 (not (msdos-long-file-names)))
4233 (concat (match-string 0 fn) ".~")) 4234 (let ((fn (file-name-nondirectory file)))
4234 (and (string-match "\\`[^.]+\\.\\(..?\\)?" fn) 4235 (concat (file-name-directory file)
4235 (concat (match-string 0 fn) "~"))))) 4236 (or (and (string-match "\\`[^.]+\\'" fn)
4236 (concat (make-backup-file-name-1 file) "~")))) 4237 (concat (match-string 0 fn) ".~"))
4238 (and (string-match "\\`[^.]+\\.\\(..?\\)?" fn)
4239 (concat (match-string 0 fn) "~")))))
4240 (concat (make-backup-file-name-1 file) "~")))
4237 4241
4238(defun make-backup-file-name-1 (file) 4242(defun make-backup-file-name-1 (file)
4239 "Subroutine of `make-backup-file-name' and `find-backup-file-name'." 4243 "Subroutine of `make-backup-file-name' and `find-backup-file-name'."
@@ -5254,14 +5258,20 @@ It also has access to the `preserve-modes' argument of `revert-buffer'
5254via the `revert-buffer-preserve-modes' dynamic variable.") 5258via the `revert-buffer-preserve-modes' dynamic variable.")
5255 5259
5256(put 'revert-buffer-insert-file-contents-function 'permanent-local t) 5260(put 'revert-buffer-insert-file-contents-function 'permanent-local t)
5257(defvar revert-buffer-insert-file-contents-function nil 5261(defvar revert-buffer-insert-file-contents-function
5262 #'revert-buffer-insert-file-contents--default-function
5258 "Function to use to insert contents when reverting this buffer. 5263 "Function to use to insert contents when reverting this buffer.
5259Gets two args, first the nominal file name to use, 5264Gets two args, first the nominal file name to use,
5260and second, t if reading the auto-save file. 5265and second, t if reading the auto-save file.
5261 5266
5262The function you specify is responsible for updating (or preserving) point.") 5267The function you specify is responsible for updating (or preserving) point.")
5263 5268
5264(defvar buffer-stale-function nil 5269(defun buffer-stale--default-function (&optional _noconfirm)
5270 (and buffer-file-name
5271 (file-readable-p buffer-file-name)
5272 (not (verify-visited-file-modtime (current-buffer)))))
5273
5274(defvar buffer-stale-function #'buffer-stale--default-function
5265 "Function to check whether a non-file buffer needs reverting. 5275 "Function to check whether a non-file buffer needs reverting.
5266This should be a function with one optional argument NOCONFIRM. 5276This should be a function with one optional argument NOCONFIRM.
5267Auto Revert Mode passes t for NOCONFIRM. The function should return 5277Auto Revert Mode passes t for NOCONFIRM. The function should return
@@ -5382,62 +5392,11 @@ non-nil, it is called instead of rereading visited file contents."
5382 (local-hook (when (local-variable-p 'after-revert-hook) 5392 (local-hook (when (local-variable-p 'after-revert-hook)
5383 after-revert-hook)) 5393 after-revert-hook))
5384 (inhibit-read-only t)) 5394 (inhibit-read-only t))
5385 (cond 5395 ;; FIXME: Throw away undo-log when preserve-modes is nil?
5386 (revert-buffer-insert-file-contents-function 5396 (funcall
5387 (unless (eq buffer-undo-list t) 5397 (or revert-buffer-insert-file-contents-function
5388 ;; Get rid of all undo records for this buffer. 5398 #'revert-buffer-insert-file-contents--default-function)
5389 (setq buffer-undo-list nil)) 5399 file-name auto-save-p)
5390 ;; Don't make undo records for the reversion.
5391 (let ((buffer-undo-list t))
5392 (funcall revert-buffer-insert-file-contents-function
5393 file-name auto-save-p)))
5394 ((not (file-exists-p file-name))
5395 (error (if buffer-file-number
5396 "File %s no longer exists!"
5397 "Cannot revert nonexistent file %s")
5398 file-name))
5399 ((not (file-readable-p file-name))
5400 (error (if buffer-file-number
5401 "File %s no longer readable!"
5402 "Cannot revert unreadable file %s")
5403 file-name))
5404 (t
5405 ;; Bind buffer-file-name to nil
5406 ;; so that we don't try to lock the file.
5407 (let ((buffer-file-name nil))
5408 (or auto-save-p
5409 (unlock-buffer)))
5410 (widen)
5411 (let ((coding-system-for-read
5412 ;; Auto-saved file should be read by Emacs's
5413 ;; internal coding.
5414 (if auto-save-p 'auto-save-coding
5415 (or coding-system-for-read
5416 (and
5417 buffer-file-coding-system-explicit
5418 (car buffer-file-coding-system-explicit))))))
5419 (if (and (not enable-multibyte-characters)
5420 coding-system-for-read
5421 (not (memq (coding-system-base
5422 coding-system-for-read)
5423 '(no-conversion raw-text))))
5424 ;; As a coding system suitable for multibyte
5425 ;; buffer is specified, make the current
5426 ;; buffer multibyte.
5427 (set-buffer-multibyte t))
5428
5429 ;; This force after-insert-file-set-coding
5430 ;; (called from insert-file-contents) to set
5431 ;; buffer-file-coding-system to a proper value.
5432 (kill-local-variable 'buffer-file-coding-system)
5433
5434 ;; Note that this preserves point in an intelligent way.
5435 (if revert-buffer-preserve-modes
5436 (let ((buffer-file-format buffer-file-format))
5437 (insert-file-contents file-name (not auto-save-p)
5438 nil nil t))
5439 (insert-file-contents file-name (not auto-save-p)
5440 nil nil t)))))
5441 ;; Recompute the truename in case changes in symlinks 5400 ;; Recompute the truename in case changes in symlinks
5442 ;; have changed the truename. 5401 ;; have changed the truename.
5443 (setq buffer-file-truename 5402 (setq buffer-file-truename
@@ -5452,6 +5411,56 @@ non-nil, it is called instead of rereading visited file contents."
5452 (run-hooks 'revert-buffer-internal-hook)) 5411 (run-hooks 'revert-buffer-internal-hook))
5453 t))))) 5412 t)))))
5454 5413
5414(defun revert-buffer-insert-file-contents--default-function (file-name auto-save-p)
5415 (cond
5416 ((not (file-exists-p file-name))
5417 (error (if buffer-file-number
5418 "File %s no longer exists!"
5419 "Cannot revert nonexistent file %s")
5420 file-name))
5421 ((not (file-readable-p file-name))
5422 (error (if buffer-file-number
5423 "File %s no longer readable!"
5424 "Cannot revert unreadable file %s")
5425 file-name))
5426 (t
5427 ;; Bind buffer-file-name to nil
5428 ;; so that we don't try to lock the file.
5429 (let ((buffer-file-name nil))
5430 (or auto-save-p
5431 (unlock-buffer)))
5432 (widen)
5433 (let ((coding-system-for-read
5434 ;; Auto-saved file should be read by Emacs's
5435 ;; internal coding.
5436 (if auto-save-p 'auto-save-coding
5437 (or coding-system-for-read
5438 (and
5439 buffer-file-coding-system-explicit
5440 (car buffer-file-coding-system-explicit))))))
5441 (if (and (not enable-multibyte-characters)
5442 coding-system-for-read
5443 (not (memq (coding-system-base
5444 coding-system-for-read)
5445 '(no-conversion raw-text))))
5446 ;; As a coding system suitable for multibyte
5447 ;; buffer is specified, make the current
5448 ;; buffer multibyte.
5449 (set-buffer-multibyte t))
5450
5451 ;; This force after-insert-file-set-coding
5452 ;; (called from insert-file-contents) to set
5453 ;; buffer-file-coding-system to a proper value.
5454 (kill-local-variable 'buffer-file-coding-system)
5455
5456 ;; Note that this preserves point in an intelligent way.
5457 (if revert-buffer-preserve-modes
5458 (let ((buffer-file-format buffer-file-format))
5459 (insert-file-contents file-name (not auto-save-p)
5460 nil nil t))
5461 (insert-file-contents file-name (not auto-save-p)
5462 nil nil t))))))
5463
5455(defun recover-this-file () 5464(defun recover-this-file ()
5456 "Recover the visited file--get contents from its last auto-save file." 5465 "Recover the visited file--get contents from its last auto-save file."
5457 (interactive) 5466 (interactive)
@@ -6204,9 +6213,10 @@ normally equivalent short `-D' option is just passed on to
6204 ;; directory if FILE is a symbolic link. 6213 ;; directory if FILE is a symbolic link.
6205 (unless full-directory-p 6214 (unless full-directory-p
6206 (setq switches 6215 (setq switches
6207 (if (stringp switches) 6216 (cond
6208 (concat switches " -d") 6217 ((stringp switches) (concat switches " -d"))
6209 (add-to-list 'switches "-d" 'append)))) 6218 ((member "-d" switches) switches)
6219 (t (append switches '("-d"))))))
6210 (apply 'call-process 6220 (apply 'call-process
6211 insert-directory-program nil t nil 6221 insert-directory-program nil t nil
6212 (append 6222 (append