diff options
| author | Lars Ingebrigtsen | 2019-10-13 21:36:57 +0200 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2019-10-13 21:42:03 +0200 |
| commit | b02f0ae995110393f7a8136d01933fb80960fc54 (patch) | |
| tree | 946ddb1cfec7fa61f51d8eb6ce431e6c6d2ad558 | |
| parent | 67ed6ee7337d66dc1101e41bc2e67bde5ab0ecd4 (diff) | |
| download | emacs-b02f0ae995110393f7a8136d01933fb80960fc54.tar.gz emacs-b02f0ae995110393f7a8136d01933fb80960fc54.zip | |
Add a new action in save-some-buffers to view the buffer
* doc/emacs/files.texi (Save Commands): Document it.
* lisp/files.el (save-some-buffers-action-alist): Offer to pop to
the buffer and then quit (bug#3625).
(save-some-buffers): Implement it.
(save-some-buffers--switch-window-callback): New variable.
| -rw-r--r-- | doc/emacs/files.texi | 3 | ||||
| -rw-r--r-- | etc/NEWS | 4 | ||||
| -rw-r--r-- | lisp/files.el | 143 |
3 files changed, 87 insertions, 63 deletions
diff --git a/doc/emacs/files.texi b/doc/emacs/files.texi index 9fe1b564a82..c3ede1833b5 100644 --- a/doc/emacs/files.texi +++ b/doc/emacs/files.texi | |||
| @@ -419,6 +419,9 @@ about other buffers. | |||
| 419 | View the buffer that you are currently being asked about. When you exit | 419 | View the buffer that you are currently being asked about. When you exit |
| 420 | View mode, you get back to @code{save-some-buffers}, which asks the | 420 | View mode, you get back to @code{save-some-buffers}, which asks the |
| 421 | question again. | 421 | question again. |
| 422 | @item C-f | ||
| 423 | Exit @code{save-some-buffers} and visit the buffer that you are | ||
| 424 | currently being asked about. | ||
| 422 | @item d | 425 | @item d |
| 423 | Diff the buffer against its corresponding file, so you can see what | 426 | Diff the buffer against its corresponding file, so you can see what |
| 424 | changes you would be saving. This calls the command | 427 | changes you would be saving. This calls the command |
| @@ -454,6 +454,10 @@ Note that this key binding will not work on MS-Windows systems if | |||
| 454 | * Editing Changes in Emacs 27.1 | 454 | * Editing Changes in Emacs 27.1 |
| 455 | 455 | ||
| 456 | +++ | 456 | +++ |
| 457 | ** 'save-some-buffers' now has a new action in the prompt: 'C-f' will | ||
| 458 | exit the command and switch to the buffer currently being asked about. | ||
| 459 | |||
| 460 | +++ | ||
| 457 | ** The new 'amalgamating-undo-limit' variable can be used to control | 461 | ** The new 'amalgamating-undo-limit' variable can be used to control |
| 458 | how many changes should be amalgamated when using the 'undo' command. | 462 | how many changes should be amalgamated when using the 'undo' command. |
| 459 | 463 | ||
diff --git a/lisp/files.el b/lisp/files.el index a1c7e3c8144..007195d22a8 100644 --- a/lisp/files.el +++ b/lisp/files.el | |||
| @@ -5390,6 +5390,8 @@ Before and after saving the buffer, this function runs | |||
| 5390 | (declare-function diff-no-select "diff" | 5390 | (declare-function diff-no-select "diff" |
| 5391 | (old new &optional switches no-async buf)) | 5391 | (old new &optional switches no-async buf)) |
| 5392 | 5392 | ||
| 5393 | (defvar save-some-buffers--switch-window-callback nil) | ||
| 5394 | |||
| 5393 | (defvar save-some-buffers-action-alist | 5395 | (defvar save-some-buffers-action-alist |
| 5394 | `((?\C-r | 5396 | `((?\C-r |
| 5395 | ,(lambda (buf) | 5397 | ,(lambda (buf) |
| @@ -5401,6 +5403,11 @@ Before and after saving the buffer, this function runs | |||
| 5401 | ;; Return nil to ask about BUF again. | 5403 | ;; Return nil to ask about BUF again. |
| 5402 | nil) | 5404 | nil) |
| 5403 | ,(purecopy "view this buffer")) | 5405 | ,(purecopy "view this buffer")) |
| 5406 | (?\C-f | ||
| 5407 | ,(lambda (buf) | ||
| 5408 | (funcall save-some-buffers--switch-window-callback buf) | ||
| 5409 | (setq quit-flag t)) | ||
| 5410 | ,(purecopy "view this buffer and quit")) | ||
| 5404 | (?d ,(lambda (buf) | 5411 | (?d ,(lambda (buf) |
| 5405 | (if (null (buffer-file-name buf)) | 5412 | (if (null (buffer-file-name buf)) |
| 5406 | (message "Not applicable: no file") | 5413 | (message "Not applicable: no file") |
| @@ -5464,69 +5471,79 @@ change the additional actions you can take on files." | |||
| 5464 | (interactive "P") | 5471 | (interactive "P") |
| 5465 | (unless pred | 5472 | (unless pred |
| 5466 | (setq pred save-some-buffers-default-predicate)) | 5473 | (setq pred save-some-buffers-default-predicate)) |
| 5467 | (save-window-excursion | 5474 | (let* ((switched-buffer nil) |
| 5468 | (let* (queried autosaved-buffers | 5475 | (save-some-buffers--switch-window-callback |
| 5469 | files-done abbrevs-done) | 5476 | (lambda (buffer) |
| 5470 | (dolist (buffer (buffer-list)) | 5477 | (setq switched-buffer buffer))) |
| 5471 | ;; First save any buffers that we're supposed to save unconditionally. | 5478 | queried autosaved-buffers |
| 5472 | ;; That way the following code won't ask about them. | 5479 | files-done abbrevs-done) |
| 5473 | (with-current-buffer buffer | 5480 | (unwind-protect |
| 5474 | (when (and buffer-save-without-query (buffer-modified-p)) | 5481 | (save-window-excursion |
| 5475 | (push (buffer-name) autosaved-buffers) | 5482 | (dolist (buffer (buffer-list)) |
| 5476 | (save-buffer)))) | 5483 | ;; First save any buffers that we're supposed to save |
| 5477 | ;; Ask about those buffers that merit it, | 5484 | ;; unconditionally. That way the following code won't ask |
| 5478 | ;; and record the number thus saved. | 5485 | ;; about them. |
| 5479 | (setq files-done | 5486 | (with-current-buffer buffer |
| 5480 | (map-y-or-n-p | 5487 | (when (and buffer-save-without-query (buffer-modified-p)) |
| 5481 | (lambda (buffer) | 5488 | (push (buffer-name) autosaved-buffers) |
| 5482 | ;; Note that killing some buffers may kill others via | 5489 | (save-buffer)))) |
| 5483 | ;; hooks (e.g. Rmail and its viewing buffer). | 5490 | ;; Ask about those buffers that merit it, |
| 5484 | (and (buffer-live-p buffer) | 5491 | ;; and record the number thus saved. |
| 5485 | (buffer-modified-p buffer) | 5492 | (setq files-done |
| 5486 | (not (buffer-base-buffer buffer)) | 5493 | (map-y-or-n-p |
| 5487 | (or | 5494 | (lambda (buffer) |
| 5488 | (buffer-file-name buffer) | 5495 | ;; Note that killing some buffers may kill others via |
| 5489 | (with-current-buffer buffer | 5496 | ;; hooks (e.g. Rmail and its viewing buffer). |
| 5490 | (or (eq buffer-offer-save 'always) | 5497 | (and (buffer-live-p buffer) |
| 5491 | (and pred buffer-offer-save (> (buffer-size) 0))))) | 5498 | (buffer-modified-p buffer) |
| 5492 | (or (not (functionp pred)) | 5499 | (not (buffer-base-buffer buffer)) |
| 5493 | (with-current-buffer buffer (funcall pred))) | 5500 | (or |
| 5494 | (if arg | 5501 | (buffer-file-name buffer) |
| 5495 | t | 5502 | (with-current-buffer buffer |
| 5496 | (setq queried t) | 5503 | (or (eq buffer-offer-save 'always) |
| 5497 | (if (buffer-file-name buffer) | 5504 | (and pred buffer-offer-save |
| 5498 | (format "Save file %s? " | 5505 | (> (buffer-size) 0))))) |
| 5499 | (buffer-file-name buffer)) | 5506 | (or (not (functionp pred)) |
| 5500 | (format "Save buffer %s? " | 5507 | (with-current-buffer buffer (funcall pred))) |
| 5501 | (buffer-name buffer)))))) | 5508 | (if arg |
| 5502 | (lambda (buffer) | 5509 | t |
| 5503 | (with-current-buffer buffer | 5510 | (setq queried t) |
| 5504 | (save-buffer))) | 5511 | (if (buffer-file-name buffer) |
| 5505 | (buffer-list) | 5512 | (format "Save file %s? " |
| 5506 | '("buffer" "buffers" "save") | 5513 | (buffer-file-name buffer)) |
| 5507 | save-some-buffers-action-alist)) | 5514 | (format "Save buffer %s? " |
| 5508 | ;; Maybe to save abbrevs, and record whether | 5515 | (buffer-name buffer)))))) |
| 5509 | ;; we either saved them or asked to. | 5516 | (lambda (buffer) |
| 5510 | (and save-abbrevs abbrevs-changed | 5517 | (with-current-buffer buffer |
| 5511 | (progn | 5518 | (save-buffer))) |
| 5512 | (if (or arg | 5519 | (buffer-list) |
| 5513 | (eq save-abbrevs 'silently) | 5520 | '("buffer" "buffers" "save") |
| 5514 | (y-or-n-p (format "Save abbrevs in %s? " abbrev-file-name))) | 5521 | save-some-buffers-action-alist)) |
| 5515 | (write-abbrev-file nil)) | 5522 | ;; Maybe to save abbrevs, and record whether |
| 5516 | ;; Don't keep bothering user if he says no. | 5523 | ;; we either saved them or asked to. |
| 5517 | (setq abbrevs-changed nil) | 5524 | (and save-abbrevs abbrevs-changed |
| 5518 | (setq abbrevs-done t))) | 5525 | (progn |
| 5519 | (or queried (> files-done 0) abbrevs-done | 5526 | (if (or arg |
| 5520 | (cond | 5527 | (eq save-abbrevs 'silently) |
| 5521 | ((null autosaved-buffers) | 5528 | (y-or-n-p (format "Save abbrevs in %s? " |
| 5522 | (when (called-interactively-p 'any) | 5529 | abbrev-file-name))) |
| 5523 | (files--message "(No files need saving)"))) | 5530 | (write-abbrev-file nil)) |
| 5524 | ((= (length autosaved-buffers) 1) | 5531 | ;; Don't keep bothering user if he says no. |
| 5525 | (files--message "(Saved %s)" (car autosaved-buffers))) | 5532 | (setq abbrevs-changed nil) |
| 5526 | (t | 5533 | (setq abbrevs-done t))) |
| 5527 | (files--message "(Saved %d files: %s)" | 5534 | (or queried (> files-done 0) abbrevs-done |
| 5528 | (length autosaved-buffers) | 5535 | (cond |
| 5529 | (mapconcat 'identity autosaved-buffers ", ")))))))) | 5536 | ((null autosaved-buffers) |
| 5537 | (when (called-interactively-p 'any) | ||
| 5538 | (files--message "(No files need saving)"))) | ||
| 5539 | ((= (length autosaved-buffers) 1) | ||
| 5540 | (files--message "(Saved %s)" (car autosaved-buffers))) | ||
| 5541 | (t | ||
| 5542 | (files--message | ||
| 5543 | "(Saved %d files: %s)" (length autosaved-buffers) | ||
| 5544 | (mapconcat 'identity autosaved-buffers ", ")))))) | ||
| 5545 | (when switched-buffer | ||
| 5546 | (pop-to-buffer-same-window switched-buffer))))) | ||
| 5530 | 5547 | ||
| 5531 | (defun clear-visited-file-modtime () | 5548 | (defun clear-visited-file-modtime () |
| 5532 | "Clear out records of last mod time of visited file. | 5549 | "Clear out records of last mod time of visited file. |