all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* LaTeX templates (or just templates in general)
@ 2009-05-16  5:56 Orri
  0 siblings, 0 replies; 5+ messages in thread
From: Orri @ 2009-05-16  5:56 UTC (permalink / raw)
  To: Help-gnu-emacs


I am rather new to emacs.

I have used the editor TextMate on mac and it has a very nice feature I like
and was wondering how I can acheive a similar thing in emacs.

When I am in latex mode in textmate and write temp[tabkey], I can choose
from a list of code segments to insert to the current file (or buffer).  I
often use this to insert frequently used code segments (3-10 lines) to
achieve tasks I frequently do (code to insert a figure with caption). These
segments are stored in a folder named ~/Library/Applications
Support/LaTeX/Templates

I know I can use [C-x i], But it takes so much time to write the correct
path every single time.
So I am looking for something like [C-x i] except it by default starts in
specified directory (rather than the current directory). 

I know I can of course, in every latex project directory specify a symbolic
link (with a short name) to this directory, but I find it to be too much of
dirty hack.

Does anyone have any suggestions about how to acieve this?
-- 
View this message in context: http://www.nabble.com/LaTeX-templates-%28or-just-templates-in-general%29-tp23570689p23570689.html
Sent from the Emacs - Help mailing list archive at Nabble.com.





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

* Re: LaTeX templates (or just templates in general)
       [not found] <mailman.7255.1242453781.31690.help-gnu-emacs@gnu.org>
@ 2009-05-16 12:52 ` Jean Magnan de Bornier
  2009-05-17  1:29   ` Tim X
  2009-05-16 17:43 ` Vagn Johansen
  1 sibling, 1 reply; 5+ messages in thread
From: Jean Magnan de Bornier @ 2009-05-16 12:52 UTC (permalink / raw)
  To: help-gnu-emacs

Orri <orritomasson@gmail.com> wrote :

| I am rather new to emacs.
>
| I have used the editor TextMate on mac and it has a very nice feature I like
| and was wondering how I can acheive a similar thing in emacs.
>
| When I am in latex mode in textmate and write temp[tabkey], I can choose
| from a list of code segments to insert to the current file (or buffer).  I
| often use this to insert frequently used code segments (3-10 lines) to
| achieve tasks I frequently do. These segments are stored in a folder named
| ~/Library/Applications Support/LaTeX/Templates
>
| I know I can use [C-x i], But it takes so much time to write the correct
| path every single time.
| So I am looking for something like [C-x i] except it by default starts in
| specified directory (rather than the current directory). 
>
| I know I can of course, in every latex project directory specify a symbolic
| link (with a short name) to this directory, but I find it to be too much of
| dirty hack.
>
| Does anyone have any suggestions about how to acieve this?

Hi,

I have several elisp functions defined in my .emacs file to help me the
way you think: here is one to add a frame to a beamer document:

.....................
(defun addframe ()
  "Ouvre une frame dans beamer" 
 (interactive)
   (insert "\\begin{frame}
 \\frametitle{}
\\end{frame}")
  (backward-char 13)
  (indent-for-tab-command)
)

(global-set-key (kbd "C-c f") 'addframe)
....................

You can write many of those to your needs...

-- 
Jean


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

* Re: LaTeX templates (or just templates in general)
       [not found] <mailman.7255.1242453781.31690.help-gnu-emacs@gnu.org>
  2009-05-16 12:52 ` LaTeX templates (or just templates in general) Jean Magnan de Bornier
@ 2009-05-16 17:43 ` Vagn Johansen
  2009-05-17  0:55   ` Orri
  1 sibling, 1 reply; 5+ messages in thread
From: Vagn Johansen @ 2009-05-16 17:43 UTC (permalink / raw)
  To: help-gnu-emacs

Orri <orritomasson@gmail.com> writes:

> I am rather new to emacs.
>
> I have used the editor TextMate on mac and it has a very nice feature I like
> and was wondering how I can acheive a similar thing in emacs.
>
> When I am in latex mode in textmate and write temp[tabkey], I can choose
> from a list of code segments to insert to the current file (or buffer).  I
> often use this to insert frequently used code segments (3-10 lines) to
> achieve tasks I frequently do. These segments are stored in a folder named
> ~/Library/Applications Support/LaTeX/Templates

http://www.emacswiki.org/emacs/CategoryTemplates

I would suggest yasnippet for people new to Emacs
  
  http://code.google.com/p/yasnippet/

It uses one file per template. It currently only has one latex-mode
template.


-- 
Vagn Johansen


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

* Re: LaTeX templates (or just templates in general)
  2009-05-16 17:43 ` Vagn Johansen
@ 2009-05-17  0:55   ` Orri
  0 siblings, 0 replies; 5+ messages in thread
From: Orri @ 2009-05-17  0:55 UTC (permalink / raw)
  To: Help-gnu-emacs


Thank you Vagn.
yasnippet works great and is exacly what I was looking for. 

