unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Xah Lee <xah@xahlee.org>
To: help-gnu-emacs@gnu.org
Subject: Re: jump between if-fi
Date: Tue, 1 Jan 2008 10:12:31 -0800 (PST)	[thread overview]
Message-ID: <106c0d25-e7ad-4cd5-a536-ff12ff73018a@e23g2000prf.googlegroups.com> (raw)
In-Reply-To: mailman.5524.1199055779.18990.help-gnu-emacs@gnu.org

rea...@newsguy.com wrote:
「How can I make emacs do something similar with if-fi constructs as it
does with parens?  」

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:

★ 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 “fi” if cursor is on word “if”, 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)

  Xah
  xah@xahlee.org
\xAD\xF4 http://xahlee.org/

On Jan 1, 7:47 am, rea...@newsguy.com wrote:
> "Lennart Borgman (gmail)" <lennart.borg...@gmail.com> 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.
>

       reply	other threads:[~2008-01-01 18: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 ` Xah Lee [this message]
2008-01-01 19:12   ` jump between if-fi Alan Mackenzie
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

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=106c0d25-e7ad-4cd5-a536-ff12ff73018a@e23g2000prf.googlegroups.com \
    --to=xah@xahlee.org \
    --cc=help-gnu-emacs@gnu.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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).