Monday, February 6, 2012

Re: folding quickfix list based on the command which created it

On Mon, Feb 6, 2012 at 2:48 PM, Marcin Szamotulski <mszamot@gmail.com> wrote:
> On 11:33 Mon 06 Feb     , Ben Fritz wrote:
>> I am trying to make a quickfix folding solution for my Vim config,
>> which does something different based on what command created the
>> quickfix list.
>>
>> Currently, I'm folding all results from the same file together for the
>> various 'grep' commands, and I'm folding away all but errors and
>> warnings for compiler commands.
>>
>> But I'm not happy with my detection of the command which created the
>> quickfix window.
>>
>> I've tried using w:quickfix_title, but I have discovered this variable
>> does not get set until sometime after the filetype autocmd fires. So,
>> I've needed to set up my foldexpr to check the w:quickfix_title
>> variable every single time its invoked to determine which behavior to
>> use. Additionally, in order to apply the proper method initially, I
>> needed to create a BufWinEnter autocmd which will do :let
>> &foldexpr=&foldexpr to re-calculate all the folds on a quickfix
>> window, since the w:quickfix_title variable is not defined when the
>> filetype plugin fires.
>>
>> So my first question is, is there a better way to detect the command
>> or command type which set the quickfix list?
>>
>
> I have a suggestion for the first problem: you can try QuickFixCmdPost.
>
> I was trying to do a similar thing: to filter quick fix list when user issues
> :cgetfile. I came up with a patch, which adds an autocommand-event, well there
> is one for that: QuickFixCmdPre (and QuickFixCmdPost) (it was not handling
> :cgetfile), but it does the job for :grep (which you mentioned). If you are
> interested I can send you the patch.
>

Thanks, I thought of using QuickFixCmdPre/Post, but if I understand
correctly these apply to the creation of the list, not the creation of
the window. So if I issue a :vimgrep followed by a :make, and then do
:colder, the wrong folding will be used. It gets even more
complicated, since quickfix commands can use either the (global)
quickfix list, or the (per-window) location list. So unless I'm
missing something, I don't think I can set up folding based on the
command used to create the list using these autocmd events. I could
probably filter them to completely remove the lines I am trying to
fold away, but I like to be able to view the context by unfolding if I
need it (even if normally it is useless). And I'm not sure how I'd
accomplish the "fold results by file" setup for the various grep
commands that way.

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments:

Post a Comment