|
| 1 | +;;; cider-scratch.el --- *scratch* buffer for Clojure -*- lexical-binding: t -*- |
| 2 | + |
| 3 | +;; Copyright © 2014 Bozhidar Batsov |
| 4 | +;; |
| 5 | +;; Author: Tim King <[email protected]> |
| 6 | +;; Phil Hagelberg <[email protected]> |
| 7 | +;; Bozhidar Batsov <[email protected]> |
| 8 | +;; Hugo Duncan <[email protected]> |
| 9 | +;; Steve Purcell <[email protected]> |
| 10 | + |
| 11 | +;; This program is free software: you can redistribute it and/or modify |
| 12 | +;; it under the terms of the GNU General Public License as published by |
| 13 | +;; the Free Software Foundation, either version 3 of the License, or |
| 14 | +;; (at your option) any later version. |
| 15 | + |
| 16 | +;; This program is distributed in the hope that it will be useful, |
| 17 | +;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | +;; GNU General Public License for more details. |
| 20 | + |
| 21 | +;; You should have received a copy of the GNU General Public License |
| 22 | +;; along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 23 | + |
| 24 | +;; This file is not part of GNU Emacs. |
| 25 | + |
| 26 | +;;; Commentary: |
| 27 | + |
| 28 | +;; Imitate Emacs's *scratch* buffer. |
| 29 | + |
| 30 | +;;; Code: |
| 31 | + |
| 32 | +(require 'cider-interaction) |
| 33 | +(require 'clojure-mode) |
| 34 | + |
| 35 | +(defvar cider-scratch-mode-map |
| 36 | + (let ((map (make-sparse-keymap))) |
| 37 | + (set-keymap-parent map clojure-mode-map) |
| 38 | + (define-key map (kbd "C-j") 'cider-eval-print-last-sexp) |
| 39 | + map)) |
| 40 | + |
| 41 | +(defconst cider-scratch-buffer-name "*cider-scratch*") |
| 42 | + |
| 43 | +;;;###autoload |
| 44 | +(defun cider-scratch () |
| 45 | + "Create a scratch buffer." |
| 46 | + (interactive) |
| 47 | + (pop-to-buffer (cider-find-or-create-scratch-buffer))) |
| 48 | + |
| 49 | +(defun cider-find-or-create-scratch-buffer () |
| 50 | + "Find or create the scratch buffer." |
| 51 | + (or (get-buffer cider-scratch-buffer-name) |
| 52 | + (cider-create-scratch-buffer))) |
| 53 | + |
| 54 | +(defun cider-create-scratch-buffer () |
| 55 | + "Create a new scratch buffer." |
| 56 | + (with-current-buffer (get-buffer-create cider-scratch-buffer-name) |
| 57 | + (clojure-mode) |
| 58 | + (insert ";; This buffer is for Clojure experiments and evaluation.\n") |
| 59 | + (insert ";; Press C-j to evaluate the last expression.") |
| 60 | + (use-local-map cider-scratch-mode-map) |
| 61 | + (current-buffer))) |
| 62 | + |
| 63 | +(provide 'cider-scratch) |
| 64 | + |
| 65 | +;; Local Variables: |
| 66 | +;; indent-tabs-mode: nil |
| 67 | +;; End: |
| 68 | + |
| 69 | +;;; cider-scratch.el ends here |
0 commit comments