Community
    • Login

    UDL 2.0 in Notepad 7 release

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    20 Posts 5 Posters 10.0k 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.
    • Claudia FrankC
      Claudia Frank @Jose Manuel Vela García
      last edited by Claudia Frank

      @Jose-Manuel-Vela-García

      if you haven’t already installed the python script plugin, then please
      install it from here instead of using
      the plugin manager.

      The script looks like this

      WIN_EOL = 45001                                                                                    # command id edit->eol conversion->windows
      UNIX_EOL = 45002                                                                                   # command id edit->eol conversion->unix 
      MAC_EOL = 45003                                                                                    # command id edit->eol conversion->mac
      
      TEXT_INSERT = 1                                                                                    # editor constants
      TEXT_DELETE = 2                                                                                    # editor constants
      
      IS_ADA_FILE = False                                                                                # variable to identify ada file
      
      format_dict={FORMATTYPE.WIN:WIN_EOL, FORMATTYPE.UNIX:UNIX_EOL, FORMATTYPE.MAC:MAC_EOL,}            # map fromattype to command id
      buffer_dict={}                                                                                     # used to save original format or different source files
      
      def this_is_a_ada_file(_filename):                                                                 # if file ends with either .a or .ada it is
          return True if _filename.endswith(('.a', '.ada')) else False                                   # considered to be an ada file
      
      
      def callback_BUFFERACTIVATED(args):                                                                # gets called when new file is opened
          global IS_ADA_FILE                                                                             # or tab has been changed
          global ORIGINAL_FROMAT_TYPE                                                                    # 
          bufferid = args['bufferID']
          filename = notepad.getBufferFilename(bufferid)                                                 # get the filename from bufferid and
          if this_is_a_ada_file(filename):                                                               # check if it is an ada file if
              IS_ADA_FILE = True                                                                         #    yes, set file identifier and
              if buffer_dict.get(bufferid, None) is None:                                                #    if it hasn't already saved
                  buffer_dict[bufferid] = notepad.getFormatType()                                        #        save eol format of current doc
          else:                                                                                          # otherwise
              IS_ADA_FILE = False                                                                        #    set file identifier to false
      
      
      def callback_FILEBEFORESAVE(args):                                                                 # gets called before file gets saved
          if IS_ADA_FILE:                                                                                # if it is a ada file
              saved_format = buffer_dict.get(args['bufferID'],None)                                      #    try to get a saved format
              if saved_format is not None:                                                               #    if one was found
                  notepad.menuCommand(format_dict.get(saved_format))                                     #        set the original format
      
      
      def callback_MODIFIED(args):                                                                       # gets called whenever something changes (text, style...)
          if IS_ADA_FILE and (notepad.getFormatType() != FORMATTYPE.WIN):                                # if it is an ada file and eol is not windows then
              mod_type = args['modificationType']                                                        #    get type of modification
              if (mod_type & TEXT_INSERT or mod_type & TEXT_DELETE) and args['text'] != '\r':            #    if it is an insert but not a \r or a delete then
                  notepad.menuCommand(WIN_EOL)                                                           #        set the windows eol else ignore it
      
      
      editor.clearCallbacks()                                                                            # sanity check - just to be sure no callback have 
      notepad.clearCallbacks()                                                                           # registered yet
      
      notepad.callback(callback_FILEBEFORESAVE, [NOTIFICATION.FILEBEFORESAVE])                           # register before save callback
      notepad.callback(callback_BUFFERACTIVATED, [NOTIFICATION.BUFFERACTIVATED ])                        # register buffer activated callback 
      editor.callback(callback_MODIFIED,[SCINTILLANOTIFICATION.MODIFIED])                                # register modify callback 
      

      I hope the comments are clear, basically, every time you open a new file or you switch
      a tab it get’s checkd if the file is an ada file by checking it extensions (see code).
      If it is and you start modifying the code it checks if windows eol is used and if not
      script sets it. If you save the file, it gets checked what the original eol was and then it
      resets the eol.

      If you create a new script with name startup.py and put the content into it
      and you change the python script configuration from LAZY to ATSTARTUP, then
      the script gets automatically executed every time you start npp.

      If you create a new script with a different name, you need to execute it manually once
      every time you start npp.

      Let me know if something is unclear.

      Cheers
      Claudia

      1 Reply Last reply Reply Quote 0
      • Claudia FrankC
        Claudia Frank @PeterJones
        last edited by

        @PeterJones

        Peter, now I know why it worked because type and subtype is also configured
        as keywords. So my workaround seems to be non-working, just another
        coloring rule is active.

        Cheers
        Claudia

        1 Reply Last reply Reply Quote 1
        • Jose Manuel Vela GarcíaJ
          Jose Manuel Vela García
          last edited by

          I have added today the python script and seems that is not solving the problem :(

          I have upload a video example of the real problem… the bug u can see in the video is totally random… in any sentence suddenly tha open/close folding mark just is in a wrong place… and just creating new lines it auto fix it… and when you remove those new lines again the mark keeps in the correct place… so strange…

          Video url --> https://youtu.be/xZZxKMRjU0w

          Many thanks !!!

          Claudia FrankC 1 Reply Last reply Reply Quote 0
          • Claudia FrankC
            Claudia Frank @Jose Manuel Vela García
            last edited by

            @Jose-Manuel-Vela-García

            the script itself doesn’t do any folding operations it just modifies the eols.
            So the bug seems not to be solved by using windows eol therefore
            the script isn’t helping either.

            Unfortunately there is no way python script can interact with lexers in
            a safely manner.

            Cheers
            Claudia

            1 Reply Last reply Reply Quote 0
            • Jose Manuel Vela GarcíaJ
              Jose Manuel Vela García
              last edited by

              So is there any news about “udl 2.0” or anyway to fix this ??

              1 Reply Last reply Reply Quote 0
              • chcgC
                chcg
                last edited by

                See https://ivan-radic.github.io/udl-documentation/ for the current docu and https://github.com/notepad-plus-plus/notepad-plus-plus/issues/2713 regarding status of UDL 3

                1 Reply Last reply Reply Quote 0
                • Jose Manuel Vela GarcíaJ
                  Jose Manuel Vela García
                  last edited by

                  About UDL3 status is there any ETA ?? Will be any UDL3 Beta ?

                  Many Thanks for the doc and info !!

                  1 Reply Last reply Reply Quote 0
                  • chcgC
                    chcg
                    last edited by

                    No status as far as I know and no timeschedule. Maybe in your case it makes sense to checkout https://sourceforge.net/p/scintilla/code/ci/fba1e8c31818fc1b38fc1b1ba3a200f40ef568f9/log/?path=/lexers/LexAda.cxx and checkout for an update there as scintilla is the basis for n++, but the update cycle of scintilla for n++ is quite slow.

                    1 Reply Last reply Reply Quote 0
                    • Jose Manuel Vela GarcíaJ
                      Jose Manuel Vela García
                      last edited by

                      There are no code folding / function list support at all in scintilla or notepad++ that’s why I am trying to do it by myself using the “user custom lang definition” and udl but udl is useless with ADA :(.

                      Would be nice if udl3 fix this kind of problems… But I am not sure after these years if udl3 will be realease any day…

                      Thanks for the info.

                      1 Reply Last reply Reply Quote 0
                      • Kerem İspirliK
                        Kerem İspirli
                        last edited by

                        ADA is not the only reason for UDL3. Generally UDL’s generally don’t work well with different themes and UDL3 is said to help with that, too: https://sourceforge.net/p/notepad-plus/discussion/331754/thread/bd2bc405/#757b

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