unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* how to close braces in all modes automatically?
@ 2003-11-05 23:11 Patrick Drechsler
  2003-11-06 10:03 ` Yongtao Yang
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Patrick Drechsler @ 2003-11-05 23:11 UTC (permalink / raw)


Hi,

is there a simple way of closing all braces automatically in all
modes (i.e. HTML, Java, LaTeX, Matlab,...)?

My Linux (Suse 8.2) came with a snipplet which does this for
LaTeX-mode but I haven't been able to adopt it for *all* modes.

--8<------------------------schnipp------------------------->8---
(defun TeX-Inserting (sta stb stc)
    (if (= (preceding-char) sta )
	(insert stb)
      (progn (insert stc) (backward-char 1))))
(defun TeX-schweif () (interactive "*") (TeX-Inserting ?\\ "{"  "{}"))
(defun TeX-rundekl () (interactive "*") (TeX-Inserting ?\\ "("  "()"))
(defun TeX-eckigek () (interactive "*") (TeX-Inserting ?\\ "["  "[]"))
(add-hook 'LaTeX-mode-hook
      '(lambda ()
	 (local-set-key  "{" 'TeX-schweif)
	 (local-set-key  "(" 'TeX-rundekl)
	 (local-set-key  "[" 'TeX-eckigek)
))					
--8<------------------------schnapp------------------------->8---

Replacing the term 'TeX' with my initials and sticking it into my
~/.emacs didn't do the trick.

Grateful for any help (esp. concerning Matlab),

Patrick
-- 
"If anyone tells me to work smarter, not harder, I will kick him or her, 
hard, in a random body part.  I will then kick him or her a second time, 
"smarter, not harder," which is to say that on the second strike, I'll 
use the same force, but target more carefully.  "           -- Catherine

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: how to close braces in all modes automatically?
  2003-11-05 23:11 how to close braces in all modes automatically? Patrick Drechsler
@ 2003-11-06 10:03 ` Yongtao Yang
  2003-11-06 12:06   ` Patrick Drechsler
  2003-11-06 12:46 ` Jiri Pejchal
  2003-11-06 17:48 ` Sandip Chitale
  2 siblings, 1 reply; 8+ messages in thread
From: Yongtao Yang @ 2003-11-06 10:03 UTC (permalink / raw)


Patrick Drechsler <patrick.drechsler@gmx.net> writes:

> Hi,
> 
> is there a simple way of closing all braces automatically in all
> modes (i.e. HTML, Java, LaTeX, Matlab,...)?
> 
> My Linux (Suse 8.2) came with a snipplet which does this for
> LaTeX-mode but I haven't been able to adopt it for *all* modes.
> 
...
> 
> Grateful for any help (esp. concerning Matlab),
> 

I have the following in my .emacs. Stupid but works. :) You have to
use matlab-mode.el for it to work

====begin=========

(autoload 'matlab-mode "matlab" "Enter Matlab mode." t)
(setq auto-mode-alist (cons '("\\.m$" . matlab-mode) auto-mode-alist))

(defun matlab-electric-semi ()
  "Insert a semicolon in matlab mode.
then linefeed and reindent the new line. "
  (interactive)
  (insert ";")
  (matlab-linefeed))

(defun matlab-electric-cont-line ()
  "Insert a continue line in matlab mode.
then linefeed and reindent the new line. "
  (interactive)
  (insert "...")
  (matlab-linefeed))

(defun matlab-electric-parenthesis ()
  "Insert a pair of parenthesis in matlab mode."
  (interactive)
  (insert "()") 
  (backward-char 1))

(defun matlab-electric-bracket ()
  "Insert a pair of brackets in matlab mode."
  (interactive)
  (insert "[]") 
  (backward-char 1))

(defun matlab-electric-brace ()
  "Insert a pair of braces in matlab mode."
  (interactive)
  (insert "{}") 
  (backward-char 1))

(defun my-matlab-mode-hook ()
     (setq matlab-shell-command-switches '("-nojvm" "-nosplash"))
     (setq matlab-function-indent t)	; if you want function bodies indented
     (setq fill-column 72)		; where auto-fill should wrap
     (setq matlab-indent-level 4)
     (setq matlab-shell-input-ring-size 1024)
     (setq matlab-shell-history-file "~/.matlab/R13/history.m")
     (setq matlab-verify-on-save-flag 'nil)
     (turn-on-auto-fill)
     (local-set-key ";" 'matlab-electric-semi)
     (local-set-key "(" 'matlab-electric-parenthesis)
     (local-set-key "[" 'matlab-electric-bracket)
     (local-set-key "{" 'matlab-electric-brace)
     (local-set-key "\C-\M-m" 'matlab-electric-cont-line)
;     (turn-on-setnu-mode)
      )
====end=========
-- 
Yongtao Yang

email: yangyongtao@yahoo.com

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: how to close braces in all modes automatically?
  2003-11-06 10:03 ` Yongtao Yang
