[Top][All Lists]

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

Re: jumping to peer parenthesis/brace

From: Andreas Roehler
Subject: Re: jumping to peer parenthesis/brace
Date: Thu, 22 Jun 2006 16:59:06 +0200
User-agent: KNode/0.9.2

Pawel wrote:

> Hallo group members
> Could You tell me ow to do the following thing:
> {<------ my pointer is here and I want to jump there
> .....                                           |
> ...[.......]                                    |
> }<-----------------------------------------------
> highlight-paren-mode is not enough when block is larger than
> screen
> Greetings
Somewhere I picked `match-paren': it allows you to jump to and fro
without changing the key:

(defun match-paren (arg)
  "Go to the matching parenthesis if on parenthesis otherwise insert %."
  (interactive "p")
  (cond ((looking-at "\\s\(")
         (forward-list 1)
         (if (eq 0 (string-match "XEmacs" (version)))
             (backward-char 1)
           (when (eq 41 (char-before))
             (backward-char 1))))
        ((looking-at "\\s\)")
         (forward-char 1) (backward-list 1))
        (t (self-insert-command (or arg 1)))))


(global-set-key "%" 'match-paren)
or better
(define-key emacs-lisp-mode-map "%" 'match-paren)

Attention: If editing format strings, it might happen you are
over a `(' while inserting a `%' is in your mind. That's an
occasion, `match-paren' will not DTRT.

So choose an other key to call match-paren eventually.

Andreas Roehler

PS.: Posting this I see, `match-paren' could do better by handling
brackets and braces also. Maybe someone will enhance it after
reading this? Maybe in paredit.el is the enhancment already?

reply via email to

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