all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Drew Adams" <drew.adams@oracle.com>
To: "'Raffaele Ricciardi'" <rfflrccrd@gmail.com>, <help-gnu-emacs@gnu.org>
Subject: RE: thing-at-point: inconsistent behaviour?
Date: Sun, 19 Aug 2012 17:15:15 -0700	[thread overview]
Message-ID: <4D47EAF5678D42D1944AA2A2D49F3290@us.oracle.com> (raw)
In-Reply-To: <a96gstF3rcU1@mid.individual.net>

>  > Especially since `thing-at-point' does NOT always return a string -
>  > it returns a list for (thing-at-point 'list), for instance.
> 
> On my GNU Emacs 24.1, `thing-at-point' always returns a (propertized) 
> string, including when used with 'list.

Yes, my bad about that one.  I think my point there was (or should have been)
that vanilla `thing-at-point' can return anything at all.  You cannot depend on
it to return a string or nil.

The version in `thingatpt+.el' ensures that the function returns a string or
nil, but the vanilla version does not.  This is because the vanilla version just
returns whatever the function that is the value of (get THING 'thing-at-point)
returns (if that property is non-nil).  It does not convert that (if non-nil) to
a string.

Since it is user-developers who put that property on THING symbols, they can use
whatever function they like, returning anything they like.

It is unfortunate that the terminology and function names suggest that any kind
of Lisp object (any THING) is returned by `thing-at-point', whereas its mission,
according to the doc (but not actually enforced) is to return only a string (or
nil).  It is really about giving you a buffer substring that _represents_ a Lisp
object (e.g. a list or a symbol).

It is all the more confusing because `thingatpt.el' also defines other
functions, such as `sexp-at-point', `symbol-at-point', `number-at-point', and
`list-at-point', which _do_ return Lisp objects.

It is further confusing because the function used to do that is `form-at-point'.
The Elisp manual gives "form" as "a Lisp object that is intended for
evaluation."

So user-developers should think to use `form-at-point' and not `thing-at-point'
if they want to return a Lisp object.  The difference is that `form-at-point'
reads the string returned by `thing-at-point', to obtain a Lisp object.

Function `thing-at-point' is about source-code representations of Lisp things.
Function `form-at-point' is about Lisp things.

And because it is so easy to just put a function on a symbol as property
`thing-at-point', users can wind up with perfectly workable calls to
`thing-at-point' which do just what they want but which do not, as the doc says,
return a string (or nil).

There are thus a few things to keep straight, starting with (1) the difference
between (thing-at-point 'symbol), which returns a symbol name and not a symbol
(likewise, for other THINGs - lists etc.), and ending with (2) the difference
between `thing-at-point' and `form-at-point' and (3) the caveat that
`thing-at-point' (a) is not intended to do what its name suggests (return a Lisp
THING) and (b) is not guaranteed to do what its doc says (return a string
representing a Lisp THING, or nil).




      reply	other threads:[~2012-08-20  0:15 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-15 18:08 thing-at-point: inconsistent behaviour? Raffaele Ricciardi
2012-08-15 18:34 ` Barry Margolin
2012-08-15 18:44   ` Drew Adams
2012-08-15 19:00   ` Raffaele Ricciardi
2012-08-16 11:52     ` Andreas Röhler
     [not found]     ` <mailman.7107.1345117968.855.help-gnu-emacs@gnu.org>
2012-08-16 15:48       ` Barry Margolin
2012-08-16 16:24         ` Andreas Röhler
     [not found]         ` <mailman.7114.1345134264.855.help-gnu-emacs@gnu.org>
2012-08-16 17:12           ` Raffaele Ricciardi
2012-08-16 23:19             ` Barry Margolin
2012-08-17  0:46             ` Drew Adams
     [not found]             ` <mailman.7128.1345164390.855.help-gnu-emacs@gnu.org>
2012-08-17  1:46               ` Barry Margolin
2012-08-17  4:38                 ` Drew Adams
     [not found]                 ` <mailman.7135.1345178331.855.help-gnu-emacs@gnu.org>
2012-08-17  9:23                   ` Raffaele Ricciardi
2012-08-20  0:15                     ` Drew Adams [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4D47EAF5678D42D1944AA2A2D49F3290@us.oracle.com \
    --to=drew.adams@oracle.com \
    --cc=help-gnu-emacs@gnu.org \
    --cc=rfflrccrd@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.