aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorDan Davison2012-05-17 00:03:27 -0300
committerFabián Ezequiel Gallina2012-05-17 00:03:27 -0300
commit9253ea694decb0d5a5995b1a59db3274db290ac8 (patch)
tree350c7db81e154ded18305d78439ff1d54eb5096e /lisp
parentb71bfa9cd6e670a97a803adb1027a859cd66bfe9 (diff)
downloademacs-9253ea694decb0d5a5995b1a59db3274db290ac8.tar.gz
emacs-9253ea694decb0d5a5995b1a59db3274db290ac8.zip
Complete module import lines in addition to variable names
Available when using ipython v0.11. Completions on lines starting with "from " or "import " are supplied by IPython.core.completerlib.module_completion ipython v0.11 configuration: (setq python-shell-interpreter "ipython" python-shell-completion-setup-code "from IPython.core.completerlib import module_completion\n" python-shell-module-completion-string-code "';'.join(module_completion('''%s'''))\n" python-shell-completion-string-code "';'.join(get_ipython().Completer.all_completions('''%s'''))\n")
Diffstat (limited to 'lisp')
-rw-r--r--lisp/progmodes/python.el42
1 files changed, 33 insertions, 9 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 4fe5bd87462..72df547d760 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -1600,24 +1600,48 @@ else:
1600 :group 'python 1600 :group 'python
1601 :safe 'stringp) 1601 :safe 'stringp)
1602 1602
1603(defun python-shell-completion--get-completions (input process) 1603(defcustom python-shell-module-completion-string-code ""
1604 "Python code used to get a string of completions separated by
1605 semicolons on a module import line.
1606
1607For IPython v0.11, add the following line to
1608`python-shell-completion-setup-code':
1609
1610from IPython.core.completerlib import module_completion
1611
1612and use the following as the value of this variable:
1613
1614';'.join(module_completion('''%s'''))\n"
1615 :type 'string
1616 :group 'python
1617 :safe 'stringp)
1618
1619(defvar python-shell-import-line-regexp "^\\(from\\|import\\)[ \t]")
1620
1621(defun python-shell-completion--get-completions (input process completion-code)
1604 "Retrieve available completions for INPUT using PROCESS." 1622 "Retrieve available completions for INPUT using PROCESS."
1605 (with-current-buffer (process-buffer process) 1623 (with-current-buffer (process-buffer process)
1606 (let ((completions (python-shell-send-string-no-output 1624 (let ((completions (python-shell-send-string-no-output
1607 (format python-shell-completion-string-code input) 1625 (format completion-code input) process)))
1608 process)))
1609 (when (> (length completions) 2) 1626 (when (> (length completions) 2)
1610 (split-string completions "^'\\|^\"\\|;\\|'$\\|\"$" t))))) 1627 (split-string completions "^'\\|^\"\\|;\\|'$\\|\"$" t)))))
1611 1628
1612(defun python-shell-completion--do-completion-at-point (process) 1629(defun python-shell-completion--do-completion-at-point (process)
1613 "Do completion for INPUT using COMPLETIONS." 1630 "Do completion for INPUT using COMPLETIONS."
1614 (with-syntax-table python-dotty-syntax-table 1631 (with-syntax-table python-dotty-syntax-table
1615 (let* ((input (substring-no-properties 1632 (let* ((line (substring-no-properties
1616 (or (comint-word (current-word)) "") nil nil)) 1633 (buffer-substring (point-at-bol) (point)) nil nil))
1617 (completions (python-shell-completion--get-completions 1634 (input (substring-no-properties
1618 input process)) 1635 (or (comint-word (current-word)) "") nil nil))
1619 (completion (when completions 1636 (completions
1620 (try-completion input completions)))) 1637 (if (and (> (length python-shell-module-completion-string-code) 0)
1638 (string-match python-shell-import-line-regexp line))
1639 (python-shell-completion--get-completions
1640 line process python-shell-module-completion-string-code)
1641 (python-shell-completion--get-completions
1642 input process python-shell-completion-string-code)))
1643 (completion (when completions
1644 (try-completion input completions))))
1621 (cond ((eq completion t) 1645 (cond ((eq completion t)
1622 t) 1646 t)
1623 ((null completion) 1647 ((null completion)