From: Dmitry Gutov <dgutov@yandex.ru>
To: emacs-devel <emacs-devel@gnu.org>
Cc: Stefan Monnier <monnier@IRO.UMontreal.CA>
Subject: Guidelines for the "symbol" syntax class
Date: Sun, 3 Jan 2016 07:09:39 +0200 [thread overview]
Message-ID: <5688AD13.7050904@yandex.ru> (raw)
Hi all and Stefan,
I intend to make some changes to the syntax of `:' in ruby-mode, and I'm
wondering how far should that change go. I can remove it from the syntax
table, but still apply it via syntax-propertize-function in other cases,
see below.
Do we have any solid guidelines for that?
Context: my two main uses of the notion of symbol are 1) "all symbols in
all buffer" completion candidates, 2) filtering the results of
xref-find-references by checking that the match begins and ends at a
symbol boundary. Currently, both of these features don't work well in
ruby-mode.
First, "M::C" is interpreted as one symbol. If I just search for
references to "C", this won't match. And vice versa, this qualified name
usually corresponds to the definition like this:
module M
class C
end
end
so if I search for references to "M::C", this won't match either. So `:'
should simply become "punctuation". Then the simplest approach will
leave to false positives, but no false negatives.
There is another way `:' is used in Ruby: Ruby Symbols (I'm going to
mention those only using a capital S, to distinguish). Which is like
weird syntax for interned strings, but they're often used to refer to
method names: for introspection, or when defining a method dynamically,
or to dispatch a call dynamically. Examples:
class C
def foo
end
end
C.instance_method(:foo) # => #<UnboundMethod: C#foo>
class C
define_method(:foo) do
3
end
end
C.new.send(:foo) # => 3
Consequently, if somewhere in my Ruby program there's a method foo_bar,
it might be beneficial to be able to complete a Symbol :fo to :foo_bar
as well, or for xref-find-references, when looking for references to
this method, include the usages of Symbol :foo_bar.
Or take this example:
class C
# attr_reader is a macro, kinda.
# Define a method C#foo that simply returns the value
# of the instance variable with the same name:
attr_reader :foo
def initialize(foo)
# Assign that instance variable.
@foo = foo
end
def do_something
# Call the previously defined method (parens are optional)
# and then call a method on the returned value:
foo.do_something_amazing
end
end
After writing the attr_reader call, it would be handy if I could use the
name of the symbol in completion when writing the name of the argument,
and the name of the variable (so there's also a question of whether @
should have the "symbol" syntax; it currently doesn't). And then later,
when calling the method.
Another argument in favor of not having `:' be symbol constituents in
Symbol literals is that we have two ways to write Hash (associative
array) literal with Symbol keys:
{:key => value} and {key: value},
where the latter is syntactic sugar for the former. If `:' is not a
symbol constituents, we won't have two superficially "different" symbols
in the buffer, and the "find references" search will easily find both.
Or, should I stop trying to make the simplest general approaches work in
ruby-mode, and write a dedicated xref backend for Ruby? One that would
use etags and Grep, but use a bit smarter filtering.
What should company-dabbrev-code do? Should it use
dabbrev-abbrev-char-regexp, which ruby-mode will then set?
Should both company-dabbrev-code and ruby-mode make use of
dabbrev-abbrev-skip-leading-regexp? Note that it still won't help to
avoid making {:key and {key: look like different symbols.
And if I do all that, what *will* be the purpose of making `:' remain
symbol constituents inside Symbol literals?
Thanks all,
especially to those who've read all this ;-)
next reply other threads:[~2016-01-03 5:09 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-03 5:09 Dmitry Gutov [this message]
2016-01-03 22:56 ` Guidelines for the "symbol" syntax class John Wiegley
2016-01-04 0:46 ` Dmitry Gutov
2016-01-04 0:51 ` Stefan Monnier
2016-01-04 0:58 ` Dmitry Gutov
2016-01-04 1:13 ` John Yates
2016-01-04 1:18 ` Dmitry Gutov
[not found] ` <CAJnXXog5fO_h5UNnVR67EJtT+u7+G-BVMFV3FnJgK=weGj0m_w@mail.gmail.com>
2016-01-04 2:01 ` Dmitry Gutov
2016-01-04 0:55 ` John Wiegley
2016-01-04 1:14 ` Dmitry Gutov
2016-01-04 2:56 ` Stefan Monnier
2016-01-04 3:47 ` Dmitry Gutov
[not found] ` <CAJnXXogonsWpqadNpX0BijzoiztorYP1d=b31seBfvGVBwwT_Q@mail.gmail.com>
[not found] ` <5689CC5C.4000408@yandex.ru>
[not found] ` <CAJnXXojy1b6LUdXcC+cDVPYT-OJMXCE8m8yqObE9oUYwU_PGbg@mail.gmail.com>
2016-01-04 2:34 ` Dmitry Gutov
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5688AD13.7050904@yandex.ru \
--to=dgutov@yandex.ru \
--cc=emacs-devel@gnu.org \
--cc=monnier@IRO.UMontreal.CA \
/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 public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).