diff options
| author | Fabián Ezequiel Gallina | 2014-07-28 01:32:28 -0300 |
|---|---|---|
| committer | Fabián Ezequiel Gallina | 2014-07-28 01:32:28 -0300 |
| commit | 7daa4ff121ad8da6e609b959d5c95796e5d3a9eb (patch) | |
| tree | 91445f90efd2b8d628d5fe01e61137c5d7a4036e /lisp/progmodes/python.el | |
| parent | 4256626a7ac486446f4dea9c12df3057053825a7 (diff) | |
| download | emacs-7daa4ff121ad8da6e609b959d5c95796e5d3a9eb.tar.gz emacs-7daa4ff121ad8da6e609b959d5c95796e5d3a9eb.zip | |
Parse completion input in a iPython friendly way.
* 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
Diffstat (limited to 'lisp/progmodes/python.el')
| -rw-r--r-- | lisp/progmodes/python.el | 53 |
1 files changed, 26 insertions, 27 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 5ec2b865a46..7d882837abc 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el | |||
| @@ -2369,9 +2369,9 @@ variable. | |||
| 2369 | (define-key inferior-python-mode-map [remap complete-symbol] | 2369 | (define-key inferior-python-mode-map [remap complete-symbol] |
| 2370 | 'completion-at-point) | 2370 | 'completion-at-point) |
| 2371 | (add-hook 'completion-at-point-functions | 2371 | (add-hook 'completion-at-point-functions |
| 2372 | 'python-shell-completion-complete-at-point nil 'local) | 2372 | 'python-shell-completion-at-point nil 'local) |
| 2373 | (add-to-list (make-local-variable 'comint-dynamic-complete-functions) | 2373 | (add-to-list (make-local-variable 'comint-dynamic-complete-functions) |
| 2374 | 'python-shell-completion-complete-at-point) | 2374 | 'python-shell-completion-at-point) |
| 2375 | (define-key inferior-python-mode-map "\t" | 2375 | (define-key inferior-python-mode-map "\t" |
| 2376 | 'python-shell-completion-complete-or-indent) | 2376 | 'python-shell-completion-complete-or-indent) |
| 2377 | (make-local-variable 'python-pdbtrack-buffers-to-kill) | 2377 | (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." | |||
| 2896 | (split-string completions | 2896 | (split-string completions |
| 2897 | "^'\\|^\"\\|;\\|'$\\|\"$" t))))))) | 2897 | "^'\\|^\"\\|;\\|'$\\|\"$" t))))))) |
| 2898 | 2898 | ||
| 2899 | (defun python-shell-completion-complete-at-point (&optional process) | 2899 | (defun python-shell-completion-at-point (&optional process) |
| 2900 | "Perform completion at point in inferior Python. | 2900 | "Function for `completion-at-point-functions' in `inferior-python-mode'. |
| 2901 | Optional argument PROCESS forces completions to be retrieved | 2901 | Optional argument PROCESS forces completions to be retrieved |
| 2902 | using that one instead of current buffer's process." | 2902 | using that one instead of current buffer's process." |
| 2903 | (setq process (or process (get-buffer-process (current-buffer)))) | 2903 | (setq process (or process (get-buffer-process (current-buffer)))) |
| 2904 | (let* ((start | 2904 | (let* ((start |
| 2905 | (save-excursion | 2905 | (save-excursion |
| 2906 | (with-syntax-table python-dotty-syntax-table | 2906 | (if (not (re-search-backward |
| 2907 | (let* ((paren-depth (car (syntax-ppss))) | 2907 | (python-rx |
| 2908 | (syntax-string "w_") | 2908 | (or whitespace open-paren close-paren string-delimiter)) |
| 2909 | (syntax-list (string-to-syntax syntax-string))) | 2909 | (cdr (python-util-comint-last-prompt)) |
| 2910 | ;; Stop scanning for the beginning of the completion | 2910 | t 1)) |
| 2911 | ;; subject after the char before point matches a | 2911 | (cdr (python-util-comint-last-prompt)) |
| 2912 | ;; delimiter | 2912 | (forward-char (length (match-string-no-properties 0))) |
| 2913 | (while (member | 2913 | (point)))) |
| 2914 | (car (syntax-after (1- (point)))) syntax-list) | ||
| 2915 | (skip-syntax-backward syntax-string) | ||
| 2916 | (when (or (equal (char-before) ?\)) | ||
| 2917 | (equal (char-before) ?\")) | ||
| 2918 | (forward-char -1)) | ||
| 2919 | (while (or | ||
| 2920 | ;; honor initial paren depth | ||
| 2921 | (> (car (syntax-ppss)) paren-depth) | ||
| 2922 | (python-syntax-context 'string)) | ||
| 2923 | (forward-char -1))) | ||
| 2924 | (point))))) | ||
| 2925 | (end (point))) | 2914 | (end (point))) |
| 2926 | (list start end | 2915 | (list start end |
| 2927 | (completion-table-dynamic | 2916 | (completion-table-dynamic |
| @@ -2930,6 +2919,11 @@ using that one instead of current buffer's process." | |||
| 2930 | process (buffer-substring-no-properties | 2919 | process (buffer-substring-no-properties |
| 2931 | (line-beginning-position) end)))))) | 2920 | (line-beginning-position) end)))))) |
| 2932 | 2921 | ||
| 2922 | (define-obsolete-function-alias | ||
| 2923 | 'python-shell-completion-complete-at-point | ||
| 2924 | 'python-shell-completion-at-point | ||
| 2925 | "24.5") | ||
| 2926 | |||
| 2933 | (defun python-shell-completion-complete-or-indent () | 2927 | (defun python-shell-completion-complete-or-indent () |
| 2934 | "Complete or indent depending on the context. | 2928 | "Complete or indent depending on the context. |
| 2935 | If content before pointer is all whitespace, indent. | 2929 | If content before pointer is all whitespace, indent. |
| @@ -3036,14 +3030,19 @@ Argument OUTPUT is a string with the output from the comint process." | |||
| 3036 | 3030 | ||
| 3037 | ;;; Symbol completion | 3031 | ;;; Symbol completion |
| 3038 | 3032 | ||
| 3039 | (defun python-completion-complete-at-point () | 3033 | (defun python-completion-at-point () |
| 3040 | "Complete current symbol at point. | 3034 | "Function for `completion-at-point-functions' in `python-mode'. |
| 3041 | For this to work as best as possible you should call | 3035 | For this to work as best as possible you should call |
| 3042 | `python-shell-send-buffer' from time to time so context in | 3036 | `python-shell-send-buffer' from time to time so context in |
| 3043 | inferior Python process is updated properly." | 3037 | inferior Python process is updated properly." |
| 3044 | (let ((process (python-shell-get-process))) | 3038 | (let ((process (python-shell-get-process))) |
| 3045 | (when process | 3039 | (when process |
| 3046 | (python-shell-completion-complete-at-point process)))) | 3040 | (python-shell-completion-at-point process)))) |
| 3041 | |||
| 3042 | (define-obsolete-function-alias | ||
| 3043 | 'python-completion-complete-at-point | ||
| 3044 | 'python-completion-at-point | ||
| 3045 | "24.5") | ||
| 3047 | 3046 | ||
| 3048 | 3047 | ||
| 3049 | ;;; Fill paragraph | 3048 | ;;; Fill paragraph |
| @@ -4268,7 +4267,7 @@ Arguments START and END narrow the buffer region to work on." | |||
| 4268 | #'python-nav-end-of-defun) | 4267 | #'python-nav-end-of-defun) |
| 4269 | 4268 | ||
| 4270 | (add-hook 'completion-at-point-functions | 4269 | (add-hook 'completion-at-point-functions |
| 4271 | #'python-completion-complete-at-point nil 'local) | 4270 | #'python-completion-at-point nil 'local) |
| 4272 | 4271 | ||
| 4273 | (add-hook 'post-self-insert-hook | 4272 | (add-hook 'post-self-insert-hook |
| 4274 | #'python-indent-post-self-insert-function 'append 'local) | 4273 | #'python-indent-post-self-insert-function 'append 'local) |