aboutsummaryrefslogtreecommitdiff
path: root/editors
diff options
context:
space:
mode:
authorMarshall Lochbaum <mwlochbaum@gmail.com>2021-02-11 21:25:33 -0500
committerMarshall Lochbaum <mwlochbaum@gmail.com>2021-02-11 21:25:33 -0500
commit13def93bc1de46a840961985115ce01429f13986 (patch)
tree3741899b7b01b2dc906e691aa9c24f8bcfa86dce /editors
parentf998b922f160ee835bb5d51a412c2c11e27f6e85 (diff)
Separate prefixed input from main file
Diffstat (limited to 'editors')
-rw-r--r--editors/emacs/bqn-backslash.el50
-rw-r--r--editors/emacs/bqn-input.el92
-rw-r--r--editors/emacs/bqn-mode.el71
3 files changed, 104 insertions, 109 deletions
diff --git a/editors/emacs/bqn-backslash.el b/editors/emacs/bqn-backslash.el
new file mode 100644
index 00000000..a667faff
--- /dev/null
+++ b/editors/emacs/bqn-backslash.el
@@ -0,0 +1,50 @@
+;;; -*- lexical-binding: t -*-
+
+(require 'cl-lib)
+(require 'quail)
+(require 'bqn-symbols)
+
+(quail-define-package "BQN-Z" "UTF-8" "⍉" t
+ "Input mode for BQN"
+ '(("\t" . quail-completion))
+ t ; forget-last-selection
+ nil ; deterministic
+ nil ; kbd-translate
+ t ; show-layout
+ nil ; create-decode-map
+ nil ; maximum-shortest
+ nil ; overlay-plist
+ nil ; update-translation-function
+ nil ; conversion-keys
+ t ; simple
+ )
+
+(defvar bqn--transcription-alist)
+(defun bqn--update-key-prefix (symbol new)
+ (quail-select-package "BQN-Z")
+ (quail-install-map
+ (let* ((prefix (string new))
+ (bqn--transcription-alist
+ (cl-loop for command in bqn--symbols
+ for key-command = (cl-third command)
+ append (cl-loop for s in (if (listp key-command)
+ key-command
+ (list key-command))
+ collect (cons (concat prefix s)
+ (cl-second command))))))
+ (quail-map-from-table
+ '((default bqn--transcription-alist)))))
+ (set-default symbol new))
+
+(defun bqn--initialize-key-prefix (symbol new)
+ (custom-initialize-default symbol new)
+ (bqn--update-key-prefix symbol (eval new)))
+
+(defcustom bqn-key-prefix ?\\
+ "Set a character to serve as prefix key for BQN symbol input."
+ :type 'character
+ :group 'bqn
+ :initialize #'bqn--initialize-key-prefix
+ :set #'bqn--update-key-prefix)
+
+(provide 'bqn-backslash)
diff --git a/editors/emacs/bqn-input.el b/editors/emacs/bqn-input.el
index 4dd72bd5..2ad842c5 100644
--- a/editors/emacs/bqn-input.el
+++ b/editors/emacs/bqn-input.el
@@ -1,50 +1,58 @@
;;; -*- lexical-binding: t -*-
(require 'cl-lib)
-(require 'quail)
(require 'bqn-symbols)
-(quail-define-package "BQN-Z" "UTF-8" "⍉" t
- "Input mode for BQN"
- '(("\t" . quail-completion))
- t ; forget-last-selection
- nil ; deterministic
- nil ; kbd-translate
- t ; show-layout
- nil ; create-decode-map
- nil ; maximum-shortest
- nil ; overlay-plist
- nil ; update-translation-function
- nil ; conversion-keys
- t ; simple
- )
-
-(defvar bqn--transcription-alist)
-(defun bqn--update-key-prefix (symbol new)
- (quail-select-package "BQN-Z")
- (quail-install-map
- (let* ((prefix (string new))
- (bqn--transcription-alist
- (cl-loop for command in bqn--symbols
- for key-command = (cl-third command)
- append (cl-loop for s in (if (listp key-command)
- key-command
- (list key-command))
- collect (cons (concat prefix s)
- (cl-second command))))))
- (quail-map-from-table
- '((default bqn--transcription-alist)))))
- (set-default symbol new))
-
-(defun bqn--initialize-key-prefix (symbol new)
- (custom-initialize-default symbol new)
- (bqn--update-key-prefix symbol (eval new)))
-
-(defcustom bqn-key-prefix ?\\
- "Set a character to serve as prefix key for BQN symbol input."
- :type 'character
+(defun bqn--make-key-command-sym (n)
+ (intern (concat "insert-sym-bqn-" n)))
+
+(cl-macrolet ((make-insert-functions ()
+ `(progn
+ ,@(mapcar #'(lambda (command)
+ `(defun ,(bqn--make-key-command-sym (car command)) ()
+ (interactive)
+ (insert ,(cadr command))))
+ bqn--symbols))))
+ (make-insert-functions))
+
+(defun bqn-insert-spc ()
+ "Insert a space. This is needed so that one can type a space
+character when using the super-prefixed characters."
+ (interactive)
+ (insert " "))
+
+(defun bqn--kbd (definition)
+ (if (functionp #'kbd)
+ (kbd definition)
+ (eval `(kbd ,definition))))
+
+(defun bqn--make-base-mode-map (prefix)
+ (let ((map (make-sparse-keymap)))
+ (dolist (command bqn--symbols)
+ (let ((key-sequence (caddr command)))
+ (dolist (s (if (listp key-sequence) key-sequence (list key-sequence)))
+ (define-key map (bqn--kbd (concat prefix s)) (bqn--make-key-command-sym (car command))))))
+ (define-key map (kbd (concat prefix "SPC")) 'bqn-insert-spc)
+ (define-key map [menu-bar bqn] (cons "BQN" (make-sparse-keymap "BQN")))
+ map))
+
+(defun bqn--make-bqn-mode-map ()
+ (bqn--make-base-mode-map bqn-mode-map-prefix))
+
+(defun bqn--set-mode-map-prefix (symbol new)
+ "Recreate the prefix and the keymap."
+ (set-default symbol new)
+ (setq bqn--mode-map (bqn--make-bqn-mode-map)))
+
+(defcustom bqn-mode-map-prefix "s-"
+ "The keymap prefix for ‘bqn--mode-map’ used both to store the new value
+using ‘set-create’ and to update ‘bqn--mode-map’ using
+ `bqn--make-bqn-mode-map'. Kill and re-start your BQN buffers to reflect the change."
+ :type 'string
:group 'bqn
- :initialize #'bqn--initialize-key-prefix
- :set #'bqn--update-key-prefix)
+ :set 'bqn--set-mode-map-prefix)
+
+(defvar bqn--mode-map (bqn--make-bqn-mode-map)
+ "The keymap for ‘bqn-mode’.")
(provide 'bqn-input)
diff --git a/editors/emacs/bqn-mode.el b/editors/emacs/bqn-mode.el
index fa4dc654..c12fc1b7 100644
--- a/editors/emacs/bqn-mode.el
+++ b/editors/emacs/bqn-mode.el
@@ -11,6 +11,9 @@
;;;
;;; Code:
+(require 'bqn-input)
+(require 'bqn-backslash)
+(require 'bqn-syntax)
;;;###autoload
(defgroup bqn nil
@@ -18,78 +21,12 @@
:prefix 'bqn
:group 'languages)
-;;;
-;;; Keymap functions
-;;;
-
-(require 'cl-lib)
-(require 'bqn-symbols)
-
-(defun bqn--make-key-command-sym (n)
- (intern (concat "insert-sym-bqn-" n)))
-
-(cl-macrolet ((make-insert-functions ()
- `(progn
- ,@(mapcar #'(lambda (command)
- `(defun ,(bqn--make-key-command-sym (car command)) ()
- (interactive)
- (insert ,(cadr command))))
- bqn--symbols))))
- (make-insert-functions))
-
-(defun bqn-insert-spc ()
- "Insert a space. This is needed so that one can type a space
-character when using the super-prefixed characters."
- (interactive)
- (insert " "))
-
-(defun bqn--kbd (definition)
- (if (functionp #'kbd)
- (kbd definition)
- (eval `(kbd ,definition))))
-
-(defun bqn--make-base-mode-map (prefix)
- (let ((map (make-sparse-keymap)))
- (dolist (command bqn--symbols)
- (let ((key-sequence (caddr command)))
- (dolist (s (if (listp key-sequence) key-sequence (list key-sequence)))
- (define-key map (bqn--kbd (concat prefix s)) (bqn--make-key-command-sym (car command))))))
- (define-key map (kbd (concat prefix "SPC")) 'bqn-insert-spc)
- (define-key map [menu-bar bqn] (cons "BQN" (make-sparse-keymap "BQN")))
- map))
-
-(defun bqn--make-bqn-mode-map ()
- (bqn--make-base-mode-map bqn-mode-map-prefix))
-
-(defun bqn--set-mode-map-prefix (symbol new)
- "Recreate the prefix and the keymap."
- (set-default symbol new)
- (setq bqn-mode-map (bqn--make-bqn-mode-map)))
-
-(defcustom bqn-mode-map-prefix "s-"
- "The keymap prefix for ‘bqn-mode-map’ used both to store the new value
-using ‘set-create’ and to update ‘bqn-mode-map’ using
- `bqn--make-bqn-mode-map'. Kill and re-start your BQN buffers to reflect the change."
- :type 'string
- :group 'bqn
- :set 'bqn--set-mode-map-prefix)
-
-(defvar bqn-mode-map (bqn--make-bqn-mode-map)
- "The keymap for ‘bqn-mode’.")
-
-;;;
-;;; Define the mode
-;;;
-
-(require 'bqn-input)
-(require 'bqn-syntax)
-
;;;###autoload
(define-derived-mode bqn-mode prog-mode "BQN"
"Major mode for editing BQN files."
:syntax-table bqn--syntax-table
:group 'bqn
- (use-local-map bqn-mode-map)
+ (use-local-map bqn--mode-map)
(setq-local font-lock-defaults bqn--token-syntax-types)
)