From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Drew Adams" Newsgroups: gmane.emacs.bugs Subject: bug#8634: 24.0.50; `number-at-point' returns char value for `?' constructs - 1) doc, 2) new fns Date: Sat, 7 May 2011 08:30:22 -0700 Message-ID: <458B95C58F7348C2AA62A340071C6E1C@us.oracle.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1304782279 16348 80.91.229.12 (7 May 2011 15:31:19 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sat, 7 May 2011 15:31:19 +0000 (UTC) To: 8634@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat May 07 17:31:12 2011 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1QIjTH-0001Jj-PL for geb-bug-gnu-emacs@m.gmane.org; Sat, 07 May 2011 17:31:08 +0200 Original-Received: from localhost ([::1]:45318 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QIjTH-0000Kl-4l for geb-bug-gnu-emacs@m.gmane.org; Sat, 07 May 2011 11:31:07 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]:37898) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QIjTE-0000KV-Bt for bug-gnu-emacs@gnu.org; Sat, 07 May 2011 11:31:05 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QIjTD-0003ls-GI for bug-gnu-emacs@gnu.org; Sat, 07 May 2011 11:31:04 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:51322) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QIjTD-0003lo-DZ for bug-gnu-emacs@gnu.org; Sat, 07 May 2011 11:31:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.69) (envelope-from ) id 1QIjTD-0006t1-4e; Sat, 07 May 2011 11:31:03 -0400 X-Loop: help-debbugs@gnu.org Resent-From: "Drew Adams" Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-To: owner@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 07 May 2011 15:31:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 8634 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: X-Debbugs-Original-To: Original-Received: via spool by submit@debbugs.gnu.org id=B.130478223926436 (code B ref -1); Sat, 07 May 2011 15:31:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 7 May 2011 15:30:39 +0000 Original-Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QIjSp-0006sK-2m for submit@debbugs.gnu.org; Sat, 07 May 2011 11:30:39 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QIjSn-0006s8-3V for submit@debbugs.gnu.org; Sat, 07 May 2011 11:30:37 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QIjSg-0003j9-VT for submit@debbugs.gnu.org; Sat, 07 May 2011 11:30:31 -0400 Original-Received: from lists.gnu.org ([140.186.70.17]:51432) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QIjSg-0003j5-Tv for submit@debbugs.gnu.org; Sat, 07 May 2011 11:30:30 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]:37807) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QIjSg-0000KL-3L for bug-gnu-emacs@gnu.org; Sat, 07 May 2011 11:30:30 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QIjSf-0003il-6g for bug-gnu-emacs@gnu.org; Sat, 07 May 2011 11:30:30 -0400 Original-Received: from rcsinet10.oracle.com ([148.87.113.121]:24133) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QIjSf-0003ih-1D for bug-gnu-emacs@gnu.org; Sat, 07 May 2011 11:30:29 -0400 Original-Received: from acsinet22.oracle.com (acsinet22.oracle.com [141.146.126.238]) by rcsinet10.oracle.com (Switch-3.4.2/Switch-3.4.2) with ESMTP id p47FUOJC020210 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Sat, 7 May 2011 15:30:26 GMT Original-Received: from acsmt358.oracle.com (acsmt358.oracle.com [141.146.40.158]) by acsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id p47FUNUs026890 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Sat, 7 May 2011 15:30:24 GMT Original-Received: from abhmt009.oracle.com (abhmt009.oracle.com [141.146.116.18]) by acsmt358.oracle.com (8.12.11.20060308/8.12.11) with ESMTP id p47FUI6M027896 for ; Sat, 7 May 2011 10:30:18 -0500 Original-Received: from dradamslap1 (/10.159.41.131) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Sat, 07 May 2011 08:30:17 -0700 X-Mailer: Microsoft Office Outlook 11 Thread-Index: AcwMy63TQPQmqp+rRSSD8kRUYJ5yjQ== X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.6090 X-Source-IP: acsinet22.oracle.com [141.146.126.238] X-Auth-Type: Internal IP X-CT-RefId: str=0001.0A090206.4DC56592.0093:SCFMA922111,ss=1,fgs=0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list Resent-Date: Sat, 07 May 2011 11:31:03 -0400 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:46308 Archived-At: `number-at-point' is defined like this: (defun number-at-point () "Return the number at point, or nil if none is found." (form-at-point 'sexp 'numberp)) That uses `read-from-string' for the sexp at point, and testing whether the result is `numberp'. That's fine, I guess, but it means that with buffer text such as ?A or ?\A-\^@ you get a non-nil result: the character value (wholenump) for ?A, which is 65, and 4194304, respectively. If you are depending on code to find _numerals_ in text and return their numeric values then this is not what you want. In that case, you want a function that returns nil when point is not on a numeral. The current behavior could admittedly be useful sometimes, but: 1. This should be mentioned in the doc string, as it's hardly what an uninformed user would expect, especially a newbie who doesn't yet know Emacs's char representation (`?.') and the fact that, for Emacs, chars are numbers. This behavior is not obvious, given the current doc and function name. 2. It might not be what the user or calling code really _wants_ in many (most?) cases. It's no doubt too late to change the name (e.g. to something like `number-or-char-at-point'). Some existing code probably depends on the current behavior. But it's not too late to add functions that do what many people might expect: return the number represented by the numeral at point, or nil if there is no numeral at point. Here are two functions that could be added. Whether you add them or not, please do mention the full behavior (with the gotcha) in the `number-at-point' doc string. (defun number-at-point-decimal () "Return the number represented by the decimal numeral at point. Return nil if none is found." (let ((strg (thing-at-point 'sexp))) (and (stringp strg) (if (fboundp 'string-match-p) (string-match-p "\\`[0-9]+\\'" strg) (string-match "\\`[0-9]+\\'" strg)) (string-to-number strg)))) (defun number-at-point-hex () "Return the number represented by the hex numeral at point. Return nil if none is found." (let ((strg (thing-at-point 'sexp))) (and (stringp strg) (if (fboundp 'string-match-p) (string-match-p "\\`[0-9a-fA-F]+\\'" strg) (string-match "\\`[0-9a-fA-F]+\\'" strg)) (string-to-number strg 16)))) In GNU Emacs 24.0.50.1 (i386-mingw-nt5.1.2600) of 2011-04-25 on 3249CTO Windowing system distributor `Microsoft Corp.', version 5.1.2600 configured using `configure --with-gcc (4.5) --no-opt --cflags -Ic:/imagesupport/include'