From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Nikolaj Schumacher Newsgroups: gmane.emacs.help Subject: Re: How do I highlight word at point? Date: Mon, 20 Oct 2008 01:58:50 +0200 Message-ID: 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 X-Trace: ger.gmane.org 1224491210 8565 80.91.229.12 (20 Oct 2008 08:26:50 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 20 Oct 2008 08:26:50 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: Xah Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Oct 20 10:27:30 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 1KriC3-0007SH-PX for geh-help-gnu-emacs@m.gmane.org; Mon, 20 Oct 2008 02:00:20 +0200 Original-Received: from localhost ([127.0.0.1]:43153 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KriAy-00036e-GD for geh-help-gnu-emacs@m.gmane.org; Sun, 19 Oct 2008 19:59:12 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KriAg-00036L-2j for help-gnu-emacs@gnu.org; Sun, 19 Oct 2008 19:58:54 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KriAe-000369-Ml for help-gnu-emacs@gnu.org; Sun, 19 Oct 2008 19:58:52 -0400 Original-Received: from [199.232.76.173] (port=55044 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KriAe-000366-HY for help-gnu-emacs@gnu.org; Sun, 19 Oct 2008 19:58:52 -0400 Original-Received: from dd18200.kasserver.com ([85.13.138.168]:46117) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1KriAe-0005fB-10 for help-gnu-emacs@gnu.org; Sun, 19 Oct 2008 19:58:52 -0400 Original-Received: from thursday (BAH0e26.bah.pppool.de [77.135.14.38]) by dd18200.kasserver.com (Postfix) with ESMTP id B577A1802DE85; Mon, 20 Oct 2008 01:58:57 +0200 (CEST) In-Reply-To: (Xah's message of "Sun\, 19 Oct 2008 13\:10\:42 -0700 \(PDT\)") User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.3 (darwin) X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) 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:58936 Archived-At: Xah 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