Is it possible to map multiple keys to notepad++ functions?



  • @Anthony-Blinco said in Is it possible to map multiple keys to notepad++ functions?:

    How do i associate colors with text?

    I normally let Notepad++ do this sort of coloring for me (it’s called lexing), so I actually don’t know the answer to this one. I suspect it might be more effort than you’d want to go to, for this simple application. Certainly doable, however.

    Are colors going to add a lot of value to it? A question you have to answer, for yourself.



  • A possibility not involving color might be to show the matching text in this fashion:

      File "t.py", line 10,     matches = []
                                ^^^^^^^
      File "t.py", line 11,     editor.search(sel_text, lambda m: matches.append(m.span(0)[0]))
                                                                  ^^^^^^^
      File "t.py", line 12,     if len(matches) > 0:
                                       ^^^^^^^
      File "t.py", line 14,         for pos in matches:
                                               ^^^^^^^
    


  • @Anthony-Blinco

    for example with something like this

    from Npp import console
    
    console.editor.styleSetFore(60, (128, 255, 128))
    console.editor.styleSetFore(61, (255, 128, 255))
    console.editor.setReadOnly(False)
    console.editor.addStyledText(Cell('Test\n', [60]))
    console.editor.addStyledText(Cell('Test\n', [61]))
    console.editor.addStyledText(Cell('Test\n', [60,61,60,61]))
    console.editor.setReadOnly(True)
    

    5b007e26-81f5-4827-b59a-b544865d3f9d-image.png



  • WOW! You guys are the best.
    I will persue those points today
    Thanks heaps!



  • Thanks for the coding tip. I will definitely implement it. Much more readable

    Thanks for the addStyledText() tip. I can get it to work for my purposes but it doesn’t seem to register for the click-and-goto-line functionality when i use it to print text.

    Another question related to this;
    Currently i use NppExec to compile my program, run my program and several other functions including launching the find dialog (using F8)
    The problem is It always asks me to cancel the current command before it executes the next one. This can be problematic when i, for example, run my program and then try to compile another program or even launch the find dialog.
    Is here a way to turn off this checking by NppExe or some way around this functionality?
    Thanks again for your awesome help



  • @Anthony-Blinco

    Sorry; you’ll have to wait for someone else to reply on NppExec.
    While the contributors to this thread are aware of NppExec, we may not know a lot about it because we’re better at PythonScripting (and thus don’t have much of a need for what NppExec offers).



  • @Anthony-Blinco said in Is it possible to map multiple keys to notepad++ functions?:

    The problem is It always asks me to cancel the current command before it executes the next one

    That means you’ve left some process open. Without seeing your NppExec script, we cannot tell you why it might still have the process open.

    The compile-and-run FAQ gives some examples of NppExec scripts that compile source code then run the resulting program, but don’t have a problem of leaving a process still running. You might want to compare your scripts to those.

    One trick, which is used in those examples, is to give the executable a new cmd window, instead of having it run directly inside the NppExec console – as called by npp_run cmd.exe /k "$(NAME_PART)", which spawns a new external process (npp_run), starts the command interpreter (cmd.exe) in a way that will leave it open after its argument finished (/k), and runs the compiled program in that new process ($(NAME_PART)) – npp_run is basically the NppExec-equivalent of the cmd.exe START command. (The same could also probably be accomplished in NppExec with cmd /c START "$(NAME_PART)".)

    You can also search the forum for @Michael-Vincent posts that contain “NppExec”, as he is a power-user of NppExec (or wait for him to show up, as he might have more advice than I have). And @Vitaliy-Dovgan, the author of NppExec, does come here on occasion



  • Perfect! Problem solved. Great advice once again.
    Thank you all so much. You guys really know your stuff!



  • Sorry for asking all the stupid questions.
    I tried the block comment/uncomment but it doesn’t work with my particular compiler.

    Can i change the comment/uncomment logic for my language (COBOL)?

    or

    It is a litle nuanced

    1. I need to save the character at column 7 (which is where the comment indicator is *). because it could be one of a couple of values and i would need to restore it when they uncomment
    2. I’m thinking i’m going to have to implement it in python. In which case i need to know how i can replace a line in the editing window

    Thanks again for all your awesome advice

    Also, i couldn’t find the editor.search() function in the python documentation. Am i looking at the right one
    http://npppythonscript.sourceforge.net/docs/latest/scintilla.html#helper-methods



  • @Anthony-Blinco

    Regarding: “comment…COBOL”: It’s probably best to start a new thread when you want to ask a totally unrelated question to what has come before in the current thread.

    Regarding editor.search() – which is proper for this thread since we’ve been discussing PythonScript – why not just move your caret to an instance of that in your text and invoke Context-Help from the PythonScript menu, right in Notepad++ ?

    Am i looking at the right one

    http://npppythonscript.sourceforge.net/docs/latest/scintilla.html#helper-methods

    I’d give that a “no”.



  • @Anthony-Blinco,

    @Alan-Kilborn said in Is it possible to map multiple keys to notepad++ functions?:

    Regarding editor.search() – which is proper for this thread since we’ve been discussing PythonScript – why not just move your caret to an instance of that in your text and invoke Context-Help from the PythonScript menu, right in Notepad++ ?

    Am i looking at the right one

    http://npppythonscript.sourceforge.net/docs/latest/scintilla.html#helper-methods

    I’d give that a “no”.

    Specifically, the old sourceforge copy of the documentation is severely out of date.

    When you install PythonScript, it also installs a local up to date version of the PythonScript documentation, which can be accessed through Notepad++ menu Plugins > PythonScript > Context-Help (and, as @Alan-Kilborn mentioned, if your caret is on the editor.search() command, it should open the help to the right place). Use that for all documentation needs on PythonScript. But yes, it is in the helper-methods section of the editor object documentation.


Log in to reply