It is, according to its project page, inspired by the template system in
TextMate I referred to.
-- 
View this message in context: http://www.nabble.com/LaTeX-templates-%28or-just-templates-in-general%29-tp23570689p23579244.html
Sent from the Emacs - Help mailing list archive at Nabble.com.





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

* Re: LaTeX templates (or just templates in general)
  2009-05-16 12:52 ` LaTeX templates (or just templates in general) Jean Magnan de Bornier
@ 2009-05-17  1:29   ` Tim X
  0 siblings, 0 replies; 5+ messages in thread
From: Tim X @ 2009-05-17  1:29 UTC (permalink / raw)
  To: help-gnu-emacs

Jean Magnan de Bornier <jean@bornier.net> writes:

> Orri <orritomasson@gmail.com> wrote :
>
> | I am rather new to emacs.
>>
> | I have used the editor TextMate on mac and it has a very nice feature I like
> | and was wondering how I can acheive a similar thing in emacs.
>>
> | When I am in latex mode in textmate and write temp[tabkey], I can choose
> | from a list of code segments to insert to the current file (or buffer).  I
> | often use this to insert frequently used code segments (3-10 lines) to
> | achieve tasks I frequently do. These segments are stored in a folder named
> | ~/Library/Applications Support/LaTeX/Templates
>>
> | I know I can use [C-x i], But it takes so much time to write the correct
> | path every single time.
> | So I am looking for something like [C-x i] except it by default starts in
> | specified directory (rather than the current directory). 
>>
> | I know I can of course, in every latex project directory specify a symbolic
> | link (with a short name) to this directory, but I find it to be too much of
> | dirty hack.
>>
> | Does anyone have any suggestions about how to acieve this?
>
> Hi,
>
> I have several elisp functions defined in my .emacs file to help me the
> way you think: here is one to add a frame to a beamer document:
>
> .....................
> (defun addframe ()
>   "Ouvre une frame dans beamer" 
>  (interactive)
>    (insert "\\begin{frame}
>  \\frametitle{}
> \\end{frame}")
>   (backward-char 13)
>   (indent-for-tab-command)
> )
>
> (global-set-key (kbd "C-c f") 'addframe)
> ....................
>
> You can write many of those to your needs...


I find tempo, which comes with emacs, to be good for this sort of
thing. I have various template files that ae loaded at startup and bound
to various keys. Usually, I do this in a load hook for the mode. I have
one general purpose template I use for headers. e.g.

(tempo-define-template "generic-header"
        '((format "%s" comment-start)
          "      Filename: " (file-name-nondirectory (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)
          "        Author: Tim Cross <tcross@some.place.com>" 'n
          (format "%s" comment-start) "   Description:" 'n
          (format "%s" comment-start) 'n
          'n))

;;; Lets setup some key bindings.

(global-set-key [(f5)] 'tempo-template-generic-header)

The above template uses the setting of the modes current comment
character to insert a file header that has a dynamic last modified
timestamp that is automatically updated when I save the file. 

What I find useful with tempo modes is that you can have it prompt for
values that it can then insert multiple times. For example, I have the
following template for creating plsql spec files

(tempo-define-template "plsql-package-spec"
                '("CREATE OR REPLACE PACKAGE " (p "Package name: " pname) 'n
                  "IS" 'n
                  'n
                  "-- Unique package identifier" '> 'n
                  "pkg_id CONSTANT urs.identifier := '" (s pname) "';" '> 'n
                  "pkg_ver CONSTANT urs.version := 1.00;"
                  'n 'n 'n
                  "END " (s pname) ";" 'n
                  "/" 'n))

this template prompts me for the name of the package and inserts it into
the definition line and sets a constant in the package. 

In addition to prompting for values that can be used multiple times in
your template, you can also control where the cursor is left and whether
or not the template should take note of mode indentation etc. 

It takes a bit of playing around to get the feel for the package, but
once you have a handle on it, its quite easy to create new templates. 

I define various hot keys to insert the templace. For example, in
plsql-mode, I hit C-c s to inisert a package spec, C-c p to insert a
procedure skeleton etc. 

There is also skeleton-mode, that is another template system for
emacs. It is a bit harder to get your head wrapped around, but it is
very powerful. 

You can also achieve a lot of template like functionality with abbrev
mode. 

I don't actually have any templates for latex as I finid the auctex
package handles it all pretty well 'out of the box'. If your using
beamer or some such package, you can re-evaluate so that it has some
knowledge about the various macros and commands. Inserting a new beamer
frame is then just a keystroke away. 

HTH

Tim

-- 
tcross (at) rapttech dot com dot au


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

end of thread, other threads:[~2009-05-17  1:29 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.7255.1242453781.31690.help-gnu-emacs@gnu.org>
2009-05-16 12:52 ` LaTeX templates (or just templates in general) Jean Magnan de Bornier
2009-05-17  1:29   ` Tim X
2009-05-16 17:43 ` Vagn Johansen
2009-05-17  0:55   ` Orri
2009-05-16  5:56 Orri

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.