commit 8735ce04a8ac9f689373585b915180910b88139e
parent 7d55c232d204fcd22ee1ba1838a3987afda4ea44
Author: Lou Woell <lou.woell@posteo.de>
Date: Mon, 6 Oct 2025 20:22:28 +0200
README update
Diffstat:
3 files changed, 21 insertions(+), 4 deletions(-)
diff --git a/README.md b/README.md
@@ -23,6 +23,7 @@ Subcommands:
resolve: resolve namespace for identifier
locate: return location of declaration for identifier
list-modules: list all modules in current harepath
+ find-references: find all references to symbol
```
### resolve namespaces
@@ -50,6 +51,17 @@ $ harehelper locate os::stdout
/usr/src/hare/stdlib/os/+linux/stdfd.ha:29
```
+### find references
+
+```bash
+$ harehelper find-references <identifier> <path>
+```
+
+Returns a list of lines in harefiles under `path` that reference `identifier`.
+Identifier is assumed to be relative to HAREPATH. The advantage over grep et. al
+is that this command is aware of namespaces and will correctly return references
+even if the symbol is aliased.
+
### print all modules in harepath
```bash
@@ -73,8 +85,10 @@ let me know that you found this tool useful, you can reach me via
### Emacs integration
`haredoc.el` provides an emacs interface to haredoc using harehelper. The main
-entry points are `haredoc/goto-definition`, `haredoc` and
-`haredoc/describe-thing-at-point`.
+entry points are, `haredoc` and `haredoc/describe-thing-at-point`. The package
+also proves a
+[xref](https://www.gnu.org/software/emacs/manual/html_node/emacs/Xref.html)-backend
+for hare.
To enable the default keymap in hare-mode, add `haredoc-nav-mode` to your
`hare-mode-hook`.
@@ -83,7 +97,6 @@ To enable the default keymap in hare-mode, add `haredoc-nav-mode` to your
(add-hook 'hare-mode-hook #'haredoc-nav-mode)
```
-- `M-.`: haredoc/goto-defintion
- `C-c C-h`: haredoc
- `C-c C-d`: haredoc/describe-thing-at-point
@@ -113,6 +126,8 @@ The following `use-package` declarations include a build step for harehelper.
:vc (:url "https://git.repetitions.de/harehelper"
:make "all")
:hook (hare-mode . haredoc-nav-mode)
+ :init
+ (add-to-list 'xref-backend-functions 'hare-xref-backend)
:config
;;...
)
@@ -129,6 +144,8 @@ The following `use-package` declarations include a build step for harehelper.
:pre-build (("make"))
:files (:defaults "harehelper"))
:hook (hare-mode . haredoc-nav-mode)
+ :init
+ (add-to-list 'xref-backend-functions 'hare-xref-backend)
:config
;; ...
)
diff --git a/cmd/harehelper/find_refs.ha b/cmd/harehelper/find_refs.ha
@@ -52,6 +52,7 @@ fn get_line (file: io::handle, loc: *lex::location) (str | io::error) = {
// This is slow.
// TODO: figure out a way to get the line from the line/column info.
+ // Problem: the lexer counts '\t' as 8 columns.
for (true) {
io::seek(file, off, io::whence::SET)!;
let r = bufio::read_rune(file);
diff --git a/haredoc.el b/haredoc.el
@@ -310,7 +310,6 @@ declaration at point."
(defvar-keymap haredoc-map
"C-c C-h" 'haredoc
- "M-." 'haredoc/goto-defintion
"C-c C-d" 'haredoc/describe-thing-at-point)
;;;###autoload