; $Header: /usr/build/vile/vile/macros/RCS/vileinit.rc,v 1.11 1999/12/16 23:46:57 kev Exp $
; This is a sample which may be installed as .vilerc (or vile.rc for non-Unix
; systems), or source'd as-is to provide quick initialization of some useful
; macros and settings.

; General preferences:
set autoindent
set check-modtime
set cmode
set flash
set implybuffer
set nomultibeep
set nowarn-reread
set ruler
set showmatch
set smooth
set undolimit=100

; Since 'map' overrides 'bind-key', ensure that we don't have a mapping for
; function-key 1, since it is useful for HELP.
map #1 xx
unmap #1
bind-key help #1

; A tab is useful for stepping through the windows:
bind-key next-window ^I

; Special settings that depend on the platform/configuration.  Note
; that there is no special symbol denoting "UNIX", so we infer it from
; the $pathlist-separator variable.

~if &seq $pathlist-separator ":"
	; Though you probably prefer an interactive shell that
	; supports history, command-line editing, etc., there are good
	; reasons for using Bourne shell to run subprocesses from vile
	; (speed, and usually lack of interference from stty commands
	; with the syntax filters).
	setv $shell=/bin/sh

	set resolve-links
	set glob=on
~endif

~if &seq $progname xvile
	setv $xshell="xterm -e xshell.sh"
~elseif &seq $progname winvile
~elseif &or &sin $cfgopts "terminfo" \
	    &sin $cfgopts "termcap"

	set xterm-mouse

	; If your keyboard is setup to transmit META as an escape character,
	; these mappings are useful for undo/redo/kill
	map u u
	map r r
	map k k
	; Shifted arrow-keys from XFree86 xterm, mapped to next-row and
	; previous-row
	map [2A 
	map O2A 
	map [2B 
	map O2B 
	map [2C #C
	map O2C #C
	map [2D #D
	map O2D #D
	; You may have a back-tab (map it to previous-window)
	map [Z O
~endif

; Useful macros for function keys:

store-procedure ToggleTabs "Toggle tabs 4/8"
~if &sin $bflags s
	write-message "Cannot set tabs"
~else
	~if &equ $ts 4
		setl ts=8
		setl sw=8
	~else
		setl ts=4
		setl sw=4
	~endif
	write-message &cat "Set tabs to " $ts
	~endif
~endm
map #3 :execute-procedure ToggleTabs

store-procedure ToggleList "Toggle list/nolist mode"
~if $list
	setl nolist
~else
	setl list
~endif
write-message &cat "Set list to " $list
~endm
map #4 :execute-procedure ToggleList

map #5 :entab-lines-til
map #6 :detab-lines-til
map #7 :format-til

; take the identifier under the cursor, wrap it in '<', '>' and search for it.
store-procedure next-cur-identifier "Find next occurrence of current token"
	~force search-forward &cat '\<' &cat $identifier '\>'
~endm
bind-key next-cur-identifier ^X-,

; Take the identifier under the cursor, wrap it in '<', '>' and search for it.
; in the alternate buffer.
store-procedure next-alt-identifier "Find current token in alternate buffer"
	~local %osearch $identifier
	set-variable %osearch $identifier
	alternate-buffer
	~force search-forward &cat '\<' &cat %osearch '\>'
	position-window "+"
	alternate-buffer
~endm
bind-key next-alt-identifier ^A-,

;; Macro to center a line.
store-procedure center "Center the current line"
	first-nonwhite
	delete-til beginning-of-line
	trim-lines-til end-of-line
	set-variable %insert &DIV &SUB 80 $llength 2
	~if &GRE %insert 0
		%insert insert-string " "
	~endif
~endm
bind-key center ^X-C

~if &sin $cfgopts "perl"
store-procedure hyper-next "Execute embedded hypertext command and move cursor past it"
    ~force execute-hypertext-command
    ~if &not $status
	~force forward-character-to-eol
    ~endif
~endm
bind-key hyper-next ^X-^M
~endif

; Make the current buffer writable and then write it out.
~if &or &seq $os "dos" &seq $os "win32"
	use-register w load-register ":!attrib -r %
:w
"
~elseif &seq $os "vms"
	use-register w load-register ":!set protection=(o:rwed) %
:w
"
~else
	use-register w load-register ":!chmod +w %
:w
"
~endif

; Variants on grep of the current token.  You need GNU grep for the -w (word)
; option.
~if &seq $pathlist-separator ":"
	use-register f load-register "!grep -n -w : *.in *.m4 *.[chly] *.def *.cc *.cpp *.xs
"
	use-register g load-register "!egrep -n : *.[chly] *.def *.cc *.cpp *.xs
"
	use-register h load-register "!egrep -n : *.* */*
"
	use-register i load-register "!egrep -n : /usr/include/*.h /usr/include/*/*.h /usr/local/include/*.h
"
	use-register j load-register "!egrep -n : *.[ch] */*.[ch]
"
~elseif &or &seq $os "dos" &seq $os "win32"
	use-register f load-register "!grep -n -w & *.in *.m4 *.[chly] *.def *.cc *.cpp *.xs
"
	use-register g load-register "!egrep -n & *.[chly] *.def *.cc *.cpp *.xs
"
~endif

source vileperl.rc
source palettes.rc
source filters.rc
setv $read-hook HighlightFilter
set autocolor=5000
setv $autocolor-hook HighlightFilter

~if &seq $pathlist-separator ":"
	source manpage.rc
	source spell.rc
~endif
