C-Kermit Case Study #26

[ Previous ] [ Next ] [ Index ] [ C-Kermit Home ] [ Kermit Home ]

Newsgroups: comp.protocols.kermit.misc
From: fdc@columbia.edu (Frank da Cruz)
Subject: Case Study #26: EMACS Kermit Mode
Date: 15 Dec 2003 21:57:46 GMT
Organization: Columbia University

On the recent Slashdot thread, the point was made (several times) that people who like Kermit tend to be the same people who like EMACS. This was either a compliment or an insult, depending on the speaker, but there's definitely some truth to it my case!

Many of us write and edit Kermit scripts in EMACS. But wouldn't it be so much better if EMACS had a Kermit Mode that automatically indented appropriately, lined up comments, etc? Now you can have one. The following instructions should work with all versions of GNU EMACS back to 19.34. Thanks to Alan Mackenzie (Munich, Germany) for lots of help with this:

  1. Get the latest cc-mode (5.30.8 or later) from:

    http://cc-mode.sourceforge.net/release.php

  2. Install it for real on your computer or, if you can't do that, install it in your own file space. Installation is explained in the README file that comes in the package.

  3. If you installed the new cc-mode in your own area, you have to tell EMACS where to find it. Add the following to your ~/.emacs file:

    (setq load-path (cons "~myuserid/cc-mode-5.31" load-path))
    (replacing "~myuserid/cc-mode-5.31" with the path of the directory where you installed the new cc-mode).

Now creating a minimal but serviceable Kermit Mode is easy; just add the following to your ~/.emacs file:

; Kermit mode

(autoload 'awk-mode "cc-mode" nil t) ; Must load new Awk mode!

(define-derived-mode kermit-mode
  awk-mode "Kermit"
  "Major Mode for Kermit Scripts"
  (auto-fill-mode 1)
  (setq fill-column 78)
  (setq indent-tabs-mode nil)
  (setq brace-else-brace 1)
  (setq comment-multi-line nil)
  (setq comment-column 40)
  (setq comment-start "\# ")
  (setq comment-end ""))

Brief explanation: recent releases of EMACS allow you define new major modes that are derived from existing ones. Awk is a language that is somewhat similar to Kermit: it uses braces like C, but does not terminate or separate statements with any particular character (like C does with semicolon). Instead (in the general case) each statement is on its own line. We use "#" as the comment character in kermit-mode because using semicolon confuses the underlying EMACS libraries too much. The old Awk mode didn't work well enough to base Kermit mode on, the new does.

You might also want to associate Kermit Mode with .ksc files. In that case add .ksc to your auto-mode-list:

(setq auto-mode-alist (append '(("\\.ksc" . kermit-mode))))

This causes EMACS to switch to Kermit Mode automatically whenever you visit a file whose name ends in ".ksc".

Kermit Mode not perfect, but it's close. The main problem I've noticed so far is that SWITCH case labels are not "outdented". Anybody who knows EMACS LISP better than I do is welcome to make improvements!

- Frank

[ Top ] [ Previous ] [ Next ] [ Index ] [ C-Kermit Home ] [ Kermit Home ]


Kermit Case Study 26 / Columbia University / kermit@columbia.edu / 15 Dec 2003