summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2013-05-20 07:42:12 +0200
committerGeorg Brandl <georg@python.org>2013-05-20 07:42:12 +0200
commit529f6da8a1fa76baf4e0d7e8d332b5ead56b48de (patch)
tree38536537148dc45c43067b068ce21f8fa665e0f9
parentfcc0147c89efa90a992bf9a5b8560ef72eaba1eb (diff)
downloadpygments-529f6da8a1fa76baf4e0d7e8d332b5ead56b48de.tar.gz
Closes #863: improve analyse_text of Python and Numpy lexers
-rw-r--r--pygments/lexers/agile.py3
-rw-r--r--pygments/lexers/math.py5
2 files changed, 7 insertions, 1 deletions
diff --git a/pygments/lexers/agile.py b/pygments/lexers/agile.py
index 896a3deb..1f81365e 100644
--- a/pygments/lexers/agile.py
+++ b/pygments/lexers/agile.py
@@ -185,7 +185,8 @@ class PythonLexer(RegexLexer):
}
def analyse_text(text):
- return shebang_matches(text, r'pythonw?(2(\.\d)?)?')
+ return shebang_matches(text, r'pythonw?(2(\.\d)?)?') or \
+ 'import ' in text[:1000]
class Python3Lexer(RegexLexer):
diff --git a/pygments/lexers/math.py b/pygments/lexers/math.py
index a72a9124..f0e49fef 100644
--- a/pygments/lexers/math.py
+++ b/pygments/lexers/math.py
@@ -983,6 +983,11 @@ class NumPyLexer(PythonLexer):
else:
yield index, token, value
+ def analyse_text(text):
+ return (shebang_matches(text, r'pythonw?(2(\.\d)?)?') or
+ 'import ' in text[:1000]) \
+ and ('import numpy' in text or 'from numpy import' in text)
+
class RConsoleLexer(Lexer):
"""