: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
(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))
(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."