unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* How to make a mode dependent operation ?
@ 2010-12-04 19:50 Fren Zeee
  2010-12-04 20:08 ` Dimitri Fontaine
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Fren Zeee @ 2010-12-04 19:50 UTC (permalink / raw)
  To: Emacs Dev [emacs-devel]

Here is a simple newbie problem :

In c-mode, I want to insert a skeleton of function as


 () {



}


and In lisp-mode, I want

( defun ()
""


)


and similarly in scheme, java, python, haskell, pascal ...


What is the quick but maybe not the dirty way to do it ?


What is the PRO way to do it ? I have heard a little about the hooking
hooks :)


What is a hook and what is proper place of use ? Is it appropriate for
this kind of private customization ?


Franz



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

* Re: How to make a mode dependent operation ?
  2010-12-04 19:50 How to make a mode dependent operation ? Fren Zeee
@ 2010-12-04 20:08 ` Dimitri Fontaine
  2010-12-04 20:54 ` Eric M. Ludlam
  2010-12-04 21:40 ` Glenn Morris
  2 siblings, 0 replies; 4+ messages in thread
From: Dimitri Fontaine @ 2010-12-04 20:08 UTC (permalink / raw)
  To: Fren Zeee; +Cc: Emacs Dev [emacs-devel]

Fren Zeee <frenzeee@gmail.com> writes:
> In c-mode, I want to insert a skeleton of function as
[...]
> and similarly in scheme, java, python, haskell, pascal ...

See either (info "(autotype) Top") in bare Emacs, or yasnippet here:

  http://code.google.com/p/yasnippet/

Regards,
-- 
dim



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

* Re: How to make a mode dependent operation ?
  2010-12-04 19:50 How to make a mode dependent operation ? Fren Zeee
  2010-12-04 20:08 ` Dimitri Fontaine
@ 2010-12-04 20:54 ` Eric M. Ludlam
  2010-12-04 21:40 ` Glenn Morris
  2 siblings, 0 replies; 4+ messages in thread
From: Eric M. Ludlam @ 2010-12-04 20:54 UTC (permalink / raw)
  To: Fren Zeee; +Cc: Emacs Dev [emacs-devel]

Hi,

To create a mode-specific operation, or a function that has different 
behaviors based on the major-mode of a given buffer, you can use 
'mode-local'.

Mode-local is a part of Emacs 23.2, and you can use 
define-overloadable-function to create the default behavior.  Then for 
each mode, use define-mode-local-override to create an implementation 
for that mode.

If you are specifically looking into template insertion, there is 
SRecode which is just another template system like skeleton, tempo, etc. 
  It is targeted at mode independent code generation, and has some 
templates for C, lisp, and Java already for basic function creation. 
Tools like autocomplete or yasnippet has a better UI if you want to 
insert random small bits of text.

To turn on SRecode, use global-srecode-minor-mode.

Eric

On 12/04/2010 02:50 PM, Fren Zeee wrote:
> Here is a simple newbie problem :
>
> In c-mode, I want to insert a skeleton of function as
>
>
>   () {
>
>
>
> }
>
>
> and In lisp-mode, I want
>
> ( defun ()
> ""
>
>
> )
>
>
> and similarly in scheme, java, python, haskell, pascal ...
>
>
> What is the quick but maybe not the dirty way to do it ?
>
>
> What is the PRO way to do it ? I have heard a little about the hooking
> hooks :)
>
>
> What is a hook and what is proper place of use ? Is it appropriate for
> this kind of private customization ?
>
>
> Franz
>
>



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

* Re: How to make a mode dependent operation ?
  2010-12-04 19:50 How to make a mode dependent operation ? Fren Zeee
  2010-12-04 20:08 ` Dimitri Fontaine
  2010-12-04 20:54 ` Eric M. Ludlam
@ 2010-12-04 21:40 ` Glenn Morris
  2 siblings, 0 replies; 4+ messages in thread
From: Glenn Morris @ 2010-12-04 21:40 UTC (permalink / raw)
  To: emacs-devel


This question was simultaneously posted to 5 newsgroups
(gnu.emacs.help, comp.emacs, comp.lang.lisp, comp.unix.shell,
comp.emacs.xemacs) and this mailing list.



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

end of thread, other threads:[~2010-12-04 21:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-12-04 19:50 How to make a mode dependent operation ? Fren Zeee
2010-12-04 20:08 ` Dimitri Fontaine
2010-12-04 20:54 ` Eric M. Ludlam
2010-12-04 21:40 ` Glenn Morris

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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).