unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: "Drew Adams" <drew.adams@oracle.com>
To: "'Xah'" <xahlee@gmail.com>, <help-gnu-emacs@gnu.org>
Subject: RE: How do I highlight word at point?
Date: Sun, 19 Oct 2008 15:16:15 -0700	[thread overview]
Message-ID: <005c01c93238$4e00c340$0200a8c0@us.oracle.com> (raw)
In-Reply-To: <d5ba97c1-3793-45e9-91c4-af37510752f6@m36g2000hse.googlegroups.com>

> here's what i would want to have ideally:
> 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.
> 
> This idea is borrowed from Mathematica's IDE (aka the Front End).
> I have wrote full description of this feature, see:
> http://xahlee.org/emacs/syntax_tree_walk.html
> 
> I have a draft version for over a year now:
> 
> (defun mark-semantic-unit ()
> "Select a semantic unit.
> Select a word under cursor. "word" here means alphanumeric sequence
> plus "_" or "-".
> 
> When this function is run for the first time and there is no active
> region, then it selects the current word (i.e. sequence of
> alphanumerics plus hyphen or underscore).
> When the function is run again, or if there is a region, it extends
> the selection to the next level of enclosing delimiters."
>  (interactive)
>  (require 'thingatpt)
> (let ((deactivate-mark nil))
> (if (or (and (eq last-command this-command))
>         (and transient-mark-mode mark-active))
>     (let ((e1 (region-beginning))  (e2 (region-end)) b1 b2)
>       (goto-char (- e1 0))
>       (skip-chars-backward "^<>("{[?<\"'")
>       (setq b1 (point))
>       (goto-char (+ e2 0))
>       (skip-chars-forward "^<>)"}]?>\"'")
>       (setq b2 (point))
>       (set-mark b1))
>   (cond
>    ( (looking-at "\\_<")
>     (setq pt (point))
>     (push-mark pt nil t)
>     (forward-symbol 1))
>    (t
>     (forward-symbol -1)
>     (setq pt (point))
>     (push-mark pt nil t)
>     (forward-symbol 1))))))
> 
> this version works when your cursor is inside a matching pair. For
> example, if your cursor is at A in: (something here A and that)
> then invoke twice it'll select the whole paren.
> 
> However, it doesn't work when the cursor is in a screwed nested
> position. For example: (something here A (and) that)
> if your cursor is at A, invoke twice won't get the whole outer paren,
> because the code doesn't track nested parens, it only looks for chars
> in a dumb way.
> 
> 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.
> 
> So, taking a step back, i tried to have the code just extending to
> outer matching pairs. (effectively a extend-semantic-unit for lisp) I
> think now i can make this code work by using the sexp navigation
> functions. I should code this soon.
> 
> If anyone can implement this, or better yet, write a proper extend-
> semantic-unit for langs with C like syntax (C++,java,javascript),
> that'd be a killer feature i think.

I'm not sure that it would help you toward what you want to do, but you might
look at `thing-cmds.el'. It has some commands for selecting successive things of
different types.
http://www.emacswiki.org/emacs/ThingAtPointCommands.

See also perhaps:
http://www.emacswiki.org/emacs/MarkCommands#mark-a-word-or-thing.






  reply	other threads:[~2008-10-19 22:16 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 [this message]
2008-10-19 23:58       ` Nikolaj Schumacher
     [not found]       ` <mailman.1544.1224460736.25473.help-gnu-emacs@gnu.org>
2008-10-20  3:46         ` Xah
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

  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='005c01c93238$4e00c340$0200a8c0@us.oracle.com' \
    --to=drew.adams@oracle.com \
    --cc=help-gnu-emacs@gnu.org \
    --cc=xahlee@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.
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).