[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#21391: 24.5; `thing-at-point' should return a string

From: Tino Calancha
Subject: bug#21391: 24.5; `thing-at-point' should return a string
Date: Mon, 07 Nov 2016 12:17:17 +0900
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux)

Drew Adams <address@hidden> 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 <address@hidden>
Date: Mon, 7 Nov 2016 12:05:28 +0900
Subject: [PATCH] * lisp/thingatpt.el (thing-at-point): Return the thing as a

 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
 (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))

In GNU Emacs (x86_64-pc-linux-gnu, GTK+ Version 3.22.2)
 of 2016-11-06
Repository revision: f1d19d1445a8e7d4ee0d13edb8ed99e222603086

reply via email to

[Prev in Thread] Current Thread [Next in Thread]