Community
    • Login

    Adding Vertical Lines

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    pluginsbuttonscustomizationvertical edge
    12 Posts 7 Posters 6.7k 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.
    • PeterJonesP
      PeterJones
      last edited by

      @Charles-Bogel said in Adding Vertical Lines:

      Notepad++'s macro documentation is non-existent
      …
      What I’m asking from the community:

      A way to assemble any set of plugins to let me press a button, OR
      Some way for me to directly pass code into Scintilla, OR
      Some documentation for macros.

      For about 4-5 years, the Notepad++ documentation was frozen; however, with the new npp-user-manual.org, that has changed, and there is a team actively working on the new documentation. It’s actually back to a fairly reasonable stage, and most major features have a reasonable level of documentation, IMO.

      For macros, the overview, which explains how to record, save, and playback macros (which is the primary intended interface for the macro feature), is at https://npp-user-manual.org/docs/macros/ . Beyond that, the newer Configuration Files Details documentation has a section on the details of the shortcuts.xml and the <Macro> section at https://npp-user-manual.org/docs/config-files/#macros . Admittedly, there is no link between the main macro page and the appropriate Config Files Details section. (I have added documentation issue#60 to remind me to make that link when I have time in the next couple of days.)

      That section of the document has a lot on the difference between type=0, 1, 2, and 3. It also includes links to the appropriate sections of Notepad++ and Scintilla documentation and code for looking up the correct message numbers.

      Further documents: Extending Functionality WIth Plugins describes how to get started on writing a plugin yourself, and Plugin Communication describes the Notepad++ messaging system.

      If you ever find that the released documentation is missing something, look at the github for the documentation, which will have the most recent versions of the docs (sometimes including updates that haven’t been released to the official website yet). If what you’re looking for is not there, browse the open issues, and if someone else hasn’t already reported it, then open a new issue.

      Back to your problem:
      Looking at your macro, I agree that you are calling the Scintilla messages for SCI_SETEDGEMODE (2363) and SCI_MULTIEDGEADDLINE (2694). My first guess for your problem is that you’re passing lParam="0xAAAAAA", which might not be translated to a number between the XML and when the message gets sent. I tried implementing that macro, but with lParam=“11184810” (which is the decimal equivalent of 0xAAAAAA, but it still didn’t work.

      If PythonScript is missing a message that you want, you could always make a request at the PythonScript github issues. And since you have the full power of Python, you should be able to find the library where you can get direct access to the Win32 API’s SendMessage function in Python; with that, and the scintilla HWNDs – which you can either get from a PythonScript command (I don’t remember for sure if there’s a wrapper for those), or you can enumerate windows to find them – search EnumWindow in the forum for examples of that)

      For passing raw messages to and from Notepad++ and Scintilla, the easiest right now is using the NppExec plugin, which has npp_sendmsg and sci_sendmsg commands, and can handle return value (which the macro feature cannot). Like Macros, or PythonScript, NppExec commands can be bound to keystrokes and can be configured to go into menus that should be accessible from CustomizeToolbar.
      Unfortunately, even using

      sci_sendmsg 2363 3 0
      sci_sendmsg 2694 12 11184810
      

      I didn’t see any vertical line get added. I also tried the single vertical bar with

      sci_sendmsg 2361 40 0
      sci_sendmsg 2365 65535
      

      but that did nothing as well.

      Sorry, I cannot immediately solve your problem for you.

      Oh, re-reading, I see you had it almost working in LuaScript. Could you post that code? One of the LuaScript experts might even be able to tell you how to put it into a menu (because it would really surprise me if the menu-config features of NppExec and PythonScript were not re-created when LuaScript was made).

      PeterJonesP 1 Reply Last reply Reply Quote 3
      • Alan KilbornA
        Alan Kilborn
        last edited by

        From reading the OP’s posting, the problem seems to be in tying a toolbar button to running a LuaScript. I’m no expert, but it seems that any time CustomizeToolbar questions come up, the end result is that that plugin is “lacking”. Doesn’t tying a keycombo to the running of the LuaScript work just as well for this?

        1 Reply Last reply Reply Quote 3
        • dinkumoilD
          dinkumoil @Charles Bogel
          last edited by

          @Charles-Bogel

          I’m the author of the ExtSettings plugin. You can configure a set of vertical lines using my plugin. Then you need a scripting plugin (e.g. NppExec, LuaScript or PythonScript) to be able to send an event to the Scintilla component of the active view to toggle visibility of this set of lines.

          The following example is for the NppExec plugin:

          To turn on vertical lines: sci_sendmsg 2363 3
          To turn off vertical lines: sci_sendmsg 2363 1

          You can store the above commands to NppExec scripts. The plugin provides the ability to create menu entries for these scripts in the Macro menu. Via Shortcut Mapper you can configure keyboard shortcuts to execute them.

          1 Reply Last reply Reply Quote 4
          • Charles BogelC
            Charles Bogel
            last edited by

            PeterJones, thank you so much for the working documentation links about the macros! All the links I had seen before were broken, so I assumed the whole site was dead. Seriously, thank you for all the context, this is great. It’ll take me a bit to dig through but I may be able to get something working from that. I was considering writing my own darn plugin, but I was hoping that is overkill for this use case.

            Working LuaScript code:

            editor.EdgeMode = EDGE_MULTILINE
            for i=1,10 do
            	editor:MultiEdgeAddLine(i*8, 0xBBBBBB)
            end
            

            And then I just manually change the color to 0xFFFFFF and re-run it to clear the lines. The current reason I can’t use it as a one-button solution is that the menu options presented to me are either run code from the console (so I would need a macro method of putting arbitrary text in the console which I haven’t been able to determine) or run it from the current file (which requires a macro method of loading a specific file which I haven’t been able to get working with any sort of consistency).


            Dinkumoil, thank you for your ExtSettings Plugin! I was really excited when I found it, but then didn’t think about using other scripts to interface with it directly. I think your solution with the added hotkeys will work overall, I am implementing it now.


            This board is fantastic, thank you all for the high quality replies!

            dinkumoilD 1 Reply Last reply Reply Quote 3
            • dinkumoilD
              dinkumoil @Charles Bogel
              last edited by

              @Charles-Bogel

              the command sci_sendmsg 2363 1 activates the standard mode of Notepad++, one single line at an arbitrary column (configurable via Preferences dialog). If you want no lines at all change the command to sci_sendmsg 2363 0.

              1 Reply Last reply Reply Quote 3
              • Charles BogelC
                Charles Bogel
                last edited by

                For future people reading this thread, here’s a complete tutorial of how to add a set of vertical lines and turn it on/off with a click. I’m sure there’s a cleaner/better way, but at least anyone else trying to work with NASTRAN or other fixed-width files will have something to work with.

                To create the lines, you will need to:

                • Update to Notepad++ 7.8 or greater (you will likely have to update, it’s a relatively new feature)
                • Install some plugins to Notepad
                  • Plugins -> Plugins Admin
                  • Select Check Boxes next to Customize Toolbar, ExtSettings, and NPPExec
                  • Click Install
                  • Click Yes to restart Notepad++ and Yes to accept changes to machine.
                • Add vertical lines via ExtSettings
                  • Plugins -> ExtSettings -> Extended Settings
                  • In the bottom left, select a color
                    • Click on the black color box
                    • Put in 220 for Red, Green, and Blue (or whatever color you want your lines to be; this makes them a light grey)
                    • Click OK
                    • If you do not do this step you will not be able to create lines
                  • Enter 8 for column
                  • Click Add
                  • Enter 16 for column
                  • Click Add
                  • Continue for 24, 32, 40, 48, 56, 64, 72, 80.
                  • Click Close to save the ExtSettings
                  • You should now have your vertical lines!

                You can stop here if you want, but the lines will be on at all times until you delete them in the same menu as above. Let’s add the ability to turn them on and off:

                • Add the ability to turn on and off lines via NppExec
                  • Plugins -> NppExec -> Execute…
                  • Copy the following text into the box:
                sci_sendmsg 2363 3
                
                  • Click Save…
                  • Enter LinesOn in the prompt
                  • Click Save
                  • Delete all the contents in the Execute… box
                  • Copy the following text into the box (Yes, it’s different, don’t save the same thing):
                sci_sendmsg 2363 1
                
                  • Click Save…
                  • Enter LinesOff in the prompt
                  • Click Save
                  • Close the Execute… box
                  • Plugins -> NppExec -> Advanced Options…
                  • In the bottom left, under “Menu Item”, enter LinesOn
                  • In the “Associated Script” dropdown, select “LinesOn” script
                  • Click Add/Modify
                  • In the bottom left, under “Menu Item”, enter LinesOff
                  • In the “Associated Script” dropdown, select “LinesOff” script
                  • Click Add/Modify
                  • In the top left, check the box next to “Place to the Macros submenu”
                  • Click OK, OK
                  • Restart Notepad++
                    • This lets the new options you added in get selected as a menu item
                • Create Buttons to turn the lines on and off
                  • Plugins -> Customize Toolbar -> Custom Buttons
                  • Restart Notepad++
                    • This enables the new buttons. See the hammer icon in the far right of the toolbar? That wasn’t there before.
                  • Open the file “C:\Users\YOUR_NAME_HERE\AppData\Roaming\Notepad++\plugins\config\CustomizeToolbar.btn”
                  • Delete all the contents and replace it with the following 2 lines:
                Macro,LinesOn,,,
                Macro,LinesOff,,,
                
                  • Save the file
                  • Restart Notepad++ (Last time)
                  • Click your new LinesOn and LinesOff buttons! They are the hammer icons on the far right.
                  • When you click LinesOff, if you had already chosen a vertical line at some via the normal Notepad++ menu, it will still be visible.
                Michael VincentM dinkumoilD 2 Replies Last reply Reply Quote 6
                • Michael VincentM
                  Michael Vincent @Charles Bogel
                  last edited by

                  @Charles-Bogel said in Adding Vertical Lines:

                  For future people reading this thread, here’s a complete tutorial of how to […]

                  Absolutely awesome! ++ thanks for taking the time to share this tutorial.

                  Cheers.

                  1 Reply Last reply Reply Quote 2
                  • EkopalypseE
                    Ekopalypse
                    last edited by

                    Just for completeness, latest pythonscript version does support the
                    newest scintilla features.

                    c0e2b7b7-e25b-495a-9904-cb60c39fcd6c-image.png

                    1 Reply Last reply Reply Quote 3
                    • dinkumoilD
                      dinkumoil @Charles Bogel
                      last edited by dinkumoil

                      @Charles-Bogel

                      You can assign unique icons to your toolbar buttons as well. The icons have to be in a 8 bits per pixel, 256 colors palletized BMP format with a size of 16 x16 pixels.

                      You can create such files by opening the icon of your choice in *.ico, *.bmp or *.png format with MS Paint, included in every version of Windows. Save them to a new file and select 256 colors bitmap as output format. Save them to e.g. %AppData%\Notepad++\plugins\config\CustomToolbarIcons.

                      In the file %AppData%\Notepad++\plugins\config\CustomizeToolbar.btn change the lines you mentioned above to:

                      Macro,LinesOn,,,CustomToolbarIcons\LinesOn.bmp
                      Macro,LinesOff,,,CustomToolbarIcons\LinesOff.bmp
                      

                      For future readers on a non-english version of Notepad++: The part Macro,LinesOn and Macro,LinesOff describe the “path” through the main menu to the menu items you would have to click to execute the related function. The names of these items have to be localized, i.e. they have to be noted in the language of your user interface.

                      1 Reply Last reply Reply Quote 2
                      • PeterJonesP
                        PeterJones @PeterJones
                        last edited by

                        @PeterJones said in Adding Vertical Lines:

                        Unfortunately, even using

                        sci_sendmsg 2363 3 0
                        sci_sendmsg 2694 12 11184810
                        

                        I didn’t see any vertical line get added

                        I don’t know what I was doing wrong (or maybe the color wasn’t showing up right on my remote-monitor), but now when I run those, it does work as expected.

                        1 Reply Last reply Reply Quote 1
                        • ludamo 0L
                          ludamo 0
                          last edited by

                          I have just worked my way through this topic to add the vertical lines so I wanted to say thanks for the guidance and just to add that instead of 2 toolbar buttons (On & Off) you can have a toggle button if you use the following NPPExec script (or something like it):

                          NPP_CONSOLE ?
                          sci_sendmsg 2362
                          if $(MSG_RESULT) = 3 then
                           sci_sendmsg 2363 0
                          else
                           sci_sendmsg 2363 3
                          endif
                          
                          1 Reply Last reply Reply Quote 1
                          • First post
                            Last post
                          The Community of users of the Notepad++ text editor.
                          Powered by NodeBB | Contributors