Modify

Opened 15 years ago

Closed 4 years ago

#5233 closed enhancement (fixed)

[Patch] Add support for tags in source file

Reported by: anton.deguet@… Owned by: ttressieres
Priority: normal Component: IncludeSourcePartialPlugin
Severity: normal Keywords:
Cc: Trac Release: 1.4

Description

Instead of using line number to extract the snippet of code, it would be nice to use some special tags to identify the starting and end lines of the code to be inserted. For example one could do:

  unsigned int var;
  // @TracWikiIncludeSourcePartialBegin(example1)
  for (var = 0; var != 10; var++)
      someFuntion(var)
  }
  // @TracWikiIncludeSourcePartialEnd(example1)

Then in the wiki page, one would use:

  [[IncludeSource(trunk/proj/file.cpp, snippet=example1, rev=1200)]]

This way, the code snippet could be moved within the file or grow but the wiki would still insert the right code.

Attachments (1)

add-search-markers.diff (1.7 KB) - added by anonymous 14 years ago.
Keeping it simple is a good idea. Please find attached a diff that allows to use plain text in start/end and searches for the first occurence of the start text in the source and the first occurence of end in a line below start to get line numbers. Though this is not a regex, it still allows to be used with any source code language.

Download all attachments as: .zip

Change History (14)

comment:1 Changed 15 years ago by Chris Heller

Status: newassigned

Your example is good because it keeps the IncludeSource macro syntax straightforward, but having a specific syntax inside the source code being included doesn't seem like a good thing to require.

Maybe instead of requiring a special syntax within the source code, the start and end could be defined as regular expressions. I wouldn't want the macro syntax itself to get too complex though.

comment:2 Changed 15 years ago by Jeff Hammel

I dislike adding tags to source files just for 3rd-party documentation purposes, if avoidable. A better (though harder) solution would be to allow language dependent includes. E.g. for python to include the FooBar class:

[[IncludeSource(trunk/proj/file.cpp,class=FooBar)]]

comment:3 Changed 15 years ago by anonymous

I second the regular expression. That would still support the example syntax it would also support more complex things, for example a specific class, or function, or even a family of functions (say, all the custom exceptions in a file)

That said, I also know regular expressions are becoming a lost art form, so we might need quite a few examples, or add in some "shortcuts" for typical cases.

Such as support RE plus the @IPSExample1, class CLASSNAME def METHODNAME etc.

I would suggest the additional support be plugins to the plugin :d So native support Regular expressions, or pass to plugin chain (either explicit plugin, or by file extension?)

the nice thing about that is, one could do double duty with code markup with a tool such as doxygen and this, assuming a plugin2 (plugin to a plugin) was created :) if you liked code doc tools, if not, you could still link to specific lines, or an RE

So I think I proposed a trinary behavior: current, regular expression, or pass to plugin2 I know, it's more work. but I like to use the wiki for code reviews, and this just makes it better!

btw, thanks for the great plugin

comment:4 Changed 15 years ago by tekknokrat

Also second support for regex. We are monitoring configuration files in trac environment and this way I can get rid of the bunch of comments typically in a default configuration file.

Just wondering how to match a specific section in a typical trac.ini with regex. Is something like this possible?

[[IncludeSource(trunk/proj/file.cpp,/^\[IniSection\],^\[.*\]],regex=true)]]

This should define a start and an end line matched via regex. The last param is for compatibility reasons for the numbering.

Last edited 7 years ago by Ryan J Ollos (previous) (diff)

comment:5 Changed 14 years ago by anonymous

example for attached patch:

[[IncludeSource(trunk/proj/file.cpp, start="function callMe", end="; // end function")]]
Last edited 8 years ago by Ryan J Ollos (previous) (diff)

Changed 14 years ago by anonymous

Attachment: add-search-markers.diff added

Keeping it simple is a good idea. Please find attached a diff that allows to use plain text in start/end and searches for the first occurence of the start text in the source and the first occurence of end in a line below start to get line numbers. Though this is not a regex, it still allows to be used with any source code language.

comment:6 Changed 14 years ago by anonymous

Summary: Add support for tags in source file[Patch] Add support for tags in source file

comment:7 Changed 8 years ago by Massimo

Some years later, are there any plans to integrate that into the plugin? However I would prefer the RegEx approach for being able to adapt to old code without adding magic comments.

It is often interesting to include the usage() part of code into wiki pages in order to keep it up to date.

Last edited 8 years ago by Ryan J Ollos (previous) (diff)

comment:8 Changed 8 years ago by Ryan J Ollos

See also CodeExampleMacro, which supports some more complex usage scenarios.

Version 0, edited 8 years ago by Ryan J Ollos (next)

comment:9 Changed 7 years ago by Ryan J Ollos

See also #12729 for IncludeMacro.

comment:10 Changed 4 years ago by Ryan J Ollos

Owner: changed from Chris Heller to ttressieres

comment:11 Changed 4 years ago by ttressieres

The patch is a good starting point, we can add also support of regex such as

[[IncludeSource(svn/monprojet/trunk/trac.ini,start=\[b.+\],end=\[.+\])]]

comment:12 Changed 4 years ago by ttressieres

In 17695:

add support of regex in "start" and/or "end" parameters (see #5233)

comment:13 Changed 4 years ago by ttressieres

Resolution: fixed
Status: assignedclosed
Trac Release: 0.111.4

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain ttressieres.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.