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

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

Re: command help : matching braces


From: Fernando Dobladez
Subject: Re: command help : matching braces
Date: Mon, 08 Apr 2002 14:07:42 -0500
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.9) Gecko/20020311

It shouldn't be necessary. Actually the special \s( and \s) in a regular expresion matches any opening/closing "parenthesis" (generic meaning) character. This meaning depends on the current mode. From the elisp manual: "In English text, and in C code, the parenthesis pairs are `()', `[]', and `{}'. In Emacs Lisp, the delimiters for lists and vectors (`()' and `[]') are classified as parenthesis characters."

Fernando.


Matthew O. Smith wrote:

Hi,

I added curly brace matching as well.
Thanks.

(defun match-paren (arg)
 "Go to the matching parenthesis if on parenthesis, otherwise insert %.
(Like in VI editor).  Thanks Fernando Dobladez <address@hidden>"
 (interactive "p")
 (cond
  ((looking-at "\\s\(") (forward-list 1) (backward-char 1))
  ((looking-at "\\s\)") (forward-char 1) (backward-list 1))
  ((looking-at "\\s\{") (forward-list 1) (backward-char 1))
  ((looking-at "\\s\}") (forward-char 1) (backward-list 1))
  (t (self-insert-command (or arg 1)))))


----- Original Message -----
From: "Fernando Dobladez" <address@hidden>
To: "Ambardekar, Shailesh" <address@hidden>
Cc: <address@hidden>
Sent: Monday, April 08, 2002 11:07 AM
Subject: Re: command help : matching braces


If you miss VI's % too much, you'd probably like to include the
following in your .emacs:

(defun match-paren (arg)
 "Go to the matching parenthesis if on parenthesis, otherwise insert %.
(Like in VI editor)"
 (interactive "p")
 (cond ((looking-at "\\s\(") (forward-list 1) (backward-char 1))
   ((looking-at "\\s\)") (forward-char 1) (backward-list 1))
   (t (self-insert-command (or arg 1)))))

(global-set-key "%"                  'match-paren)


That will make the '%' go to the matching brace if the cursor is on a
brace, and it will insert "%" otherwise.

Fernando.


Ambardekar, Shailesh wrote:

In gnu emacs 20.3.1 under Sun Solaris 2.6,
what is the emacs command for going to the matching brace ?
( looking for emacs equivalent of % vi command ).

Thanks in advance.

Shailesh




_______________________________________________
Help-gnu-emacs mailing list
address@hidden
http://mail.gnu.org/mailman/listinfo/help-gnu-emacs








reply via email to

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