Emacs

From SysCAD Documentation
Jump to navigation Jump to search

Navigation: User Guide ➔ Editors and Utilities ➔ Emacs

Related Links: PGM Introduction


Setting up emacs as the default PGM code editor

It is easy enough to specify emacs as the editor but if you do this you will get a new copy each time you edit a pgm file. Instead you have to use emacs as a server, and specify the client as follows

In the .emacs file:

(server-start)

and specify the client using an environment variable, for example

SYSCAD_TEXT_EDITOR = C:\bin\emacs-23.2\bin\emacsclientw.exe

Emacsclient.png


The latest (and greatest) version of emacs is 23.2 as of May 2010. It now recognizes image files and can deal with them inline. Unfortunately, the .pgm extension happens to coincide with that of a particular image file. This is a text image format, but it is based on the unix newline convention, and emacs thinks that it shouldnt convert to the DOS form which results in spurious ^M characters being displayed. To modify this, customize auto-coding-alist to remove pgm.

Auto-coding-alist.png

Font Locking

Font-locking can be done simply using generic mode, a basic example good enough for most needs would be to add this to the emacs startup file:

(require 'generic-x)

(define-generic-mode 'pgm-code-mode
  '(";") 
  '("byte" "Double" "Str" "Settag" "Gettag" "SetDynTag" "Logerror" "MsgBox")
  '(("\\<if\\|\\<else\\|endif\\|elseif" . 'font-lock-variable-name-face))
  '(".pgm\\'")
  nil)

(defun browse-pgm-help () (interactive) (browse-url "http://help.syscad.net/PGMs"))

This sets some keywords, the comment character and tells emacs that files with a pgm exension use this minor mode. There are a number of other font lock customizations that can be done, but the result ends up looking like a lightning strike on a full wino.

It also defines a command browse-pgm-help which will open the PGM help URL in a browser.

Emacs-fontlock.png