Microsoft "Quotes"
-
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!
-
@james-burke-0 said in Microsoft "Quotes":
Microsoft quotes
I guess a good place to start is to define what Microsoft quotes are.
-
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”.
- FIND =
-
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.
-
@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.
-
@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. -
-
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