I'm trying to adding inferior-lisp support for clojure. I've read several articles how to do it and it looks so easy, just do something like this:
M-x set-variable inferior-lisp-program "lein repl"
and then I hit
C-c C-z
And it does the job, which is the repl is on. But when I type something e.g. (def foo "bar") and hit enter, the repl just idle. Any ideas how to fix this?
You can take a look at this blog which shows a way to not using cider.
Related
I'm trying to work with Clojure using inferior lisp mode. My setup:
(setq inferior-lisp-program "lein repl")
(run-lisp) ;; Clojure REPL appears then...
When I evaluate short forms using lisp-eval-region, there are not any errors. But, when I try to eval a long region or even entire buffer, I face the following strange behavior:
The input text sent to the REPL buffer is full of rubbish symbols:
(doseq [addr addresses][53G[38G[54G
For unknown reason, some symbols are cut and so cannot be found:
(u/validat (:entity_id obj)[61G[46G[62G Whereas in the code I have (u/validate-access!.
More comprehensive dump is here.
ps: I've been working with cider for a long time, just wondering are there any alternatives.
The "rubbish symbols" are ANSI escape codes for putting the cursor on a certain column. Your REPL process is outputting these, and Emacs's process buffer doesn't know how to handle them.
Notice that in a lein repl when you type a closing parenthesis your cursor will briefly jump back to the opening one, that's what those escape codes do.
You're right that inf-lisp should work, Rich Hickey used it for a long time, maybe he still does. I would try using it with the plain built-in Clojure REPL, instead of with Leiningen's, since the latter really expects an actual terminal on the other end.
(setq inferior-lisp-program "lein run -m clojure.main")
Also consider using inf-clojure, it's very similar to inf-lisp, but is better suited for use with Clojure.
I just installed racket-mode in my emacs 24.3, when I run the REPL via racket-repl command, the REPL starts correctly, but some of the racket procedures/functions aren't recognized. i.e
> (class object%)
; class: undefined;
; cannot reference undefined identifier
> (enter! "test.rkt")
; enter!: undefined;
; cannot reference undefined identifier
The current value of the racket-racket-program variable is set to Racket.exe. On the other hand if I just run Racket.exe from the windows command line, then the REPL works as expected.
Any help with this is greatly appreciated.
When you do a racket-repl, that REPL initially opens with the equivalent of #lang racket/base. At the prompt you could type (require racket) to get the bigger language, including the class stuff like object%.
(There's an open issue about this. Feel free to chime in there.)
Instead of typing (enter! "test.rkt") at the prompt, try ,run test.rkt.
In fact, the easiest way to do this is with an Emacs buffer open on test.rkt. Then you can press C-c C-k a.k.a. M-x racket-run.
(Note that this leaves point in the test.rkt buffer. If you prefer point to go to the REPL, instead you can use M-x racket-run-and-switch-to-repl, bound by default to F5 like in DrRacket.)
TL;DR the most common use pattern with racket-mode is:
Visit a .rkt file in a buffer.
"Run" it with C-c C-c (or F5).
Explore in the REPL interactively as you wish.
Goto 2.
If your file contains #lang racket then the REPL picks up what language to use.
If no such line is present my guess is that racket/base is used -- and object% is not defined in racket/base.
Try entering this program:
#lang racket
(+ 1 2)
Then start the REPL and try your snippet again.
I am doing both clojure and clojurescript development. I usually start clojure by the clojure-jack-in function, and clojurescript repl by the following funciton -
(defun clojurescript-repl ()
(interactive)
(run-lisp "lein2 trampoline cljsbuild repl-listen"))
The clojure-jack-in starts swank while the above function starts inferior-lisp. However both of them have same key bindings. How do I change the key bindings to use both of them at once?
Thanks,
Murtaza
The short answer is that there isn't a great way to do this.
The Clojurescript One wiki has some pointers tho:
https://github.com/brentonashworth/one/wiki/Emacs
I am quite new to Emacs.
When running Emacs' python interpretor, it does
>>> print(24)
print(24)
24
Is there a way I can prevent the re-printing of my input and make it as below?
>>> print(24)
24
Thank you so much :)
The trick here is that the buffer you're running the python process in doesn't have comint-process-echoes set.
There are a couple of other questions that are relevant to your problem.
How to turn off the echoing
How to set emacs so it always turns off echoing
But the basic gist is you need to customize the value of comint-process-echoes. If you are new to emacs, you might not know that most customizations are done using emacs lisp, where setting a variable looks something like this:
(setq variable-name new-value)
In this case, the variable we want is comint-process-echoes so the lisp we want to evaluate is:
(setq comint-process-echoes t)
Where t is lisp-speak for "true."
So, to borrow the advice of the first link above, to actually tell emacs to evaluate this lisp code, use the M-: (meta+colon) command. From the python shell buffer, type meta+colon, then type (setq comint-process-echoes t) then hit return. Your problem should be solved.
I have a confession: I don't know Lisp. Despite that fact, with a bit of help from some co-workers, I managed to write an emacs macro/script which:
switched to shell mode (ie. M-x shell-mode)
disabled truncating lines (ie. M-x toggle-truncate-lines)
started a database console (ie. "mysql")
I was then able to start emacs with that macro using the --script option, and suddenly I had a way to start mysql in a much friendlier environment with a single command :-)
But here's the problem: I changed jobs and left that script behind. Now I'd very much like to re-create that script at my new job, but I no longer have any emacs experts to help me write it like I did at the old job.
Now, I really hate SO posts where someone basically says "please write my code for me", so I don't want to do that. However, if any emacs macro experts could at least give me some pointers (like "here's how you invoke a M-x command in a macro"), or point me to an emacs-macro-writing guide, or otherwise "teach me to fish" on this issue, I would greatly appreciate it.
... and if someone just happened to have a similar script already lying around that they wanted to post, I certainly wouldn't complain ;-)
Most emacs commands (i.e., M-x toggle-truncate-lines) can be translated directly to elisp by wrapping them in parentheses:
(toggle-truncate-lines)
The rumours are true, in lisp you just scatter parentheses around and they make magic.
Now in this case, you can do better. Toggling makes sense for an interactive function, but in a program you don't really want to toggle truncate-lines, you want to turn on truncate-lines. Its the same thing if truncate-lines was turned off to begin with, but you don't know when your program will be run next. Anyways, in Emacs, features are often controlled by a variable. In this case, the variable is truncate-lines, and to turn that feature on, you set the variable to t (which means true).
To do this, use:
(setq truncate-lines t)
We use setq instead of = for assignment, because they made lisp before = had been invented.
For the real scoop you should take a look at Robert Chassel's excellent "An introduction to to Programming in Emacs Lisp". It comes built-in with your emacs, you can get to it with C-h i m Emacs Lisp Intro.
A good way (I think) to start writing elisp functions is to record keyboard macros, and then to analyse them using edit-kbd-macro
For example, if you start recording a keyboard macro using f3, then do interactively all the things you want and terminate the macro using f4, you can see the underlying emacs-lisp commands using M-xedit-kbd-macrof4 (this last f4 is the key binding you'd have used to execute the keyboard macro)
<<shell>> ;; shell
<<toggle-truncate-lines>> ;; toggle-truncate-lines
mysql ;; self-insert-command * 5
RET ;; comint-send-input
Now you can write a script using these functions, looking up the documentation (e.g. C-h ftoggle-truncate-lines) to see if you should call them with special arguments in non-interactive mode.
You should also replace self-insert-command by calls to insert.
This should give you something like the following script, which you can call using emacs --load myscript.el
(shell)
(toggle-truncate-lines 1)
(insert "mysql")
(comint-send-input)
Of course, this might not work as expected the first time, so you might have to eval (setq debug-on-error t) to get debugging information.
What version of Emacs are you using?
In Emacs 24, I have M-x sql-mysql, which does everything you ask and has font-locking.