git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2 1/2] grep: add option to show whole function as context

From
René Scharfe <rene.scharfe@lsrfire.ath.cx>
Date
Aug 2, 2011, 18:08 UTC
Message-ID
<4E383D32.5090604@lsrfire.ath.cx>
In-Reply-To
<7vei14hgcd.fsf@alter.siamese.dyndns.org>
Am 02.08.2011 01:17, schrieb Junio C Hamano:
Show 17 quoted lines
> René Scharfe <rene.scharfe@lsrfire.ath.cx> writes:
> 
>> Add a new option, -W, to show the whole surrounding function of a match.
> 
> Thanks, will queue both patches.
> 
> It feels somewhat dirty to take the range between the previous "funcname"
> and the next "funcname" and consider it the whole function, as if there is
> nothing outside the function, though. I certainly understand that this is
> a natural and unfortunate consequence that "funcname" is a mechanism
> designed to mark only the _beginning_, and we didn't have any need for a
> mechanism to mark the _end_.
> 
> I am not complaining; just making an observation.  I do not offhand have a
> suggestion for improving this, and I think the obvious "then let's come up
> with another configuration to mark the end" is not an improvement but
> making things worse, so...

A certain amount of dirtyness is unavoidable unless we use a real parser. Apropos, labels are function boundaries as well, so there we have another limitation (i.e. we won't get a function whole if it contains labels without leading whitespace).

Ideally I'd like to see the whole function text up to the closing brace but including any leading comments, if present. Which is even more complicated, of course.

For C-style and Shell files, /^}/ would probably suffice as a regex to find function endings..

First I'm curious to see how useful the simple start-to-start heuristic is, though. Even the -[ABC] options are kind of fuzzy -- how do you know the number is high enough before running grep? Let's see how far this quick and dirty approach to present a smarter context can take us.

René
Previous: Junio C HamanoNext: René Scharfe
Message 8 of 11 in “grep: add option to show whole function as context”
  1. grep: add option to show whole function as contextRené Scharfe, Jul 31, 2011
  2. Sverre RabbelierJul 31, 2011
  3. René ScharfeAug 1, 2011
  4. Sverre RabbelierAug 1, 2011
  5. René ScharfeAug 1, 2011
  6. 1/2 grep: add option to show whole function as contextRené Scharfe, Aug 1, 2011
  7. Junio C HamanoAug 1, 2011
  8. René ScharfeAug 2, 2011
  9. 2/2 grep: long context optionsRené Scharfe, Aug 1, 2011
  10. TaitAug 2, 2011
  11. René ScharfeAug 2, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.