Klimi's new dotfiles with stow.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

99 lines
3.4 KiB

4 years ago
  1. ;;; cider-scratch.el --- *scratch* buffer for Clojure -*- lexical-binding: t -*-
  2. ;; Copyright © 2014-2019 Bozhidar Batsov and CIDER contributors
  3. ;;
  4. ;; Author: Tim King <kingtim@gmail.com>
  5. ;; Phil Hagelberg <technomancy@gmail.com>
  6. ;; Bozhidar Batsov <bozhidar@batsov.com>
  7. ;; Artur Malabarba <bruce.connor.am@gmail.com>
  8. ;; Hugo Duncan <hugo@hugoduncan.org>
  9. ;; Steve Purcell <steve@sanityinc.com>
  10. ;; This program is free software: you can redistribute it and/or modify
  11. ;; it under the terms of the GNU General Public License as published by
  12. ;; the Free Software Foundation, either version 3 of the License, or
  13. ;; (at your option) any later version.
  14. ;; This program is distributed in the hope that it will be useful,
  15. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. ;; GNU General Public License for more details.
  18. ;; You should have received a copy of the GNU General Public License
  19. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. ;; This file is not part of GNU Emacs.
  21. ;;; Commentary:
  22. ;; Imitate Emacs's *scratch* buffer.
  23. ;;; Code:
  24. (require 'cider-eval)
  25. (require 'clojure-mode)
  26. (require 'easymenu)
  27. (defcustom cider-scratch-initial-message
  28. ";; This buffer is for Clojure experiments and evaluation.\n
  29. ;; Press C-j to evaluate the last expression.\n
  30. ;; You can also press C-u C-j to evaluate the expression and pretty-print its result.\n\n"
  31. "The initial message displayed in new scratch buffers."
  32. :type 'string
  33. :group 'cider
  34. :package-version '(cider . "0.18.0"))
  35. (defvar cider-clojure-interaction-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. (define-key map [remap paredit-newline] #'cider-eval-print-last-sexp)
  40. (easy-menu-define cider-clojure-interaction-mode-menu map
  41. "Menu for Clojure Interaction mode"
  42. '("Clojure Interaction"
  43. (["Eval and print last sexp" #'cider-eval-print-last-sexp]
  44. "--"
  45. ["Reset" #'cider-scratch-reset])))
  46. map))
  47. (defconst cider-scratch-buffer-name "*cider-scratch*")
  48. ;;;###autoload
  49. (defun cider-scratch ()
  50. "Go to the scratch buffer named `cider-scratch-buffer-name'."
  51. (interactive)
  52. (pop-to-buffer (cider-scratch-find-or-create-buffer)))
  53. (defun cider-scratch-find-or-create-buffer ()
  54. "Find or create the scratch buffer."
  55. (or (get-buffer cider-scratch-buffer-name)
  56. (cider-scratch--create-buffer)))
  57. (define-derived-mode cider-clojure-interaction-mode clojure-mode "Clojure Interaction"
  58. "Major mode for typing and evaluating Clojure forms.
  59. Like clojure-mode except that \\[cider-eval-print-last-sexp] evals the Lisp expression
  60. before point, and prints its value into the buffer, advancing point.
  61. \\{cider-clojure-interaction-mode-map}"
  62. (setq-local sesman-system 'CIDER))
  63. (defun cider-scratch--insert-welcome-message ()
  64. "Insert the welcome message for the scratch buffer."
  65. (insert cider-scratch-initial-message))
  66. (defun cider-scratch--create-buffer ()
  67. "Create a new scratch buffer."
  68. (with-current-buffer (get-buffer-create cider-scratch-buffer-name)
  69. (cider-clojure-interaction-mode)
  70. (cider-scratch--insert-welcome-message)
  71. (current-buffer)))
  72. (defun cider-scratch-reset ()
  73. "Reset the current scratch buffer."
  74. (interactive)
  75. (erase-buffer)
  76. (cider-scratch--insert-welcome-message))
  77. (provide 'cider-scratch)
  78. ;;; cider-scratch.el ends here