Browse Source

Add `indium-interaction-eval-node-hook` to allow for eval hooks, e.g. for overlays

workspaces
Torgeir Thoresen 3 years ago
parent
commit
16fa378c8f
2 changed files with 14 additions and 7 deletions
  1. +5
    -1
      indium-interaction.el
  2. +9
    -6
      indium-render.el

+ 5
- 1
indium-interaction.el View File

@ -77,6 +77,10 @@ the current buffer."
(indium-interaction--eval-node node)
(user-error "No function at point")))
(defvar indium-interaction-eval-node-hook nil
"Hooks to run after evaluating node before the point.")
(add-hook 'indium-interaction-eval-node-hook #'indium-message)
(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."
@ -89,7 +93,7 @@ If PRINT is non-nil, print the output into the current buffer."
(if print
(save-excursion
(insert description))
(indium-message "%s" description))))))))
(run-hook-with-args 'indium-interaction-eval-node-hook description))))))))
(defun indium-reload ()
"Reload the page."


+ 9
- 6
indium-render.el View File

@ -173,14 +173,17 @@ Otherwise, insert a newline."
(let ((function (get-text-property (point) 'indium-action)))
(funcall function)))
(defun indium-fontify-js (args)
"Fontify ARGS as JavaScript."
(with-temp-buffer
(js-mode)
(insert (apply #'format args))
(font-lock-fontify-region (point-min) (point-max))
(buffer-string)))
(defun indium-message (&rest args)
"Display ARGS like `message', but fontified as JavaScript."
(let ((string (with-temp-buffer
(js-mode)
(insert (apply #'format args))
(font-lock-fontify-region (point-min) (point-max))
(buffer-string))))
(message "%s" string)))
(message "%s" (apply #'indium-fontify-js args)))
(defun indium-render--truncate-string-to-newline (string)
"Return STRING truncated before the first newline.


Loading…
Cancel
Save