JVM: defalias doesn't work?
jeroenvandijk opened this issue · 5 comments
I'm trying to extend the git
command with a browse
option, but defalias
doesn't do what I expect.
In ~/.closhrc
(defalias git-sh "git")
=>
$ git-sh
git-sh: command not found
Other functions work fine so I know closhrc
is loaded.
The same thing happens when I do it in the shell itself:
$ (defalias git-sh "git")
{"git-sh" "git"}
$ git-sh
git-sh: command not found
$ (git-sh)
CompilerException java.lang.RuntimeException: Unable to resolve symbol: git-sh in this context, compiling:(NO_SOURCE_PATH:1:1)
$
You are right, aliases and abbreviations in the node version work by transforming the input string before it gets passed to the reader. I haven't got around to hooking it into the rebel-readline yet, so it does not work for the JVM version at the moment.
Although a bit clunky a possible workaround for now would be to use the defcmd
like so:
(defcmd git-sh [& args]
(eval (macroexpand `(sh "git" ~@args))))
Thanks! There are two other issues though. With your example:
RuntimeException Invalid leading character: ` clojure.lang.Util.runtimeException (Util.java:221)
When I try to hack around with eval and use '
I get this:
CompilerException java.lang.RuntimeException: Unable to resolve symbol: ' in this context, compiling:(NO_SOURCE_PATH:0:0)
This seems to be an issue specific to closhrc. In the shell it does seem to work
I've been playing with the last closh-zero version and I worked around the alias "issue" in a similar way as you suggested https://gist.github.com/jeroenvandijk/33c51ab73480358ddad18277fc066717
@djblue This is a bit tricky, but I think I figured out a potential approach now.
For comparison the Clojurescript implementation is pretty straightforward. We get a line as string and just replace it if we find a match.
Clojure uses readers which makes it more difficult. The approach might be to create a reader which sits in between and buffers input to look for matches. I imagine it could be similar to how the custom reader hook is implemented.