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

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

Re: Inserting standard text


From: Tim X
Subject: Re: Inserting standard text
Date: Fri, 27 Apr 2007 09:51:39 +1000
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.95 (gnu/linux)

anders <anders.u.persson@gmail.com> writes:

> Hi!
> I have tryed to relace my development enviroment with Emacs, and i
> have found it gives me
> a lot of stuff i like.
>
> Becurse i am new maby my question i simple, i have read a beginners
> book but missing some.
>
> I have debug text, that i tody in my old editor just press a key and
> it insert this text.
>
> Wha't is the easys way to do this, ELISP + KEYDEF or,,
>
> I am develop in C under windows and compiling on a Solaris machine
> any tips regarding whould be nice.
>

Emacs comes with two packages which may meet your needs, plus there are a
number of add-on 'template' style packages out there. 

The two standard packages are skeleton mode and tempo mode. Each allows varying
degrees of static and dynamic templates, which you can then bind to a key. For
example, I use this to put a standard template at the beginning of my code
files -

;;;                                                                

(tempo-define-template "generic-header"
                                   '((format "%s" comment-start) 
                        "      Filename: " (buffer-file-name) 'n
                                                 (format "%s" comment-start) " 
Creation Date: "
                                                 (format-time-string "%A, %d %B 
%Y %I:%M %p %Z") 'n
                                                 (format "%s" comment-start) " 
Last Modified: " 'n
                                                 (format "%s" comment-start) 
                                                 "           Job: " (p "Job: ") 
'n
                                                 (format "%s" comment-start) 
                                                 "        Author: Tim Cross 
<tcross@une.edu.au>"
                                                 'n
                                                 (format "%s" comment-start) "  
 Description:" 'n
                                                 (format "%s" comment-start) 'n
                                                 'n))

I have this function bound to F6, so that I can insert it in a new file if
needed. The template contains the name of the file (and location) the date it
was created and a modified date that is automatically updated whenever the file
is saved. I've defined other templates for various languages that will setup
standard constructs in that language. Some of the templates, like the one
above, also prompts for information that is put into the template when it is
inserted. 

If you don't want/need this level of flexibility or don't feel confident about
working with a bit of elisp, you can achieve a simple templating solution using
just a template file and creating either a named keyboard macro or function
that just inserts a template file into the current buffer. 

You should also check out abbrevs. Many modes create 'electric' functions that
replace a bit of text with a simple template. For example, I think C mode uses
a combination of abbrev mode and skeleton mode so that while in that mode,
typeing 'if' can result in 

if ( !  ) {

}

where ! indicates where the pointer/cursor will be after typing 'if'. 

Tim
-- 
tcross (at) rapttech dot com dot au


reply via email to

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