Giter Club home page Giter Club logo

wandbox-vim's Introduction

Wandbox for vimmers

This is a Vim plugin to use Wandbox in Vim. You can compile and execute the current buffer with one or more compilers and display the results in Vim without any registration. Now, Wandbox can execute C, C++, C#, D, Ruby, Python, Python3, PHP, Lua, Perl, Haskell, Erlang, Bash and SQL codes.

screenshot

What is Wandbox?

Wandbox is a new and cool social compilation service mainly for C++ers. You can use various versions of compilers and famous libraries. In addition, Wandbox provides some other languages like Ruby, Python, Haskell, D and so on. Wandbox has been created by @melpon and @kikairoya. Repository page is here.

Usage

:[range]Wandbox [--compiler={compiler}] [--options={options}] [--compiler-options={options}] [--file={file}] [--runtime-options] [--stdin] [--stdin-file={stdin-file}]

If [range] is omitted, whole buffer would be selected.

[--compiler={compiler}] specifies a compiler like gcc-head, clang-head, gcc-4.8.2, clang-3.3... Default value is gcc-head for C++. See autoload/wandbox.vim to know default values of each filetype. You can set multiple compilers with comma-separated string like 'gcc-head,clang-head'.

[--options={options}] specifies options for compilation like warning, c++1y, boost-1.55... This value must be comma-separated and no space is allowed like warning,c++1y,boost-1.55. Default value is warning,gnu++1y,boost-1.55 for C++, 'haskell-warning' for Haskell, '' for others. If multiple compilers are set, you can set each options for the compilers with colon-separated string like 'warning,c++11:warning,c++0x'. When you set single options like 'warning,c++11' even if multiple compilers are set, all compilers uses the same option you set.

[--compiler-options={options}] directly specifies compiler options like -Wall, -std=c++17, -O2... This value must be separated by backslash comma (',') and no space is allowed like -Wall\,-std=c++17\,-O2. If multiple compilers are set, you can set each options for the compilers with backslash-colon-separated string like -Wall\,-std=c++11\:-Wall\,-std=c++17. When you set single options even if multiple compilers are set, all compilers uses the same option you set.

[--file={file}] specifies the file to execute. If it is omitted, a current buffer will be executed.

[--runtime-options] specifies arguments for the program at runtime. You can input the arguments.

[--stdin] specifies stdin. You can input the arguments, or use global variable like --stdin=g:stdin.

[--stdin-file] specifies file which will be used as stdin.

Files included with relative paths in a source are expand automatically. To send requests asynchronously, curl or wget command and vimproc are required. Otherwise, requests are sent synchronously and they will block Vim.

The compile time messages (warnings, errors) are output to a quickfix window and the program output messages are output to a message window.

Example

Execute the buffer with default compiler and options.

:Wandbox

Execute the buffer with clang and gcc at the same time.

:Wandbox --compiler=clang-head,gcc-head

When you want to know about options,

:WandboxOptionList

If you want to search incrementally, unite.vim is a good choice.

:Unite output:WandboxOptionList

Below is an example for heavy use.

:Wandbox --compiler=clang-3.3 --options=boost-1.55,c++1y,warning,optimize,sprout

If you want to use wandbox with vim-quickrun, wandbox runner for quickrun is available.

:QuickRun -runner wandbox

Installation

Use modern plugin manager like neobundle.vim or vundle.

Though it is NOT recommended, you can install manually by copying the files in this repository into your Vim script directory which is usually ~/.vim/, or $HOME/vimfiles on Windows.

