;;; -*- Mode: Scheme -*- (define (ed-def . args) "(ed-def &optional NAME KEEP? USE-EXISTING?)" (letrec ((y-or-n (lambda (prompt) (let ((ans (readline (string-append prompt " [y/N]")))) (or (equal? ans "y") (equal? ans "Y")))))) (let* ((name (or (and (> (length args) 0) (car args)) (let ((nm (readline "File Name: "))) (if (string-null? nm) (tmpnam) (begin (add-history nm) nm))))) (keep? (or (and (> (length args) 1) (cadr args)) (y-or-n "Keep file when done?"))) (use? (and (file-exists? name) (or (and (> (length args) 2) (caddr args)) (y-or-n "Use existing file?")))) (p '()) (ed (or (getenv "XEDITOR") (getenv "EDITOR") (getenv "VISUAL") (and (file-exists? "/usr/bin/editor") "editor") (and (or (file-exists? "/bin/vi") (file-exists? "/usr/bin/vi")) "vi") (error "None of XEDITOR, EDITOR, nor VISUAL are set.")))) (and (not use?) (set! p (open-file name "w")) (display ";;; -*- scheme -*-\n" p) (close-port p)) (system (string-append "$EDITOR " name)) (load name) (if (not keep?) (system (string-append "rm -f " name))) #t)))