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: Sun, 19 Oct 2008 19:00:58 +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=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1224477394 31499 80.91.229.12 (20 Oct 2008 04:36:34 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 20 Oct 2008 04:36:34 +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 06:37:12 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 1Krbfe-0002o1-Bf for geh-help-gnu-emacs@m.gmane.org; Sun, 19 Oct 2008 19:02:26 +0200 Original-Received: from localhost ([127.0.0.1]:36636 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KrbeZ-00042o-8m for geh-help-gnu-emacs@m.gmane.org; Sun, 19 Oct 2008 13:01:19 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KrbeI-00042X-Oc for help-gnu-emacs@gnu.org; Sun, 19 Oct 2008 13:01:02 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KrbeG-00042I-M5 for help-gnu-emacs@gnu.org; Sun, 19 Oct 2008 13:01:01 -0400 Original-Received: from [199.232.76.173] (port=57421 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KrbeG-00042F-GF for help-gnu-emacs@gnu.org; Sun, 19 Oct 2008 13:01:00 -0400 Original-Received: from dd18200.kasserver.com ([85.13.138.168]:59900) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1KrbeF-0000vF-UT for help-gnu-emacs@gnu.org; Sun, 19 Oct 2008 13:01:00 -0400 Original-Received: from thursday (BAH0e26.bah.pppool.de [77.135.14.38]) by dd18200.kasserver.com (Postfix) with ESMTP id 8E99618C2BF7D; Sun, 19 Oct 2008 19:01:03 +0200 (CEST) In-Reply-To: <8403dd42-f1a6-41fa-91d0-fa8b2a873932@u40g2000pru.googlegroups.com> (Xah's message of "Sat\, 18 Oct 2008 22\:44\:14 -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:58928 Xah wrote: > (defun select-word () > "Select a word under cursor. > =E2=80=9Cword=E2=80=9D here is considered any alphenumeric sequence with = =E2=80=9C_=E2=80=9D or =E2=80=9C-=E2=80=9D." > (interactive) > (let (b1 b2) > (skip-chars-backward "-_A-Za-z0-9") > (setq b1 (point)) > (skip-chars-forward "-_A-Za-z0-9") > (setq b2 (point)) > (set-mark b1) > ) > ) Why not use syntactic tables to determine what a word is? That way it would work for non-English languages and use less code. (defun mark-current-word () "Place the region around the word at point." (interactive) (forward-word 1) (mark-word -1)) I think I'll also use this (replacing M-@). But it should still be able to grow the region... Let's see: (defun mark-current-word (arg &optional incremental) "Place the region around the word at point. ARG determines how many following words to include. When INCREMENTAL is non-nil, extend the existing region." (interactive (list (prefix-numeric-value current-prefix-arg) (or (and transient-mark-mode mark-active) (eq last-command this-command)))) (and incremental (> (* (signum arg) (- (mark) (point))) 0) (exchange-point-and-mark)) (forward-word arg) (unless incremental (mark-word (- arg)))) (global-set-key "\M-@" 'mark-current-word) (improvements welcome) regards, Nikolaj Schumacher