Community
    • Login

    Microsoft "Quotes"

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    8 Posts 5 Posters 723 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.
    • James Burke 0J
      James Burke 0
      last edited by James Burke 0

      Occasionlly I find Microsoft quotes inside my Javascript, but it’s not always easy to spot them with the tiny fonts in use these days. I’m using NPP v7.8.6 on Win 7. How can I ban Microsoft quotes from appearing in Notepad++? NPP requires me to use Gmail or FB to post here, so I’m not sure I’ll be able to spot the replies. Please reply anyway and I’ll keep trying to login to catch any replies. Thanks!

      Alan KilbornA PeterJonesP 2 Replies Last reply Reply Quote 0
      • Alan KilbornA
        Alan Kilborn @James Burke 0
        last edited by

        @james-burke-0 said in Microsoft "Quotes":

        Microsoft quotes

        I guess a good place to start is to define what Microsoft quotes are.

        1 Reply Last reply Reply Quote 0
        • PeterJonesP
          PeterJones @James Burke 0
          last edited by

          @james-burke-0 ,

          I am going to assume by “Microsoft Quotes”, you mean “Smart Quotes”, like what show up in the forum when you type “quotes” in your text: “”, and ‘smart single quotes’ like here: ‘’

          If I have a file that has

          “Microsoft Quotes”
          “Microsoft Quotes”
          “Microsoft Quotes”
          “”
          ‘smart single quotes’
          ‘smart single quotes’
          ‘smart single quotes’
          ‘’
          
          • FIND = ([“”])?([‘’])?
          • REPLACE = (?1")(?2')
          • SEARCH MODE = Regular Expression
            and replace them all, I get
          "Microsoft Quotes"
          "Microsoft Quotes"
          "Microsoft Quotes"
          ""
          'smart single quotes'
          'smart single quotes'
          'smart single quotes'
          ''
          

          which is all normal quotes now instead of “smart quotes”.

          1 Reply Last reply Reply Quote 0
          • James Burke 0J
            James Burke 0
            last edited by

            Peter, thanks - that’s exactly the nuisance that appears from time to time. I’m wondering if NPP can block the MS (smart) quotes so I don’t have to dig them out from time to time either by hand or using the reg-ex method as per your example. I can’t find even a simple search method in NPP, nor an encoding choice that will do the job.

            PeterJonesP 1 Reply Last reply Reply Quote 0
            • PeterJonesP
              PeterJones @James Burke 0
              last edited by PeterJones

              @james-burke-0 said in Microsoft "Quotes":

              I’m wondering if NPP can block the MS (smart) quotes

              No. Notepad++ will assume every byte in a file is a character (or part of a character, for multibyte encodings like UTF-8), and will treat it as such. It is a text editor, and those quote characters are valid text, even if you don’t like them.

              1 Reply Last reply Reply Quote 0
              • Alan KilbornA
                Alan Kilborn
                last edited by

                @james-burke-0 said…

                Occasionlly I find Microsoft quotes inside my Javascript,

                Where are these special quotes coming from? I would guess they occur when you copy and paste data from other places.

                I’m wondering if NPP can block the MS (smart) quotes

                Well, not natively, meaning not with Notepad++ as it ships, but you can do a lot with scripting (via the use of a scripting plugin).

                But even with a scripting plugin, there isn’t really one “blanket” great way to do it.

                If it were me doing it for my own purpose, I would set it up one of two ways, both using the PythonScript plugin:

                • (Since I presume it is coming a paste,) I would change the paste operation such that the conversion happens before the data is pasted

                • I would set it up to do the conversion each time the file is saved

                Since maybe the “on save” portion is slightly more desirable, and slightly easier to implement, I’ll show that. If there’s interest in the first method, I could also demo that, but I won’t unless it is asked for.

                Let’s steal some existing code as a starting point. I found THIS THREAD which has THIS POSTING - Sep 25, 2018 3:45 PM in it, and I derived the new script’s functionality from that.

                I call this script QuotesConversionOnSave.py and here it is:

                # -*- coding: utf-8 -*-
                
                from Npp import *
                
                class QCOS(object):
                
                    def __init__(self):
                        notepad.callback(self.beforesave_notify, [NOTIFICATION.FILEBEFORESAVE])
                
                    def beforesave_notify(self, args):
                        view_and_index_tuple = (notepad.getCurrentView(), notepad.getCurrentDocIndex(notepad.getCurrentView()))
                        notepad.activateBufferID(args['bufferID'])
                        if notepad.getCurrentFilename().lower().endswith('.java'):
                            editor.rereplace('([“”])?([‘’])?', '(?1")' + "(?2')")
                        notepad.activateIndex(*view_and_index_tuple)
                
                if __name__ == '__main__':
                    try:
                        qcos
                    except NameError:
                        qcos = QCOS()
                
                

                How does the script function? Well, every time an unsaved document is saved, it will see if a file is a .java file, and if so, run Peter’s regular expression replacement on it first before saving. The other code is there in the event of a Save All to keep the tab active at the time of the save the active tab after the save completes – otherwise you could get a tab switch to a tab different from the one you were working in.

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

                  Hi, @james-burke-0, @peterjones, @alan-kilborn and All,

                  Peter, why don’t you use, simply, one of these regex S/R :

                  SEARCH ([“”])|[‘’]

                  REPLACE ?1":'

                  or

                  SEARCH [“”]|([‘’])

                  REPLACE ?1':"

                  Best Regards,

                  guy038

                  mathlete2M 1 Reply Last reply Reply Quote 1
                  • mathlete2M
                    mathlete2 @guy038
                    last edited by

                    @guy038 many thanks for this useful regex code!

                    For those who wish to put it into a Macro for more convenient usage, you can use the code block below as a template. Note that the default shortcut sequence is Ctrl+' on US standard keyboards.

                    <Macro name="Convert smart quotes to code quotes" Ctrl="yes" Alt="no" Shift="no" Key="222">
                    	<Action type="3" message="1700" wParam="0" lParam="0" sParam="" />
                    	<Action type="3" message="1601" wParam="0" lParam="0" sParam="([“”])|[‘’]" />
                    	<Action type="3" message="1625" wParam="0" lParam="2" sParam="" />
                    	<Action type="3" message="1602" wParam="0" lParam="0" sParam="?1&quot;:&apos;" />
                    	<Action type="3" message="1702" wParam="0" lParam="768" sParam="" />
                    	<Action type="3" message="1701" wParam="0" lParam="1609" sParam="" />
                    </Macro>
                    
                    1 Reply Last reply Reply Quote 1
                    • First post
                      Last post
                    The Community of users of the Notepad++ text editor.
                    Powered by NodeBB | Contributors