
(defvar sas-c-mode nil "\
Variable indicating if the sas-c-mode is active.")

(defvar sas-c-compile-command "sc:c/smake" "\
The command to run when a sas-c-build is executed.")

(defun sas-c-mode (arg) "\
Minor mode which enables Emacs to communicate with SCMSG,
the error handler from SAS/C. If the function is called without args
the mode is toggled, a positive integer switchen it on and a negative off.

The following keys are added to the current local map:

C-c C-a		Display the alternative file, if any.
C-c C-c		Build a project (normally execute smake).
C-c C-d		Delete the current message, and display next
C-c C-h		Hide the SCMSG window.
C-c C-l		Redisplay current message.
C-c C-n		Display next error.
C-c <down>	dito
C-c C-p		Display previous error.
C-c C-q		Remove all messages for a certain primary file.
C-c C-s		Show the SCMSG window.
C-c <up>	dito
C-c <		Go to the first error message.
C-c <sh. up>	dito
C-c >		Go to the last error message.
C-c <sh. down>	dito

When sas-c-mode is switched on, the hook sas-c-hook is called.

If a key shall be defined, the best way is to use a hook and the
sas-c-define-key function. This way the keys are removed and the
original values are restored when sas-c-mode is disabled.

For example:
 (setq sas-c-mode-hook '(lambda ()
		    (sas-c-define-key \"\\C-ca\" 'your-favorite-fnk)
		    (sas-c-define-key \"\\C-cb\" 'another-function)
		    ))" (interactive "P") (byte-code "ÆˆÇÁ!ˆÇÅ!ˆ	
?ƒ 	?‚ È
!ÉV‰ˆÊÁ\"†* ËB‰ˆ	…1 ?ƒŽ ÌÍÄ\"ˆÆ‰ˆÎÏÐ\"ˆÎÑÒ\"ˆÎÓÔ\"ˆÎÕÖ\"ˆÎ×Ø\"ˆÎÙÚ\"ˆÎÛÚ\"ˆÎÜÝ\"ˆÎÞÝ\"ˆÎßà\"ˆÎáâ\"ˆÎãä\"ˆÎåä\"ˆÎæç\"ˆÎèç\"ˆéê!‚™ 	?…” …™ ë )‡" [sas-c-mode-orig sas-c-mode arg minor-mode-alist t sas-c-original-keys nil make-local-variable prefix-numeric-value 0 assq (sas-c-mode " SAS/C") amiga-arexx-do-command "call addlib('slashquote.library',-20,-30,0)" sas-c-define-key "" sas-c-display-altfile "" sas-c-build "" sas-c-delete "" sas-c-hide "" sas-c-display-error "" sas-c-next "B" "" sas-c-prev "A" "" sas-c-delcomp "" sas-c-show "<" sas-c-top "T" ">" sas-c-bottom "S" run-hooks sas-c-mode-hook sas-c-undef-keys] 23))

(defun sas-c-define-key (key fnk) "\
Make a keybinding which can be undone." (byte-code "	Ã	!BB‰ˆÄ	
\"‡" [sas-c-original-keys key fnk local-key-binding local-set-key] 4))

(defun sas-c-undef-keys nil "\
Unmake the keybindings made by sas-c-mode
and restore the keys previous values." (byte-code "…& @A@@Ã	!ƒ Ä
!‚ Å
	\"*ˆA‰ˆ‚  ‡" [sas-c-original-keys fnk key numberp local-unset-key local-set-key] 6))

(defun sas-c-delete nil "\
Delete the current error message and move to the next." (interactive) (byte-code "ÀˆÁÂ!ˆÃ ‡" [nil sas-c-scmsg "delete" sas-c-display-error] 3))

(defun sas-c-next nil "\
Move to the nest error message." (interactive) (byte-code "ÀˆÁÂ!ˆÃ ‡" [nil sas-c-scmsg "next" sas-c-display-error] 3))

(defun sas-c-prev nil "\
Move to the prevous error message." (interactive) (byte-code "ÀˆÁÂ!ˆÃ ‡" [nil sas-c-scmsg "prev" sas-c-display-error] 3))

