On 20/06/2015 14:54, Neil Jerram wrote:
Michael Tiedtke <michele.ti...@o2online.de> writes:
Just to quote myself:
The (null-environment 5) gives me an empty environment but how
should I insert the editor commands?
Just think of these editor commands as regular Scheme definitions.
I think you're looking for 'module-define!':
scheme@(guile-user)> (define n (null-environment 5))
scheme@(guile-user)> (eval 'car n)
ERROR: In procedure memoize-variable-access!:
ERROR: Unbound variable: car
Entering a new prompt. Type `,bt' for a backtrace or `,q' to continue.
scheme@(#{ g3900}#) [1]> ,q
scheme@(guile-user)> (eval 'car (current-module))
$2 = #<procedure car (_)>
scheme@(guile-user)> (module-define! n 'car car)
scheme@(guile-user)> (eval 'car n)
$3 = #<procedure car (_)>
Hope that helps!
Neil
Y E S, yes yes yes yes! Exactly that! THANK YOU! Why didn't they put it
in the documentation for 1.8?? Yes, finally I can force my editor users
to use my stripped down editor language and not just use /open/ on a
file on the internal command line to /load-file/. But I could change RED
(read eval display) to open port objects in editor buffers just to see
it wait for a device file or socket ... well, let's see ...
;; DEFUNCT
;; nUI0c - last test case
;;
(use-modules (oop goops)
(pretext)
(terminal)
(buffer)
(buffer-view)
(command-line-environment))
(define (switch-mode mode)
(set! current-event-dispatcher mode))
(define (command-mode key-code)
(case key-code
((#\:) (cursor-home terminal) (display ":")
(switch-mode command-line-mode))
((#\i) (switch-mode insert-mode))
((#\k up) (cursor-up terminal))
((#\j down) (cursor-down terminal))
((#\l right) (cursor-forward terminal))
((#\h left) (cursor-backward terminal))))
(define command-line-buffer '())
(define key-code-enter #\newline)
(define (command-line-mode key-code)
(display key-code)
(case key-code
((#\cr) (command-line-execute))
((#\esc) (set! command-line-buffer '())
(switch-mode command-mode))
(else
(set! command-line-buffer
(cons key-code command-line-buffer)))))
(define (command-line-execute)
(define (R-E-D command-string)
(display (eval-command-line (read-string command-string)
my-command-interface)))
(define (read-string string)
(call-with-input-string string read))
(let ((command (list->string
(reverse! command-line-buffer))))
(set! command (string-append "(" command ")"))
(cursor-home terminal)
(my-debug " Command: " command " END COMMAND ")
(cursor-home terminal)
(catch #t
(lambda () (R-E-D command))
(lambda (key . args)
(apply throw key args))
;; (if (eq? 'quit key)
;; (throw key)
;; (switch-mode command-mode)))
(lambda (key . args)
(if (not (eq? 'quit key))
(backtrace))))
(set! command-line-buffer '())))
;;
;; Events, Jumps and other Party Functions
(define (my-command-interface what . args)
(case what
((exit) (clean-exit))
((open) (open-file (car args)))))
(define buffer-view (make <buffer-view> #:terminal terminal))
(define (open-file path)
(let* ((buffer (load-file path))
(view (make <buffer-view> #:buffer buffer
#:terminal terminal)))
(set! buffer-view view)
(refresh view)))
(define (clean-exit)
(tty-sane-mode my-port)
(quit))
;(primitive-exit))
(define current-event-dispatcher command-mode)
(define (event-dispatcher key-code)
(current-event-dispatcher key-code))
(define (the-pre-final-handler key . args)
(tty-sane-mode my-port)
(backtrace))
(define (the-final-handler key . args)
(display " Oh dear, we're gone! ")
(for-each display args)
(newline))
;;
;; This would have been music on Telex
(define my-port (fdopen (port->fdes (current-output-port)) "r+0b"))
(define terminal (make <terminal> #:port my-port))
(full-reset terminal)
(tty-raw-mode my-port)
(cursor-home terminal)
;;
;; Catch all or ketcHUP
(catch #t (lambda ()
(start-event-loop terminal event-dispatcher))
the-final-handler
the-pre-final-handler)