From 548e9b8accb86d33658e5f27b59815ba71d81c7b Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Sat, 2 Apr 2022 12:37:25 -0500 Subject: Add +scratch-buffer --- lisp/acdw.el | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/lisp/acdw.el b/lisp/acdw.el index 764a246..e47770b 100644 --- a/lisp/acdw.el +++ b/lisp/acdw.el @@ -386,5 +386,30 @@ the `format' call in a list." `(with-eval-after-load ',this (+with-eval-after-loads ,rest ,@body))))) +(defun +scratch-buffer (&optional nomode) + "Create a new scratch buffer and switch to it. +If the region is active, paste its contents into the scratch +buffer. The scratch buffer inherits the mode of the current +buffer unless NOMODE is non-nil. When called interactively, +NOMODE will be set when called with \\[universal-argument]." + (interactive "P") + (let* ((mode major-mode) + (bufname (generate-new-buffer-name (format "*scratch (%s)*" mode))) + (paste (and (region-active-p) + (prog1 + (buffer-substring (mark t) (point)) + (deactivate-mark))))) + (when (and (not nomode) + (bound-and-true-p ess-dialect)) ; Not sure what `ess-dialect' is + (setq mode (intern-soft (concat ess-dialect "-mode")))) + ;; Set up buffer + (switch-to-buffer (get-buffer-create bufname)) + (when (and (not nomode) mode) + (ignore-errors (funcall mode))) + (insert (format "%s Scratch buffer for %s%s\n\n" + comment-start mode comment-end)) + (when paste (insert paste)) + (get-buffer bufname))) + (provide 'acdw) ;;; acdw.el ends here -- cgit 1.4.1-21-gabe81