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: jump between if-fi Date: Tue, 1 Jan 2008 10:12:31 -0800 (PST) Organization: http://groups.google.com Message-ID: <106c0d25-e7ad-4cd5-a536-ff12ff73018a@e23g2000prf.googlegroups.com> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-2022-JP Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1199212889 14423 80.91.229.12 (1 Jan 2008 18:41:29 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 1 Jan 2008 18:41:29 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Jan 01 19:41:48 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 1J9m3c-0007Gg-4s for geh-help-gnu-emacs@m.gmane.org; Tue, 01 Jan 2008 19:41:44 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1J9m3G-0003Im-5h for geh-help-gnu-emacs@m.gmane.org; Tue, 01 Jan 2008 13:41:22 -0500 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!postnews.google.com!e23g2000prf.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 76 Original-NNTP-Posting-Host: 64.9.239.250 Original-X-Trace: posting.google.com 1199211151 1421 127.0.0.1 (1 Jan 2008 18:12:31 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Tue, 1 Jan 2008 18:12:31 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: e23g2000prf.googlegroups.com; posting-host=64.9.239.250; posting-account=qPxGtQkAAADb6PWdLGiWVucht1ZDR6fn User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/523.12.2 (KHTML, like Gecko) Version/3.0.4 Safari/523.12.2, gzip(gfe), gzip(gfe) Original-Xref: shelby.stanford.edu gnu.emacs.help:154998 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:50418 Archived-At: rea...@newsguy.com wrote: $B!V(BHow can I make emacs do something similar with if-fi constructs as it does with parens? $B!W(B To match paren, you want to turn on Show Paren Mode under the Options menu. Once the mode is on, when your cursor is on a paren, the matching paren (or the entire enclosed text) will be highlighted, and you can jump to it by forward-sexp. For details on these, see: $B!z(B Tips For Editing Lisp Code With Emacs http://xahlee.org/emacs/emacs_editing_lisp.html Now, the problem is to make it work for shell's if/fi syntax. Alan Mackenzie gave suggestions how to properly implement this, but he drivels on like a militarist sees the world. Here's a hack that does what you want. (defun jump-to-if-fi () "jump to $B!H(Bfi$B!I(B if cursor is on word $B!H(Bif$B!I(B, and vice versa." (interactive) (let (myword) (setq myword (thing-at-point 'word)) (if (equal myword "if") (progn (set-mark-command nil) (search-forward "fi") ) (if (equal myword "fi") (progn (set-mark-command nil) (search-backward "if") ) ) ) ) ) (global-set-key (kbd "") 'jump-to-if-fi) Xah xah@xahlee.org $B-t(B http://xahlee.org/ On Jan 1, 7:47 am, rea...@newsguy.com wrote: > "Lennart Borgman (gmail)" writes: > > > > > rea...@newsguy.com wrote: > >> I hope this isn't one of those things that is just plain obvious to > >> lookup in emacs but I'm striking out with M-x apropos > > >> How can I make emacs do something similar with if-fi constructs as it > >> does with parens? > > >> Even better I'd like the kind of behaviour one can get in vim with > >> parens, where not only does the syntax coloring show the other paren > >> but you can jump there with a Ctrl-% > > > Maybe you mean %, not C-%? > > > You can in Emacs too, using Viper. But see > > > http://www.emacswiki.org/cgi-bin/wiki/ViKeys > > http://www.emacswiki.org/cgi-bin/wiki/ViAndEmacs > > Sorry I missed it in that first link you provided but > Turns out to be right in the emacs FAQ. I repost it here incase > people searching these forms should hit this thread. > > I didn't really like the idea of turning on a whole vi like mode and I > guess a good number of others didn't either. >