From 5e9cd756af1e0b1bbd54103204189832e4860527 Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Thu, 29 Sep 2022 14:32:42 +1000 Subject: Extracting out button actions in rendered html doc - help mode: should stay in help mode (unimplemented due to API limitation, goto definition for now). - eldoc / id query results: should goto definition. --- hcel-utils.el | 46 +++++++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 21 deletions(-) (limited to 'hcel-utils.el') diff --git a/hcel-utils.el b/hcel-utils.el index df76f2a..83b3cb6 100644 --- a/hcel-utils.el +++ b/hcel-utils.el @@ -145,14 +145,16 @@ Example of an idSrcSpan: (alist-get 'exprType (alist-get 'info expr))))) (cons expression type))) -(defun hcel-render-html (html) +(defun hcel-render-html (html &optional action) + (unless action (setq action 'hcel-tag-span-button-load-source)) (when html ;; (hcel-debug-html html) (with-temp-buffer (insert html) - (let ((shr-external-rendering-functions - '((span . hcel-tag-span) - (div . hcel-tag-div)))) + (let* ((hcel-tag-span (hcel-tag-span-function action)) + (shr-external-rendering-functions + `((span . ,hcel-tag-span) + (div . hcel-tag-div)))) (shr-render-region (point-min) (point-max))) (buffer-string)))) @@ -161,23 +163,25 @@ Example of an idSrcSpan: (insert html) (pp (libxml-parse-html-region (point-min) (point-max))))) -(defun hcel-tag-span (dom) - (let ((start (point))) - (shr-tag-span dom) - (mapc (lambda (attr) - (cond ((eq (car attr) 'data-location) - (put-text-property start (point) - 'location-info - (json-read-from-string (cdr attr))) - (make-text-button start (point) - 'action - (lambda (m) - (hcel-load-module-location-info - (hcel-to-exact-location - (get-text-property m 'location-info)))) - 'face 'button) -))) - (dom-attributes dom)))) +(defun hcel-tag-span-function (button-action) + (lambda (dom) + (let ((start (point))) + (shr-tag-span dom) + (mapc (lambda (attr) + (cond ((eq (car attr) 'data-location) + (put-text-property start (point) + 'location-info + (json-read-from-string (cdr attr))) + (make-text-button start (point) + 'action button-action + 'face 'button) + ))) + (dom-attributes dom))))) + +(defun hcel-tag-span-button-load-source (marker) + (hcel-load-module-location-info + (hcel-to-exact-location + (get-text-property marker 'location-info)))) (defun hcel-tag-div (dom) (if (equal (dom-attr dom 'class) "source-code") -- cgit v1.2.3