commit 7158ca3c5fb7584e5fe2e3e6e3e4dad473cf3cd8
parent 0f0eae721d0812e461b519d7c7c8345c1e41e1b5
Author: Lou Woell <lou.woell@posteo.de>
Date:   Thu,  4 Sep 2025 15:29:43 +0200

harepath manipulation tools

Diffstat:
Mcmd/harehelper/helper.ha | 38++++++++++++++++++++++++++------------
Mharedoc.el | 24++++++++++++++++--------
2 files changed, 42 insertions(+), 20 deletions(-)

diff --git a/cmd/harehelper/helper.ha b/cmd/harehelper/helper.ha @@ -6,12 +6,15 @@ use hare::module; use io; use os; use path; +use strings; def HAREPATH = "/usr/src/hare/stdlib/:/usr/src/hare/third-party:."; const help: []getopt::help = [ "help with hare", ('h', "show help"), + ('p', "path", "append to harepath"), + ('P', "return harepath"), ("list", [ "list symbols in package", "identier" @@ -27,6 +30,10 @@ const help: []getopt::help = [ export fn main () void = { + let ppath = false; + + const cmd = getopt::parse(os::args, help...); + defer getopt::finish(&cmd); const ctx = module::context { harepath = os::tryenv("HAREPATH", HAREPATH), harecache = match (os::getenv("HARECACHE")) { @@ -35,16 +42,31 @@ export fn main () void = { case void => yield dirs::cache("hare"); }, - tags = [], + tags = ["linux"], }; - const cmd = getopt::parse(os::args, help...); - defer getopt::finish(&cmd); + for (let (k, v) .. cmd.opts) { + switch(k){ + case 'h' => + getopt::printhelp(os::stdout, "cleandir", help)!; + os::exit(0); + case 'p' => + ctx.harepath = strings::join(":", ctx.harepath, v)!; + case 'P' => + ppath = true; + case => void; + }; + }; + + if(ppath) { + fmt::print(ctx.harepath)!; + os::exit(0); + }; match(cmd.subcmd){ case void => void; case let c: (str, *getopt::command) => - switch(c.0) { + switch (c.0) { case "find" => find(*c.1); case "list" => @@ -56,12 +78,4 @@ export fn main () void = { os::exit(0); }; - for (let (k, v) .. cmd.opts) { - switch(k){ - case 'h' => - getopt::printhelp(os::stdout, "cleandir", help)!; - os::exit(0); - case => void; - }; - }; }; diff --git a/haredoc.el b/haredoc.el @@ -35,13 +35,17 @@ (defvar hare/helperbindir (f-dirname (macroexp-file-name))) (defvar hare/helperbin (concat hare/helperbindir "/harehelper")) +(defun hare/root-dir () + (project-root (project-current nil))) + (defun hh/exec (strings) (let ((res (shell-command-to-string (string-join strings " ")))) (if (string= res "") nil res))) (defun hare/get-modules () "Return list of Hare modules." - (string-split (hh/exec (list hare/helperbin "list-modules")) "\n")) + (string-split (hh/exec (list hare/helperbin "-p" (hare/root-dir) + "list-modules")) "\n")) (defun hare/read-module (&optional init) (completing-read "Pick Module: " (hare/get-modules) nil nil init)) @@ -54,7 +58,10 @@ (t (progn (thing-at-point-looking-at "\\(\\(\\sw\\|\\s_\\)+::\\)*\\(\\sw\\|\\s_\\)+") (string-replace "*" "" (match-string 0))))))) - (hh/exec (list hare/helperbin "find" id (buffer-file-name))))) + ;; resolve identifier + (or (hh/exec (list hare/helperbin "-p" (hare/root-dir) "find" id + (buffer-file-name))) + id))) ;; Shows haredoc for the selected or word. ;;;###autoload @@ -62,12 +69,13 @@ "Run haredoc with the current word under the cursor and display the results in a new buffer." (interactive) - (let* ((current-word - (cond - (sign sign) - (t (hare/read-module)))) - (command (concat "haredoc -a -F tty " current-word)) - (output (shell-command-to-string command)) + (let* ((current-word (cond (sign sign) + (t (hare/read-module)))) + (output (with-environment-variables + (("HAREPATH" (hh/exec (list hare/helperbin + "-p" (hare/root-dir) + "-P")))) + (hh/exec (list "haredoc" "-a" "-F" "tty" current-word)))) (buffer-name "*haredoc*")) (with-output-to-temp-buffer buffer-name (with-current-buffer buffer-name