Hi,
I've made a little patch (attached) to src/edwin/editor.scm that, when
combined with the shell script and Scheme code below, lets me open
Edwin directly on a file from the terminal like so:
$ edwin file.txt
... (new Edwin opens with file.txt loaded)
I'm not submitting this patch for inclusion as it is, it's not very
nice; instead I have questions:
* Is there a way to open Edwin directly on a file without doing this?
* If there currently isn't an official way to do this, I'd appreciate
any comments on how to do this in a less roundabout way so that it
could be submitted for the ``official'' Edwin.
* This starts a new Scheme/Edwin every time, which is OK but sort of
uncool. Is there a way to send a message to a currently running
Edwin to open the file in a new frame or buffer?
Here's the shell script:
#!/bin/bash
EDIT_FILE=$1
CODE_DIR=$HOME/Code/mathoms
SCHEME_FILE=$CODE_DIR/edit-file.scm
/Users/rloveland/bin/scheme --args $EDIT_FILE --load $SCHEME_FILE
And the `edit-file.scm' loaded by Scheme above is:
(load-option 'FORMAT)
(define (build-plausible-filename candidate)
(let ((longname (string-append (->namestring (pwd)) candidate)))
(cond
((file-exists? longname) longname)
((file-exists? candidate) candidate)
(else #f))))
(define (edit-file)
(let* ((args (command-line))
(maybe-file (car args)) ; (list-tail args (- (length args) 1))))
(file (build-plausible-filename maybe-file)))
(format #t "~%;Editing ~A~%" file)
(edit file)))
(edit-file)
Thanks!
Rich
diff --git a/src/edwin/editor.scm b/src/edwin/editor.scm
index 5d23827..933e22d 100644
--- a/src/edwin/editor.scm
+++ b/src/edwin/editor.scm
@@ -28,13 +28,13 @@ USA.
(declare (usual-integrations))
-(define (edit . args)
+(define (edit file . args)
(call-with-current-continuation
(lambda (continuation)
(cond (within-editor?
(error "edwin: Editor already running"))
((not edwin-editor)
- (apply create-editor args))
+ (apply create-editor file args))
((not (null? args))
(error "edwin: Arguments ignored when re-entering editor" args))
(edwin-continuation
@@ -112,13 +112,16 @@ USA.
(define create-editor-args
'())
-(define (create-editor . args)
+(define (create-editor file . args)
(let ((args
(if (null? args)
create-editor-args
(begin
(set! create-editor-args args)
- args))))
+ args)))
+ (filename (if (file-exists? file)
+ file
+ #f)))
(reset-editor)
(event-distributor/invoke! editor-initializations)
(set! edwin-editor
@@ -137,9 +140,11 @@ USA.
(set! edwin-initialization
(lambda ()
(set! edwin-initialization #f)
- (standard-editor-initialization)))
+ (if filename
+ (standard-editor-initialization filename)
+ (standard-editor-initialization))
(set! edwin-continuation #f)
- unspecific))
+ unspecific))))
(define editor-initializations
(make-event-distributor))
@@ -165,7 +170,7 @@ USA.
(find-preferred preferences))
-(define (standard-editor-initialization)
+(define (standard-editor-initialization #!optional filename)
(with-editor-interrupts-disabled
(lambda ()
(if (and (not init-file-loaded?)
@@ -176,7 +181,10 @@ USA.
(load-edwin-file filename '(EDWIN) #t)))
(set! init-file-loaded? #t)
unspecific))))
- (let ((buffer (find-buffer initial-buffer-name)))
+ (let ((buffer (find-buffer initial-buffer-name))
+ (filename (if (not (default-object? filename))
+ ((ref-command find-file) filename)
+ #f)))
(if (and buffer
(not inhibit-initial-inferior-repl?))
(start-inferior-repl!
_______________________________________________
MIT-Scheme-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/mit-scheme-devel