• Login
Community
  • Login

Should $(CURRENT_LINE) be zero-based?

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
19 Posts 5 Posters 3.6k Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y
    Yaron
    last edited by Jun 8, 2018, 9:42 PM

    Is there a reason for $(CURRENT_LINE) to be zero-based?

    Create a file Test.vbs containing the line msgbox WScript.Arguments(0).
    Add <Command name="Test" Ctrl="no" Alt="no" Shift="no" Key="0">wscript.exe YourPath\Test.vbs $(CURRENT_LINE)</Command> to shortcuts.xml.
    Menu -> Run -> Test.

    If the caret is placed in line 6, $(CURRENT_LINE) returns 5.

    Thank you.

    1 Reply Last reply Reply Quote 1
    • P
      PeterJones
      last edited by PeterJones Jun 8, 2018, 10:07 PM Jun 8, 2018, 10:04 PM

      Probably because SCI_GETLINE say “lines start at 0” and SCI_GOTOLINE says “first line is 0”. Apparently, Scintilla made the decision to be computer-sciencey about their line numbering API.

      1 Reply Last reply Reply Quote 2
      • Y
        Yaron
        last edited by Jun 8, 2018, 10:18 PM

        Practically it’s not the expected behavior IMO.
        I want to open the current file and line in a different editor and get the wrong line.
        Using the Current Line argument in other editors you get the correct line.

        Thank you.

        1 Reply Last reply Reply Quote 1
        • P
          PeterJones
          last edited by Jun 8, 2018, 10:22 PM

          What’s this “other editor” heresy? ;-)

          (makes sense, really)

          1 Reply Last reply Reply Quote 1
          • Y
            Yaron
            last edited by Jun 8, 2018, 10:24 PM

            EditPad. :)

            1 Reply Last reply Reply Quote 0
            • S
              Scott Sumner
              last edited by Jun 9, 2018, 12:27 AM

              I have encountered this before and I fully agree with @Yaron . Having $(CURRENT_LINE) being zero-based pretty much destroys its usefulness for any purpose. :-(

              1 Reply Last reply Reply Quote 1
              • C
                Claudia Frank
                last edited by Jun 9, 2018, 2:19 AM

                Actually I think having $(CURRENT_LINE) not being 0-indexed doesn’t make sense.
                Value comes from scintilla and can be past to scintilla so why should npp add and
                substract a value to get the correct line if it just can pass the value.

                @Yaron - a possible solution might be to chose a language which uses
                0 based indexes - like … :-D you know it :-D

                Cheers
                Claudia

                S 1 Reply Last reply Jun 9, 2018, 2:35 AM Reply Quote 1
                • S
                  Scott Sumner @Claudia Frank
                  last edited by Jun 9, 2018, 2:35 AM

                  It is not an issue if one stays “within” Notepad++/Scintilla, but a typical use might be in interacting with other tools that you don’t control the source of (can’t edit/rebuild). These tools would typically expect a user line number (1-indexed) rather than the 0-indexed value provided by $(CURRENT_LINE).

                  @Yaron 's example would be perfect if he didn’t “control the source” of his Test.vbs. Clearly, he could adjust the number his vbs receives by increasing by one whatever comes in, by editing the code. Unfortunately, we don’t always have the luxury of having the code or being able to change/recompile it to make such an adjustment.

                  Think about an error parser for a compiler. The compiler outputs warnings/errors with a filename and a line number (and sometimes a column number too) to indicate where the problem occurred. I have never seen such a line(/column) number be zero-based; it’s always one-based because the output is intended first-and-foremost for the humans, whose first thought is to start counting from 1 not 0.

                  My 2c…maybe I need some change back…

                  1 Reply Last reply Reply Quote 2
                  • C
                    Claudia Frank
                    last edited by Jun 9, 2018, 2:50 AM

                    I see where this could become handy but I do also see where this would be problematic.
                    Like you said, how to distinguish between used internally and externally.
                    If you change it to get work with external programs which do assume 1based indexing
                    you open the door to complain for those who use it internally.
                    So in such cases I think keeping its native feature does make more sense.

                    Cheers
                    Claudia

                    S 1 Reply Last reply Jun 9, 2018, 10:39 AM Reply Quote 0
                    • Y
                      Yaron
                      last edited by Jun 9, 2018, 9:03 AM

                      a possible solution might be to chose a language which uses
                      0 based indexes

                      Test.vbs was just an example.

                      I’m actually using
                      <Command name="Open in EditPad..." Ctrl="no" Alt="no" Shift="no" Key="0">&quot;C:\Program Files\EditPad\EditPad.exe&quot; &quot;$(FULL_CURRENT_PATH)&quot; /l$(CURRENT_LINE)/c$(CURRENT_COLUMN)</Command>

                      how to distinguish between used internally and externally

                      If I understand it correctly, $(CURRENT_LINE) is meant for interacting with External Programs .
                      NPP uses getCurrentLineNumber() and adds +1 when necessary (e.g. setting Ln in the status bar).

                      So apparently

                      wsprintf(expandedStr, TEXT("%d"), lineNumber);
                      

                      in RunDlg.cpp should be changed to

                      wsprintf(expandedStr, TEXT("%d"), lineNumber + 1);
                      

                      Thank you.

                      1 Reply Last reply Reply Quote 1
                      • S
                        Scott Sumner @Claudia Frank
                        last edited by Jun 9, 2018, 10:39 AM

                        @Claudia-Frank said:

                        So in such cases I think keeping its native feature does make more sense

                        I wasn’t advocating for change (I’ll let @Yaron do that!)…just opining that the few times I remember considering using $(CURRENT_LINE) for something, I realized I couldn’t do it because of the offset-by-1 for what I needed at the time (can’t really remember what I was attempting…).

                        @Yaron : Ah…@PeterJones was right…Editpad…the heresy! :-D

                        @Yaron : There’s a $(CURRENT_COLUMN) variable supported in Notepad++??

                        1 Reply Last reply Reply Quote 1
                        • Y
                          Yaron
                          last edited by Jun 9, 2018, 12:36 PM

                          Ah…@PeterJones was right…Editpad…the heresy!

                          Actually, the heresy was merely mentioning “other editor”.
                          The explicit name was my reply to his question.

                          I solemnly swear that I am up to no good. :)

                          There’s a $(CURRENT_COLUMN) variable supported in Notepad++??

                          					if (internalVar == CURRENT_LINE || internalVar == CURRENT_COLUMN)
                          					{
                          						auto lineNumber = ::SendMessage(hWnd, RUNCOMMAND_USER + internalVar, 0, 0);
                          						wsprintf(expandedStr, TEXT("%d"), lineNumber + 1);	
                          					}
                          

                          And it’s also zero-based.
                          Adding +1 fixes both line and column.

                          1 Reply Last reply Reply Quote 1
                          • C
                            Claudia Frank
                            last edited by Jun 9, 2018, 12:37 PM

                            But that would mean, that, for example, we cannot use

                            SCI_SENDMSG 2227 $(CURRENT_LINE) $(CURRENT_LINE)
                            

                            in NppExec anymore and this is true for all other messages which uses CURRENT_LINE as being a parameter in the call.

                            Maybe I’m wrong but I still think it is correct as it is.

                            Cheers
                            Claudia

                            S 1 Reply Last reply Jun 9, 2018, 12:43 PM Reply Quote 1
                            • Y
                              Yaron
                              last edited by Jun 9, 2018, 12:43 PM

                              Claudia,

                              Can you use

                              SCI_SENDMSG 2227 $(CURRENT_LINE)-1
                              

                              ?
                              I think you can’t achieve that in the command line.

                              1 Reply Last reply Reply Quote 1
                              • S
                                Scott Sumner @Claudia Frank
                                last edited by Scott Sumner Jun 9, 2018, 12:44 PM Jun 9, 2018, 12:43 PM

                                @Claudia-Frank : Hmmm…have to look up 2227…what could take two parameters of current-line?..what magic is CF up to now?..hmmm…

                                All: Maybe the best solution is some new things being created, perhaps $(CURRENT_LINE1) and $(CURRENT_COLUMN1), or whatever names are most appropriate…

                                1 Reply Last reply Reply Quote 4
                                • C
                                  Claudia Frank
                                  last edited by Claudia Frank Jun 9, 2018, 12:52 PM Jun 9, 2018, 12:52 PM

                                  Yaron, of course we could manipulate the output but does this makes sense?
                                  I don’t know how many macros/scripts/or_whatever_it_is_called are out there
                                  and do use the variable in conjunction with another call expecting this variable
                                  as paramter -> all would have to be changed in this case

                                  Scott, it is hiding lines - just an example - nothing magic :-)
                                  But I would vote for having an additional variable which returns the “human expected” value.

                                  Cheers
                                  Claudia

                                  1 Reply Last reply Reply Quote 3
                                  • Y
                                    Yaron
                                    last edited by Jun 9, 2018, 12:58 PM

                                    Claudia,

                                    Good point.

                                    Scott,

                                    Good idea.

                                    Thank you both.

                                    1 Reply Last reply Reply Quote 2
                                    • Vitaliy DovganV
                                      Vitaliy Dovgan
                                      last edited by Vitaliy Dovgan Jun 10, 2018, 8:37 PM Jun 10, 2018, 8:37 PM

                                      NppExec can live with any version of $(CURRENT_LINE) :) E.g.:

                                      set local line ~ $(CURRENT_LINE) + 1 // in case of zero-based
                                      "C:\Program Files\EditPad\EditPad.exe" "$(FULL_CURRENT_PATH)" /l$(line)/c$(CURRENT_COLUMN)
                                      

                                      or

                                      set local line ~ $(CURRENT_LINE) - 1 // in case of one-based
                                      SCI_SENDMSG SCI_HIDELINES $(line) $(line)
                                      

                                      P.S. Remembering all the Scintilla messages’ numbers (such as SCI_HIDELINES = 2227) are kind of hardcore. My colleague once said he was learning all the main GUIDs present in Windows, but he was certainly joking :)
                                      The “NppExec” subfolder near to NppExec.dll contains header files which are read by NppExec at runtime to use string constants such as SCI_HIDELINES instead of numbers.

                                      1 Reply Last reply Reply Quote 2
                                      • Y
                                        Yaron
                                        last edited by Yaron Jun 10, 2018, 10:17 PM Jun 10, 2018, 10:16 PM

                                        @Vitaliy-Dovgan,

                                        Thank you for the info. I appreciate it.

                                        Remembering all the Scintilla messages’ numbers (such as SCI_HIDELINES = 2227) are kind of hardcore.

                                        Not for @Claudia-Frank. :)


                                        @guy038,

                                        Regards.

                                        1 Reply Last reply Reply Quote 0
                                        2 out of 19
                                        • First post
                                          2/19
                                          Last post
                                        The Community of users of the Notepad++ text editor.
                                        Powered by NodeBB | Contributors