Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 1 set of alternative mappings #108

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions boon-arguments.el
Original file line number Diff line number Diff line change
Expand Up @@ -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))))
Expand Down
65 changes: 60 additions & 5 deletions boon-core.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand All @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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."
Expand Down Expand Up @@ -249,6 +299,11 @@ 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))))

;;; Initialisation and activation

(define-minor-mode boon-local-mode
Expand All @@ -260,13 +315,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)

Expand Down Expand Up @@ -307,6 +361,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 "???")))
Expand Down
29 changes: 25 additions & 4 deletions boon-keys.el
Original file line number Diff line number Diff line change
Expand Up @@ -51,27 +51,46 @@
(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>") 'left-char)
(define-key boon-moves-map (kbd "<right>") 'right-char)
(define-key boon-moves-map (kbd "<up>") 'previous-line)
(define-key boon-moves-map (kbd "<down>") 'next-line)
(define-key boon-alt-moves-map "'" 'boon-switch-mark)
(define-key boon-alt-moves-map (kbd "<left>") 'left-char)
(define-key boon-alt-moves-map (kbd "<right>") 'right-char)
(define-key boon-alt-moves-map (kbd "<up>") 'previous-line)
(define-key boon-alt-moves-map (kbd "<down>") 'next-line)

(define-key boon-command-map "'" 'boon-toggle-mark)
(define-key boon-command-map [(return)] 'undefined)
(define-key boon-command-map (kbd "<RET>") 'undefined)
(define-key boon-command-map [(backspace)] 'undefined)
(define-key boon-command-map (kbd "<DEL>") '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 "<RET>") 'undefined)
(define-key boon-alt-command-map [(backspace)] 'undefined)
(define-key boon-alt-command-map (kbd "<DEL>") '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
Expand All @@ -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)
Expand Down