项目作者: edkolev

项目描述 :
Evil align operator
高级语言: Emacs Lisp
项目地址: git://github.com/edkolev/evil-lion.git
创建时间: 2017-03-09T11:31:44Z
项目社区:https://github.com/edkolev/evil-lion

开源协议:

下载


Build Status
MELPA

Emacs evil alignment operator

evil-lion

This package provides gl and gL align operators: gl MOTION CHAR and right-align gL MOTION CHAR.

Use CHAR / to enter regular expression if a single character wouldn’t suffice.

Use CHAR RET to align with align.el’s default rules for the active major mode.

Port of vim-lion

scar

Installation

with use-package

  1. (use-package evil-lion
  2. :ensure t
  3. :config
  4. (evil-lion-mode))

without use-package

M-x package-install RET evil-lion RET, then add in init.el:

(evil-lion-mode)

Usage

Align with gl MOTION CHAR or right-align with gL MOTION CHAR.

If the align separator is / you will be prompted for a regular expression instead of a plain character.
If the align separator is RET alignment will be performed with align.el’s rules specific for the major mode.

You can pass count 1 to align on the first occurrence of CHAR. To pass count, use: COUNT gl MOTION CHAR.

Example, left align gl:

After pressing glip= (gl is the operator, ip text object paragraph, = separator)

  1. one = 1
  2. three = 3
  3. fifteen = 15

will become:

  1. one = 1
  2. three = 3
  3. fifteen = 15

Example, right align with gL:

After pressing gLip,

  1. one, two, three,
  2. fifteen, sixteen, seventeen

will become:

  1. one, two, three,
  2. fifteen, sixteen, seventeen

Example, align with major mode’s alignment rules:

In perl-mode, after pressing glib RET (RET is return key, not individal keys):

  1. my %hash = (
  2. a => 1,
  3. bbb => 2,
  4. cccc => 3,
  5. a => 1,
  6. bbb => 2,
  7. cccccc => 3
  8. );

will become:

  1. my $hash = (
  2. a => 1,
  3. bbb => 2,
  4. cccc => 3,
  5. a => 1,
  6. bbb => 2,
  7. cccccc => 3
  8. ););

Example, align on the first occurrence of CHAR:

After pressing 1glip"

  1. (red "red"
  2. (teal-green "#6fb593")
  3. (wheat "#b9c791")
  4. (blue "blue")
  5. (cyan "#54b6b6")

will become:

  1. (red "red"
  2. (teal-green "#6fb593")
  3. (wheat "#b9c791")
  4. (blue "blue")
  5. (cyan "#54b6b6")

Customization

Disable squeezing of spaces

By default, evil-lion will remove unnecessary spaces if there are any. To disable this behaviour:

  1. (setq evil-lion-squeeze-spaces nil) ;; default t

Change the default keys

  1. ;; use `g a` (mnemonic `align`)
  2. ;; these variables should be changed before (evil-lion-mode) is called
  3. (setq evil-lion-left-align-key (kbd "g a"))
  4. (setq evil-lion-right-align-key (kbd "g A"))
  5. (evil-lion-mode)

Or withuse-package and bind-key:

  1. (use-package evil-lion
  2. :ensure t
  3. :bind (:map evil-normal-state-map
  4. ("g l " . evil-lion-left)
  5. ("g L " . evil-lion-right)
  6. :map evil-visual-state-map
  7. ("g l " . evil-lion-left)
  8. ("g L " . evil-lion-right)))

Bind in prog modes only

Bind evil-lion-left and evil-lion-right to your liking.
The evil-lion-mode is just a convenience mode and should not be enabled with this setup.

  1. (evil-define-key 'normal prog-mode-map
  2. (kbd "g l") 'evil-lion-left
  3. (kbd "g L") 'evil-lion-right)
  4. (evil-define-key 'visual prog-mode-map
  5. (kbd "g l") 'evil-lion-left
  6. (kbd "g L") 'evil-lion-right)