Skip to content

Commit 8844263

Browse files
committed
Fix json-increment-number-at-point to respect prefix arg
Fixes #62 Also fix for negative numbers.
1 parent f3fdc40 commit 8844263

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

json-mode.el

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ This function calls `json-mode--update-auto-mode' to change the
101101
(char ?\"))
102102
(zero-or-more blank)
103103
?\:))
104-
(defconst json-mode-number-re (rx (group (one-or-more digit)
104+
(defconst json-mode-number-re (rx (group (optional ?-)
105+
(one-or-more digit)
105106
(optional ?\. (one-or-more digit)))))
106107
(defconst json-mode-keyword-re (rx (group (or "true" "false" "null"))))
107108

@@ -230,7 +231,7 @@ json font lock syntactic face function."
230231
((setq symbol (bounds-of-thing-at-point 'symbol))
231232
(cond
232233
((looking-at-p "null"))
233-
((save-excursion (skip-chars-backward "[0-9.]") (looking-at json-mode-number-re))
234+
((save-excursion (skip-chars-backward "[-0-9.]") (looking-at json-mode-number-re))
234235
(kill-region (match-beginning 0) (match-end 0))
235236
(insert "null"))
236237
(t (kill-region (car symbol) (cdr symbol)) (insert "null"))))
@@ -244,8 +245,8 @@ json font lock syntactic face function."
244245

245246
(defun json-increment-number-at-point (&optional delta)
246247
"Add DELTA to the number at point; DELTA defaults to 1."
247-
(interactive)
248-
(when (save-excursion (skip-chars-backward "[0-9.]") (looking-at json-mode-number-re))
248+
(interactive "P")
249+
(when (save-excursion (skip-chars-backward "[-0-9.]") (looking-at json-mode-number-re))
249250
(let ((num (+ (or delta 1)
250251
(string-to-number (buffer-substring-no-properties (match-beginning 0) (match-end 0)))))
251252
(pt (point)))
@@ -255,10 +256,10 @@ json font lock syntactic face function."
255256

256257
(define-key json-mode-map (kbd "C-c C-i") 'json-increment-number-at-point)
257258

258-
(defun json-decrement-number-at-point ()
259+
(defun json-decrement-number-at-point (&optional delta)
259260
"Decrement the number at point."
260-
(interactive)
261-
(json-increment-number-at-point -1))
261+
(interactive "P")
262+
(json-increment-number-at-point (- (or delta 1))))
262263

263264
(define-key json-mode-map (kbd "C-c C-d") 'json-decrement-number-at-point)
264265

0 commit comments

Comments
 (0)