Skip to content

Commit

Permalink
undo-fu; multiple-cursors
Browse files Browse the repository at this point in the history
  • Loading branch information
JJPandari committed Apr 10, 2023
1 parent ad8bf84 commit 2ad48df
Show file tree
Hide file tree
Showing 9 changed files with 158 additions and 62 deletions.
1 change: 1 addition & 0 deletions modes/init-buffer.el
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"b i" 'ibuffer
"b k" 'jester/kill-this-buffer
"b r" 'rename-buffer
"b q" 'bury-buffer
"b h" (lambda! (switch-to-buffer (help-buffer)))
"b m" (lambda! (switch-to-buffer (messages-buffer)))
"b s" 'jester/switch-to-scratch-buffer
Expand Down
2 changes: 0 additions & 2 deletions modes/init-company.el
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

(use-package company
:demand t
;; make sure bindings in company-active-map won't be overriden
:after evil-multiedit
:init
(setq company-backends
'(company-capf company-files
Expand Down
11 changes: 10 additions & 1 deletion modes/init-editing-utils.el
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@
;; undo
;;----------------------------------------------------------------------------
(use-package undo-fu
:init
(general-define-key
:states '(emacs)
"C-/" 'undo-fu-only-undo
"C-?" 'undo-fu-only-redo)
:demand t
:config
(customize-set-variable 'evil-undo-system 'undo-fu))
Expand All @@ -59,7 +64,11 @@
:config
(undo-fu-session-global-mode))

(use-package vundo)
(use-package vundo
:init
(jester/with-leader "v u" 'vundo)
:config
(setq vundo-glyph-alist vundo-unicode-symbols))


(use-package expand-region
Expand Down
128 changes: 98 additions & 30 deletions modes/init-evil.el
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
evil-motion-state-cursor '("plum3" box)
evil-visual-state-cursor '("gray" (hbar . 2))
evil-insert-state-cursor '("chartreuse3" (bar . 2))
evil-emacs-state-cursor '("SkyBlue2" box)
evil-emacs-state-cursor '("RoyalBlue" bar)
evil-operator-state-cursor '("chocolate" box)
evil-replace-state-cursor '("chocolate" (hbar . 2))
evil-multiedit-state-cursor '("MediumPurple1" box)
Expand Down Expand Up @@ -232,15 +232,12 @@
(unless (jester/in-expression-area-p)
(evil-multiedit-toggle-or-restrict-region)))))))
:config
(general-define-key
:keymaps 'evil-multiedit-mode-map
"<return>" 'evil-multiedit-toggle-or-restrict-region
"<S-tab>" 'evil-multiedit-prev)
;; these have to be loaded before company so they don't shadow tab bindings in `company-active-map'
(general-define-key
:states '(normal)
:keymaps 'evil-multiedit-mode-map
"<return>" 'evil-multiedit-toggle-or-restrict-region
"<tab>" 'evil-multiedit-next
"<S-tab>" 'evil-multiedit-prev
"C-n" 'evil-multiedit-match-and-next
"C-p" 'evil-multiedit-match-and-prev)
(general-define-key
Expand All @@ -256,14 +253,14 @@
:init
;; don't bind any keys
(setq evil-mc-key-map (make-sparse-keymap))
(general-define-key
:states '(normal visual)
"K" 'evil-mc-make-all-cursors
"M-n" 'evil-mc-make-and-goto-next-match
"M-p" 'evil-mc-make-and-goto-prev-match
"M-j" 'evil-mc-make-cursor-move-next-line
"M-k" 'evil-mc-make-cursor-move-prev-line
"<M-return>" 'jester/evil-mc-toggle-cursors-pause)
;; (general-define-key
;; :states '(normal visual)
;; "K" 'evil-mc-make-all-cursors
;; "M-n" 'evil-mc-make-and-goto-next-match
;; "M-p" 'evil-mc-make-and-goto-prev-match
;; "M-j" 'evil-mc-make-cursor-move-next-line
;; "M-k" 'evil-mc-make-cursor-move-prev-line
;; "<M-return>" 'jester/evil-mc-toggle-cursors-pause)
(defun jester/evil-mc-toggle-cursors-pause ()
"Toggle between pausing or resuming all cursors."
(interactive)
Expand All @@ -286,20 +283,66 @@
(push (cons fn '((:default . evil-mc-execute-default-call)))
evil-mc-custom-known-commands)))


;; https://github.com/abo-abo/hydra/wiki/multiple-cursors
(use-package multiple-cursors
:init
(general-define-key
:states '(emacs)
"M-j" 'mc/mark-next-like-this
"M-k" 'mc/mark-previous-like-this
"M-n" 'mc/mark-next-like-this-symbol
"M-p" 'mc/mark-previous-like-this-symbol)
;; TODO not work
(general-define-key
:states '(emacs)
:keymaps 'mc/keymap
"<escape>" 'mc/keyboard-quit)
(general-define-key :keymaps 'mc/keymap "<return>" nil)

(defhydra hydra-multiple-cursors (:hint nil :exit nil)
"
Up^^ Down^^ Miscellaneous % 2(mc/num-cursors) cursor%s(if (> (mc/num-cursors) 1) \"s\" \"\")
------------------------------------------------------------------
[_p_] Next [_n_] Next [_l_] Edit lines [_0_] Insert numbers
[_P_] Skip [_N_] Skip [_a_] Mark all [_A_] Insert letters
[_M-p_] Unmark [_M-n_] Unmark [_s_] Search [_q_] Quit
[_|_] Align with input CHAR [Click] Cursor at point"
("l" mc/edit-lines :exit t)
("a" mc/mark-all-like-this :exit t)
("n" mc/mark-next-like-this)
("N" mc/skip-to-next-like-this)
("M-n" mc/unmark-next-like-this)
("p" mc/mark-previous-like-this)
("P" mc/skip-to-previous-like-this)
("M-p" mc/unmark-previous-like-this)
("|" mc/vertical-align)
("s" mc/mark-all-in-region-regexp :exit t)
("0" mc/insert-numbers :exit t)
("A" mc/insert-letters :exit t)
("<mouse-1>" mc/add-cursor-on-click)
;; Help with click recognition in this hydra
("<down-mouse-1>" ignore)
("<drag-mouse-1>" ignore)
("q" nil)))


(use-package evil-collection
:demand t
:after evil
:config
;; modes I don't want evil-collection to setup
(dolist (mode '(vterm (term term ansi-term multi-term)))
;; modes I don't want evil-collection to touch
(dolist (mode '(company compile comint help info ivy vterm (term term ansi-term multi-term)))
(setq evil-collection-mode-list (delete mode evil-collection-mode-list)))
(setq evil-collection-want-unimpaired-p nil
evil-collection-want-find-usages-bindings nil)
(evil-collection-init)

;; modify a bit after evil-collection setup
;; TODO not overridding evil-collection?
(general-define-key
:states '(normal)
:keymaps 'magit-mode-map
:keymaps '(magit-mode-map magit-diff-mode-map magit-log-mode-map)
"/" 'jester/swiper-dwim))


Expand Down Expand Up @@ -427,10 +470,6 @@
;;----------------------------------------------------------------------------
;; Set initial states for modes.
;;----------------------------------------------------------------------------
;; TODO what happened to `evil-motion-state-modes'???
(evil-set-initial-state 'help-mode 'motion)
(evil-set-initial-state 'Info-mode 'motion)

(evil-set-initial-state 'debugger-mode 'motion)
(evil-set-initial-state 'messages-buffer-mode 'motion)

Expand Down Expand Up @@ -495,6 +534,7 @@
"t" 'evil-replace
"Q" "@q"
"gJ" 'jester/evil-join-no-whitespace
"z i" 'evil-emacs-state
"<" nil
">" nil)

Expand Down Expand Up @@ -550,7 +590,7 @@
"C-e" 'evil-end-of-line)

(general-define-key
:states '(insert emacs)
:states '(insert)
"M-v" 'evil-scroll-down
"M-c" 'evil-scroll-up
"C-b" 'delete-forward-char
Expand All @@ -561,12 +601,34 @@
"C-e" 'move-end-of-line
"C-k" 'kill-line
"C-w" 'evil-delete-backward-word
"C-x" 'kill-region
"C-v" 'yank
;; leave C-r for commands similar to backward-search
"C-y" 'evil-paste-from-register
"M-d" 'backward-word
"M-b" 'kill-word
"H-x" 'kill-region)
"H-x" ctl-x-map)

(general-define-key
:states '(emacs)
"M-v" 'evil-scroll-down
"M-c" 'evil-scroll-up
"C-b" 'delete-forward-char
"C-d" 'backward-char
"C-n" 'next-line
"C-p" 'previous-line
"C-a" 'beginning-of-line-text
"C-e" 'move-end-of-line
"C-k" 'kill-line
"C-w" 'backward-kill-word
"C-x" 'kill-region
"C-v" 'yank
;; leave C-r for commands similar to backward-search
;; "C-y" 'evil-paste-from-register
"M-d" 'backward-word
"M-b" 'kill-word
"H-x" ctl-x-map
"<escape>" 'evil-exit-emacs-state)

;;----------------------------------------------------------------------------
;; Not-so-evil keys...
Expand All @@ -577,18 +639,24 @@
"C-h c" 'describe-char
"C-h K" 'find-function-on-key
;; copy insert state bindings here, so keys do the same when evil disabled
"M-v" 'evil-scroll-down
"M-c" 'evil-scroll-up
"C-b" 'delete-forward-char
"C-d" 'backward-char
"C-n" 'next-line
"C-p" 'previous-line
"C-a" 'beginning-of-line-text
"C-e" 'move-end-of-line
"C-k" 'kill-line
"C-w" 'evil-delete-backward-word
"C-w" 'backward-kill-word
"C-x" 'kill-region
"C-v" 'yank
;; leave C-r for commands similar to backward-search
;; "C-y" 'evil-paste-from-register
"M-d" 'backward-word
"M-b" 'kill-word
"H-x" 'kill-region)
"H-x" ctl-x-map
"<escape>" 'keyboard-quit)

;;----------------------------------------------------------------------------
;; Some functions.
Expand Down Expand Up @@ -685,21 +753,21 @@
(dolist (cmd '(evil-yank evil-delete lispyville-yank lispyville-delete))
(advice-add cmd :after 'jester/evil-portal-jump-advice))

(defun jester/goto-line-beginning-or-end ()
(defun jester/cycle-line-beginning-end ()
"Go to line text beginning, line end, line very beginning, in turn."
(interactive)
(cl-block 'my-return
(when (and (looking-at "[^\s]") (looking-back "^\s*")) (evil-end-of-line) (cl-return-from 'my-return)) ; at beg of line text
(when (looking-at ".$") (evil-beginning-of-line) (cl-return-from 'my-return)) ; at end of line
(when (looking-at (if evil-move-beyond-eol "$" ".$")) (evil-beginning-of-line) (cl-return-from 'my-return)) ; at end of line
(when (bolp) (evil-first-non-blank) (cl-return-from 'my-return)) ; at very beg of line
(evil-first-non-blank)))
(general-define-key
:states '(normal visual operator)
"0" 'jester/goto-line-beginning-or-end)
"0" 'jester/cycle-line-beginning-end)

;; TODO try citre-read
;; TODO try citre-read or clue

;; TODO "vio" vs "yio": make visual "auto line-wise"?
;; TODO show bookmark name in fringe


(provide 'init-evil)
6 changes: 5 additions & 1 deletion modes/init-hydra.el
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
(use-package hydra
:demand t)
:custom (hydra-hint-display-type 'posframe)
:demand t
:config
(plist-put hydra-posframe-show-params :poshandler 'posframe-poshandler-frame-bottom-center))


;; hydras are defined in other files grouped by their functionalities.

Expand Down
34 changes: 18 additions & 16 deletions modes/init-ivy.el
Original file line number Diff line number Diff line change
Expand Up @@ -210,22 +210,24 @@ If called interactively, let the user select start directory first."
:commands ivy-wgrep-change-to-wgrep-mode)


;; (use-package ivy-posframe
;; :demand t
;; :after ivy
;; :if window-system
;; :config
;; ;; (setq ivy-posframe-display-functions-alist '((t . ivy-posframe-display)))
;; (setq ivy-posframe-display-functions-alist '((t . ivy-posframe-display-at-frame-center)))
;; ;; (setq ivy-posframe-display-functions-alist '((t . ivy-posframe-display-at-window-center)))
;; ;; (setq ivy-posframe-display-functions-alist '((t . ivy-posframe-display-at-frame-bottom-left)))
;; ;; (setq ivy-posframe-display-functions-alist '((t . ivy-posframe-display-at-window-bottom-left)))
;; ;; (setq ivy-posframe-display-functions-alist '((t . ivy-posframe-display-at-frame-top-center)))
;; (setq ivy-posframe-hide-minibuffer t)
;; (setq ivy-posframe-parameters
;; `((background-color . ,(face-attribute 'default :background))
;; (foreground-color . ,(face-attribute 'default :foreground))))
;; (ivy-posframe-mode 1))
(use-package ivy-posframe
:demand t
:after ivy
:if window-system
:config
(setq ivy-posframe-hide-minibuffer t)
(setq ivy-posframe-parameters
`((background-color . ,(face-attribute 'default :background))
(foreground-color . ,(face-attribute 'default :foreground))
(left-fringe . 8)))
(set-face-attribute 'ivy-posframe-cursor nil :foreground "RoyalBlue")
(setq ivy-posframe-style 'frame-bottom-left
ivy-posframe-display-functions-alist
'((swiper . ivy-display-function-fallback)
(swiper-all . ivy-display-function-fallback)
(complete-symbol . ivy-posframe-display-at-point)
(t . ivy-posframe-display)))
(ivy-posframe-mode 1))


(use-package ivy-rich
Expand Down
5 changes: 5 additions & 0 deletions modes/init-jump.el
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
;;----------------------------------------------------------------------------
;; bookmark
;;----------------------------------------------------------------------------
;; (defun jester/bookmark-set-auto-name ()
;; "Do `bookmark-set', if region is active, use the region as bookmark name."
;; (interactive)
;; )
;; TODO use the macro for "/"
(jester/with-leader
"b n" 'bookmark-set
"b j" 'bookmark-jump)
Expand Down
3 changes: 2 additions & 1 deletion modes/init-shell.el
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
(dolist (key '("<tab>"
"C-f" "C-d" "C-a" "C-e" "C-n" "C-p"
"C-b" "C-w" "C-k"
"C-r" "C-t" "C-v" "C-/"
"C-r" "C-t" "C-/"
"M-c" "M-f" "M-d" "M-b"))
(general-define-key
:states '(insert emacs)
Expand All @@ -62,6 +62,7 @@
:keymaps 'vterm-mode-map
"C-h" nil
"C-c" 'vterm--self-insert
"C-v" 'vterm-yank
"C-s" 'swiper)

(general-define-key
Expand Down
30 changes: 19 additions & 11 deletions modes/init-windows.el
Original file line number Diff line number Diff line change
Expand Up @@ -163,17 +163,25 @@ bound to KEY in the leader sub-keymap."
(cl-incf jester/eyebrowse-random-number-seed)
(eyebrowse-switch-to-window-config (+ jester/eyebrowse-random-number-seed 10000)))


;; set to 0 so we jump a lot by default, making sure we land at middle of window when using marks
(setq scroll-conservatively 0)
;; use 999 when moving the cursor, so it stays at top/bottom of window, not being jumpy
;; TODO not work
(dolist (no-jumpy-command '(evil-next-line evil-previous-line next-line previous-line))
(advice-add no-jumpy-command :around 'jester/run-command-no-jumpy))
(defun jester/run-command-no-jumpy (old-fun &rest args)
"Around advice. Run OLD-FUN (next-line, prev-line etc.) without jumping cursor to middle of screen."
(let ((scroll-conservatively 999))
(apply old-fun args)))
;;----------------------------------------------------------------------------
;; scroll smoothly, press scroll easily, scroll to center sometimes...
;;----------------------------------------------------------------------------
(setq scroll-conservatively 999
scroll-margin 0
scroll-preserve-screen-position t)
;; when `scroll-conservatively' is 0, recenter happens automatically, not when 999
(add-hook 'counsel-grep-post-action-hook 'recenter)
(defun jester/recenter (&rest _)
"Wrapper for `recenter', taking whatever arguments and ignore them."
(recenter))
(dolist (command '(xref-pop-marker-stack
evil-goto-mark evil-goto-last-change evil-goto-last-change-reverse
evil-search-next evil-search-previous
evilmi-jump-items
symbol-overlay-jump-next symbol-overlay-jump-prev
flycheck-next-error flycheck-previous-error
magit-diff-visit-file))
(advice-add command :after 'jester/recenter))

(use-package smooth-scroll
:demand t
Expand Down

0 comments on commit 2ad48df

Please sign in to comment.