To be honest, I don't think that reading a file once and using its content in a list is slower than opening the substitution file always, if you tested this with more than one file. But a general question, all that you want to do is to find some text and replace it, correct? If so, why not using ... notepad.open(fileName.encode('utf-8')) for s in sl editor.replace(s[0],s[1]) notepad.save() notepad.close() There is no need for doing findText, saving position ... first. Another hint, you can define...
Well than you need to find out what encoding has been used, which, btw, cannot be done in a 100% save manner. Npp uses chardet to identify the encoding, chardet is also available as python module. If only utf8 with or without BOM is used, than you can use codecs module and do something like import codecs with codecs.open(u'FILENAME') as f: for l in f: if len(l) > 1: s = l.split() if s[0].startswith(codecs.BOM_UTF8): _s = s[0][len(codecs.BOM_UTF8):].decode('utf-8') else: _s = s[0] ... Cheers Clau...
Why not converting your file to UTF-8 (without the BOM). Cheers Claudia
yep, another possible way :-D
get/setProperty is normally used to get/set lexer specific properties like allow folding etc... Recently npp added fold.quotes.python property to allow doc comments to be folded, this wasn't possible before unless you would have set it with python script for example. But this gaves also the possibility to add any info/value you want to a document and it is only avaliable through the lifetime of that document. Once document closes everything is gone and you don't have to take care of it.(well, in...
Correct, setProperty is per document as globals() returns the current global scope which is used by every script you run as long as your in the same namespace. Scott, I think moon refers to my example where I used 42 in setProperty call.
You could use the global namespace or the editor.setProperty function to save data need on subsequent calls global namespace: counter = globals().get('counter', 1) t = globals().get('t', 'set') print '{} {}'.format(t, counter) counter += 1 or editor.setProperty('MY_VAR','42') print editor.getProperty('MY_VAR')
@Moon, After rereading my post I guess I was a bit unclear - yes, getTag(number) rerturns a submatch but there is no function to retrieve how many submatches were catched. Sorry for confusion.
An updated version (V2) is available here https://sourceforge.net/p/npppythonscript/discussion/1199074/thread/f59511a4/
Not quite sure if I understand your question correctly. getTag doesn't provide a functionality to retrieve "submatches" (results when using regex like (hello).(world) where hello would be the first and world the second "submatch". If you still want to use getTag, than you have to loop over it and as soon as you receive an empty string your done. In order to retrieve this, I would, for example, use a match object and lastindex property. Concerning the backward search, why not using current position...
Not quite sure if I understand your question correctly. getTag doesn't provide a functionality to retrieve "submatches" (results when using regex like (hello).(world) where hello would be the first and world the second "submatch". If you still want to use getTag, than you have to loop over it and as soon as you receive an empty string your done. In order to retrieve this, I would, for example, use a match object and lastindex property. Concerning the backward search, why not using current position...
David, I don't think that Cell can be used in such a case as the Cell class seems not to provide any functions which could convert the input and in addition scintilla documentation states, that setting the text must be prior to setting styles. Let's see what Dave thinks. My strategy is the following ERROR_MSG_ID = 20 WARNING_MSG = 21 INFO_MSG = 22 editor.styleSetFore(ERROR_MSG_ID,(255,0,0)) editor.styleSetBack(ERROR_MSG_ID,(0,0,0)) editor.styleSetFore(WARNING_MSG,(255,255,0)) editor.styleSetBack(WARNING_MSG,(0,0,0))...
I haven't used Cell class (to be honest wasn't even aware that it exists) but I use it like this editor.annotationClearAll() editor.annotationSetText(1,'hello\nworld') editor.annotationSetStyles(1, "\1\1\1\2\2\2\3\3\3\4\5") editor.annotationSetVisible(2) Hope this is helpful for you. Be aware that the document needs to get the focus to make it work. Cheers Claudia
I haven't used Cell class (to be honest wasn't even aware that it exists) but I use it like this editor.annotationClearAll() editor.annotationSetText(1,'hello\nworld') editor.annotationSetStyles(1, "\1\1\1\2\2\2\3\3\3\4\5") editor.annotationSetVisible(2) Hope this is helpful for you. Cheers Claudia
By using filePathSrc = u'D:\TEMP\a' you turn everything returned by os.walk into a unicode string but open function expects normal byte string. Use filePathSrc = 'D:\TEMP\a' instead. Cheers Claudia
This is not really python syntax ;-) import os os.chdir('Y:\dataFiles') list_of_files = [x for x in os.listdir('.') if x.endswith('.xml')] for file in list_of_files: notepad.open(file) editor.rereplace('replaceData', notepad.getCurrentFilename()) notepad.save() notepad.close() First you cahnge to the directory (as you already did) then you create a list of all files which end with .xml now iterate over that list and open it (otherwise you cannot use editor object) replace the data save and close...
How do you start the batch? From commandline or within notepad++? Did you consider running the batch using python script plugin? Or do you use nppexec to run the batch. In general, the notepad++ sprecific objects are only accessible within a running notepad++ instance. Cheers Claudia
How do you start the batch? From commandline or within notepad++? Did you consider running the batch using python script plugin? Or do you use nppexec to run the batch. Cheers Claudia
Nice job and thank you for sharing it. Cheers Claudia
so what is the solution Escaping. Python uses the backslash internally as well, so you need to do things like \\4,\\1... Cheers Claudia
so what is the solution Escaping. Python uses the backslash internally as well, so you need to do things like \\4,\\1... Cheers Claudia
so what is the solution Escaping. Python uses the backslash internally as well, so you need to do things like \4,\1... Cheers Claudia
Hi, this is my second version of the RegexTester. Bugfixes and new features. I hope...
editor.addText does only add the text without the end of line characters (carriage...
Just use an empty line and coloring should go away ;-) Cheers Claudia
So something like this would do it. If there is something unclear about the code...
and the result should be this? Written by somesoft 1.1.0 version v1.1.0 tags Name_tags...
and the result should be Written by somesoft 1.1.0 version v1.1.0 tags Name_tags...
Could you provide an example what you try to do? Especially the part with sorting...
Is the script run from Python Script folder as other one? What do you mean from folder?...
What is expected? The WHOLEDOC treats the ^ as start of doc and $ as end of document....
What is not working? Do you have any error in the console? Cheers Claudia
Afaik this is mostly bug fixing - especially when using console object together with...
Is it possible to override a key press? Somehow, you could hook npp message queue...
Providing the source code encoding # -- coding: utf-8 -- will solve this. Cheers...
Just to be sure, you responded to the original poster, didn't you? You are right,...
btw. there is a known issue that the backup functionality might jump in wile doing...
I assume you wanna replace the literals }, with },\n If so, the regex is incorrect...
Hi Dave, of course you are correct (and corrected) but I don't know why/how this...
Hello, script needs to use both npp views, 2nd is were you type the regular expression....
Hello, script needs to use both npp views, 2nd is were you type the regular expression....
Hello Thomas, you are correct, npp is using \1 notation internally where as boost...
Hello Thomas, you are correct, npp is using \1 notation internally where as boost...
Hello Thomas, you are correct, npp is using \1 notation internally where as boost...
Hello Thomas, you are correct, npp is using \1 notation internally where as boost...
Hallo André, deine Antworten, wie bereits von Dave gesagt, führen zur Verwirrung....
Hi Dave, thank you for your kind words. Supporting your plugin is the minimum I can...
Hallo André, ja, aber was macht die if Frage? Übersetzt: Wenn von der Datei die letzte...
Hallo André, guter Gedanke aber kann eine Datei .php UND .js extension haben? if...
Plugins->Python Script->Show Console Wenn du deinen Code mit meinem vergleichst,...
Hallo André, du hast die console nicht geöffnet, dort würde auf jeden Fall eine Fehler...
Hallo André, du hast die console nicht geöffnet, dort würde auf jeden Fall eine Fehler...
Hallo André, was gibt es für eine Fehlermeldung in der Console? Wenn Lösung 1, dann...
Hallo André, du kannst root überprüfen. Wenn Dateien in Broker und alle Subverzeichnisse...
Andre, bei einem konkreten Problem zu helfen ist eine Seite aber das was du wunscht...
No, but see my answer to your other question. Cheers Claudia
Oh, I see - no, I don't think that you can get these information within the filebeforeloaded...
Sorry, don't understand your question Cheers Claudia
I think it is only possible when using external modules like win32file. import win32file...
Hallo Andre, ja, das macht Sinn. Gruß Claudia
Hallo Andre, du meinst hier hast Du ohne BOM eingegeben notepad.runMenuCommand("Kodierung",...
Hallo Andre, schön das du es geschafft hast. Wegen dem UTF-8, dass ist nicht gut...
Hi Mirko, the easieast way to see if a menucommand or plugin command works is to...
Hi Mirko, the easieast way to see if a menucommand or plugin command works is to...
Hi Mirko, the easieast way to see if a menucommand or plugin command works is to...
Hallo André, dann vermute ich, das du einen Mix aus Tab und Spaces hast, das ist...
Hallo André, dann vermute ich, das du einen Mix aus Tab und Spaces hast, das ist...
Hallo André, welcher Fehler kommt? Öffne die python console (Plugins->PythonScript->Show...
Hallo Andre, ja, füge folgende Zeile vor dem notepad.save() ein editor.replace('iso-8859-1',...
Hallo Andre, in notepad 6.8.8 musse es heissen notepad.runMenuCommand("Encoding",...
Hallo Andre, in notepad 6.8.8 musse es heissen notepad.runMenuCommand("Encoding",...
Hello Andre, in notepad 6.8.8 musse es heissen notepad.runMenuCommand("Encoding",...
Hallo, ich hoffe mein Deutsch ist gut genug. Bei Python muss man auf Tabs oder Spaces...
From the scintilla docs The SCI_NULL does nothing and is the value assigned to keys...
What I do is making a main function out of the main part and using return instead....
May I ask you why you want to go this way? Why not using a pure python script, without...
Hi Dave, sorry for late answer but I didn't get a notifcation sent that someone had...
OK, solution seems to be setting indicator styles within for loop. Hmm, still not...
Hello, I try to use indicators but it doesn't work as expected. When running the...
Hello, I try to use indicators but it doesn't work as expected. When running the...
Hello, I try to use indicators but it doesn't work as expected. When running the...
Hi Philip, thank you and sorry for answering so late. I will give it a try and see...
Hi, I wonder if it is possible to have more than one renderer delegate per column...
Hi Bernhard, more or less. What about calling Select.All and iterating over SelectedObjects?...
Hello Philip, kinda, it looks like this is an XP problem only (or I did something...
Hi Frans, I did the test with your configuration and still get the RowState=Modified...
Hi Frans, I did the test with your configuration and still get the RowState=Modified...
Hi Frans, yes, I set the same properties. I even installed 4.5.1, which I wasn't...
Hi Frasse, to be honest, I don't see any problem. I used your code, edited the first...
Well, I'm not a C# expert but I assume you must define the initial size first. var...
Hi, this doesn't seem to be an ObjectListview problem. It looks like that your row...
Hi, I'm using ObjectListview 2.8.1.830 on Windows XP SP3 and Me.dataTreeListView.ExpandAll()...
OK - Problem found and solved. SQLite.Net defines INTEGER as INT64. As I'm developing...
Hello, as subject says it all, doesn't it? Is this expected behaviour? If not, it...
Hello, I do have a SQLite database and want to use a DataTreeListview to show the...
Hi Andrew, because you wrote that you start learning python I thought I may give...
Hi, npp currently uses scintilla version 3.3.4 whereas the requested function has...
Hi, Plugins->Python Script->Configuration and check Prefer installed python libraries...
Hi, if you want to provide the maxCount you need to provide flags, startPosition...
Depends what the plugin does but from my understanding about what you wrote you have...