Subject: bug#8634: 24.0.50; `number-at-point' returns char value for `?' constructs - 1) doc, 2) new fns

From: Nicolas Richard <[email-masked]>
Date: Mon, 10 Feb 2014 15:27:27 +0100

Drew Adams <[email-masked]> writes:

>> I just tried saying the same in the *scratch* buffer, and there it
>> returns 65!
>> 
>> Here in the Message buffer it returns nil.  It does in a
>> fundamental-mode buffer, too...
>
> Sounds like we might be getting somewhere now.  Something in
> certain buffers causes `number-at-point' to do the wrong thing.

That is because number-at-point uses the 'sexp at point, which depends
on the syntax table.

The following definition seems to fix that dependance (500 is arbitrary
choice -- the same arbitrary choice as for emails) :

diff --git a/lisp/thingatpt.el b/lisp/thingatpt.el
index 9a40049..7b4cf56 100644
--- a/lisp/thingatpt.el
+++ b/lisp/thingatpt.el
@@ -581,7 +581,10 @@ Signal an error if the entire string was not used."
 ;;;###autoload
 (defun number-at-point ()
   "Return the number at point, or nil if none is found."
-  (form-at-point 'sexp 'numberp))
+  (when (thing-at-point-looking-at "-?[0-9]+\\.?[0-9]*" 500)
+    (string-to-number
+     (buffer-substring (match-beginning 0) (match-end 0)))))
+
 (put 'number 'thing-at-point 'number-at-point)
 ;;;###autoload
 (defun list-at-point ()

-- 
Nico.