How to start Racket with xrepl? - racket

I very often open Racket in bash shell, however in order for it to support xrepl, I need to execute (require xrepl) command first.
Is there any way to start racket and execute command above automatically?

See Installing XREPL, especially the part I bolded below:
To use XREPL, start racket and enter (require xrepl). You will know that it works when the prompt changes to a ->, and, if you’re working on a capable terminal, you will now have readline editing. You can also start racket and ask for XREPL to be loaded using command-line arguments:
racket -il xrepl
If you want to enable XREPL automatically, add this expression to your Racket initialization file. An easy way to do the necessary editing is to enter ,install!, which will inspect and edit your initialization file (it will describe the change and ask for your permission). Alternatively, you can edit the file directly: on Unix, it is ~/.racketrc, and for other platforms evaluate (find-system-path 'init-file) to see where it is.

Related

Run emacs command in terminal

I'm using Emacs Muse for work reasons and I don't really enjoy editing my .muse files in emacs.
I haven't found alternatives to publishing .muse files in another editor.
Is it possible to run Emacs commands from outside Emacs almost as if using it as a sort of interpreter?
I want to be able to go to the terminal and run something like:
> emacs -ne file_with_command file_to_publish.muse
The command in question is M-x muse-project-publish-this-file
edit: In Emacs, this command also has inputs that it prompts me to give one at a time. It's the style of publishing (html in my case) and the directory where the publication will go to.
muse-project-publish-this-file is not design to use in batch mode.Use muse-publish-file instead.
First,
git clone https://github.com/jwiegley/muse /path/to/muse
Then create script.el with content
(add-to-list 'load-path "/path/to/muse/lisp")
(require 'muse-publish)
(muse-publish-file "file_to_publish.muse" (muse-define-style "newstyle" nil) "/path/to/publish/directory")
notice is /muse/lisp not muse.
Last, emacs --batch -l script.el

How to configure the Racket interpreter to support command history?

I've just set up Racket and have been trying out the interpreter.
However, I can't seem to go up and down the command history using the arrows (or Ctrlp/Ctrln for that matter) or use Ctrlr to search through it.
Is that even supported? Can I build it with that feature in?
Coming from a Python background I'm very used to these features and would like to have them available for Racket too.
DrRacket IDE
In the Racket IDE you can hold CTRL with arrow keys to get to previously written statements in the interactions window.
Racket in terminal
eXtended REPL
Extended REPL gives read-line features like using arrows to go back in history as well as you can search with CTRL+r. It has in addition REPL-commands like ,apropos. By entering ,help you get a list of commands you can use or you can consult the documentation. To use it you can:
enter (require xrepl) to activate it
run racket with racket -il xrepl
install it once and for all from xrepl by evaluating ,install!
Standard readline
You have normal readline which you can activate by:
enter (require readline/rep) to activate it
run racket with racket -il readline
install in once and for all by evaluating (install-readline!).

Cross compile on Emacs

How do I create/issue compilation command on Emacs, so I don't need to switch back and forth between it and console? My usual compilation procedure I'd like to see as Emacs command:
$ export PATH=/toolchain/gcc-linaro-arm-linux-gnueabihf-4.7/bin:$PATH
$ cd my/project
$ make CROSS_COMPILE=arm-linux-gnueabihf- all
I tried to make my own version of M-x compile command following instructions, but failed as I'm not familiar with Lisp and Emacs internals enough. Please note, that projects in question are big (i.e. kernel) with multi directories and Makefiles, so the approaches (closest Makefile, default directory etc.) described in the previous link are not a solution. Bonus points if you could bind it to a single key, like Fx key on modern IDEs.
P.S. I'm aware that there's similar question, but it's outdated and doesn't cover cross compile issue, I hope there's a better solution nowadays.
You can create a custom function that runs a specific compile command in a specific directory, like this:
(defun my-compile ()
(interactive)
(let ((default-directory "~/my/project"))
(compile "export PATH=/toolchain/gcc-linaro-arm-linux-gnueabihf-4.7/bin:$PATH && make CROSS_COMPILE=arm-linux-gnueabihf- all")))
And then bind it to some convenient key:
(global-set-key [f12] 'my-compile)
Ctrl U Meta x compile should ask you what compilation command to use. You could type make CROSS_COMPILE=arm-linux-gnueabi all
Otherwise, configure your compilation-command Emacs variable, perhaps in your ~/.emacs; and you might make that a file-local variable.
You could put in your ~/.emacs the following untested lines
(load-library "compile")
(global-set-key [f12] 'recompile)
(setq compilation-command "make CROSS_COMPILE=arm-linux-gnueabihf all")
BTW, your export PATH=... could be added e.g. in your ~/.bashrc, or you could have a shell script running that exact make with the appropriate PATH and have that script be your Emacs compilation-command (perhaps even "temporarily", i.e. just in your emacs session)

How can I reload and re-enter a modified Racket file in Geiser?

I'm using Geiser in Emacs on Windows as a Racket programming environment. I'm working on the file "d:/code/racket/foo.rkt". "d:/code/racket/foo.rkt" is a module (it starts with #lang racket).
I can use ,enter "d:/code/racket/foo.rkt" at the Racket REPL to enter the module, and having done so I can successfully execute functions from the file.
However, if I change the file and re-run ,enter "d:/code/racket/foo.rkt", the file is not re-loaded: changes to functions in my file are not reflected when I re-execute them in the REPL.
I have tried re-compiling my buffer with C-c C-k before re-running ,enter, but this makes no difference.
I've also tried executing ,enter #f to exit the foo.rkt module, then re-running ,enter "d:/code/racket/foo.rkt"; this still doesn't reload the module.
I've also observed that running (enter! (file "d:/code/racket/foo.rkt")) instead of ,enter "d:/code/racket/foo.rkt" does reload the file.
Is this a known limitation of Geiser's ,enter form, or am I missing a trick?
(Versions are: Geiser 0.5, Emacs 24.3.1, Racket 6.0, Windows 8)

how to save keyboard operation time in compiling with emacs for erlang?

When using emacs for writing erlang source code, I have made the following configuration.
In the emacs, 6 windows are open at the same time, 4 windows for source code writing, 1 windows for terminal shell, 1 windows for erlang shell.
After one source code modification, I have use command "m-x ter" to switch "terminal shell", then using "m-p" for recovering last history command, then pressing "enter" to run.
Then using "c-x, left " to switch to erlang shell, then press m-p to repeat last command.
The above two switch process seems a little long, could you have better solution?
The compile function is the general mechanism for such things, and the compile-command variable tells it what to do (as a shell command to run).
By default, the command is make, so if you have a Makefile, you're already sorted.
If not, and writing one isn't appropriate, then you can customise compile-command for your files, perhaps using local variables.
File-local variables for this purpose are covered in the linked Q&A.
You can also use Directory-local variables if you want it to automatically apply to all files under a given directory.
Or if there's a general pattern which can be applied to all erlang files, everywhere, then you might set up compile-command using the erlang mode hook.
Finally, you can just supply the command on demand. Called interactively, M-x compile prompts you for the command to run, and uses the previous command as the default for the next time.