Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'g C-a' like incremental increment functionality, support block selections, and more #11

Open
wants to merge 127 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
127 commits
Select commit Hold shift + click to select a range
84bb03c
Add incremental increasing like `g C-a' in vim
juliapath May 4, 2016
ff37f83
Add incremental increase feature to README
juliapath May 4, 2016
b754f53
support for increasing superscripts
unhammer Jun 3, 2016
cfa8650
Remove extra &optional
Nov 5, 2018
31c7f1a
Fix wrong handling of region if number of characters changes
Nov 5, 2018
7ff262f
Support block selections
Nov 8, 2018
e5dd1e2
Fix changing the number directly behind us
Nov 10, 2018
cbbfd83
Merge https://github.com/unhammer/evil-numbers
Nov 10, 2018
9e2d6f7
Support negative superscripts and fix padding of negative numbers
Nov 10, 2018
f033965
Support subscript numbers
Nov 11, 2018
8da2221
Make padding optional and off by default (can be configured)
Nov 12, 2018
154703d
Make binary, octal and hexadecimal numbers honour padDefault
Nov 12, 2018
a2ce896
Update documentation
Nov 12, 2018
4fd2d40
Add CHANGELOG
Nov 12, 2018
9478e05
Fix documentation markup. Closes #2
Jan 8, 2019
ac4101f
Explicitly require evil.
leungbk Mar 12, 2019
4a17780
Merge pull request #5 from leungbk/require
Mar 12, 2019
fb16206
Fix autoloading
Mar 12, 2019
ebfb368
Create evil-numbers customisation group
Mar 12, 2019
d988041
List myself as maintainer
Mar 12, 2019
d1b1f50
Autoload operators as interactive commands
Apr 13, 2020
c2cfdd1
Merge pull request #6 from hlissner/patch-1
Apr 14, 2020
8b59acf
fix: handle hyphen-separated numbers correctly
midchildan Jul 11, 2020
006da40
Merge pull request #7 from midchildan/fix/hyphens
Jul 19, 2020
4308935
Resolve looking-back warnings
ideasman42 May 6, 2021
02de70f
Quiet checkdoc warnings
ideasman42 May 6, 2021
aa94cd1
Merge pull request #11 from ideasman42/patch-1
juliapath May 6, 2021
37d148f
Merge branch 'master' into patch-2
juliapath May 6, 2021
c6ba8e3
Merge pull request #13 from ideasman42/patch-2
juliapath May 6, 2021
26ec2d4
Use lexical binding, remove unused function 'pad'
ideasman42 May 6, 2021
74cd618
Merge pull request #14 from ideasman42/patch-3
juliapath May 10, 2021
ff3bcf4
Change repo URLs
juliapath May 11, 2021
963e78c
Change repo URLs in Readme too
juliapath May 11, 2021
5622da3
Cleanup: spelling, use full sentences
ideasman42 May 12, 2021
a75c4b0
Cleanup: replace tabs with spaces
ideasman42 May 12, 2021
f33d013
Cleanup: quiet package-lint warnings
ideasman42 May 12, 2021
6fa8e02
Cleanup: avoid right shift
ideasman42 May 12, 2021
ab6d436
Cleanup: use '--' separator for private functions
ideasman42 May 12, 2021
3a0c5a8
Merge pull request #16 from juliapath/temp-priv-vars
juliapath May 12, 2021
b54cc5b
Fix spelling
juliapath May 12, 2021
5356111
Cleanup: avoid let binding to set default values for arguments
ideasman42 May 13, 2021
b1ba250
Cleanup: reduce right shift
ideasman42 May 13, 2021
cc930fb
Cleanup: use 'rx' for number search regex
ideasman42 May 14, 2021
027f8d5
Fix #18 operating on bin/hex/octal failed w/ the cursor at the start
ideasman42 May 14, 2021
e8dfba5
Cleanup: split skip characters matching out into a function
ideasman42 May 15, 2021
445943f
Fix #17 bin/octal/hex numbers don't support becoming negative
ideasman42 May 15, 2021
adda2cc
Cleanup: use private function name
ideasman42 May 15, 2021
626ea72
Cleanup: add missing argument to doc-string
ideasman42 May 15, 2021
6093a5e
Cleanup: use identity functions
ideasman42 May 16, 2021
11fc45c
Cleanup: move subscript encode/decode into utility functions
ideasman42 May 16, 2021
15dcea1
Fix #20 The cursor moves when increment/decrement fails
ideasman42 May 16, 2021
bea0c10
Cleanup: use term amount for both decimal/(hex/bin/octal) functions
ideasman42 May 16, 2021
1520c24
Fix padded argument is ignored on non-decimal types
ideasman42 May 16, 2021
a6cf01f
Fix #21 increment w/ selection ignores items before the cursor
ideasman42 May 16, 2021
3fe5621
Cleanup: docstring
ideasman42 May 16, 2021
c37a4cf
Fix padding being ignored with block selection
ideasman42 May 16, 2021
299e041
Cleanup: remove duplicate number search logic
ideasman42 May 16, 2021
b2397f2
Cleanup: move forward character check in evil-numbers--search-number
ideasman42 May 16, 2021
819530c
Cleanup: use xdigit for matching hexidecimal
ideasman42 May 16, 2021
83e98f9
Correct invalid limit argument to `looking-back'
ideasman42 May 16, 2021
8403eeb
Correct oversight in 299e0418caa43cb7c15dd21d2dd40b75b147990f
ideasman42 May 16, 2021
b87c8b7
Use ORG mode for the CHANGELOG
ideasman42 May 16, 2021
0934e38
README: various minor updates
ideasman42 May 16, 2021
7ca411f
CHANGELOG: use fullstops
ideasman42 May 16, 2021
7602f3b
Cleanup: split number incrementing into it's own function
ideasman42 May 16, 2021
ad15824
Cleanup: share code-paths for decimal and bin/hex/octal encoding
ideasman42 May 16, 2021
6483ab6
Cleanup: use '?' instead of '*' for matching sign
ideasman42 May 17, 2021
b98a3dc
Cleanup: forward limits to evil-numbers--search-and-replace
ideasman42 May 17, 2021
4303612
Cleanup: line length < 80, spelling
ideasman42 May 17, 2021
a01fa6b
Rename evil-numbers/padDefault to evil-numbers-pad-default
ideasman42 May 17, 2021
af088b7
Cleanup: < 80 chars, reduce right shift
ideasman42 May 17, 2021
8d84bd3
Cleanup: remove strict number searching logic
ideasman42 May 17, 2021
0bbf3a8
Cleanup: store unicode subscript/superscript in constants
ideasman42 May 17, 2021
79daec8
Cleanup: sort code into sections
ideasman42 May 17, 2021
a427fda
Update README.org
ideasman42 May 17, 2021
b88595d
Cleanup: reduce vertical space use
ideasman42 May 17, 2021
9841266
Cleanup: replace catch/throw with a 'found' variable
ideasman42 May 17, 2021
01c6892
README.org: update keymap examples
ideasman42 May 17, 2021
43ae060
README.org: keypad can be used for other platforms too
ideasman42 May 18, 2021
0d66b63
CHANGELOG.org: update with recent fixes
ideasman42 May 18, 2021
70b9862
Cleanup: declare nums as `(list)` for readability
ideasman42 May 18, 2021
d5c40d2
Cleanup: docstring line wrapping
ideasman42 May 18, 2021
9cf802c
Fix #24 hexadecimal values case when incrementing/decrementing
ideasman42 May 19, 2021
6ff686b
Cleanup: remove autoload on defcustom
ideasman42 May 19, 2021
f485043
Add evil-numbers-case option
ideasman42 May 19, 2021
c39f8f1
Cleanup: auto-indent the changelog
ideasman42 May 19, 2021
a65dbc5
Cleanup: remove nil for empty body
ideasman42 May 19, 2021
11883bc
Fix incremental regression in cleanup from 7602f3b4842f4ec149d3b8ed32…
ideasman42 May 19, 2021
d09a0e6
Fix #25 increment steps to the next line
ideasman42 May 20, 2021
407d622
Add separator character support (issue #23)
ideasman42 May 20, 2021
fd74294
README.org use definition lists for options
ideasman42 May 20, 2021
1acf906
Bump to 0.6
ideasman42 May 20, 2021
d7a3e6d
Add evil to requirements
ideasman42 May 20, 2021
623bcbd
README: add "similar packages" section
ideasman42 May 21, 2021
48b528b
Refactor: instead of passing an amount, pass in a function
ideasman42 Jun 3, 2021
1bf577a
Fix #26: Optionally match characters directly before the cursor
ideasman42 Jun 3, 2021
e1b60f3
Fix #27 Number directly before the cursor manipulated in some cases
ideasman42 Jun 4, 2021
3bd9472
Cleanup: indentation
ideasman42 Jun 4, 2021
ef72a4f
Cleanup: correct doc-strings
ideasman42 Jun 5, 2021
cd23a7b
README.org: update poor wording
ideasman42 Jun 5, 2021
bce451b
Use message instead of error when no number is found
ideasman42 Aug 8, 2021
29859e6
Add automated tests, resolve #22
ideasman42 Aug 8, 2021
061de6f
Tests: watch evil-numbers.el as well as the tests
ideasman42 Aug 9, 2021
6087ef4
Tests: run increment operations at different offsets
ideasman42 Aug 9, 2021
cb9eb99
Tests: add simple-nop-non-number-with-newline-after test
ideasman42 Aug 9, 2021
9423e4c
Tests: add simple-hex-negative-to-positive
ideasman42 Aug 9, 2021
8ce0066
Tests: rename evil-numbers-test.el to evil-numbers-tests.el
ideasman42 Aug 9, 2021
8761f55
Cleanup: redundant group usage
ideasman42 Oct 11, 2021
08f0c1e
Cleanup: warnings for tests
ideasman42 Oct 11, 2021
a6c886d
Add Makefile for "make test"
ideasman42 Jul 11, 2022
061f523
Cleanup: quiet un-escaped quote warning
ideasman42 Jul 11, 2022
61dde4e
Bump to 0.7
ideasman42 Jul 11, 2022
bfbe8ea
Cleanup: move requirement for ert and evil-numbers into the test
ideasman42 Jul 31, 2022
7bd9bb0
Cleanup: use pcase-dolist
ideasman42 Jul 31, 2022
434298e
Auto format using elisp-autofmt
ideasman42 Jan 13, 2023
dbe39b0
Cleanup: replace 'if' with 'cond'
ideasman42 Jan 13, 2023
9bebb3a
Cleanup: remove redundant `format` and quoted lambda
ideasman42 Jan 13, 2023
743e605
Cleanup: replace point-at-bol/eol with pos-bol/eol
ideasman42 Jan 13, 2023
5ddc167
Fix compatibility for pos-bol/eol for emacs <29.1
ideasman42 Jan 13, 2023
af8d71b
Cleanup: remove redundant :options for boolean
ideasman42 Jan 16, 2023
ee2c027
Cleanup: reformat with updated elisp-autofmt
ideasman42 Jan 16, 2023
8724645
Cleanup: tweak to argument grouping
ideasman42 Jan 17, 2023
1f78ca1
Cleanup: disable auto-wrapping for blocks for readability
ideasman42 Jan 31, 2023
7a1b62a
Cleanup: reduce vertical space of `concat` use in tests
ideasman42 Feb 1, 2023
cc58cc7
Cleanup: use SPDX license header
ideasman42 Apr 16, 2024
b6fcd2e
Cleanup: use a single comment block for "Commentary"
ideasman42 Apr 16, 2024
c789989
Header: add myself as a contributor
ideasman42 Apr 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added .elisp-autofmt
Empty file.
49 changes: 49 additions & 0 deletions CHANGELOG.org
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#+TITLE: Evil Numbers CHANGELOG

* 0.7

** Additions
+ =evil-numbers-use-cursor-at-end-of-number= option to match numbers directly before the cursor
(diverging from VIM's default behavior).

** Changes
+ Use =message= instead of =error= when no number is found
(don't error since VIM doesn't use an error in this case).

** Fixes
+ Fix #27 Number directly before the cursor manipulated when the cursor can't move forward.

* 0.6

** 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).

** 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.

* 0.5

** 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).

