Skip to content

Commit

Permalink
Undo-region: more ergonomic keybindings (syl20bnr#15631)
Browse files Browse the repository at this point in the history
  • Loading branch information
BenedictHW authored Jul 15, 2022
1 parent 872c714 commit aee4fa8
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.develop
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ the [[file:CHANGELOG.org][CHANGELOG.org]] file.
(thanks to Seong Yong-ju)
- Changed ~SPC t t m~ from ~timeclock-modeline-display~ which was deprecated
in Emacs 24.3 to ~timeclock-mode-line-display~ (thanks to Zach Pearson)
- Added =vim-style-enable-undo-region= style variables to enable undo-region
in Vim editing style; disabled by default. (thanks to Benedict HW)
- Other:
- Support for multiple cursors using =evil-mc= is now encapsulated in the
=multiple-cursors= layer (thanks to Codruț Constantin Gușoi)
Expand Down
4 changes: 4 additions & 0 deletions layers/+distributions/spacemacs-bootstrap/config.el
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ if used there.")
dotspacemacs-visual-line-move-text nil)
"If non-nil, J and K move lines up and down when in visual mode.")

(defvar vim-style-enable-undo-region nil
"If non-nil, `u' is remapped to `undo' in visual state.
Otherwise, in visual state `u' downcases visually selected text.")

(defvar vim-style-ex-substitute-global
(spacemacs|dotspacemacs-backward-compatibility
dotspacemacs-ex-substitute-global nil)
Expand Down
3 changes: 3 additions & 0 deletions layers/+distributions/spacemacs-bootstrap/packages.el
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@
(define-key evil-visual-state-map "J" 'drag-stuff-down)
(define-key evil-visual-state-map "K" 'drag-stuff-up))

(when vim-style-enable-undo-region
(define-key evil-visual-state-map (kbd "u") 'undo))

(evil-ex-define-cmd "enew" 'spacemacs/new-empty-buffer)

(define-key evil-normal-state-map (kbd "K") 'spacemacs/evil-smart-doc-lookup)
Expand Down
19 changes: 19 additions & 0 deletions layers/+spacemacs/spacemacs-editing/README.org
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* Table of Contents :TOC_5_gh:noexport:
- [[#description][Description]]
- [[#features][Features:]]
- [[#customization][Customization]]
- [[#undo-region][Undo Region]]

* Description
This layer adds packages to improve editing with Spacemacs.
Expand Down Expand Up @@ -33,3 +35,20 @@ This layer adds packages to improve editing with Spacemacs.
- Support for [[https://github.com/PythonNut/evil-easymotion][=evil-easymotion=]] if the editing style is =vim= or =hybrid=.
- Support for cycling between multi line block styles via [[https://github.com/IvanMalison/multi-line/][=multi-line=]].
- Support for editing strings inplace via [[https://github.com/magnars/string-edit.el][=string-edit=]]
- Presents undo history as a tree via [[https://gitlab.com/tsc25/undo-tree/-/blob/master/undo-tree.el][=undo-tree=]]

* Customization
** Undo Region
In normal state, ~u~ is bound to =evil-undo= which undo changes in the buffer.
Emacs's builtin =undo= command in addition has the ability to undo changes in a
selected region. But by default in visual state, ~u~ is bound to =evil-downcase=
which downcases the selected text.

You can bound =undo= to ~u~ in visual state, by setting the variable
=vim-style-enable-undo-region= to =t= in your =~/.spacemacs=.

#+BEGIN_SRC emacs-lisp
(setq-default dotspacemacs-configuration-layers
'((spacemacs-editing :variables
vim-style-enable-undo-region t)))
#+END_SRC
2 changes: 2 additions & 0 deletions layers/+spacemacs/spacemacs-editing/packages.el
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,8 @@
(progn
(setq undo-tree-visualizer-timestamps t
undo-tree-visualizer-diff t
;; See `vim-style-enable-undo-region'.
undo-tree-enable-undo-in-region t
;; 10X bump of the undo limits to avoid issues with premature
;; Emacs GC which truncages the undo history very aggresively
undo-limit 800000
Expand Down

0 comments on commit aee4fa8

Please sign in to comment.