Next: , Previous: , Up: Api   [Contents][Index]


5.7 KLECL

A box without hinges, key, or lid, yet golden treasure inside is hid.

The Hobbit – J. R. R. Tolkien

We finally have all the pieces to properly build the KLECL. First, we have to accept input.

Variable: event-queue
Variable: read-event-hook
Variable: emacsy-interactive?

With the command loop I’ve also adopted a prefix of [[primitive-]] which signifies that it does not do any error handling. The command loop sets up a fair amount of state.

Variable: this-command-event
Variable: last-command-event
Variable: pre-command-hook
Variable: post-command-hook
Variable: emacsy-ran-undefined-command?
Variable: command-loop-count

Each command loop is given a different number.

Scheme Procedure: emacsy-event event
Scheme Procedure: emacsy-key-event char #:optional (modifier-keys (quote ))

This is a convenience procedure to enqueue a key event.

Scheme Procedure: emacsy-mouse-event position button state #:optional (modifier-keys (quote ))
Scheme Procedure: emacsy-discard-input!

And mainly for testing purposes we also want to discard all input. Or there are cases where we want to unread an event and push it to the front of the queue rather than the rear.

Scheme Procedure: emacsy-event-unread event

[[read-event]] is the lowest-level procedure for grabbing events. It will block if there are no events to read.

Scheme Procedure: read-event #:optional (prompt #f)
Scheme Procedure: read-key #:optional (prompt #f)

read-key-sequence #:optional prompt #:key keymaps

Scheme Procedure: quit-key? aKey keymaps

We also check all the maps for a quit key, typically defined as C-g.

Scheme Procedure: default-klecl-maps
Scheme Procedure: message . args

I find it convenient to begin emitting messages in case of error. However, I would like for there to be a clean separation between Emacsy and its KLECL such that someone may write a clean vim-y using it if they so chose. So this message will merely go to the stdout\; however, it will be redefined later.

primitive-command-tick #:optional prompt #:key keymaps undefined-command XXX Rename this to klec, for Key-Lookup-Execute-Command (KLEC)—just missing the loop component?

Scheme Procedure: command-tick #:key (keymaps (default-klecl-maps))
Scheme Procedure: primitive-command-loop #:optional (continue-pred (const #t))

Now let’s write the command loop without any error handling. This seems a little messy with the continue predicate procedure being passed along. I’m not sure yet, how best to organize it.

Interactive Procedure: keyboard-quit

We have finished the KLECL. Note that although we have used Emacs-like function names, we have not implemented the Emacs-like UI yet. We have not defined any default key bindings. I want to encourage people to explore different user interfaces based on the KLECL, and one can start from this part of the code. If one wanted to create a modal UI, one could use the [[(emacsy klecl)]] module and not have to worry about any “pollution” of Emacs-isms.


Next: , Previous: , Up: Api   [Contents][Index]