(defun sas-c-top nil "\
Move to the first error message." (interactive) (byte-code "ÀˆÁÂ!ˆÃ ‡" [nil sas-c-scmsg "top" sas-c-display-error] 3))

(defun sas-c-bottom nil "\
Move to the last error message." (interactive) (byte-code "ÀˆÁÂ!ˆÃ ‡" [nil sas-c-scmsg "bottom" sas-c-display-error] 3))

(defun sas-c-delcomp-current nil "\
Delete all messages for the primary file of the current error." (byte-code "ÀÁ!‡" [sas-c-scmsg "delcomp"] 2))

(defun sas-c-delcomp (filename) "\
Delete all messages with the specified filename as primary filename." (interactive "fFilename (Press return for current file): ") (byte-code "ÁˆÂÃÄ\"!‡" [filename nil sas-c-scmsg format "delcomp \"%s\""] 4))

(defun sas-c-show (& optional arg) "\
Show the scmsg window.
If called with arguments the window gets unactivated." (interactive "P") (byte-code "ÁˆÂƒ Ã‚ Ä!‡" [arg nil sas-c-scmsg "show" "show activate"] 2))

(defun sas-c-hide nil "\
Show the scmsg window." (interactive) (byte-code "ÀˆÁÂ!‡" [nil sas-c-scmsg "hide"] 2))

(defun sas-c-build nil "\
Build with SAS/C. (The command sas-c-compile-command is executed
and the output is places in the buffer *compilation*" (interactive) (byte-code "ÁˆÂ!‡" [sas-c-compile-command nil compile] 2))

(defun sas-c-display-error nil "\
Display the current error in SCMSG." (interactive) (byte-code "ÁˆÂÃ!ÄÅ\"ƒ ÆÇ!‚\" ÈÉÊ!ÂË!ÂÌ!ÂÍ!%)‡" [file nil sas-c-scmsg-str "file" equal "" message "No more errors" sas-c-view-message sas-c-scmsg-num "line" "text" "class" "errnum"] 13))

(defun sas-c-display-altfile nil "\
Display the secondary file. (Same as C-u sas-c-display-error.)" (interactive) (byte-code "ÁˆÂÃ!ÄÅ\"ƒ ÆÇ!‚\" ÈÉÊ!ÂË!ÂÌ!ÂÍ!%)‡" [file nil sas-c-scmsg-str "altfile" equal "" message "No alternate file" sas-c-view-message sas-c-scmsg-num "altline" "text" "class" "errnum"] 13))

(defun sas-c-view-message (file line text class errnum) (byte-code "Æ!ˆÇ`!ˆÈ	!ˆÉÊ\"
… Ë
O‰ˆÌÍÎ
ƒ) Ï‚* Ð%!)‡" [file line isalt text class errnum sas-c-get-file set-mark goto-line string-match "; See line [0-9]* file \".*\"" 0 message format "%s %s%s: %s" " (Alt)" ""] 11))

(defun sas-c-get-file (file) "\
Get the file requested into a visiable buffer." (byte-code "Ã	!ƒ Ä!
ƒ Å
!‚ Æ!)‚  Ç	!)‡" [buf file win get-file-buffer get-buffer-window select-window switch-to-buffer find-file] 6))

(defun sas-c-scmsg (command) "\
Sends a command to SCMSG." (byte-code "ÂÃÄQÁ\"‡" [command t amiga-arexx-do-command "address 'SC_SCMSG' '" "'"] 4))

(defun sas-c-scmsg-str (command) "\
Sends a command to SCMSG and sets the resulting string in sas-c-result." (byte-code "ÃÄÅQÁ\"ˆ
‡" [command t sas-c-result amiga-arexx-do-command "options results; address 'SC_SCMSG' '" "'; address 'EMACS1' '(setq sas-c-result' slashquote(result)')'"] 4))

(defun sas-c-scmsg-num (command) "\
Sends a command to SCMSG and sets the resulting number in sas-c-result." (byte-code "ÃÄÅQÁ\"ˆ
‡" [command t sas-c-result amiga-arexx-do-command "options results; address 'SC_SCMSG' '" "'; address 'EMACS1' '(setq sas-c-result 'result')'"] 4))
