From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Xah Lee Newsgroups: gmane.emacs.help Subject: Re: Mark whole Word Date: Tue, 9 Dec 2008 13:23:23 -0800 (PST) Organization: http://groups.google.com Message-ID: References: <493e97c5$0$31334$9b4e6d93@newsspool4.arcor-online.net> 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 1228893347 25607 80.91.229.12 (10 Dec 2008 07:15:47 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 10 Dec 2008 07:15:47 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Dec 10 08:16:50 2008 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 1LAJJQ-0000il-8q for geh-help-gnu-emacs@m.gmane.org; Wed, 10 Dec 2008 08:16:48 +0100 Original-Received: from localhost ([127.0.0.1]:38462 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LAJIF-000432-2e for geh-help-gnu-emacs@m.gmane.org; Wed, 10 Dec 2008 02:15:35 -0500 Original-Path: news.stanford.edu!newsfeed.stanford.edu!postnews.google.com!g1g2000pra.googlegroups.com!not-for-mail Original-Newsgroups: comp.emacs,gnu.emacs.help Original-Lines: 152 Original-NNTP-Posting-Host: 24.6.185.159 Original-X-Trace: posting.google.com 1228857804 10377 127.0.0.1 (9 Dec 2008 21:23:24 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Tue, 9 Dec 2008 21:23:24 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: g1g2000pra.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.27.1 (KHTML, like Gecko) Version/3.2.1 Safari/525.27.1, gzip(gfe), gzip(gfe) Original-Xref: news.stanford.edu comp.emacs:97441 gnu.emacs.help:165188 X-Mailman-Approved-At: Wed, 10 Dec 2008 02:15:14 -0500 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:60526 Archived-At: over comp.emacs, someone asked a way to select whole word, where mark- word is somewhat inconvenient. I think this is a frequently desired operation. Here's some suggestions i wrote up on this issue, which i myself wanted and thought about for the past year. =E2=80=A2 Suggestions on Emacs's mark-word Command http://xahlee.org/emacs/modernization_mark-word.html plain text version follows. (formatting may be screwed up) ------------------ Xah Lee, 2008-12-09 Emacs has a command to select the current word, mark-word, with default shortcut of =E2=80=9CAlt+@=E2=80=9D. Selecting the current word is = a frequently needed operation. However, emacs's mark-word command is inconvenient. It does not select the whole word. It only select from the cursor position to the end of the word. For example, if your word is =E2=80=9Ctransmission=E2=80=9D, and your cursor is at the =E2=80=9Cm=E2= =80=9D, then it will select just =E2=80=9Cmission=E2=80=9D. To select the whole word, you need to move = the cursor to the beginning of the word first. Also, mark-word has a feature that if you repeat the command, then it extend the selection to the next word to the right. Here we suggest a improvement. We want a command that select the whole word. When repeated, it should select the next larger syntactic unit. In human languages, that would be sentence, then paragraph, then whole buffer. In computer languages, the sequence would be: current identifier, current expression, current construct (or line), current block or defun. Similarly, if the lang is lisp, it simply extend the selection to the next outer parens. For detailed example of this, see: A Text Editor Feature: Extend Selection By Semantic Unit. Here's the code that implements the above idea for lisp (or any simply nested syntax): ;; by Nikolaj Schumacher, 2008-10-20. Released under GPL. (defun semnav-up (arg) (interactive "p") (when (nth 3 (syntax-ppss)) (if (> arg 0) (progn (skip-syntax-forward "^\"") (goto-char (1+ (point))) (decf arg)) (skip-syntax-backward "^\"") (goto-char (1- (point))) (incf arg))) (up-list arg)) ;; by Nikolaj Schumacher, 2008-10-20. Released under GPL. (defun extend-selection (arg &optional incremental) "Select the current word. Subsequent calls expands the selection to larger semantic unit." (interactive (list (prefix-numeric-value current-prefix-arg) (or (and transient-mark-mode mark-active) (eq last-command this-command)))) (if incremental (progn (semnav-up (- arg)) (forward-sexp) (mark-sexp -1)) (if (> arg 1) (extend-selection (1- arg) t) (if (looking-at "\\=3D\\(\\s_\\|\\sw\\)*\\_>") (goto-char (match-end 0)) (unless (memq (char-before) '(?\) ?\")) (forward-sexp))) (mark-sexp -1)))) (global-set-key (kbd "M-8") 'extend-selection) In the above, =E2=80=9CAlt+8=E2=80=9D is assigned to the command, because s= electing whole word is a commonly needed operation, and =E2=80=9CAlt+8=E2=80=9D is o= ne key simpler than =E2=80=9CAlt+@=E2=80=9D on a standard American layout PC keybo= ard. Pressing =E2=80=9CAlt+8=E2=80=9D will select the current whole word. Press = it again will extend the selection to the next outer parens. The above code effectively does extend selection to higher level of semantic unit for lisp or simply nested syntax. It does not work in more complicated nesting, such as HTML/XML. For the code to work in other langs like Java, Perl, Python, XML, it'll need some more work. Another frequently needed operation is to select text inside quotes. This is especially frequently needed in most languages such as C, C++, Java, JavaScript, Perl, Python, PHP, HTML/XML. Ideally, the extend- selection above should do it, by simply invoking the command twice, or just once when cursor is on the quote, but since the above is limited to lisp syntax only, so here's a additional command as a workaround to do the frequently needed operation of selecting text inside quote pairs. (defun select-text-in-quote () "Select text between the nearest left and right delimiters. Delimiters are paired characters: ()[]<>=C2=AB=C2=BB=E2=80=9C=E2=80=9D=E2= =80=98=E2=80=99=E3=80=8C=E3=80=8D, including \"\"." (interactive) (let (b1 b2) (skip-chars-backward "^<>(=E2=80=9C{[=E3=80=8C=C2=AB\"=E2=80=98") (setq b1 (point)) (skip-chars-forward "^<>)=E2=80=9D}]=E3=80=8D=C2=BB\"=E2=80=99") (setq b2 (point)) (set-mark b1) ) ) (global-set-key (kbd "M-*") 'select-text-in-quote) With both of the above defined, pressing =E2=80=9CAlt+8=E2=80=9D will selec= t whole word (or extend current selection). Pressing =E2=80=9CAlt+Shift+8=E2=80=9D = (that is: =E2=80=9CAlt+*=E2=80=9D) will select the text inside matching quotes. The above is included in the ergo map: A Ergonomic Keyboard Shortcut Layout For Emacs. Xah =E2=88=91 http://xahlee.org/ =E2=98=84 On Dec 9, 8:07=C2=A0am, Michael Schuster wrote: > Hi, > > I'm searching for way to mark a word. I know the mark-word function, but > this marks only the word from the cursor. So if the cursor is at the 'd' = in > the word "Wordmarker" only "dmarker" is marked. I want a function to mark > the whole word regardingless where in the word the cursor is. > > Does anybody know such a function? > Any help is welcome. > > Thanks in advance > Michael > -- > Remove the sport from my address to obtain emailwww.enertex.de- Innovativ= e Systeml=C3=B6sungen der Energie- und Elektrotechnik