GNU bug report logs -
#21391
24.5; `thing-at-point' returns error when called with arguments 'number t
Previous Next
Reported by: Tino Calancha <f92capac <at> gmail.com>
Date: Tue, 1 Sep 2015 01:57:01 UTC
Severity: minor
Found in version 24.5
Done: Lars Ingebrigtsen <larsi <at> gnus.org>
Bug is archived. No further changes may be made.
Full log
View this message in rfc822 format
Drew Adams <drew.adams <at> oracle.com> 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 <tino.calancha <at> gmail.com>
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
This bug report was last modified 4 years and 329 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.