-
-
Save caiorss/b967d464afeee1f45d4e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defmacro create-scratch-buffer (name &optional comment body) | |
"Create a new custom scratch buffer. The name should be a valid major mode name without -mode suffix. | |
The body should be lambda block or a symbol of function that be invoked after a scratch buffer created. nil is accepted to turn it off." | |
`(defun ,(intern (concat "scratch-" name)) | |
() | |
(interactive) | |
(let ((bufname (concat "*scratch-" ,name "*"))) | |
(if (buffer-live-p (get-buffer bufname)) | |
(switch-to-buffer bufname) | |
(with-current-buffer (get-buffer-create bufname) | |
(setq buffer-read-only nil) | |
(when ,comment | |
(insert-string (concat ,comment "\n\n"))) | |
(,(intern (concat name "-mode"))) | |
(when ,body | |
(funcall ,body)) | |
(delete-other-windows) | |
(switch-to-buffer bufname)))))) | |
;;; Examples | |
;; scratch-sql | |
;; C-c C-c to send a last line to *SQL* buffer. | |
(setenv "MYSQL_PS1" "") | |
(create-scratch-buffer | |
"sql" | |
"-- This buffer is for notes you don't want to save, and for SQL evaluation. | |
-- If you want to create a file, visit that file with C-x C-f, | |
-- then enter the text in that file's own buffer." | |
'(lambda () | |
(sql-product-interactive | |
(completing-read | |
"Product: " | |
'(ansi db2 informix ingres interbase linter microsoft mysql oracle postgres solid sqlite sybase))))) | |
;; scratch-lisp | |
(setq inferior-lisp-program "clisp") | |
(create-scratch-buffer | |
"lisp" | |
";; This buffer is for notes you don't want to save, and for Common Lisp evaluation. | |
;; If you want to create a file, visit that file with C-x C-f, | |
;; then enter the text in that file's own buffer." | |
#'slime) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment