Skip to content

Splitsettings #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions doc/vimya.txt
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,19 @@ Contents *vimya*
the system's default temporary path will be used, as determined
by Python's 'tempfile' library. See there for details.

g:vimyaSplitBelow - number (default &splitbelow)
if 'STail' command is used in g:vimyaTailCommand. You can set
this value to always splitbelow. This will not affect the global
'splitbelow' settings.

g:vimyaForceRefresh - number (default 1)
Setting this value will cause vimya tail to refresh every time
the send buffer command is used with the tail option enabled.

g:vimyaRefreshWait - number (default 2.0)
The number of seconds vimya should wait before forcing a tail
refresh to allow maya time to write back to the log file

Example setting in your |.vimrc| file:
>
let vimyaPort=54321
Expand All @@ -123,6 +136,13 @@ Contents *vimya*
nnoremap <leader>sb :py sendBufferToMaya (True)<cr>
vnoremap <leader>sb :py sendBufferToMaya (True)<cr>

nnoremap <leader>sr :py vimyaPing (0)<cr>
nnoremap <leader>st :py vimyaPing (1)<cr>
nnoremap <leader>sl :py vimyaPing (2)<cr>
vnoremap <leader>sr :py vimyaPing (0)<cr>
vnoremap <leader>st :py vimyaPing (1)<cr>
vnoremap <leader>sl :py vimyaPing (2)<cr>

See |vimya-usage| below for details on these function.

=======================================================================
Expand Down Expand Up @@ -181,6 +201,20 @@ Contents *vimya*
Vim, unless this behaviour is disabled by setting the variable
'g:vimyaShowLog' to 0. See |:TabTail| or |:Tail| if installed.

The following function can be used to reset or refresh the tail

:py vimyaPing (opt = 0)

Pass opt value for different effect as described below:

-----------------------------------------------------------
Value | Function
-------+--------------------------------------------------
0 | Forced refreshes the tail window.
1 | Recreates the tail window if it had been closed
2 | Sets up a new log file
----------------------------------------------------------

All temporary files are deleted automatically. The files sourced by
Maya will be deleted by Maya itself: after the command to source the
file the
Expand Down Expand Up @@ -225,6 +259,8 @@ Contents *vimya*

7. Changelog *vimya-changelog*

2014/05/08 * added options to facilitate logging in split window
* added refresh and reset tail functions with mappings
2014/02/11 * added the vimyaTempDir and vimyaTailCommand options,
thanks to Claude Ronin
* minor updates to the documentation
Expand Down
97 changes: 95 additions & 2 deletions plugin/vimya.vim
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@ if ! exists ('g:vimyaTailCommand')
let g:vimyaTailCommand = 'TabTail'
endif

if ! exists('g:vimyaSplitBelow')
let g:vimyaSplitBelow = &splitbelow
endif

if ! exists('g:vimyaRefreshWait')
let g:vimyaRefreshWait = 2.0
endif

if ! exists('g:vimyaForceRefresh')
let g:vimyaForceRefresh = 1
endif

"""
" Mappings:
"""
Expand All @@ -69,6 +81,15 @@ if ! hasmapto ('sendBufferToMaya')
vnoremap <leader>sb :py sendBufferToMaya (True)<cr>
endif

if ! hasmapto ('vimyaPing')
nnoremap <leader>sr :py vimyaPing (0)<cr>
nnoremap <leader>st :py vimyaPing (1)<cr>
nnoremap <leader>sl :py vimyaPing (2)<cr>
vnoremap <leader>sr :py vimyaPing (0)<cr>
vnoremap <leader>st :py vimyaPing (1)<cr>
vnoremap <leader>sl :py vimyaPing (2)<cr>
endif

"""
" Main stuff (most of it is Python):
"""
Expand All @@ -86,6 +107,7 @@ import os
import socket
import tempfile
import vim
import time

logPath = ''
setLog = 0
Expand Down Expand Up @@ -160,6 +182,9 @@ def sendBufferToMaya (forceBuffer = False, userCmd = None):
port = int (vim.eval ('g:vimyaPort'))
tail = int (vim.eval ('g:vimyaUseTail'))
showLog = int (vim.eval ('g:vimyaShowLog'))
splitbelow = int (vim.eval ('g:vimyaSplitBelow'))
wait = float (vim.eval('g:vimyaRefreshWait'))
refresh = int (vim.eval('g:vimyaForceRefresh'))

if tempDir:
tempfile.tempdir = tempDir
Expand Down Expand Up @@ -206,13 +231,20 @@ def sendBufferToMaya (forceBuffer = False, userCmd = None):
return __vimyaErrorMsg ('Could not connect to the command port.')

try:
goback = 0

if setLog == 1:
connection.send (
"cmdFileOutput -o \"%s\";\n" % logPath.replace ('\\', '/')
)
vim.command ("%s %s" % (tailCommand, logPath))
sb = int(vim.eval('&splitbelow'))
vim.command ("set %ssplitbelow" % ("" if splitbelow else "no"))
try:
vim.command ("%s %s" % (tailCommand, logPath))
finally:
vim.command ("set %ssplitbelow" % ("" if sb else "no"))
setLog = 0
goback = 1

connection.send ("commandEcho -state on -lineNumbers on;\n")
if type == 'python' or (type == '' and defaultType == 'python'):
Expand All @@ -228,6 +260,12 @@ def sendBufferToMaya (forceBuffer = False, userCmd = None):
"sysFile -delete \"%s\";\n" % tmpPath.replace ('\\', '/')
)

if showLog and tail and refresh:
if goback:
vim.command("wincmd p")
time.sleep(wait)
__refreshTail()

except:
return __vimyaErrorMsg ('Could not send the commands to Maya.')

Expand All @@ -238,6 +276,61 @@ def sendBufferToMaya (forceBuffer = False, userCmd = None):

return True

EOP

def vimyaPing(opt=0):
''' wrapper for refresh and reset functions '''
if opt==1:
__resetVimyaTail()
elif opt==2:
__resetVimyaLog()
else:
__refreshTail()


def __refreshTail():
''' Refresh the contents of the vimya Tail '''
tail = int (vim.eval ('g:vimyaUseTail'))
try:
vim.command('call tail#Refresh()')
except:
if logPath and tail:
if not setLog:
__resetVimyaTail()
else:
__resetVimyaLog()
vim.command('call tail#Refresh()')

def __resetVimyaTail():
''' if the log file exists make another preview window '''
tail = int (vim.eval ('g:vimyaUseTail'))
splitbelow = int(vim.eval('g:vimyaSplitBelow'))
tailCommand = vim.eval('g:vimyaTailCommand')
global setLog
if tail:
vim.command('pclose')
sb = int(vim.eval('&splitbelow'))
vim.command ("set %ssplitbelow" % ("" if splitbelow else "no"))
try:
vim.command ("%s %s" % (tailCommand, logPath))
finally:
vim.command ("set %ssplitbelow" % ("" if sb else "no"))
setLog = 0
vim.command("wincmd p")
return True
return False

def __resetVimyaLog():
''' Generate new log file and make Maya write there '''
tail = int (vim.eval ('g:vimyaUseTail'))
if tail:
__vimyaRemoveLog()
vim.command('pclose')
global logPath, setLog
logPath=''
setLog=1
sendBufferToMaya(userCmd='print "Vimya log file was reset";')
return True
return False

EOP
" vim: set et si nofoldenable ft=python sts=4 sw=4 tw=79 ts=4 fenc=utf8 :