Question about cursor position



  • Won’t be hard to figure out here, I guess I’d be considered a newbie. I’ve been using notepad++ for many years, but i never really dug in to get it set up the way i want.

    Using this to write some jQuery functions and I think there’s a way to do this but not sure.

    The smart editor adds end tags automatically right? so if I type a parenthesis open it automatically closes it. The problem is, it always puts the cursor between the two. more often than not I want the cursor to be after the closing tag. I know this might seem counter intuitive but for me it helps. For instance ‘function(’ would be ‘function()’ but my cursor would be between them. i want it to drop the closing tag before the cursor position

    Is there a way to configure this? I didn’t see it in the settings.



  • Hello John-Thompson,

    afaik it can’t be configured through settings. What I can propose is a python script solution,
    which means you need to install the python script plugin to make this work.
    What needs to be done would be

    • disable the autocompletion function from npp
    • write a script which listens for charadded event , do the completion and put the cursor behind the added char.

    Let me know if you want to go this way.

    Cheers
    Claudia



  • yes that makes sense. I would be happy to do that, unfortunately I know nothing about python. of course I could install the plugin

    just to explain a little more, I know this sounds counter intuitive, but my problem is I can’t seem to teach my brain to know I’m between them, so since I don’t always watch as I type I unconsciously hit the back arrow once when i open a tag. it’s a habit formed from a different editor I used to use that did just what I’m proposing



  • Hello John-Thompson,

    what needs to be done first is described here.

    The python script would be

    dict_complete_char = {'(':')','{':'}'}
    
    def callback_CHARADDED(args):
    
        if(args.has_key('ch')):
            if dict_complete_char.get(chr(args['ch'])):
                editor.addText(dict_complete_char.get(chr(args['ch'])))
         
        
    editor.clearCallbacks([SCINTILLANOTIFICATION.CHARADDED]);
    editor.callback(callback_CHARADDED, [SCINTILLANOTIFICATION.CHARADDED])
    

    As said, disable auto insert by unchecking everything from
    Settings->Preferences->Auto-Completion -> Auto-Insert section
    like here.

    Once you saved the script with a meanigful name, restart npp.

    Open a file and click Plugins->PythonScript->Scripts->NAME_OF_SCRIPT
    now if you type a ( it should automatically add the ) char and the cursor is behind the ) char.

    Current script supports ( and { chars if you want to add additional pairs you need to modify the line

    dict_complete_char = {'(':')','{':'}'}
    

    e.g. you want to have < auto closed as well then you add it like

    dict_complete_char = {'(':')','{':'}','<':'>'}
    

    and so on.

    If you are fine with it and you a tired of running the script everytime you start npp,
    we can modify the startup.py, which is part of the python script pluign installation, to start
    this script automatically.

    Cheers
    Claudia



  • Wow i didn’t expect you to write it for me, i figured I could research python a little. i installed the plugin after your reply so i’ll do this in the morning.

    Thank you SO much!



  • sorry for spoiling the party ;-)

    Cheers
    Claudia



  • Oh you didn’t spoil anything, you saved me a lot of time. lol i greatly appreciate it


Log in to reply