Advanced Customization, How Does Xah Fly Keys Work
2022-01-14 xtodo work in progress. may be outdated.
Advanced Customization, How Does Xah Fly Keys Work
If you look at the file, in 10 minutes you should have a basic idea. The code is simple.
There's these 2 important variables:
- xah-fly-key-map
- Variable. Value is a elisp keymap. This keymap is used for command mode and insertion mode.
- xah-fly-leader-key-map
- Variable. Value is a elisp keymap. It's the leader keys sequence.
(note: in elisp, keymap is just a list of key/command pairs. The command part can be another keymap, in which case, it is a key sequence.)
There's these 2 important commands:
xah-fly-command-mode-init
- set keybinding for command mode. Basically, it just modify xah-fly-key-map.
xah-fly-insert-mode-init
-
set keybinding for insert mode. Basically, it just modify xah-fly-key-map, by setting all keys to nil (which means, do emacs default, usually means they do
self-insert-command
).
xah-fly-command-mode-init
looks like this:
(defun xah-fly-command-mode-init () (xah-fly--define-keys xah-fly-key-map '( ("a" . execute-extended-command) ("b" . isearch-forward) ("c" . previous-line) ;; more here )))
The
"a"
"b"
"c"
there are Dvorak keys.
The function
xah-fly--define-keys
takes care of translating Dvorak to QWERTY, if user has qwery set
(xah-fly-keys-set-layout 'qwerty)
.
xah-fly-insert-mode-init
looks like this:
(defun xah-fly-insert-mode-init () (xah-fly--define-keys xah-fly-key-map '( ("a" . nil) ("b" . nil) ("c" . nil) ;; more )))
xah-fly-leader-key-map looks like this:
(xah-fly--define-keys (define-prefix-command 'xah-fly-leader-key-map) '( ("a" . mark-whole-buffer) ("b" . end-of-buffer) ("c" . xah-fly-c-keymap) ("d" . beginning-of-buffer) ("e" . xah-fly-e-keymap) ("f" . xah-search-current-word) ;; more ))
For example, the line
("b" . end-of-buffer)
means
press leader b will call end-of-buffer
.
Note: All keys in the file are Dvorak keys. For example, if you see
("b" . isearch-forward)
, that's Dvorak b, and when user has QWERTY set, that b is automatically translated to n.