;;*   Sample initials macro source file
;;*   To find additions for CLARION support, search for comments that begin
;;*   with ;;*

;**	_init macro.
;**	Do not change this macro (always overwritten by Setup).
(macro _init
	(
		(extern	autosave				;**	External macro declarations
					toggle_re
		)
		(color 1 7 10 11 12 0x80)	;**	Set the screen colors
		(search_case 1)				;**	Case insensitive search
		(autosave)						;**	Automatic file save when idle
	)
)

;**	Initials macro.
;**	Use this macro for additional customization.
(macro ABC
	(
      (assign_to_key "<Backspace>" "bbkspace")
      (assign_to_key "<Keypad-8>" "NewKeyPad 8")
      (assign_to_key "<Keypad-4>" "NewKeyPad 4")
      (assign_to_key "<Keypad-2>" "NewKeyPad 2")
      (assign_to_key "<Keypad-6>" "NewKeyPad 6")
      (assign_to_key "<Keypad-1>" "NewKeyPad 1")
      (assign_to_key "<Keypad-7>" "NewKeyPad 7")
      (int keyboardFlag)
      (global keyboardFlag)
      (autoload "extsrch" "search_fwd" "search_back" "search_again")

      ;;* Add this line to load CLARION language support
      (autoload "ccompile" "compile_it" "cc")
      ;;* Macro Uppercases statements/inserts parens
      (autoload "up_paren" "up_paren")

		(return)
	)
)


;**	File Extension Macros, etc.
;**	Macros marked "Overwritable" may be overwritten by SETUP.

(macro NewKeyPad
   (
      (int whatKey)                             ;** The number pressed
      (string whatKeyString)                    ;** The number inserted
      (get_parm 0 whatKey)                      ;** Get the parameter passed
      (sprintf whatKeyString "%d" whatKey)      ;** Turn whatKey into a string
      (= keyboardFlag (inq_kbd_flags))          ;** Check the status of the keyboard
      (if (> (& 0x20 keyboardFlag) 0)           ;** Is the Num Lock on
         (insert whatKeyString)                 ;** If so insert a number
      ;else
         (
            (if (|| (> (& 0x1 keyboardFlag) 0) (> (& 0x2 keyboardFlag) 0))  ;** Are one of the shift keys pressed
               (
                  (switch whatKey                  ;** act on what key was pressed
                     8
                        (change_window 0)          ;** up one window
                     4
                        (change_window 3)          ;** right one window
                     2
                        (change_window 2)          ;** down one window
                     6
                        (change_window 1)          ;** left one window
                     1
                        (insert whatKeyString)     ;** put in a one
                     7
                        (insert whatKeyString)     ;** put in a seven
                  )
               )
            )
         )

      )
   )
);** end of macro NewKeyPad



;**	Overwritable by Setup
(macro default
	(
		(tabs 4 6 8 10)
	)
)

;**	Overwritable by Setup
(macro .h
	(
		(tabs 4 7)
	)
)

;**	Overwritable by Setup
(macro .m
	(
		(tabs 4 7)
	)
)

;**	Overwritable by Setup
(macro .bas
	(
		(tabs 2 4 6 8 10 12)
	)
)

;**	Overwritable by Setup
(macro .bas_next_error
	(returns (search_fwd "^[ \\t\\n]+\\c[~ \\t\\n]" 1 1))
)

;**	Overwritable by Setup
(macro .bas_prev_error
	(returns (search_back "^[ \\t\\n]+\\c[~ \\t\\n]" 1 1))
)

;**	Overwritable by Setup
(macro .bas_error_info
	(
		(string	error_text)

		(int		error_buf
					source_buf
					line_found
		)
		(save_position)
		(search_back "< [0-9A-F][0-9A-F][0-9A-F][0-9A-F] [~^]@>" 1 1)
		(= error_text (substr (ltrim (substr (read) 17)) 1 80))

		(if (== error_text "")
			(= error_text "*")
		)
		(= error_buf (inq_buffer))
		(get_parm 4 source_buf)
		(set_buffer source_buf)

		(if (! (search_fwd error_text 0 1))
			(search_back error_text 0 1)
		)
		(inq_position line_found)
		(set_buffer error_buf)
		(restore_position)

		(put_parm 1 line_found)
		(put_parm 3 (trim (read)))
		(put_parm 2 0)
		(returns 2)
	)
)

;**	Overwritable by Setup
(macro .bat
	(
		(tabs 4 8 10 12)
	)
)

;**	Overwritable by Setup
(macro .c
	(
		(tabs 4 7)
	)
)

;**	Overwritable by Setup
(macro .txt
	(
		(tabs 2 4 6 8 10)
	)
)

;**	Overwritable by Setup
(macro .doc
	(
		(tabs 4 6 8 10)
	)
)

;**	Overwritable by Setup
(macro .asm
	(
		(tabs 9 17)
	)
)

;;* Include macros to provide support for Clarion Compiler and error detection

#include "clainitl.inc"
