summaryrefslogtreecommitdiff
path: root/lisp/thingatpt.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/thingatpt.el')
-rw-r--r--lisp/thingatpt.el15
1 files changed, 11 insertions, 4 deletions
diff --git a/lisp/thingatpt.el b/lisp/thingatpt.el
index 319f4b2cf8a..1ce4b98fd1b 100644
--- a/lisp/thingatpt.el
+++ b/lisp/thingatpt.el
@@ -632,10 +632,17 @@ Signal an error if the entire string was not used."
(if thing (intern thing))))
;;;###autoload
(defun number-at-point ()
- "Return the number at point, or nil if none is found."
- (when (thing-at-point-looking-at "-?[0-9]+\\.?[0-9]*" 500)
- (string-to-number
- (buffer-substring (match-beginning 0) (match-end 0)))))
+ "Return the number at point, or nil if none is found.
+Decimal numbers like \"14\" or \"-14.5\", as well as hex numbers
+like \"0xBEEF09\" or \"#xBEEF09\", are regognized."
+ (when (thing-at-point-looking-at
+ "\\(-?[0-9]+\\.?[0-9]*\\)\\|\\(0x\\|#x\\)\\([a-zA-Z0-9]+\\)" 500)
+ (if (match-beginning 1)
+ (string-to-number
+ (buffer-substring (match-beginning 1) (match-end 1)))
+ (string-to-number
+ (buffer-substring (match-beginning 3) (match-end 3))
+ 16))))
(put 'number 'thing-at-point 'number-at-point)
;;;###autoload