Last active
December 17, 2023 11:00
-
-
Save mmarshall540/70d4baf0b6a42a77aee44efe3283356b to your computer and use it in GitHub Desktop.
A simplistic modal editing system.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; This is based on a Dvorak keyboard layout and isn't | |
;; very comprehensive. The purpose is just to demonstrate | |
;; that you can create your own modal editing system in Emacs | |
;; using only a little bit of code. | |
;; | |
;; After loading this file, you can use "M-\" to enter command | |
;; mode (aka "normal-state"). | |
;; | |
;; To exit back to "insert-state", press "i". | |
(define-minor-mode simple-modal-mode | |
"A simple modal editing minor-mode." | |
:init-value nil | |
:lighter " Modal" | |
:keymap | |
`(([?{] . "\M-{") ;; backward-paragraph | |
([?}] . "\M-}") ;; forward-paragraph | |
([?\(] . "\M-a") ;; backward-sentence | |
([?\)] . "\M-e") ;; forward-sentence | |
([?\;] . "\M-\;") ;; comment-dwim | |
([?,] . "\M-<") ;; beginning-of-buffer | |
([?.] . "\M->") ;; end-of-buffer | |
([?y] . "\C-y") ;; yank | |
([?g] . "\M-b") ;; backward-word | |
([?G] . "\C-\M-b") ;; backward-sexp | |
([?c] . "\C-p") ;; previous-line | |
([?C] . "\C-\M-u") ;; backward-up-list | |
([?\M-C] . "\M-v") ;; Page up | |
([?r] . "\M-f") ;; forward-word | |
([?R] . "\C-\M-f") ;; forward-sexp | |
([?u] . "\C-xu") ;; undo | |
([?@] . "\M-^") ;; delete-indentation *dvp | |
([?a] . "\C-a") ;; move-beginning-of-line | |
([?A] . "\M-m") ;; back-to-indentation | |
([?o] . "\C-\M-o") ;; split-line | |
([?e] . "\C-e") ;; move-end-of-line | |
([?d] . "\C-d") ;; delete-char | |
([?D] . [backspace]) ;; delete-backward-char | |
([?h] . "\C-b") ;; backward-char | |
([?t] . "\C-n") ;; next-line | |
([?T] . "\C-\M-d") ;; down-list | |
([?\M-T] . "\C-v") ;; Page down | |
([?n] . "\C-f") ;; forward-char | |
([?s] . "\C-s") ;; isearch-forward | |
([?S] . "\C-r") ;; isearch-backward | |
([?-] . [?\C--]) ;; negative-argument | |
([?q] . "\C-q") ;; quoted-insert | |
([?k] . "\C-k") ;; kill-line | |
([?w] . "\C-w") ;; kill-region | |
([?1] . digit-argument) | |
([?2] . digit-argument) | |
([?3] . digit-argument) | |
([?4] . digit-argument) | |
([?5] . digit-argument) | |
([?6] . digit-argument) | |
([?7] . digit-argument) | |
([?8] . digit-argument) | |
([?9] . digit-argument) | |
([?0] . digit-argument) | |
([?i] . simple-modal-mode-stop))) ;; switch to non-modal state | |
(defun simple-modal-mode-start () | |
"Enable `simple-modal-mode'." | |
(interactive) | |
(simple-modal-mode 1)) | |
(defun simple-modal-mode-stop () | |
"Disable `simple-modal-mode'." | |
(interactive) | |
(simple-modal-mode -1)) | |
(global-set-key "\M-\\" 'simple-modal-mode-start) | |
(provide 'simple-modal) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment