Giter VIP home page Giter VIP logo

asynccommand's Introduction

AsyncCommand

AsyncCommand allows you to execute shell commands without waiting for them to complete. When the application terminates, its output can be loaded into a vim buffer. AsyncCommand is written to be compatible with Windows and Linux (tested on Win7 and Ubuntu 11.10).

Currently three types of commands are supported:

AsyncGrep
grep for files and load results in quickfix
AsyncShell
run any program and load results in a split
AsyncCscopeFindSymbol, AsyncCscopeFindCalls, AsyncCscopeFindX
cscope commands
AsyncMake
run your makeprg with input arguments and load the results in quickfix

For more information, see :help asynccommand

asynccommand's People

Contributors

idbrii avatar mah avatar zenchild avatar zhangjunbo1993 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

asynccommand's Issues

asynchandler# functions aren't being found

I just cloned this repository into my bundle dir and tried to run AsyncMake in one of my c projects:

Error detected while processing function 13_AsyncMake:
line 8:
E117: Unknown function: asynchandler#quickfix
E116: Invalid arguments for function asynccommand#run

AsyncCommand with macvim

Hi,

I am trying to use AsyncCommand with macvim, but nothing happens upon using the AsyncCommand commands. The doc file seemed to suggest there are some extra steps to get AsyncCommand working with macvim, are there more details on this somewhere?

All the best
Colin

Get AsyncCommand work with errormarker?

Hi all,

I found AsyncCommand on StackOverflow, and found it is a terrific tool! I am trying to get it work with errormarker plugin, but encountered some problem.

i don't know exactly what the problem is. I traced errormarker's script, and found error use following script to hook QuickFixCmdPost to event, and set markers to lines of source files.

augroup errormarker
    autocmd QuickFixCmdPost make call <SID>SetErrorMarkers()
augroup END

According to the :help, the second argument(make) is the pattern of the file(for example: *.html). I don't what is a make file pattern, I tried

autocmd QuickFixCmdPost AsyncMake call <SID>SetErrorMarkers()

It does not work(sure). But I don't know what else I can do. I do googled "AsyncCommand errormarker" but get nothing.

Is there are any comment? Any suggestion is appreciated. Thanks in advance.

redraw!

I have autoread set and use some autocmd's triggered by BufEnter,BufNew,BufRead,WinEnter,FileChangedShell,ShellCmdPost,FocusGained events to handle some menu sensitivity for a plugin that I'm working on. After executing a version control command using asynccommand#run, a file may autoread from the permissions change, and the idea is to trigger a function. I generally use the quickfix handler to display the results of such commands (something like file is now open for edit). However, the menu is not redrawn after the command (not exactly sure if the event isn't firing or it fires and the menu needs an explicit redraw). It does work if In asynccommand#tab_restore(env), I change "redraw" to "redraw!".

I'm not sure if this is something that you would want to include in the plugin or if it is only due to my own very specific usage.

Thanks,
Chad Moore

