VOICE Home Page: http://www.os2voice.org
April 2001

[Newsletter Index]
[Previous Page] [Next Page]
[Features Index]


Emacs 20.6.1 under OS/2 -
Part II

By: Oliver Heidelbach ©April 2001

(Editor's Note. Emacs is a self-documenting real-time display editor, extensible and customizable in a dialect of the Lisp programming language, that can be used to create HTML, Info and TeX and any other plain text documents. Further information can be found at <http://www.gnu.org/software/emacs/emacs.html>.)

Basically it was planned to devote a good part of this article to addtional mail setup (bbdb, mailcrypt and tm). As it turned out that the current port of Emacs still has some basic problems serving as a reliable mailer, I dropped that idea. Instead we will have a look at some other things, but read on...

Additional Setup

Emacs is an extensible editor. It comes with many extensions written in elisp - the Emacs own Lisp programming language - developed over the years. All those files officialy part of the Emacs distribution reside in the lisp directory x:\emacs\20.6.\lisp.

You don't have to learn elisp to use Emacs efficiently. However changing this or that in the Emacs setup files does not require much skill and you will need to do it if you would like to install additional elisp packages. Please also note that exactly this problem is minimized by the newly introduced Emacs customization menu mentioned in part I of this article. Emacs 20.6.1 under OS/2 - Part I

New elisp snippets and problem solutions are are written all the time and not all older snippets have made it in into the official distribution. Many of those get published in the Usenet newsgroup gnu.emacs.sources, others are collected on web sites such as http://www.cis.ohio-state.edu/emacs-lisp/, the old official archive at the Ohio State University recently re-opened, or http://anc.ed.ac.uk/~stephen/emacs/ell.html, a privately maintained collection with many recent code samples.

While most of those elisp extensions will work fine under OS/2 some actually might not. One example I found which may be of common interest is browse-url.el.


browse-url.el provides an interface to the most common web browsers from within any Emacs buffer. Once installed you are able to visit any URL just by pressing a key combination on your keyboard.

browse-url.el does work under OS/2 as well, but does not check correctly for Netscape. In fact it assumes Netscape for Un*x to be installed.

In function (defun browse-url-netscape (url &optional new-window) the statement

  (if (eq window-system 'w32)

      (list url)


     (if new-window '("-noraise"))

     (list "-remote"

           (concat "openURL(" url

                   (if new-window ",new-window")


has to be changed to

  (if (memq window-system '(w32 pm))  ;; ready for OS/2 Warp ;-)

      (list url)


     (if new-window '("-noraise"))

     (list "-remote"

           (concat "openURL(" url

                   (if new-window ",new-window")


Download the OS2-ready browse-url.el

HTML helper mode

Although one can use Emacs for things one wouldn't expect an editor to be capable of, e.g. sending mail and news, plotting areas of the Mandelbrot set, playing tetris etc., of course its basic use is editing.

Elisp programs providing editing and/or syntax highlighting functions for certain types of files are called 'modes'. One such mode, which has not made it yet into the official distribution, but which is nevertheless very popular is the HTML helper mode introduced by Nelson Minar. It has an own home page on the WWW at http://www.santafe.edu/~nelson/tools/.

Installing a new mode in Emacs is easy. Just copy the appropriate elisp file, in this case html-helper-mode.el, to your personal lisp directory, e.g. x:\emacs\lisp. Either load it into Emacs and byte-compile the file via the 'Emacs-Lisp' menu or issue the following at the OS/2 command line:
emacs -batch -q -no-site-file -f batch-byte-compile html-helper-mode.el

Byte compilation is done on human readable elisp files to make those more compact and faster processible by Emacs. Byte compiled files have the extension *.elc and are not human readable or editible anymore, so please don't delete the original elisp file.

Now that you have managed to install your first mode, you will need to setup a few things in your site-start.el or .emacs file. (For an explanation of those, please see part I of this article.)

Put the following into your Emacs setup file:

(setq auto-mode-alist (cons '("\\.htm.*$" . html-helper-mode)


(autoload 'html-helper-mode "html-helper-mode" "Yay HTML" t)

You are done with the standard setup. Most of the external and even internal elisp modes or packages require a little such setup. You will find a description of the user-definable variables and other things to set up in the beginning comments of the elisp files themselves.

There are other things you may want to define. You may want to change the formatting of the time stamp string HTML helper mode provides. A possible solution could be the following:

(defun my-html-helper-default-insert-timestamp ()

  "Default timestamp insertion function"

  (insert "[<EM>" (current-time-string) "</EM>]\n"))

(setq html-helper-timestamp-hook 'my-html-helper-default-insert-timestamp)

(setq html-helper-do-write-file-hooks t

      html-helper-build-new-buffer t

      html-helper-use-expert-menu t

      html-helper-address-string "<STRONG>* page title *</STRONG>

Oliver Heidelbach <A HREF=\"mailto:ohei@snafu.de\"><ohei@snafu.de></A>")

These statements format the time stamp string in italics by default, put on the expert menu and personalize the address string to insert below HTML documents.

HTML helper mode also provides a function to define a template for new HTML files to be edited. Again just as an example this is the setup from my own site-start.el If you plan do use this to define your own template, please don't forget to fill in your name and email address where appropriate.

(setq html-helper-new-buffer-template


    "<!-- comment line 1 -->\n<!-- comment line 2  -->\n"


    "<LINK REV=\"owns\" TITLE=\"Oliver Heidelbach, Berlin, Germany\" HREF=\"mailto:ohei\@snafu.de\">\n"

    "<META NAME=\"Author\" CONTENT=\"Oliver Heidelbach\">\n"

    "<META NAME=\"DESCRIPTION\" CONTENT=\"******\">\n"

    "<META NAME=\"KEYWORDS\" CONTENT=\"******\">\n"

    "<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html;CHARSET=iso8859-1\">\n"

    "<TITLE>" p "</TITLE>\n"



    "<H1>" p "</H1>\n\n"



    "<ADDRESS>" html-helper-address-string "</ADDRESS>\n"




The above is already a fairly complete setup of HTML helper mode and my real setup does not differ very much from it.

HTML template automatically genenerated by HTML helper mode
Above: HTML template automatically genenerated by HTML helper mode

Mule independent character set switching

If you are living outside the US, it is most likely that you want your editor to be not only capable of an extended ASCII set of characters, but also to be able to edit documents in the ISO-8859-1 character set which is also widely used on the internet. Of course the following may also be useful to you if you live inside the US.

A while back MULE was included into the official Emacs distribution and this port brings it to the OS/2 platform as well. MULE is an acronym and stands for 'Multilingual Enhancement of GNU Emacs'. While Mule really can make Emacs understand any language in the world including multibyte character sets like chinese, japanese or korean, we take a look at another solution which is also suitable for older versions of Emacs which came without Mule.

The following uses iso-pc.el, a snippet written by Carsten Leonhardt. As before just copy the elisp file into your personal lisp directory.

Add the following to your Emacs setup file:

;;; Set ISO-8859-1 character set up for correct use with mails, postings etc.

;; (require 'iso-syntax)  ;; only needed for version 19.xx

(require 'iso-pc)

That's basically it, but now we are going for some self-written extensions which should make life really easy. Just put the following into your Emacs setup file too and below the above piece of elisp code.

(defun my-show-current-code-page ()

  "Show active codepage"


  (if (equal (current-code-page) '1004)

      (message (concat "Active codepage is " (current-code-page) " \(ISO-8859-1\)"))

    (message (concat "Active codepage is " (current-code-page) " \(PC\)"))))

(defun my-toggle-code-page ()

  "Toggle codepage between 850 \(PC\) and 1004 \(ISO-8859-1\)"


  (if (equal (current-code-page) '1004)

      (set-code-page '850)

    (set-code-page '1004))

  (message (concat "Using codepage " (current-code-page))))

(defun my-toggle-charset ()

  "Toggle codepage between 850 \(PC\) and 1004 \(ISO-8859-1\)"


  (if window-system



(global-set-key [f9] 'my-toggle-charset)

(global-set-key [C-f9] 'my-show-current-code-page)

The first function my-show-current-code-page shows the current active character set in the mini-buffer, the area at the very bottom of the Emacs window. This is in case we have forgotten which character set is activated. The last two functions do the actual work of switching the character set.

Finally we bind the functions to appropriate keys on the keyboard. Using the above example, pressing function key F9 switches the character set back and forth and pressing the key combination CTRL-F9 shows which of the both alternatives is currently active. Of course you may change the keybindings to fit your own needs.

You may also want to put the line CODEPAGE=437,1004 in your config.sys and you will be able to not only switch codepages in Emacs, but for any OS/2 session with chcp 1004 and chcp 437 respectively. The OS/2 codepage 1004 is not equal to but very similar to the ISO-8859-1 character set. (Editor's Note. Some programs, e.g. DeScribe, rely on the codepage 850 being used.)


As I am an every day Emacs users, one elisp extension I personally cannot live without anymore is edit-history.el. It provides an additional menu entry on the menu bar showing the files which were last edited. It enables you to reload files just by two mouse-clicks instead of having to load those via the file find menu.

To make use of it copy the file into your personal lisp directory, byte-compile it and put the following into your Emacs setup file:

;;; Set up a menu displaying the last visited files

(load "edit-history")

(setq ehistory-history-length 25)

;;; which files to ignore

(setq ehistory-ignore-regexp "/\\(browse\\|diary\\|site-diary\\|tags\\|.*rmail.*\\|.*\.tmp\\|.*a[d]*ress.*\\|.*-scores\\|.*\.bbdb\\)$")


Menu provided by edit-history.el
Above: Menu provided by edit-history.el

Download edit-history.el.

That's it already. Thank you for your time. I hope these articles will evoke some interest in this powerful editor. There are ports for Emacs for nearly every platform, including most Un*x flavours, Windows, Amiga, Atari and of course OS/2. There are Emacs users all over the world and the Internet and Usenet are full of snippets, problem solutions and discussion forums. If you have not already tested this editor, give it a try.

Oliver Heidelbach is an OS/2 user since 1993 and an Emacs user since 1994. He currently works for the Internet Movie Database (IMDb) as content editor.

Article References:
Emacs 20.6.1 under OS/2 - Part I, Basic Installation and Setup

What is Emacs?

Elisp archives on the WWW
Ohio State University archive http://www.cis.ohio-state.edu/emacs-lisp/
Stephen's private archive http://anc.ed.ac.uk/~stephen/emacs/ell.html

Official elisp files changed for OS/2
OS/2 ready browse-url.el http://userpage.fu-berlin.de/~oheiabbd/emacs/browse-url.zip

Other elisp files
edit-history.el http://userpage.fu-berlin.de/~oheiabbd/emacs/edit-history.el
HTML helper mode home page http://www.santafe.edu/~nelson/tools/
iso-pc.el and character set switching functions http://userpage.fu-berlin.de/~oheiabbd/emacs/german-snippets.zip

My commented site-start.el http://userpage.fu-berlin.de/~oheiabbd/emacs/emacs206-os2-site-start.html

[Previous Page ] [ Index] [Next Page ]
VOICE Home Page: http://www.os2voice.org