commit 4a3ed0ccfcfa2d18c0416c3c2956afeff92d53ff Author: Russell Sim Date: Wed Jul 11 12:06:24 2012 +1000 Enhanced py-find-imports to handle multiline imports. diff --git a/python-mode.el b/python-mode.el index 6795843..81ecff8 100644 --- a/python-mode.el +++ b/python-mode.el @@ -8869,11 +8869,19 @@ Useful for newly defined symbol, not known to python yet. " (save-excursion (goto-char (point-min)) (while (re-search-forward - "^import *[A-Za-z_][A-Za-z_0-9].*\\|^from +[A-Za-z_][A-Za-z_0-9]+ +import .*" nil t) - (setq imports - (concat - imports - (buffer-substring-no-properties (match-beginning 0) (match-end 0)) ";")))) + "^import *[A-Za-z_][A-Za-z_0-9].*\\|^from +[A-Za-z_][A-Za-z_0-9.]+ +import .*" nil t) + + (let ((start-point (point))) + (end-of-line) + (while (equal (char-before) (string-to-char "\\")) + (next-line) + (end-of-line)) + (setq imports + (concat + imports + (replace-regexp-in-string + "[\\]\r?\n?\s*" "" + (buffer-substring-no-properties (match-beginning 0) (point))) ";"))))) (when (and py-verbose-p (interactive-p)) (message "%s" imports)) imports)) diff --git a/test/py-bug-numbered-tests.el b/test/py-bug-numbered-tests.el index 56b545c..2912cfb 100644 --- a/test/py-bug-numbered-tests.el +++ b/test/py-bug-numbered-tests.el @@ -2947,6 +2947,42 @@ if __name__ == \"__main__\": (py-narrow-to-defun) (assert (eq 522 (point-max)) nil "py-narrow-to-defun-lp-1020531-test failed")) +(defun py-find-imports-lp-1023236-test (&optional arg) + (interactive "p") + (let ((teststring "#! /usr/bin/env python +# -*- coding: utf-8 -*- +############################################################################# +# +# Import test +# +############################################################################# + +import urllib +import os, sys +from hashlib import md5 + +from construct import Container +from twisted.internet import reactor, defer +from twisted.internet.protocol import ClientFactory +from twisted.python import log, failure, filepath + +from mock import mock1, mock2, \\ + mock3, mock4 +print \"ignored\" + +print \"ignored\" + +def something(): + pass + +")) + (py-bug-tests-intern 'py-find-imports-lp-1023236-base arg teststring))) + + +(defun py-find-imports-lp-1023236-base () + (goto-char 334) + (assert (equal "import urllib;import os, sys;from hashlib import md5;from construct import Container;from twisted.internet import reactor, defer;from twisted.internet.protocol import ClientFactory;from twisted.python import log, failure, filepath;from mock import mock1, mock2, mock3, mock4;" + (py-find-imports)) nil "py-find-imports-lp-1023236-test failed")) (provide 'py-bug-numbered-tests) ;;; py-bug-numbered-tests.el ends here diff --git a/test/python-mode-tests.sh b/test/python-mode-tests.sh index 6abe6ce..3d7445c 100755 --- a/test/python-mode-tests.sh +++ b/test/python-mode-tests.sh @@ -672,6 +672,7 @@ $EMACS -Q --batch --eval "(message (emacs-version))" --eval "(when (featurep 'py -eval "(assert (commandp 'py-mark-block-misbehave-lp:949310-test) nil \"py-mark-block-misbehave-lp:949310-test not detected as command\")" \ -eval "(assert (commandp 'py-mark-partial-expression) nil \"py-mark-partial-expression not detected as command\")" \ -eval "(message \"commandp tests done\")" \ +--funcall py-find-imports-lp-1023236-test \ --funcall key-binding-tests \ --funcall py-narrow-to-defun-lp-1020531-test \ --funcall pycomplete-imports-not-found-error-when-no-symbol-lp:1019791-test \