help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: jump between if-fi


From: Xah Lee
Subject: Re: jump between if-fi
Date: Tue, 1 Jan 2008 10:12:31 -0800 (PST)
User-agent: G2/1.0

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 via email to

[Prev in Thread] Current Thread [Next in Thread]