emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] trunk r117634: * progmodes/python.el: Completion code clea


From: Fabián Ezequiel Gallina
Subject: [Emacs-diffs] trunk r117634: * progmodes/python.el: Completion code cleanups.
Date: Sat, 02 Aug 2014 22:53:29 +0000
User-agent: Bazaar (2.6b2)

------------------------------------------------------------
revno: 117634
revision-id: address@hidden
parent: address@hidden
committer: Fabián Ezequiel Gallina <address@hidden>
branch nick: trunk
timestamp: Sat 2014-08-02 19:52:55 -0300
message:
  * progmodes/python.el: Completion code cleanups.
  (python-shell-completion-get-completions): Detect and send import
  statements directly to completion function.
  (python-shell-completion-at-point): Simplify prompt calculation
  and import vs input completion logic.
modified:
  lisp/ChangeLog                 changelog-20091113204419-o5vbwnq5f7feedwu-1432
  lisp/progmodes/python.el       python.el-20091113204419-o5vbwnq5f7feedwu-3008
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2014-08-02 18:52:48 +0000
+++ b/lisp/ChangeLog    2014-08-02 22:52:55 +0000
@@ -1,3 +1,11 @@
+2014-08-02  Fabián Ezequiel Gallina  <address@hidden>
+
+       * progmodes/python.el: Completion code cleanups.
+       (python-shell-completion-get-completions): Detect and send import
+       statements directly to completion function.
+       (python-shell-completion-at-point): Simplify prompt calculation
+       and import vs input completion logic.
+
 2014-08-02  Alan Mackenzie  <address@hidden>
 
        Fix confusion in C++ file caused by comma in "= {1,2},".  Bug

=== modified file 'lisp/progmodes/python.el'
--- a/lisp/progmodes/python.el  2014-08-01 00:18:19 +0000
+++ b/lisp/progmodes/python.el  2014-08-02 22:52:55 +0000
@@ -2872,21 +2872,15 @@
   :type 'string
   :group 'python)
 
-(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."
+(defun python-shell-completion-get-completions (process import input)
+  "Do completion at point using PROCESS for IMPORT or INPUT.
+When IMPORT is non-nil takes precedence over INPUT for
+completion."
   (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)
-            (save-excursion
+            (let ((prompt-boundaries (python-util-comint-last-prompt)))
               (buffer-substring-no-properties
-               (- (point) (length line))
-               (progn
-                 (re-search-backward "^")
-                 (python-util-forward-comment)
-                 (point))))))
+               (car prompt-boundaries) (cdr prompt-boundaries)))))
          (completion-code
           ;; Check whether a prompt matches a pdb string, an import
           ;; statement or just the standard prompt and use the
@@ -2899,19 +2893,14 @@
                   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)))
+         (subject (or import input)))
     (and completion-code
          (> (length input) 0)
          (with-current-buffer (process-buffer process)
            (let ((completions
                   (python-util-strip-string
                    (python-shell-send-string-no-output
-                    (format completion-code input) process))))
+                    (format completion-code subject) process))))
              (and (> (length completions) 2)
                   (split-string completions
                                 "^'\\|^\"\\|;\\|'$\\|\"$" t)))))))
@@ -2921,14 +2910,20 @@
 Optional argument PROCESS forces completions to be retrieved
 using that one instead of current buffer's process."
   (setq process (or process (get-buffer-process (current-buffer))))
-  (let* ((start
+  (let* ((last-prompt-end (cdr (python-util-comint-last-prompt)))
+         (import-statement
+          (when (string-match-p
+                 (rx (* space) word-start (or "from" "import") word-end space)
+                 (buffer-substring-no-properties last-prompt-end (point)))
+            (buffer-substring-no-properties last-prompt-end (point))))
+         (start
           (save-excursion
             (if (not (re-search-backward
                       (python-rx
                        (or whitespace open-paren close-paren string-delimiter))
-                      (cdr (python-util-comint-last-prompt))
+                      last-prompt-end
                       t 1))
-                (cdr (python-util-comint-last-prompt))
+                last-prompt-end
               (forward-char (length (match-string-no-properties 0)))
               (point))))
          (end (point)))
@@ -2936,8 +2931,7 @@
           (completion-table-dynamic
            (apply-partially
             #'python-shell-completion-get-completions
-            process (buffer-substring-no-properties
-                     (line-beginning-position) end))))))
+            process import-statement)))))
 
 (define-obsolete-function-alias
   'python-shell-completion-complete-at-point


reply via email to

[Prev in Thread] Current Thread [Next in Thread]