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.

71 lines
2.3 KiB

  1. ;;; indium-scratch.el --- Scratch buffer for JS evaluation -*- lexical-binding: t; -*-
  2. ;; Copyright (C) 2016-2017 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. (defun indium-scratch ()
  22. "Pop to the scratch buffer.
  23. If no scratch buffer exists for the current connection, create
  24. one first."
  25. (interactive)
  26. (pop-to-buffer (indium-scratch-get-buffer-create)))
  27. (defun indium-scratch-get-buffer-create ()
  28. "Return a scratch buffer for the current connection.
  29. If no buffer exists, create one.
  30. If there is no current connection, throw an error."
  31. (unless-indium-connected
  32. (user-error "No current connection"))
  33. (let* ((bufname (indium-scratch-buffer-name))
  34. (buf (get-buffer bufname)))
  35. (unless buf
  36. (setq buf (get-buffer-create bufname))
  37. (indium-scratch-setup-buffer buf))
  38. buf))
  39. (defun indium-scratch-buffer-name ()
  40. "Return the scratch buffer name."
  41. "*JS scratch*")
  42. (defun indium-scratch-setup-buffer (buffer)
  43. "Setup the scratch BUFFER."
  44. (with-current-buffer buffer
  45. (js2-mode)
  46. (indium-interaction-mode)
  47. (setq-local company-backends '(company-indium-repl))
  48. (indium-scratch-insert-welcome-message)))
  49. (defun indium-scratch-insert-welcome-message ()
  50. "Insert a welcome message to help use the scratch buffer."
  51. (insert "// This buffer is for JavaScript evaluation.
  52. // Press C-x C-e to evaluate the last expression.
  53. // Press C-c M-i to inspect the last expression.\n\n"))
  54. (provide 'indium-scratch)
  55. ;;; indium-scratch.el ends here