Skip to content
This repository was archived by the owner on Aug 20, 2023. It is now read-only.

Commit 57ac8b5

Browse files
committed
Add autoatic lexer guess
1 parent 4c72d0c commit 57ac8b5

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

codehighlighter/Addons.xcu

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@
1818
~ You should have received a copy of the GNU General Public License
1919
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
2020
-->
21-
22-
<oor:component-data oor:name="Addons" oor:package="org.openoffice.Office" xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema">
21+
<oor:component-data oor:name="Addons" oor:package="org.openoffice.Office"
22+
xmlns:oor="http://openoffice.org/2001/registry"
23+
xmlns:xs="http://www.w3.org/2001/XMLSchema">
2324
<node oor:name="AddonUI">
2425
<node oor:name="OfficeMenuBarMerging">
2526
<node oor:name="javahelps.codehighlighter" oor:op="replace">
@@ -46,7 +47,21 @@
4647
<value>Highlight Code</value>
4748
</prop>
4849
<node oor:name="Submenu">
49-
<node oor:name="lang_1" oor:op="replace">
50+
<node oor:name="lang_0" oor:op="replace">
51+
<prop oor:name="Context" oor:type="xs:string">
52+
<value>com.sun.star.text.TextDocument,com.sun.star.sdb.TextReportDesign,com.sun.star.text.WebDocument,com.sun.star.xforms.XMLFormDocument,com.sun.star.text.GlobalDocument,com.sun.star.sdb.FormDesign,com.sun.star.sheet.SpreadsheetDocument,com.sun.star.drawing.DrawingDocument,com.sun.star.presentation.PresentationDocument,com.sun.star.sdb.OfficeDatabaseDocument</value>
53+
</prop>
54+
<prop oor:name="Title" oor:type="xs:string">
55+
<value xml:lang="en">Automatic</value>
56+
</prop>
57+
<prop oor:name="URL" oor:type="xs:string">
58+
<value>vnd.sun.star.script:codehighlighter.oxt|python|highlight.py$highlight_automatic_default?language=Python&amp;location=user:uno_packages</value>
59+
</prop>
60+
<prop oor:name="Target" oor:type="xs:string">
61+
<value>_self</value>
62+
</prop>
63+
</node>
64+
<node oor:name="lang_1" oor:op="replace">
5065
<prop oor:name="Context" oor:type="xs:string">
5166
<value>com.sun.star.text.TextDocument,com.sun.star.sdb.TextReportDesign,com.sun.star.text.WebDocument,com.sun.star.xforms.XMLFormDocument,com.sun.star.text.GlobalDocument,com.sun.star.sdb.FormDesign,com.sun.star.sheet.SpreadsheetDocument,com.sun.star.drawing.DrawingDocument,com.sun.star.presentation.PresentationDocument,com.sun.star.sdb.OfficeDatabaseDocument</value>
5267
</prop>
@@ -5352,7 +5367,6 @@
53525367
<value>_self</value>
53535368
</prop>
53545369
</node>
5355-
53565370
</node>
53575371
</node>
53585372
</node>

codehighlighter/python/highlight.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,10 @@ def highlightSourceCode(lang, style):
5959

6060

6161
def highlight_code(code, cursor, lang, style):
62-
lexer = get_lexer_by_name(lang)
63-
# lexer = guess_lexer(code)
62+
if lang is None:
63+
lexer = guess_lexer(code)
64+
else:
65+
lexer = get_lexer_by_name(lang)
6466
style = styles.get_style_by_name(style)
6567
for tok_type, tok_value in lexer.get_tokens(code):
6668
cursor.goRight(len(tok_value), True) # selects the token's text
@@ -72,6 +74,8 @@ def highlight_code(code, cursor, lang, style):
7274
finally:
7375
cursor.goRight(0, False) # deselects the selected text
7476

77+
def highlight_automatic_default(*args):
78+
highlightSourceCode(None, 'default')
7579

7680
def highlight_abap_default(*args):
7781
highlightSourceCode('abap', 'default')

0 commit comments

Comments
 (0)