Racket Terminal: Command for exiting a current program? - racket

When running Racket in a command line, you can start running a racket program using
(enter! "yourfile.rkt")
How do we exit the current .rkt program while still keeping Racket open in the command line?
Using
(exit)
closes Racket altogether instead of the current .rkt program.

Maybe you could try it and the current namespace will restore to the original.
(enter! #f)

Related

Emacs remembering compilation command and directory

Is it possible to force emacs to remember compilation command so after I restart it and run M-x recompile it will run the last compilation process instead of make -k in current dir?
Use savehist-mode, so minibuffer history is saved when you exit emacs and restored in the next session:
(require 'savehist)
(savehist-mode 1)
(setq history-length 1000)

How to invoke Emacs from an Erlang escript?

Inspired by Git as when you type "git commit", it opens an Emacs or Vim session for you. I'm writing an Erlang escript, and I want it to open an Emacs session at the end of the execution of the escript. I've tried
os:cmd("emacs -nw file.txt")
but it doesn't seem to work. Evaluating the above command within the Erlang shell yields
"emacs: standard input is not a tty\n"
One way to do this is to keep an Emacs running with server mode (put (server-mode) in your ~/.emacs), and call emacsclient instead of emacs from Erlang. That will open the file in the existing Emacs session. emacsclient exits and returns control to your Erlang program once you hit C-x # in Emacs.

Evaluate emacs lisp expression on command line

I'm a newbie to emacs. I'm working with emacs-24.1 on redhat linux, and trying to evaluate an elisp expression. What I want emacs to do is to evaluate the elisp expression without launching emacs itself. I'm trying different things
emacs --eval '(+ 2 3)'
I do not know if emacs is evaluating the expression, but the result is not shown on console and emacs window comes up. Next I tried this
emacsclient --eval '(+ 2 3)'
Emacs client is expecting a server. It could not find the server and hence throwing an error (can't find socket. start server etc). So I launched a server (server-name is SERVER) and ran emacsclient again
emacsclient --server-file=SERVER -e '(+ 2 3)'
This time, emacs evaluated the expression and printed the result on console. That is because emacs is using the existing server to evaluate the expression. Now I get a problem when the server is not running.
emacsclient --server-file=ANOTHER_SERVER -e '(+ 2 3)' -a emacs
This time, I'm not getting any error on console. Emacs is launching a new window, because of -a (my .emacs has (server-start) command in it and server-name set to ANOTHER_SERVER). But emacs then is trying to edit the file (+ 2 3). It is shown on the mode line. I'm confused. emacsclient --help showed me this
-e, --eval Evaluate the FILE arguments as ELisp expressions
and emacs manual says this.
'-e'
'--eval'
Tell Emacs to evaluate some Emacs Lisp code, instead of visiting some files.
When this option is given, the arguments to emacsclient are interpreted as a
list of expressions to evaluate, not as a list of files to visit.
I do not know how to proceed on this. As I said, my goal is to evaluate an elisp expression without launching emacs. Is it possible?
After a bit of testing it looks like you can use --batch to have emacs dump any messages to stderr. Then you can call message to print things to stderr where you'll be able to see them. Your example would become emacs --batch --eval '(message (number-to-string (+ 2 3)))' and the result would be printed to stderr.
If you're trying to redirect the output to a file you'll need to redirect stderr instead of stdout by using 2> instead of just >.
Try
emacs --batch --eval '(print (+ 2 3))'

Emacs compilation mode won't see bash alias

Emacs M-x compile does not see any aliases set in .bashrc. If I use M-x shell then type the alias, it is fine. I tried sourcing .bashrc from /etc/profile, from ~/.profile, ~/bash_env, anything I can think of to no avail.
I am on Emacs 23 and Ubuntu 11. I start emacs using /usr/bin/emacs %F, from a desktop button.
Emacs inherits its environment from the parent process. How are you invoking Emacs - from the command line, or some other way?
What happens if you:
M-x compile RET C-a C-k bash -i -c your_alias RET
Invoking bash as an interactive shell (-i option) should read your .bashrc aliases.
Edit: I think both M-x shell-command and M-x compile execute commands in an inferior shell via call-process. Try the following in your .emacs (or just evaluate):
(setq shell-file-name "bash")
(setq shell-command-switch "-ic")
I notice that after evaluation of the above, .bashrc aliases are picked up for use by both M-x shell-command and M-x compile, i.e
M-x compile RET your_alias RET
should then work.
My environment: Emacs 24.1 (pretest rc1), OSX 10.7.3
Keith Flower's answer works but can result in some slowdowns due to .bashrc being unnecessarily loaded in other places (presumably many many times, my computer is not exactly under-powered but emacs was almost unusable when trying to use autocomplete.el).
An alternative way is to locally modify shell-command-switch only for the functions where it is needed. This can be done using emacs' "advice" feature to create a wrapper around those functions. Here's an example that modifies compile:
;; Define + active modification to compile that locally sets
;; shell-command-switch to "-ic".
(defadvice compile (around use-bashrc activate)
"Load .bashrc in any calls to bash (e.g. so we can use aliases)"
(let ((shell-command-switch "-ic"))
ad-do-it))
You need to write similar "advice" for each function that you want to use .bashrc (e.g. I also needed to define the same advice for recompile), just copy the above and replace compile in the above with another function name.
You may like emac's bash-completion :
https://github.com/szermatt/emacs-bash-completion
You'll be able to use tab completion of your aliases in the compilation minibuffer and in shell-mode.
Enjoy !
(they speak about it here Bash autocompletion in Emacs shell-mode )
I think compilation commands are not interpreted through a shell: they are juste exec'ed by emacs (which means aliases, shell functions and other shell-specific things are not taken into account).
Try to wrap you compilation command into a shell-script which would source the correct environment.
You can do this either with a full-fledged shell-script in the form
#!/bin/bash
source "~/.bashrc"
my_command
or directly in emacs with a compilation command of the form
bash -c "source ~/.bashrc; my_command"
See Is there a way to get my emacs to recognize my bash aliases and custom functions when I run a shell command? for a fix which doesn't run all your .bashrc and doesn't create these error messages:
bash: cannot set terminal process group (-1): Inappropriate ioctl for device
bash: no job control in this shell

I want to run the cygwin bash shell from native windows emacs app

I have followed instructions from How can I run Cygwin Bash Shell from within Emacs? this question and I have gone further and added the (setq explicit-bash-args '("--login" "-i")) command, however emacs continues to only display the dos prompt when I type M-x shell. In summery my .emacs file looks like this:
(defun cygwin-shell ()
"Run cygwin bash in shell mode."
(interactive)
(let ((explicit-shell-file-name "C:/cygwin/bin/bash"))
(call-interactively 'shell)))
(setq explicit-bash-args '("--login" "-i"))`
Please be gentle with the answers as I am right at the bottom of the famous vertical emacs learning curve!
If you implemented the answer from that question, note that you have to do M-x cygwin-shell to start bash. If you want to use it for every M-x shell you need to call
(setq explicit-shell-file-name "C:/cygwin/bin/bash")
Since you stated that you are learning, here's a few tips when trying this out.
type C-x C-f ~/.emacs to open your .emacs file in your user path.
Enter your function above at the end
M-x load-file [RET] .emacs: loads the buffer (no need to restart emacs)
C-h a: If you are interested in some specific action, you can look it up
C-h v [RET] variable: can inspect the variable, check the value of explicit-bash-args for instance
And, btw, I'm not sure what the "--login -i" does, but someone stated in a comment that you should have that so "ls" would work. If you have your cygwin bin path in your PATH environment variable, bash will find ls anyway. No need to escape the path variable either, this is handled by bash (do an echo $PATH in bash when you get it working and you'll see).