about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorCase Duckworth2022-04-02 12:37:25 -0500
committerCase Duckworth2022-04-02 12:37:25 -0500
commit548e9b8accb86d33658e5f27b59815ba71d81c7b (patch)
tree03f7a6f8d99aad7c0815bdcabd979700f19d4206
parentMerge branch 'main' of tildegit.org:acdw/emacs (diff)
downloademacs-548e9b8accb86d33658e5f27b59815ba71d81c7b.tar.gz
emacs-548e9b8accb86d33658e5f27b59815ba71d81c7b.zip
Add +scratch-buffer
-rw-r--r--lisp/acdw.el25
1 files changed, 25 insertions, 0 deletions
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."
386 `(with-eval-after-load ',this 386 `(with-eval-after-load ',this
387 (+with-eval-after-loads ,rest ,@body))))) 387 (+with-eval-after-loads ,rest ,@body)))))
388 388
389(defun +scratch-buffer (&optional nomode)
390 "Create a new scratch buffer and switch to it.
391If the region is active, paste its contents into the scratch
392buffer. The scratch buffer inherits the mode of the current
393buffer unless NOMODE is non-nil. When called interactively,
394NOMODE will be set when called with \\[universal-argument]."
395 (interactive "P")
396 (let* ((mode major-mode)
397 (bufname (generate-new-buffer-name (format "*scratch (%s)*" mode)))
398 (paste (and (region-active-p)
399 (prog1
400 (buffer-substring (mark t) (point))
401 (deactivate-mark)))))
402 (when (and (not nomode)
403 (bound-and-true-p ess-dialect)) ; Not sure what `ess-dialect' is
404 (setq mode (intern-soft (concat ess-dialect "-mode"))))
405 ;; Set up buffer
406 (switch-to-buffer (get-buffer-create bufname))
407 (when (and (not nomode) mode)
408 (ignore-errors (funcall mode)))
409 (insert (format "%s Scratch buffer for %s%s\n\n"
410 comment-start mode comment-end))
411 (when paste (insert paste))
412 (get-buffer bufname)))
413
389(provide 'acdw) 414(provide 'acdw)
390;;; acdw.el ends here 415;;; acdw.el ends here