]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Added emacs.py (for misc/py-connect.el).
authorGuido van Rossum <guido@python.org>
Sun, 9 Aug 1992 13:54:50 +0000 (13:54 +0000)
committerGuido van Rossum <guido@python.org>
Sun, 9 Aug 1992 13:54:50 +0000 (13:54 +0000)
posixpath.py: added undocumented expanndvars() (expands $VAR in string).

Lib/emacs.py [new file with mode: 0644]
Lib/posixpath.py

diff --git a/Lib/emacs.py b/Lib/emacs.py
new file mode 100644 (file)
index 0000000..ffce099
--- /dev/null
@@ -0,0 +1,18 @@
+# Execute Emacs code from a Python interpreter.
+# This code should be imported from a Python interpreter that is
+# running as an inferior process of Emacs.
+# See misc/py-connect.el for the companion Emacs lisp code.
+# Author: Terrence M. Brannon.
+
+start_marker = '+'
+end_marker   = '~'
+
+def eval (string):
+       tmpstr = start_marker + '(' + string + ')' + end_marker
+       print tmpstr
+
+def dired (directory):
+       eval( 'dired ' + '"' + directory + '"' )
+
+def buffer_menu ():
+       eval( 'buffer-menu(buffer-list)' )
index b178e6728d4613809de67c7ed4de2c7843acdef6..d2bda1059ca2aed67eb369b08becf760adfd1b18 100644 (file)
@@ -230,3 +230,29 @@ def expanduser(path):
                        return path
                userhome = pwent[5]
        return userhome + path[i:]
+
+
+# Expand paths containing shell variable substitutions.
+# This is done by piping it through the shell.
+# Shell quoting characters (\ " ' `) are protected by a backslash.
+# NB: a future version may avoid starting a subprocess and do the
+# substitutions internally.  This may slightly change the syntax
+# for variables.
+
+def expandvars(path):
+       if '$' not in path:
+               return path
+       q = ''
+       for c in path:
+               if c in ('\\', '"', '\'', '`'):
+                       c = '\\' + c
+               q = q + c
+       d = '!'
+       if q == d:
+               d = '+'
+       p = posix.popen('cat <<' + d + '\n' + q + '\n' + d + '\n', 'r')
+       res = p.read()
+       del p
+       if res[-1:] == '\n':
+               res = res[:-1]
+       return res