From 16fa378c8fa6b6f262a9f6ff2bb2dd307318b99f Mon Sep 17 00:00:00 2001 From: Torgeir Thoresen Date: Sun, 20 Aug 2017 21:41:53 +0200 Subject: [PATCH] Add `indium-interaction-eval-node-hook` to allow for eval hooks, e.g. for overlays --- indium-interaction.el | 6 +++++- indium-render.el | 15 +++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/indium-interaction.el b/indium-interaction.el index 3ae671b..d29aaa3 100644 --- a/indium-interaction.el +++ b/indium-interaction.el @@ -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." diff --git a/indium-render.el b/indium-render.el index 3998125..0947da8 100644 --- a/indium-render.el +++ b/indium-render.el @@ -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.