From fde7b61089d3acc8a0ac06e30fe58fb169c2a1af Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Thu, 7 Jul 2022 23:07:18 -0500 Subject: Add burly --- lisp/+burly.el | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 lisp/+burly.el (limited to 'lisp') diff --git a/lisp/+burly.el b/lisp/+burly.el new file mode 100644 index 0000000..a32bc97 --- /dev/null +++ b/lisp/+burly.el @@ -0,0 +1,63 @@ +;;; +burly.el --- Bespoke burly add-ons -*- lexical-binding: t; -*- + +;;; Commentary: + +;;; Code: + +(require 'burly) + +(defgroup +burly nil + "Extra `burly' customizations." + :group 'burly + :prefix "+burly-") + +(defcustom +burly-windows-bookmark-name "pre-close-window-config" + "The name of the window config bookmark pre-frame deletion.") + +(defun +burly--get-name (arg) + "Get the name of a Burly bookmark to restore. +If ARG is passed, ask for the bookmark's name; otherwise, just +use `+burly-windows-bookmark-name'." + (if arg + (completing-read "Save Burly bookmark: " (burly-bookmark-names) + nil nil burly-bookmark-prefix) + +burly-windows-bookmark-name)) + +(defun +burly-recover-windows-bookmark (&optional arg frame) + "Recover the window configuration from a previous bookmark. +ARG is passed to `+burly--get-name', which see." + (interactive (list current-prefix-arg + (selected-frame))) + (with-selected-frame frame + (burly-open-bookmark (+burly--get-name arg)))) + +(defun +burly--recover-windows-on-new-frame (frame) + "Recover the current window configuration in a new frame. +This function removes itself from `after-make-frame-functions'." + ;; XXX: For some reason, *scratch* pops up. So I need to run this after a + ;; short delay, which sadly causes a flash of *scratch*. + (run-with-idle-timer 0.1 nil + (lambda (f) (+burly-recover-windows-bookmark nil f)) + frame) + (remove-hook 'after-make-frame-functions #'+burly--recover-windows-on-new-frame)) + +(defun +burly-save-then-close-frame (&optional arg) + "Save window configuration and close the frame. +ARG is passed to `+burly--get-name', which see." + (interactive "P") + (if (not (frame-parameter nil 'client)) + (when (yes-or-no-p "Sure you want to quit? ") + (save-buffers-kill-emacs)) + (save-some-buffers t) + (burly-bookmark-windows (+burly--get-name arg)) + (delete-frame nil :force))) + +(defun +burly-save-then-close-frame-remembering () + "Save window configurations and close the frame. +The next frame created will restore the window configuration." + (interactive) + (add-hook 'after-make-frame-functions #'+burly--recover-windows-on-new-frame 90) + (+burly-save-then-close-frame)) + +(provide '+burly) +;;; +burly.el ends here -- cgit 1.4.1-21-gabe81