-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Begin forwarded message:

From: "Yongsub Chung" <[EMAIL PROTECTED]>
Date: November 19, 2008 3:07:27 PM EST
To: [EMAIL PROTECTED]
Subject: Python mode function that I use
Message-Id: <[EMAIL PROTECTED]>


Message body follows:

Hi.  I have two python-mode elisp functions that can be
useful.  However, since I am very rough on elisp, I hope
that someone can complete this more elegantly.

Initially, its named after my namespace prefix, but
hopefully, this becomes 'python-insert-import' and
'python-insert-from-import'.

Thank you.

Raymond


;;; code from here ;;;

(defun ray-py-import (inc top)
 "Insert python import without changing buffer-location.
For now, if '^import ' statement appears in the middle of
the code,
it is not smart to skip it. "
 (interactive "sImport name: \nsGoing to the top? (y/N) ")
 (if (or (string= top "y") (string= top "Y"))
     (save-excursion
       (beginning-of-buffer)
       (goto-char (re-search-forward "^import" nil t))
       (move-beginning-of-line nil)
       (insert-string "import " inc "\n"))
   (save-excursion
     (goto-char (re-search-backward "^import" nil t))
     (move-end-of-line nil)
     (insert-string "\n")
     (insert-string "import " inc))))

(defun ray-py-from-import (from inc top)
 "Insert python 'from module import c1,c2' without changing
buffer-location
For now, if '^from ' statement appears in the middle of the
code,
it is not smart to skip it. "
 (interactive "sFrom module: \nsImport name: \nsGoing to
the top? (y/N) ")
 (if (or (string= top "y") (string= top "Y"))
     (save-excursion
       (beginning-of-buffer)
       (goto-char (re-search-forward "^from " nil t))
       (move-beginning-of-line nil)
       (insert-string "from " from " import " inc "\n"))
   (save-excursion
     (goto-char (re-search-backward "^from " nil t))
     (move-end-of-line nil)
     (insert-string "\n")
     (insert-string "from " from " import " inc ))))


--
This message has been sent to you, a registered SourceForge.net user,
by another site user, through the SourceForge.net site.  This message
has been delivered to your SourceForge.net mail alias.  You may reply
to this message using the "Reply" feature of your email client, or
using the messaging facility of SourceForge.net at:
https://sourceforge.net/sendmessage.php?touser=2294541


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Darwin)

iQCVAwUBSScXM3EjvBPtnXfVAQIDJwP/YfThDf8WWo9xyZGW7gCShQBMjpGcxptM
+FEQE7Wu4z6CWbFeLSHEMbhUABEOjyOam2CYvmY5Oy1u2kk6mWlDbvjXNri7mhsQ
8E5PiEQcYmS5ZMs4ObLNk7jbdGElV18j9znso3Kn37kVdcb764Cop/cRLvi2/taN
XyboXjebFrM=
=6A1e
-----END PGP SIGNATURE-----
_______________________________________________
Python-mode mailing list
Python-mode@python.org
http://mail.python.org/mailman/listinfo/python-mode

Reply via email to