Merge branch 'master' of github.com:jyp/boon

This commit is contained in:
Jean-Philippe Bernardy 2016-11-14 13:30:49 +01:00
commit b7a9f555b3
9 changed files with 168 additions and 101 deletions

1
.gitignore vendored
View file

@ -12,3 +12,4 @@ TAGS
/.stack-work
/boon.elc
/Colemak.hs

View file

@ -11,6 +11,13 @@ cheat.pdf: cheat-sheet.hs
test:
$(emacs) -batch --script boon-test.el
Colemak.hs:
$(emacs) -batch \
--eval "(add-to-list 'load-path (expand-file-name \".\"))" \
--eval "(package-initialize)" \
-l boon-tutorial.el \
--eval '(boon-dump-cheatsheet "colemak")'
clean:
rm -f *.elc

View file

@ -255,7 +255,7 @@ See boon-regs.el."
(while (and (or kmv kms) (not (commandp kms)) (not (commandp kmv)))
(let ((last-char (read-event (format "%s %s" msg my-prefix-arg))))
;; read-event, because mc badly advises read-char
(if (and (>= last-char ?0) (<= last-char ?9))
(if (and (integerp last-char) (>= last-char ?0) (<= last-char ?9))
(setq my-prefix-arg (+ (- last-char ?0) (* 10 my-prefix-arg )))
(if kms (setq kms (lookup-key kms (vector last-char))))
(if kmv (setq kmv (lookup-key kmv (vector last-char)))))))

View file

@ -12,7 +12,7 @@
(define-key boon-select-map "a" 'boon-select-borders) ;; Around
(define-key boon-select-map "r" 'boon-select-justline) ;; Row
(define-key boon-select-map "s" 'boon-select-wim) ;; symbol
(define-key boon-select-map "s" '("symbol" . boon-select-wim)) ;; symbol
(define-key boon-select-map "t" 'boon-select-with-spaces)
(define-key boon-select-map "d" 'boon-select-document)
(define-key boon-select-map "b" 'boon-select-block)
@ -25,7 +25,7 @@
(define-key boon-select-map "k" 'boon-select-blanks) ;; blanKs
(define-key boon-moves-map "k" 'boon-switch-mark) ; bacK to marK
(define-key boon-moves-map "k" '("bacK to marK" . boon-switch-mark)) ; bacK to marK
(define-key boon-moves-map "K" 'xref-pop-marker-stack)
(define-key boon-moves-map "j" '("jump" . xref-find-definitions))
@ -57,33 +57,18 @@
;; Top row
;; q
(define-key boon-command-map "q" 'boon-quote-character)
(define-key boon-command-map "q" '("quote" . boon-quote-character))
;; w,f
;; where is? find?
(define-key boon-moves-map "w " 'isearch-backward)
(define-key boon-moves-map "f " 'isearch-forward)
(define-key boon-moves-map "wt" 'boon-qsearch-previous-at-point)
(define-key boon-moves-map "ft" 'boon-qsearch-next-at-point)
(define-key boon-moves-map "ws" 'boon-qsearch-previous-at-point)
(define-key boon-moves-map "fs" 'boon-qsearch-next-at-point)
(define-key boon-moves-map "w" '("where was?" . boon-backward-search-map))
(define-key boon-moves-map "f" '("find" . boon-forward-search-map))
(define-key boon-moves-map "ww" 'boon-qsearch-previous)
(define-key boon-moves-map "ff" 'boon-qsearch-next)
(define-key boon-moves-map "W" 'boon-qsearch-previous)
(define-key boon-moves-map "F" 'boon-qsearch-next)
(define-key boon-moves-map "wp" 'boon-qsearch-previous)
(define-key boon-moves-map "fp" 'boon-qsearch-next)
(define-key boon-moves-map "we" 'previous-error)
(define-key boon-moves-map "fe" 'next-error)
(define-key boon-moves-map "wk" 'flycheck-previous-error)
(define-key boon-moves-map "fk" 'flycheck-next-error)
(define-key boon-moves-map "wb" 'previous-buffer)
(define-key boon-moves-map "fb" 'next-buffer)
(define-key boon-moves-map "fu" 'mc/cycle-forward)
(define-key boon-moves-map "wu" 'mc/cycle-backward)
;; p
;; Pinpoint Place
@ -91,25 +76,24 @@
;; Misc crap
(define-key boon-command-map "P" 'kmacro-end-or-call-macro) ; Play
(define-key boon-command-map "X" 'boon-highlight-regexp)
;; g Gather/Go To
(define-key boon-command-map "g" boon-goto-map)
;; g
(define-key boon-command-map "g" (cons "goto" boon-goto-map))
;; home row
;; a
(define-key boon-command-map "a" 'boon-enclose) ; around
(define-key boon-command-map "a" '("around" . boon-enclose))
;; r
(define-key boon-command-map "r" 'boon-substitute-region) ; replace
(define-key boon-command-map "R" 'kmacro-start-macro) ; Record
(define-key boon-command-map "r" '("replace" . boon-substitute-region))
(define-key boon-command-map "R" '("Record" . kmacro-start-macro))
;; s
(define-key boon-command-map "s" 'boon-splice) ; splice
(define-key boon-command-map "s" '("splice" . boon-splice))
(define-key boon-command-map "S" 'yank-pop)
;; t
(define-key boon-command-map "t" 'boon-take-region) ; "take"
(define-key boon-command-map "t" '("take" . boon-take-region))
(define-key boon-command-map "T" 'boon-treasure-region) ; "treasure"
;; d
@ -120,12 +104,14 @@
;; reserved (repeat?)
;; x
(define-key boon-command-map "x" boon-x-map)
(define-key boon-command-map "X" 'boon-highlight-regexp)
;; c
(define-key boon-command-map "c" 'boon-c-god)
;; v
(define-key boon-command-map (kbd "C-v") 'boon-open-line-and-insert)
(define-key boon-command-map "V" 'boon-open-next-line-and-insert)
(define-key boon-command-map "v" 'boon-set-insert-like-state) ; 'v' looks like an insertion mark
(define-key boon-command-map "v" '("v looks like an insert mark" . boon-set-insert-like-state))
;; b
(define-key boon-command-map "B" 'boon-copy-to-register)
(define-key boon-command-map "b" 'insert-register)

View file

@ -120,7 +120,8 @@ those. See 'boon-special-map' for exceptinons.")
mu4e-view-mode
)
"A List of modes which should use `boon-special-state'."
:group 'boon)
:group 'boon
:type '(repeat symbol))
(defun boon-special-mode-p ()
"Should the mode use `boon-special-state'?"

View file

@ -9,6 +9,28 @@
(require 'boon-core)
(define-prefix-command 'boon-backward-search-map)
(define-prefix-command 'boon-forward-search-map)
(define-key boon-forward-search-map " " 'isearch-forward)
(define-key boon-forward-search-map "t" 'boon-qsearch-next-at-point)
(define-key boon-forward-search-map "s" 'boon-qsearch-next-at-point)
(define-key boon-forward-search-map "p" 'boon-qsearch-next)
(define-key boon-forward-search-map "e" 'next-error)
(define-key boon-forward-search-map "k" 'flycheck-next-error)
(define-key boon-forward-search-map "b" 'next-buffer)
(define-key boon-forward-search-map "u" 'mc/cycle-forward)
(define-key boon-backward-search-map " " 'isearch-backward)
(define-key boon-backward-search-map "t" 'boon-qsearch-previous-at-point)
(define-key boon-backward-search-map "s" 'boon-qsearch-previous-at-point)
(define-key boon-backward-search-map "p" 'boon-qsearch-previous)
(define-key boon-backward-search-map "e" 'previous-error)
(define-key boon-backward-search-map "k" 'flycheck-previous-error)
(define-key boon-backward-search-map "b" 'previous-buffer)
(define-key boon-backward-search-map "u" 'mc/cycle-backward)
(defvar boon-goto-map (make-sparse-keymap))
(set-keymap-parent boon-goto-map goto-map)
@ -45,6 +67,7 @@
(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 [escape] 'boon-set-command-state)
;; Insert mode rebinds
(define-key boon-insert-map [remap newline] 'boon-newline-dwim)
@ -62,7 +85,7 @@
"Swap the control 'bit' in EVENT, if that is a good choice."
(interactive (list (read-key)))
(cond
((memq event '(9 13 ?{ ?} ?[ ?] ?$ ?< ?> ?: ?\;)) event)
((memq event '(9 13 ?{ ?} ?[ ?] ?$ ?< ?> ?: ?\; ?/ ?? ?. ?,)) event)
((<= event 27) (+ 96 event))
((not (eq 0 (logand (lsh 1 26) event))) (logxor (lsh 1 26) event))
(t (list 'control event))))

View file

@ -173,10 +173,9 @@ line."
(interactive)
(if mark-active
(exchange-point-and-mark)
(if (mark)
(progn
(goto-char (mark))
(pop-mark)))))
(when (mark)
(goto-char (mark))
(pop-mark))))
(defun boon-switch-mark-quick ()
"Pop the mark ring until we find ourselves on a different line."

View file

@ -23,7 +23,7 @@
(define-key boon-select-map "b" 'boon-select-blanks) ;; blanKs
(define-key boon-moves-map "n" 'boon-switch-mark) ; nope
(define-key boon-moves-map "n" '("noon walk" . boon-switch-mark))
(define-key boon-moves-map "N" 'xref-pop-marker-stack)
(define-key boon-moves-map "y" 'xref-find-definitions) ; fYnd
@ -44,7 +44,7 @@
(define-key boon-moves-map "l" 'forward-char)
(define-key boon-moves-map "<" 'beginning-of-buffer)
(define-key boon-moves-map ">" 'end-of-buffer)
(define-key boon-moves-map "h" 'avy-goto-word-1)
(define-key boon-moves-map "h" '("hop" . avy-goto-word-1))
(define-key boon-moves-map "H" 'avy-goto-char)
@ -55,36 +55,22 @@
;; Top row
;; q
(define-key boon-command-map "q" 'boon-quote-character)
(define-key boon-command-map "q" '("quote" . boon-quote-character))
;; w,e
;; where is? elsewhere?
(define-key boon-moves-map "w " 'isearch-backward)
(define-key boon-moves-map "e " 'isearch-forward)
(define-key boon-moves-map "wt" 'boon-qsearch-previous-at-point)
(define-key boon-moves-map "et" 'boon-qsearch-next-at-point)
(define-key boon-moves-map "ws" 'boon-qsearch-previous-at-point)
(define-key boon-moves-map "es" 'boon-qsearch-next-at-point)
(define-key boon-moves-map "w" '("where was?" . boon-backward-search-map))
(define-key boon-moves-map "e" '("elsewhere?" . boon-forward-search-map))
(define-key boon-moves-map "ww" 'boon-qsearch-previous)
(define-key boon-moves-map "ee" 'boon-qsearch-next)
(define-key boon-moves-map "W" 'boon-qsearch-previous)
(define-key boon-moves-map "E" 'boon-qsearch-next)
(define-key boon-moves-map "wp" 'boon-qsearch-previous)
(define-key boon-moves-map "ep" 'boon-qsearch-next)
(define-key boon-moves-map "we" 'previous-error)
(define-key boon-moves-map "ee" 'next-error)
(define-key boon-moves-map "wk" 'flycheck-previous-error)
(define-key boon-moves-map "ek" 'flycheck-next-error)
(define-key boon-moves-map "wb" 'previous-buffer)
(define-key boon-moves-map "eb" 'next-buffer)
(define-key boon-moves-map "eu" 'mc/cycle-forward)
(define-key boon-moves-map "wu" 'mc/cycle-backward)
;; r
(define-key boon-command-map "r" 'occur) ;; occuR
(define-key boon-command-map "R" 'kmacro-start-macro) ; Record
;; Misc crap
(define-key boon-command-map "P" 'kmacro-end-or-call-macro) ; Play
@ -96,22 +82,21 @@
;; home row
;; a
(define-key boon-command-map "a" 'boon-enclose) ; around
(define-key boon-command-map "a" '("around" . boon-enclose))
;; s
(define-key boon-command-map "r" 'boon-substitute-region) ; replace
(define-key boon-command-map "R" 'kmacro-start-macro) ; Record
(define-key boon-command-map "s" '("substitute" . boon-substitute-region))
;; d
(define-key boon-command-map "d" 'boon-take-region) ; "delete"
(define-key boon-command-map "d" '("delete" . boon-take-region)) ; "delete"
(define-key boon-command-map "D" 'boon-treasure-region) ; "duplicate"
;; f
(define-key boon-command-map "f" 'boon-splice) ; flush
(define-key boon-command-map "f" '("fetch" . boon-splice)) ; flush
(define-key boon-command-map "F" 'yank-pop)
;; g
(define-key boon-command-map "g" boon-goto-map) ;; goto
(define-key boon-command-map "g" (cons "goto" boon-goto-map))
;; Bottom row
;; z
@ -123,7 +108,7 @@
;; v
(define-key boon-command-map (kbd "C-v") 'boon-open-line-and-insert)
(define-key boon-command-map "V" 'boon-open-next-line-and-insert)
(define-key boon-command-map "v" 'boon-set-insert-like-state) ; 'v' looks like an insertion mark
(define-key boon-command-map "v" '("v looks like an insert mark" . boon-set-insert-like-state))
;; b
(define-key boon-command-map "B" 'boon-copy-to-register) ; bank
(define-key boon-command-map "b" 'insert-register)

View file

@ -7,6 +7,64 @@
;;; Code:
(require 'boon-core)
(require 'boon-keys)
(require 'dash)
(defun boon-dump-map (map)
"Dump the MAP in a format usable to generate a cheat sheet."
(apply
'concat
(--map (let* ((b (lookup-key map (make-vector 1 it)))
(mn (boon-mnemonic-noformat b map)))
(format "(%d,%S,\"%S\"):" it mn
(cond ((symbolp b) b)
((eq b boon-x-map) 'x-map)
((eq b boon-goto-map) 'goto-map))
))
(-concat
(-iterate '1+ ?A 26)
(-iterate '1+ ?a 26)
'(?\; ?: ?- ?' ?, ?. ?< ?>)
))))
(defun boon-dump-cheatsheet (flavour)
"Dump cheatcheat info for FLAVOUR."
(let ((module (capitalize flavour))
(el (concat "boon-" flavour ".el")))
(require 'boon)
(load el)
(with-temp-buffer
(insert (format "module %s where \n " module))
(insert (format "nil = \"\"\n"))
(insert (format "commandMap = %s:[]\n" (boon-dump-map boon-command-map)))
(insert (format "movesMap = %s:[]\n" (boon-dump-map boon-moves-map)))
(insert (format "selectMap = %s:[]\n" (boon-dump-map boon-select-map)))
(write-region nil nil (concat module ".hs")))))
(defun boon-keymap-rev-look (sub map)
"Return an event yielding SUB from the keymap MAP."
(let (res)
(map-keymap (lambda (event b)
(when (and (consp b) (stringp (car b))) (setq b (cdr b)))
(when (eq b sub) (setq res event)))
map)
(key-description (vector res))))
(defun boon-mnemonic-noformat (sub &optional map)
"Return the mnemonic for SUB from the keymap MAP."
(let (res)
(map-keymap (lambda (_event b) (when (and (consp b)
(stringp (car b))
(eq (cdr b) sub))
(setq res (car b))))
(or map boon-command-map))
res))
(defun boon-mnemonic (sub &optional map)
"Return the formatted mnemonic for SUB from the keymap MAP."
(format "(mnemonic: %s)" (boon-mnemonic-noformat sub map)))
;; utilities to create the tutorial
;;;###autoload
@ -18,16 +76,15 @@
(insert (symbol-name (lookup-key boon-command-map key)))
(insert "]"))
;; (global-set-key (kbd "C-'") 'boon-gen-key)
;;;###autoload
(defun boon-gen-sel-key (key)
"Generate a suitable tutorial string to refer to selection KEY."
(interactive (list (read-key "key?")))
(insert "\\\\<boon-select-map>\\\\")
(insert "[")
(insert (symbol-name (lookup-key boon-select-map (vconcat (list key)))))
(insert "]\\\\<boon-command-map> "))
(insert (concat "\" (selector '" (symbol-name (lookup-key boon-select-map (vconcat (list key)))) ") \"")))
;; (global-set-key (kbd "C-'") 'boon-gen-key)
;; (global-set-key (kbd "C-'") 'boon-gen-sel-key)
;;;###autoload
(defun boon-tutorial ()
@ -35,22 +92,25 @@
(interactive)
(switch-to-buffer (generate-new-buffer "BOON-TUTORIAL"))
(turn-on-boon-mode)
(insert (substitute-command-keys
(let ((x-key (boon-keymap-rev-look boon-x-map boon-command-map)))
(cl-flet ((selector (sel) (boon-keymap-rev-look sel boon-select-map)))
(insert (substitute-command-keys (concat
"Boon tutorial. See end for copying conditions.
\\<boon-command-map>
This tutorial assumes that you know Emacs already.
Note on the tutorial: sometimes the tutorial will mention a
mnemonic for a key. A mnemonic is a story linking the key to type
to the action that it does. This story is often small, maybe just
a word. You may use the mnemonics provided by the tutorial, but
it is best to invent your own. If the tutorial says 'mnemonic:
nil', this means that the frontend that you have activated has
not defined a mnemonic for that command.
Make sure that Boon is active in this buffer. Call
\\[turn-on-boon-mode] if necessary.
Note on the tutorial: sometimes the tutorial will mention a
mnemonic for a key. A mnemonic should be a (small) story linking
the key to type to the action that it does. You may reuse the
standard mnemonics, but it is best to invent your own. The
mnemonics written in the tutorial come from the colemak frontend,
they may make no sense for other frontends.
Boon has two states: command state and insert state. Boon
indicates the difference between command state and insert state
in several ways:
@ -65,8 +125,9 @@ in several ways:
having to read any text.
You can switch from command to insert mode by typing
\\[boon-set-insert-like-state] (mnemonic: v looks like an
insert mark). Go back to command mode by typing <ESC>.
\\[boon-set-insert-like-state] " (boon-mnemonic
'boon-set-insert-like-state)". Go back to command mode by typing
<ESC>.
>> Switch to command mode now (type <ESC>)
@ -173,7 +234,7 @@ command.
>> Move forward by seven words.
To insert a character several times, you can use the escaping
command '\\[boon-quote-character]' (mnemonic: quote).
command '\\[boon-quote-character]' " (boon-mnemonic 'boon-quote-character) "
>> Try that now -- type '8\\[boon-quote-character]*' to insert ********.
@ -183,9 +244,9 @@ command '\\[boon-quote-character]' (mnemonic: quote).
There are two other movement commands, bound to \\[avy-goto-word-1] and \\[boon-switch-mark].
- \\[boon-switch-mark] (mnemonic: bacK to marK) jumps pops a mark and jumps to it. (If a region is active, exchange point and mark)
- \\[boon-switch-mark] " (boon-mnemonic 'boon-switch-mark) " jumps pops a mark and jumps to it. (If a region is active, exchange point and mark)
- \\[avy-goto-word-1] (mnemonic: hop) activates avy-goto-word-1 (if installed)
- \\[avy-goto-word-1] " (boon-mnemonic 'avy-goto-word-1) " activates avy-goto-word-1 (if installed)
- Additionally, \\[xref-find-definitions] is bound to `xref-find-definitions'.
@ -196,8 +257,8 @@ If Emacs stops responding to your commands, you can stop it safely by
typing C-g. You can use C-g to stop a command which is taking too
long to execute.
You can also use C-g to discard a numeric argument or the beginning of
a command that you do not want to finish.
You can also use C-g to discard an argument or the beginning of a
command that you do not want to finish.
<ESC> is an alternative which works in many contexts.
@ -205,20 +266,24 @@ a command that you do not want to finish.
* C-x prefix
-------------
Instead of the C-x prefix; you may just type 'x'
Instead of the C-x prefix; you may just type " x-key "
>> Type \\[split-window-below] to split this window
>> Type \\[delete-other-windows] to close the other windows
Additionally, the `execute-extended-command' command is bound to '\\[execute-extended-command]'
Additionally, the `execute-extended-command' command is bound to
'\\[execute-extended-command]'. It is a good idea to bind your
own favourite commands in `boon-x-map', so you can access them
via " x-key ". (Standard commands are always available under C-x)
* C-c prefix
------------
Mode-specific commands have often the form 'C-c C-<key>'. These are
accessible by typing simply '\\[boon-c-god]<key>' from command mode. Unfortunately
there is no such binding in text mode by default --- so you cannot
test this right away.
Mode-specific commands have often the form 'C-c
C-<letter>'. These are accessible by typing simply
'\\[boon-c-god]<letter>' from command mode. Unfortunately there
is no such binding in text mode by default --- so you cannot test
this right away.
* INSERTING AND DELETING
@ -232,7 +297,7 @@ In insert mode, regular Emacs editing commands can be used.
>> Type \\[boon-set-insert-like-state] to insert some text; then <ESC> to go back to command mode.
Deleting text is mostly done with the '\\[boon-take-region]' key (mnemonic: take).
Deleting text is mostly done with the '\\[boon-take-region]' key " (boon-mnemonic 'boon-take-region) ".
The take command expects an argument. This argument can be any
right-hand move command (in `boon-moves-map'), such as '\\[backward-char]'.
@ -244,10 +309,10 @@ In the above, \\[backward-char] is the argument to the \\[boon-take-region] comm
>> Type '\\[boon-take-region] \\[boon-smarter-backward]' to delete backwards, up to the beginning of a word
You can also use a left-hand _region specifier_ as an argument to
`boon-take-region'. One of such arguments is '\\<boon-select-map>\\[boon-select-wim]\\<boon-command-map>', which refers to the symbol
`boon-take-region'. One of such arguments is '" (selector 'boon-select-wim) "', which refers to the symbol
(or sexp) at point.
>> Type \\[boon-take-region] \\<boon-select-map>\\[boon-select-wim]\\<boon-command-map> to delete the symbol where the cursor is (even if in the
>> Type \\[boon-take-region] " (selector 'boon-select-wim) " to delete the symbol where the cursor is (even if in the
middle of the symbol)
One of the most useful region specifier is \\<boon-select-map>\\[boon-select-line]\\<boon-command-map>, which specifies the
@ -290,19 +355,19 @@ left-hand ones.
>> Type \\[boon-drop-mark] again to undo the selection
In particular, the region specifier `boon-select-line' (\\<boon-select-map>\\[boon-select-line]\\<boon-command-map>) can be
In particular, the region specifier `boon-select-line' (" (selector 'boon-select-line) ") can be
given to the marking command (\\[boon-drop-mark]).
>> Type \\[boon-drop-mark] \\<boon-select-map>\\[boon-select-line]\\<boon-command-map> to select the current line
>> Type \\[boon-drop-mark] " (selector 'boon-select-line) " to select the current line
>> Type \\[next-line] a few times to select some lines
>> Type \\[boon-take-region] to delete all these lines
You can kill and switch to insert mode in a single command, bound to
'\\[boon-substitute-region]' (mnemonic: replace).
'\\[boon-substitute-region]' " (boon-mnemonic 'boon-substitute-region) ".
>> Try typing '\\[boon-substitute-region] \\<boon-select-map>\\[boon-select-wim]\\<boon-command-map>' to replace the symbol at point.
>> Try typing \\[boon-substitute-region] " (selector 'boon-select-wim) " to replace the symbol at point.
The command for yanking is '\\[boon-splice]'. (mnemonic: splice)
The command for yanking is '\\[boon-splice]'. " (boon-mnemonic `boon-splice) "
>> Try it; type \\[boon-splice] to yank the text back.
@ -349,11 +414,11 @@ region (if such do not exist, it adds the spaces before).
Boon provides help to manipulate parentheses.
The command '\\[boon-enclose]' (mnemonic: around) adds parentheses around a region.
The command '\\[boon-enclose]' " (boon-mnemonic 'boon-enclose) " adds parentheses around a region.
It takes two arguments:
1. the kind of parentheses to use ('p' for regular parentheses)
1. the kind of parentheses to use (by defaut 'p' for regular parentheses)
2. the region to surround. This region is specified by the same
language as the arguments to \\[boon-take-region] or \\[boon-drop-mark] commands.
@ -362,7 +427,7 @@ It takes two arguments:
enclose it in parens.
It's often useful to put parens around what has been just
It is often useful to put parens around what has been just
pasted. The just pasted region is accessible using (\\[boon-toggle-mark]).
>> kill a word, then paste it.
@ -463,7 +528,7 @@ from the standard Emacs tutorial,
Copyright (C) 1985, 1996, 1998, 2001-2013 Free Software Foundation,
Inc.
"))
")))))
(goto-char 1))
;;; boon-tutorial.el ends here