** 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=).
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# SPDX-License-Identifier: GPL-2.0-or-later

test:
./tests/evil-numbers-tests.sh
111 changes: 86 additions & 25 deletions README.org
Original file line number Diff line number Diff line change
@@ -1,47 +1,108 @@
* Evil Numbers
- Increment / Decrement binary, octal, decimal and hex literals
#+TITLE: Evil Numbers

- works like C-a/C-x in vim, i.e. searches for number up to eol and then
increments or decrements and keep zero padding up (unlike in vim)
* 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)
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).


** Detected Literals
- binary, e.g. =0b0101=, =0B0101=
- octal, e.g. =0o755=, =0O700=
- hexadecimal, e.g. =0xDEADBEEF=, =0XCAFE=
- Binary, e.g. =0b0101=, =0B0101=.
- Octal, e.g. =0o755=, =0O700=.
- Hexadecimal, e.g. =0xDEADBEEF=, =0XCAFE=.
- Unicode superscript and subscript, e.g. =²= and =₁=.

* 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.

** 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.

** Install
Put in =load-path=, =(require 'evil-numbers)= and bind, for example:
- =evil-numbers-case= ::
The case to use for hexadecimal numbers.

- =nil= Current case (default).
- '=upcase= Always upper case.
- '=downcase= Always lower case.

- =evil-numbers-use-cursor-at-end-of-number= ::
Support matching numbers directly before the cursor.

This is off by default as it doesn't follow VIM's behavior.

** Key Bindings
Example key bindings:

#+BEGIN_SRC emacs-lisp
(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)
#+END_SRC

or only in evil's =normal= & =visual= states:

#+BEGIN_SRC emacs-lisp
(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)
#+END_SRC

or only in evil's normal state:
Keypad =+= and =-= present an alternative that can be directly bound without shadowing the regular =+= and =-=:

#+BEGIN_SRC emacs-lisp
(define-key evil-normal-state-map (kbd "C-c +") 'evil-numbers/inc-at-pt)
(define-key evil-normal-state-map (kbd "C-c -") 'evil-numbers/dec-at-pt)
(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)
#+END_SRC

For window system users the keypad =+= and =-= present an alternative that can be
directly bound without shadowing the regular =+= and =-=:
* Install

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

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

#+BEGIN_SRC emacs-lisp
(define-key evil-normal-state-map (kbd "<kp-add>") 'evil-numbers/inc-at-pt)
(define-key evil-normal-state-map (kbd "<kp-subtract>") 'evil-numbers/dec-at-pt)
(use-package evil-numbers)
#+END_SRC

** Usage
Position cursor on literal and play with your numbers!
* Known Bugs
See http://github.com/juliapath/evil-numbers/issues

** Known Bugs
See http://github.com/cofi/evil-numbers/issues
* Similar Packages
- [[https://melpa.org/#/mouse-slider-mode][Mouse Slider Package]]
- [[https://melpa.org/#/number][Number Package]]
- [[https://melpa.org/#/shift-number][Shift Number Package]]
- [[https://www.emacswiki.org/emacs/IncrementNumber][Emacs Wiki (Increment Number)]]

** Contributors
- Matthew Fidler <[email protected]>
- Michael Markert <[email protected]>
* Contributors
- Matthew Fidler <[email protected]>
- Michael Markert <[email protected]>
- Julia Path <[email protected]>
- Campbell Barton <[email protected]>
Loading