Browse Source

New command indium-eval-defun

indium-eval-defun is similar to eval-defun, buf for JavaScript buffers.
workspaces
Nicolas Petton 4 years ago
parent
commit
664bd1e75f
3 changed files with 51 additions and 24 deletions
  1. +27
    -15
      doc/Indium.texi
  2. +18
    -4
      indium-interaction.el
  3. +6
    -5
      sphinx-doc/code-evaluation.rst

+ 27
- 15
doc/Indium.texi View File

@ -21,7 +21,7 @@
@copying
@quotation
Indium 0.3.3, Apr 18, 2017
Indium 0.4.1, Apr 29, 2017
Nicolas Petton
@ -219,7 +219,7 @@ Add the following to your Emacs configuration:
@end example
@node Getting up and running,The REPL,Installation,Table of contents
@anchor{setup doc}@anchor{7}@anchor{setup getting-up-and-running}@anchor{8}@anchor{setup up-and-running}@anchor{9}
@anchor{setup up-and-running}@anchor{7}@anchor{setup getting-up-and-running}@anchor{8}@anchor{setup doc}@anchor{9}
@section Getting up and running
@ -231,7 +231,7 @@ Add the following to your Emacs configuration:
@end menu
@node NodeJS,Chrome/Chromium,,Getting up and running
@anchor{setup id1}@anchor{a}@anchor{setup nodejs}@anchor{b}
@anchor{setup nodejs}@anchor{a}@anchor{setup id1}@anchor{b}
@subsection NodeJS
@ -262,7 +262,7 @@ Connecting Indium to the node process will open a debugger on the first line of
the application code if you passed the CLI argument @code{--debug-brk}.
@node Chrome/Chromium,Using local files when debugging,NodeJS,Getting up and running
@anchor{setup chrome}@anchor{c}@anchor{setup chrome-chromium}@anchor{d}
@anchor{setup chrome-chromium}@anchor{c}@anchor{setup chrome}@anchor{d}
@subsection Chrome/Chromium
@ -336,7 +336,7 @@ directory!
@end cartouche
@node The REPL,Interaction in JS buffers,Getting up and running,Table of contents
@anchor{repl the-repl}@anchor{10}@anchor{repl repl}@anchor{11}@anchor{repl doc}@anchor{12}
@anchor{repl repl}@anchor{10}@anchor{repl the-repl}@anchor{11}@anchor{repl doc}@anchor{12}
@section The REPL
@ -353,7 +353,7 @@ directory!
A REPL (Read Eval Print Loop) buffer is automatically open when a new Indium
connection is made (see @ref{9,,Getting up and running}).
connection is made (see @ref{7,,Getting up and running}).
@image{repl,,,,png}
@ -487,7 +487,7 @@ the current stack frame, and will be able to access local variables from the
stack, etc.
@node Interaction in JS buffers,The stepping debugger,The REPL,Table of contents
@anchor{code-evaluation interaction}@anchor{19}@anchor{code-evaluation doc}@anchor{1a}@anchor{code-evaluation interaction-in-js-buffers}@anchor{1b}
@anchor{code-evaluation interaction-in-js-buffers}@anchor{19}@anchor{code-evaluation interaction}@anchor{1a}@anchor{code-evaluation doc}@anchor{1b}
@section Interaction in JS buffers
@ -515,12 +515,24 @@ add or remove breakpoints from your buffers.
@subsection Evaluating and inspecting
To evaluate the JavaScript expression preceding the point, press @code{C-x C-e}.
Here's a list of available keybindings:
To inspect the result of the evaluation of an expression, press @code{C-c M-i} (see
@itemize -
@item
@code{C-x C-e}: Evaluate the JavaScript expression preceding the point.
@item
@code{C-M-x}: Evaluate the innermost function enclosing the point.
@item
@code{C-c M-i}: Inspect the result of the evaluation of an expression (see
@ref{14,,The inspector}).
The entire buffer can be evaluated with @code{M-x indium-eval-buffer}.
@item
@code{M-x indium-eval-buffer}: Evaluate the entire buffer.
@end itemize
@node Switching to the REPL buffer,Adding and removing breakpoints,Evaluating and inspecting,Interaction in JS buffers
@anchor{code-evaluation switching-to-the-repl-buffer}@anchor{1d}
@ -528,7 +540,7 @@ The entire buffer can be evaluated with @code{M-x indium-eval-buffer}.
Press @code{C-c C-z} from any buffer with @code{indium-interaction-mode} turned on to
switch back to the REPL buffer (see @ref{11,,The REPL}).
switch back to the REPL buffer (see @ref{10,,The REPL}).
@node Adding and removing breakpoints,,Switching to the REPL buffer,Interaction in JS buffers
@anchor{code-evaluation adding-and-removing-breakpoints}@anchor{1e}
@ -572,18 +584,18 @@ updated automatically. You can either refresh the page or evaluate
@end cartouche
@node The stepping debugger,The inspector,Interaction in JS buffers,Table of contents
@anchor{debugger doc}@anchor{20}@anchor{debugger debugger}@anchor{1f}@anchor{debugger the-stepping-debugger}@anchor{21}
@anchor{debugger the-stepping-debugger}@anchor{20}@anchor{debugger debugger}@anchor{1f}@anchor{debugger doc}@anchor{21}
@section The stepping debugger
@node The inspector,,The stepping debugger,Table of contents
@anchor{inspector the-inspector}@anchor{22}@anchor{inspector inspector}@anchor{14}@anchor{inspector doc}@anchor{23}
@anchor{inspector inspector}@anchor{14}@anchor{inspector the-inspector}@anchor{22}@anchor{inspector doc}@anchor{23}
@section The inspector
Indium features an object inspector that can be open on any object reference
from a REPL buffer (see @ref{11,,The REPL}), the debugger (see @ref{1f,,The stepping debugger}), or
the result of any evaluation of JavaScript code (see @ref{19,,Interaction in JS buffers}).
from a REPL buffer (see @ref{10,,The REPL}), the debugger (see @ref{1f,,The stepping debugger}), or
the result of any evaluation of JavaScript code (see @ref{1a,,Interaction in JS buffers}).
To inspect the result of the evaluation of an expression, press @code{C-c M-i}. An
inspector buffer will pop up. You can also press @code{RET} or left click on


+ 18
- 4
indium-interaction.el View File

@ -49,20 +49,33 @@ evaluated."
"Evaluate the node before point; print in the echo area.
This is similar to `eval-last-sexp', but for JavaScript buffers.
Interactively, with a prefix argument ARG, print output into
current buffer."
Interactively, with a prefix argument ARG, print the output into
the current buffer."
(interactive "P")
(indium-interaction--eval-node (indium-interaction-node-before-point) arg))
(defun indium-eval-defun ()
"Evaluate the innermost function enclosing the current point."
(interactive)
(if-let ((node (js2-mode-function-at-point)))
(indium-interaction--eval-node node)
(user-error "No function at point")))
(defun indium-interaction--eval-node (node &optional print)
"Evaluate the AST node NODE.
If PRINT is non-nil, print the output into the current buffer."
(indium-interaction--ensure-connection)
(js2-mode-wait-for-parse
(lambda ()
(indium-eval (js2-node-string (indium-interaction-node-before-point))
(indium-eval (js2-node-string node)
(lambda (value _error)
(let ((description (indium-render-value-to-string value)))
(if arg
(if print
(save-excursion
(insert description))
(indium-message "%s" description))))))))
(defun indium-reload ()
"Reload the page."
(interactive)
@ -137,6 +150,7 @@ current buffer."
(defvar indium-interaction-mode-map
(let ((map (make-sparse-keymap)))
(define-key map (kbd "C-x C-e") #'indium-eval-last-node)
(define-key map (kbd "C-M-x") #'indium-eval-defun)
(define-key map (kbd "C-c M-i") #'indium-inspect-last-node)
(define-key map (kbd "C-c C-z") #'indium-switch-to-repl-buffer)
(define-key map (kbd "C-c b b") #'indium-toggle-breakpoint)


+ 6
- 5
sphinx-doc/code-evaluation.rst View File

@ -16,12 +16,13 @@ add or remove breakpoints from your buffers.
Evaluating and inspecting
-------------------------
To evaluate the JavaScript expression preceding the point, press ``C-x C-e``.
Here's a list of available keybindings:
To inspect the result of the evaluation of an expression, press ``C-c M-i`` (see
:ref:`inspector`).
The entire buffer can be evaluated with ``M-x indium-eval-buffer``.
- ``C-x C-e``: Evaluate the JavaScript expression preceding the point.
- ``C-M-x``: Evaluate the innermost function enclosing the point.
- ``C-c M-i``: Inspect the result of the evaluation of an expression (see
:ref:`inspector`).
- ``M-x indium-eval-buffer``: Evaluate the entire buffer.
Switching to the REPL buffer
----------------------------


Loading…
Cancel
Save