From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Drew Adams" Newsgroups: gmane.emacs.help Subject: RE: How do I highlight word at point? Date: Sun, 19 Oct 2008 15:16:15 -0700 Message-ID: <005c01c93238$4e00c340$0200a8c0@us.oracle.com> References: <1224382569.209484@nntp.acecape.com><8403dd42-f1a6-41fa-91d0-fa8b2a873932@u40g2000pru.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1224493299 15793 80.91.229.12 (20 Oct 2008 09:01:39 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 20 Oct 2008 09:01:39 +0000 (UTC) To: "'Xah'" , Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Oct 20 11:02:34 2008 connect(): Connection refused Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1Krgaa-0004Sb-So for geh-help-gnu-emacs@m.gmane.org; Mon, 20 Oct 2008 00:17:33 +0200 Original-Received: from localhost ([127.0.0.1]:40840 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KrgZV-0004B5-9H for geh-help-gnu-emacs@m.gmane.org; Sun, 19 Oct 2008 18:16:25 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KrgZA-0004Aj-BL for help-gnu-emacs@gnu.org; Sun, 19 Oct 2008 18:16:04 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KrgZ7-0004AX-Lj for help-gnu-emacs@gnu.org; Sun, 19 Oct 2008 18:16:02 -0400 Original-Received: from [199.232.76.173] (port=49271 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KrgZ7-0004AU-Fc for help-gnu-emacs@gnu.org; Sun, 19 Oct 2008 18:16:01 -0400 Original-Received: from rgminet01.oracle.com ([148.87.113.118]:25642) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1KrgZ7-0005QG-6N for help-gnu-emacs@gnu.org; Sun, 19 Oct 2008 18:16:01 -0400 Original-Received: from rgmgw1.us.oracle.com (rgmgw1.us.oracle.com [138.1.186.110]) by rgminet01.oracle.com (Switch-3.2.4/Switch-3.1.6) with ESMTP id m9JMFw6e008480; Sun, 19 Oct 2008 16:15:58 -0600 Original-Received: from acsmt701.oracle.com (acsmt701.oracle.com [141.146.40.71]) by rgmgw1.us.oracle.com (Switch-3.2.4/Switch-3.2.4) with ESMTP id m9JMFvKY027810; Sun, 19 Oct 2008 16:15:57 -0600 Original-Received: from dradamslap1 (/24.23.165.218) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Sun, 19 Oct 2008 22:15:56 +0000 X-Mailer: Microsoft Office Outlook 11 In-Reply-To: Thread-Index: AckyKwludWT9eLlcQreeZ7GmGP8A3gAAWJAA X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3350 X-Brightmail-Tracker: AAAAAQAAAAI= X-Brightmail-Tracker: AAAAAQAAAAI= X-Whitelist: TRUE X-Whitelist: TRUE X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.4-2.6 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:58941 Archived-At: > 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.