From 6f522c08939cfbe5f2993a093dd8302aa438fb57 Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Tue, 6 Sep 2022 10:21:10 +1000 Subject: showing docs in hcel-ids mode, switch to buffer --- lisp/hcel-results.el | 11 +++++++++-- lisp/hcel-source.el | 23 ++++++++++++++++------- lisp/hcel-utils.el | 7 +++++++ 3 files changed, 32 insertions(+), 9 deletions(-) (limited to 'lisp') diff --git a/lisp/hcel-results.el b/lisp/hcel-results.el index d623d59..63f3c91 100644 --- a/lisp/hcel-results.el +++ b/lisp/hcel-results.el @@ -228,7 +228,13 @@ Start by choosing a package." hcel-results-max-page-number)) (mapc (lambda (result) - (let ((location-info (alist-get 'locationInfo result))) + (let* ((location-info (alist-get 'locationInfo result)) + (doc (hcel-render-html + (or (alist-get 'doc result) + (alist-get 'documentation + (ignore-errors + (hcel-definition-site-location-info + location-info))))))) (insert "--\n") (insert (propertize (format "%s :: %s\n" @@ -239,7 +245,8 @@ Start by choosing a package." (insert (format "Defined in %s %s\n" (hcel-format-package-id (alist-get 'packageId location-info) "-") - (alist-get 'modulePath location-info))))) + (alist-get 'modulePath location-info))) + (when doc (insert doc)))) (alist-get 'json results)) (goto-char (point-min)))) diff --git a/lisp/hcel-source.el b/lisp/hcel-source.el index c397387..29efab0 100644 --- a/lisp/hcel-source.el +++ b/lisp/hcel-source.el @@ -89,6 +89,19 @@ If NO-JUMP is non-nil, just open the source and does not jump to the location wi 'next-error)) buffer)) +(defun hcel-switch-buffer () + (interactive) + (switch-to-buffer + (read-buffer + "Switch to buffer: " nil t + (lambda (buffer) + (equal + (buffer-local-value + 'major-mode + (get-buffer (if (stringp buffer) buffer (car buffer)))) + 'hcel-mode))))) +(define-key hcel-mode-map "b" 'hcel-switch-buffer) + (defun hcel-definition-site-at-point () "Call definitionSite for identifier at point. @@ -149,17 +162,13 @@ May cause error if the identifier has exact location." ;; same module (alist-get 'doc (hcel-lookup-identifier-at-point)) ;; other module - (when-let - ((definition (ignore-errors (hcel-definition-site-at-point)))) - (alist-get 'documentation definition)) + (alist-get 'documentation + (ignore-errors (hcel-definition-site-at-point))) ;; hoogle (when-let ((hoogle-docs (ignore-errors (hcel-hoogle-docs-at-point)))) (when (length> hoogle-docs 0) (concat "Hoogle: " hoogle-docs)))))) - (with-temp-buffer - (insert docs) - (shr-render-region (point-min) (point-max)) - (buffer-string)))) + (hcel-render-html docs))) ;; TODO: multiple expressions (defun hcel-expressions-type (beg end) diff --git a/lisp/hcel-utils.el b/lisp/hcel-utils.el index c7b6755..9db5d81 100644 --- a/lisp/hcel-utils.el +++ b/lisp/hcel-utils.el @@ -140,4 +140,11 @@ Example of an idSrcSpan: (alist-get 'exprType (alist-get 'info expr))))) (cons expression type))) +(defun hcel-render-html (html) + (when html + (with-temp-buffer + (insert html) + (shr-render-region (point-min) (point-max)) + (buffer-string)))) + (provide 'hcel-utils) -- cgit v1.2.3