elisp -> Python (was Re: [OT] Emacs, Eclipse, Leo (was Re: IDE

G. S. Hayes sjdevnull at yahoo.com
Thu Jul 22 15:12:38 EDT 2004


Paul Rubin <http://phr.cx@NOSPAM.invalid> wrote in message news:<7xn01sfqhs.fsf at ruckus.brouhaha.com>...
> François Pinard <pinard at iro.umontreal.ca> writes:
> > Pymacs is not Emacs Lisp, and Python in Vim is not Vimscript either,
> > tweaks are needed in both cases for accessing some of the underlying
> > scripting facilities.  Pymacs is rather elegant, Python in Vim is rather
> > clean.
>
> What are these editors?

Emacs and vi are the two most common editors for serious programmers
in the Unix/Linux world; vim is the standard vi implementation used on
most Linux distributions (and is widely available on other platforms,
including other Unixes as well as Windows, Macintosh, Amiga, Vax,
etc).  GNU Emacs is the standard emacs implementation used on most
Unix platforms that have any emacs implementation (and is widely
available on other platforms, probably all those listed above but
certainly Windows, Macintosh, and other Unixes).  Other common vi
implementations include nvi (used by BSD) and vile, other common emacs
implementations include XEmacs (formerly Lucid Emacs) and jed.

>  Are they written in Python?  How do they implement the editing buffer?  

Vim is implemented in C, and supports at least 4 scripting languages
for extensions (vim, python, perl, and tcl); most larger extensions
are written in Perl or Python, though some are in vim's built-in
script.

Emacs is a hybrid C/elisp implementation (elisp being Emacs' dialect
of LISP) and normally extensions are written in elisp.  Pymacs allows
writing extensions in python.

> How do they implement searching backwards for a regexp in the buffer?

At what level?  In vim, at the user or vimscript level:
?some_regex
At the python level, you can use:

import vim
current_buffer=vim.current.buffer

And then use the standard Python re to search current_buffer (a list
of lines) or otherwise edit current_buffer.  And you can treat
current_buffer basically as you would expect:

current_buffer[0]="New"                # Change first line to "New"
current_buffer[0:0]="New"              # insert new first line "New"
del current_buffer[9]                  # delete 10th line of buffer
current_buffer.append("Last")          # Append line "Last" to buffer

Inside of vim, ":help python" has more info on the Python interface.

Alternatively, you could execute a Vim command from the Python
interface:

import vim
vim.command("?some_regex\n")     #The search-backward command a user
would run



More information about the Python-list mailing list