[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/evil-numbers 221ceb6177 001/145: Initial commit.
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/evil-numbers 221ceb6177 001/145: Initial commit. |
Date: |
Thu, 6 Jan 2022 03:00:13 -0500 (EST) |
branch: elpa/evil-numbers
commit 221ceb6177a97029d28bd1a245211e5f7f58ca63
Author: Michael Markert <markert.michael@googlemail.com>
Commit: Michael Markert <markert.michael@googlemail.com>
Initial commit.
Adapted from gist.
Signed-off-by: Michael Markert <markert.michael@googlemail.com>
---
.gitignore | 1 +
evil-numbers.el | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 104 insertions(+)
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000000..c531d9867f
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+*.elc
diff --git a/evil-numbers.el b/evil-numbers.el
new file mode 100644
index 0000000000..d59e9da48f
--- /dev/null
+++ b/evil-numbers.el
@@ -0,0 +1,103 @@
+;; evil-numbers -- increment/decrement numbers like in vim
+
+;; Copyright (C) 2011 by Michael Markert
+;; Author: 2011 Michael Markert <markert.michael@googlemail.com>
+;; Created: 2011-09-02
+;; Version: 0.
+;; Keywords: numbers increment decrement octal hex binary
+
+;; This file is not part of GNU Emacs.
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation; either version 2 of the License, or
+;; (at your option) any later version.
+;;
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+;;
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs; see the file COPYING. If not, write to the
+;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+;; Boston, MA 02111-1307, USA.
+
+;; Known Bugs:
+;; See http://github.com/cofi/evil-numbers/issues
+
+;; Install:
+
+;; Usage:
+
+;; Homepage: http://github.com/cofi/evil-numbers
+;; Git-Repository: git://github.com/cofi/evil-numbers.git
+
+(defun evil-numbers/inc-at-pt (amount)
+ "Increment the number at point by `amount'"
+ (interactive "p*")
+ (save-match-data
+ (or
+ ;; find binary literals
+ (when (looking-back "0[bB][01]*")
+ ;; already ensured there's only one -
+ (skip-chars-backward "01")
+ (search-forward-regexp "[01]*")
+ (replace-match
+ (evil-numbers/format-binary (+ amount (string-to-number (match-string
0) 2))
+ (- (match-end 0) (match-beginning 0))))
+ t)
+
+ ;; find octal literals
+ (when (looking-back "0[oO]-?[0-7]*")
+ ;; already ensured there's only one -
+ (skip-chars-backward "-01234567")
+ (search-forward-regexp "-?\\([0-7]+\\)")
+ (replace-match
+ (format (format "%%0%do" (- (match-end 1) (match-beginning 1)))
+ (+ amount (string-to-number (match-string 0) 8))))
+ t)
+
+ ;; find hex literals
+ (when (looking-back "0[xX]-?[0-9a-fA-F]*")
+ ;; already ensured there's only one -
+ (skip-chars-backward "-0123456789abcdefABCDEF")
+ (search-forward-regexp "-?\\([0-9a-fA-F]+\\)")
+ (replace-match
+ (format (format "%%0%dX" (- (match-end 1) (match-beginning 1)))
+ (+ amount (string-to-number (match-string 0) 16))))
+ t)
+
+ ;; find decimal literals
+ (progn
+ (skip-chars-backward "0123456789")
+ (skip-chars-backward "-")
+ (when (looking-at "-?\\([0-9]+\\)")
+ (replace-match
+ (format (format "%%0%dd" (- (match-end 1) (match-beginning 1)))
+ (+ amount (string-to-number (match-string 0) 10))))
+ t))
+ (error "No number at point"))))
+
+(defun evil-numbers/format-binary (number &optional width fillchar)
+ "Format `NUMBER' as binary.
+Fill up to `WIDTH' with `FILLCHAR' (defaults to ?0) if binary
+representation of `NUMBER' is smaller."
+ (let (nums
+ (fillchar (or fillchar ?0)))
+ (do ((num number (truncate num 2)))
+ ((= num 0))
+ (push (number-to-string (% num 2)) nums))
+ (let ((len (length nums)))
+ (apply #'concat
+ (if (and width (< len width))
+ (make-string (- width len) fillchar)
+ "")
+ nums))))
+
+(defun evil-numbers/dec-at-pt (amount)
+ "Decrement the number at point by `amount'"
+ (interactive "p*")
+ (evil-numbers/inc-at-pt (- amount)))
+
+(provide evil-numbers)
- [nongnu] elpa/evil-numbers fd742943fd 127/145: README.org use definition lists for options, (continued)
- [nongnu] elpa/evil-numbers fd742943fd 127/145: README.org use definition lists for options, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-numbers cd23a7b458 136/145: README.org: update poor wording, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-numbers 9841266544 113/145: Cleanup: replace catch/throw with a 'found' variable, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-numbers 9cf802c29d 119/145: Fix #24 hexadecimal values case when incrementing/decrementing, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-numbers 6ea1c8c3a9 036/145: Use list for contributers., ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-numbers a2ce896e05 049/145: Update documentation, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-numbers ac4101f0e4 052/145: Explicitly require evil., ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-numbers 4fd2d402fe 050/145: Add CHANGELOG, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-numbers 8b59acf267 059/145: fix: handle hyphen-separated numbers correctly, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-numbers e0f4ba3d13 004/145: Fix number search., ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-numbers 221ceb6177 001/145: Initial commit.,
ELPA Syncer <=
- [nongnu] elpa/evil-numbers 7e7e2e42f3 005/145: Remove "support" for negative non-decimal literals., ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-numbers 4466368c6d 008/145: Adjust error messages., ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-numbers db0c5adc68 029/145: Add documentation the increment of region., ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-numbers d37c9812a1 024/145: Remove superflous but malicious check., ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-numbers 649c01ee4a 028/145: deactivate-mark when operating on region, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-numbers ecc51feda6 020/145: Fix glitches., ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-numbers 8ef07f7883 019/145: Prepare for elpa submission., ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-numbers caa4679814 031/145: Merge pull request #3 from mlf176f2/evil-numbers-in-region, ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-numbers 2543f0bf35 016/145: Fix number search., ELPA Syncer, 2022/01/06
- [nongnu] elpa/evil-numbers e40b606d92 025/145: Add readme., ELPA Syncer, 2022/01/06