A JavaScript development environment for Emacs https://indium.readthedocs.io
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.

69 lines
2.2KB

  1. ;;; indium-scratch.el --- Scratch buffer for JS evaluation -*- lexical-binding: t; -*-
  2. ;; Copyright (C) 2016-2018 Nicolas Petton
  3. ;; Author: Nicolas Petton <nicolas@petton.fr>
  4. ;; Keywords: javascript, tools
  5. ;; This program is free software; you can redistribute it and/or modify
  6. ;; it under the terms of the GNU General Public License as published by
  7. ;; the Free Software Foundation, either version 3 of the License, or
  8. ;; (at your option) any later version.
  9. ;; This program is distributed in the hope that it will be useful,
  10. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ;; GNU General Public License for more details.
  13. ;; You should have received a copy of the GNU General Public License
  14. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. ;;; Commentary:
  16. ;; Open a scratch buffer with `indium-scratch'.
  17. ;;; Code:
  18. (require 'indium-interaction)
  19. (require 'indium-repl)
  20. (eval-and-compile (require 'indium-structs))
  21. ;;;###autoload
  22. (defun indium-scratch ()
  23. "Pop to the scratch buffer.
  24. If no scratch buffer exists for the current connection, create
  25. one first."
  26. (interactive)
  27. (pop-to-buffer (indium-scratch-get-buffer-create)))
  28. (defun indium-scratch-get-buffer-create ()
  29. "Return a scratch buffer for the current connection.
  30. If no buffer exists, create one."
  31. (let* ((bufname (indium-scratch-buffer-name))
  32. (buf (get-buffer bufname)))
  33. (unless buf
  34. (setq buf (get-buffer-create bufname))
  35. (indium-scratch-setup-buffer buf))
  36. buf))
  37. (defun indium-scratch-buffer-name ()
  38. "Return the scratch buffer name."
  39. "*JS scratch*")
  40. (defun indium-scratch-setup-buffer (buffer)
  41. "Setup the scratch BUFFER."
  42. (with-current-buffer buffer
  43. (js2-mode)
  44. (indium-interaction-mode)
  45. (setq-local company-backends '(company-indium-repl))
  46. (indium-scratch-insert-welcome-message)))
  47. (defun indium-scratch-insert-welcome-message ()
  48. "Insert a welcome message to help use the scratch buffer."
  49. (insert "// This buffer is for JavaScript evaluation.
  50. // Press C-x C-e to evaluate the last expression.
  51. // Press C-c M-i to inspect the last expression.\n\n"))
  52. (provide 'indium-scratch)
  53. ;;; indium-scratch.el ends here