From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Drew Adams Newsgroups: gmane.emacs.bugs Subject: bug#21391: 24.5; `thing-at-point' returns error when called with arguments 'number t) Date: Fri, 4 Nov 2016 13:03:40 -0700 (PDT) Message-ID: <1773ab35-70b1-42f9-8a8b-fe07881487d1@default> References: <0a68c2ae-0940-4e2c-8b3c-1faceb45c43c@default> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1478289876 18856 195.159.176.226 (4 Nov 2016 20:04:36 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 4 Nov 2016 20:04:36 +0000 (UTC) To: Tino Calancha , 21391@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Nov 04 21:04:32 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 1c2kif-0001yh-1S for geb-bug-gnu-emacs@m.gmane.org; Fri, 04 Nov 2016 21:04:09 +0100 Original-Received: from localhost ([::1]:40563 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c2kii-00018g-06 for geb-bug-gnu-emacs@m.gmane.org; Fri, 04 Nov 2016 16:04:12 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:34727) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c2kib-00018M-LO for bug-gnu-emacs@gnu.org; Fri, 04 Nov 2016 16:04:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c2kiY-0004Jl-68 for bug-gnu-emacs@gnu.org; Fri, 04 Nov 2016 16:04:05 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:57924) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1c2kiY-0004Jf-2a for bug-gnu-emacs@gnu.org; Fri, 04 Nov 2016 16:04:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1c2kiX-0005eF-Qo for bug-gnu-emacs@gnu.org; Fri, 04 Nov 2016 16:04:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Drew Adams Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 04 Nov 2016 20:04: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.147828983221696 (code B ref 21391); Fri, 04 Nov 2016 20:04:01 +0000 Original-Received: (at 21391) by debbugs.gnu.org; 4 Nov 2016 20:03:52 +0000 Original-Received: from localhost ([127.0.0.1]:45090 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1c2kiO-0005ds-G5 for submit@debbugs.gnu.org; Fri, 04 Nov 2016 16:03:52 -0400 Original-Received: from aserp1040.oracle.com ([141.146.126.69]:34492) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1c2kiN-0005de-6p for 21391@debbugs.gnu.org; Fri, 04 Nov 2016 16:03:51 -0400 Original-Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id uA4K3iJU003138 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 4 Nov 2016 20:03:44 GMT Original-Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id uA4K3h5Z010697 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 4 Nov 2016 20:03:44 GMT Original-Received: from abhmp0019.oracle.com (abhmp0019.oracle.com [141.146.116.25]) by aserv0121.oracle.com (8.13.8/8.13.8) with ESMTP id uA4K3fcN004782; Fri, 4 Nov 2016 20:03:42 GMT In-Reply-To: <0a68c2ae-0940-4e2c-8b3c-1faceb45c43c@default> X-Priority: 3 X-Mailer: Oracle Beehive Extensions for Outlook 2.0.1.9.1 (1003210) [OL 12.0.6753.5000 (x86)] X-Source-IP: userv0021.oracle.com [156.151.31.71] 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:125352 Archived-At: Sorry, but I confused things further, I'm afraid. `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). FWIW, this is the code that I use (prefix `tap-' is for the package). Note that the doc string's first line says that what is returned is a string. (defun tap-thing-at-point (thing &optional no-properties syntax-table) "Return the THING at point as a string. If no THING is present at point then return nil. THING is an Emacs Lisp symbol that specifies a type of syntactic entity. THING examples include `symbol', `list', `sexp', `defun', `filename', `url', `email', `word', `sentence', `whitespace', `line', `number', and `page'. See the commentary of library `thingatpt.el' for how to define a symbol as a valid THING. If THING has property `thing-at-point' then the property value should be a function. The function is called with no arguments. If the return value of that function is a string or nil then that value is returned by this function also. Otherwise, that value is converted to a string and returned. Optional arg NO-PROPERTIES means that if a string is to be returned then it is first stripped of any text properties. Optional arg SYNTAX-TABLE is a syntax table to use." (let* ((thing-fn (or (get thing 'tap-thing-at-point) =20 (get thing 'thing-at-point))) (text (if thing-fn (let* ((opoint (point)) (thg (prog1 (funcall thing-fn) (constrain-to-field nil opoint)))) (if (stringp thg) thg (and thg (format "%s" thg)))) (let ((bounds (tap-bounds-of-thing-at-point thing syntax-table))) (and bounds (buffer-substring (car bounds) (cdr bounds))))))) (when (and text no-properties) (set-text-properties 0 (length text) nil text)) text))