Function: python-shell-completion-extra-context
python-shell-completion-extra-context is a byte-compiled function
defined in python.el.gz.
Signature
(python-shell-completion-extra-context &optional POS)
Documentation
Get extra completion context at position POS in Python buffer.
If optional argument POS is nil, use current position.
Readline completers could use current line as the completion context, which may be insufficient. In this function, extra context (e.g. multi-line function call) is found and reformatted as one line, which is required by native completion.
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/python.el.gz
(defun python-shell-completion-extra-context (&optional pos)
"Get extra completion context at position POS in Python buffer.
If optional argument POS is nil, use current position.
Readline completers could use current line as the completion
context, which may be insufficient. In this function, extra
context (e.g. multi-line function call) is found and reformatted
as one line, which is required by native completion."
(let (bound p)
(save-excursion
(and pos (goto-char pos))
(setq bound (pos-bol))
(python-nav-up-list -1)
(when (and (< (point) bound)
(or
(looking-back
(python-rx (group (+ (or "." symbol-name)))) (pos-bol) t)
(progn
(forward-line 0)
(looking-at "^[ \t]*\\(from \\)"))))
(setq p (match-beginning 1))))
(when p
(replace-regexp-in-string
"\n[ \t]*" "" (buffer-substring-no-properties p (1- bound))))))