unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Michael Tiedtke <michele.titke@o2online.de>
To: guile-user@gnu.org
Subject: Re: How to create hygienic environments?
Date: Sat, 20 Jun 2015 15:16:34 +0200	[thread overview]
Message-ID: <558567B2.4090303@o2online.de> (raw)
In-Reply-To: <87ioaia6bs.fsf@ossau.homelinux.net>

[-- Attachment #1: Type: text/plain, Size: 4470 bytes --]



On 20/06/2015 14:54, Neil Jerram wrote:
> Michael Tiedtke <michele.titke@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)


[-- Attachment #2: Type: text/html, Size: 6115 bytes --]

      reply	other threads:[~2015-06-20 13:16 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-19 14:39 How to create hygienic environments? Michael Tiedtke
2015-06-19 22:08 ` Matt Wette
2015-06-20  4:54   ` Michael Tiedtke
2015-06-20 12:54     ` Neil Jerram
2015-06-20 13:16       ` Michael Tiedtke [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=558567B2.4090303@o2online.de \
    --to=michele.titke@o2online.de \
    --cc=guile-user@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).