Text alignment with evil lion

A wrapper integrating evil text objects with Emacs' align function.
This commit is contained in:
Howard Abrams 2022-09-11 21:58:47 -07:00
parent ec3d445a65
commit 682d7e1bc8
2 changed files with 46 additions and 6 deletions

View file

@ -12,11 +12,11 @@ Best success comes from using the [[https://github.com/d12frosted/homebrew-emacs
#+end_src #+end_src
I find that I need to … at least, on my work computer, install two different versions of Emacs that I use to distinguish one for “work” and the other for other activities, like IRC and [[file:ha-feed-reader.org][elfeed]]. To that end, I run the following commands to install Emacs: I find that I need to … at least, on my work computer, install two different versions of Emacs that I use to distinguish one for “work” and the other for other activities, like IRC and [[file:ha-feed-reader.org][elfeed]]. To that end, I run the following commands to install Emacs:
#+begin_src sh #+begin_src sh
brew install emacs-plus@28 --with-native-comp --with-mailutils --with-imagemagick brew install emacs-plus@28 --with-native-comp --with-mailutils --with-imagemagick --with-elrumo2-icon
#+end_src #+end_src
And the following for “work”: And the following for “work”:
#+begin_src sh #+begin_src sh
brew install emacs-plus@29 --with-native-comp brew install emacs-plus@29 --with-native-comp --with-elrumo1-icon
#+end_src #+end_src
* Supporting Packages * Supporting Packages
Now install all the extras: Now install all the extras:

View file

@ -471,6 +471,7 @@ And the keybindings:
(define-key evil-inner-text-objects-map "g" #'ha-evil-inner-paren) (define-key evil-inner-text-objects-map "g" #'ha-evil-inner-paren)
(define-key evil-outer-text-objects-map "g" #'ha-evil-a-paren) (define-key evil-outer-text-objects-map "g" #'ha-evil-a-paren)
#+end_src #+end_src
*** Key Chord *** Key Chord
Using the key-chord project allows me to make Escape be on two key combo presses on both sides of my keyboard: Using the key-chord project allows me to make Escape be on two key combo presses on both sides of my keyboard:
#+begin_src emacs-lisp #+begin_src emacs-lisp
@ -488,6 +489,45 @@ The [[https://github.com/PythonNut/evil-easymotion][evil-easymotion]] project co
:config (evilem-default-keybindings "<f19>")) :config (evilem-default-keybindings "<f19>"))
#+end_src #+end_src
My ~F19~ key is within easy reach of my [[https://configure.zsa.io/moonlander/layouts/L4laD/latest/0][Moonlander configuration]], so this might be a good, if somewhat distracting, feature. Perhaps a better solution is to use [[Jump with Avy][avy]] (see below). My ~F19~ key is within easy reach of my [[https://configure.zsa.io/moonlander/layouts/L4laD/latest/0][Moonlander configuration]], so this might be a good, if somewhat distracting, feature. Perhaps a better solution is to use [[Jump with Avy][avy]] (see below).
*** Evil Lion
The [[https://github.com/edkolev/evil-lion][evil-lion]] package is a wrapper around Emacs [[help:align][align]] function. Just a little easier to use. Primary sequence is ~g a i p =~ to align along all the equal characters in the paragraph (block), or ~g a i b RET~ to use a built in rule to align (see below), or ~g a i b /~ to specify a regular expression, similar to [[help:align-regexp][align-regexp]].
#+begin_src emacs-lisp
(use-package evil-lion
:after evil
:bind (:map evil-normal-state-map
("g a" . evil-lion-left)
("g A" . evil-lion-right)
:map evil-visual-state-map
("g a" . evil-lion-left)
("g A" . evil-lion-right)))
#+end_src
Lion sounds like /align/ … get it?
Where I like to align, is on variable assignments, e.g.
#+begin_src emacs-lisp :tangle no
(let ((foobar "Something something")
(a 42)
(very-long-var "odd string"))
;;
)
#+end_src
If you press ~RETURN~ for the /character/ to align, =evil-lion= package simply calls the built-in [[help:align][align]] function. This function chooses a regular expression based on a list of /rules/, and aligning Lisp variables requires a complicated regular expression. Extend [[elisp:(describe-variable 'align-rules-list)][align-rules-list]]:
#+begin_src emacs-lisp
(use-package align
:straight (:type built-in)
:config
(add-to-list 'align-rules-list
`("lisp-assignments"
(regexp . ,(rx (group (one-or-more space))
(or
(seq "\"" (zero-or-more any) "\"")
(one-or-more (not space)))
(one-or-more ")") (zero-or-more space) eol))
(group . 1)
(modes . align-lisp-modes))))
#+end_src
** General Leader Key Sequences ** General Leader Key Sequences
The one thing that both Spacemacs and Doom taught me, is how much I like the /key sequences/ that begin with a leader key. In both of those systems, the key sequences begin in the /normal state/ with a space key. This means, while typing in /insert state/, I have to escape to /normal state/ and then hit the space. The one thing that both Spacemacs and Doom taught me, is how much I like the /key sequences/ that begin with a leader key. In both of those systems, the key sequences begin in the /normal state/ with a space key. This means, while typing in /insert state/, I have to escape to /normal state/ and then hit the space.
@ -905,10 +945,10 @@ The [[https://github.com/mhayashi1120/Emacs-wgrep][wgrep package]] integrates wi
Stealing much of this from Spacemacs. Stealing much of this from Spacemacs.
#+begin_src emacs-lisp #+begin_src emacs-lisp
(ha-leader (ha-leader
"x" '(:ignore t :which-key "text") "x" '(:ignore t :which-key "text")
"x a" '("align" . align-regexp) "x a" '("align" . align-regexp)
"x q" '("fill paragraph" . fill-paragraph) "x q" '("fill paragraph" . fill-paragraph)
"x p" '("unfill paragraph" . unfill-paragraph)) "x p" '("unfill paragraph" . unfill-paragraph))
#+end_src #+end_src
Unfilling a paragraph joins all the lines in a paragraph into a single line. Taken [[http://www.emacswiki.org/UnfillParagraph][from here]] … I use this all the time: Unfilling a paragraph joins all the lines in a paragraph into a single line. Taken [[http://www.emacswiki.org/UnfillParagraph][from here]] … I use this all the time: