How to run DrRacket program from command line? - lisp

I have the following program which I normally run from within DrRacket:
; 1.scm
#lang sicp
(display "hello\n")
(+ 1 1)
Is there a way to run the file directly as an executable, something like /path/to/racket/binary 1.scm ? If so, where can I find the binary for racket (I'm on Mac).

You should be able to find the executable path here, and for Mac it would be:
On Mac OS...It is probably in a Racket folder that you dragged into your Applications folder. If you want to use command-line tools, instead, Racket executables are in the "bin" directory of the Racket folder (and if you want to set your PATH environment variable, you’ll need to do that manually).
And to run it I could use the racket binary:
$ '/Applications/Racket v8.0/bin/racket' ~/Desktop/sicp/1.scm

Related

How to start Racket with xrepl?

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.

emacs compile-command find makefile in superior directory

This seems like such an obvious hack I hate to write it myself, but I've had no luck finding it.
I would like an approach to M-x compile that will search upward in the directory tree from cwd to the first directory with a Makefile, after which it runs the make command. So, it's basically
if ./Makefile exists, run the make command
otherwise, cd .. and try again
Stop at $HOME.
The following code defines compile-parent, which locates the nearest Makefile and creates a make command to use that Makefile. It behaves like compile in that it still prompts, showing you the command that it will use, and giving you a chance to edit it, e.g. by specifying a specific target.
(defun compile-parent (command)
(interactive
(let* ((make-directory (locate-dominating-file (buffer-file-name)
"Makefile"))
(command (concat "make -k -C "
(shell-quote-argument make-directory))))
(list (compilation-read-command command))))
(compile command))
You may also want to look at the Projectile extension, which provides a minor mode to detect projects by the presence of VCS metadata or specific build files, with several commands to work from the project root directory, including a projectile-compile command, that runs M-x compile from the project root.

Independent emacs installations and locations of the .emacs.d directory and the .emacs file

I have multiple installations of emacs on my Windows 7 computer, each configured slightly differently. Let's say installation1 and installation2, where installation1 is the main emacs, and installation2 is subsidiary.
I would like to maintain two sets of .emacs files and .emacs.d. directories, such that installation1 looks for it in the default HOME or %appdata% directory (C-x C-f ~/.emacs RET), but that installation2 cannot find the .emacs file in these directories at all. That is, I would like installation2 to not look in the HOME or %appdata% locations for the .emacs.d directory or .emacs file. Ideally, this would be implemented by redefining the ~ expansion for installation2.
I guess I could have a (add-to-list 'load-path "C:/installation2-location/.emacs.d/lisp/") and save it to a .emacs file in the same directory as the installation2 emacs executable, but I am not sure that this is a robust solution.
Suggestions welcome.
Well you can use the system-type variable. From the Emacs help
system-type is a variable defined in `C source code'. Its value is
darwin
Documentation: The value is a symbol indicating the type of operating
system you are using. Special values: gnu' compiled for a
GNU Hurd system.gnu/linux' compiled for a GNU/Linux system.
gnu/kfreebsd' compiled for a GNU system with a FreeBSD kernel.
darwin' compiled for Darwin (GNU-Darwin, Mac OS X, ...).
ms-dos' compiled as an MS-DOS application.windows-nt'
compiled as a native W32 application. `cygwin' compiled using
the Cygwin library. Anything else (in Emacs 24.1, the possibilities
are: aix, berkeley-unix, hpux, irix, usg-unix-v) indicates some sort
of Unix system.
Or use system-name to determine discriminate between machines of the same of.
Finally you can make a function to load what you want in installation-1 and another to load what you want in installation-2. But I can't see any valid reason as to why you would want to maintain different emacs.d in the same machine.

Setting Racket Geiser Emacs Path

I'm trying to get Geiser's REPL to work in Emacs, but it doesn't seem to be able to find Racket.
racket is on my path, but anytime I type
run-geiser
followed by
racket
it complains:
Unable to start REPL: Searching for program: no such file or directory, racket
I read in the Geiser docs that I may have to manually tell Geiser where to find racket, but I can't tell where to configure this property of Geiser.
Thanks for your help.
Ok, so I added:
(setq geiser-racket-binary "/home/user/racket/bin/racket")
to my .emacs file after loading geiser.el.
I was expecting a configuration file somewhere to set this.
Thanks.
I know this is an old question, but for future people having a hard time getting it to find the Racket executable despite it being in your path, you can simply use the executable-find function.
This searches your path and returns the absolute path to the executable, which is what the geiser-racket-binary function wants. So this is an alternative to explicitly setting the absolute path:
(setq geiser-racket-binary (executable-find "Racket"))
In Windows, adding the location of the Racket executable to the "path" environment variable which is part of Windows will allow Geiser/Emacs to find the Racket Executable.

Platform-independent path (in LaTex and Elisp)?

I run Emacs on Win7 and Ubuntu and try to share most of my configuration via dropbox.com. I still could not figure out how to write the path to load-files or images (for example) in a platform independent way.
I mirrored my directory structure on both machines so that inside the home directory the relative path should work out. Is there a way to achieve this with a single path without if-clauses (if system ... else ...) everywhere?
I tried ~/ and it worked sometimes, sometimes not.
'home' is set on Win7, but it must be addressed as %home% on Win7 and as $HOME on ubuntu (right?).
I need a solution for:
elisp code
latex files (adress images, listings)
In Windows, ~ resolves to whatever the HOME environment variable is set to. I found it most useful to set HOME to C:\Users\username (in Win 7). This means I can put my .emacs file there, and also that ~ will reference files in it when I'm opening files.
Once you do this, your elisp can refer to ~ as your home directory on either Windows or Linux.
I have a setting at the top of my .emacs the tests the OS, and sets a CONST pointing to the the root directory of the path accordingly. Then, within the configurations, I just reference the variable within my path statements. Just tested on OS X and Windows 7.
Here's some examples:
(defconst HOME_DIR
(if (eq system-type 'darwin)
(concat "/Users/" (getenv "USER"))
(concat "c:/cygwin/home/" (getenv "USER")))
"Home directory. I could rely on the HOME environment variable,
but I'm being retentive.")
(defconst EMACS_PKGS (concat HOME_DIR "/emacs-pkgs")
"Directory for the emacs pkgs and configuration files.
Default uses `HOME_DIR' as a prefix")
;; isolate customize settings
(setq custom-file (concat EMACS_PKGS "/emacs-custom.el"))
My experience with Emacs on Windows is that ~ is not at C:\Users\yourusername. For me, it's in C:\Users\rafe\AppData\Roaming. So, for the case of Emacs, if you drop files in, say, %HOME%\AppData\Roaming (or, in Windows Emacs, ~), you'll have access to those files. That's where my .emacs was by default, at least. The path might be different on your system, so see where Emacs takes you when you try to find a file and type ~/.
That setting might be configurable, but I've never cared enough to change it.
As for LaTeX, sadly I can't help.
For LaTeX, see: “How to add an extra searchable dir with personal style files to TeXLive, NOT under ~/Library/texmf?” on the TeX SE. It might help.