Web Images Videos Maps News Shopping Gmail more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Printing column number for matched text
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  5 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Eric Van Dewoestine  
View profile  
 More options Oct 23 2008, 11:54 pm
From: "Eric Van Dewoestine" <ervan...@gmail.com>
Date: Thu, 23 Oct 2008 20:54:28 -0700
Local: Thurs, Oct 23 2008 11:54 pm
Subject: [PATCH] Printing column number for matched text

I recently started using ack inside of vim (set grepprg=ack) which is
a huge improvement in functionality over the standard :grep and a huge
speed boost over :vimgrep when working over a nfs mount.

However, I quickly became annoyed at the lack of column number
information, which prevents vim from jumping to the actual matched
text.

So, to remedy the situation, I patched Ack.pm to support a new
--column option and to print the column number along with the line
number like so:

$ ack -H --text --column line somefile.txt
somefile.txt
1:6:some line matched
2:12:some other line matched

The change is pretty simple, but I'm new to ack and I'm not sure of
the full implications of this change.  Hopefully this, or a similar
patch can be included to improve support for vim (and probably other
text editors as well).

NOTE: the patch is against version 1.86
--
eric

[ Ack.pm.diff 1K ]
*** Ack.pm.orig 2008-10-23 18:44:57.000000000 -0700
--- Ack.pm      2008-10-23 20:29:20.000000000 -0700
***************
*** 216,221 ****
--- 216,222 ----
          'u|unrestricted'        => \$opt{u},
          'v|invert-match'        => \$opt{v},
          'w|word-regexp'         => \$opt{w},
+         'column'                => \$opt{column},

          'ignore-dirs=s'         => sub { shift; my $dir = remove_dir_sep( shift ); $ignore_dirs{$dir} = '--ignore-dirs' },
          'noignore-dirs=s'       => sub { shift; my $dir = remove_dir_sep( shift ); delete $ignore_dirs{$dir} },
***************
*** 1146,1151 ****
--- 1147,1153 ----
      my $color = $opt->{color};
      my $heading = $opt->{heading};
      my $show_filename = $opt->{show_filename};
+     my $show_column = $opt->{column};

      if ( $show_filename ) {
          if ( not defined $display_filename ) {
***************
*** 1175,1180 ****
--- 1177,1185 ----
          if ( $show_filename ) {
              App::Ack::print_filename($display_filename, $sep) if not $heading;
              App::Ack::print_line_no($line_no, $sep);
+             if ( $show_column && $is_match && $regex && $_ =~ /$regex/g ) {
+               App::Ack::print_line_no($-[0] + 1, $sep);
+             }
          }

          if ( $output_func ) {


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Discussion subject changed to "[PATCH] Printing column number for matched text" by Ovid
Ovid  
View profile  
 More options Oct 29 2008, 5:53 am
From: Ovid <curtis....@gmail.com>
Date: Wed, 29 Oct 2008 09:53:32 +0000
Local: Wed, Oct 29 2008 5:53 am
Subject: Re: [ack-users] [PATCH] Printing column number for matched text
On Fri, Oct 24, 2008 at 3:54 AM, Eric Van Dewoestine <ervan...@gmail.com> wrote:

> I recently started using ack inside of vim (set grepprg=ack) which is
> a huge improvement in functionality over the standard :grep and a huge
> speed boost over :vimgrep when working over a nfs mount.

> However, I quickly became annoyed at the lack of column number
> information, which prevents vim from jumping to the actual matched
> text.

That sounds very useful.  I've also integrated ack into vim:

  http://use.perl.org/~Ovid/journal/36430

As a quick hack, I jump to the matched text with:

  execute "/\\v"  . pattern

If you use simple Perl regular expressions, this will allow vim to
usually jump directly to the first match it finds (see "help \v" in
vim).

Cheers,
Ovid


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Eric Van Dewoestine  
View profile  
 More options Oct 29 2008, 10:39 am
From: "Eric Van Dewoestine" <ervan...@gmail.com>
Date: Wed, 29 Oct 2008 07:39:44 -0700
Local: Wed, Oct 29 2008 10:39 am
Subject: Re: [ack-users] Re: [PATCH] Printing column number for matched text

I took a quick look at your integration and it looks like it doesn't
integrate with vim's quickfix.  It seems to concentrate on finding one
file at a time.

While this may satisfy your workflow quite well, my primary usage
takes heavy advantage of vim's quickfix support where I want to be
able to navigate around all matches.  The patch I submitted makes such
usage much more pleasant as it allows :cnext, :cprev, etc. to place
the cursor directly on the match.

Hopefully the powers that be will consider the patch for mainline
integration.

--
eric


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Andy Lester  
View profile  
 More options Oct 29 2008, 10:41 am
From: Andy Lester <a...@petdance.com>
Date: Wed, 29 Oct 2008 09:41:50 -0500
Local: Wed, Oct 29 2008 10:41 am
Subject: Re: [ack-users] Re: [PATCH] Printing column number for matched text

On Oct 29, 2008, at 9:39 AM, Eric Van Dewoestine wrote:

> While this may satisfy your workflow quite well, my primary usage
> takes heavy advantage of vim's quickfix support where I want to be
> able to navigate around all matches.  The patch I submitted makes such
> usage much more pleasant as it allows :cnext, :cprev, etc. to place
> the cursor directly on the match.

I don't understand.  Are you talking about a patch to vim, or  
something we should be doing in ack?

--
Andy Lester => a...@petdance.com => www.petdance.com => AIM:petdance


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Eric Van Dewoestine  
View profile  
 More options Oct 29 2008, 10:54 am
From: "Eric Van Dewoestine" <ervan...@gmail.com>
Date: Wed, 29 Oct 2008 07:54:12 -0700
Local: Wed, Oct 29 2008 10:54 am
Subject: Re: [ack-users] Re: [PATCH] Printing column number for matched text

My original mail[1] includes a patch[2] to ack to allow it to print
the column number along with the line number for each match found.
The main motivation being integration with vim, but I would assume
that other editors could take advantage of the additional information
as well.

[1] http://groups.google.com/group/ack-users/browse_thread/thread/562cb32...
[2] http://ack-users.googlegroups.com/attach/d876aa71645f7fbf/Ack.pm.diff...

--
eric


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google