From: Alan Mackenzie <acm@muc.de>
To: Xah Lee <xah@xahlee.org>
Cc: help-gnu-emacs@gnu.org
Subject: Re: jump between if-fi
Date: Tue, 1 Jan 2008 19:12:05 +0000 [thread overview]
Message-ID: <20080101191205.GF3830@muc.de> (raw)
In-Reply-To: <106c0d25-e7ad-4cd5-a536-ff12ff73018a@e23g2000prf.googlegroups.com>
Hi, Xah!
On Tue, Jan 01, 2008 at 10:12:31AM -0800, Xah Lee wrote:
> rea...@newsguy.com wrote:
> How can I make emacs do something similar with if-fi constructs as it
> does with parens?
[ .... ]
> 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.
And a Happy New Year to you too, Xah!
> Here's a hack that does what you want.
> (defun jump-to-if-fi ()
> "jump to ?$B!Hfi?$B!I if cursor is on word ?$B!Hif?$B!I, 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 "<f8>") 'jump-to-if-fi)
That's fine up to a point, my dear boy, but "if"s, "while"s, and so on
nest in shell scripts. The above function thus wouldn't always find the
right "fi" or "if".
The approach is a perfectly good one and can be made to work, but it will
involve some sort of recursion, either by explicitly building a push-down
automaton, or recursively calling functions to scan over "if-fi"s and
"while-done"s.
However, this way will surely be more tedious and difficult to debug and
modify than setting text properties and using Emacs's built in syntax
table functionality.
> Xah
--
Alan Mackenzie (Nuremberg, Germany).
next prev parent reply other threads:[~2008-01-01 19:12 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <mailman.5524.1199055779.18990.help-gnu-emacs@gnu.org>
2008-01-01 18:12 ` jump between if-fi Xah Lee
2008-01-01 19:12 ` Alan Mackenzie [this message]
2007-12-30 23:02 reader
2007-12-30 23:23 ` Lennart Borgman (gmail)
2007-12-31 6:29 ` reader
2007-12-31 8:12 ` Thierry Volpiatto
2007-12-31 14:41 ` reader
2008-01-01 15:47 ` reader
[not found] ` <mailman.5533.1199082573.18990.help-gnu-emacs@gnu.org>
2008-01-09 5:40 ` Stefan Monnier
2007-12-31 16:24 ` Alan Mackenzie
2008-01-01 2:29 ` reader
2008-01-01 14:18 ` Alan Mackenzie
2008-01-01 15:39 ` reader
2008-01-05 18:33 ` reader
2008-01-09 9:43 ` Arnaldo Mandel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20080101191205.GF3830@muc.de \
--to=acm@muc.de \
--cc=help-gnu-emacs@gnu.org \
--cc=xah@xahlee.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.