From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Xah Newsgroups: gmane.emacs.help Subject: Re: How do I highlight word at point? Date: Sun, 19 Oct 2008 20:46:32 -0700 (PDT) Organization: http://groups.google.com Message-ID: <1ed6498a-19fc-42f2-b00c-b369e74396b1@p10g2000prf.googlegroups.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=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1224505603 27628 80.91.229.12 (20 Oct 2008 12:26:43 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 20 Oct 2008 12:26:43 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Oct 20 14:27:28 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 1Krman-0003LN-VL for geh-help-gnu-emacs@m.gmane.org; Mon, 20 Oct 2008 06:42:10 +0200 Original-Received: from localhost ([127.0.0.1]:48375 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KrmZi-0004cU-OF for geh-help-gnu-emacs@m.gmane.org; Mon, 20 Oct 2008 00:41:02 -0400 Original-Path: news.stanford.edu!newsfeed.stanford.edu!postnews.google.com!p10g2000prf.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 91 Original-NNTP-Posting-Host: 24.6.185.159 Original-X-Trace: posting.google.com 1224474392 32241 127.0.0.1 (20 Oct 2008 03:46:32 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Mon, 20 Oct 2008 03:46:32 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: p10g2000prf.googlegroups.com; posting-host=24.6.185.159; posting-account=bRPKjQoAAACxZsR8_VPXCX27T2YcsyMA User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10_4_11; en) AppleWebKit/525.18 (KHTML, like Gecko) Version/3.1.2 Safari/525.22, gzip(gfe), gzip(gfe) Original-Xref: news.stanford.edu gnu.emacs.help:163608 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:58947 Archived-At: On Oct 19, 4:58 pm, Nikolaj Schumacher wrote: > 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)))) Super. is it possible to make it work with selecting a string? suppose your cursor is on the word =E2=80=9Cthing=E2=80=9D below: ([ =C2=AB =E2=80=B9 "some thing here" =E2=80=BA =C2=BB { ht} =E3=80=8C chinese bracket =E3=80=8Emore=E3=80=8F =E3=80=8D ]) 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... =E2=80=9CSemantic=E2=80=9D? 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 =E2=86=92 select current word 2nd press =E2=86=92 current string if inside string press again =E2=86=92 current line press again =E2=86=92 current content inside {} press again =E2=86=92 next outer braces press again =E2=86=92 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 =E2=88=91 http://xahlee.org/ =E2=98=84