From b22f20cbb3bf38a8cdaeb6685013764365f08c56 Mon Sep 17 00:00:00 2001 From: grirgz Date: Tue, 7 Aug 2018 22:43:46 +0200 Subject: [PATCH 1/3] add .loadRelative support --- sc/SCVim.sc | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/sc/SCVim.sc b/sc/SCVim.sc index 29f9ac5..da9dbe7 100644 --- a/sc/SCVim.sc +++ b/sc/SCVim.sc @@ -23,8 +23,24 @@ SCVim.generateTagsFile(); */ +Document { + // needed for thisProcess.nowExecutingPath to work.. see Kernel::interpretCmdLine + var vimPath; + classvar nodes, <>vimPath, <>vimServerName="scvim"; *initClass { nodes = List[]; @@ -221,4 +237,17 @@ SCVim { tagfile.close(); "finished generating tagsfile".postln; } + + *currentPath { + var cmd = "expand(\"%:p\")"; + var path = "vim --servername % --remote-expr '%'".format(vimServerName, cmd).unixCmdGetStdOut; + if( path == "" ) { + //"can't get Vim current path".error; // also happen on unsaved files, but there is already an error message with .loadRelative + ^nil + }; + if (PathName(path).isAbsolutePath) { + ^path; + }; + ^nil; + } } // end class From c43bd7d328d034a868f0d8e5e811764f8588ed69 Mon Sep 17 00:00:00 2001 From: grirgz Date: Wed, 16 Jan 2019 19:02:05 +0100 Subject: [PATCH 2/3] add check for vim executable, clientserver feature and available servers --- sc/SCVim.sc | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/sc/SCVim.sc b/sc/SCVim.sc index da9dbe7..65837e4 100644 --- a/sc/SCVim.sc +++ b/sc/SCVim.sc @@ -40,12 +40,13 @@ Document { SCVim { - classvar nodes, <>vimPath, <>vimServerName="scvim"; + classvar nodes, <>vimPath, <>vimServerEnabled=false, <>vimServerName="SCVIM"; *initClass { nodes = List[]; // TODO this has to be not so mac-centric + vimPath = "vim"; Platform.case(\osx) { var whichVim = "which mvim".unixCmdGetStdOut; @@ -57,6 +58,10 @@ SCVim { vimPath = vimPath.replace("\n", ""); }; + vimServerEnabled = "% --version".format(vimPath).unixCmdGetStdOut.contains("+clientserver") and: { + "% --serverlist".format(vimPath).unixCmdGetStdOut.contains(vimServerName.toUpper) + }; + StartUp.add { var classList, file, hugeString = "syn keyword scObject", basePath; // search two folders deep below ~/.vim for a folder named "*scvim*" @@ -240,14 +245,17 @@ SCVim { *currentPath { var cmd = "expand(\"%:p\")"; - var path = "vim --servername % --remote-expr '%'".format(vimServerName, cmd).unixCmdGetStdOut; - if( path == "" ) { - //"can't get Vim current path".error; // also happen on unsaved files, but there is already an error message with .loadRelative - ^nil - }; - if (PathName(path).isAbsolutePath) { - ^path; - }; + var path; + if(vimServerEnabled) { + path = "% --servername % --remote-expr '%'".format(vimPath, vimServerName, cmd).unixCmdGetStdOut; + if( path == "" ) { + //"can't get Vim current path".error; // also happen on unsaved files, but there is already an error message with .loadRelative + ^nil + }; + if (PathName(path).isAbsolutePath) { + ^path; + }; + } ^nil; } } // end class From bd4f41308885e3c4f2a912cf878bc942cc60c26d Mon Sep 17 00:00:00 2001 From: grirgz Date: Wed, 5 Jun 2019 17:21:48 +0200 Subject: [PATCH 3/3] server name can be changed, now warn if not found, add doc --- README.md | 17 +++++++++++++++ sc/SCVim.sc | 62 +++++++++++++++++++++++++++++++++-------------------- 2 files changed, 56 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 84de8ba..57d2ef1 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,22 @@ If for some reason vim can't find the path to the two launch scripts let g:sclangPipeApp = "~/.vim/bundle/scvim/bin/start_pipe" let g:sclangDispatcher = "~/.vim/bundle/scvim/bin/sc_dispatcher" +### Document support + +If vim is compiled with +clientserver option, SuperCollider can retrieve the path of the current vim buffer and enable String:loadRelative. +In debian based distributions, this option often comes with gui-enabled vim packages (vim-gtk for example). + + "fileInSameFolder.scd".loadRelative; + +To use this feature, you also need to start vim in server mode: + + vim --servername SCVIM + +You can change the default server name used by SuperCollider to contact vim: + + SCVim.vimServerName = "MYNAME"; + + Usage ----- To start open a file with the right extension :e foo.sc(d) @@ -119,3 +135,4 @@ in normal/insert mode: * `F5` to execute a block of code scvim will attempt to find the outermost bracket * `F6` to execute the current line of code * `F12` is a hard stop + diff --git a/sc/SCVim.sc b/sc/SCVim.sc index 65837e4..cc39121 100644 --- a/sc/SCVim.sc +++ b/sc/SCVim.sc @@ -24,15 +24,15 @@ SCVim.generateTagsFile(); */ Document { - // needed for thisProcess.nowExecutingPath to work.. see Kernel::interpretCmdLine - var vimPath, <>vimServerEnabled=false, <>vimServerName="SCVIM"; + classvar nodes, <>vimPath, <>vimServerEnabled=false,