IceWalkers.com - Linux Software downloads and news
Name : Password :
Linux SoftwareLinux RPMLinux HowtosLink UsAboutAdvertise

HOWTOs

Search Howtos :Match :
Next Previous Contents

6. Dirty Tricks

6.1 Inserting a header automatically

Emacs allows you to hook some actions to any event (opening of a file, saving, running a new mode, etc).

The autoinsert library uses this feature: when you open a new file under Emacs, this library inserts, according to the type of the file, a standard header.

In our case, this standard header could well be the part declaring the document type (LinuxDoc), the title, the author, and the date.

I will describe here two ways to insert such a header. You could insert a template file containing the information to insert, or you could run an elisp routine.

by inserting a file

You must first tell Emacs to run the auto-insert when opening a file, then to read the autoinsert library which declares the auto-insert-alist list which we need to change. This list defines the header to insert for each file type. By default, the file to insert must be in the ~/insert/ directory, but it is possible to redefine the auto-insert-directory variable if you want to put it somewhere else.

Add the following lines to your .emacs file to insert the ~/emacs/sgml-insert.sgml file each time you open a new SGML file:

      (add-hook 'find-file-hooks 'auto-insert)
      (load-library "autoinsert")
      (setq auto-insert-directory "~/emacs/")
      (setq auto-insert-alist
            (append '((sgml-mode .  "sgml-insert.sgml"))
                    auto-insert-alist))
      

You can then write in the ~/emacs/sgml-insert.sgml file your customised header, then re-run Emacs and open some foobar.sgml file. Emacs should ask you to confirm the automatic insertion, and if you answer yes, insert your header.

by running a routine

This works like before, but instead of setting the auto-insert-alist to a file to insert, you need to set it to a function to execute. This is how to proceed, taking for granted you want to write this function in a file named ~/emacs/sgml-header.el. (there's no need to burden your .emacs file with such a function, as it may turn out to be quite long):

      (add-hook 'find-file-hooks 'auto-insert)
      (load-library "autoinsert")
      (add-to-list 'load-path "~/emacs")
      (load-library "sgml-header")
      (setq auto-insert-alist
            (append '(((sgml-mode .  "SGML Mode") . insert-sgml-header))
                    auto-insert-alist))
      

You will find in appendix an example of insert-sgml-header function.


Next Previous Contents
Search Howtos :Match :
Transmission 1.41 beta 2
Lightweight, yet powerful BitTorrent client
X-Moto 0.5.0
2D motocross platform game
Gdm 2.25.1
Reimplementation of the well known xdm program.
Linux Kernel 2.6 2.6.28-rc7
Linux Kernel
Linux Kernel 2.4 2.4.37
Linux Kernel
RIP 7.3
Small linux system for the purpose of system booting or repairing
GEdit 2.25.1
Small but powerful text editor
VLC media player 0.9.7
Cross-platform media player and streaming server
GNOME 2.25.2
GNOME desktop environment
WebGUI 7.6.5
A fully featured content management system.
Free IT Magazines, White Papers, eBooks, and more !
Dr. Dobb's Journal

Dr. Dobb's Journal enables programmers to write the most efficient and sophisticated programs and help in daily programming quandaries.

The 7 Things that IT Security Professionals MUST KNOW!

Gain key insight into security problem and find the safest means to protect your technological assets.

Database Trends and Applications

Provides timely coverage of the technology, intelligence and insight needed to plan, implement and manage information-rich projects.

Linux Software Map
Find Linux RPM
Best Rated Linux Software
Most Rated Linux Software
Linux Distributions
Linux Howtos
Quick Survey

Please take our survey and help us improve our website to serve you better.

Thank you.
Linux Software
Linux / IT Resources
Site Resources
Google
Privacy Policy
Contact Us
Submit Software
Advertising info