##############################################################################
# User plugin space.

import sys
from os.path import expanduser, join
sys.path.append(join(expanduser('~'), '.vy'))
##############################################################################
# Functions used to load the plugins.
from vyapp.plugins import autoload, autocall, mapset

##############################################################################
# Example remaping keys.

# Use the function mapset to remap your keys. 
# The 'line-index' stands for the plugin namespace.
# The code below permits the code binded to <Control-q> in NORMAL mode
# to work in NORMAL mode when <Key-g> event happens.
# It may be interesting to call mapset close to the plugin
# imports It is not necessary to be here but it has to be set
# before the plugin is installed with autoload.

# mapset('line-index', {
# ('NORMAL', '<Control-q>'): (('NORMAL', '<Control-q>'), 
# ('NORMAL', '<Key-g>'))})

# Note: Plugin namepaces should follow the pattern
# plugin-name it means any '_' is replaced for '-'.

##############################################################################
# Basic core modes.

import vyapp.plugins.delta_mode
autoload(vyapp.plugins.delta_mode)


import vyapp.plugins.gamma_mode
autoload(vyapp.plugins.gamma_mode)


import vyapp.plugins.beta_mode
autoload(vyapp.plugins.beta_mode)


import vyapp.plugins.alpha_mode
autoload(vyapp.plugins.alpha_mode)


import vyapp.plugins.insert_mode
autoload(vyapp.plugins.insert_mode)


import vyapp.plugins.normal_mode
autoload(vyapp.plugins.normal_mode)


import vyapp.plugins.cursor_status
autoload(vyapp.plugins.cursor_status)


import vyapp.plugins.mode_status
autoload(vyapp.plugins.mode_status)


import vyapp.plugins.io_status
autoload(vyapp.plugins.io_status)


# Start untwisted reactor.
import vyapp.plugins.startup
##############################################################################
# Core plugins.

# Pinned modes.
import vyapp.plugins.mode_shortcut
autoload(vyapp.plugins.mode_shortcut)


# Provide anchors for text.
import vyapp.plugins.anchors
autoload(vyapp.plugins.anchors)


# Implement keycommands to select special sequences of chars.
import vyapp.plugins.data_sel
autoload(vyapp.plugins.data_sel)


# Implement keycommand to remove selection from chars.
import vyapp.plugins.clear_sel
autoload(vyapp.plugins.clear_sel)


# Quickly switch focus between tabs by
# using lazy search pattern.
import vyapp.plugins.tab_search
autoload(vyapp.plugins.tab_search)


# The word_search plugin.
import vyapp.plugins.word_search
autoload(vyapp.plugins.word_search)


# Shifting blocks of code.
import vyapp.plugins.shift
autoload(vyapp.plugins.shift, width=4, char=' ')


# Used to quickly jump to the end/start of the cursor line.
import vyapp.plugins.line_jumps
autoload(vyapp.plugins.line_jumps)


# Used to quickly jump to the end/start of the file.
import vyapp.plugins.text_jumps
autoload(vyapp.plugins.text_jumps)


# Used to deal with panes.
import vyapp.plugins.splits
autoload(vyapp.plugins.splits)


# Used to deal with tabs.
import vyapp.plugins.tabs
autoload(vyapp.plugins.tabs)


# Implement keycommands to select text from the cursor position 
# to the start/end of the file.
import vyapp.plugins.text_sel
autoload(vyapp.plugins.text_sel)


# Default events for 'Text'.
import vyapp.plugins.default
autoload(vyapp.plugins.default)


# Implement keycommands to undo/redo operations.
import vyapp.plugins.undo
autoload(vyapp.plugins.undo)


# It implements keycomands to move the cursor up, down, left, right.
import vyapp.plugins.main_jumps
autoload(vyapp.plugins.main_jumps)


# The quick_search plugin implements incremental search.
import vyapp.plugins.quick_search
autoload(vyapp.plugins.quick_search)


# It implements keycommands to select/unselect a char on the cursor.
import vyapp.plugins.char_sel
autoload(vyapp.plugins.char_sel)


# Used to jump quickly to chars.
import vyapp.plugins.seek_symbol
autoload(vyapp.plugins.seek_symbol)


# This plugin implements keycommands to scroll lines.
import vyapp.plugins.line_scroll
autoload(vyapp.plugins.line_scroll)


# This plugin implements keycommands to scroll pages.
import vyapp.plugins.page_scroll
autoload(vyapp.plugins.page_scroll)


# This plugin implements keycommands to jump quickly
# to the next/previous word from the cursor position.
import vyapp.plugins.word_jumps
autoload(vyapp.plugins.word_jumps)


# Used to select the text between pairs of (), [], {} when 
# the cursor is placed over one of the (), {}, [].
import vyapp.plugins.sym_pair_sel
autoload(vyapp.plugins.sym_pair_sel)


# Implement a keycomand to select/unselect a line.
import vyapp.plugins.line_sel
autoload(vyapp.plugins.line_sel)


