Left Gutter / Space at the begginning of a line / SCI code 2155



  • Years ago I discovered a scintilla message/code that added a left gutter/gap at the beginning of each line in np++.
    I’ve been using the following macro at np++ startup, but it stopped stopped working after v7.6.3.

    <Macro name=“leftGutter” Ctrl=“yes” Alt=“no” Shift=“yes” Key=“71”>
    <Action type=“0” message=“2155” wParam=“1” lParam=“12” sParam="" />
    </Macro>

    The reason for using this gap is related to positioning the cursor at the beginning of a line and selecting one or more characters from the beginning of a line using a mouse.
    By default in np++, there are less pixels to the left of the first character of a line than other characters that can be used for positioning the cursor and selecting text.

    20ffb4c3-2c04-4194-b3c0-9fccfb4f5131-image.png

    I found one discussion for reference.
    https://community.notepad-plus-plus.org/topic/20157/how-to-add-a-gap-between-letters-and-border-of-n-window?_=1619023497176&lang=en-US
    But it mentions adjusting the margin which behaves differently. I believe that left-clicking the margin selects the line text, whereas left-clicking the gutter positions the cursor at the beginning of the line.

    If anyone has any info on how to get this working on more recent versions, it would be appreciated.

    Thanks



  • To Clarify:
    b3df4d50-9d46-4fb7-9fe3-c09a22caed56-image.png



  • @Adam-West ,

    <Action type=“0” message=“2155” wParam=“1” lParam=“12” sParam="" />

    Hmm, I would have expected that to still work. Or maybe a slightly modified

    <Action type="0" message="2155" wParam="0" lParam="12" sParam="" />
    

    … because the SCI_SETMARGINLEFT doesn’t expect a wParam, and as the <macros> documentation says, “Use 0 if the message or command doesn’t require a wParam.”

    However, I just tried on v7.9.5, and it doesn’t. Notepad++ may have taken 2155 = SCI_SETMARGINLEFT out of its list of macro-recordable/macro-playable actions. I am not sure why it would have done so, because it meets the requirements that are generally applied for recording scintilla actions; but so it goes.

    That said, both NppExec and PythonScript can easily handle sending those messages, and can put their scripts into a menu that you can assign keyboard shortcuts to. The discussion you linked even shows how to put the editor.setMarginLeft(12) in startup.py to make it live all the time; if you want it user-decided, then you could just create a new script rather than using startup.py as shown. And NppExec can do it via sci_sendmsg 2155 0 12 . (PythonScript has the benefit that it can set both views (normal view and other view) in the same script; with NppExec, it will only affect the active view.)

    Sorry it doesn’t work in the builtin macros anymore.



  • @Adam-West

    Back in February 2019 the European Community started a bug bounty program called EU-FOSSA (short for Free and Open Source Software Auditing) to find critical security issues in widely used open source software. Notepad++ was one of the projects that have undergone an audit.

    As a reaction to one of the security issues found during this audit, >> at February, 21st 2019 there has been made a commit << to the Notepad++ code base to prevent the software from executing arbitrary Scintilla commands from the shortcuts.xml file in order to prevent hackers from being able to create harmful macros by changing this file. This afore mentioned commit introduced a white-list of Scintilla commands considered to be safe for execution from within a macro. Unfortunately the commmand SCI_SETMARGINLEFT (whose numeric representation is the number 2155 that you use in your macro) is not part of that list.

    Since the commit mentioned above has been made in between the release of Notepad++ v7.6.3 and v7.6.4, the last version where your macro should work is v7.6.3. But the whole v7.6.x branch of Notepad++ versions was experimental due to heavy changes in plugin loading and management (the v7.6.x branch made the old external Plugin Manager obsolete, new internal Plugins Admin has been introduced and lots of plugins had to be updated to meet the new requirements that arose from these changes). Thus it is NOT recommended to roll back to v7.6.3.

    The only way to get back the ability to run your macro in recent releases of Notepad++ is filing a feature request at the project’s GitHub repository. Please >> read this << to learn how to do that.



  • There will be a new setting in the next release of Notepad++, presumed to be 7.9.6 that probably helps with the OP’s need.


    Here’s an example of the existing way it is, and the new setting with Left Padding set to zero:

    f016a04a-c682-4f42-8f7c-e69a97bc671c-image.png


    Contrast that with a non-zero setting for it:

    ad96e9a4-c03e-4590-9169-0c28a0ffb25b-image.png


    And yes, it does help make mouse-selecting a column 1 character a bit easier (the only real practical use I see for it).



  • [OFF TOPIC]

    @PeterJones said in Left Gutter / Space at the begginning of a line / SCI code 2155:

    PythonScript has the benefit that it can set both views (normal view and other view) in the same script; with NppExec, it will only affect the active view.

    FYI: NppExec can send window messages to arbitrary windows, thus it can send messages to both Scintilla views. The tricky part is how to get the Scintilla window handles, see the following code:

    npp_sendmsg NPPM_GETCURRENTVIEW
    set local $(CurView) = $(MSG_RESULT)
    
    npp_sendmsg NPPM_ACTIVATEDOC 0 -1
    set local $(SCI1_HWND) = $(SCI_HWND)
    
    npp_sendmsg NPPM_ACTIVATEDOC 1 -1
    set local $(SCI2_HWND) = $(SCI_HWND)
    
    npp_sendmsg NPPM_ACTIVATEDOC $(CurView) -1
    

    After executing this code the original view is the active view again and you have two variables $(SCI1_HWND) and $(SCI2_HWND) containing the window handles of the two Scintilla views. Now you can use npp_sendmsgex to send messages to them:

    npp_sendmsgex $(SCI2_HWND) SCI_GETTEXTLENGTH
    echo Text length: $(MSG_RESULT)
    


  • @PeterJones
    @Alan-Kilborn
    @dinkumoil

    Thank you all for the very detailed information and explanation of why it doesn’t work anymore. I wasn’t expecting so much.
    np++ is the best editor I’ve used in my 20 years as a PeopleSoft developer. I look forward to the left-padding setting, but will give startup.py a shot for now.
    -Adam


Log in to reply