From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Tino Calancha Newsgroups: gmane.emacs.bugs Subject: bug#21391: 24.5; `thing-at-point' should return a string Date: Mon, 07 Nov 2016 12:17:17 +0900 Message-ID: <874m3krnb6.fsf_-_@gmail.com> References: <0a68c2ae-0940-4e2c-8b3c-1faceb45c43c@default> <1773ab35-70b1-42f9-8a8b-fe07881487d1@default> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1478488721 14700 195.159.176.226 (7 Nov 2016 03:18:41 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 7 Nov 2016 03:18:41 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) Cc: Tino Calancha To: 21391@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Nov 07 04:18:36 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 1c3aRk-00008G-9z for geb-bug-gnu-emacs@m.gmane.org; Mon, 07 Nov 2016 04:18:08 +0100 Original-Received: from localhost ([::1]:50692 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c3aRn-00030a-7j for geb-bug-gnu-emacs@m.gmane.org; Sun, 06 Nov 2016 22:18:11 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:36212) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c3aRh-0002zI-7r for bug-gnu-emacs@gnu.org; Sun, 06 Nov 2016 22:18:06 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c3aRe-0003fj-34 for bug-gnu-emacs@gnu.org; Sun, 06 Nov 2016 22:18:05 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:60192) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1c3aRd-0003el-Vp for bug-gnu-emacs@gnu.org; Sun, 06 Nov 2016 22:18:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1c3aRd-0008Kg-M3 for bug-gnu-emacs@gnu.org; Sun, 06 Nov 2016 22:18:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Tino Calancha Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 07 Nov 2016 03:18:01 +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.147848865031992 (code B ref 21391); Mon, 07 Nov 2016 03:18:01 +0000 Original-Received: (at 21391) by debbugs.gnu.org; 7 Nov 2016 03:17:30 +0000 Original-Received: from localhost ([127.0.0.1]:47358 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1c3aR7-0008Jv-UI for submit@debbugs.gnu.org; Sun, 06 Nov 2016 22:17:30 -0500 Original-Received: from mail-pf0-f170.google.com ([209.85.192.170]:36025) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1c3aR5-0008Jj-K0 for 21391@debbugs.gnu.org; Sun, 06 Nov 2016 22:17:28 -0500 Original-Received: by mail-pf0-f170.google.com with SMTP id 189so83706112pfz.3 for <21391@debbugs.gnu.org>; Sun, 06 Nov 2016 19:17:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:references:cc:date:in-reply-to:message-id :user-agent:mime-version; bh=pKpklgzbEySA/7eE6fDAb8THopO4TjzVJ4ZgnIL21KQ=; b=PDSbmmczzZPIX7JHbvSUeZkMPhm8YvLlAJ11F42EvI8B1pf//92UY2kG56VYzZ1RaX s37P86z3FC/V+nzo+XPZzqHn/jCGeKefabwGUN6pDq33a7kUYchEQg3UHB5MpkmgCYkx ICceIaGOYCUvyj9my3gUwnLnDqJOB3pp9WadwnwEzE5Sj6ftZR8HNZf/dvkUVqpVF4Wi TS+RaRdbfZ0RIdYZMOeEBrebQ+MAh/YZVEh1QS04Tw8NBkF4nZXMqVm5e3w8wVsoXGjC txB9CMJIcemLmpDAIbwLXvs+vHl5HS1ZkYUAsDKUACH4q5t3n0UqHx5fRmp6zmzeUckA W8LA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:references:cc:date:in-reply-to :message-id:user-agent:mime-version; bh=pKpklgzbEySA/7eE6fDAb8THopO4TjzVJ4ZgnIL21KQ=; b=XsAfK/h8HZl7xDjnYkxBMiGyJmccB6kYI3rqS1uuu1khBzcolKj0x9nVrExLTojrBY 2FCT/dHcmKt/6Bde87sxU4hV/ggyGCM45vzqhfOYBY8xWBwhAtnU2jPKfwizteXL2L4G YhXLpoRRLamkjv0UWqLmtjqAKJ5Bu51DXwoiBtoKX6hfKqg/+zWoeTMkhVc8O5qW9v8L N9KPwoSxl1TrEOwPUjEUjfEdiuKKoNz0TrI44wW+j7FMvu2rqDIXczRLFI7JnNEQsV+H 2yF8JKMGG2bHvUHgENAt0hVPfE+gpo+4db2S8SHousTZ2qZ2tGsotmufwh7imUQ6I1wN BU0Q== X-Gm-Message-State: ABUngvcSV1QFJik/91oKZK/Bo7mqdpeKbTenwdf3WEbPKm75tUVC+B7SoKmMzOsjfuBRzA== X-Received: by 10.99.135.200 with SMTP id i191mr7595608pge.18.1478488641824; Sun, 06 Nov 2016 19:17:21 -0800 (PST) Original-Received: from calancha-pc ([240f:6e:c00e:1:6875:2e94:598b:96cb]) by smtp.gmail.com with ESMTPSA id y2sm20351665pay.10.2016.11.06.19.17.19 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 06 Nov 2016 19:17:21 -0800 (PST) In-Reply-To: <1773ab35-70b1-42f9-8a8b-fe07881487d1@default> (Drew Adams's message of "Fri, 4 Nov 2016 13:03:40 -0700 (PDT)") 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:125405 Archived-At: Drew Adams writes: > `thing-at-point' should always return a string. > `list-at-point', `form-at-point', etc. are a different > story - they can return anything. > > The problem with the code of `thing-at-point' is not where > it has been identified so far. The problem is that if > THING has property `thing-at-point', and if that function > returns something that is not a string, then > `set-text-properties' raises an error. > > A proper fix is to convert the result returned by > (funcall (get thing 'thing-at-point)) to a string. > For that, you can use (format "%s" thing). It's natural if `thing-at-point' returns the thing as a string. When the user don't want a string then s?he can use the specific functions, like `number-at-point' or `list-at-point'. Indeed, that is what is specified in the manual: * doc/lispref/text.texi (Examining Buffer Contents) Following patch pass all the Emacs tests: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; >From ce1ced756c2762b4b0448a0480173e757804f784 Mon Sep 17 00:00:00 2001 From: Tino Calancha Date: Mon, 7 Nov 2016 12:05:28 +0900 Subject: [PATCH] * lisp/thingatpt.el (thing-at-point): Return the thing as a string --- lisp/thingatpt.el | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lisp/thingatpt.el b/lisp/thingatpt.el index e423630..fd6b323 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,9 @@ 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 (not (stringp text))) + (setq text (format "%s" text))) + (when (and text no-properties) (set-text-properties 0 (length text) nil text)) text)) -- 2.10.1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; In GNU Emacs 26.0.50.6 (x86_64-pc-linux-gnu, GTK+ Version 3.22.2) of 2016-11-06 Repository revision: f1d19d1445a8e7d4ee0d13edb8ed99e222603086