Smart HighLighting for multiple view !



  • Hello,

    I search a way to display all variables on all view.

    Ex: http://fr.tinypic.com/r/e13ln5/9

    Thank you for your help



  • Hello Marvin Gerardin

    I have a python script which could almost do what you want.
    What needs to be done first is described here.

    def clearScintillaCallbacks():
        editor.clearCallbacks([SCINTILLANOTIFICATION.DOUBLECLICK, SCINTILLANOTIFICATION.INDICATORCLICK]) 
    
    clearScintillaCallbacks()
        
    def clearIndicators():
        text_end_position1 = editor1.getLength()
        text_end_position2 = editor2.getLength()
    
        editor1.setIndicatorCurrent(8)
        editor1.indicatorClearRange(0, text_end_position1)
    
        editor2.setIndicatorCurrent(8)
        editor2.indicatorClearRange(0, text_end_position2)
    
    def toggleview():
        # 0 = main_view
        # 1 = second_view
        current_doc_index_main_view = notepad.getCurrentDocIndex(0)
        current_doc_index_second_view = notepad.getCurrentDocIndex(1)
    
        if notepad.getCurrentView() == 0:
            notepad.activateIndex(1, current_doc_index_second_view)
        else:
            notepad.activateIndex(0, current_doc_index_main_view)
    
    def colorize():
    
        selected_text = editor.getSelText()
        
        clearIndicators()
    
        toggleview()
        
        matches = []
        editor.research('\\b{0}\\b'.format(selected_text), lambda m: matches.append(m.span(0)))
    
        for match in matches:
            editor.indicSetStyle(8,INDICATORSTYLE.ROUNDBOX)
            editor.indicSetFore(8,(117,217,117))
            editor.indicSetAlpha(8,255)
            editor.indicSetOutlineAlpha(8,255)
            editor.indicSetUnder(8,True)   
            editor.setIndicatorCurrent(8)
            editor.indicatorFillRange(match[0], match[1] - match[0])  
        
        toggleview()
        
    def sci_callback_DOUBLECLICK(args):
        if editor2:
            colorize()
        else:
            clearScintillaCallbacks()
    
    def sci_callback_INDICATORCLICK(args):
        clearIndicators()
        
    editor.callback(sci_callback_DOUBLECLICK, [SCINTILLANOTIFICATION.DOUBLECLICK]) 
    editor.callback(sci_callback_INDICATORCLICK, [SCINTILLANOTIFICATION.INDICATORCLICK])    
    

    I hope that code itself is self-explaining mostly therefore I only describe
    the critical parts and how it should be used.

    The script itself registers two callback functions,
    sci_callback_DOUBLECLICK and sci_callback_INDICATORCLICK.

    When you doubleclick on a text the function gets called
    and tries to find the selected word in the 2nd view. If it
    can be found it marks it. If you click (only one mouse click)
    on the marked text, highlighting disappears.
    If you click anywhere else only the highlighted text in this view
    loses its markings. If you close the second view and double click
    on a text then all callbacks will be cleared.

    So, after you created the script
    run it
    open both views and
    play with it by double clicking words.

    As already described, 2nd view needs to be active before
    you double click words or callbacks get cleared and you
    need to run the script again.

    One minor issue I discovered while testing.
    It happened to me that words which were already
    highlighted got cleaned again. Not sure why?
    But it looks like this only happens if you
    often double click in short time.

    If this is all greek to you let me know I try to clarify.

    Cheers
    Claudia



  • Thank you for your reply.

    This work with 2 identical file (WinMerge)
    http://i66.tinypic.com/xqgm85.png

    what I would like:
    http://i68.tinypic.com/2mma5nr.png



  • Hello Marvin-Gerardin

    at the beginning of your script put

    import re
    

    which means import the regular expression module.

    and change the line

    editor.research('\\b{0}\\b'.format(selected_text), lambda m: matches.append(m.span(0)))
    

    with

    editor.research('{0}'.format(selected_text), lambda m: matches.append(m.span(0)),re.IGNORECASE)
    

    which forces the research function to, well, ignore the case. And missing of \\b has the additional feature to ignore
    whether this is a whole word or just part of a word.

    Cheers
    Claudia



  • @Claudia-Frank said:

    which forces the research function to, well, ignore the case. And missing of \b has the additional feature to ignore
    whether this is a whole word or just part of a word.

    No work :/ http://i64.tinypic.com/169ruxg.png

    def clearScintillaCallbacks():
    editor.clearCallbacks([SCINTILLANOTIFICATION.DOUBLECLICK, SCINTILLANOTIFICATION.INDICATORCLICK])

    clearScintillaCallbacks()

    def clearIndicators():
    text_end_position1 = editor1.getLength()
    text_end_position2 = editor2.getLength()

    editor1.setIndicatorCurrent(8)
    editor1.indicatorClearRange(0, text_end_position1)
    
    editor2.setIndicatorCurrent(8)
    editor2.indicatorClearRange(0, text_end_position2)
    

    def toggleview():
    # 0 = main_view
    # 1 = second_view
    current_doc_index_main_view = notepad.getCurrentDocIndex(0)
    current_doc_index_second_view = notepad.getCurrentDocIndex(1)

    if notepad.getCurrentView() == 0:
        notepad.activateIndex(1, current_doc_index_second_view)
    else:
        notepad.activateIndex(0, current_doc_index_main_view)
    

    def colorize():

    selected_text = editor.getSelText()
    
    clearIndicators()
    
    toggleview()
    
    matches = []
    editor.research('{0}'.format(selected_text), lambda m: matches.append(m.span(0)),re.IGNORECASE)
    
    for match in matches:
        editor.indicSetStyle(8,INDICATORSTYLE.ROUNDBOX)
        editor.indicSetFore(8,(117,217,117))
        editor.indicSetAlpha(8,255)
        editor.indicSetOutlineAlpha(8,255)
        editor.indicSetUnder(8,True)
        editor.setIndicatorCurrent(8)
        editor.indicatorFillRange(match[0], match[1] - match[0])
    
    toggleview()
    

    def sci_callback_DOUBLECLICK(args):
    if editor2:
    colorize()
    else:
    clearScintillaCallbacks()

    def sci_callback_INDICATORCLICK(args):
    clearIndicators()

    editor.callback(sci_callback_DOUBLECLICK, [SCINTILLANOTIFICATION.DOUBLECLICK])
    editor.callback(sci_callback_INDICATORCLICK, [SCINTILLANOTIFICATION.INDICATORCLICK])



  • Hello,

    I don’t see the

    import re
    

    line, which would break the whole script.
    Could you open console (Plugins->Pytrhon Script->Show Console)
    and run the script again. Do you get any errors?

    Cheers
    Claudia



  • is my script:
    https://drive.google.com/file/d/0B884biTIbPZ-ekU3V2VqZGtKXzg/view?usp=sharing

    in :
    C:\Users*\AppData\Roaming\Notepad++\plugins\Config\PythonScript\scripts

    I do not understand what I have to do in the console :/

    I have a message:
    PluginsManager::runPluginCommand Exception
    Unknown exeception

    and this : http://i64.tinypic.com/4r2hqe.png



  • @Marvin-Gerardin
    sorry have to leave - will come back on this next year ;-)

    Cheers
    Claudia



  • So let’s summarize.
    The script worked before but not as expected
    because the original version matched only whole words
    and not if the searched word is part of another word.

    To change this I changed

    editor.research('\\b{0}\\b'.format(selected_text), lambda m: matches.append(m.span(0)))
    

    to

    editor.research('{0}'.format(selected_text), lambda m: matches.append(m.span(0)))
    

    then I thought maybe there can be also a difference in notation
    therefore I included regex module

    import re
    

    and added the ignorecase flag to the research function.

    editor.research('{0}'.format(selected_text), lambda m: matches.append(m.span(0)),re.IGNORECASE)
    

    Which broke not only your uploaded code, which by the way is working for me,
    but also the python script plugin??

    This is weird. There is nothing fancy here. re module is part of the standard python lib.

    OK, please comment the import re line

    # import re
    

    and change the editor.research … to

    editor.research('{0}'.format(selected_text), lambda m: matches.append(m.span(0)))
    

    and do another test.

    You do not need to do anything in the python script console, just open it, it serves as an
    error output window if something within the python code is wrong.
    For example if you add the re.IGNORECASE flag but you do not import re module first
    the error would be shown in the console window as soon as you double click on a word.

    Traceback (most recent call last):
      File "...\Notepad++\plugins\Config\PythonScript\scripts\Highlight.py", line 42, in sci_callback_DOUBLECLICK
        colorize()
      File "...\Notepad++\plugins\Config\PythonScript\scripts\Highlight.py", line 29, in colorize
        editor.research('{0}'.format(selected_text), lambda m: matches.append(m.span(0)),re.IGNORECASE)
    NameError: global name 're' is not defined
    

    May I ask you which OS, npp and python script plugin version you use?

    Cheers
    Claudia


Log in to reply