[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/hyperdrive f30fe3d890 11/14: Add: kill-buffer-query-functi
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/hyperdrive f30fe3d890 11/14: Add: kill-buffer-query-functions integration |
Date: |
Wed, 6 Sep 2023 04:00:04 -0400 (EDT) |
branch: elpa/hyperdrive
commit f30fe3d890bb426901819573c35c5af38af5bdf5
Author: Joseph Turner <joseph@ushin.org>
Commit: Joseph Turner <joseph@ushin.org>
Add: kill-buffer-query-functions integration
This prevents accidental loss of unsaved hyperdrive files.
---
hyperdrive.el | 36 ++++++++++++++++++++++++++++++++++--
1 file changed, 34 insertions(+), 2 deletions(-)
diff --git a/hyperdrive.el b/hyperdrive.el
index f375ace2e2..8422bbf013 100644
--- a/hyperdrive.el
+++ b/hyperdrive.el
@@ -317,8 +317,6 @@ Intended to be passed to `buffer-local-restore-state'.")
write-contents-functions (cl-adjoin
#'hyperdrive--write-contents write-contents-functions)
;; TODO: Modify buffer-local value of
`save-some-buffers-action-alist'
;; to allow diffing modified buffer with hyperdrive file
- ;; TODO(A): Add to `kill-buffer-query-functions' to
- ;; query before killing hyperdrive buffers.
buffer-offer-save t))
(add-hook 'after-change-major-mode-hook
#'hyperdrive--hack-write-contents-functions nil 'local))
@@ -746,6 +744,40 @@ The return value of this function is the retrieval buffer."
(rx-to-string `(or ,eww-use-browse-url (seq bos "hyper://")))
(rx bos "hyper://"))))
+;;;; `kill-buffer-query-functions' integration
+
+(defun hyperdrive--kill-buffer-possibly-save (buffer)
+ "Ask whether to kill modified hyperdrive file BUFFER."
+ ;; Mostly copied from `kill-buffer--possibly-save'.
+ (cl-assert (and hyperdrive-mode hyperdrive-current-entry))
+ (let ((response
+ (cadr
+ (read-multiple-choice
+ (format "Hyperdrive file %s modified; kill anyway?"
+ (hyperdrive-entry-description hyperdrive-current-entry))
+ '((?y "yes" "kill buffer without saving")
+ (?n "no" "exit without doing anything")
+ (?s "save and then kill" "save the buffer and then kill it"))
+ nil nil (and (not use-short-answers)
+ (not (use-dialog-box-p)))))))
+ (if (equal response "no")
+ nil
+ (unless (equal response "yes")
+ (with-current-buffer buffer
+ (save-buffer)))
+ t)))
+
+(defun hyperdrive-kill-buffer-query-function ()
+ "Ask before killing an unsaved hyperdrive file buffer."
+ (if (and hyperdrive-mode
+ hyperdrive-current-entry
+ (not (hyperdrive--entry-directory-p hyperdrive-current-entry))
+ (buffer-modified-p))
+ (hyperdrive--kill-buffer-possibly-save (current-buffer))
+ t))
+
+(cl-pushnew #'hyperdrive-kill-buffer-query-function
kill-buffer-query-functions)
+
;;;; Footer
(provide 'hyperdrive)
- [nongnu] elpa/hyperdrive 465e8a1aca 10/14: Comment: Explanation, (continued)
- [nongnu] elpa/hyperdrive 465e8a1aca 10/14: Comment: Explanation, ELPA Syncer, 2023/09/06
- [nongnu] elpa/hyperdrive 109452e780 09/14: Merge branch 'view-file', ELPA Syncer, 2023/09/06
- [nongnu] elpa/hyperdrive 006dcb9261 12/14: Meta: Update changelog, ELPA Syncer, 2023/09/06
- [nongnu] elpa/hyperdrive 466cbdd551 01/14: Comment: Remove TODO, ELPA Syncer, 2023/09/06
- [nongnu] elpa/hyperdrive 38e110b99f 02/14: Change: (hyperdrive-open) Add createp flag, ELPA Syncer, 2023/09/06
- [nongnu] elpa/hyperdrive ab00310b84 03/14: Fix: Describe return values in docstrings, ELPA Syncer, 2023/09/06
- [nongnu] elpa/hyperdrive a000cfb8ff 13/14: Comment: Explanation, ELPA Syncer, 2023/09/06
- [nongnu] elpa/hyperdrive f9e2623048 05/14: Add: (hyperdrive-dir-view-file) View file from hyperdrive-dir-mode, ELPA Syncer, 2023/09/06
- [nongnu] elpa/hyperdrive 55494532f3 07/14: Docs: Document hyperdrive-view-file and dir/history wrappers, ELPA Syncer, 2023/09/06
- [nongnu] elpa/hyperdrive aa29fa3652 06/14: Add: (hyperdrive-history-view-file) View file from history mode, ELPA Syncer, 2023/09/06
- [nongnu] elpa/hyperdrive f30fe3d890 11/14: Add: kill-buffer-query-functions integration,
ELPA Syncer <=
- [nongnu] elpa/hyperdrive e85bd37f52 14/14: Fix: (-entry-version-ranges-no-gaps) Handle unknown entries, ELPA Syncer, 2023/09/06