aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuchen Pei <hi@ypei.me>2022-09-28 14:13:06 +1000
committerYuchen Pei <hi@ypei.me>2022-09-28 14:13:06 +1000
commitf85beb8c1b8ac06a02ffc4d2fc6f80f18dc65523 (patch)
treef1d9eaaee52a3fe54da0e83943cead7afa036ea7
parentb322b6e16b5e9e4fc80065ec667a4da66cd81bf2 (diff)
Moving declarations from local var to text property
-rw-r--r--hcel-source.el51
1 files changed, 36 insertions, 15 deletions
diff --git a/hcel-source.el b/hcel-source.el
index 40af781..4151f63 100644
--- a/hcel-source.el
+++ b/hcel-source.el
@@ -24,8 +24,6 @@
(require 'xref)
(defvar-local hcel-identifiers nil)
-(defvar-local hcel-declarations nil)
-(defvar-local hcel-occurrences nil)
(defvar-local hcel-package-id nil)
(defvar-local hcel-module-path nil)
(defvar-local hcel-highlight-id nil)
@@ -56,12 +54,12 @@ When FORCE is non-nil, kill existing source buffer if any."
;; (hcel-write-source-to-buffer (alist-get 'tokenizedLines json))
(hcel-write-html-source-to-buffer (hcel-source-html json)
(alist-get 'occurrences json))
+ (hcel-annotate-declarations (alist-get 'declarations json))
;; (hcel-fontify-with-haskell-mode)
;; it is important the setq of local vars are after the (hcel-mode)
;; otherwise they may be rewritten
(hcel-mode)
- (setq hcel-declarations (alist-get 'declarations json)
- hcel-identifiers (alist-get 'identifiers json)
+ (setq hcel-identifiers (alist-get 'identifiers json)
hcel-package-id package-id
hcel-module-path module-path)
(goto-char (point-min)))))
@@ -321,6 +319,29 @@ the location with pulsing.
(dom-by-tag line 'span))
(insert "\n"))
+(defun hcel-annotate-declarations (decls)
+ (save-excursion
+ (mapc
+ (lambda (decl)
+ (goto-char (point-min))
+ (forward-line (1- (alist-get 'lineNumber decl)))
+ (add-text-properties (point) (1+ (point))
+ (list 'declaration decl)))
+ decls)))
+
+(defun hcel-source-next-declaration ()
+ (interactive)
+ (beginning-of-line)
+ (text-property-search-forward 'declaration nil t))
+(define-key hcel-mode-map "n" #'hcel-source-next-declaration)
+
+(defun hcel-source-previous-declaration ()
+ (interactive)
+ (beginning-of-line)
+ (text-property-search-backward 'declaration nil t)
+ (left-char))
+(define-key hcel-mode-map "p" #'hcel-source-previous-declaration)
+
(defface hcel-type-face '((t :inherit font-lock-type-face))
"Face used to highlight types" :group 'hcel-faces)
(defface hcel-value-face '((t :inherit font-lock-variable-name-face))
@@ -354,17 +375,17 @@ the location with pulsing.
(defun hcel-imenu-create-index ()
(unless (derived-mode-p 'hcel-mode)
(error "Not in hcel-mode!"))
- (mapcar
- (lambda (decl)
- (cons
- (hcel-render-components
- (alist-get 'components
- (alist-get 'declType decl))
- (alist-get 'name decl))
- (progn (goto-char (point-min))
- (forward-line (1- (alist-get 'lineNumber decl)))
- (point))))
- hcel-declarations))
+ (goto-char (point-min))
+ (let ((index) (match))
+ (while (setq match (text-property-search-forward 'declaration))
+ (push (cons
+ (hcel-render-components
+ (alist-get 'components
+ (alist-get 'declType (prop-match-value match)))
+ (alist-get 'name (prop-match-value match)))
+ (1- (point)))
+ index))
+ index))
(define-key hcel-mode-map "j" #'imenu)
;; xref