• Login
Community
  • Login

Question about cursor position

Scheduled Pinned Locked Moved General Discussion
7 Posts 2 Posters 5.2k 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.
  • J
    John Thompson
    last edited by John Thompson Jan 8, 2016, 11:48 PM Jan 8, 2016, 11:48 PM

    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.

    C 1 Reply Last reply Jan 9, 2016, 12:06 AM Reply Quote 0
    • C
      Claudia Frank @John Thompson
      last edited by Jan 9, 2016, 12:06 AM

      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

      1 Reply Last reply Reply Quote 0
      • J
        John Thompson
        last edited by John Thompson Jan 9, 2016, 12:12 AM Jan 9, 2016, 12:11 AM

        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

        C 1 Reply Last reply Jan 9, 2016, 12:41 AM Reply Quote 0
        • C
          Claudia Frank @John Thompson
          last edited by Jan 9, 2016, 12:41 AM

          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

          1 Reply Last reply Reply Quote 1
          • J
            John Thompson
            last edited by Jan 9, 2016, 1:22 AM

            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!

            C 1 Reply Last reply Jan 9, 2016, 1:45 AM Reply Quote 0
            • C
              Claudia Frank @John Thompson
              last edited by Jan 9, 2016, 1:45 AM

              sorry for spoiling the party ;-)

              Cheers
              Claudia

              1 Reply Last reply Reply Quote 0
              • J
                John Thompson
                last edited by Jan 9, 2016, 2:36 AM

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

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