]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix completion retrieval parsing.
authorFabián Ezequiel Gallina <fgallina@gnu.org>
Sat, 21 Jun 2014 14:14:54 +0000 (11:14 -0300)
committerFabián Ezequiel Gallina <fgallina@gnu.org>
Sat, 21 Jun 2014 14:14:54 +0000 (11:14 -0300)
* progmodes/python.el (python-mode):
(python-util-strip-string): New function.
(python-shell-completion-get-completions): Use it.

* automated/python-tests.el (python-util-strip-string-1): New test.

Fixes: debbugs:17209
lisp/ChangeLog
lisp/progmodes/python.el
test/ChangeLog
test/automated/python-tests.el

index 46f87253825b354887f1d65e219fd930474329f8..9af92aebf3a94491bafe12bc520c998822337d52 100644 (file)
@@ -1,3 +1,10 @@
+2014-06-21  Fabián Ezequiel Gallina  <fgallina@gnu.org>
+
+       Fix completion retrieval parsing (bug#17209).
+       * progmodes/python.el (python-mode):
+       (python-util-strip-string): New function.
+       (python-shell-completion-get-completions): Use it.
+
 2014-06-21  Eli Zaretskii  <eliz@gnu.org>
 
        * skeleton.el (skeleton-insert): Fix last change.
index f127d4b7028b8ce3b51282b29117e7149cc17195..f99a580b3769d156b0adb323e4eb7a5d2fb2828a 100644 (file)
@@ -2463,8 +2463,10 @@ LINE is used to detect the context on how to complete given INPUT."
     (and completion-code
          (> (length input) 0)
          (with-current-buffer (process-buffer process)
-           (let ((completions (python-shell-send-string-no-output
-                               (format completion-code input) process)))
+           (let ((completions
+                  (python-util-strip-string
+                   (python-shell-send-string-no-output
+                    (format completion-code input) process))))
              (and (> (length completions) 2)
                   (split-string completions
                                 "^'\\|^\"\\|;\\|'$\\|\"$" t)))))))
@@ -3644,6 +3646,14 @@ returned as is."
               n (1- n)))
       (reverse acc))))
 
+(defun python-util-strip-string (string)
+  "Strip STRING whitespace and newlines from end and beginning."
+  (replace-regexp-in-string
+   (rx (or (: string-start (* (any whitespace ?\r ?\n)))
+           (: (* (any whitespace ?\r ?\n)) string-end)))
+   ""
+   string))
+
 \f
 (defun python-electric-pair-string-delimiter ()
   (when (and electric-pair-mode
index 443479b099e36dba634c54597291c669aff06e72..f86084739affd88d1814ce3230d6e30698c38f5c 100644 (file)
@@ -1,3 +1,7 @@
+2014-06-21  Fabián Ezequiel Gallina  <fgallina@gnu.org>
+
+       * automated/python-tests.el (python-util-strip-string-1): New test.
+
 2014-05-08  Glenn Morris  <rgm@gnu.org>
 
        * automated/vc-bzr.el (vc-bzr-test-bug9726, vc-bzr-test-bug9781)
index de963a670bc00283a4df4997a46431b65fd8663f..f580e946b8fee95ab64f4bab0410532fdc0f1558 100644 (file)
@@ -2706,6 +2706,15 @@ def foo(a, b, c):
         (equal (symbol-value (car ccons)) (cdr ccons)))))
     (kill-buffer buffer)))
 
+(ert-deftest python-util-strip-string-1 ()
+  (should (string= (python-util-strip-string "\t\r\n    str") "str"))
+  (should (string= (python-util-strip-string "str \n\r") "str"))
+  (should (string= (python-util-strip-string "\t\r\n    str \n\r ") "str"))
+  (should
+   (string= (python-util-strip-string "\n str \nin \tg \n\r") "str \nin \tg"))
+  (should (string= (python-util-strip-string "\n \t \n\r ") ""))
+  (should (string= (python-util-strip-string "") "")))
+
 \f
 ;;; Electricity