
(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 the function 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 accoring to sas-c-compile-command.
C-c C-c		Build the project the same way the build icon does.
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-m		Build the project using smake
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 sas-c-original-keys nil make-local-variable prefix-numeric-value 0 assq (sas-c-mode " SAS/C") sas-c-define-key "" sas-c-display-altfile "" sas-c-build "" sas-c-compile "" sas-c-delete "" sas-c-hide "" sas-c-display-error "" sas-c-make "" sas-c-next "B" "" sas-c-prev "A" "" sas-c-delcomp sas-c-delfile "" sas-c-show "<" sas-c-top "T" ">" sas-c-bottom "S" run-hooks sas-c-mode-hook sas-c-undef-keys] 25))

(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" 0 message "No more messages" sas-c-display-error] 4))

(defun sas-c-prev nil "\
Move to the prevous error message." (interactive) (byte-code "ÀˆÁÂ!Ã=?ƒ ÄÅ!‚ Æ ‡" [nil sas-c-scmsg "prev" 0 message "No more messages" sas-c-display-error] 4))

(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-delfile-current nil "\
Delete all messages for the secondary file of the current error." (byte-code "ÀÁ!‡" [sas-c-scmsg "delfile"] 2))

(defun sas-c-delfile (filename) "\
Delete all messages with the specified filename as secondary filename." (interactive "fFilename (Press return for current file): ") (byte-code "ÁˆÂÃÄ\"!‡" [filename nil sas-c-scmsg format "delfile \"%\"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-compile nil "\
Build with SAS/C. The command in 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-build nil "\
Build the project the same way the build icon does" (interactive) (byte-code "ÀˆÁÂ!‡" [nil compile "sc:c/sc BUILDPROJECT"] 2))

(defun sas-c-make nil "\
Build the project using smake" (interactive) (byte-code "ÀˆÁÂ!‡" [nil compile "sc:c/smake"] 2))

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

(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‰ˆÏÐÑƒ5 Ò‚6 È%!)‡" [file nil line isalt text class errnum equal "" sas-c-get-file set-mark goto-line string-match "; See line [0-9]* file \".*\"" 0 message format "%s %s%s: %s" " (Alt)"] 12))

(defun sas-c-view-note (text) (byte-code "ÁÂÃ\"!‡" [text message format "Note: %s"] 4))

(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.
Returns the returncode set by SCMSG" (byte-code "ÂÃÄÅQÁ\"!‡" [command t string-to-int amiga-arexx-do-command "address 'SC_SCMSG' '" "'; exit rc"] 5))

(defun sas-c-scmsg-str (command) "\
Sends a command to SCMSG and returns the result string." (byte-code "ÂÃÄQÁ\"‡" [command t amiga-arexx-do-command "options results; address 'SC_SCMSG' '" "'; return result"] 4))

(defun sas-c-scmsg-num (command) "\
Sends a command to SCMSG and returns the resulting number." (byte-code "ÂÃÄÅQÁ\"!‡" [command t string-to-int amiga-arexx-do-command "options results; address 'SC_SCMSG' '" "'; return result"] 5))
