• Login
Community
  • Login

[plugin development] Correctly handling npp indentation

Scheduled Pinned Locked Moved Notepad++ & Plugin Development
auto-indendatiopluginindentation
4 Posts 2 Posters 5.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.
  • G
    greenzest
    last edited by Aug 12, 2015, 8:19 PM

    Hello community,

    The context :
    I’m currently creating a npp plugin to help my co-workers programming in “4GL progress”.
    I already have a pretty good UDL xml which color the synthax nicely and allow the use of smart indentation to be pretty efficient.

    The problem :
    The only problem is that i need to indent only for 1 line after the “THEN” keyword (think of it as a block of 1 line) and i can’t do that with the non-less awesome UDL2.0.

    My thoughts :
    I was thinking about handling the SCN_CHARADDED notification, check for new lines and set the current line (which is the new line) indentation to what i want.
    Expect it doesn’t work. It looks like npp correct the line indentation AFTER what im doing during the notification.
    Same goes for SCN_MODIFIED and checking for lines added.

    The question :
    Can you think of a solution to overwrite npp’s auto-indentation? Or do you know if i can Send_message something to npp to deactivate auto-indentation in npp?

    (Sorry for the double post, i posted in the wrong place and couldn’t delete the first topic…)
    ++

    1 Reply Last reply Reply Quote 1
    • D
      dail
      last edited by Aug 13, 2015, 1:06 AM

      I had to do something similar in one of my plugins. What I did was catch the SCN_CHARADDED and then waited for SCN_UPDATEUI to actually modify any text. See this section of my plugin.

      1 Reply Last reply Reply Quote 0
      • G
        greenzest
        last edited by Aug 13, 2015, 5:32 PM

        Wow thank you very much dail! I found a solution but yours is so much cleaner =)

        I adapted your solution in C#, ill post it here if it can help someone else

        In a static class:

        public static Action ActionAfterUpdateUi { get; set; }
        

        On SCN_CHARADDED, define your action :

        ActionAfterUpdateUi = () => {
          Npp.SetCurrentLineRelativeIndent(0);
        };
        

        On SCN_CHARADDED, define your action :

        ActionAfterUpdateUi = () => {
          Npp.SetCurrentLineRelativeIndent(0);
        };
        

        On SCN_UPDATEUI, execute the action :

        if (Plug.ActionAfterUpdateUi != null) {
            Plug.ActionAfterUpdateUi();
            Plug.ActionAfterUpdateUi = null;
        }
        

        Thanks again dail!

        1 Reply Last reply Reply Quote 0
        • D
          dail
          last edited by Aug 13, 2015, 6:47 PM

          Glad this worked for you. Also glad you took time to describe the problem in the original post. Most people post a sentence or two and expect others to know exactly what they want! :)

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