How to open a file in Edwin from the command line
The Edwin text editor that comes with MIT Scheme has no direct way for the user to provide the name of the file to open via a command line argument. This stands in stark contrast with other text editors, such as Emacs, where such a convenience is the norm (e.g.
emacs myfile.txt). In this article, I will show two methods of specifying a filename on the command line when starting Edwin.
Method 1: environment variable
This method uses an environment variable
EDWIN_OPEN_FILE that specifies the name of the file to open. First, add the following to your Edwin configuration file (
~/.edwin on UNIX-like systems):
(let ((filename (get-environment-variable "EDWIN_OPEN_FILE"))) (when (and filename (not (string=? filename ""))) (set-environment-variable! "EDWIN_OPEN_FILE" #f) ; Optional: unset environment variable. (find-file filename)))
Then, to open a file directly from the command line, specify that environment variable when starting Edwin from the command line:
EDWIN_OPEN_FILE='/path/to/my/file' mit-scheme --eval "(edwin 'console)"
Method 2: command line arguments
This method looks at the command line arguments passed to MIT Scheme. However, this method only works in MIT Scheme 9.2 or later, because it depends on MIT Scheme's
--args command line option, which was added in MIT Scheme 9.2. For MIT Scheme 9.2 only, add this to your Edwin configuration file:
(let (args (command-line)) (when (and (not (null? args)) (not (string=? (car args) ""))) (find-file (car args))))
For MIT Scheme 10.1.1 or later, add this to your Edwin configuration file instead:
(let ((args (command-line-arguments))) (when (and (not (null? args)) (not (string=? (car args) ""))) (find-file (car args))))
Why the difference between MIT Scheme 9.2 and the later versions? It's because the
command-line procedure was renamed to
command-line-arguments from MIT Scheme 10.1.1 onwards to avoid a conflict with R7RS-small's
Then, to directly open a file from the command line:
mit-scheme --eval "(edwin 'console)" --args "/path/to/my/file"
For convenience, you could probably wrap that in a shell script named "edwin":
#!/bin/sh mit-scheme --eval "(edwin 'console)" --args "$1"