aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2013-07-24 00:56:12 -0400
committerStefan Monnier2013-07-24 00:56:12 -0400
commitac93e56b698c82d9fcfbf39394740ec1f8d411c5 (patch)
tree34c37cb443d2274972091e27349c39cf8e071b90
parent2cdeb903c57126d3ad5f0cbd72e182584b76ee29 (diff)
downloademacs-ac93e56b698c82d9fcfbf39394740ec1f8d411c5.tar.gz
emacs-ac93e56b698c82d9fcfbf39394740ec1f8d411c5.zip
* lisp/files.el (revert-buffer-function): Use a non-nil default.
(revert-buffer-preserve-modes): Declare var to provide access to the `preserve-modes' argument. (revert-buffer): Let-bind it. (revert-buffer--default): New function, extracted from revert-buffer.
-rw-r--r--lisp/ChangeLog8
-rw-r--r--lisp/files.el224
2 files changed, 124 insertions, 108 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 4c115d8435a..24fbe1acb2c 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,5 +1,13 @@
12013-07-24 Stefan Monnier <monnier@iro.umontreal.ca> 12013-07-24 Stefan Monnier <monnier@iro.umontreal.ca>
2 2
3 * files.el (revert-buffer-function): Use a non-nil default.
4 (revert-buffer-preserve-modes): Declare var to
5 provide access to the `preserve-modes' argument.
6 (revert-buffer): Let-bind it.
7 (revert-buffer--default): New function, extracted from revert-buffer.
8
92013-07-24 Stefan Monnier <monnier@iro.umontreal.ca>
10
3 * lpr.el: Signal print errors more prominently. 11 * lpr.el: Signal print errors more prominently.
4 (print-region-function): Don't default to nil. 12 (print-region-function): Don't default to nil.
5 (lpr-print-region): New function, extracted from print-region-1. 13 (lpr-print-region): New function, extracted from print-region-1.
diff --git a/lisp/files.el b/lisp/files.el
index ff4ccec2279..10d66e0b2e0 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -5246,10 +5246,12 @@ comparison."
5246 5246
5247 5247
5248(put 'revert-buffer-function 'permanent-local t) 5248(put 'revert-buffer-function 'permanent-local t)
5249(defvar revert-buffer-function nil 5249(defvar revert-buffer-function #'revert-buffer--default
5250 "Function to use to revert this buffer, or nil to do the default. 5250 "Function to use to revert this buffer, or nil to do the default.
5251The function receives two arguments IGNORE-AUTO and NOCONFIRM, 5251The function receives two arguments IGNORE-AUTO and NOCONFIRM,
5252which are the arguments that `revert-buffer' received.") 5252which are the arguments that `revert-buffer' received.
5253It also has access to the `preserve-modes' argument of `revert-buffer'
5254via the `revert-buffer-preserve-modes' dynamic variable.")
5253 5255
5254(put 'revert-buffer-insert-file-contents-function 'permanent-local t) 5256(put 'revert-buffer-insert-file-contents-function 'permanent-local t)
5255(defvar revert-buffer-insert-file-contents-function nil 5257(defvar revert-buffer-insert-file-contents-function nil
@@ -5296,6 +5298,11 @@ This is true even if a `revert-buffer-function' is being used.")
5296 5298
5297(defvar revert-buffer-internal-hook) 5299(defvar revert-buffer-internal-hook)
5298 5300
5301;; `revert-buffer-function' was defined long ago to be a function of only
5302;; 2 arguments, so we have to use a dynbind variable to pass the
5303;; `preserve-modes' argument of `revert-buffer'.
5304(defvar revert-buffer-preserve-modes)
5305
5299(defun revert-buffer (&optional ignore-auto noconfirm preserve-modes) 5306(defun revert-buffer (&optional ignore-auto noconfirm preserve-modes)
5300 "Replace current buffer text with the text of the visited file on disk. 5307 "Replace current buffer text with the text of the visited file on disk.
5301This undoes all changes since the file was visited or saved. 5308This undoes all changes since the file was visited or saved.
@@ -5337,112 +5344,113 @@ non-nil, it is called instead of rereading visited file contents."
5337 ;; reversal of the argument sense. So I'm just changing the user 5344 ;; reversal of the argument sense. So I'm just changing the user
5338 ;; interface, but leaving the programmatic interface the same. 5345 ;; interface, but leaving the programmatic interface the same.
5339 (interactive (list (not current-prefix-arg))) 5346 (interactive (list (not current-prefix-arg)))
5340 (if revert-buffer-function 5347 (let ((revert-buffer-in-progress-p t)
5341 (let ((revert-buffer-in-progress-p t)) 5348 (revert-buffer-preserve-modes preserve-modes))
5342 (funcall revert-buffer-function ignore-auto noconfirm)) 5349 (funcall (or revert-buffer-function #'revert-buffer--default)
5343 (with-current-buffer (or (buffer-base-buffer (current-buffer)) 5350 ignore-auto noconfirm)))
5344 (current-buffer)) 5351(defun revert-buffer--default (ignore-auto noconfirm)
5345 (let* ((revert-buffer-in-progress-p t) 5352 (with-current-buffer (or (buffer-base-buffer (current-buffer))
5346 (auto-save-p (and (not ignore-auto) 5353 (current-buffer))
5347 (recent-auto-save-p) 5354 (let* ((auto-save-p (and (not ignore-auto)
5348 buffer-auto-save-file-name 5355 (recent-auto-save-p)
5349 (file-readable-p buffer-auto-save-file-name) 5356 buffer-auto-save-file-name
5350 (y-or-n-p 5357 (file-readable-p buffer-auto-save-file-name)
5351 "Buffer has been auto-saved recently. Revert from auto-save file? "))) 5358 (y-or-n-p
5352 (file-name (if auto-save-p 5359 "Buffer has been auto-saved recently. Revert from auto-save file? ")))
5353 buffer-auto-save-file-name 5360 (file-name (if auto-save-p
5354 buffer-file-name))) 5361 buffer-auto-save-file-name
5355 (cond ((null file-name) 5362 buffer-file-name)))
5356 (error "Buffer does not seem to be associated with any file")) 5363 (cond ((null file-name)
5357 ((or noconfirm 5364 (error "Buffer does not seem to be associated with any file"))
5358 (and (not (buffer-modified-p)) 5365 ((or noconfirm
5359 (catch 'found 5366 (and (not (buffer-modified-p))
5360 (dolist (regexp revert-without-query) 5367 (catch 'found
5361 (when (string-match regexp file-name) 5368 (dolist (regexp revert-without-query)
5362 (throw 'found t))))) 5369 (when (string-match regexp file-name)
5363 (yes-or-no-p (format "Revert buffer from file %s? " 5370 (throw 'found t)))))
5364 file-name))) 5371 (yes-or-no-p (format "Revert buffer from file %s? "
5365 (run-hooks 'before-revert-hook) 5372 file-name)))
5366 ;; If file was backed up but has changed since, 5373 (run-hooks 'before-revert-hook)
5367 ;; we should make another backup. 5374 ;; If file was backed up but has changed since,
5368 (and (not auto-save-p) 5375 ;; we should make another backup.
5369 (not (verify-visited-file-modtime (current-buffer))) 5376 (and (not auto-save-p)
5370 (setq buffer-backed-up nil)) 5377 (not (verify-visited-file-modtime (current-buffer)))
5371 ;; Effectively copy the after-revert-hook status, 5378 (setq buffer-backed-up nil))
5372 ;; since after-find-file will clobber it. 5379 ;; Effectively copy the after-revert-hook status,
5373 (let ((global-hook (default-value 'after-revert-hook)) 5380 ;; since after-find-file will clobber it.
5374 (local-hook (when (local-variable-p 'after-revert-hook) 5381 (let ((global-hook (default-value 'after-revert-hook))
5375 after-revert-hook)) 5382 (local-hook (when (local-variable-p 'after-revert-hook)
5376 (inhibit-read-only t)) 5383 after-revert-hook))
5377 (cond 5384 (inhibit-read-only t))
5378 (revert-buffer-insert-file-contents-function 5385 (cond
5379 (unless (eq buffer-undo-list t) 5386 (revert-buffer-insert-file-contents-function
5380 ;; Get rid of all undo records for this buffer. 5387 (unless (eq buffer-undo-list t)
5381 (setq buffer-undo-list nil)) 5388 ;; Get rid of all undo records for this buffer.
5382 ;; Don't make undo records for the reversion. 5389 (setq buffer-undo-list nil))
5383 (let ((buffer-undo-list t)) 5390 ;; Don't make undo records for the reversion.
5384 (funcall revert-buffer-insert-file-contents-function 5391 (let ((buffer-undo-list t))
5385 file-name auto-save-p))) 5392 (funcall revert-buffer-insert-file-contents-function
5386 ((not (file-exists-p file-name)) 5393 file-name auto-save-p)))
5387 (error (if buffer-file-number 5394 ((not (file-exists-p file-name))
5388 "File %s no longer exists!" 5395 (error (if buffer-file-number
5389 "Cannot revert nonexistent file %s") 5396 "File %s no longer exists!"
5390 file-name)) 5397 "Cannot revert nonexistent file %s")
5391 ((not (file-readable-p file-name)) 5398 file-name))
5392 (error (if buffer-file-number 5399 ((not (file-readable-p file-name))
5393 "File %s no longer readable!" 5400 (error (if buffer-file-number
5394 "Cannot revert unreadable file %s") 5401 "File %s no longer readable!"
5395 file-name)) 5402 "Cannot revert unreadable file %s")
5396 (t 5403 file-name))
5397 ;; Bind buffer-file-name to nil 5404 (t
5398 ;; so that we don't try to lock the file. 5405 ;; Bind buffer-file-name to nil
5399 (let ((buffer-file-name nil)) 5406 ;; so that we don't try to lock the file.
5400 (or auto-save-p 5407 (let ((buffer-file-name nil))
5401 (unlock-buffer))) 5408 (or auto-save-p
5402 (widen) 5409 (unlock-buffer)))
5403 (let ((coding-system-for-read 5410 (widen)
5404 ;; Auto-saved file should be read by Emacs's 5411 (let ((coding-system-for-read
5405 ;; internal coding. 5412 ;; Auto-saved file should be read by Emacs's
5406 (if auto-save-p 'auto-save-coding 5413 ;; internal coding.
5407 (or coding-system-for-read 5414 (if auto-save-p 'auto-save-coding
5408 (and 5415 (or coding-system-for-read
5409 buffer-file-coding-system-explicit 5416 (and
5410 (car buffer-file-coding-system-explicit)))))) 5417 buffer-file-coding-system-explicit
5411 (if (and (not enable-multibyte-characters) 5418 (car buffer-file-coding-system-explicit))))))
5412 coding-system-for-read 5419 (if (and (not enable-multibyte-characters)
5413 (not (memq (coding-system-base 5420 coding-system-for-read
5414 coding-system-for-read) 5421 (not (memq (coding-system-base
5415 '(no-conversion raw-text)))) 5422 coding-system-for-read)
5416 ;; As a coding system suitable for multibyte 5423 '(no-conversion raw-text))))
5417 ;; buffer is specified, make the current 5424 ;; As a coding system suitable for multibyte
5418 ;; buffer multibyte. 5425 ;; buffer is specified, make the current
5419 (set-buffer-multibyte t)) 5426 ;; buffer multibyte.
5420 5427 (set-buffer-multibyte t))
5421 ;; This force after-insert-file-set-coding 5428
5422 ;; (called from insert-file-contents) to set 5429 ;; This force after-insert-file-set-coding
5423 ;; buffer-file-coding-system to a proper value. 5430 ;; (called from insert-file-contents) to set
5424 (kill-local-variable 'buffer-file-coding-system) 5431 ;; buffer-file-coding-system to a proper value.
5425 5432 (kill-local-variable 'buffer-file-coding-system)
5426 ;; Note that this preserves point in an intelligent way. 5433
5427 (if preserve-modes 5434 ;; Note that this preserves point in an intelligent way.
5428 (let ((buffer-file-format buffer-file-format)) 5435 (if revert-buffer-preserve-modes
5429 (insert-file-contents file-name (not auto-save-p) 5436 (let ((buffer-file-format buffer-file-format))
5430 nil nil t)) 5437 (insert-file-contents file-name (not auto-save-p)
5431 (insert-file-contents file-name (not auto-save-p) 5438 nil nil t))
5432 nil nil t))))) 5439 (insert-file-contents file-name (not auto-save-p)
5433 ;; Recompute the truename in case changes in symlinks 5440 nil nil t)))))
5434 ;; have changed the truename. 5441 ;; Recompute the truename in case changes in symlinks
5435 (setq buffer-file-truename 5442 ;; have changed the truename.
5436 (abbreviate-file-name (file-truename buffer-file-name))) 5443 (setq buffer-file-truename
5437 (after-find-file nil nil t nil preserve-modes) 5444 (abbreviate-file-name (file-truename buffer-file-name)))
5438 ;; Run after-revert-hook as it was before we reverted. 5445 (after-find-file nil nil t nil revert-buffer-preserve-modes)
5439 (setq-default revert-buffer-internal-hook global-hook) 5446 ;; Run after-revert-hook as it was before we reverted.
5440 (if local-hook 5447 (setq-default revert-buffer-internal-hook global-hook)
5441 (set (make-local-variable 'revert-buffer-internal-hook) 5448 (if local-hook
5442 local-hook) 5449 (set (make-local-variable 'revert-buffer-internal-hook)
5443 (kill-local-variable 'revert-buffer-internal-hook)) 5450 local-hook)
5444 (run-hooks 'revert-buffer-internal-hook)) 5451 (kill-local-variable 'revert-buffer-internal-hook))
5445 t)))))) 5452 (run-hooks 'revert-buffer-internal-hook))
5453 t)))))
5446 5454
5447(defun recover-this-file () 5455(defun recover-this-file ()
5448 "Recover the visited file--get contents from its last auto-save file." 5456 "Recover the visited file--get contents from its last auto-save file."