From f3c6b1870d5cbe1b52bc1ad244bd0310ffdec555 Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Mon, 28 Jul 2025 16:05:05 -0700 Subject: oni-core: Add functions to inc-/decrement number at point --- oni-core.el | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/oni-core.el b/oni-core.el index a62f8ef..8e7798b 100644 --- a/oni-core.el +++ b/oni-core.el @@ -4,7 +4,7 @@ ;; Author: Tom Willemse ;; Keywords: local -;; Version: 2025.0707.145555 +;; Version: 2025.0728.160458 ;; Package-Requires: (oni-data-dir oni-embrace oni-hydra expand-region multiple-cursors gcmh diminish ws-butler which-key insert-char-preview mixed-pitch ace-window vertico marginalia orderless consult embark docstr mini-frame) ;; This program is free software; you can redistribute it and/or modify @@ -103,6 +103,24 @@ (let ((inhibit-message t)) (recentf-save-list))) +(defun mutate-number-at-point (mutator) + (let ((bounds (bounds-of-thing-at-point 'symbol))) + (replace-region-contents + (car bounds) + (cdr bounds) + (lambda () + (number-to-string + (funcall mutator (string-to-number + (buffer-substring (point-min) (point-max))))))))) + +(defun increment-number-at-point () + (interactive) + (mutate-number-at-point '1+)) + +(defun decrement-number-at-point () + (interactive) + (mutate-number-at-point '1-)) + (defhydra oni-sort-and-align-hydra (:color teal :hint nil) " ^Sort^ @@ -218,6 +236,8 @@ _s_: String list" (global-set-key [remap upcase-word] #'upcase-dwim) (global-set-key [remap downcase-word] #'downcase-dwim) (global-set-key [remap capitalize-word] #'capitalize-dwim) +(global-set-key (kbd "C-c i +") #'increment-number-at-point) +(global-set-key (kbd "C-c i -") #'decrement-number-at-point) (global-set-key (kbd "C-") 'winner-undo) (global-set-key (kbd "C-") 'winner-redo) -- cgit v1.3-2-g0d8e