Author Topic: Perl Comment Reflow, Visual SlickEdit 2010??  (Read 4078 times)

craig.martell

  • Community Member
  • Posts: 9
  • Hero Points: 1
Perl Comment Reflow, Visual SlickEdit 2010??
« on: May 07, 2011, 04:08:35 pm »
ALL:

I am new to Visual SlickEdit, but so far I really like it.  Particularly, I like the customizability.  I have a work habit that is mostly CUA but partially Emacs.  (This comes, I think, from going back and forth between Windows, Mac and Linux a lot.)  So, I love that I can bind the keys anyway I want.

I am, however, having some trouble with reflowing block comments in Perl.  Can you tell me if I am doing it correctly?

I enter some text:


Here are some lines that I
would like block comments around.
Here is another. And, here
is one more.


When I then do "Alt+C" for the Document menu, and "B" to comment block, I get the following as expected:

###################################
#Here are some lines that I       #
#would like block comments around.#
#Here is another. And, here       #
#is one more.                     #
###################################



But when I add text to the block, see the <insert text> and <and insert text>, I get:

###################################
#Here are some lines that I       #
#would like block comments around.#
#Here is another. And, here <insert text>      #
#is one more.      
#<and insert text>              #
###################################


I then go to Reflow Comment, and no matter what options I try, I don't get any changes.

Am I wrong in what Reflow Comment is supposed to do?  Is this just a Perl issue?  

Any help is appreciated.

Thanks,

Craig
« Last Edit: May 07, 2011, 04:21:40 pm by craig.martell »

Graeme

  • Senior Community Member
  • Posts: 1923
  • Hero Points: 221
Re: Perl Comment Reflow, Visual SlickEdit 2010??
« Reply #1 on: May 08, 2011, 12:49:16 am »
Unfortunately, comment wrap is available only for C, C++, C#, Java, and Slick-C®  - see comment wrap in the help.  This means that reflow won't work for perl.  From looking at the slick C code below, comment wrap works for more than what the help file says.  The help file could document this better and the reflow comment menu option should be grayed out for a non supported language, just as the comment wrap menu option is.  For C/C++, comment wrap is great.

It's probably not hard to write a slick C macro to reflow at least perl line comments.  You could even record a macro that swaps # for //, switch to C mode temporarily, invoke reflow, switch // back to #  (except it doesn't work, I just tried). 


Code: [Select]
boolean commentwrap_isSupportedLanguage2(_str lang = CW_p_LangId) {
   if (_LanguageInheritsFrom('c', lang) ||
       //_LanguageInheritsFrom('xml', lang) ||
       file_eq('xml', lang) ||
       file_eq('html', lang) ||
       ('phpscript' == lang) ||
       //file_eq('xsd', lang) ||
       //file_eq('xhtml', lang) ||
       _LanguageInheritsFrom('java', lang) ||
       _LanguageInheritsFrom('e', lang) ||
       _LanguageInheritsFrom('js', lang) ||
       //_LanguageInheritsFrom('fundamental', lang) ||
       _LanguageInheritsFrom('cs', lang)) {
      return (true);
   }
   return (false);
}


This didn't work.

Code: [Select]
   _macro('R',1);
   replace_buffer_text('#','I?M*','//','1','0','0','0','0','0');
   _SetEditorLanguage('c');
   deselect();
   _select_char('','E');
   cursor_down(2);
   select_it('CHAR','','E');
   _begin_select('',false,false);
   _deselect();
   cursor_up();
   cursor_down();
   execute('gui-reflow-comment');


Graeme

  • Senior Community Member
  • Posts: 1923
  • Hero Points: 221
Re: Perl Comment Reflow, Visual SlickEdit 2010??
« Reply #2 on: May 08, 2011, 01:03:42 am »
Oops, the record macro thing should work.  I just had the line width option set too wide to notice it working.  You probably need to use a regular expression to get the # // substitution working correctly.   Block comments could be a bit harder but could probably be done.

