Can the quickfix window title be set to the command which generated it?

121 views
Skip to first unread message

Benjamin Fritz

unread,
Jun 7, 2012, 10:57:53 AM6/7/12
to eclim-dev
I added this to my config as a hack to show info about the search
which generated a quickfix/location list (like :CSearch), but it's
probably not the best way to accomplish it:


diff -r f6f38a3a7418 eclim/autoload/eclim/lang.vim
--- a/eclim/autoload/eclim/lang.vim Thu Jun 07 09:53:22 2012 -0500
+++ b/eclim/autoload/eclim/lang.vim Thu Jun 07 09:56:31 2012 -0500
@@ -156,8 +156,12 @@
let encoding = eclim#util#GetEncoding()
let search_cmd .= ' -f "' . file . '"' .
\ ' -o ' . offset . ' -l ' . length . ' -e ' . encoding
+
+ let search_what = "elmt: ".expand("<cword>")
else
" quote the search pattern
+ let search_what = "ptrn: ".substitute(
+ \ search_cmd, '\(.*-p\s\+\)\(.\{-}\)\(\s\|$\)\(.*\)','\2','')
let search_cmd = substitute(
\ search_cmd, '\(.*-p\s\+\)\(.\{-}\)\(\s\|$\)\(.*\)', '\1"\2"\3\4', '')
endif
@@ -195,6 +199,14 @@
call cursor(entry.lnum, entry.col)
else
exec 'lopen ' . g:EclimLocationListHeight
+ let w:quickfix_title = search_cmd
+ " strip out stuff not that useful that makes it too long
+ let w:quickfix_title = substitute(w:quickfix_title,
'\s*-command\s\+\(\S\+\)', '\1', '')
+ let w:quickfix_title = substitute(w:quickfix_title,
'\s*-n\s\+"\([^"]\+\)"', ' \1', '')
+ let w:quickfix_title = substitute(w:quickfix_title,
'\s*-f\s\+"\([^"]\+\)"', '', '')
+ let w:quickfix_title = substitute(w:quickfix_title,
'\s*-e\s\+\S\+', '', '')
+ " clarify search text
+ let w:quickfix_title = substitute(w:quickfix_title,
'\(\s*\)\%(-o\s\+\d\+\s\+-l\s\+\d\+\|-p\s\+"\S\+"\)\(.*\)',
'\2\1'.search_what, '')
endif
return 1
else

Eric Van Dewoestine

unread,
Jun 16, 2012, 1:02:19 PM6/16/12
to ecli...@googlegroups.com
I finally got a chance to play with this, and while I like the idea,
setting w:quickfix_title doesn't work very well. That variable gets
reset on any updates to the quickfix/loclist window, so if you close
and then reopen the window, any changes to w:quickfix_title are lost
(same with :cnewer/:colder).

So, I decided to take a crack at patching vim to add two new
functions: setqftitle() and setloctitle()

My C skills are pretty poor these days (not that they were ever very
good), so my patch could very well have some silly mistakes, but it
seems to be working pretty good for me. I was hoping you'd give it a
shot and if you can't find any issues I'll submit it to vim-dev and
see if it can get accepted into the mainline.

Note: I haven't made any changes to eclim yet, so to utilize the patch
you'll have to update your submitted patch to call setqftitle()
instead of setting w:quickfix_title directly. If this patch makes it
into vim then I'll go through the eclim code and set the
quickfix/loclist titles accordingly.

--
eric
setqftitle.patch

Ben Fritz

unread,
Jun 19, 2012, 1:08:53 PM6/19/12
to ecli...@googlegroups.com
On Saturday, June 16, 2012 12:02:19 PM UTC-5, Eric Van Dewoestine wrote:
> On 2012-06-07 09:57:53, Benjamin Fritz wrote: 
> > I added this to my config as a hack to show info about the search 
> > which generated a quickfix/location list (like :CSearch), but it's 
> > probably not the best way to accomplish it: 
> > 
> > 
> > [patch removed] 
> I finally got a chance to play with this, and while I like the idea, 
> setting w:quickfix_title doesn't work very well. That variable gets 
> reset on any updates to the quickfix/loclist window, so if you close 
> and then reopen the window, any changes to w:quickfix_title are lost 
> (same with :cnewer/:colder). 
> So, I decided to take a crack at patching vim to add two new 
> functions: setqftitle() and setloctitle() 

I noticed that same problem quite a while ago, that you can use setqflist and
the list is stored with :colder and :cnewer, but the title is not. Am I to
understand that setqftitle(), followed by a new command creating a new
quickfix list, followed by :colder, would restore the title? That sounds like
an excellent feature (maybe even a bug fix)!

> My C skills are pretty poor these days (not that they were ever very 
> good), so my patch could very well have some silly mistakes, but it 
> seems to be working pretty good for me. I was hoping you'd give it a 
> shot and if you can't find any issues I'll submit it to vim-dev and 
> see if it can get accepted into the mainline. 

I'll see if I can try it out from home sometime in the next couple of weeks. I
don't use a custom-compiled Vim at work where I normally use Eclim. 

I'm not very knowledgeable about the Vim C code itself, so you may get
faster/better feedback if you just post to vim_dev directly. I'll certainly
download and apply the patch at home though and see what it can do.

> Note: I haven't made any changes to eclim yet, so to utilize the patch 
> you'll have to update your submitted patch to call setqftitle() 
> instead of setting w:quickfix_title directly. If this patch makes it 
> into vim then I'll go through the eclim code and set the 
> quickfix/loclist titles accordingly. 

Sounds good. I'll admit I'm not happy when I lose the title or the title
becomes innacurate because of a new quickfix command, so probably the feature
isn't worth adding until the title is actually associated with the list.

Eric Van Dewoestine

unread,
Jun 19, 2012, 1:24:28 PM6/19/12
to ecli...@googlegroups.com
On 2012-06-19 10:08:53, Ben Fritz wrote:
> On Saturday, June 16, 2012 12:02:19 PM UTC-5, Eric Van Dewoestine wrote:
> > On 2012-06-07 09:57:53, Benjamin Fritz wrote:
> > > I added this to my config as a hack to show info about the search
> > > which generated a quickfix/location list (like :CSearch), but it's
> > > probably not the best way to accomplish it:
> > >
> > >
> > > [patch removed]
> >
> > I finally got a chance to play with this, and while I like the idea,
> > setting w:quickfix_title doesn't work very well. That variable gets
> > reset on any updates to the quickfix/loclist window, so if you close
> > and then reopen the window, any changes to w:quickfix_title are lost
> > (same with :cnewer/:colder).
> >
> > So, I decided to take a crack at patching vim to add two new
> > functions: setqftitle() and setloctitle()
> >
>
> I noticed that same problem quite a while ago, that you can use setqflist
> and
> the list is stored with :colder and :cnewer, but the title is not. Am I to
> understand that setqftitle(), followed by a new command creating a new
> quickfix list, followed by :colder, would restore the title?

Exactly. It replaces the vim generated title (NULL for setqflist,
'cexpr ..', 'make', etc. if populated using one of those) stored in
the quickfix info struct with the value supplied to setqftitle() so
that the title is stored with the results and restored into
w:quickfix_title when using :colder/:cnewer.

> That sounds like an excellent feature (maybe even a bug fix)!

> > My C skills are pretty poor these days (not that they were ever very
> > good), so my patch could very well have some silly mistakes, but it
> > seems to be working pretty good for me. I was hoping you'd give it a
> > shot and if you can't find any issues I'll submit it to vim-dev and
> > see if it can get accepted into the mainline.
> >
>
> I'll see if I can try it out from home sometime in the next couple of
> weeks. I
> don't use a custom-compiled Vim at work where I normally use Eclim.
>
> I'm not very knowledgeable about the Vim C code itself, so you may get
> faster/better feedback if you just post to vim_dev directly. I'll certainly
> download and apply the patch at home though and see what it can do.

I'll post it after you get a chance to try it out if for no other
reason that to get the extra bit of testing before submitting it to
the scrutiny of others.

> > Note: I haven't made any changes to eclim yet, so to utilize the patch
> > you'll have to update your submitted patch to call setqftitle()
> > instead of setting w:quickfix_title directly. If this patch makes it
> > into vim then I'll go through the eclim code and set the
> > quickfix/loclist titles accordingly.
> >
>
> Sounds good. I'll admit I'm not happy when I lose the title or the title
> becomes innacurate because of a new quickfix command, so probably the
> feature
> isn't worth adding until the title is actually associated with the list.

--
eric

Ben Fritz

unread,
Jul 8, 2012, 3:33:32 PM7/8/12
to ecli...@googlegroups.com
I cannot get your patch to apply cleanly. I first tried importing it into my mq patch series, but all hunks were rejected. So then I tried applying with the basic "patch" utility (with -p1), and the same thing happened. What might I be doing wrong? It looks like patch isn't even trying different line offsets.

I think I mostly got it working by also using a really big value in an -F argument to the patch command (I used 5000 when 500 gave rejects), but I still had a total of 3 rejected hunks which look trivial to apply in eval.c and quickfix.c, and I have no idea why patch would fail on those. I'll fix them by hand and try it out tonight barring a new patch.

ben@LivingRoom:~/Code/vim-src$ hg update default
0 files updated, 0 files merged, 0 files removed, 0 files unresolved
ben@LivingRoom:~/Code/vim-src$ hg status
? .cproject
? .project
? .settings/org.eclipse.cdt.codan.core.prefs
? .settings/org.eclipse.cdt.core.prefs
? .settings/org.eclipse.cdt.ui.prefs
? config.out
? make.out
ben@LivingRoom:~/Code/vim-src$ patch -i ../patches/setqftitle.patch -p1
patching file runtime/doc/eval.txt
Hunk #1 FAILED at 1919.
Hunk #2 FAILED at 5123.
Hunk #3 FAILED at 5207.
3 out of 3 hunks FAILED -- saving rejects to file runtime/doc/eval.txt.rej
patching file runtime/doc/quickfix.txt
Hunk #1 FAILED at 313.
1 out of 1 hunk FAILED -- saving rejects to file runtime/doc/quickfix.txt.rej
patching file runtime/doc/tags
Hunk #1 FAILED at 7469.
1 out of 1 hunk FAILED -- saving rejects to file runtime/doc/tags.rej
patching file src/eval.c
Hunk #1 FAILED at 682.
Hunk #2 FAILED at 8014.
Hunk #3 FAILED at 16189.
Hunk #4 FAILED at 16207.
Hunk #5 FAILED at 16322.
5 out of 5 hunks FAILED -- saving rejects to file src/eval.c.rej
patching file src/quickfix.c
Hunk #1 FAILED at 882.
Hunk #2 FAILED at 913.
Hunk #3 FAILED at 3833.
3 out of 3 hunks FAILED -- saving rejects to file src/quickfix.c.rej 
ben@LivingRoom:~/Code/vim-src$ hg summary
parent: 3809:906c91f4fae8
Added tag v7-3-591 for changeset e5b925ae56e3
branch: default
commit: 7 unknown (clean)
update: 26 new changesets, 2 branch heads (merge)
mq: 1 unapplied

Eric Van Dewoestine

unread,
Jul 8, 2012, 4:09:10 PM7/8/12
to ecli...@googlegroups.com
Attached is an updated version of the patch after pulling the latest
vim code:

$ hg tip
changeset: 3663:906c91f4fae8
tag: tip
user: Bram Moolenaar <br...@vim.org>
date: Fri Jul 06 18:27:39 2012 +0200
summary: Added tag v7-3-591 for changeset e5b925ae56e3

I tested reverting my local changes and apply the patch a couple
different ways:

$ patch -p1 < qftitle.patch
$ hg import qftitle.patch

Let me know if the new patch continues to give you problems, and
thanks for taking a look!

--
eric
qftitle.patch

Ben Fritz

unread,
Jul 13, 2012, 1:17:58 AM7/13/12
to ecli...@googlegroups.com
The patch seems to work as advertised. I still haven't got much of a chance to actually review it.

I'm not sure if it's due to the patch, but i get a compiler warning in f_getqftitle,

"assignment makes pointer from integer without a cast" eval.c line 11658

Eric Van Dewoestine

unread,
Jul 15, 2012, 5:21:51 PM7/15/12
to ecli...@googlegroups.com
On 2012-07-12 22:17:58, Ben Fritz wrote:
> The patch seems to work as advertised. I still haven't got much of a chance
> to actually review it.
>
> I'm not sure if it's due to the patch, but i get a compiler warning in
> f_getqftitle,
>
> "assignment makes pointer from integer without a cast" eval.c line 11658

I actually get the same warning, I just didn't notice it before. I
poked around but my lack of c skills really shows here. I'm not sure
why that warning is triggered. I compared my patch against some
similar functions in vim and I don't see the difference, so I guess at
some point I'll just submit it to the vim-dev list and let someone on
there point out my mistake and let Bram decide if he wants to include
the new functions.
> --
> You received this message because you are subscribed to the Google Groups "eclim-dev" group.
> To view this discussion on the web visit https://groups.google.com/d/msg/eclim-dev/-/uEWDKpYqeaYJ.
> To post to this group, send email to ecli...@googlegroups.com.
> To unsubscribe from this group, send email to eclim-dev+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/eclim-dev?hl=en.
>

--
eric
Reply all
Reply to author
Forward
0 new messages