]> git.eshelyaron.com Git - emacs.git/commitdiff
Parse completion input in a iPython friendly way.
authorFabián Ezequiel Gallina <fgallina@gnu.org>
Mon, 28 Jul 2014 04:32:28 +0000 (01:32 -0300)
committerFabián Ezequiel Gallina <fgallina@gnu.org>
Mon, 28 Jul 2014 04:32:28 +0000 (01:32 -0300)
* lisp/progmodes/python.el
(python-shell-completion-at-point): Rename from
python-shell-completion-complete-at-point.
(inferior-python-mode): Use it.
(python-completion-at-point): Rename from
python-completion-complete-at-point.  Parse input up to first
backward occurrence of whitespace, open-paren, close-paren or
string delimiter.
(python-mode): Use it.

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

index 0dee47e5287b339d4f64f7a454067b041e702497..e00e58c20b58ae46cc0d44d0af37a0ca5439f5da 100644 (file)
@@ -1,3 +1,16 @@
+2014-07-28  Fabián Ezequiel Gallina  <fgallina@gnu.org>
+
+       Parse completion input in a iPython friendly way.  (Bug#18084)
+       * progmodes/python.el
+       (python-shell-completion-at-point): Rename from
+       python-shell-completion-complete-at-point.
+       (inferior-python-mode): Use it.
+       (python-completion-at-point): Rename from
+       python-completion-complete-at-point.  Parse input up to first
+       backward occurrence of whitespace, open-paren, close-paren or
+       string delimiter.
+       (python-mode): Use it.
+
 2014-07-28  Fabián Ezequiel Gallina  <fgallina@gnu.org>
 
        Prevent Python process shell buffer to pop twice.
index 5ec2b865a4653fd35470d0a8bf6b5a945e2fe0ab..7d882837abc7b98d08fa30cf118fb83683bb00df 100644 (file)
@@ -2369,9 +2369,9 @@ variable.
   (define-key inferior-python-mode-map [remap complete-symbol]
     'completion-at-point)
   (add-hook 'completion-at-point-functions
-            'python-shell-completion-complete-at-point nil 'local)
+            'python-shell-completion-at-point nil 'local)
   (add-to-list (make-local-variable 'comint-dynamic-complete-functions)
-               'python-shell-completion-complete-at-point)
+               'python-shell-completion-at-point)
   (define-key inferior-python-mode-map "\t"
     'python-shell-completion-complete-or-indent)
   (make-local-variable 'python-pdbtrack-buffers-to-kill)
@@ -2896,32 +2896,21 @@ LINE is used to detect the context on how to complete given INPUT."
                   (split-string completions
                                 "^'\\|^\"\\|;\\|'$\\|\"$" t)))))))
 
-(defun python-shell-completion-complete-at-point (&optional process)
-  "Perform completion at point in inferior Python.
+(defun python-shell-completion-at-point (&optional process)
+  "Function for `completion-at-point-functions' in `inferior-python-mode'.
 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
           (save-excursion
-            (with-syntax-table python-dotty-syntax-table
-              (let* ((paren-depth (car (syntax-ppss)))
-                     (syntax-string "w_")
-                     (syntax-list (string-to-syntax syntax-string)))
-                ;; Stop scanning for the beginning of the completion
-                ;; subject after the char before point matches a
-                ;; delimiter
-                (while (member
-                        (car (syntax-after (1- (point)))) syntax-list)
-                  (skip-syntax-backward syntax-string)
-                  (when (or (equal (char-before) ?\))
-                            (equal (char-before) ?\"))
-                    (forward-char -1))
-                  (while (or
-                          ;; honor initial paren depth
-                          (> (car (syntax-ppss)) paren-depth)
-                          (python-syntax-context 'string))
-                    (forward-char -1)))
-                (point)))))
+            (if (not (re-search-backward
+                      (python-rx
+                       (or whitespace open-paren close-paren string-delimiter))
+                      (cdr (python-util-comint-last-prompt))
+                      t 1))
+                (cdr (python-util-comint-last-prompt))
+              (forward-char (length (match-string-no-properties 0)))
+              (point))))
          (end (point)))
     (list start end
           (completion-table-dynamic
@@ -2930,6 +2919,11 @@ using that one instead of current buffer's process."
             process (buffer-substring-no-properties
                      (line-beginning-position) end))))))
 
+(define-obsolete-function-alias
+  'python-shell-completion-complete-at-point
+  'python-shell-completion-at-point
+  "24.5")
+
 (defun python-shell-completion-complete-or-indent ()
   "Complete or indent depending on the context.
 If content before pointer is all whitespace, indent.
@@ -3036,14 +3030,19 @@ Argument OUTPUT is a string with the output from the comint process."
 \f
 ;;; Symbol completion
 
-(defun python-completion-complete-at-point ()
-  "Complete current symbol at point.
+(defun python-completion-at-point ()
+  "Function for `completion-at-point-functions' in `python-mode'.
 For this to work as best as possible you should call
 `python-shell-send-buffer' from time to time so context in
 inferior Python process is updated properly."
   (let ((process (python-shell-get-process)))
     (when process
-      (python-shell-completion-complete-at-point process))))
+      (python-shell-completion-at-point process))))
+
+(define-obsolete-function-alias
+  'python-completion-complete-at-point
+  'python-completion-at-point
+  "24.5")
 
 \f
 ;;; Fill paragraph
@@ -4268,7 +4267,7 @@ Arguments START and END narrow the buffer region to work on."
        #'python-nav-end-of-defun)
 
   (add-hook 'completion-at-point-functions
-            #'python-completion-complete-at-point nil 'local)
+            #'python-completion-at-point nil 'local)
 
   (add-hook 'post-self-insert-hook
             #'python-indent-post-self-insert-function 'append 'local)