How to do automatic expansion or autocomplete of functions and variables in a Clojure repl

一个人想着一个人 提交于 2019-12-10 01:52:21

问题


Is there a way to expand the current command at the Clojure repl like I'd be able to do in Common Lisp?

For example say I have typed:

Math/

I would like the tab key to expand to all the available variables and functions in that namespace.

I'm using Clojure as inferior-lisp would like to know how to do this from the plain vanilla repl in Clojure, and through swank slime.


回答1:


Another vote in favour of clojure-mode and slime under Emacs. In particular, if you set up auto-complete, then you can use my ac-slime package to get context-aware tab completion in a dropdown list. Here's a screencast showing it in action.

And, further to technomancy's comment about hippie-expand, here's how to tie slime completion into hippie-expand.

Update: as of 2012, nrepl, nrepl.el and ac-nrepl are replacing slime and ac-slime; same functionality, smaller and cleaner codebase.

Update2: as of Oct 2013 nrepl.el is renamed to cider and it and ac-nrepl have moved to the clojure-emacs organisation on github. nrepl remains as the server component




回答2:


Have you tried Clojure mode for Emacs? It has autocomplete (suggestions are shown in new window, and if there's only one possible option, it is used to expand name), highlighting and many other nice features (not more then for CL, but not less too).

It is available via ELPA. After installing ELPA type M-x package-list-packages, set cursor near needed package and press i (already installed packages are in red). You'll need packages clojure-mode, slime, slime-repl and swank-clojure. When you're done with i-marks, press x to complete installation. Finally, press M-x slime - Emacs will tell, that Clojure is not installed and propose to download and use latest version. Just agree.

You can also integrate Emacs with Leiningen.




回答3:


The vanilla repl in Clojure is pretty crippled; it doesn't even have history. Avoid it for anything but the most primitive of tasks. I don't think you can get this in inferior-lisp, but in the slime repl you can just use TAB to complete things like this. In clojure-mode buffers with slime activated it's M-TAB, or you can tie it into your hippie-expand functions.



来源:https://stackoverflow.com/questions/4289480/how-to-do-automatic-expansion-or-autocomplete-of-functions-and-variables-in-a-cl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!