From d74eb78c70ac29667a7b06017a646e22d1caf6e4 Mon Sep 17 00:00:00 2001 From: László Németh Date: Mon, 9 Jul 2012 19:25:27 +0200 Subject: fix position of underlining + alt. separator for suggestions --- ChangeLog | 11 +++++++++++ Lightproof.py | 8 +++++--- doc/syntax.txt | 18 +++++++++--------- pythonpath/lightproof_impl___implname__.py | 15 +++++++-------- 4 files changed, 32 insertions(+), 20 deletions(-) diff --git a/ChangeLog b/ChangeLog index 12ab0cb..106d74c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2012-07-09 László Németh : + - fix positions of underlining of part of the matched pattern: + (foo) (bar) -2> baz # Did you mean? + - "|" as alternative separator of suggestions + foo -> bar|baz # Did you mean? + - print depends from PYUNO_DEBUG_LEVEL (fix for Windows) + - print() for future Python 3 support + +2012-05-27 Olivier Ronez : + - fix: suggestion with capital is based on selected back reference group + 2012-02-15 Olivier Ronez : - new: error positioning, underline a back reference group instead of the full pattern diff --git a/Lightproof.py b/Lightproof.py index a0c703f..71d8be4 100644 --- a/Lightproof.py +++ b/Lightproof.py @@ -2,7 +2,7 @@ # Lightproof grammar checker for LibreOffice and OpenOffice.org # 2009-2012 (c) László Németh (nemeth at numbertext org), license: MPL 1.1 / GPLv3+ / LGPLv3+ -import uno, unohelper, sys, traceback +import uno, unohelper, os, sys, traceback from lightproof_impl_${implname} import locales from lightproof_impl_${implname} import pkg import lightproof_impl_${implname} @@ -113,7 +113,8 @@ class Lightproof( unohelper.Base, XProofreader, XServiceInfo, XServiceName, XSer aRes.aText = "" return aRes except: - print traceback.format_exc() + if 'PYUNO_LOGLEVEL' in os.environ: + print(traceback.format_exc()) l = rText[nSuggestedSentenceEndPos:nSuggestedSentenceEndPos+1] while l == " ": @@ -130,7 +131,8 @@ class Lightproof( unohelper.Base, XProofreader, XServiceInfo, XServiceName, XSer if len(rProperties) > 0 and rProperties[0].Name == "Debug" and len(e.args) == 2: aRes.aText, aRes.nStartOfSentencePosition = e else: - print traceback.format_exc() + if 'PYUNO_LOGLEVEL' in os.environ: + print(traceback.format_exc()) return aRes def ignoreRule(self, rid, aLocale): diff --git a/doc/syntax.txt b/doc/syntax.txt index a0240b6..be280b8 100644 --- a/doc/syntax.txt +++ b/doc/syntax.txt @@ -72,9 +72,9 @@ use [?] or [.] patterns to check "?" and "." signs in the text. == Multiple suggestions == -Use \n (new line) in the replacement text to add multiple suggestions: +Use | or \n (new line) in the replacement text to add multiple suggestions: -foo -> Foo\nFOO\nBar\nBAR # Did you mean: +foo -> Foo|FOO|Bar|BAR # Did you mean: (Foo, FOO, Bar and BAR suggestions for the input word "foo") @@ -100,9 +100,9 @@ foobar -> _ # Message == Longer explanations == -Warning messages can contain optional URLs for longer explanations separated by "\n": +Warning messages can contain optional URLs for longer explanations separated by "|" or "\n": -(your|her|our|their)['’]s -> \1s # Possessive pronoun: \n http://en.wikipedia.org/wiki/Possessive_pronoun +(your|her|our|their)['’]s -> \1s # Possessive pronoun:|http://en.wikipedia.org/wiki/Possessive_pronoun == Back references in explanations == @@ -148,21 +148,21 @@ D \d{1,3} # 1, 2 or 3 digits # rules # ISO thousand marker: space, here: no-break space (U+00A0) -{d2}{d} -> {d2},{d}\n{d2} {d} # Use thousand marker (common or ISO). -{D}{d}{d} -> {D},{d},{d}\n{D} {d} {d} # Use thousand markers (common or ISO). +{d2}{d} -> {d2},{d}|{d2} {d} # Use thousand marker (common or ISO). +{D}{d}{d} -> {D},{d},{d}|{D} {d} {d} # Use thousand markers (common or ISO). Note: Lightproof uses named groups for name definitions and their references, adding a hidden number to the group names in the form of "_n". You can use these explicit names in the replacement: -{d2}{d} -> {d2_1},{d_1}\n{d2_1} {d_1} # Use thousand marker (common or ISO). -{D}{d}{d} -> {D_1},{d_1},{d_2}\n{D_1} {d_1} {d_2} # Use thousand markers (common or ISO). +{d2}{d} -> {d2_1},{d_1}|{d2_1} {d_1} # Use thousand marker (common or ISO). +{D}{d}{d} -> {D_1},{d_1},{d_2}|{D_1} {d_1} {d_2} # Use thousand markers (common or ISO). Note: back references of name definitions are zeroed after new line characters, see this and the following example: E ( |$) # name definition: space or end of sentence -"\b[.][.]{E}" -> .{E}\n…{E} # Period or ellipsis? +"\b[.][.]{E}" -> .{E}|…{E} # Period or ellipsis? See src/en/en.dat for more examples. diff --git a/pythonpath/lightproof_impl___implname__.py b/pythonpath/lightproof_impl___implname__.py index 1f6b376..8788863 100644 --- a/pythonpath/lightproof_impl___implname__.py +++ b/pythonpath/lightproof_impl___implname__.py @@ -156,26 +156,24 @@ def proofread( nDocId, TEXT, LOCALE, nStartOfSentencePos, nSuggestedSentenceEndP try: if not i[3] or eval(i[3]): aErr = uno.createUnoStruct( "com.sun.star.linguistic2.SingleProofreadingError" ) - aErr.nErrorStart = nStartOfSentencePos + m.start(0) # nStartOfSentencePos + aErr.nErrorStart = nStartOfSentencePos + m.start(i[4]) # nStartOfSentencePos aErr.nErrorLength = m.end(i[4]) - m.start(i[4]) - if i[4]: - aErr.nErrorStart += m.start(i[4]) aErr.nErrorType = PROOFREADING aErr.aRuleIdentifier = str(i[0]) iscap = (i[-1] and m.group(i[4])[0:1].isupper()) if i[1][0:1] == "=": - aErr.aSuggestions = tuple(cap(eval(i[1][1:]).split("\n"), iscap, LOCALE)) + aErr.aSuggestions = tuple(cap(eval(i[1][1:]).replace('|', "\n").split("\n"), iscap, LOCALE)) elif i[1] == "_": aErr.aSuggestions = () else: - aErr.aSuggestions = tuple(cap(m.expand(i[1]).split("\n"), iscap, LOCALE)) + aErr.aSuggestions = tuple(cap(m.expand(i[1]).replace('|', "\n").split("\n"), iscap, LOCALE)) comment = i[2] if comment[0:1] == "=": comment = eval(comment[1:]) else: comment = m.expand(comment) - aErr.aShortComment = comment.split("\\n")[0].strip() - aErr.aFullComment = comment.split("\\n")[-1].strip() + aErr.aShortComment = comment.replace('|', '\\n').split("\\n")[0].strip() + aErr.aFullComment = comment.replace('|', '\\n').split("\\n")[-1].strip() if "://" in aErr.aFullComment: p = PropertyValue() p.Name = "FullCommentURL" @@ -217,7 +215,8 @@ def compile_rules(dic): i += [False] i[0] = re.compile(i[0]) except: - print "Lightproof: bad regular expression: ", traceback.format_exc() + if 'PYUNO_LOGLEVEL' in os.environ: + print("Lightproof: bad regular expression: ", traceback.format_exc()) i[0] = None def get_rule(loc): -- cgit v1.2.3