edkolev / evil-lion Goto Github PK
View Code? Open in Web Editor NEWEvil align operator
Evil align operator
When I type gl
, the cursor changes from normal to operator (in my setup, goes from a filled green box to an empty red one), but after I've typed e.g. ip
, it changes back to the normal-state (green box). Can we have it stay the operator cursor until I've typed the alignment character? The first time I tried it, I thought alignment wasn't working at all, so I gave up and pressed M-x align
โฆ
Spacemacs has some interesting functions regarding alignment right here.
Consider incorporating some the functionality into lion. the align-repeat seems to be the most useful. Here's the snippet:
;; BEGIN align functions
;; modified function from http://emacswiki.org/emacs/AlignCommands
(defun spacemacs/align-repeat (start end regexp &optional justify-right after)
"Repeat alignment with respect to the given regular expression.
If JUSTIFY-RIGHT is non nil justify to the right instead of the
left. If AFTER is non-nil, add whitespace to the left instead of
the right."
(interactive "r\nsAlign regexp: ")
(let* ((ws-regexp (if (string-empty-p regexp)
"\\(\\s-+\\)"
"\\(\\s-*\\)"))
(complete-regexp (if after
(concat regexp ws-regexp)
(concat ws-regexp regexp)))
(group (if justify-right -1 1)))
(message "%S" complete-regexp)
(align-regexp start end complete-regexp group 1 t)))
;; Modified answer from http://emacs.stackexchange.com/questions/47/align-vertical-columns-of-numbers-on-the-decimal-point
(defun spacemacs/align-repeat-decimal (start end)
"Align a table of numbers on decimal points and dollar signs (both optional)"
(interactive "r")
(require 'align)
(align-region start end nil
'((nil (regexp . "\\([\t ]*\\)\\$?\\([\t ]+[0-9]+\\)\\.?")
(repeat . t)
(group 1 2)
(spacing 1 1)
(justify nil t)))
nil))
(defmacro spacemacs|create-align-repeat-x (name regexp &optional justify-right default-after)
(let ((new-func (intern (concat "spacemacs/align-repeat-" name))))
`(defun ,new-func (start end switch)
(interactive "r\nP")
(let ((after (not (eq (if switch t nil) (if ,default-after t nil)))))
(spacemacs/align-repeat start end ,regexp ,justify-right after)))))
(spacemacs|create-align-repeat-x "comma" "," nil t)
(spacemacs|create-align-repeat-x "semicolon" ";" nil t)
(spacemacs|create-align-repeat-x "colon" ":" nil t)
(spacemacs|create-align-repeat-x "equal" "=")
(spacemacs|create-align-repeat-x "math-oper" "[+\\-*/]")
(spacemacs|create-align-repeat-x "ampersand" "&")
(spacemacs|create-align-repeat-x "bar" "|")
(spacemacs|create-align-repeat-x "left-paren" "(")
(spacemacs|create-align-repeat-x "right-paren" ")" t)
(spacemacs|create-align-repeat-x "backslash" "\\\\")
;; END align functions
Thanks again for the package.
This is such a great feature. One of those things that you've always missed without knowing it. One question, though: Does it make sense that this has it's own mode? I would guess that users want this when evil mode is on but not otherwise. Making this its own mode means that it can be switched on with evil off and the reverse. Not sure if there are any use cases for these combinations.
The first example works, but the second one is not working. Any suggestions?
Whenever I use /
, the minibuffer suggests /
as the default instead of what I last used. Ie. do glap/-- RET
and then glap/
and it'll show Pattern [/]:
instead of Pattern [--]:
evil-define-operator
is not supported by autoload cookies, so the whole (evil-define-operator...)
will be pulled into the autoload file. You need to manually specify the autoload. For example:
;; nil can be replaced with a docstring
;;;###autoload (autoload 'evil-lion-left "evil-lion" nil t)
(evil-define-operator evil-lion-left ....)
Hi, thanks for the package.
Please consider providing a way for the user to customize the keybinds. I for one already use the gl
bind for something else.
Evil-lion-left
and built-in align-regexp
have the different rules to align the strings. With evil-lion it looks like you align a piece of code to a new string(fourth string) instead of align a new string to the existing piece of code.
For example:
(teal-green "#6fb593")
(wheat "#b9c791")
(dark-blue "#2a4661")
(blue "#5485b6")
(alt-blue "#6666be")
(cyan "#54b6b6")
In my opinion, the align-regexp
way is more natural.
Would you like to add an option to set alignment rules? Or maybe change the current behavior?
hi @edkolev,
is it possible to turn this:
#<ip-address> <hostname.domain.org> <hostname>
127.0.0.1 localhost.localdomain localhost
::1 localhost.localdomain localhost
# 127.0.0.1 thinkpad.localdomain thinkpad
192.168.0.4 julicloud.local julicloud
127.0.1.1 thinkpad.localdomain thinkpad
into this:
#<ip-address> <hostname.domain.org> <hostname>
127.0.0.1 localhost.localdomain localhost
::1 localhost.localdomain localhost
# 127.0.0.1 thinkpad.localdomain thinkpad
192.168.0.4 julicloud.local julicloud
127.0.1.1 thinkpad.localdomain thinkpad
with your package?
When using evil-lion functions on lisp forms the result always gets
two spaces as indentation regardless. For example gl<space>
gives this result
(<m>
refers to the mark and |
refers to point):
Before:
(prog1 'evil-surround
(add-to-list 'package-selected-packages 'evil-surround)
(when (fboundp 'evil-surround-mode)
(autoload #'evil-surround-edit "evil-surround" nil t)
(autoload #'evil-Surround-edit "evil-surround" nil t)
(autoload #'evil-surround-region "evil-surround" nil t)
(autoload #'evil-Surround-region "evil-surround" nil t)
<m> (define-key evil-operator-state-map "s" 'evil-surround-edit)
(define-key evil-operator-state-map "S" 'evil-Surround-edit)
(define-key evil-visual-state-map "s" 'evil-surround-region)
(define-key evil-visual-state-map "S" 'evil-Surround-region)))
|
After:
(prog1 'evil-surround
(add-to-list 'package-selected-packages 'evil-surround)
(when (fboundp 'evil-surround-mode)
(autoload #'evil-surround-edit "evil-surround" nil t)
(autoload #'evil-Surround-edit "evil-surround" nil t)
(autoload #'evil-surround-region "evil-surround" nil t)
(autoload #'evil-Surround-region "evil-surround" nil t)
| (define-key evil-operator-state-map "s" 'evil-surround-edit)
(define-key evil-operator-state-map "S" 'evil-Surround-edit)
(define-key evil-visual-state-map "s" 'evil-surround-region)
(define-key evil-visual-state-map "S" 'evil-Surround-region)))
Versions:
Emacs 28.1
Evil: 1.14.2
Evil-lion: 0.0.2
I have other packages installed as well, but these are the most relevant.
hi again @edkolev.
your awesome package is very close to mimic vim-easy-align in functionality. One functionality I miss comming from vim is the gaip*=
vs gaip=
where I can control the repeatability of the pattern, like this demo.
consider adding said functionality.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.