@ 2003-11-06 12:06   ` Patrick Drechsler
  2003-11-06 12:41     ` Yongtao Yang
  0 siblings, 1 reply; 8+ messages in thread
From: Patrick Drechsler @ 2003-11-06 12:06 UTC (permalink / raw)


Thanks for the reply!

Yongtao Yang wrote on 06 Nov 2003 11:03:21 MET:

> I have the following in my .emacs. Stupid but works. :) You have to
> use matlab-mode.el for it to work

[...code...]

Your code doesn't work here -- probably because I'm invoking emacs
from within matlab via EmacsLink..

Any further ideas?

Patrick
-- 
Math is like love -- a simple idea but it can get complicated.
          --R. Drabek

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: how to close braces in all modes automatically?
  2003-11-06 12:06   ` Patrick Drechsler
@ 2003-11-06 12:41     ` Yongtao Yang
  0 siblings, 0 replies; 8+ messages in thread
From: Yongtao Yang @ 2003-11-06 12:41 UTC (permalink / raw)


Patrick Drechsler <patrick.drechsler@gmx.net> writes:

> Thanks for the reply!
> 
> Yongtao Yang wrote on 06 Nov 2003 11:03:21 MET:
> 
> > I have the following in my .emacs. Stupid but works. :) You have to
> > use matlab-mode.el for it to work
> 
> [...code...]
> 
> Your code doesn't work here -- probably because I'm invoking emacs
> from within matlab via EmacsLink..
> 
I don't use EmacsLink. But if you start a new emacs session and open a
*.m file and press '(', did you get a ')' automatically?  Otherwise,
try 'C-h k (' to see if it is binded to some other function.

HTH

-- 
Yongtao Yang

email: yangyongtao@yahoo.com

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: how to close braces in all modes automatically?
  2003-11-05 23:11 how to close braces in all modes automatically? Patrick Drechsler
  2003-11-06 10:03 ` Yongtao Yang
@ 2003-11-06 12:46 ` Jiri Pejchal
  2003-11-06 14:49   ` Patrick Drechsler
  2003-11-06 17:48 ` Sandip Chitale
  2 siblings, 1 reply; 8+ messages in thread
From: Jiri Pejchal @ 2003-11-06 12:46 UTC (permalink / raw)


Patrick Drechsler <patrick.drechsler@gmx.net> writes:

> Hi,
> 
> is there a simple way of closing all braces automatically in all
> modes (i.e. HTML, Java, LaTeX, Matlab,...)?

What about this:

