From: Xah <xahlee@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: How do I highlight word at point?
Date: Sun, 19 Oct 2008 20:46:32 -0700 (PDT) [thread overview]
Message-ID: <1ed6498a-19fc-42f2-b00c-b369e74396b1@p10g2000prf.googlegroups.com> (raw)
In-Reply-To: mailman.1544.1224460736.25473.help-gnu-emacs@gnu.org
On Oct 19, 4:58 pm, Nikolaj Schumacher <m...@nschum.de> wrote:
> Xah <xah...@gmail.com> wrote:
> > press a key, expand selection to the current word, press again, expand
> > to the next semantic unit (with respect to the current lang/mode),
> > press again, expand further.
>
> I have a strong interest in such a function, as well.
>
> > However, it doesn't work when the cursor is in a screwed nested
> > position. For example:
>
> > (something here A (and) that)
>
> That case I can fix. Here's some code I wrote a while ago...
>
> (defun my-mark-sexp (arg &optional incremental)
> "Mark the sexp surrounding point.
> Subsequent calls mark higher levels of sexps."
> (interactive (list (prefix-numeric-value current-prefix-arg)
> (or (and transient-mark-mode mark-active)
> (eq last-command this-command))))
> (if incremental
> (progn
> (up-list (- arg))
> (forward-sexp)
> (mark-sexp -1))
> (if (> arg 1)
> (my-mark-sexp (1- arg) t)
> (re-search-forward "\\_>")
> (mark-sexp -1))))
Super.
is it possible to make it work with selecting a string?
suppose your cursor is on the word “thing” below:
([
« ‹ "some thing here" › »
{ ht}
「 chinese bracket 『more』 」
])
after second press, it'd be nice to select the string.
> > Ideally, this mark-semantic-unit should just extend a semantic unit,
> > where what's considered a semantic unit depends on the language. But
> > this i imagine would be rather a non-trivial problem. I am not sure
> > emacs's syntax table system is rich enough to be used for this.
>
> As you can see from your own code, character syntax isn't enough. There
> would have to be a real parser involved to detect where statements start
> and end. As far as I know even Semantic doesn't parse any function
> bodies, and that's probably the smartest lib we have. (Luckily lisp is
> that easy to parse.)
>
> Maybe there is an adequate heuristic...
“Semantic”? is that a elisp package?
yes, i think heuristics will do sufficient job. C syntax langs (java,
javascript, C, C++, C#, LSL, and even to large extent perl), has
little tell tail signs good enough for a practical solution. typically
just of this form:
import xyz;
f f (type x, type y) {
...;
...;
}
to start with, we can have the cmd such that:
one press → select current word
2nd press → current string if inside string
press again → current line
press again → current content inside {}
press again → next outer braces
press again → whole function def
i think this is not difficult to implement this to the degree it works
correctly 95% of time.
the nxml and js2 packages contains full parser for xml and javascript.
I think eventually lang modes in emacs would have full lexers.
Xah
∑ http://xahlee.org/
☄
next prev parent reply other threads:[~2008-10-20 3:46 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-10-19 2:16 How do I highlight word at point? Wei Weng
2008-10-19 3:02 ` Giorgos Keramidas
2008-10-19 12:09 ` Francis Moreau
2008-10-19 16:19 ` Nikolaj Schumacher
[not found] ` <mailman.1504.1224419414.25473.help-gnu-emacs@gnu.org>
2008-10-19 13:24 ` Thorsten Bonow
2008-10-19 15:54 ` Francis Moreau
2008-10-19 15:14 ` Giorgos Keramidas
2008-10-19 15:52 ` Francis Moreau
2008-10-29 22:13 ` Francis Moreau
2008-10-29 22:44 ` Andreas Politz
2008-10-30 20:22 ` Francis Moreau
2008-10-30 13:57 ` Scott Frazer
2008-10-19 5:44 ` Xah
2008-10-19 17:00 ` Nikolaj Schumacher
[not found] ` <mailman.1521.1224435664.25473.help-gnu-emacs@gnu.org>
2008-10-19 20:10 ` Xah
2008-10-19 22:16 ` Drew Adams
2008-10-19 23:58 ` Nikolaj Schumacher
[not found] ` <mailman.1544.1224460736.25473.help-gnu-emacs@gnu.org>
2008-10-20 3:46 ` Xah [this message]
2008-10-20 12:31 ` Nikolaj Schumacher
[not found] ` <mailman.1579.1224505887.25473.help-gnu-emacs@gnu.org>
2008-10-20 18:43 ` Xah
2008-10-21 8:57 ` Nikolaj Schumacher
2008-10-19 23:35 ` Drew Adams
2008-10-19 23:39 ` Drew Adams
2008-10-21 3:43 ` htbest2000
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=1ed6498a-19fc-42f2-b00c-b369e74396b1@p10g2000prf.googlegroups.com \
--to=xahlee@gmail.com \
--cc=help-gnu-emacs@gnu.org \
/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.