git clone https://github.com/rhysd/wandbox-vim.git
cd wandbox-vim
cp -R autoload/* ~/.vim/autoload/
cp -R plugin/* ~/.vim/plugin/

Customization

Variables

You can set the default compiler and default options for each filetype by g:wandbox#default_compiler and g:wandbox#default_options.

" Set default compilers for each filetype
if ! exists('g:wandbox#default_compiler')
    let g:wandbox#default_compiler = {}
endif
let g:wandbox#default_compiler = {
\   'cpp' : 'clang-head',
\   'ruby' : 'ruby-1.9.3-p0',
\ }

" Set default options for each filetype.  Type of value is string or list of string
if ! exists('g:wandbox#default_options')
    let g:wandbox#default_options = {}
endif
let g:wandbox#default_options = {
\   'cpp' : 'warning,optimize,boost-1.55',
\   'haskell' : [
\     'haskell-warning',
\     'haskell-optimize',
\   ],
\ }

" Set extra options for compilers if you need
let g:wandbox#default_extra_options = {
\   'clang-head' : '-O3 -Werror',
\ }

Mappings

If you want to execute :Wandbox quickly, you can add mappings to :Wandbox like below.

" For all filetypes, use default compiler and options
noremap <Leader>wb :Wandbox<CR>
" For specific filetypes, specify compilers to use
augroup wandbox-settings
    autocmd!
    autocmd FileType cpp noremap <buffer><Leader>ww :Wandbox --compiler=gcc-head,clang-head<CR>
    autocmd FileType cpp noremap <buffer><Leader>wg :Wandbox --compiler=gcc-head<CR>
    autocmd FileType cpp noremap <buffer><Leader>wc :Wandbox --compiler=clang-head<CR>
augroup END

(Maybe) To Do

  • Better command interface
  • Unite interface for compiler options
  • Unite interface for compilers
  • Persistent caching for options which would be used in quickrun type generation and unite interface
  • doc/wandbox.txt
  • Execute remote Gist code
  • No plugin is allowed to have no test
  • Make an option list prettier
  • Separate default setting and user setting
  • Output error and warning to location-list
  • Retry if request is timed out

Libraries wandbox-vim Using

wandbox-vim is standing on the shoulders of below libraries (you don't need to install below by your hand).

  • Vital.Web.HTTP
  • Vital.Web.JSON
  • Vital.OptionParser
  • Vital.Data.List
  • Vital.Prelude
  • vim-prettyprint

References

  • Wandbox

https://wandbox.org/

  • Wandbox API

https://github.com/melpon/wandbox/blob/master/kennel2/API.rst

License

Copyright (c) 2013 rhysd

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

wandbox-vim's People

Contributors

demotomohiro avatar rhysd avatar yuntan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wandbox-vim's Issues

出力結果の順番が正しくない時がある

次のコードで :Wandbox を行うと出力される順番が正しくない時がありました。

// http://melpon.org/wandbox/permlink/7EHCtHou4ZWMiyg2
#include <tuple>
#include <array>
#include <utility>
#include <iostream>


template<
    typename F,
    typename Seq,
    std::size_t ...Indexes
>
constexpr auto
invoke_impl(
    F func,
    Seq const& seq,
    std::index_sequence<Indexes...>
){
    return func(std::get<Indexes>(seq)...);
}


template<typename F, typename Seq>
constexpr auto
invoke(F func, Seq const& seq){
    return invoke_impl(func, seq, std::make_index_sequence<std::tuple_size<Seq>{}>{});
}


template<typename F>
auto
make_fused(F func){
    return [=](auto seq){
        return invoke(func, seq);
    };
}


struct disp{
    void
    operator()() const{}

    template<typename T, typename ...Args>
    void
    operator()(T t, Args... args) const{
        std::cout << t << std::endl;
        (*this)(args...);
    }
};


int
main(){
    invoke(disp{}, std::make_tuple(1, 2, 3));
    auto f = make_fused(disp{});
    f(std::make_tuple(1, 2, 3));
    f(std::make_tuple(1, "homu", 3.14));

    return 0;
}
出力結果
## clang-head
 * [output]

  homu
  3.14
  1
  2
  3
  1
  2
  3
  1

本来であれば

1
2
3
1
2
3
1
homu
3.14

と出力が行われるはずです。

" wandbox.vim の設定
let g:wandbox#default_compiler = {'cpp' : 'clang-head', '-' : 'clang-head' }
let g:wandbox#default_options = {'cpp' : 'warning,c++1y,boost-1.55', '-' : 'warning,c++1y,boost-1.55' }
  • 現状把握している範囲
    • 順番は不順
    • 正しく出力される場合もある
    • :WandboxAsync でも WandboxSync でも再現する
    • Web で何回か試してみたけど問題はなかった
    • API かクライアント側の問題の可能性が高い

実行時にエラーが起きる

以下のコードを表示して
:Wandbox
を行うと

function wandbox#run_sync_or_async..wandbox#run_async..<SNR>85_prepare_args の処理中にエラーが検出されました:
行    1:
E492: エディタのコマンドではありません:     PP! a:000

とエラーが起きます。

その後、結果が戻ってきますので、実行は成功している?と思われます。

# clang-head
  hello

Wandbox returned compilation error or warning.

環境はWindows GVim kaoriya 64bit の最新版です。
プラグインのインストールは
vimrcに
NeoBundle'rhysd/wandbox-vim'
を記述しています。

#include <iostream>

int main(int argc, char const* argv[])
{
    std::cout << "hello" << std::endl;
    return 0;
}

out of the box error for command :Wandbox

When running :Wandbox on the following code ( only open file in vim 8 ) right after I installed it with vundles PluginInstall, I get the error shown below.

Did I miss some installation instruction?

Arch Linux 4.16.5-1-ARCH
vim 8.1.22

#include <iostream>

int main () {
  std::cout << "hello world" << std::endl;
}
Error detected while processing function wandbox#run_sync_or_async[4]..wandbox#run[4]..wandbox#compile:
line   19:
E605: Exception not caught: Request has failed! Status 0: 
Error detected while processing function wandbox#run_sync_or_async:
line    4:
E171: Missing :endif

実行時にエラーが起きる

#include <stdio.h>

int main(void)
{ 

printf("%5-1の答えは%d¥n", 5-1);
printf("10÷2の答えは5d¥n", 10/2);
printf("2×5の答えは%d¥n", 2*5);

return 0,   

}

boost cannot be used even if it is specified in --options

The following code can never run successfully from vim

#include <boost/tuple/tuple.hpp>
#include <iostream>
int main()
{
    int x = 3;
    std::cout << x << std::endl;
}

I ran it using :Wandbox --options=boost-1.67. Changing the boost version in options or changing the compiler has no effect.

The error message is:

mprog.cc:1:10: fatal error: 'boost/tuple/tuple.hpp' file not found

Commenting out the first line (#include <boost/tuple/tuple.hpp>) can make it work

Could you please take a look? Thanks

\ (バックスラッシュ) が自動でエスケープされる (ご教授ください)

手側の環境の問題だと思うので大変恐縮なのですが、以下のように\が自動でエスケープされてしまいます。

input
result

また、帰ってくる結果も正常に表示できないケースがあるようです。

warning

環境

  • OS: Ubuntu 16.04 server
    • Note: gnome desktop をインストールして使用
  • Vim: VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Dec 12 2017 05:25:06) 適用済パッチ: 1-1385
  • Install method:

初歩的かつ、どちらかというとVimの問題で wandbox-vim の問題ではなさそうなのですが、
私が調べた限りでは解決方法がわからなかったため、ご教授いただけましたら幸いです。

Permlink API

  • https://github.com/melpon/wandbox/blob/master/kennel2/API.rst
  • Add an option to generate permlink. The permlink is output with echomsg in commandlline and copied to clipboard automatically.
  • The feature is not enabled by default because it generates many useless permlinks and data in DB on wandbox.
  • Considering that the prompt "Generate a permlink? (Y/n)" should be shown to prevent the option being set always.
  • Considering more useful way to output the permlinks. Any idea?

:WandboxOptionList 実行でエラー

WandboxOptionList 実行でエラーになります。

環境はWindows GVim kaoriya 64bit の最新版です。
プラグインのインストールは
vimrcに
NeoBundle'rhysd/wandbox-vim'
を記述しています。

行   31:
function wandbox#show_option_list..wandbox#list..<SNR>187_request..177 の処理中にエラーが検出されました:
E121: 未定義の変数です: s:Process
function wandbox#show_option_list..wandbox#list の処理中にエラーが検出されました:
行    6:
E605: 例外が捕捉されませんでした: Request has failed! Status 0: 
行    1:
E170: :endfor がありません
function wandbox#show_option_list の処理中にエラーが検出されました:

:QuickRun -runner wandbox が成功しない(Windows)

QuickRun側の問題かもしれないのですが、

:QuickRun -runner wandbox
を実行すると

quickrun: "command" option is empty.

と出力され実行されません。
:Wandbox
の実行は成功します。

環境はWindows GVim kaoriya 64bit の最新版です。
しかし、同じ設定のMacVim kaoriya では動作します。

vimrcで行っている設定のうち関係しそうな部分です

NeoBundleLazy 'rhysd/wandbox-vim', {'autoload': {'commands': [{'complete': 'customlist,wandbox#complete_command', 'name': 'WandboxAsync'}, {'complete': 'customlist,wandbox#complete_command', 'name': 'WandboxSync'}, {'complete': 'customlist,wandbox#complete_command', 'name': 'Wandbox'}, 'WandboxOptionList', 'WandboxOpenBrowser', 'WandboxOptionListAsync', 'WandboxAbortAsyncWorks']}}

NeoBundleLazy 'thinca/vim-quickrun', {
            \   'depends' : [
            \       'osyo-manga/shabadou.vim',
            \       'rhysd/wandbox-vim'
            \    ],
            \    'autoload': {
            \        'mappings': [['sxn', '<Plug>(quickrun']],
            \        'commands': [{'complete': 'customlist,quickrun#complete', 'name': 'QuickRun'}]
            \    }
            \ }
NeoBundleLazy 'osyo-manga/shabadou.vim', {}

" wandbox-vim {{{

let s:bundle = neobundle#get('wandbox-vim')
function! s:bundle.hooks.on_source(bundle)

    " wandbox.vim で quickfix を開かないようにする
    let g:wandbox#open_quickfix_window = 0

    let g:wandbox#default_compiler = {
                \   'cpp' : 'clang-head',
                \ }
endfunction
unlet s:bundle

" }}}
" vim-quickrun {{{

let s:bundle = neobundle#get('vim-quickrun')
function! s:bundle.hooks.on_source(bundle)

    " http://d.hatena.ne.jp/osyo-manga/20120919/1348054752
    let g:quickrun_config = {
                \   "_" : {
                \       "hook/close_unite_quickfix/enable_hook_loaded": 1,
                \       "hook/unite_quickfix/enable_failure":           1,
                \       "hook/close_quickfix/enable_exit":              1,
                \       "hook/close_buffer/enable_failure":             1,
                \       "hook/close_buffer/enable_empty_data":          1,
                \       "outputter":                                    "multi:buffer:quickfix",
                \       "outputter/buffer/split":                       ":botright 16sp",
                \       "runner":                                       "vimproc",
                \       "runner/vimproc/updatetime":                    40,
                \   },
                \   "cpp" : {
                \       "runner":                                       "wandbox",
                \    }
                \ }
endfunction
unlet s:bundle

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.