From dd3afe747ecf51f87d33318c2ad68953d153495f Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Mon, 23 May 2022 20:12:53 -0500 Subject: meh --- lisp/+scratch.el | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'lisp/+scratch.el') diff --git a/lisp/+scratch.el b/lisp/+scratch.el index e9b825a..7fc2bde 100644 --- a/lisp/+scratch.el +++ b/lisp/+scratch.el @@ -35,18 +35,33 @@ For `kill-buffer-query-functions'." "ABANDON ALL HOPE YE WHO ENTER HERE")))) (concat (replace-regexp-in-string "^" ";; " s) "\n\n"))) - + ;; [[https://old.reddit.com/r/emacs/comments/ui1q41/weekly_tips_tricks_c_thread/i7ef4xg/][u/bhrgunatha]] (defun +scratch-text-scratch () "Create a \"*text*\" scratch buffer in Text mode." (with-current-buffer (get-buffer-create "*text*") (text-mode))) +(defcustom +scratch-buffers '("*text*" "*scratch*") + "Scratch buffers.") + +(defvar +scratch-last-non-scratch-buffer nil + "Last buffer that wasn't a scratch buffer.") + (defun +scratch-toggle (buffer) - "Switch to BUFFER, or to the previous buffer." - (switch-to-buffer (unless (eq (current-buffer) - (get-buffer buffer)) - buffer))) + "Switch to BUFFER, or to the previous (non-scratch) buffer." + (if (or (null +scratch-last-non-scratch-buffer) + (not (member (buffer-name (current-buffer)) +scratch-buffers))) + ;; Switch to a scratch buffer + (progn + (setq +scratch-last-non-scratch-buffer (current-buffer)) + (switch-to-buffer buffer)) + ;; Switch away from scratch buffer ... + (if (equal (get-buffer-create buffer) (current-buffer)) + ;; to the original buffer + (switch-to-buffer +scratch-last-non-scratch-buffer) + ;; to another scratch + (switch-to-buffer buffer)))) (defun +scratch-switch-to-scratch () "Switch to scratch buffer." -- cgit 1.4.1-21-gabe81