aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuchen Pei <hi@ypei.me>2022-09-19 13:11:22 +1000
committerYuchen Pei <hi@ypei.me>2022-09-19 13:11:22 +1000
commit3da82c44a4a6ed7e3760fe2e9d37ebf2cfd669d1 (patch)
tree73b135b8d0dbe7330492e4c91455ad8143dcbb0e
parentc14271c3732f02ae391c3847ed7a687171ef4013 (diff)
find definition / references / eldoc now look at previous point too.
-rw-r--r--hcel-results.el28
-rw-r--r--hcel-source.el61
-rw-r--r--hcel-utils.el5
3 files changed, 48 insertions, 46 deletions
diff --git a/hcel-results.el b/hcel-results.el
index 5f27b6a..06eddbb 100644
--- a/hcel-results.el
+++ b/hcel-results.el
@@ -23,6 +23,7 @@
;; compilation-mode.
;;; Code:
+(require 'hcel-utils)
(defun hcel-results-next-error-no-open (n)
(interactive "p")
@@ -202,24 +203,23 @@ Start by choosing a package."
"Find references of the identifier at point."
(interactive)
(hcel-find-references-internal hcel-package-id hcel-module-path
- (get-text-property (point) 'identifier)))
+ (hcel-text-property-near-point 'identifier)))
(define-key hcel-mode-map (kbd "M-?") 'hcel-find-references-at-point)
(defun hcel-minor-find-references-at-point ()
(interactive)
- (let ((props (text-properties-at (point))))
- (cond ((or (eq major-mode 'hcel-outline-mode)
- (eq (current-buffer) eldoc--doc-buffer))
- (hcel-find-references-internal
- (plist-get props 'package-id)
- (plist-get props 'module-path)
- (plist-get props 'internal-id)))
- ((eq major-mode 'hcel-ids-mode)
- (hcel-find-references-internal
- (alist-get 'packageId (plist-get props 'location-info))
- (alist-get 'modulePath (plist-get props 'location-info))
- (plist-get props 'internal-id)))
- (t (error "%S not supported and not in eldoc doc buffer." major-mode)))))
+ (cond ((or (eq major-mode 'hcel-outline-mode)
+ (eq (current-buffer) eldoc--doc-buffer))
+ (hcel-find-references-internal
+ (hcel-text-property-near-point 'package-id)
+ (hcel-text-property-near-point 'module-path)
+ (hcel-text-property-near-point 'internal-id)))
+ ((eq major-mode 'hcel-ids-mode)
+ (hcel-find-references-internal
+ (alist-get 'packageId (hcel-text-property-near-point 'location-info))
+ (alist-get 'modulePath (hcel-text-property-near-point 'location-info))
+ (hcel-text-property-near-point 'internal-id)))
+ (t (error "%S not supported and not in eldoc doc buffer." major-mode))))
(defun hcel-find-references-internal (package-id module-path identifier)
(when (and package-id module-path identifier)
diff --git a/hcel-source.el b/hcel-source.el
index 688fff1..7a793c6 100644
--- a/hcel-source.el
+++ b/hcel-source.el
@@ -130,7 +130,7 @@ If NO-JUMP is non-nil, just open the source and does not jump to the location wi
(when occ (alist-get 'contents (alist-get 'sort occ)))))
(defun hcel-occ-symbol-at-point ()
- (when-let* ((occ (get-text-property (point) 'occurrence))
+ (when-let* ((occ (hcel-text-property-near-point 'occurrence))
(splitted (split-string occ "-"))
(line (string-to-number (car splitted)))
(col-beg (string-to-number (cadr splitted)))
@@ -140,7 +140,7 @@ If NO-JUMP is non-nil, just open the source and does not jump to the location wi
(defun hcel-type-at-point ()
(interactive)
(hcel-render-type-internal hcel-package-id hcel-module-path
- (get-text-property (point) 'identifier)))
+ (hcel-text-property-near-point 'identifier)))
(defun hcel-render-type-internal (package-id module-path identifier)
(when (and package-id module-path identifier)
@@ -169,7 +169,7 @@ If NO-JUMP is non-nil, just open the source and does not jump to the location wi
(defun hcel-id-docs-at-point ()
(hcel-id-docs-internal hcel-package-id hcel-module-path
- (get-text-property (point) 'identifier)))
+ (hcel-text-property-near-point 'identifier)))
(defun hcel-id-docs-internal (package-id module-path identifier)
(when (and package-id module-path identifier)
@@ -242,8 +242,7 @@ If NO-JUMP is non-nil, just open the source and does not jump to the location wi
(hcel-minor-mode))))
(defun hcel-minor-eldoc-id-type (cb)
- (when-let* ((props (text-properties-at (point)))
- (identifier (plist-get props 'internal-id))
+ (when-let* ((identifier (hcel-text-property-near-point 'internal-id))
(symbol (save-excursion
(buffer-substring
(progn
@@ -257,13 +256,13 @@ If NO-JUMP is non-nil, just open the source and does not jump to the location wi
(docstring
(cond ((eq major-mode 'hcel-outline-mode)
(hcel-render-type-internal
- (plist-get props 'package-id)
- (plist-get props 'module-path)
+ (hcel-text-property-near-point 'package-id)
+ (hcel-text-property-near-point 'module-path)
identifier))
((eq major-mode 'hcel-ids-mode)
(hcel-render-type-internal
- (alist-get 'packageId (plist-get props 'location-info))
- (alist-get 'modulePath (plist-get props 'location-info))
+ (alist-get 'packageId (hcel-text-property-near-point 'location-info))
+ (alist-get 'modulePath (hcel-text-property-near-point 'location-info))
identifier))
(t nil))))
(funcall cb docstring
@@ -280,18 +279,17 @@ If NO-JUMP is non-nil, just open the source and does not jump to the location wi
(hcel-minor-mode))))
(defun hcel-minor-eldoc-docs (cb)
- (when-let* ((props (text-properties-at (point)))
- (docstring
+ (when-let* ((docstring
(cond ((eq major-mode 'hcel-outline-mode)
(hcel-id-docs-internal
- (plist-get props 'package-id)
- (plist-get props 'module-path)
- (plist-get props 'internal-id)))
+ (hcel-text-property-near-point 'package-id)
+ (hcel-text-property-near-point 'module-path)
+ (hcel-text-property-near-point 'internal-id)))
((eq major-mode 'hcel-ids-mode)
(hcel-id-docs-internal
- (alist-get 'packageId (plist-get props 'location-info))
- (alist-get 'modulePath (plist-get props 'location-info))
- (plist-get props 'internal-id)))
+ (alist-get 'packageId (hcel-text-property-near-point 'location-info))
+ (alist-get 'modulePath (hcel-text-property-near-point 'location-info))
+ (hcel-text-property-near-point 'internal-id)))
(t nil))))
(setq this-command nil)
(funcall cb docstring)
@@ -426,8 +424,8 @@ If NO-JUMP is non-nil, just open the source and does not jump to the location wi
(defun hcel-find-definition ()
(hcel-find-definition-internal
hcel-package-id hcel-module-path
- (get-text-property (point) 'identifier)
- (get-text-property (point) 'occurrence)))
+ (hcel-text-property-near-point 'identifier)
+ (hcel-text-property-near-point 'occurrence)))
(add-hook 'hcel-minor-mode-hook
(lambda ()
@@ -438,19 +436,18 @@ If NO-JUMP is non-nil, just open the source and does not jump to the location wi
(hcel-minor-find-definition-at-point))
(defun hcel-minor-find-definition-at-point ()
(interactive)
- (let ((props (text-properties-at (point))))
- (cond ((or (eq major-mode 'hcel-outline-mode)
- (eq (current-buffer) eldoc--doc-buffer))
- (hcel-find-definition-internal
- (plist-get props 'package-id)
- (plist-get props 'module-path)
- (plist-get props 'internal-id)))
- ((eq major-mode 'hcel-ids-mode)
- (hcel-find-definition-internal
- (alist-get 'packageId (plist-get props 'location-info))
- (alist-get 'modulePath (plist-get props 'location-info))
- (plist-get props 'internal-id)))
- (t (error "%S not supported and not in eldoc doc buffer." major-mode)))))
+ (cond ((or (eq major-mode 'hcel-outline-mode)
+ (eq (current-buffer) eldoc--doc-buffer))
+ (hcel-find-definition-internal
+ (hcel-text-property-near-point 'package-id)
+ (hcel-text-property-near-point 'module-path)
+ (hcel-text-property-near-point 'internal-id)))
+ ((eq major-mode 'hcel-ids-mode)
+ (hcel-find-definition-internal
+ (alist-get 'packageId (hcel-text-property-near-point 'location-info))
+ (alist-get 'modulePath (hcel-text-property-near-point 'location-info))
+ (hcel-text-property-near-point 'internal-id)))
+ (t (error "%S not supported and not in eldoc doc buffer." major-mode))))
(defun hcel-find-definition-internal (package-id module-path identifier
&optional occurrence)
diff --git a/hcel-utils.el b/hcel-utils.el
index 18e1062..e5a82e7 100644
--- a/hcel-utils.el
+++ b/hcel-utils.el
@@ -166,4 +166,9 @@ Example of an idSrcSpan:
(shr-render-region (point-min) (point-max))
(buffer-string))))
+(defun hcel-text-property-near-point (prop)
+ "Find property prop at point, or just before point."
+ (or (get-text-property (point) prop)
+ (get-text-property (1- (point)) prop)))
+
(provide 'hcel-utils)