From dc3b9b6c1c77f018717342221f0d377c40a31741 Mon Sep 17 00:00:00 2001 From: Talha Ahmed Date: Thu, 8 May 2014 17:00:23 +0500 Subject: [PATCH 1/3] Added splitbelow and refresh options --- plugin/vimya.vim | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/plugin/vimya.vim b/plugin/vimya.vim index 6928acd..4f1fcaf 100644 --- a/plugin/vimya.vim +++ b/plugin/vimya.vim @@ -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: """ @@ -86,6 +98,7 @@ import os import socket import tempfile import vim +import time logPath = '' setLog = 0 @@ -160,6 +173,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 @@ -211,7 +227,12 @@ def sendBufferToMaya (forceBuffer = False, userCmd = None): 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 connection.send ("commandEcho -state on -lineNumbers on;\n") @@ -228,6 +249,10 @@ def sendBufferToMaya (forceBuffer = False, userCmd = None): "sysFile -delete \"%s\";\n" % tmpPath.replace ('\\', '/') ) + if showLog and tail and refresh: + time.sleep(wait) + vim.command('call tail#Refresh()') + except: return __vimyaErrorMsg ('Could not send the commands to Maya.') From e84aae1b1dafa626b517dc51c2fdf106828aaf2a Mon Sep 17 00:00:00 2001 From: Talha Ahmed Date: Thu, 8 May 2014 19:48:25 +0500 Subject: [PATCH 2/3] Added Refresh and Reset functions with mappings --- plugin/vimya.vim | 72 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 70 insertions(+), 2 deletions(-) diff --git a/plugin/vimya.vim b/plugin/vimya.vim index 4f1fcaf..d68d391 100644 --- a/plugin/vimya.vim +++ b/plugin/vimya.vim @@ -81,6 +81,15 @@ if ! hasmapto ('sendBufferToMaya') vnoremap sb :py sendBufferToMaya (True) endif +if ! hasmapto ('vimyaPing') + nnoremap sr :py vimyaPing (0) + nnoremap st :py vimyaPing (1) + nnoremap sl :py vimyaPing (2) + vnoremap sr :py vimyaPing (0) + vnoremap st :py vimyaPing (1) + vnoremap sl :py vimyaPing (2) +endif + """ " Main stuff (most of it is Python): """ @@ -222,6 +231,7 @@ def sendBufferToMaya (forceBuffer = False, userCmd = None): return __vimyaErrorMsg ('Could not connect to the command port.') try: + goback = 0 if setLog == 1: connection.send ( @@ -234,6 +244,7 @@ def sendBufferToMaya (forceBuffer = False, userCmd = None): 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'): @@ -250,8 +261,10 @@ def sendBufferToMaya (forceBuffer = False, userCmd = None): ) if showLog and tail and refresh: + if goback: + vim.command("wincmd p") time.sleep(wait) - vim.command('call tail#Refresh()') + __refreshTail() except: return __vimyaErrorMsg ('Could not send the commands to Maya.') @@ -263,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 : From 1e413faf4fb5a79fb9a0d438ca3a347e9954615a Mon Sep 17 00:00:00 2001 From: Talha Ahmed Date: Thu, 8 May 2014 20:23:33 +0500 Subject: [PATCH 3/3] modified help file to reflect the changes made --- doc/vimya.txt | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/doc/vimya.txt b/doc/vimya.txt index d25d6c2..18e9e52 100644 --- a/doc/vimya.txt +++ b/doc/vimya.txt @@ -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 @@ -123,6 +136,13 @@ Contents *vimya* nnoremap sb :py sendBufferToMaya (True) vnoremap sb :py sendBufferToMaya (True) + nnoremap sr :py vimyaPing (0) + nnoremap st :py vimyaPing (1) + nnoremap sl :py vimyaPing (2) + vnoremap sr :py vimyaPing (0) + vnoremap st :py vimyaPing (1) + vnoremap sl :py vimyaPing (2) + See |vimya-usage| below for details on these function. ======================================================================= @@ -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 @@ -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