commit 4b5ade9959ffe01c0717364e22c2c421d0881e9b
parent 604e3cd5743a715569158203c8ccc9ba2f738a50
Author: Lou Woell <lou.woell@posteo.de>
Date: Fri, 10 Oct 2025 03:30:04 +0200
[haredoc.el] handle harehelper errors gracefully
Diffstat:
| M | haredoc.el | | | 49 | ++++++++++++++++++++++++++----------------------- |
1 file changed, 26 insertions(+), 23 deletions(-)
diff --git a/haredoc.el b/haredoc.el
@@ -24,8 +24,8 @@
;;; Commentary:
;; `haredoc.el' provides an Emacs interface for `haredoc' using harehelper. The
-;; main entry points are `haredoc/goto-definition', `haredoc' and
-;; `haredoc/describe-thing-at-point'.
+;; main entry points are, `haredoc' and `haredoc/describe-thing-at-point', as
+;; well as the `xref' backend.
;; To enable the default keymap in hare-mode, add `haredoc-nav-mode' to your
;; `hare-mode-hook':
@@ -62,7 +62,12 @@ Defaults to directory containing this file.")
(defmacro haredoc|harehelper (&rest args)
"Run harehelper with arguments ARGS."
- `(process-lines haredoc-helperbin ,@args))
+ `(catch 'exit
+ (process-lines-handling-status haredoc-helperbin
+ (lambda (x)
+ (unless (= x 0)
+ (throw 'exit nil)))
+ ,@args)))
(defun haredoc/root-dir ()
"Return root directory of current project or \".\"."
@@ -172,20 +177,20 @@ buffer. See also `haredoc/forward'."
(haredoc item)))
;;;###autoload
-(defun haredoc (&optional sign)
- "Run haredoc with hare identifier SIGN and present result in help buffer.
-If SIGN is nil, ask user."
- (interactive)
- (let* ((id (or sign (haredoc/read-module)))
- (components (string-split id "::" t))
- (loc (haredoc/get-location id))
- (path (xref-file-location-file (xref-item-location loc)))
- (parent-ns (if (length> components 1)
- (string-join (butlast components) "::")
- (car components)))
- (current-ns (if (f-directory? path)
- (string-trim-right id "::")
- parent-ns)))
+(defun haredoc (id)
+ "Run haredoc with hare identifier ID and present result in help buffer.
+If called interactively, ask user for ID."
+ (interactive (haredoc/read-module))
+ (when-let* ((id id)
+ (components (string-split id "::" t))
+ (loc (haredoc/get-location id))
+ (path (xref-file-location-file (xref-item-location loc)))
+ (parent-ns (if (length> components 1)
+ (string-join (butlast components) "::")
+ (car components)))
+ (current-ns (if (f-directory? path)
+ (string-trim-right id "::")
+ parent-ns)))
(when haredoc-stack-item
(push haredoc-stack-item haredoc-backward-stack)
(setq haredoc-forward-stack nil))
@@ -239,17 +244,14 @@ If SIGN is nil, ask user."
(defun haredoc/get-location (name)
"Get the location of the declaration of hare identifier NAME by calling
-the executable at `haredoc-helperbin'.
-
-Return value is a string \"/path/to/file.ha:line:column\"."
+the executable at `haredoc-helperbin'."
(when-let* ((loc (car (haredoc|harehelper "-p" (haredoc/root-dir)
"locate" name)))
(loc (split-string loc ":"))
(file (nth 0 loc))
(line (string-to-number (nth 1 loc)))
(col (string-to-number (nth 2 loc)))
- (sum (or (nth 3 loc)
- name)))
+ (sum (or (nth 3 loc) name)))
(xref-make sum (xref-make-file-location file line col))))
;;;###autoload
@@ -343,7 +345,8 @@ declaration at point."
(cl-defmethod xref-backend-definitions ((_backend (eql 'haredoc-xref))
symbol)
- (when-let* ((loc (haredoc/get-location symbol)))
+ (when-let* ((id symbol)
+ (loc (haredoc/get-location id)))
(list loc)))
(cl-defmethod xref-backend-identifier-completion-table