(setq skeleton-pair t)
(global-set-key "(" 'skeleton-pair-insert-maybe)
(global-set-key "[" 'skeleton-pair-insert-maybe)
(global-set-key "\"" 'skeleton-pair-insert-maybe)
(global-set-key "'" 'skeleton-pair-insert-maybe)
(global-set-key "{" 'skeleton-pair-insert-maybe)

 

--
Jiri Pejchal

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: how to close braces in all modes automatically?
  2003-11-06 12:46 ` Jiri Pejchal
@ 2003-11-06 14:49   ` Patrick Drechsler
  0 siblings, 0 replies; 8+ messages in thread
From: Patrick Drechsler @ 2003-11-06 14:49 UTC (permalink / raw)


Hi Jiri,

Jiri Pejchal wrote on 06 Nov 2003 13:46:03 MET:

> Patrick Drechsler <patrick.drechsler@gmx.net> writes:
>
>> Hi,
>> 
>> is there a simple way of closing all braces automatically in all
>> modes (i.e. HTML, Java, LaTeX, Matlab,...)?
>
> What about this:
>
> (setq skeleton-pair t)
> (global-set-key "(" 'skeleton-pair-insert-maybe)
> (global-set-key "[" 'skeleton-pair-insert-maybe)
> (global-set-key "\"" 'skeleton-pair-insert-maybe)
> (global-set-key "'" 'skeleton-pair-insert-maybe)
> (global-set-key "{" 'skeleton-pair-insert-maybe)

Exactly what I was looking for! Thank you very much,

Patrick
-- 
If your operating system goes down more often
than your girlfriend, then either you need to get
a Catholic girl, or you need to stop running NT.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: how to close braces in all modes automatically?
  2003-11-05 23:11 how to close braces in all modes automatically? Patrick Drechsler
  2003-11-06 10:03 ` Yongtao Yang
  2003-11-06 12:46 ` Jiri Pejchal
@ 2003-11-06 17:48 ` Sandip Chitale
  2003-11-07  8:01   ` Patrick Drechsler
  2 siblings, 1 reply; 8+ messages in thread
From: Sandip Chitale @ 2003-11-06 17:48 UTC (permalink / raw)


Check out this thread:

http://groups.google.com/groups?hl=en&lr=lang_en&ie=UTF-8&oe=UTF-8&edition=us&frame=right&th=163242e8bb30f14d&seekm=b607d812.0302280000.6d4fa1b7%40posting.google.com

The idea is that a matching delimiter insertion is done based on the
syntax-table for the mode.

sandip

Patrick Drechsler <patrick.drechsler@gmx.net> wrote in message news:<m3ekwme7h2.fsf@pdrechsler.fqdn.th-h.de>...
> Hi,
> 
> is there a simple way of closing all braces automatically in all
> modes (i.e. HTML, Java, LaTeX, Matlab,...)?
> 
> My Linux (Suse 8.2) came with a snipplet which does this for
> LaTeX-mode but I haven't been able to adopt it for *all* modes.
> 
> --8<------------------------schnipp------------------------->8---
> (defun TeX-Inserting (sta stb stc)
>     (if (= (preceding-char) sta )
> 	(insert stb)
>       (progn (insert stc) (backward-char 1))))
> (defun TeX-schweif () (interactive "*") (TeX-Inserting ?\\ "{"  "{}"))
> (defun TeX-rundekl () (interactive "*") (TeX-Inserting ?\\ "("  "()"))
> (defun TeX-eckigek () (interactive "*") (TeX-Inserting ?\\ "["  "[]"))
> (add-hook 'LaTeX-mode-hook
>       '(lambda ()
> 	 (local-set-key  "{" 'TeX-schweif)
> 	 (local-set-key  "(" 'TeX-rundekl)
> 	 (local-set-key  "[" 'TeX-eckigek)
> ))					
> --8<------------------------schnapp------------------------->8---
> 
> Replacing the term 'TeX' with my initials and sticking it into my
> ~/.emacs didn't do the trick.
> 
> Grateful for any help (esp. concerning Matlab),
> 
> Patrick

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: how to close braces in all modes automatically?
  2003-11-06 17:48 ` Sandip Chitale
@ 2003-11-07  8:01   ` Patrick Drechsler
  0 siblings, 0 replies; 8+ messages in thread
From: Patrick Drechsler @ 2003-11-07  8:01 UTC (permalink / raw)


Hi Sandip,

Sandip Chitale wrote on 06 Nov 2003 18:48:35 MET:

> http://groups.google.com/groups?hl=en&lr=lang_en&ie=UTF-8&oe=UTF-8&edition=us&frame=right&th=163242e8bb30f14d&seekm=b607d812.0302280000.6d4fa1b7%40posting.google.com

Thanks for the link!

Since skeletonizing solves my problem I'll stick with that since it's
a built-in function.

Cheers,

Patrick
-- 
Just saying `no' prevents teenage pregnancy the way `Have a nice day'
cures chronic depression.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2003-11-07  8:01 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-11-05 23:11 how to close braces in all modes automatically? Patrick Drechsler
2003-11-06 10:03 ` Yongtao Yang
2003-11-06 12:06   ` Patrick Drechsler
2003-11-06 12:41     ` Yongtao Yang
2003-11-06 12:46 ` Jiri Pejchal
2003-11-06 14:49   ` Patrick Drechsler
2003-11-06 17:48 ` Sandip Chitale
2003-11-07  8:01   ` Patrick Drechsler

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).