]> git.eshelyaron.com Git - emacs.git/commitdiff
Make `python-shell-completion--do-completion-at-point' to return a list for `completi...
authorFabián Ezequiel Gallina <fgallina@cuca>
Thu, 17 May 2012 03:03:36 +0000 (00:03 -0300)
committerFabián Ezequiel Gallina <fgallina@gnu.org>
Thu, 17 May 2012 03:03:36 +0000 (00:03 -0300)
Removed vars:
 + python-shell-completion-original-window-configuration

lisp/progmodes/python.el

index cfc15c7d040ee1e6dc39ee55726759813ccdbf06..377ad72756f5ea1e4ffaaaa9417200844c935cbb 100644 (file)
@@ -1707,8 +1707,6 @@ and use the following as the value of this variable:
   :type 'string
   :group 'python)
 
-(defvar python-shell-completion-original-window-configuration nil)
-
 (defun python-shell-completion--get-completions (input process completion-code)
   "Retrieve available completions for INPUT using PROCESS.
 Argument COMPLETION-CODE is the python code used to get
@@ -1722,16 +1720,21 @@ completions on the current context."
 (defun python-shell-completion--do-completion-at-point (process)
   "Do completion at point for PROCESS."
   (with-syntax-table python-dotty-syntax-table
-    (let* ((line (substring-no-properties
-                  (buffer-substring (point-at-bol) (point)) nil nil))
-           (input (substring-no-properties
-                   (or (comint-word (current-word)) "") nil nil))
+    (let* ((beg (save-excursion (skip-syntax-backward "w") (point)))
+           (end (point))
+           (line (buffer-substring-no-properties (point-at-bol) end))
+           (input (buffer-substring-no-properties beg end))
+           ;; Get the last prompt for the inferior process buffer. This is
+           ;; used for the completion code selection heuristic.
            (prompt
             (with-current-buffer (process-buffer process)
               (buffer-substring-no-properties
                (overlay-start comint-last-prompt-overlay)
                (overlay-end comint-last-prompt-overlay))))
            (completion-code
+            ;; Check wether 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))
@@ -1749,32 +1752,8 @@ completions on the current context."
            (completions
             (and completion-code (> (length input) 0)
                  (python-shell-completion--get-completions
-                  line process completion-code)))
-           (completion (when completions
-                         (try-completion input completions))))
-      (cond ((eq completion t)
-             (if (eq this-command last-command)
-                 (when python-shell-completion-original-window-configuration
-                   (set-window-configuration
-                    python-shell-completion-original-window-configuration)))
-             (setq python-shell-completion-original-window-configuration nil)
-             t)
-            ((null completion)
-             (message "Can't find completion for \"%s\"" input)
-             (ding)
-             nil)
-            ((not (string= input completion))
-             (progn (delete-char (- (length input)))
-                    (insert completion)
-                    t))
-            (t
-             (unless python-shell-completion-original-window-configuration
-               (setq python-shell-completion-original-window-configuration
-                     (current-window-configuration)))
-             (with-output-to-temp-buffer "*Python Completions*"
-               (display-completion-list
-                (all-completions input completions)))
-             t)))))
+                  line process completion-code))))
+      (list beg end completions))))
 
 (defun python-shell-completion-complete-at-point ()
   "Perform completion at point in inferior Python process."