From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Dmitry Gutov Newsgroups: gmane.emacs.bugs Subject: bug#21391: 24.5; `thing-at-point' should return a string Date: Thu, 10 Nov 2016 01:30:20 +0200 Message-ID: <76505436-e66c-0ed3-6d7a-ce654f38ef30@yandex.ru> References: <0a68c2ae-0940-4e2c-8b3c-1faceb45c43c@default> <1773ab35-70b1-42f9-8a8b-fe07881487d1@default> <874m3krnb6.fsf_-_@gmail.com> <83a8dbiaps.fsf@gnu.org> <83pom7gjhl.fsf@gnu.org> <0a8d76e4-4d1b-a26d-2b76-a2d9384d9f72@yandex.ru> <83mvhbgitf.fsf@gnu.org> <25bb22e8-1388-275a-d0da-7e698acdf6da@yandex.ru> <83inrygggr.fsf@gnu.org> <83y40sfyij.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------F9952C605D30E7F792E52751" X-Trace: blaine.gmane.org 1478734293 12514 195.159.176.226 (9 Nov 2016 23:31:33 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 9 Nov 2016 23:31:33 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:50.0) Gecko/20100101 Thunderbird/50.0 Cc: tino.calancha@gmail.com, 21391@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Nov 10 00:31:29 2016 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1c4cL0-0002KX-9V for geb-bug-gnu-emacs@m.gmane.org; Thu, 10 Nov 2016 00:31:26 +0100 Original-Received: from localhost ([::1]:42982 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c4cL3-0004jH-DR for geb-bug-gnu-emacs@m.gmane.org; Wed, 09 Nov 2016 18:31:29 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:60174) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c4cKg-0004IC-Ob for bug-gnu-emacs@gnu.org; Wed, 09 Nov 2016 18:31:07 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c4cKc-0001yw-Id for bug-gnu-emacs@gnu.org; Wed, 09 Nov 2016 18:31:06 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:36016) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1c4cKc-0001yc-AX for bug-gnu-emacs@gnu.org; Wed, 09 Nov 2016 18:31:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1c4cKc-0008Bm-5P for bug-gnu-emacs@gnu.org; Wed, 09 Nov 2016 18:31:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Dmitry Gutov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 09 Nov 2016 23:31:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 21391 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 21391-submit@debbugs.gnu.org id=B21391.147873423031434 (code B ref 21391); Wed, 09 Nov 2016 23:31:02 +0000 Original-Received: (at 21391) by debbugs.gnu.org; 9 Nov 2016 23:30:30 +0000 Original-Received: from localhost ([127.0.0.1]:51414 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1c4cK5-0008Av-Ri for submit@debbugs.gnu.org; Wed, 09 Nov 2016 18:30:30 -0500 Original-Received: from mail-wm0-f44.google.com ([74.125.82.44]:37441) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1c4cK4-0008Ai-9a for 21391@debbugs.gnu.org; Wed, 09 Nov 2016 18:30:28 -0500 Original-Received: by mail-wm0-f44.google.com with SMTP id t79so330633595wmt.0 for <21391@debbugs.gnu.org>; Wed, 09 Nov 2016 15:30:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:subject:to:references:cc:from:message-id:date:user-agent :mime-version:in-reply-to:content-language; bh=+tPGMnAF6UpejGsLILfBs04G0w1amhG8osICaoGdeJU=; b=nF4QBZwMuP7d2V8E6SxqpPLlxmnnQNYi9FMofIQoBYYpcoUMBga7ZrEEOVIIla6MCM GI3kLEd/g3UyYQBbxuXQMBVq5ctGFp7WzQ2Y7LZRVuBGK3ugOk8fIbpMjX+NtJffDWVd PgQplqpeqAN1CpEDgedd4uBH9bQ7xWo1yZF2gqnH8j400/O/sqaM+oRvcZPMs5uzrmCC 9Os4m6Q67Wm8ciGkGFvpf9QLTeq0zc8qnwUiyvNthKqJ7Ie+mV9l6sOAMEKhflQmZbOe 8JBC7XSt7myHh+wWYc2NKDXg78MUDg5ViAxQY1MVPf5Q0G2MMkJzIFe8yXGZQjOXXR54 CRVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:subject:to:references:cc:from:message-id :date:user-agent:mime-version:in-reply-to:content-language; bh=+tPGMnAF6UpejGsLILfBs04G0w1amhG8osICaoGdeJU=; b=HsyRO4l+kyEgG84rL5ovo/eVF93VR6Guf028EWzU+pgYyhodd5OGRYkS8jmri+wKXl 8C8kBcZq9msn0sYa/Bh+vGBoNa+ZTP7ouBHStq//snSUkZoAG/XnMvE0lMfzGYYdTqKk kOy6OuUrZ9HdkyMAl06rkvcL3/nazRSc35+OoPBfHp94nCcLsAZdoLqEioWP49TOo9eI kRCcSD9ffz2RAHrM2yMOtReSQwUNvFFxJaXxfGAuyVXXBNjb1gj9e0f/gQzH+6Mwfts/ Zrs8FL8YNZw7McfdupwKlcUJ/Arejb//a37CJgoW6jbDtkVilA5bWLYQYb4gYnpioknB MOEA== X-Gm-Message-State: ABUngveZ8GXR7ltrlt1T9nZOtLyOnT+3oTW+VE0mQPLL3FnPq4Cj3HO30B4kiYmrpM08jw== X-Received: by 10.194.176.40 with SMTP id cf8mr1814940wjc.68.1478734222621; Wed, 09 Nov 2016 15:30:22 -0800 (PST) Original-Received: from [192.168.1.3] ([185.105.173.41]) by smtp.googlemail.com with ESMTPSA id w65sm2843459wmd.23.2016.11.09.15.30.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 09 Nov 2016 15:30:21 -0800 (PST) In-Reply-To: <83y40sfyij.fsf@gnu.org> Content-Language: en-US X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.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" Xref: news.gmane.org gmane.emacs.bugs:125537 Archived-At: This is a multi-part message in MIME format. --------------F9952C605D30E7F792E52751 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit On 09.11.2016 17:45, Eli Zaretskii wrote: > I don't think I understand what you are suggesting. Can you show a > proposed patch, so I could see the light? See the attached patch. Or to take a step further, we might want to deprecate the `thing-at-point' property, and recommend to only use the `bounds-of-thing-at-point' property. This way, we get the string-ness guarantee automatically, and the bounds-of-thing-at-point function will work for all things (it currently fails for `number'). >>> If >>> there is such code, why would we want to break it? To what end? And >>> if no code uses this loophole, why do we care that it exists? >> >> To make thing-at-point behavior more consistent. > > It is consistent now. Put point on a number. Number is a sexp. Not all sexps are strings. (thing-at-point 'number) => 123 (thing-at-point 'sexp) => "123" That doesn't looks consistent to me. And there's no way to guess the return value type in advance without knowing which exact function is the thing's `thing-at-point' property. > The only way to make it inconsistent is to have > a 'thing-at-point' property that violates that, but we never do that > in Emacs proper, so if someone else does that, it would be their bug. number's `thing-at-point' property is not like the others. --------------F9952C605D30E7F792E52751 Content-Type: text/x-diff; name="thingatpt-number.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="thingatpt-number.diff" diff --git a/lisp/thingatpt.el b/lisp/thingatpt.el index 9920fa0..1c630f7 100644 --- a/lisp/thingatpt.el +++ b/lisp/thingatpt.el @@ -128,7 +128,7 @@ bounds-of-thing-at-point ;;;###autoload (defun thing-at-point (thing &optional no-properties) - "Return the THING at point. + "Return the THING at point as a string. THING should be a symbol specifying a type of syntactic entity. Possibilities include `symbol', `list', `sexp', `defun', `filename', `url', `email', `word', `sentence', `whitespace', @@ -145,7 +145,7 @@ thing-at-point (let ((bounds (bounds-of-thing-at-point thing))) (when bounds (buffer-substring (car bounds) (cdr bounds))))))) - (when (and text no-properties (sequencep text)) + (when (and text no-properties) (set-text-properties 0 (length text) nil text)) text)) @@ -557,6 +557,14 @@ thing-at-point-email-regexp (put 'buffer 'end-op (lambda () (goto-char (point-max)))) (put 'buffer 'beginning-op (lambda () (goto-char (point-min)))) +;; Number + +(put 'number 'thing-at-point + (lambda () + (let ((thing (thing-at-point 'sexp))) + (when (numberp (thing-at-point--read-from-whole-string thing)) + thing)))) + ;; Aliases (defun word-at-point () @@ -604,7 +612,6 @@ symbol-at-point (defun number-at-point () "Return the number at point, or nil if none is found." (form-at-point 'sexp 'numberp)) -(put 'number 'thing-at-point 'number-at-point) ;;;###autoload (defun list-at-point () "Return the Lisp list at point, or nil if none is found." --------------F9952C605D30E7F792E52751--