# Implement keycommands to insert a line up/down.
import vyapp.plugins.line_feed
autoload(vyapp.plugins.line_feed)


# Used to put the cursor on a given line.col.
import vyapp.plugins.line_index
autoload(vyapp.plugins.line_index)


# Implement keycommands to control where data written 
# to sys.stdout is going to be echoed.
import vyapp.plugins.outputs
autoload(vyapp.plugins.outputs)


# Used to execute python code on the fly, things like python functions
# to substitute text, format stuff etc, load plugins.
import vyapp.plugins.cmd
autoload(vyapp.plugins.cmd)


# Used to search for text/format text with regex.
import vyapp.plugins.find
autoload(vyapp.plugins.find)


# It implements ways of opening/saving files.
import vyapp.plugins.io
autoload(vyapp.plugins.io)


# Implement key-commands to delete selected text, lines, chars.
import vyapp.plugins.data_del
autoload(vyapp.plugins.data_del)


# Used to highlight pairs of character like () {} [].
# It is useful when playing with lisp things.
import vyapp.plugins.match_sym_pair
autoload(vyapp.plugins.match_sym_pair)


# Used to complete words when Control-q is issued on insert mode.
import vyapp.plugins.word_completion
autoload(vyapp.plugins.word_completion)


# Implements key-commands to copy/cut/paste text.
import vyapp.plugins.clipboard
autoload(vyapp.plugins.clipboard)


# Used to remember an important position of the 
# text and quickly switch back to it.
import vyapp.plugins.quick_jumps
autoload(vyapp.plugins.quick_jumps)


# This plugin is used to place the cursor over 
# the next occurrence of the symbols passed to 
# symbol_jumps install function.
import vyapp.plugins.symbol_jumps
autoload(vyapp.plugins.symbol_jumps, 
('(', ')', '.', '[', ']', '{', '}', ',', ':', ';', "'", '"'))


# text_spots plugin is used to mark lines then quickly
# go to the previous or next mark.
import vyapp.plugins.text_spots
autoload(vyapp.plugins.text_spots)


# range_sel plugin implemets selection commannds.
import vyapp.plugins.range_sel
autoload(vyapp.plugins.range_sel)


# block_selection plugin implemets selection commannds.
import vyapp.plugins.block_sel
autoload(vyapp.plugins.block_sel)

##############################################################################
# Extra plugins.

# The mc filenamanager.
# import vyapp.plugins.mc
# Configure your color scheme here.
# vyapp.plugins.mc.COLOR_SCHEME = {'(MC-DIRECTORY)': {'foreground': 'red'},
# '(MC-FILE)': {'foreground': 'blue'}}
# autoload(vyapp.plugins.mc)


# A wrap around unix locate command.
# import vyapp.plugins.fsniff
# autoload(vyapp.plugins.fsniff)


# The html checker plugin that uses
# Html tidy. It is necessary to have that
# package installed.
# The path argument corresponds to where your tidy
# executable stays.
# import vyapp.plugins.html_checker
# autoload(vyapp.plugins.html_checker, path='tidy')


# Download html from the clipboard url in the active AreaVi
# instance.
import vyapp.plugins.urls
autoload(vyapp.plugins.urls)


# This plugin implements a keycommand to quickly load the user vyrc file
# into the current AreaVi instance.
import vyapp.plugins.editrc
autoload(vyapp.plugins.editrc)


# Python auto completion plugin using jedi.
import vyapp.plugins.python_completion
autoload(vyapp.plugins.python_completion)


# Ruby auto completion using rsense.
# It is needed to start rsense daemon first. 
# Note: When first starting the daemon, it may take
# some time for rsense to set up working.
# import vyapp.plugins.ruby_completion
# autoload(vyapp.plugins.ruby_completion, path='rsense', port=47367)


# Javascript completion using tern.
# Initializes the tern daemon and installs javascript 
# autocomplete plugin. Notice 'tern' should stand for your tern plugin path.
# It means where your tern script is in.


# from vyapp.plugins.javascript_completion import javascript_tools
# javascript_tools('tern', port=1234)
# import vyapp.plugins.javascript_completion
# autoload(vyapp.plugins.javascript_completion, 'tern', port=1234)


# Used to insert tab, spaces.
import vyapp.plugins.spacing
autoload(vyapp.plugins.spacing, 
tab_scheme = {
'.rb': (2, ' '),
'.c' : (4, ' '),
'.cpp' : (4, ' '),
'.java' : (4, ' '),
'.py': (4, ' ')},
default_tab_size=4)


# This plugin implements keys to comment pieces of text inside 
# programming language files.
import vyapp.plugins.inline_comment
autoload(vyapp.plugins.inline_comment)


# Used to debug python applications. The python argument 
# specifies the interpreter path.
# import vyapp.plugins.pdb.unix_platform
# autoload(vyapp.plugins.pdb.unix_platform, python='python2')
import vyapp.plugins.pdb.cross_platform
autoload(vyapp.plugins.pdb.cross_platform, python='python2')


