diff options
author | Thomas Voss <mail@thomasvoss.com> | 2024-09-23 14:10:43 +0200 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2024-09-23 14:10:43 +0200 |
commit | 064c30c54e43b0bf8da112d33005c0b09e624eed (patch) | |
tree | 63b6e3819ae89e656991f013b481139567d3743c /.config | |
parent | 8292b58022406cc6030f5ef7af63f9bb632807bd (diff) |
emacs: Don’t throw an error if there’s no number at point
Diffstat (limited to '.config')
-rw-r--r-- | .config/emacs/increment.el | 58 |
1 files changed, 29 insertions, 29 deletions
diff --git a/.config/emacs/increment.el b/.config/emacs/increment.el index ade0246..09def2d 100644 --- a/.config/emacs/increment.el +++ b/.config/emacs/increment.el @@ -45,35 +45,35 @@ the number at point has leading zeros then the width of the number is preserved." (interactive "*p") (save-match-data - (let* (hex-style - (case-fold-search nil) - (base (cond - ((thing-at-point-looking-at - "\\(-\\|\\b\\)0x\\(0*\\)\\([0-9a-f]+\\)\\b") - (setq hex-style 'lower) - 16) - ((thing-at-point-looking-at - "\\(-\\|\\b\\)0x\\(0*\\)\\([0-9A-Fa-f]+\\)\\b") - 16) - ((thing-at-point-looking-at - "\\(-?\\)\\(0*\\)\\([0-9]+\\)") - 10) - ((thing-at-point-looking-at - "\\(-\\|\\b\\)0o\\(0*\\)\\([0-7]+\\)\\b") - 8) - ((thing-at-point-looking-at - "\\(-\\|\\b\\)0b\\(0*\\)\\([01]+\\)\\b") - 2))) - (substr (buffer-substring-no-properties (match-beginning 3) - (match-end 3))) - (sign (if (= (match-beginning 1) (match-end 1)) +1 -1)) - (result (+ (* (string-to-number substr base) sign) - (or arg 1)))) - (replace-match (increment--format-number-with-base - result base - (- (match-end 2) - (match-beginning 2)) - substr hex-style))))) + (let (hex-style case-fold-search) + (when-let* ((base + (cond + ((thing-at-point-looking-at + "\\(-\\|\\b\\)0x\\(0*\\)\\([0-9a-f]+\\)\\b") + (setq hex-style 'lower) + 16) + ((thing-at-point-looking-at + "\\(-\\|\\b\\)0x\\(0*\\)\\([0-9A-Fa-f]+\\)\\b") + 16) + ((thing-at-point-looking-at + "\\(-?\\)\\(0*\\)\\([0-9]+\\)") + 10) + ((thing-at-point-looking-at + "\\(-\\|\\b\\)0o\\(0*\\)\\([0-7]+\\)\\b") + 8) + ((thing-at-point-looking-at + "\\(-\\|\\b\\)0b\\(0*\\)\\([01]+\\)\\b") + 2))) + (substr (buffer-substring-no-properties + (match-beginning 3) (match-end 3))) + (sign (if (= (match-beginning 1) (match-end 1)) +1 -1)) + (result (+ (* (string-to-number substr base) sign) + (or arg 1)))) + (replace-match (increment--format-number-with-base + result base + (- (match-end 2) + (match-beginning 2)) + substr hex-style)))))) ;;;###autoload (defun decrement-number-at-point (&optional arg) |