From 918b3a6b661ead1bf66bcfc43a2fb8ae16b43fbf Mon Sep 17 00:00:00 2001 From: 10sr <8.slashes@gmail.com> Date: Thu, 12 Dec 2019 14:13:13 +0900 Subject: [PATCH] Add peek-file --- emacs.el | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/emacs.el b/emacs.el index be21476..2e85414 100644 --- a/emacs.el +++ b/emacs.el @@ -2392,10 +2392,36 @@ Any output will be written to current buffer." ;;;;;;;;;;;;;;;;;;; ;; peek-file-mode +(defvar peek-file-buffers + () + "Peek buffers.") + (defun peek-file (file) "Peek FILE." - (interactive) - (message "%s" file)) + (interactive "fFile to peek: ") + (with-current-buffer (find-file file) + (peek-file-mode))) + +(define-minor-mode peek-file-mode + "Peek file mode." + :lighter "PK" + (view-mode peek-file-mode) + (add-to-list 'peek-file-buffers + (current-buffer)) + (add-hook 'switch-buffer-functions + 'peek-file-remove-buffers)) + +(defun peek-file-remove-buffers (&args _) + "Remove peek file buffers." + (cl-dolist (buf (cl-copy-list peek-file-buffers)) + (unless (get-buffer-window buf t) + (setq peek-file-buffers + (delq buf + peek-file-buffers)) + (with-current-buffer buf + (when peek-file-mode + (kill-buffer)))))) + ;;;;;;;;;;;;;;;;;;;; ;; remember-projectile