]> git.eshelyaron.com Git - emacs.git/commitdiff
* lisp/progmodes/python.el (python-shell-completion-get-completions):
authorStefan Monnier <monnier@iro.umontreal.ca>
Wed, 1 Oct 2014 00:41:51 +0000 (20:41 -0400)
committerStefan Monnier <monnier@iro.umontreal.ca>
Wed, 1 Oct 2014 00:41:51 +0000 (20:41 -0400)
Use python-shell--prompt-calculated-input-regexp from the
process buffer.
Don't assume that `line' comes from the process buffer.

Fixes: debbugs:18582
lisp/ChangeLog
lisp/progmodes/python.el

index 9ac4f6b1bf128125cfd0905af7651b1dddfb921d..0a0fb21b1e5ec147fe3c17c3766548727dd7f2fc 100644 (file)
@@ -1,3 +1,10 @@
+2014-10-01  Stefan Monnier  <monnier@iro.umontreal.ca>
+
+       * progmodes/python.el (python-shell-completion-get-completions):
+       Use python-shell--prompt-calculated-input-regexp from the
+       process buffer (bug#18582).
+       Don't assume that `line' comes from the process buffer.
+
 2014-09-30  Leonardo Nobrega  <leonobr@gmail.com>  (tiny change)
 
        * progmodes/python.el (python-fill-paren): Don't inf-loop at EOB
index d5126fa888144046686e2da25505cdce01e16b7a..aa9d9b10dbc88aee4d30b0b07345d9818711420e 100644 (file)
@@ -2687,39 +2687,38 @@ the full statement in the case of imports."
 (defun python-shell-completion-get-completions (process line input)
   "Do completion at point for PROCESS.
 LINE is used to detect the context on how to complete given INPUT."
-  (let* ((prompt
-          ;; Get last prompt of the inferior process buffer (this
-          ;; intentionally avoids using `comint-last-prompt' because
-          ;; of incompatibilities with Emacs 24.x).
-          (with-current-buffer (process-buffer process)
+  (with-current-buffer (process-buffer process)
+    (let* ((prompt
+            ;; Get last prompt of the inferior process buffer (this
+            ;; intentionally avoids using `comint-last-prompt' because
+            ;; of incompatibilities with Emacs 24.x).
             (save-excursion
               (buffer-substring-no-properties
-               (- (point) (length line))
+               (line-beginning-position) ;End of prompt.
                (progn
                  (re-search-backward "^")
-                 (python-util-forward-comment)
-                 (point))))))
-         (completion-code
-          ;; Check whether a prompt matches a pdb string, an import
-          ;; statement or just the standard prompt and use the
-          ;; correct python-shell-completion-*-code string
-          (cond ((and (> (length python-shell-completion-pdb-string-code) 0)
-                      (string-match
-                       (concat "^" python-shell-prompt-pdb-regexp) prompt))
-                 python-shell-completion-pdb-string-code)
-                ((string-match
-                  python-shell--prompt-calculated-input-regexp prompt)
-                 python-shell-completion-string-code)
-                (t nil)))
-         (input
-          (if (string-match
-               (python-rx (+ space) (or "from" "import") space)
-               line)
-              line
-            input)))
-    (and completion-code
-         (> (length input) 0)
-         (with-current-buffer (process-buffer process)
+                 (python-util-forward-comment) ;FIXME: Why?
+                 (point)))))
+           (completion-code
+            ;; Check whether a prompt matches a pdb string, an import
+            ;; statement or just the standard prompt and use the
+            ;; correct python-shell-completion-*-code string
+            (cond ((and (> (length python-shell-completion-pdb-string-code) 0)
+                        (string-match
+                         (concat "^" python-shell-prompt-pdb-regexp) prompt))
+                   python-shell-completion-pdb-string-code)
+                  ((string-match
+                    python-shell--prompt-calculated-input-regexp prompt)
+                   python-shell-completion-string-code)
+                  (t nil)))
+           (input
+            (if (string-match
+                 (python-rx (+ space) (or "from" "import") space)
+                 line)
+                line
+              input)))
+      (and completion-code
+           (> (length input) 0)
            (let ((completions
                   (python-util-strip-string
                    (python-shell-send-string-no-output