Community
    • Login

    Using Mark (Markers) and Styles

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    34 Posts 6 Posters 20.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.
    • Sridhar RaghavanS
      Sridhar Raghavan
      last edited by

      Is there a simple How-To write-up for using Markers for the following:

      Search/Mark for different words and
      Mark the Results in different colors and
      (optionally) Color the Bookmark Bubbles in the Margin Area in the same respective colors?

      I have gone through this forum, and read various posts, but the basic question is not “answered clearly” (there are plenty of justifying tangential discussions about complexities and what things have to be aligned together etc.)

      I upgraded to the latest version today, and I was hoping to see relevant button/drops downs in the Search/Mark panel (that comes up when you do Control-F). But I do not see any when I select the Mark Tab.

      I was hoping to see a drop down for
      what Style to use? (one of Styles 1, 2…5)

      Side Note:
      I know and did configure colors for each style using
      Settings->Style Configurator.

      On the Search->Mark All-> …
      I do see each style showing different colors and
      so I know that is working correctly.

      Anyway Results are Marked with the Same “Red” color.

      This is such a powerful feature and I started needing such features as my programming context has exploded in complexity.

      Just in case you are wondering, I have been using Notepad++ for 20+ years. But this is the first time I am exploring the Styles… I assumed it was something to do with UI appearance, and not a User productivity function.

      Appreciate your help.

      regards Sri.

      Alan KilbornA PeterJonesP Michael VincentM 3 Replies Last reply Reply Quote 1
      • Alan KilbornA
        Alan Kilborn @Sridhar Raghavan
        last edited by

        @Sridhar-Raghavan said in Using Mark (Markers) and Styles:

        Mark the Results in different colors and

        (optionally) Color the Bookmark Bubbles in the Margin Area in the same respective colors?

        Sorry, neither of these things is currently available (currently = 8.0).

        1 Reply Last reply Reply Quote 0
        • Sridhar RaghavanS
          Sridhar Raghavan
          last edited by

          Thanks Alan for the quick response.
          Wish the reality was more encouraging.

          In the light of this, what is the intended Usage Design for Marker/Styles?

          Hope some power user can share their thoughts about it.

          br Sri.

          Alan KilbornA 1 Reply Last reply Reply Quote 1
          • Alan KilbornA
            Alan Kilborn @Sridhar Raghavan
            last edited by

            @Sridhar-Raghavan said in Using Mark (Markers) and Styles:

            what is the intended Usage Design for Marker/Styles?

            Quick and temporary marking of literal text in 5 different colors, usually via the right-click context menu items Style … token.

            1 Reply Last reply Reply Quote 0
            • PeterJonesP
              PeterJones @Sridhar Raghavan
              last edited by

              (I see there have been a few more back-and-forths since I started my reply, but I think it’s still relevant to the discussion.)

              @Sridhar-Raghavan ,

              Is there a simple How-To write-up for using Markers for the following:

              Have you checked the online documentation at npp-user-manual.org, which is linked from Notepad++'s ?-menu:
              6fb2f472-06b2-41ef-bffb-3d1d1f8775c0-image.png

              Because the “Searching” page has a section on how to use the “Mark” tab of the find/replace/mark dialog. And it has another section called “Highlighting” which details how to use the 5 numbered styles.

              Notice that they are controlled from different commands, and are not the same action, despite the similar names (I wish that the Search > Mark/Unmark All menu’s were called “highlight” rather than “Mark”, but we’ve got years of history, and they aren’t going to change that name at this point). But you should think of them as completely separate functions, which aren’t controlled from the same place or in the same manner. The Mark dialog is for a search/regex based marking of text (the Mark dialog), whereas the Mark All numbered-styles submenu is for manually highlighting a single selection (or all the smart-highlighting matches, if smart-highlighting is enabled). Put another way, the Mark All numbered styles are used to make the current smart-highlighting selection persist (stay highlighted) even when you move the cursor someplace else.

              (BTW: 20+ years with Notepad++ is quite the accomplishment. Notepad++ v1.0 was released in late 2003. I personally didn’t start using it until about 2010, probably with v5.7)

              1 Reply Last reply Reply Quote 0
              • Sridhar RaghavanS
                Sridhar Raghavan
                last edited by

                Peter

                I did check the online manual and also this forum. I also try to infer things by playing with the “feature” and declared that I was not getting anywhere. I am using just the “Mark” feature and “Styles” still remain elusive (I guess for reason Alan mentioned).

                Sorry was catching the Truth, or lack of it, in the expression.

                By 20+ years, I just meant as far as I can remember and matters!!
                I do not know when I switched to Note Pad++ , but even before 2000 I was using others with Note* as the prefix!!

                br Sri.

                1 Reply Last reply Reply Quote 1
                • Michael VincentM
                  Michael Vincent @Sridhar Raghavan
                  last edited by

                  @Sridhar-Raghavan said in Using Mark (Markers) and Styles:

                  Search/Mark for different words and
                  Mark the Results in different colors

                  Have a look at the the AnalysePlugin. I don’t think it does colors inline, but does in the search / results window of the plugin.

                  Depending on how complicated / dynamic your search / mark / coloring requirements are, you could do it with a UDL.

                  Cheers.

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

                    We could certainly also do some different colors from search hits via scripting – let me know if you want to go this far…or I may put together a demo anyway (or dig up and old reference to one).

                    1 Reply Last reply Reply Quote 0
                    • Sridhar RaghavanS
                      Sridhar Raghavan
                      last edited by Sridhar Raghavan

                      Michael / Alan

                      Simple and interesting XML/UDL code and usage.
                      It is an excellent “knowledge byte” and might come very handy for adapting and usage in various contexts. For now, I am totally new to Note Pad++ scripting and would love to get some more handwaves.

                      My coloring requirements are as stated above.
                      Given a Python file (just as an example):

                      Specify WORD1 for marking, and color COLOR1
                      Execute Search/mark
                      resulting WORD1 instances are marked in COLOR1
                      and Bookmark Bubbles are marked in COLOR1

                      do it again with WORD2 and COLOR2
                      do it again with WORD3 and COLOR3

                      Do not worry about “results overlap” cases. A simple rule that later results will prevail is fine. Three color choices would be adequate for the start. Bookmark Bubble coloring would be nice, but can be treated as optional add-on frill to get going.

                      Alan thanks for your kind offer - yes I would like to go further – explore the scripting idea with your “demo and directions”.

                      br Sri.

                      Alan KilbornA 1 Reply Last reply Reply Quote 1
                      • Alan KilbornA
                        Alan Kilborn @Sridhar Raghavan
                        last edited by

                        @Sridhar-Raghavan said in Using Mark (Markers) and Styles:

                        Specify WORD1 for marking, and color COLOR1
                        Execute Search/mark
                        resulting WORD1 instances are marked in COLOR1
                        do it again with WORD2 and COLOR2
                        do it again with WORD3 and COLOR3

                        So this is almost what “right-click” > Style all occurrences of token > Using 1st Style actually does.

                        The difference being that you have to have your caret on your “token” (i.e., word) of interest.

                        Can you confirm that you really want to be able to type in the word to find, instead of just being “on” that word with your caret (and wanting to highlight it and other occurrences of it).

                        I don’t mind putting the effort into the demo discussed, but it really sounds like the functionality you want may be present already.

                        and Bookmark Bubbles are marked in COLOR1

                        Can you explain what functionality you think this would give you?
                        I guess what I’m saying is that I can’t see much use for bookmarks of different color.
                        Visually it would make a difference, of course, but even with that, you already have that same color (for the matched text) in the line that would be bookmarked, so the bookmark color just seems an extra (redundant) visual effect.

                        1 Reply Last reply Reply Quote 1
                        • Sridhar RaghavanS
                          Sridhar Raghavan
                          last edited by

                          Alan

                          Sorry for the delay. I was off line.

                          Interesting and you are right.
                          Thanks for pointing out that the Style Token -> … is available on the Right Click Menu.
                          That is clearer for use, as the selected/Highlighted Token is what is being searched with the selected Style.
                          But if you do not know if/where the token is present you have to do that find first.
                          Yes the minimum functionality is present through this.
                          I can also leverage this for tracing more than one thread of token(s) through my code.

                          But how does one express the bookmark option?
                          The found lines are not bookmarked as of now.

                          For me, this is better than the other two options…

                          1. The other method Search ->Mark -> is not clear about what is being searched for.
                          2. The Search Panel (Control-F) is not clear about what Style is being used.

                          This also brings to the fore, the need for the colored bookmarks and… for doing next/prev on the selected color.

                          Regarding the demo, please consider it as a lesson on how one might do this via Scripting. I did read about scripting and since it is Pythonic, it feels like I will be in my comfort zone. (but Objects, Methods, Sequencing and other things will be the key).

                          br Sri.

                          Alan KilbornA 1 Reply Last reply Reply Quote 1
                          • Alan KilbornA
                            Alan Kilborn @Sridhar Raghavan
                            last edited by

                            @Sridhar-Raghavan said in Using Mark (Markers) and Styles:

                            if you do not know if/where the token is present you have to do that find first.

                            True.

                            But how does one express the bookmark option?

                            Bookmarking is not available using Style token styling; only via the Mark functionality.

                            For me, this is better than the other two options…

                            The other method Search ->Mark -> is not clear about what is being searched for.

                            The Search Panel (Control-F) is not clear about what Style is being used.

                            I’m not sure I understand this part.
                            “for me this is better” – what is better?

                            Search > Mark IS very clear about what is being searched for … it is in the Find what box

                            There is no styling with Ctrl+f searching. With the Ctrl+m (Mark) searching, there’s only one style used, the default red styling.

                            Regarding the demo, please consider it as a lesson on how one might do this via Scripting. I did read about scripting and since it is Pythonic, it feels like I will be in my comfort zone. (but Objects, Methods, Sequencing and other things will be the key).

                            Sure, I’ll continue with the demo – check back in a bit.

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

                              So here’s a very simple demo PythonScript that prompts you for a string to search for, then prompts you for a color/style, then does the desired hit styling:

                              # -*- coding: utf-8 -*-
                              from __future__ import print_function
                              
                              from Npp import editor, notepad
                              
                              # Notepad++'s style numbers:
                              #  25 = Style #1
                              #  24 = Style #2
                              #  23 = Style #3
                              #  22 = Style #4
                              #  21 = Style #5
                              
                              class T_21275(object):
                              
                                  def __init__(self):
                                      search_input = notepad.prompt('Enter search string:', '', '')
                                      if search_input == None or len(search_input) == 0: return
                                      matches = []
                                      editor.search(search_input, lambda m: matches.append(m.span(0)))
                                      if len(matches) > 0:
                                          color_input = notepad.prompt('Enter style color number (1-5):', '', '')
                                          try:
                                              color_input = int(color_input)
                                          except ValueError:
                                              return
                                          if 1 <= color_input <= 5:
                                              color_input -= 1
                                              for (match_start_pos, match_end_pos) in matches:
                                                  editor.setIndicatorCurrent(25 - color_input)
                                                  editor.indicatorFillRange(match_start_pos, match_end_pos - match_start_pos)
                              
                              if __name__ == '__main__': T_21275()
                              

                              There’s a nice PeterJones tutorial for obtaining the PythonScript plugin and getting your first script going, found HERE, if you need that.

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

                                And, while it is possible to do some manipulations with the bookmark symbol, if what you want to do extends beyond something visual, there’s going to be deficiencies.

                                But, still, I am unclear on what your intentions are for bookmarks that reflect a color.

                                But, for the sake of fun, here’s an example of making the bookmark look like Style #1:

                                be3c3693-27d1-4268-8148-664537bf931e-image.png

                                I should mention that the 24 is Notepad++'s internal number for a bookmark.

                                1 Reply Last reply Reply Quote 2
                                • Sridhar RaghavanS
                                  Sridhar Raghavan
                                  last edited by

                                  Alan

                                  Thanks for both your notes and the nice code.
                                  I will install, test/use it - could not get to it yet.
                                  Thanks also for the pointer to Peter Jones tutorial.
                                  I am planning to venture into this - as I think it will come handy for other situations.

                                  Sorry if some of the things are not clear.
                                  I was going to say something more about the alternate methods for doing searching, marking, bookmarking and previous/next navigation. But let me play with all the approaches, including your code, to get a better grip of the pros/cons.

                                  My main goal is to be able to pursue more than one thread of code analysis & tracking through a code File.

                                  Incidentally it dawned on me, that the ability to bookmark manually in different colors and doing prev/next through different colored set is the real underlying canonical problem. That capability will be more general and powerful - and will serve better during code analysis. I will be able to bookmark as needed - and this may not correlate much with search terms.

                                  Your last line about “bookmark symbols” caught my eye as well. Were you highlighting that bookmarks could vary in colors as well as shapes? Clearly the ability to do next/prev on a selected set is quite critical.

                                  br Sri.

                                  1 Reply Last reply Reply Quote 1
                                  • Sridhar RaghavanS
                                    Sridhar Raghavan
                                    last edited by

                                    Alan

                                    Just ran your code.
                                    It took only a few seconds to get going with it.

                                    Plugins->Python Scripts -> New -> Gave a Name to the file,
                                    copied and pasted your code,
                                    saved.

                                    The script showed up in Plugins->Python Scripts-> Scripts

                                    Works nicely creating different colored marked items.
                                    Thanks for the Nice Job creating this basic idiom for building further.

                                    br Sri.

                                    Alan KilbornA 1 Reply Last reply Reply Quote 2
                                    • Alan KilbornA
                                      Alan Kilborn @Sridhar Raghavan
                                      last edited by

                                      @Sridhar-Raghavan

                                      I’m still unsure why you even need the bookmarks.

                                      Say you use the script to mark multiple pieces of text with multiple different colors.

                                      Then you can use the Jump Down (or Jump Up) commands on the Search menu to navigate to any color you’d like:

                                      3be7fc72-d780-4b90-a365-bf019975492f-image.png

                                      Either one of these submenus contains the colors possible:

                                      08442ca6-3741-4fb2-b649-02b2df488573-image.png

                                      So for example, say you mark some text (with the script) in the 5th style, i.e. default of green color. Then you may find occurrences of your marked text from you current position to the end of your file by repeatedly pressing Ctrl+5.

                                      No need for bookmarks of any type, or am I still misunderstanding your desires?

                                      1 Reply Last reply Reply Quote 1
                                      • Sridhar RaghavanS
                                        Sridhar Raghavan
                                        last edited by

                                        Alan

                                        You are absolutely right. The ability to mark different colors and jump up/down gives all the functionality I needed. Bookmark is not needed for the stated purpose.

                                        I am happy to see that this exactly addresses the “canonical” problem I was referring to. I am sure there would be additional operations may be invoked on “Bookmarked” lines, that can be very useful.

                                        Side Note. Like Copy Bookmarked Lines, Remove Bookmarked Lines, Remove Un Marked Lines.

                                        br Sri.

                                        More…

                                        Here a few additional things I would like to do in the work activity context …

                                        a) Show Only Marked Areas. (and hide all Un-Marked Areas). Specific to a color.

                                        If a line has a marked text, then
                                        N lines above and
                                        M lines below will be
                                        considered as “Marked Areas”.
                                        (this will give a window surrounding the marked text).

                                        And the counterpart Unhide Marked Areas of Specific Color.

                                        Note: Current Mark Panel has a “Copy Marked Text” button, but it only copies the “marked text” and not the lines. So you get a redundant list of the same text many times (except one is using regex).

                                        b) Bookmarks can be inversed. Good to know and this is nice.

                                        Is there a function to hide bookmarked lines? (and of course unhide if it can be defined)

                                        I owe a deep and sincere thanks to you. This thread of discussion has been personally extremely valuable for understanding these features [which I had not been using], the main drive for this thread. I hope this also benefits others. Furthermore, it triggers a revisit of these related functions by developers, at some point, for expressive consistencies and completeness.

                                        I will certainly write a short note on things learned here and post it. A similar note by you might be far better given your solid overall understanding of individual functions and how they may be combined together.

                                        Alan KilbornA 3 Replies Last reply Reply Quote 2
                                        • Alan KilbornA
                                          Alan Kilborn @Sridhar Raghavan
                                          last edited by

                                          @Sridhar-Raghavan said in Using Mark (Markers) and Styles:

                                          I am sure there would be additional operations may be invoked on “Bookmarked” lines, that can be very useful.
                                          Side Note. Like Copy Bookmarked Lines, Remove Bookmarked Lines, Remove Un Marked Lines.

                                          You mean these kinds of commands? (note red dot is right-click point):

                                          2a2c2d16-a04d-4437-8f7d-a5e76a39d7c0-image.png

                                          1 Reply Last reply Reply Quote 0
                                          • Alan KilbornA
                                            Alan Kilborn @Sridhar Raghavan
                                            last edited by

                                            @Sridhar-Raghavan said in Using Mark (Markers) and Styles:

                                            Note: Current Mark Panel has a “Copy Marked Text” button, but it only copies the “marked text” and not the lines. So you get a redundant list of the same text many times (except one is using regex).

                                            Yes, it often goes unstated here when people talk about Copy Marked Text, but it really is only useful when dealing with text that was marked by a regular expression search.

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