It is currently Tue Jun 23, 2026 4:54 am


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 13 posts ] 
Author Message
 Post subject: How to extract comment line from script or plugins ?
PostPosted: Wed Dec 25, 2013 10:41 am  (#1) 
Offline
GimpChat Member

Joined: Apr 12, 2010
Posts: 5870
I would like to know how to split the comment line from script fu and python plugins
(..even better if works also with C plugin but i need mostly for the scripts )

I need because , even when there is not a proper user's guide at least may be something close ( intended use, , description of the commands , dependencies ) inside the comment lines


I am sure there is a command in Notepad++ for this , but no idea how to find it ...except asking here :


what i need is copy and save on a new text file the comment :
all comment lines inside " make planet.scm" are to be automatically copied and saved in "make planet_comment.txt"

i am totally lost , i am sure that should be easy and quick but..well i need your help to find the right commands

_________________
My 3D Gallery on Deviantart http://photocomix2.deviantart.com/
Main gallery http://www.flickriver.com/photos/photocomix-mandala/
Mandala and simmetry http://www.flickriver.com/photos/photocomix_mandala/

Image

Mrs Wilbress


Share on Facebook Share on Twitter Share on Orkut Share on Digg Share on MySpace Share on Delicious Share on Technorati
Top
 Post subject: Re: How to extract comment line from script or plugins ?
PostPosted: Wed Dec 25, 2013 11:06 am  (#2) 
Offline
GimpChat Founder
User avatar

Joined: May 22, 2008
Posts: 5241
Location: Gimpville
You might want to take a look at this online tool..

http://textmechanic.com/Remove-Lines-Containing.html

The following sed command will extract all lines containing the character ";" from infile.scm and output them to comments.txt

sed '/^\;/d' infile.scm > comments.txt
        ^

_________________
“If you reach for the stars, you just might land on a decently sized hill.” - Stuart Hill


Top
 Post subject: Re: How to extract comment line from script or plugins ?
PostPosted: Wed Dec 25, 2013 12:59 pm  (#3) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4812
PhotoComix wrote:
I would like to know how to split the comment line from script fu and python plugins
(..even better if works also with C plugin but i need mostly for the scripts )

I need because , even when there is not a proper user's guide at least may be something close ( intended use, , description of the commands , dependencies ) inside the comment lines


I am sure there is a command in Notepad++ for this , but no idea how to find it ...except asking here :


what i need is copy and save on a new text file the comment :
all comment lines inside " make planet.scm" are to be automatically copied and saved in "make planet_comment.txt"

i am totally lost , i am sure that should be easy and quick but..well i need your help to find the right commands


The plugin registration data includes a string that explain the parameters to the plugin (the 'blurb'), and is displayed in the plugin browser ('Additional information'). I don't see an author taking the time and effort to write this information and then put it at the wrong place (code comments) when a pair of quotes would make it appear where it is needed.

_________________
Image


Top
 Post subject: Re: How to extract comment line from script or plugins ?
PostPosted: Wed Dec 25, 2013 2:22 pm  (#4) 
Offline
Script Coder
User avatar

Joined: Nov 06, 2012
Posts: 239
Location: Italy
Photocomix, I think I have found a way to extract all of the comment lines from a single script in Notepad++, which consists in eliminating all the other lines that are uncommented by means of the RegEx functionality.

Once you have opened the script with Notepad++, launch the "Replace" window through "Search -> Replace..." and, first of all, activate the "Regular expression" radio button placed at the bottom of the window in question, then copy the following string and paste it to the "Find what" text box (sembra ostrogoto, lo so!):

^(?!((\s)*(;)+))([^;])*

Then leave the "Replace with" text box blank, disable the "Match case" checkbox and enable the "Wrap around" checkbox.

Lastly, click "Replace All" and, in case, save the outcome to a new file with a different name than the original one in order to keep this unchanged.

I have tested this method on one of my scripts and it seems to work correctly. Also, since it should work regardless of the contents of the particular text loaded, I suggest you record the steps I described in a Macro, so you will have the possibility of reproducing such type of manipulation every time you want by simply playing the saved macro.



P.S.: in case the source code to handle is written in Python, this stratagem should still be valid, provided that you use the following regular expression in place of the one I posted above referring to Script-Fu instead:

^(?!((\s)*(#)+))([^#])*

_________________
Gino D's GIMP scripts: https://sites.google.com/site/ginodonig/gimp-scripts


Top
 Post subject: Re: How to extract comment line from script or plugins ?
PostPosted: Wed Dec 25, 2013 3:54 pm  (#5) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4812
Gino D wrote:
P.S.: in case the source code to handle is written in Python, this stratagem should still be valid, provided that you use the following regular expression in place of the one I posted above referring to Script-Fu instead:

^(?!((\s)*(#)+))([^#])*


In Python, methods descriptions (that end up in automatically generated documentation, available with help()) are not in comments but in 'docstrings', that are an unassigned string literal that immediately follows the 'def' statement. And a string literal can be delimited either with single or double quotes, or withing triple simple or double quotes (this allows formatting). So you need to catch:
def distance_to_line(p, line_point1,line_point2):
    'Simple description in simple quotes'

def distance_to_line(p, line_point1,line_point2):
    "Simple description in double quotes"

def distance_to_line(p, line_point1,line_point2):
    '''
Formated description
in triple simple quotes
'''

def distance_to_line(p, line_point1,line_point2):
    """
Formated description
in triple double quotes
"""

_________________
Image


Top
 Post subject: Re: How to extract comment line from script or plugins ?
PostPosted: Wed Dec 25, 2013 4:02 pm  (#6) 
Offline
GimpChat Member
User avatar

Joined: Nov 16, 2011
Posts: 5127
Location: Metro Vancouver, BC
For Linux and Mac OS X, Kate (text editor) supports regular expressions.

_________________
Image
Gimp 2.8.18, Linux, median user
Gimp Chat Tutorials Index
Spirit Bear (Kermode)


Top
 Post subject: Re: How to extract comment line from script or plugins ?
PostPosted: Wed Dec 25, 2013 6:37 pm  (#7) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4812
Odinbc wrote:
For Linux and Mac OS X, Kate (text editor) supports regular expressions.


http://xkcd.com/208/
:geek

_________________
Image


Top
 Post subject: Re: How to extract comment line from script or plugins ?
PostPosted: Wed Dec 25, 2013 7:58 pm  (#8) 
Offline
GimpChat Member

Joined: Apr 12, 2010
Posts: 5870
@GinoD

thank for all the details :yes :tyspin

_________________
My 3D Gallery on Deviantart http://photocomix2.deviantart.com/
Main gallery http://www.flickriver.com/photos/photocomix-mandala/
Mandala and simmetry http://www.flickriver.com/photos/photocomix_mandala/

Image

Mrs Wilbress


Top
 Post subject: Re: How to extract comment line from script or plugins ?
PostPosted: Wed Dec 25, 2013 11:21 pm  (#9) 
Offline
GimpChat Member
User avatar

Joined: Nov 16, 2011
Posts: 5127
Location: Metro Vancouver, BC
ofnuts wrote:
That's a good one Ofnuts, where would Perl be without regex? :)

_________________
Image
Gimp 2.8.18, Linux, median user
Gimp Chat Tutorials Index
Spirit Bear (Kermode)


Top
 Post subject: Re: How to extract comment line from script or plugins ?
PostPosted: Thu Dec 26, 2013 5:15 am  (#10) 
Offline
Script Coder
User avatar

Joined: Nov 06, 2012
Posts: 239
Location: Italy
PhotoComix wrote:
@GinoD

thank for all the details :yes :tyspin

Prego. :)

Regular expressions represent a very useful mean whose huge potential I discovered only quite recently.

As Odinbc rightly pointed out, Notepad++ is not the only text editor allowing you to work with them. Besides Kate, we could also mention other smart applications in this field, such as jEdit and Gedit, for instance, which both have the advantage of being multiplatform.

Take a look at this very detailed and well explained documentation on how to handle regular expressions in Notepad++, while in my opinion it proves to provide valid guidelines on RegEX for other programs as well:
http://sourceforge.net/apps/mediawiki/n ... xpressions

_________________
Gino D's GIMP scripts: https://sites.google.com/site/ginodonig/gimp-scripts


Top
 Post subject: Re: How to extract comment line from script or plugins ?
PostPosted: Thu Dec 26, 2013 5:32 am  (#11) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4812
Gino D wrote:
PhotoComix wrote:
@GinoD

thank for all the details :yes :tyspin

Prego. :)

Regular expressions represent a very useful mean whose huge potential I discovered only quite recently.

As Odinbc rightly pointed out, Notepad++ is not the only text editor allowing you to work with them. Besides Kate, we could also mention other smart applications in this field, such as jEdit and Gedit, for instance, which both have the advantage of being multiplatform.

Take a look at this very detailed and well explained documentation on how to handle the regular expressions in Notepad++, while in my opinion it proves to provide valid guidelines on RegEX for other programs as well:
http://sourceforge.net/apps/mediawiki/n ... xpressions


Nowadays any decent programmer editor handles regexes(*). The Windows "Notepad" is closer to the Android app I use for my shopping list.

(*) But strangely, not all programmers... for many of them it still seems to be a black art. Even as a noob, you get instant guru status after reading the "Owl book".

_________________
Image


Top
 Post subject: Re: How to extract comment line from script or plugins ?
PostPosted: Thu Dec 26, 2013 5:54 am  (#12) 
Offline
Script Coder
User avatar

Joined: Nov 06, 2012
Posts: 239
Location: Italy
ofnuts wrote:
(*) But strangely, not all programmers... for many of them it still seems to be a black art. Even as a noob, you get instant guru status after reading the "Owl book".

I have to agree. As for me, learning how to use regular expressions has been very important and easier than I initially thought. In fact, I regret not having learned it much earlier.

_________________
Gino D's GIMP scripts: https://sites.google.com/site/ginodonig/gimp-scripts


Top
 Post subject: Re: How to extract comment line from script or plugins ?
PostPosted: Thu Dec 26, 2013 12:47 pm  (#13) 
Offline
GimpChat Member
User avatar

Joined: Nov 16, 2011
Posts: 5127
Location: Metro Vancouver, BC
Gino D wrote:
...As Odinbc rightly pointed out, Notepad++ is not the only text editor allowing you to work with them. Besides Kate, we could also mention other smart applications in this field, such as jEdit and Gedit, for instance, which both have the advantage of being multiplatform...
FYI, gedit needs Advanced Find / Replace plugin to use regular expressions. There is also gEdit RE Search.
I believe regex is native in the current beta.
Here's a handy chart of features for most text editors.

_________________
Image
Gimp 2.8.18, Linux, median user
Gimp Chat Tutorials Index
Spirit Bear (Kermode)


Top
Post new topic Reply to topic  [ 13 posts ] 

All times are UTC - 5 hours [ DST ]



* Login  



Powered by phpBB3 © phpBB Group