Skip to content

Commit 5292cde

Browse files
author
Bozhidar Batsov
committed
[Fix #498] Implement scratch buffer functionality
1 parent 9d4eb71 commit 5292cde

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ cider-nrepl's info middleware for jump-to-definition.
2121
* New inspector inspired by SLIME's inspector
2222
* STDERR ouput is now font-locked with `cider-repl-err-output-face` to make it
2323
visually distinctive from `cider-repl-output-face` (used for STDOUT output).
24+
* New interactive command `cider-scratch`.
2425

2526
### Changes
2627

cider-scratch.el

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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

Comments
 (0)