From f7a5713c301bc90a66108a233344d3fab449c1b1 Mon Sep 17 00:00:00 2001 From: Anderson Torres Date: Sun, 5 Mar 2023 19:53:19 -0300 Subject: [PATCH] [task] bqn-mode-map.el: improvements As taken from https://github.com/museoa/bqn-mode/pull/22 --- bqn-mode-map.el | 42 +++++++++++++++++------------------------- 1 file changed, 17 insertions(+), 25 deletions(-) diff --git a/bqn-mode-map.el b/bqn-mode-map.el index 30f7602..5d12d61 100644 --- a/bqn-mode-map.el +++ b/bqn-mode-map.el @@ -14,35 +14,27 @@ ;;; Code: -(eval-and-compile - (defun bqn-mode-map--make-key-command-sym (n) - (intern (concat "insert-sym-bqn-" n)))) +(defun bqn-mode-map--command-name (name) + "Return a symbol for the command NAME." + (intern (concat "bqn-insert-sym-" name))) -(cl-macrolet ((make-insert-functions () - `(progn - ,@(mapcar (lambda (command) - `(defun ,(bqn-mode-map--make-key-command-sym (car command)) () - (interactive) - (insert ,(cadr command)))) - bqn-symbols--list)))) - (make-insert-functions)) - -(defun bqn-mode-map--kbd (definition) - "Function wrapper for `kbd' with arg DEFINITION." - (if (functionp #'kbd) - (kbd definition) - (eval `(kbd ,definition)))) +(pcase-dolist (`(,name ,symbol ,_) bqn-symbols--list) + (defalias (bqn-mode-map--command-name name) + (lambda () + (interactive) + (insert symbol)))) (defun bqn-mode-map--make-base (prefix) "Create a new keymap using the key PREFIX." (let ((map (make-sparse-keymap))) - (dolist (command bqn-symbols--list) - (let ((key (single-key-description (caddr command)))) - (define-key map (bqn-mode-map--kbd (concat prefix key)) (bqn-mode-map--make-key-command-sym (car command))))) + (pcase-dolist (`(,name ,_ ,key) bqn-symbols--list) + (let ((cmd (bqn-mode-map--command-name name)) + (key (single-key-description key))) + (define-key map (kbd (concat prefix key)) cmd))) (define-key map [menu-bar bqn] (cons "BQN" (make-sparse-keymap "BQN"))) map)) -;; value gets updated by initialization of bqn-mode-map-prefix +;; value gets updated by initialization of `bqn-mode-map-prefix' (defvar bqn-mode-map--keymap nil "The keymap for ‘bqn-mode’.") @@ -52,15 +44,15 @@ (setq bqn-mode-map--keymap (bqn-mode-map--make-base new))) (defcustom bqn-mode-map-prefix "s-" - "This stores the keymap prefix for ‘bqn-mode-map--keymap’. + "This stores the keymap prefix for `bqn-mode-map--keymap'. It is used both to store the new value using -‘set-create’ and to update ‘bqn-mode-map--keymap’ using +`set-create’ and to update `bqn-mode-map--keymap' using `bqn-mode-map--make-base'. Kill and restart your BQN buffers to reflect the change." :type 'string :group 'bqn - :set 'bqn-mode-map--set-prefix - :initialize 'custom-initialize-set) + :set #'bqn-mode-map--set-prefix + :initialize #'custom-initialize-set) (provide 'bqn-mode-map)