Created
February 3, 2013 13:31
-
-
Save spacebat/4701798 to your computer and use it in GitHub Desktop.
Create a scratch buffer, with a mode and some locals for take off no zigs there
This file contains 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
(defvar scratch-buffer-locals '(lexical-binding t) | |
"A plist of variables and bindings to apply in a new scratch buffer") | |
(defvar scratch-buffer-mode-locals '(cperl-mode (cperl-indent-level 4)) | |
"A plist of modes and the buffer locals to set in a new scratch buffer according to mode") | |
(defun create-scratch-buffer (&optional mode) | |
"Create a new scratch buffer to work in. (could be *scratch* - *scratchX*)" | |
(interactive "aMode: ") | |
(let ((n 0) | |
(effective-mode (if (or (not mode) (eq mode '##)) 'emacs-lisp-mode mode)) | |
bufname) | |
(while (progn | |
(setq bufname (concat "*scratch" | |
(if (= n 0) "" (int-to-string n)) | |
"*")) | |
(setq n (1+ n)) | |
(get-buffer bufname))) | |
(switch-to-buffer (get-buffer-create bufname)) | |
(funcall effective-mode) | |
(let ((mode-locals (append scratch-buffer-locals (getf scratch-buffer-mode-locals effective-mode nil)))) | |
(when mode-locals | |
(loop for (k v) on mode-locals by 'cddr | |
do (set (make-local-variable k) v)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment