mirror of
https://git.savannah.gnu.org/git/emacs.git
synced 2025-01-05 11:45:45 +00:00
(find-alternate-file): Offer to save a modified buffer.
Handle kill-buffer-query-functions better.
This commit is contained in:
parent
682b60ae44
commit
63fabbb4fe
@ -929,11 +929,14 @@ If the current buffer now contains an empty file that you just visited
|
|||||||
file-dir (file-name-directory file)))
|
file-dir (file-name-directory file)))
|
||||||
(list (read-file-name
|
(list (read-file-name
|
||||||
"Find alternate file: " file-dir nil nil file-name))))
|
"Find alternate file: " file-dir nil nil file-name))))
|
||||||
(and (buffer-modified-p) (buffer-file-name)
|
(unless (run-hook-with-args-until-failure 'kill-buffer-query-functions)
|
||||||
;; (not buffer-read-only)
|
(error "Aborted"))
|
||||||
(not (yes-or-no-p (format "Buffer %s is modified; kill anyway? "
|
(when (and (buffer-modified-p) (buffer-file-name))
|
||||||
(buffer-name))))
|
(if (yes-or-no-p (format "Buffer %s is modified; save it first? "
|
||||||
(error "Aborted"))
|
(buffer-name)))
|
||||||
|
(save-buffer)
|
||||||
|
(unless (yes-or-no-p "Kill and replace the buffer without saving it? ")
|
||||||
|
(error "Aborted"))))
|
||||||
(let ((obuf (current-buffer))
|
(let ((obuf (current-buffer))
|
||||||
(ofile buffer-file-name)
|
(ofile buffer-file-name)
|
||||||
(onum buffer-file-number)
|
(onum buffer-file-number)
|
||||||
@ -949,14 +952,20 @@ If the current buffer now contains an empty file that you just visited
|
|||||||
(setq buffer-file-number nil)
|
(setq buffer-file-number nil)
|
||||||
(setq buffer-file-truename nil)
|
(setq buffer-file-truename nil)
|
||||||
(find-file filename))
|
(find-file filename))
|
||||||
(cond ((eq obuf (current-buffer))
|
(when (eq obuf (current-buffer))
|
||||||
(setq buffer-file-name ofile)
|
;; This executes if find-file gets an error
|
||||||
(setq buffer-file-number onum)
|
;; and does not really find anything.
|
||||||
(setq buffer-file-truename otrue)
|
;; We put things back as they were.
|
||||||
(lock-buffer)
|
;; If find-file actually finds something, we kill obuf below.
|
||||||
(rename-buffer oname))))
|
(setq buffer-file-name ofile)
|
||||||
(or (eq (current-buffer) obuf)
|
(setq buffer-file-number onum)
|
||||||
(kill-buffer obuf))))
|
(setq buffer-file-truename otrue)
|
||||||
|
(lock-buffer)
|
||||||
|
(rename-buffer oname)))
|
||||||
|
(unless (eq (current-buffer) obuf)
|
||||||
|
;; We already asked; don't ask again.
|
||||||
|
(setq kill-buffer-query-functions nil)
|
||||||
|
(kill-buffer obuf))))
|
||||||
|
|
||||||
(defun create-file-buffer (filename)
|
(defun create-file-buffer (filename)
|
||||||
"Create a suitably named buffer for visiting FILENAME, and return it.
|
"Create a suitably named buffer for visiting FILENAME, and return it.
|
||||||
|
Loading…
Reference in New Issue
Block a user