help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: How do I highlight word at point?


From: Nikolaj Schumacher
Subject: Re: How do I highlight word at point?
Date: Mon, 20 Oct 2008 01:58:50 +0200
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.3 (darwin)

Xah <xahlee@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))))

> 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...



regards,
Nikolaj Schumacher




reply via email to

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