emacs-devel
[Top][All Lists]
Advanced

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

Re: symbol-at-point


From: Stefan Monnier
Subject: Re: symbol-at-point
Date: Fri, 27 Jul 2007 01:36:16 -0400
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1.50 (gnu/linux)

>> > Wouldn't it be more clean to write a separate (intern
>> > SYMBOL-at-point) function, if someone wants to do that?
>> 
>> I agree that symbol-at-point should return a string.
>> When I fixed symbol-at-point to work in non-elisp major modes, I preserved
>> this part of the behavior for no good reason.

> No, it should not return a string.  Changing that could mean changing code
> that uses the result, for example, in a completion list.  Even though Emacs
> 22 now accepts a list of strings in place of an alist as a completion list,
> I think that change would be a bad idea.

I have no idea if code might break or not, but I'd assume that some amount
of code would break, of course (your completion list example sounds highly
unconvincing (lists of symbols have never worked any better than lists of
strings), but I don't need any example to be convinced anyway).

> It's better to leave `symbol-at-point' as is, returning a symbol, and have a
> separate function, `symbol-name-at-point', which gives you the name.  That is
> the approach I took in the thingatpt.el patch I sent.

Sounds good to me.  Tho I guess that (thing-at-point 'symbol), which already
works right now, isn't that bad either.
But I do think we should discourage the use of symbol-at-point (i.e. mark
it obsolete).

>> But returning a symbol has the main disadvantage that you can't
>> distinguish the case where point is not on a symbol (w.g. it's
>> looking at a semi-colon) from the case where it's looking at
>> the symbol "nil".

> Right. In the patch that I sent, these issues are addressed (for Lisp
> symbols). Separate `lisp-symbol-name-*' functions return the symbol name, or
> "" if there is no such symbol, whereas `list-symbol-*' returns the symbol
> itself (possibly nil) or nil if thre is no such symbol.

I see 0 need for such lisp-symbol-* functions:
(with-syntax-table emacs-lisp-mode-syntax-table (thing-at-point 'symbol))
works just fine and in most cases the with-syntax-table is not even needed
because we know we're in an elisp buffer.

Similarly, if you need a symbol rather than a string calling `intern' is
trivial enough that there's no justification for a separate function.


        Stefan




reply via email to

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