EDIT 12/15/2011: BTW, I saw a TODO comment about notification of a completed command (when there's no output returned). This is a highly anticipated feature in my book. Thanks!

Pipe result through sed?

Because my builds happen in a different directory than where I edit my source, I need to substitute the name of the source directory for the build directory in my build output. To this end, I've got a shellpipe set for normal :make like this:

set shellpipe=|2>&1|sed\ 's/^.*build///g'|tee

There is no good way to do this that I can see with AsyncMake. Right now I've just made this hardcoded change, but it would be good if AsyncMake had something like shellpipe that can be configured via an option.

function! s:AsyncMake(target)

  • let make_cmd = &makeprg ." ". a:target
  • let make_cmd = &makeprg ." ". a:target . "|sed 's/^.*build///'"

Better error message when no X server is available?

I've been getting a few complaints about console vim (using AsyncCommand 3.1) giving the following error, even when started via "vim --servername asdf":

Error: AsyncCommand requires vim to be started with a servername.
       See :help --servername

Is there a way to make it more obvious that users should have X available (ie something in :echo serverlist())?

I don't know if this situation could be detected or not but even the refercenced documentation via :help --servername don't make this point clear.

It's usually a case of not RTFM (my docs explain this) but the same question seems to crop up often.

quick fix not updating

Hi,

I have a problem that async command does not update the quick fix window after completing commands. Not sure how to go forward with a repro case but I can run a modified version or help with debugging if I can get some hints on where to start.

System:
Windows7
gVim 7.3
AsyncCommand 3.1

/joel de vahl

quickfix list not updated when gvim and vim are different

On Fedora, gvim is provided by vim-X11 and vim by vim-enhanced. vim-enhanced does not recognize the --remote-expr option.

There are two workarounds:

  1. set g:asynccommand_prg to 'gvim'
  2. uninstall vim-enhanced and symlink /usr/bin/gvim to /usr/bin/vim (or use update-alternatives --install)

Vim crashes on AsyncGrep with eclim installed

Versions

Ubuntu 11.04 using Unity
VIM - Vi IMproved 7.3 (2010 Aug 15, compiled Mar 24 2011 07:07:34)
I have eclim 1.6.3 installed.
I've tried several versions of AsyncCommand. I've included a stripped down version that exhibits the same problem.

Problem

Sometimes AsyncGrep causes vim to crash with "Vim: Caught deadly signal SEGV"

  1. Open Gvim (most reliable with the Unity Launcher, might be because of -f flag)
  2. :AsyncGrep Free -R ~/.vim/eclim/compiler/

The quickfix window opens, but then vim quickly crashes.

Removing eclim prevents the error.

Stripped down AsyncCommand

Put in ~/.vim/plugin

command! -nargs=+ -complete=file AsyncGrep call AsyncGrep(<q-args>)

function! AsyncGrep(query)
    let grep_cmd = "grep --line-number --with-filename ".a:query
    "let grep_cmd = "date"
    let vim_func = "OnCompleteGetAsyncGrepResults"

    let temp_file = tempname()
    let tool_cmd = grep_cmd . printf(&shellredir, temp_file)
    let vim_cmd = "vim --servername ".v:servername." --remote-expr \"" . vim_func . "('" . temp_file . "')\" "
    silent exec "! (".tool_cmd." ; ".vim_cmd.") &"
endfunction
function! OnCompleteGetAsyncGrepResults(temp_file_name)
    let &errorformat = &grepformat
    exec "cgetfile " . a:temp_file_name
    cwindow
    "redraw
endfunction

Can this plugin be made easier to extend?

I've been working on a flymake-like plugin that uses AsyncCommand to compile asynchronously. Here it is:
http://www.vim.org/scripts/script.php?script_id=3924

Unfortunately, the plugin required making a few unconfigurable changes to AsyncCommand. The end results is that I ended up copying some of the implementation and modifying it slightly. This is a very poor solution.

I would not expect you to add user-definable functions all over the place in AsyncCommand because you could never really predict how users will want to customize it. I do have a suggestion, though. If the script's methods were not script-scope (s:something), the plugin would be easy to extend. In my case, I could then use the after directory and function! to redefine the functions that needed changed.

I'm also open to other suggestions.

Thanks,
Chad

Issues with using ctrl-c in shell commands

Hi,
I've experienced the following:
When I use asynccommand#run("example") and then, in addition, cancel a shell command with ctrl-c (say, :!python), ctrl-c will also cancel example.
Is there any way to circumvent this behaviour so that example will keep running?

SIdenote: This only happens when I use the console-version of vim, not Gvim

AsyncMake generates colors, not displayed

My Makefile generates some colored output. I would like the colors to either be displayed correctly in the quicklist, or to be able to somehow detect from within the Makefile that the "shell" doesn't support colors, and not generate them at all.

Currently, $TERM is the same as my regular terminal, making it difficult to distinguish the two cases.

No warning if vim doesn't exist

If you use gvim but don't have vim installed, then AsyncCommand will silently fail.

Workaround: use let g:asynccommand_prg = 'gvim'

Should fallback to gvim and then fallback to error.

asynchandler#rename not working?

Thank you so much for this incredible project

I'm having some trouble with asynchandler#rename, but it may be user error

For example, the command I'm trying to run is just RSpec on the directory of the file the cursor is currently in. I get that directory with %:h (which I found using :help filename-modifiers)

I want RSpec to save an html file, and if there are any errors RSpec spits back to the console, I want AsyncCommand to save those in a 2nd file for me

Here's what I tried:

command! MyRspecFunction call MyRspecFunction()
function! MyRspecFunction()
    let cmd = 'rspec %:h\*_spec.rb --format html --out %:h\most_recent_rspec.html'
    let env = asynchandler#rename('%:h\ErrorMessage.txt')

    call asynccommand#run(cmd, env)
endfunction

What works:
The file "most_recent_rspec.html" does get saved in the expected directory, right alongside the specs! Very cool. So the cmd part is working

What doesn't seem to work:
The file "ErrorMessage.txt" is never created, no matter what

I can, of course, manually see what RSpec would have spit back to the console by typing this into vim:

:AsyncShell 'rspec %:h\*_spec.rb --format html --out %:h\most_recent_rspec.html'

but, I do need that ErrorMessage.txt file and unless I misunderstood, I thought that's what #rename was for. Sorry if I'm misusing it somehow! :|

AsyncGrep runs for ever on invalid input

On the latest (96d832a), AsyncGrep doesn't end when run on some invalid input.

For example, when not terminating your strings:

grep \\" %

Fails with an error like unexpected EOF while looking for matching '"'. The same search in AsyncGrep:

AsyncGrep \\" %

And you get no output, no quickfix opens, and grep is not running in the background. So grep terminated, but the vim_cmd to tell vim was never executed. It's probably because the quoting includes vim_cmd as part of the invalid grep command.

Suggestion: Don't clobber a quickfix when :colder was used

:help quickfix-error-lists describes how you can navigate between recent quickfix lists with :colder and :newer. It adds this note:

When adding a new error list, it becomes the current list.

When ":colder" has been used and ":make" or ":grep" is used to add a new error list, one newer list is overwritten. This is especially useful if you are browsing with ":grep" |grep|. If you want to keep the more recent error lists, use ":cnewer 99" first.

Consider always running :cnewer 99 before loading something in the quickfix since when AsyncCommand populates the quickfix is unpredictable by the user.

Note: I haven't actually encountered this problem.

`printf` in `asynchandler#qf()` fails

printf in asynchandler#qf() fails from s:AsyncMake because title does not contain any format string '%d'

asynchandler#qf()
...
               let w:quickfix_title = printf(self.title, len(self.mode == 'c' ? getqflist() : getloclist()))
...

AsyncMake fails with filter

Hi!

The :AsyncMake command fails with my makeprg configuration:

setlocal makeprg=lilypond\ \"%\"\ 2>&1\ \\\|\ lilypond_error_filter

Is there a way to get this working?

Thanks!

Support for running vim commands

It would be excellent if asynccommand#run() could also run arbitrary vim commands asynchronously. I'm thinking of something like:

    let env = {}

    function! env.get(temp_file) dict
        let qfl = eval(join(readfile(a:temp_file), "\n"))
        ...
    endf

    function! env.put(temp_file) dict
        let qfl = ...
        call writefile([string(qfl)], a:temp_file)
    endf

    call asynccommand#run("", env)

This would first run env.put() in the remote sub-vim to write some info to the tempfile, and then use
env.get() to retrieve the info.

Subtle shell redirection bug

I just started upgrading to 3.1 and have been working with a small function to run Gimple Software's FlexeLint. In our organization, we are supporting both Vim and Emacs--which leads us to moving shared functionality into shell scripts when beneficial. In this case, we have a shell script that takes a numeric, optional last argument.

From our plugin:

function! util#LintImpl(client, target, options)
    let cmd = '/u/asdf/lint_build.sh '.a:client.' '.a:target.' '.a:options
"    echo 'Executing <'.cmd.'> asynchronously.'
    let env = asynchandler#quickfix(&errorformat, 'lint results')
    call asynccommand#run(cmd, env)
endfunction

From ./autoload/asynccommand.vim:

  let shellredir = &shellredir
  if match( shellredir, '%s') == -1
      " ensure shellredir has a %s so printf works
      let shellredir .= '%s'
  endif

  " Grab output and error in case there's something we should see
  let tool_cmd = a:command . printf(shellredir, temp_file)

The problem is that the shell redirection characters are appended to the user's shell command (without a space of separation). For example, I wanted to run "/u/asdf/lint_build.sh X Y 1" which results in tool_cmd "/u/asdf/lint_build.sh X Y 1>%s 2>&1" (where %s is the temp file name). The command that executes now redirects stdout unexpectedly!

Here's the patch to throw a space in between:

67c67
<   let tool_cmd = a:command . printf(shellredir, temp_file)

---
>   let tool_cmd = a:command . ' ' . printf(shellredir, temp_file)

Thanks,
Chad Moore

Request: Display pending jobs

Would be great to pull up a scratch window containing a list of background jobs (probably don't currently maintain much useful information about them though) or to have a statusline segment that showed the number of background jobs.

Show QuickFix window only if command fails?

It would be great if AsyncMake could be configured such that:

  • if the make fails (return code != 0), the quickfix window is displayed
  • if the make succeeds, it just does ":echo Build Successful" or similar.

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.