Community
    • Login

    Quote/apostrophe macros insert garbage text

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    2 Posts 2 Posters 1.8k 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.
    • FriendOfFredF
      FriendOfFred
      last edited by

      Hello all,

      I wanted a quick way to type curly quotation marks and apostrophes in Notepad++, so I created macros with Alt and Ctrl keyboard shortcuts that inserted these characters. To create the macros, I used Windows Alt+number pad shortcuts:

      ‘ Alt+0145 Ctrl+'
      ’ Alt+0146 Alt+'
      “ Alt+0147 Ctrl+Shift+'
      ” Alt+0148 Alt+Shift+'

      Sometimes, in conditions I still haven’t figured out how to reproduce, the macro inserts a string of characters after the desired character: [U+001]mVYȸ_[U+009][U+001]@HD[U+001]$N. U+001 is “Start of Heading” and U+009 is Tab. Only the second-to-last character in the string varies: it comes out as ", !, #, or $ depending on the character I tried to enter. When I enter the characters directly with Alt+numpad instead of using my Notepad++ shortcuts, the problem never occurs.

      All files involved were encoded in UTF-8 without BOM, which is also my default Notepad++ encoding.

      I also looked up the macro definition in my shortcuts.xml file, and didn’t find a clue there:

      <Macro name="Insert apostrophe" Ctrl="no" Alt="yes" Shift="no" Key="222">
              <Action type="1" message="2170" wParam="0" lParam="0" sParam="&#x2019;" />
          </Macro>
      

      Clearly I’m doing something wrong, but what?

      1 Reply Last reply Reply Quote 0
      • guy038G
        guy038
        last edited by

        Hi @FriendOfFred, and All,

        I, personally, add your macro, which works correctly, on my configuration ! But I admit that I didn’t do intensive tests to determine when something is going wrong !

        I’ve replied to a similar question, in the post, below :

        https://notepad-plus-plus.org/community/topic/15909/replace-text-between-2-characters/2

        So, here is a regex S/R, which will normalize the normal quotes to their enhanced version !

        SEARCH (?-s)["“](.+?)["”]|['‘](.+?)['’]

        REPLACE (?1“\1”:‘\2’)

        • Select the Regular expression search mode

        • Tick the Wrap around option

        • Click on the Replace All button

        Et voilà !

        So, given this initial text, below :

        "Test"    "Test”    “Test"    “Test”
        
        'Test'    'Test’    ‘Test'    ‘Test’
        

        You should get the following text :

        “Test”    “Test”    “Test”    “Test”
        
        ‘Test’    ‘Test’    ‘Test’    ‘Test’
        

        So, at any time, when you perform this S/R, you’re sure that, after replacement, you get the two syntaxes “Test” and ‘Test’, only !

        You could, even, record this S/R as a macro, if you prefer to !

        Cheers,

        guy038

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