Setup `repeat-mode' real nice like

This commit is contained in:
Case Duckworth 2021-08-24 23:01:20 -05:00
parent 8d9ebc1b86
commit da40526c8a
2 changed files with 93 additions and 3 deletions

83
init.el
View File

@ -676,7 +676,12 @@ like a dumbass."
(recentf-mode +1))
(setup repeat
;; new for Emacs 28!
(:only-if (fboundp #'repeat-mode))
(:option repeat-exit-key "g"
repeat-exit-timeout 5)
(repeat-mode +1))
(setup (:require savehist)
@ -819,9 +824,69 @@ like a dumbass."
(acdw/system :home)))
recenter-positions '(top middle bottom))
(tooltip-mode -1)
(tooltip-mode -1))
(setup winner
;; see https://lists.gnu.org/archive/html/emacs-devel/2021-08/msg00888.html
(:global "C-x 4 C-/" winner-undo
"C-x 4 /" winner-undo
"C-x 4 C-?" winner-redo
"C-x 4 ?" winner-redo)
;; add `winner-undo' and `winner-redo' to `repeat-mode'
(when (fboundp 'repeat-mode)
(defvar winner-mode-repeat-map
(let ((map (make-sparse-keymap)))
(define-key map "/" #'winner-undo)
(define-key map "?" #'winner-redo)
map)
"Keymap to repeat `winner-mode' sequences. Used in `repeat-mode'.")
(put 'winner-undo 'repeat-map 'winner-mode-repeat-map)
(put 'winner-redo 'repeat-map 'winner-mode-repeat-map))
(winner-mode +1))
(setup windmove
(:option windmove-wrap-around t)
(:global
;; moving
"C-x 4 <left>" windmove-left
"C-x 4 <right>" windmove-right
"C-x 4 <up>" windmove-up
"C-x 4 <down>" windmove-down
;; swapping
"C-x 4 S-<left>" windmove-swap-states-left
"C-x 4 S-<right>" windmove-swap-states-right
"C-x 4 S-<up>" windmove-swap-states-up
"C-x 4 S-<down>" windmove-swap-states-down)
(when (fboundp 'repeat-mode)
(defvar windmove-repeat-map
(let ((map (make-sparse-keymap)))
;; moving
(define-key map [left] #'windmove-left)
(define-key map [right] #'windmove-right)
(define-key map [up] #'windmove-up)
(define-key map [down] #'windmove-down)
;; swapping
(define-key map [S-left] #'windmove-swap-states-left)
(define-key map [S-right] #'windmove-swap-states-right)
(define-key map [S-up] #'windmove-swap-states-up)
(define-key map [S-down] #'windmove-swap-states-down)
map)
"Keymap to repeat various `windmove' sequences. Used in `repeat-mode'.")
(dolist (sym '(windmove-left
windmove-right
windmove-up
windmove-down
windmove-swap-states-left
windmove-swap-states-right
windmove-swap-states-up
windmove-swap-states-down))
(put sym 'repeat-map 'windmove-repeat-map))))
(setup w32
(:option w32-allow-system-shell t
w32-pass-lwindow-to-system nil
@ -1028,13 +1093,25 @@ like a dumbass."
(funcall #'vertico-exit)))))
(setup (:straight crux)
(:global "M-`" crux-other-window-or-switch-buffer
(:global "C-x o" acdw/other-window-or-switch-buffer
"C-o" crux-smart-open-line
"M-o" crux-smart-open-line-above
"C-M-\\" crux-cleanup-buffer-or-region
"C-x 4 t" crux-transpose-windows)
(when (fboundp 'repeat-mode)
(define-key other-window-repeat-map "o"
#'acdw/other-window-or-switch-buffer)
(define-key other-window-repeat-map "O"
(defun acdw/other-window-or-switch-buffer-backward ()
(interactive)
(setq repeat-map 'other-window-repeat-map)
(acdw/other-window-or-switch-buffer -1)))
(put 'acdw/other-window-or-switch-buffer
'repeat-map 'other-window-repeat-map))
(crux-reopen-as-root-mode +1))
;; requires extension:

View File

@ -566,5 +566,18 @@ It's called 'require-private' for historical reasons."
(forward-sexp 2)
('scan-error (end-of-buffer))))
;;; Crux tweaks
;; `crux-other-window-or-switch-buffer' doesn't take an argument.
(defun acdw/other-window-or-switch-buffer (&optional arg)
"Call `other-window' or switch buffers, depending on window count."
(interactive "P")
(if (one-window-p)
(switch-to-buffer nil)
(other-window (or arg 1))))
(provide 'acdw)
;;; acdw.el ends here