From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Tim X Newsgroups: gmane.emacs.help Subject: Re: LaTeX templates (or just templates in general) Date: Sun, 17 May 2009 11:29:35 +1000 Organization: Rapt Technologies Message-ID: <87hbzk7c00.fsf@lion.rapttech.com.au> References: <87my9ddxbj.fsf@bornier.net> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1242524511 13400 80.91.229.12 (17 May 2009 01:41:51 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 17 May 2009 01:41:51 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun May 17 03:41:44 2009 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1M5VNn-0001qh-9C for geh-help-gnu-emacs@m.gmane.org; Sun, 17 May 2009 03:41:43 +0200 Original-Received: from localhost ([127.0.0.1]:58098 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1M5VNm-0003OR-P5 for geh-help-gnu-emacs@m.gmane.org; Sat, 16 May 2009 21:41:42 -0400 Original-Path: news.stanford.edu!newsfeed.stanford.edu!newshub.sdsu.edu!news.astraweb.com!border2.newsrouter.astraweb.com!not-for-mail Original-Newsgroups: gnu.emacs.help User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.93 (gnu/linux) Cancel-Lock: sha1:gw3wtZirHNYhipCfguVOpGDsu5w= Original-Lines: 121 Original-NNTP-Posting-Host: fe032f5d.news.astraweb.com Original-X-Trace: DXC=ZXQ78iCENf5hn]AcMfkkb9L?0kYOcDh@:e:PNj8E6J4=hcM: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:64509 Archived-At: Jean Magnan de Bornier writes: > Orri 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 " '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