Author Topic: How to have formated multi-line comments in C code  (Read 1324 times)

Offline SolarAxix

  • Newbie
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
How to have formated multi-line comments in C code
« on: November 13, 2014, 05:04:50 pm »
Being a new user to HippoEDIT, and having previously been using Notepad++ (Npp), I am trying to reproduce the same functionality in Npp when it handles multi-line comments in C code.

In Npp, when I start a line with /*, every subsequent line will start with " * " until there's a */. Since most of what I am doing right now are university assignments, I find that having a block of comments with * in front to be easier to spot on the printed assignment that I hand out. Is there an easy way to accomplish this multi-line comment in HippoEdit?

Here are a few an example:

/*
 * CS 3344
 * Assignment #4
 *
 * Name:
 * Student Number:
 *
 * Semaphore Exercise
 *
 * Program description....
 *
 */

/*
 * Sorting function using the bubble sort algorithm.
 *
 * Takes the starting index as a parameter.
 *
 */
« Last Edit: November 13, 2014, 05:08:12 pm by SolarAxix »

Offline alex

  • Developer
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2161
  • Karma: +37/-3
    • View Profile
    • HippoEDIT
Re: How to have formated multi-line comments in C code
« Reply #1 on: November 13, 2014, 07:10:55 pm »
Hi SolarAxix,

welcome on forum.

I got the point, and I am afraid this is not available.
There is a "Smart Comment" feature in HE (Tools->Options->Formatting->Smart Helpers) which help to continue line comments.
So for example, if you type two time line comment:
Code: [Select]
// abc
// dsfsdf

than third // you will get for free on Enter.

But this does not work for block comments. Notepad++ can have special treatment for /* comment to add * on new line (actually I was not able to reproduce this feature in NP++, on default installation, maybe it is some plugin?), but HE completely generic, and do not have any build in logic, that is not defined in schema. And there is no way to define such behavior in schema now.

Theoretically, it can be plugin, for C based languages, that can implement such proprietary logic (similar to Shortkeys plugin), but I am not sure. Will check if easy achievable, and will be happy if someone will help with implementation ;)

BR, Alex.
P.S: looks like plugin has problems with commenting feature. Will clarify till next build.



and currently I do not see easy way to achieve this.

Offline alex

  • Developer
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2161
  • Karma: +37/-3
    • View Profile
    • HippoEDIT
Re: How to have formated multi-line comments in C code
« Reply #2 on: November 17, 2014, 12:18:11 am »
Hi SolarAxix,

I have updated the Shortkey plugin with Smart Block Comment feature.
I hope that one will cover you needs. If need, you can modify it how you like in %HippoEDIT Install Dir%\plugins\shortkeys.hejs:

Code: Javascript
  1. function onNewLine(oView, nKey, bUp, bShift, bControl, bAlt) {
  2.         if (oView.Selection.IsEmpty) {
  3.                 var style_range = oView.Document.GetStyleFromPos(oView.Position);
  4.                 if (style_range.Style.ID == "comment") {
  5.                         var indent = "";
  6.                         if (oView.Position.Line) {
  7.                                 var line = oView.Document.GetLine(oView.Position.Line);
  8.                                 for (var i = 0; i < line.length && (line[i] == " " || line[i] == "\t"); i++) {
  9.                                         indent += line[i];
  10.                                 }
  11.                         }
  12.                         oView.Document.InsertText(oView.Position, oView.Document.LineBreak + indent + "* ", AddUndoActionType("Smart Block Comment"));
  13.                         return true;
  14.                 }
  15.         }
  16.         return false;
  17. }
  18.  
  19. var oNewLine = new ShortKey(onNewLine);
  20. Application.RegisterShortKey(0x0D, oNewLine, "cbased"); // VK_ENTER
  21.  

BR, Alex

 

Related Topics

  Subject / Started by Replies Last post
3 Replies
4687 Views
Last post September 15, 2010, 08:13:09 am
by kryten
1 Replies
1398 Views
Last post May 10, 2010, 01:32:40 pm
by alex
1 Replies
1906 Views
Last post October 21, 2010, 02:22:24 pm
by alex
2 Replies
1633 Views
Last post November 19, 2010, 03:53:45 pm
by scunliffe
2 Replies
1250 Views
Last post December 03, 2010, 04:57:59 pm
by jgodfrey