[Python-mode] Fwd: Idea for python-mode
Barry Warsaw
barry at python.org
Sun Apr 13 00:35:11 CEST 2008
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Martin has a need idea...
Begin forwarded message:
> From: Martin Blais <blais at furius.ca>
> Date: March 31, 2008 12:49:23 PM EDT
> Subject: Idea for python-mode
>
> Here is an idea I've had for emacs python-mode: something
> like (find-library) in Emacs, but for Python::
>
> (defun string-rstrip (str)
> "Strips the whitespace at the end of string STR."
> (string-match "[ \t\n]*\\'" str)
> (substring str 0 (match-beginning 0)))
>
> (defun py-find-library (modname)
> "Run a subordinate python to find out where a module is located
> and load it in a buffer."
> (interactive "MModule name: ")
> (let* ((program (format "import %s as m; print m.__file__"
> modname))
> (filename
> (replace-regexp-in-string
> "\\(\\.pyc\\|\\.pyo\\)" ".py"
> (string-rstrip
> (shell-command-to-string (format "python -c '%s'"
> program))))))
> (unless (file-exists-p filename)
> (error (format "File %s could not be found." filename)))
> (find-file filename)
> ))
>
> Feel free to scavenge, adapt and integrate in python-mode if
> you like.
- -Barry
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.8 (Darwin)
iQCVAwUBSAE5I3EjvBPtnXfVAQLItgP8D0x1WeoTtBk5nyWZ5ZcFxb97Hxio90v3
cM+8lMxk5zzdKmI+hrtQKdJU2vDKGQSUMbewNnBVYWq3b/ZFudxAECRQgCAivsVg
d6YG5B3RCycm/WKdkxcSeGuHkredBH97iUb9c50Al53Rg+SMLek4gwKVFQ+Zk2RN
wnZAiEZaJEQ=
=+vdG
-----END PGP SIGNATURE-----
More information about the Python-mode
mailing list