sly-scratch.el (1230B)
1 ;;; sly-scratch.el -*- lexical-binding: t; -*- 2 3 (require 'sly) 4 (require 'cl-lib) 5 6 (define-sly-contrib sly-scratch 7 "Imitate Emacs' *scratch* buffer" 8 (:authors "Helmut Eller <heller@common-lisp.net>") 9 (:on-load 10 (define-key sly-selector-map (kbd "s") 'sly-scratch)) 11 (:license "GPL")) 12 13 14 ;;; Code 15 16 (defvar sly-scratch-mode-map 17 (let ((map (make-sparse-keymap))) 18 (set-keymap-parent map lisp-mode-map) 19 (define-key map "\C-j" 'sly-eval-print-last-expression) 20 map)) 21 22 (defun sly-scratch () 23 (interactive) 24 (sly-switch-to-scratch-buffer)) 25 26 (defun sly-switch-to-scratch-buffer () 27 (set-buffer (sly-scratch-buffer)) 28 (unless (eq (current-buffer) (window-buffer)) 29 (pop-to-buffer (current-buffer) t))) 30 31 (defvar sly-scratch-file nil) 32 33 (defun sly-scratch-buffer () 34 "Return the scratch buffer, create it if necessary." 35 (or (get-buffer (sly-buffer-name :scratch)) 36 (with-current-buffer (if sly-scratch-file 37 (find-file sly-scratch-file) 38 (get-buffer-create (sly-buffer-name :scratch))) 39 (rename-buffer (sly-buffer-name :scratch)) 40 (lisp-mode) 41 (use-local-map sly-scratch-mode-map) 42 (sly-mode t) 43 (current-buffer)))) 44 45 (provide 'sly-scratch)