From 6e09c106f00858c2b154853609aec450a9519ff2 Mon Sep 17 00:00:00 2001 From: Shane Creighton-Young Date: Thu, 11 Feb 2021 16:09:31 -0500 Subject: [PATCH 1/2] add 1 set of alternative mappings --- boon-arguments.el | 4 +-- boon-core.el | 67 +++++++++++++++++++++++++++++++++++++++++++---- boon-keys.el | 29 +++++++++++++++++--- 3 files changed, 89 insertions(+), 11 deletions(-) diff --git a/boon-arguments.el b/boon-arguments.el index 224169f..6a6decd 100644 --- a/boon-arguments.el +++ b/boon-arguments.el @@ -302,8 +302,8 @@ subregions or when repeating a command. The bounds that are eventually returned are in the form of a list of regs. See boon-regs.el." (let ((my-prefix-arg 0) - (kmv boon-moves-map) - (kms boon-select-map)) + (kmv (if boon-using-altp boon-alt-moves-map boon-moves-map)) + (kms (if boon-using-altp boon-alt-select-map boon-select-map))) ;; We read a move or selection, in both keymaps in parallel. First command found wins. (while (and (or kmv kms) (not (commandp kms)) (not (commandp kmv))) (let ((last-char (read-event (format "%s %s" msg my-prefix-arg)))) diff --git a/boon-core.el b/boon-core.el index 98bd302..b966589 100644 --- a/boon-core.el +++ b/boon-core.el @@ -38,13 +38,32 @@ Any move is also a valid region selector, see `boon-moves-map'.") See also `boon-special-mode-list'. \\{boon-special-map}") +;; Alternate maps +(defvar boon-alt-command-map (make-sparse-keymap) + "Alternate keymap used in Boon command mode. + +\\{boon-alt-command-map}") +(suppress-keymap boon-alt-command-map 't) +(defvar boon-alt-moves-map (make-sparse-keymap) + "Alternate keymap for moves (subset of alt command mode). + +\\{boon-alt-moves-map}") +(set-keymap-parent boon-alt-command-map boon-alt-moves-map) + +(defvar boon-alt-select-map (make-sparse-keymap) + "Alternate keymap for text regions selectors. +\\{boon-alt-select-map} + +Any move is also a valid region selector, see `boon-alt-moves-map'.") (defvar-local boon-mode-map-alist nil) (push 'boon-mode-map-alist emulation-mode-map-alists) ;; States +(defvar boon-using-altp nil "Non-nil when the alternate keymap is active.") (defvar-local boon-off-state nil "Used to disable boon altogether without fiddling with emulation-mode-map-alists") (defvar-local boon-command-state nil "Non-nil when boon command mode is activated. (Boon commands can be entered in this mode.)") +(defvar-local boon-alt-command-state nil "Non-nil when boon alt command mode is activated. (Boon alt commands can be entered in this mode.)") (defvar-local boon-insert-state nil "Non-nil when boon insert mode is activated.") (defvar-local boon-special-state nil "Non-nil when special state is activated. Special is active when special-mode buffers (see `boon-special-mode-list') are @@ -57,6 +76,7 @@ those. See `boon-special-map' for exceptions.") (defcustom boon-default-cursor-type 'bar "Default `cursor-type', also used for the minibuffer." :group 'boon :type 'sexp) (defcustom boon-command-cursor-type 'box "`cursor-type' for command mode." :group 'boon :type 'sexp) +(defcustom boon-alt-command-cursor-type 'box "`cursor-type' for command mode." :group 'boon :type 'sexp) (defcustom boon-insert-cursor-type 'bar "`cursor-type' for insert mode." :group 'boon :type 'sexp) (defcustom boon-special-cursor-type 'box "`cursor-type' for special mode." :group 'boon :type 'sexp) @@ -78,6 +98,13 @@ of `boon-command-cursor-color', `boon-insert-cursor-color' and must also be set." :group 'boon :type 'string) +(defcustom + boon-alt-command-cursor-color + nil + "`cursor-color' for command mode. `boon-default-cursor-color' +must also be set." + :group 'boon + :type 'string) (defcustom boon-insert-cursor-color nil @@ -101,6 +128,7 @@ must also be set." (cond (boon-insert-state (list boon-insert-cursor-type boon-insert-cursor-color)) (boon-command-state (list boon-command-cursor-type boon-command-cursor-color)) + (boon-alt-command-state (list boon-alt-command-cursor-type boon-alt-command-cursor-color)) (boon-special-state (list boon-special-cursor-type boon-special-cursor-color)) (t (list boon-default-cursor-type boon-default-cursor-color))) (setq cursor-type type) @@ -170,10 +198,11 @@ input-method is reset to nil.)") "Set the boon state (as STATE) for this buffer." (when boon-insert-state (setq-local boon-input-method current-input-method)) (setq boon-command-state nil) + (setq boon-alt-command-state nil) (setq boon-insert-state nil) (setq boon-special-state nil) (set state t) - (cond (boon-command-state + (cond ((or boon-command-state boon-alt-command-state) (deactivate-input-method) (when (and boon/insert-command boon/insert-command-history) (push `(,@boon/insert-command @@ -207,7 +236,28 @@ input-method is reset to nil.)") (defun boon-set-command-state () "Switch to command state." - (interactive) (boon-set-state 'boon-command-state)) + (interactive) + (setq boon-using-altp nil) + (boon-set-state 'boon-command-state)) + +(defun boon-set-alt-command-state () + "Switch to alt command state." + (interactive) + (setq boon-using-altp t) + (boon-set-state 'boon-alt-command-state)) + +(defun boon-restore-command-state () + "Switch to command or alt command mode." + (interactive) + (if boon-using-altp + (boon-set-alt-command-state) + (boon-set-command-state))) + +(defun boon-toggle-alt () + "Swap between command-mode and alt-command-mode globally." + (interactive) + (setq boon-using-altp (not boon-using-altp)) + (boon-restore-command-state)) (defun boon-set-special-state () "Switch to special state." @@ -249,6 +299,13 @@ input-method is reset to nil.)") (-some 'eval boon-special-conditions) (memq major-mode boon-special-mode-list))) +(defun boon-initialize-state () + (cond ((boon-special-mode-p) (boon-set-state 'boon-special-state)) + ((-some 'eval boon-insert-conditions) (boon-set-insert-state)) + (t (boon-restore-command-state)))) + +(add-hook 'buffer-list-update-hook #'boon-initialize-state) + ;;; Initialisation and activation (define-minor-mode boon-local-mode @@ -260,13 +317,12 @@ input-method is reset to nil.)") (boon-set-state 'boon-off-state) (setq boon-mode-map-alist (list (cons 'boon-command-state (or (get major-mode 'boon-map) boon-command-map)) + (cons 'boon-alt-command-state (or (get major-mode 'boon-map) boon-alt-command-map)) (cons 'boon-special-state boon-special-map) (cons 'boon-insert-state boon-insert-map))) (unless (memq 'boon/after-change-hook after-change-functions) (push 'boon/after-change-hook after-change-functions)) - (cond ((boon-special-mode-p) (boon-set-state 'boon-special-state)) - ((-some 'eval boon-insert-conditions) (boon-set-insert-state)) - (t (boon-set-command-state))))) + (boon-initialize-state))) (add-hook 'minibuffer-setup-hook 'boon-minibuf-hook) @@ -307,6 +363,7 @@ the buffer changes." "Return a string describing the current state." (cond (boon-command-state "CMD") + (boon-alt-command-state "ACMD") (boon-insert-state "INS") (boon-special-state "SPC") (t "???"))) diff --git a/boon-keys.el b/boon-keys.el index 360058e..3dcc1e3 100644 --- a/boon-keys.el +++ b/boon-keys.el @@ -51,11 +51,20 @@ (define-key boon-select-map "#" 'boon-select-all) (define-key boon-select-map " " 'boon-select-line) (define-key boon-select-map "\"" 'boon-select-outside-quotes) +(define-key boon-alt-select-map "@" 'boon-select-occurences) +(define-key boon-alt-select-map "#" 'boon-select-all) +(define-key boon-alt-select-map " " 'boon-select-line) +(define-key boon-alt-select-map "\"" 'boon-select-outside-quotes) (define-key boon-moves-map "'" 'boon-switch-mark) (define-key boon-moves-map (kbd "") 'left-char) (define-key boon-moves-map (kbd "") 'right-char) (define-key boon-moves-map (kbd "") 'previous-line) (define-key boon-moves-map (kbd "") 'next-line) +(define-key boon-alt-moves-map "'" 'boon-switch-mark) +(define-key boon-alt-moves-map (kbd "") 'left-char) +(define-key boon-alt-moves-map (kbd "") 'right-char) +(define-key boon-alt-moves-map (kbd "") 'previous-line) +(define-key boon-alt-moves-map (kbd "") 'next-line) (define-key boon-command-map "'" 'boon-toggle-mark) (define-key boon-command-map [(return)] 'undefined) @@ -63,15 +72,25 @@ (define-key boon-command-map [(backspace)] 'undefined) (define-key boon-command-map (kbd "") 'undefined) (define-key boon-command-map "`" 'boon-toggle-case) -(define-key boon-moves-map "[" '("[-" . boon-navigate-backward)) -(define-key boon-moves-map "]" '("-]" . boon-navigate-forward)) +(define-key boon-alt-command-map "'" 'boon-toggle-mark) +(define-key boon-alt-command-map [(return)] 'undefined) +(define-key boon-alt-command-map (kbd "") 'undefined) +(define-key boon-alt-command-map [(backspace)] 'undefined) +(define-key boon-alt-command-map (kbd "") 'undefined) +(define-key boon-alt-command-map "`" 'boon-toggle-case) +(define-key boon-alt-moves-map "[" '("[-" . boon-navigate-backward)) +(define-key boon-alt-moves-map "]" '("-]" . boon-navigate-forward)) (define-key boon-command-map "!" 'shell-command) (define-key boon-command-map "|" 'shell-command-on-region) (define-key boon-command-map "-" 'undo) +(define-key boon-alt-command-map "!" 'shell-command) +(define-key boon-alt-command-map "|" 'shell-command-on-region) +(define-key boon-alt-command-map "-" 'undo) (dolist (number '("0" "1" "2" "3" "4" "5" "6" "7" "8" "9")) (define-key boon-command-map number 'digit-argument)) (define-key boon-command-map "~" 'universal-argument) +(define-key boon-alt-command-map "~" 'universal-argument) (define-key universal-argument-map "~" 'universal-argument-more) (defcustom boon-quit-key [escape] "Key to go back to command @@ -80,16 +99,18 @@ state and generally exit local states and modes." :group 'boon (define-key boon-command-map " " 'boon-drop-mark) (define-key boon-command-map boon-quit-key 'boon-quit) +(define-key boon-alt-command-map " " 'boon-drop-mark) +(define-key boon-alt-command-map boon-quit-key 'boon-quit) ;; Special mode rebinds (define-key boon-special-map "`" 'boon-quote-character) (define-key boon-special-map "'" 'boon-quote-character) (define-key boon-special-map "x" boon-x-map) -(define-key boon-special-map boon-quit-key 'boon-set-command-state) +(define-key boon-special-map boon-quit-key 'boon-restore-command-state) ;; Insert mode rebinds (define-key boon-insert-map [remap newline] 'boon-newline-dwim) -(define-key boon-insert-map boon-quit-key 'boon-set-command-state) +(define-key boon-insert-map boon-quit-key 'boon-restore-command-state) ;; Global rebinds (define-key global-map boon-quit-key 'keyboard-quit) From ebf9d28f4a4eee64be1b9ab0bf20e3386f79a3b0 Mon Sep 17 00:00:00 2001 From: Shane Creighton-Young Date: Mon, 5 Apr 2021 16:00:14 -0400 Subject: [PATCH 2/2] Don't re-init states in buffer list update --- boon-core.el | 2 -- 1 file changed, 2 deletions(-) diff --git a/boon-core.el b/boon-core.el index b966589..cc06b77 100644 --- a/boon-core.el +++ b/boon-core.el @@ -304,8 +304,6 @@ input-method is reset to nil.)") ((-some 'eval boon-insert-conditions) (boon-set-insert-state)) (t (boon-restore-command-state)))) -(add-hook 'buffer-list-update-hook #'boon-initialize-state) - ;;; Initialisation and activation (define-minor-mode boon-local-mode