4

I wrote a new lexer for pygments and I try to use it. Thus I look at this page

http://pygments.org/docs/lexerdevelopment/

where the install procedure is described. They said to do make mapfiles but I don't know where.

I look into this two directories where there is the other.py module they talk about.

/usr/share/pyshared/pygments/lexers/

and

/usr/share/pyshared/pygments/lexers/

But there is not any makefiles in there. Thus how can I do ?

2 Answers 2

6

The blog post Custom syntax in pygments explains another way to add a custom lexer to pygments:


Pygments enables custom plugins via something called entrypoints in setuptools.

Directory structure:

|- FantomLexer
   |- fantomlexer
   |  |- __init__.py
   |  |- lexer.py
   |- setup.py

The __init__.py file can be empty but it needs to be there so its enough to simply touch it. The lexer.py will contain the regex lexer for pygments.

The contents of the setup.py goes as following:

from setuptools import setup, find_packages

setup (
  name='fantomlexer',
  packages=find_packages(),
  entry_points =
  """
  [pygments.lexers]
  fantomlexer = fantomlexer.lexer:FantomLexer
  """,
)

You can then install your lexer via sudo python setup.py develop.

Sign up to request clarification or add additional context in comments.

Comments

2

I found a solution which works. I guess you lexer is in the file mylex.py. I did the following under ubuntu 13.10. You need to have root permissions to do that.

  1. Copy your new lexer into /usr/share/pyshared/pygments/lexers/
  2. In the same directory run python _mapping.py
  3. Do a symbolic link of your lexer into /usr/lib/python2.7/dist-packages/pygments/lexers/. For example :

    cd /usr/lib/python2.7/dist-packages/pygments/lexers/

    ln -s /usr/share/pyshared/pygments/lexers/algobox.py .

1 Comment

This worked for me, though I copied the file directly to dist-packages instead of pyshared (which I can't find).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.