[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Crazy idea for M-(: surround region
From: |
Sandip Chitale |
Subject: |
Re: Crazy idea for M-(: surround region |
Date: |
14 Jul 2003 17:06:17 -0700 |
kai.grossjohann@gmx.net (Kai Großjohann) wrote in message
news:<843chbzdtv.fsf@lucy.is.informatik.uni-duisburg.de>...
> If transient-mark-mode is active, M-( should surround the region with
> parens, ie do like C-w M-( C-y.
>
> WDYT?
I have this: (works based on the syntax of the char in the files mode.
Also leaves the cursor after first delim or before second delim based
on arg).
(defun electric-open-delimeter (arg)
"Automatically insert matching delimeter."
(interactive "*P")
(let (
(mark-was-active mark-active)
(beg)
(end)
(syntax (char-syntax last-command-char))
(key-match (assoc last-command-char '(
(?\( . ?\))
(?\{ . ?\})
(?\[ . ?\])
(?\" . ?\")
(?\' . ?\')
(?\` . ?\')
(?\< . ?\>)
)
)
)
)
(if (or
(eq syntax 40)
(eq syntax 34)
(eq syntax 47)
(eq syntax 36)
)
(progn
(if mark-was-active
(progn
(setq beg (region-beginning))
(setq end (+ (region-end) 1))
(goto-char beg)
)
)
(self-insert-command 1)
(if mark-was-active
(goto-char end)
)
(if key-match
(progn (insert (cdr key-match))
(backward-char)
)
)
(if mark-was-active
(progn
(indent-region beg (+ end 1) nil)
(if (not arg)
(if (or
(eq syntax 40)
(eq syntax 36)
)
(goto-char (1+ beg))
(goto-char (1+ end))
)
)
)
)
)
(self-insert-command 1)
)
)
)
(global-set-key (kbd "(") 'electric-open-delimeter)
(global-set-key (kbd "{") 'electric-open-delimeter)
(global-set-key (kbd "[") 'electric-open-delimeter)
(global-set-key (kbd "\"") 'electric-open-delimeter)
(global-set-key (kbd "'") 'electric-open-delimeter)
(global-set-key (kbd "<") 'electric-open-delimeter)
- Re: Crazy idea for M-(: surround region, (continued)
- Re: Crazy idea for M-(: surround region, Jesper Harder, 2003/07/12
- Re: Crazy idea for M-(: surround region, Eric Hanchrow, 2003/07/12
- Re: Crazy idea for M-(: surround region, Olivier Aumage, 2003/07/13
- Re: Crazy idea for M-(: surround region, Kevin Rodgers, 2003/07/14
- Re: Crazy idea for M-(: surround region, Barry Margolin, 2003/07/14
- Re: Crazy idea for M-(: surround region, Stefan Monnier, 2003/07/14
- Re: Crazy idea for M-(: surround region, Kai Großjohann, 2003/07/14
- Re: Crazy idea for M-(: surround region, Barry Margolin, 2003/07/14
- Re: Crazy idea for M-(: surround region, Kai Großjohann, 2003/07/15
- Re: Crazy idea for M-(: surround region, Stefan Monnier, 2003/07/15
Re: Crazy idea for M-(: surround region,
Sandip Chitale <=
Re: Crazy idea for M-(: surround region, Ilya Zakharevich, 2003/07/15