NonGNU ELPA - evil-numbers

evil-numbers

Description
Increment/decrement numbers like in VIM
Latest
evil-numbers-0.6.tar, 2022-Jan-06, 40.0 KiB
Maintainer
Julia Path <julia@jpath.de>
Home page
http://github.com/juliapath/evil-numbers
Browse ELPA's repository
CGit or Gitweb
Badge

To install this package, run in Emacs:

M-x package-install RET evil-numbers RET

Full description

1 Features

  • Increment / Decrement binary, octal, decimal and hex literals.
  • Works like C-a / C-x in VIM, i.e. searches for number up to eol and then increments or decrements.
  • When a region is active, as in evil's visual mode, all the numbers within that region will be incremented/decremented (unlike in VIM).
  • Increment/decrement numbers incrementally like g C-a / g C-x in VIM.
  • Optionally keep zero padding (off by default).

1.1 Detected Literals

  • Binary, e.g. 0b0101, 0B0101.
  • Octal, e.g. 0o755, 0O700.
  • Hexadecimal, e.g. 0xDEADBEEF, 0XCAFE.
  • Unicode superscript and subscript, e.g. ² and .

2 Usage

Once this package is installed, all you need to do is bind keys to evil-numbers/inc-at-pt and evil-numbers/dec-at-pt.

Position cursor over or before the literal and play with your numbers!

You may also want to bind keys to the incremental versions of these functions.

2.1 Customization

evil-numbers-pad-default
Set to t if you want numbers to be padded with zeros (numbers with a leading zero are always padded). If you want both behaviors, all commands take an optional argument padded.
evil-numbers-separator-chars

This option to support separator characters, set to "_" or "," to support numeric literals such as: 16_777_216 or 4,294,967,296.

You may wish to set this as a buffer local variable to enable this only for languages that support separators.

evil-numbers-case
The case to use for hexadecimal numbers.
  • nil Current case (default).
  • 'upcase Always upper case.
  • 'downcase Always lower case.

2.2 Key Bindings

Example key bindings:

(global-set-key (kbd "C-c +") 'evil-numbers/inc-at-pt)
(global-set-key (kbd "C-c -") 'evil-numbers/dec-at-pt)
(global-set-key (kbd "C-c C-+") 'evil-numbers/inc-at-pt-incremental)
(global-set-key (kbd "C-c C--") 'evil-numbers/dec-at-pt-incremental)

or only in evil's normal & visual states:

(evil-define-key '(normal visual) 'global (kbd "C-c +") 'evil-numbers/inc-at-pt)
(evil-define-key '(normal visual) 'global (kbd "C-c -") 'evil-numbers/dec-at-pt)
(evil-define-key '(normal visual) 'global (kbd "C-c C-+") 'evil-numbers/inc-at-pt-incremental)
(evil-define-key '(normal visual) 'global (kbd "C-c C--") 'evil-numbers/dec-at-pt-incremental)

Keypad + and - present an alternative that can be directly bound without shadowing the regular + and -:

(evil-define-key '(normal visual) 'global (kbd "<kp-add>") 'evil-numbers/inc-at-pt)
(evil-define-key '(normal visual) 'global (kbd "<kp-subtract>") 'evil-numbers/dec-at-pt)
(evil-define-key '(normal visual) 'global (kbd "C-<kp-add>") 'evil-numbers/inc-at-pt-incremental)
(evil-define-key '(normal visual) 'global (kbd "C-<kp-subtract>") 'evil-numbers/dec-at-pt-incremental)

3 Install

3.1 Basic Installation

Put in load-path, (require 'evil-numbers) and set key bindings.

3.2 Use Package

Assuming you have the melpa repository enabled, use-package can be used as follows.

(use-package evil-numbers)

5 Contributors

  • Matthew Fidler <matthew.fidler@gmail.com>
  • Michael Markert <markert.michael@gmail.com>
  • Julia Path <julia@jpath.de>
  • Campbell Barton <ideasman42@gmail.com>

News

1 0.6

1.1 Additions

  • Add evil-numbers-separator-chars option to support separator characters, such as 16_777_216 or 4,294,967,296.
  • Add evil-numbers-case option for the case to use for hexadecimal values (defaults to the current case).

1.2 Fixes

  • Fix #25 increment steps to the next line.
  • Fix #24 hexadecimal values case changes when incrementing/decrementing.
  • Fix padding being ignored with block selection.
  • Fix #21 increment w/ selection ignores items before the cursor.
  • Fix padded argument is ignored on non-decimal types.
  • Fix #20 The cursor moves when increment/decrement fails.
  • Fix #18 operating on bin/hex/octal failed w/ the cursor at the start.
  • Fix #17 bin/octal/hex numbers don't support becoming negative.
  • Fix hyphen-separated numbers handling.
  • Fix auto-loading evil macros.

2 0.5

2.1 Additions

  • Make padding optional.
  • Add support for block selections.
  • Add support for subscript and superscript numbers.
  • Add g C-a like functionality (i.e. increment first number in selection by 1, second one by 2 and so on).
  • Pad negative numbers and add a plus sign if a negative number is turned into a positive number (if padding is enabled).

2.2 Fixes

  • Fix numbers being pushed out of selections.

    (e.g. calling inc-at-pt on ^9 9$ where ^$ denote the start and end of the selection would result in 10 9).