; $Header: /usr/build/vile/vile/macros/RCS/vileinit.rc,v 1.21 2002/09/02 16:43:46 tom 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

; In command-mode, we can use home/end keys most effectively by going to either
; end of the line:
bind-cmdmode-key goto-bol FN-H
bind-cmdmode-key goto-eol FN-E

; 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

	~if &seq $os "cygwin"
		set noresolve-links
	~else
		set resolve-links
	~endif
	set glob=on
~endif

~if &seq $progname xvile
	setv $xshell="xterm -e xshell.sh"
	setv $xshell-flags=""
~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 :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 :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
	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.  VMS has a native search utility.
~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 *.c *.h *.def *.cc *.cpp *.xs
"
	use-register g load-register "!egrep -n & *.c *.h *.def *.cc *.cpp *.xs
"
~elseif &seq $os "vms"
	use-register f load-register "!search/exact *.c,*.h,*.com,*.mms &
"
	use-register g load-register "!search *.c,*.h,*.com,*.mms &
"
	use-register j load-register "!search [...]*.c,*.h,*.com,*.mms &
"
~endif

source vileperl.rc
source palettes.rc
source filters.rc
source which.rc
~if &not &error $ncolors
setv $read-hook HighlightFilter
set autocolor=5000
setv $autocolor-hook HighlightFilter
~endif

~if &not &seq $os "vms"
	source manpage.rc
~endif

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