auto paren mode

auto paren mode

Post by Klaus Leopol » Sat, 13 Apr 2002 05:39:02



hi all,

it there something like an auto paren mode in xemacs? if i open a paren (, {
or [ it should be immediately closed.

thanks,
Klaus

 
 
 

auto paren mode

Post by Adrian Aichne » Sat, 13 Apr 2002 05:55:42


    Klaus> hi all,

    Klaus> it there something like an auto paren mode in xemacs? if i
    Klaus> open a paren (, { or [ it should be immediately closed.

This depends on the major-mode you are using.

cperl has the concept of
 * cperl-electric-parens          - Non-nil (and non-null) means parentheses should be electric in CPerl.
which see.

There's also "Balanced Editing"
like
M-( (insert-parentheses)
and
M-) (move-past-close-and-reindent)

Try
C-x C-e (eval-last-sexp)
at the end of following line:
(Info-goto-node "(xemacs)Balanced Editing")

Hope this helps,

Adrian

    Klaus> thanks,
    Klaus> Klaus

--
Adrian Aichner

 http://www.xemacs.org/

 
 
 

auto paren mode

Post by Sebastian Kap » Sat, 13 Apr 2002 06:40:36


Quote:// Klaus Leopold writes:
> it there something like an auto paren mode in xemacs? if i open a paren (, {
> or [ it should be immediately closed.

I'm using the this:

(defun my-dbl-brace ()
  (interactive)
  (cond ((looking-at "\\b")
         (insert "{"))
        (t
         (insert "{}")
         (forward-char -1))))

(defun my-dbl-paren ()
  (interactive)
  (cond ((looking-at "\\b")
         (insert "("))
        (t
         (insert "()")
         (forward-char -1))))

(defun my-dbl-bracket ()
  (interactive)
  (cond ((looking-at "\\b")
         (insert "["))
        (t
         (insert "[]")
         (forward-char -1))))

(defun my-dbl-angle ()
  (interactive)
  (cond ((looking-at "\\b")
         (insert "<"))
        (t
         (insert "<>")
         (forward-char -1))))

This just inserts double parens if the cursor is not located before a
word. If it is just a the opening paren is inserted. I found this to be
more convenient than blindly inserting a pair of parens.

--
Ciao, Sebastian

* HP:    http://www.sauerland.de/~toyland/          PGP-Key available

 
 
 

auto paren mode

Post by Juli » Sat, 13 Apr 2002 10:52:49




Quote:> hi all,

> it there something like an auto paren mode in xemacs? if i open a
> paren (, { or [ it should be immediately closed.

this is somebody else's:

(defun my-dbl-brace ()
  (interactive)
  (cond ((looking-at "\[0-9A-Za-z]")
         (insert "{"))
        (t
         (insert "{}")
         (forward-char -1))))

(defun my-dbl-paren ()
  (interactive)
  (cond ((looking-at "\\b")
         (insert "("))
        (t
         (insert "()")
         (forward-char -1))))

(defun my-dbl-bracket ()
  (interactive)
  (cond ((looking-at "\\b")
         (insert "["))
        (t
         (insert "[]")
         (forward-char -1))))

(defun my-dbl-angle ()
  (interactive)
  (cond ((looking-at "\\b")
         (insert "<"))
        (t
         (insert "<>")
         (forward-char -1))))

 
 
 

auto paren mode

Post by kroni » Sat, 13 Apr 2002 11:33:10




Quote:> // Klaus Leopold writes:

>> it there something like an auto paren mode in xemacs? if i open a
>> paren (, { or [ it should be immediately closed.

> I'm using the this:

...
<snip some function definitions>

Just a note that if you want to associate some function like this to a
mode you have to add a mode hook eg, if you want to associate his dbl-
paren function to c:

(add-hook 'c-mode-hook
          (lambda()
            (define-key haskell-mode-map "(" 'my-dbl-paren))

 
 
 

auto paren mode

Post by those who know me have no need of my nam » Sat, 13 Apr 2002 16:13:42



Quote:><snip some function definitions>

>Just a note that if you want to associate some function like this to a
>mode you have to add a mode hook eg, if you want to associate his dbl-
>paren function to c:

>(add-hook 'c-mode-hook
>          (lambda()
>            (define-key haskell-mode-map "(" 'my-dbl-paren))

hmm.  perhaps the following would be better:

(add-hook 'c-mode-hook (lambda (local-set-key "(" 'my-dbl-paren))))

--
bringing you boring signatures for 17 years

 
 
 

auto paren mode

Post by Sebastian Kap » Sat, 13 Apr 2002 18:06:17


// those who know me have no need of my name writes:

Quote:> hmm.  perhaps the following would be better:
> (add-hook 'c-mode-hook (lambda (local-set-key "(" 'my-dbl-paren))))

Why would this be better?

--
Ciao, Sebastian

* HP:    http://www.sauerland.de/~toyland/          PGP-Key available

 
 
 

auto paren mode

Post by those who know me have no need of my nam » Sat, 13 Apr 2002 20:22:01



Quote:>// those who know me have no need of my name writes:

[previously quoted function restored]


>>>(add-hook 'c-mode-hook
>>>          (lambda()
>>>            (define-key haskell-mode-map "(" 'my-dbl-paren))
>> hmm.  perhaps the following would be better:
>> (add-hook 'c-mode-hook (lambda (local-set-key "(" 'my-dbl-paren))))

>Why would this be better?

adding a keystroke to haskell-mode-map probably doesn't have much effect on
a c-mode buffer.  use of `local-set-key' instead of `define-key some-map'
insures that the keymap for the buffer running the hook is modified.  there
may be times when the later is what is desired, but generally it is not.
(heck, i even considered suggesting (kbd "(") instead of "(".)  and last,
but not least, it's syntactically correct -- the original is missing two
trailing close parenthesis.

--
bringing you boring signatures for 17 years

 
 
 

auto paren mode

Post by kroni » Sat, 13 Apr 2002 22:06:22




Quote:> adding a keystroke to haskell-mode-map probably doesn't have much
> effect on a c-mode buffer.  use of `local-set-key' instead of
> `define-key some-map' insures that the keymap for the buffer running
> the hook is modified.  there may be times when the later is what is
> desired, but generally it is not. (heck, i even considered suggesting
> (kbd "(") instead of "(".)  and last, but not least, it's
> syntactically correct -- the original is missing two trailing close
> parenthesis.

Yes, sorry it was the result of a bad cut and pasting on my part (I
accidentally cut the haskell on and as I was in a big rush, to go
somewhere, didn't pay enought attention). Obviously, it should be c-mode-
map and to avoid this kind of stupid error, of course it is preferable to
use local-set-key.

Cheers.

 
 
 

auto paren mode

Post by Klaus Leopol » Sun, 14 Apr 2002 01:40:10


Thanks a lot for all the postings! it works fine... as i like the auto-paren
stuff for the whole xemacs and not for a singe mode only i used

(global-set-key "(" 'my-dbl-paren)
(global-set-key "{" 'my-dbl-brace)
(global-set-key "[" 'my-dbl-bracket)

;-)

thanks again,

klaus

 
 
 

auto paren mode

Post by Juli » Sun, 14 Apr 2002 01:56:36




Quote:> Thanks a lot for all the postings! it works fine... as i like the
> auto-paren stuff for the whole xemacs and not for a singe mode only i
> used

> (global-set-key "(" 'my-dbl-paren)
> (global-set-key "{" 'my-dbl-brace)
> (global-set-key "[" 'my-dbl-bracket)

I like that! C-x C-f init.el!
 
 
 

auto paren mode

Post by Sebastian Kap » Sun, 14 Apr 2002 02:43:08


// those who know me have no need of my name writes:

Quote:> adding a keystroke to haskell-mode-map probably doesn't have much effect on
> a c-mode buffer.  use of `local-set-key' instead of `define-key some-map'
> insures that the keymap for the buffer running the hook is modified.  there
> may be times when the later is what is desired, but generally it is not.
> (heck, i even considered suggesting (kbd "(") instead of "(".)

Ah, thanks for pointing this out.

--
Ciao, Sebastian

* HP:    http://www.sauerland.de/~toyland/          PGP-Key available

 
 
 

auto paren mode

Post by Klaus Leopol » Sun, 14 Apr 2002 06:18:21


WOW! i've one more great idea... i guess it's not that easy to do:

if i'm writing a*document it's totally enoying to type the \begin{XXX}
\end{xxx} stuff. is it somehow possible, if i write \begin{whatever...} the
tag \end{whatever...} is automatically written by the great xemacs one line
belos??

like that:

\begin{verbatim}
\end{verbatim}

i guess it's not that easy to do as a singe char, because you'll have to
parse the text...

however, if there's a solution i'd be totally grateful.

Klaus

 
 
 

auto paren mode

Post by Erwan Davi » Sun, 14 Apr 2002 06:36:36



> WOW! i've one more great idea... i guess it's not that easy to do:

> if i'm writing a*document it's totally enoying to type the \begin{XXX}
> \end{xxx} stuff. is it somehow possible, if i write \begin{whatever...} the
> tag \end{whatever...} is automatically written by the great xemacs one line
> belos??

> like that:

> \begin{verbatim}
> \end{verbatim}

> i guess it's not that easy to do as a singe char, because you'll have to
> parse the text...

> however, if there's a solution i'd be totally grateful.

if you use AucTeX (standard with xemacs) that's C-c C-e verbatim<ret>

--
He was said to have the body of a twenty-five year old, although no one
knew where he kept it.
        -- The Life and Times of Corp*Nobbs
           (Terry Pratchett, Men at Arms)

 
 
 

auto paren mode

Post by Klaus Leopol » Mon, 15 Apr 2002 00:13:16



> if you use AucTeX (standard with xemacs) that's C-c C-e verbatim<ret>

that's right! thanks... :-\

Klaus

 
 
 

1. (paren-set-mode 'paren)

Keywords:

Hi,

my .emacs contains

  (require 'paren)
  (paren-set-mode 'paren)

and all the corresponding variables are still set to their correct values when
a c-mode buffer comes up. There are no other settings elsewhere in .emacs.  But
parenthesis are not highlighted until I do another explicit (paren-set-mode
'paren) for this buffer. Shouldn't this setting be global?

    /-/ansi

--

Hans-Juergen Richstein
Scientific Center Heidelberg, IBM Germany
Advanced Radio Communication (ARTe)


Voice:            +49-6221-59-4397             FAX:+49-6221-59-3500

2. fortran

3. paren.el enhancement: paren-backwards-message

4. IBM Waverunner V.42bis Compression

5. fixed: (auto) ispell-mode.el which works well w/ auto-fill

6. gifs

7. paren-mode highlighting both matching parenthesis?

8. MSN Messenger and SSDP (Did You Know)

9. something weird with paren-mode

10. show-paren-mode in Xemacs?

11. paren blinking in autoconf-mode

12. vip-paren-match fails in c-mode

13. Paren-mode being fragile?