Permalink
Browse files

Use package instead of __package__, because of PEP366.

Use version instead of __version__, for symmetry.
More pymacs.py to Pymacs.py adjustments, in contrib/ and elsewhere.
  • Loading branch information...
1 parent ff26250 commit e3f67f9473aa5b31e9381bacf686b0b52b5052ee @pinard committed Jan 29, 2012
View
@@ -31,8 +31,8 @@ See the Pymacs documentation (check `README') for more information.
# Identification of version.
-__package__ = 'Pymacs'
-__version__ = '@VERSION@'
+package = 'Pymacs'
+version = '@VERSION@'
if PYTHON3:
import collections, os, sys
@@ -124,7 +124,7 @@ Arguments are added to the search path for Python modules.
sys.stdout = os.fdopen(sys.stdout.fileno(), 'wb')
# Start protocol and services.
- lisp._protocol.send('version', '"@VERSION@"')
+ lisp._protocol.send('version', '"%s"' % version)
lisp._protocol.loop()
def generic_handler(self, number, frame):
@@ -23,9 +23,9 @@ Interface between Emacs Lisp and Python - Module initialisation.
A few symbols are moved in here so they appear to be defined at this level.
"""
-from pymacs import Let, lisp
+from Pymacs import Let, lisp
# Identification of version.
-__package__ = 'Pymacs'
-__version__ = '@VERSION@'
+package = 'Pymacs'
+version = '@VERSION@'
@@ -50,7 +50,7 @@ def get_module_name_if_python_file_handle():
if fname==None:
return None
# check it:
- if fname[-3:] == '.py' and (fname.endswith("pymacs.py")==False):
+ if fname[-3:] == '.py' and not fname.endswith("Pymacs.py")):
# Ok, we have got something to do:
# replace last / with a point and try it down:
i=fname.rfind("/")
View
@@ -14,13 +14,11 @@
__license__= "GPL"
import re
-from Pymacs import pymacs
+from Pymacs import lisp
-# emacs is the global which handles lisp-based interaction with the active
+# lisp is the global which handles lisp-based interaction with the active
# Emacs buffer from which any function is called
-emacs = pymacs.lisp
-
# interactions is a global dict which MUST be updated for each new function
# defined which we want to be visible to Emacs. Each function must have an
# entry in it with the function as key (the function *object*, NOT its name as
@@ -60,7 +58,7 @@ def clean_undo_after(checkpoint):
"""\
Remove all intermediate boundaries from the Undo list since CHECKPOINT.
"""
- emacs("""
+ lisp("""
(let ((undo-list %s))
(if (not (eq buffer-undo-list undo-list))
(let ((cursor buffer-undo-list))
@@ -114,15 +112,15 @@ def cut_region(mode='string'):
as a string or as a list of lines (mode='list').
It is the caller's responsibility to insert the updated text at the
- end back in the Emacs buffer with a call to emacs.insert(...)."""
+ end back in the Emacs buffer with a call to lisp.insert(...)."""
- start, end = emacs.point(), emacs.mark(emacs.t)
+ start, end = lisp.point(), lisp.mark(lisp.t)
# BUG: buffer_substring() can't extract regions with dos line endings (\r\n)
# It dumps a traceback.
- region = emacs.buffer_substring(start, end)
+ region = lisp.buffer_substring(start, end)
if mode == 'list':
region = region.splitlines()
- emacs.delete_region(start, end)
+ lisp.delete_region(start, end)
return region
# cut_region() doesn't need an entry in interactions[] b/c it's meant to
# be used internally by other functions in this module, not directly
@@ -135,10 +133,10 @@ def insert_text(text,offset=0):
If called with no offset, leaves the cursor at the current position."""
# save undo state so we can roll everything into a single operation for undo
- checkpoint = emacs.buffer_undo_list.value()
- user_pos = emacs.point()
- emacs.insert(text)
- emacs.goto_char(user_pos+offset)
+ checkpoint = lisp.buffer_undo_list.value()
+ user_pos = lisp.point()
+ lisp.insert(text)
+ lisp.goto_char(user_pos+offset)
# Collapse all operations into a single one, for Undo.
clean_undo_after(checkpoint)
@@ -147,27 +145,27 @@ def insert_indented_text(text,offset):
"""Insert indented text in buffer and move cursor to a certain offset."""
# save undo state so we can roll everything into a single operation for undo
- checkpoint = emacs.buffer_undo_list.value()
+ checkpoint = lisp.buffer_undo_list.value()
# figure out if we are indented or not, and adapt text accordingly
indent_level = get_line_offset()
if indent_level > 0:
text = indent(text,indent_level)
# perform actual insertion with proper cursor positioning
offset += indent_level
- emacs.beginning_of_line()
- user_pos = emacs.point()
- emacs.insert(text)
- emacs.goto_char(user_pos+offset)
+ lisp.beginning_of_line()
+ user_pos = lisp.point()
+ lisp.insert(text)
+ lisp.goto_char(user_pos+offset)
# Collapse all operations into a single one, for Undo.
clean_undo_after(checkpoint)
#---------------------------------------------------------------------------
def get_line_offset():
"""Return number of characters cursor is offset from margin. """
- user_pos = emacs.point()
- emacs.beginning_of_line()
- line_start = emacs.point()
- emacs.goto_char(user_pos)
+ user_pos = lisp.point()
+ lisp.beginning_of_line()
+ line_start = lisp.point()
+ lisp.goto_char(user_pos)
return user_pos - line_start
# end get_line_offset()
@@ -201,7 +199,7 @@ def bow():
Originally an example in Pymacs' README."""
region = cut_region()
- emacs.insert('\n'.join(region.split()))
+ lisp.insert('\n'.join(region.split()))
# Update interactions[] for functions meant to be visible in Emacs.
@@ -230,13 +228,13 @@ def dos2unix():
"""Remove DOS line endings from a region.
"""
# Save undo state so we can roll everything into a single operation for undo
- checkpoint = emacs.buffer_undo_list.value()
+ checkpoint = lisp.buffer_undo_list.value()
region = cut_region('list')
- emacs.insert('\n'.join(region)+'\n')
+ lisp.insert('\n'.join(region)+'\n')
# Collapse all operations into a single one, for Undo.
clean_undo_after(checkpoint)
-# BUG: it's not working b/c of a bug in emacs.buffer_substring(), so let's not
+# BUG: it's not working b/c of a bug in lisp.buffer_substring(), so let's not
# activate it for now.
#interactions[dos2unix] = ''
@@ -23,9 +23,9 @@ Interface between Emacs Lisp and Python - Module initialisation.
A few symbols are moved in here so they appear to be defined at this level.
"""
-from pymacs import Let, lisp
+from Pymacs import Let, lisp
# Identification of version.
-__package__ = 'Pymacs'
-__version__ = '@VERSION@'
+package = 'Pymacs'
+version = '@VERSION@'
View
@@ -285,7 +285,7 @@ be installed in turn. Always start with the Python file.
install --help``. Consult the Distutils documentation if you need
more information about this.
- That's normally all to it. To check that :file:`pymacs.py` is
+ That's normally all to it. To check that :file:`Pymacs.py` is
properly installed, start an interactive Python session and type
``from Pymacs import lisp``: you should not receive any error.
@@ -387,10 +387,11 @@ forever. It should not be a practical problem in most simple cases.
Some later versions of Emacs 20 silently create ordinary tables when
asked for weak hash tables. Older Emacses do not have hash tables.
-In earlier versions, Pymacs was installing a :file:`Pymacs`
-Python package holding a single :file:`pymacs.py` file (besides
-:file:`__init__.py`). This is now replaced by a single
-:file:`Pymacs.py` file, and the API did not need to change.
+In earlier versions, Pymacs was installing a :file:`Pymacs` Python
+package holding a single :file:`pymacs.py` file (besides the
+mandatory :file:`__init__.py`). This is now replaced by a single
+:file:`Pymacs.py` file, and because of the capitalisation, the API did
+not need to change.
Emacs Lisp structures and Python objects
========================================
@@ -1626,9 +1627,9 @@ actual need. But if the challenge interests someone, please go ahead!
Here is how it could go. Pymacs has a Python interpreter running as a
sub-process of Emacs. In fact, Emacs loads :file:`pymacs.el`, which
-in turn gets Python to execute :file:`pymacs.py`, and both communicate
-afterwards. :file:`pymacs.py` is only active whenever :file:`pymacs.el`
-calls it, otherwise it is blocked. :file:`pymacs.py` could, under some
+in turn gets Python to execute :file:`Pymacs.py`, and both communicate
+afterwards. :file:`Pymacs.py` is only active whenever :file:`pymacs.el`
+calls it, otherwise it is blocked. :file:`Pymacs.py` could, under some
option, start another thread within itself. The initial thread would
block waiting for Emacs, as usual. The second thread would block
waiting to serve any Python client wanting to access Emacs. When this
@@ -1695,9 +1696,9 @@ mean here, that the real problem to solve is something else.
On a related matter, Ali Gholami Rudi suggested that Pymacs supports Emacs
so-called *keyword arguments*, and even provide a simple patch to do so::
- diff --git a/Pymacs/pymacs.py b/Pymacs/pymacs.py
- --- a/Pymacs/pymacs.py
- +++ b/Pymacs/pymacs.py
+ diff --git a/Pymacs.py b/Pymacs.py
+ --- a/Pymacs.py
+ +++ b/Pymacs.py
@@ -453,13 +453,16 @@
write(') nil)')
lisp._eval(''.join(fragments))
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
-# Checking if pymacs.py loads.
+# Checking if Pymacs.py loads.
def test_1():
import setup
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
-# Checking if pymacs.py works (Emacs and the Pymacs helper are not used).
+# Checking if Pymacs.py works (Emacs and the Pymacs helper are not used).
import re
import setup

0 comments on commit e3f67f9

Please sign in to comment.