# Used to talk to extern processes, playing with interpreters etc.
# Available: Unix/Linux
# import vyapp.plugins.ibash
# autoload(vyapp.plugins.ibash)


# This plugin highlights links when files are opened.
import vyapp.plugins.hlink
autoload(vyapp.plugins.hlink)


# It implementes some features like a key command
# to copy to the clipboard the name of the actual opened file.
import vyapp.plugins.clip_path
autoload(vyapp.plugins.clip_path)


##############################################################################
# syntax plugin is used to highlight code.
# It uses python pygments styles to highlight code :)
# Check out more pygments styles.
# Note: When uncommenting a theme dont forget to comment the previously used one.
import vyapp.plugins.syntax.spider

# from pygments.styles.emacs import EmacsStyle
# autoload(vyapp.plugins.syntax.spider, EmacsStyle())

# from pygments.styles.murphy import MurphyStyle
# autoload(vyapp.plugins.syntax.spider, MurphyStyle())

# from pygments.styles.colorful import ColorfulStyle
# autoload(vyapp.plugins.syntax.spider, ColorfulStyle())

# from pygments.styles.tango import TangoStyle
# autoload(vyapp.plugins.syntax.spider, TangoStyle())

# from pygments.styles.trac import TracStyle
# autoload(vyapp.plugins.syntax.spider, TracStyle())

# from pygments.styles.igor import IgorStyle
# autoload(vyapp.plugins.syntax.spider, IgorStyle())

# from pygments.styles.paraiso_dark import ParaisoDarkStyle
# autoload(vyapp.plugins.syntax.spider, ParaisoDarkStyle())

# from pygments.styles.vim import VimStyle
# autoload(vyapp.plugins.syntax.spider, VimStyle())

from vyapp.plugins.syntax.styles.vy import VyStyle
autoload(vyapp.plugins.syntax.spider, VyStyle())

##############################################################################

# Used to log the files that you opened/saved.
# You must change the '.vy_history' to something like.
# '/home/your_home/.vy_history'
# import vyapp.plugins.log_opened_file
# autoload(vyapp.plugins.log_opened_file, '.vy_history')

##############################################################################
# Core command plugins.

# Implement commands for common key-commands.
import vyapp.plugins.cmd_utils


# Plugin tools.
import vyapp.plugins.plugin_tools


# Saving, opening files from vy python command line.
import vyapp.plugins.iocmd


# Find, replace, highlight patterns from vy python command line.
import vyapp.plugins.cmd_search


# Strip spaces from the beginning of lines.
import vyapp.plugins.line_strips

##############################################################################
# Extra command plugins.

# Implement lower and upper functions.
from vyapp.plugins import caps


# Count words.
import vyapp.plugins.count_words


# Managing file encodings.
import vyapp.plugins.codec


# Spawning processes.
import vyapp.plugins.shell

##############################################################################
# The vy irc mode.
from vyapp.plugins.vyirc import IrcMode

# Uncomment these lines to set up your custom color scheme.
# It accepts all available config options for Tkinter Text widget.
# IrcMode.COLOR_SCHEME = {'(VYIRC-PRIVMSG)': {'foreground': '#688B96'},
# '(VYIRC-JOIN)': {'foreground': '#F06EF0'},
# '(VYIRC-PART)': {'foreground': '#F0BDAD'},
# '(VYIRC-QUIT)': {'foreground': '#4EDB1F'},
# '(VYIRC-NICK)': {'foreground': '#E9F0AD'},
# '(VYIRC-KICK)': {'foreground': '#FC8D9A'},
# '(VYIRC-353)': {'foreground': '#BF9163'},
# '(VYIRC-332)': {'foreground': '#81BFFC'},
# '(VYIRC-CLOSE)': {'foreground': '#A7F2E9'}}

# Here, the network connections can be defined. 
def irc_freenode(addr='irc.freenode.org', port=6667, user='vy vy vy :vyirc', nick='vyirc', 
             irccmd='PRIVMSG nickserv :identify nick_password', channels=['#vy']):
    IrcMode(addr, port, user, nick, irccmd, channels)

def irc_arcamens(addr='irc.arcamens.com', port=6667, user='vy vy vy :vyirc', nick='vyirc', 
             irccmd='PRIVMSG nickserv :identify nick_password', channels=['#arcamens']):
    IrcMode(addr, port, user, nick, irccmd, channels)


##############################################################################
# Setup area settings, like default background, foreground, font style etc.

# Note: Plugins like syntax highlighting will define AreaVi instance settings 
# like background and foreground. # It is possible to override these settings 
# by uncommenting foreground and background arguments below. 

# Handles like setup are the last ones.

def setup(area):
    area.config(blockcursor=True, insertbackground='red', 
                # background='black', foreground='yellow', 
                font=('Monospace', 8, 'bold'), undo=True)

autocall(setup) 