You could also have a macro that let you use dynamic comment wrapping by temporarily switching to C mode, replacing #.  Then another macro that switches back to perl mode and re-substitutes // #.  A bit messy though.

Graeme

craig.martell

  • Community Member
  • Posts: 9
  • Hero Points: 1
Re: Perl Comment Reflow, Visual SlickEdit 2010??
« Reply #3 on: May 08, 2011, 01:15:30 pm »
Oops, the record macro thing should work.  I just had the line width option set too wide to notice it working.  You probably need to use a regular expression to get the # // substitution working correctly.   Block comments could be a bit harder but could probably be done.

You could also have a macro that let you use dynamic comment wrapping by temporarily switching to C mode, replacing #.  Then another macro that switches back to perl mode and re-substitutes // #.  A bit messy though.

Graeme


Thanks Graeme,

As I learn more about Slick-C, I will give this a try.  I am very happy with most aspects of SlickEdit so far, but I definitely need both Perl and LaTex support  :).

Craig

craig.martell

  • Community Member
  • Posts: 9
  • Hero Points: 1
Re: Perl Comment Reflow, Visual SlickEdit 2010??
« Reply #4 on: May 10, 2011, 02:50:26 am »
My current plan is to write a macro that deletes all the comment symbols (#) from the block, and then calls block-comment as if it were a new block to comment.  I wonder if that would work.

Craig

Graeme

  • Senior Community Member
  • Posts: 1923
  • Hero Points: 221
Re: Perl Comment Reflow, Visual SlickEdit 2010??
« Reply #5 on: May 10, 2011, 12:35:48 pm »
My current plan is to write a macro that deletes all the comment symbols (#) from the block, and then calls block-comment as if it were a new block to comment.  I wonder if that would work.

Craig

Don't think so.  As you can see in your first post, slick will put # around your text but won't reflow any lines.  It currently has no ability to reflow lines in perl.

I've heard that perl is good at text processing.  Another way you could do it is to use filter_command and pass it the name of a perl script to execute.  Filter-command takes the current selection, makes it into a temporary file and passes it to the external command you specify.  The output of the command is then used to replace the selection.

See
http://community.slickedit.com/index.php?topic=5503.0
http://community.slickedit.com/index.php?topic=5091.0

Type fp filter_command on the slickedit command line and you'll get taken to the source code for filter_command in util.e.  You'll see it call
Code: [Select]
cmdline=cmdline:+' >'temp_out;
shell(cmdline,'QP');   
this runs the external command.  A few lines further down it calls get(temp_out) to get the result of the external command.  The command must take the input from stdin and output to stdout.
If filter_command doesn't do exactly what you want, you might be able to copy the entire function into a source file of your own and change it  - depending on whether it uses any static functions (or data) in util.e

It's not that hard to learn slick C though, if you're familiar with C like languages.  In the slick help "Slick C macro programming guide" section, have a look at the tutorials topic "reading and modifying buffers".  Also see the  "Slick C programming and best practices" doc.  Recording a macro and looking at the code generated is also useful.  Slick also comes with a full blown Slick C debugger but I just use say() to debug.

Graeme

ronw

  • Community Member
  • Posts: 36
  • Hero Points: 0
Re: Perl Comment Reflow, Visual SlickEdit 2010??
« Reply #6 on: May 10, 2011, 11:25:25 pm »
You could also have a macro that let you use dynamic comment wrapping by temporarily switching to C mode, replacing #.  Then another macro that switches back to perl mode and re-substitutes // #.  A bit messy though.

Actually, Perl has an interesting feature that would allow you to use C/C++ style comments in Perl. Near the top of your source file put:

use Filter::cpp;

All lines following that will then be preprocessed by the C preprocessor. Since, in C/C++, comments are handled by the preprocessor, this will allow you to use C/C++ comments.

Then just have to get SlickEdit into C mode.