6

I'm using Emacs 24.4.1 on OSX (installed with Homebrew), with the built in python.el, and Python 3 (also installed with Homebrew), along with IPython 2.3.0. I have this in my .emacs:

(setq
 python-shell-interpreter "/usr/local/bin/ipython3"
 python-shell-prompt-regexp "In \\[[0-9]+\\]: "
 python-shell-prompt-output-regexp "Out\\[[0-9]+\\]: "
 python-shell-completion-setup-code
 "from IPython.core.completerlib import module_completion"
 python-shell-completion-module-string-code
 "';'.join(module_completion('''%s'''))\n"
 python-shell-completion-string-code
 "';'.join(get_ipython().Completer.all_completions('''%s'''))\n")

Everything works correctly when I invoke M-x run-python, except one thing: the <tab>-completion of module names doesn't work in the REPL (it says "No match" in the *Messages* buffer). I'm pretty sure it was working with Emacs 24.3, which I upgraded very recently, but I'm not 100% sure. Anyone has an idea what might cause this, or how I could try to debug it?

Update:

After having set debug-on-message to "No match" as suggested by @Constantine below, trying to do:

In [4]: import nump<tab>

yields:

Debugger entered--Lisp error: "No match"
  message("%s" "No match")
  minibuffer-message("No match")
  completion--message("No match")
  completion--do-completion(#<marker at 406 in *Python*> 410)
  completion--in-region-1(#<marker at 406 in *Python*> 410)
  #[1028 "\n\203!\304!\203\202\305!\305\306\"F\307\310!\210\311\"*\207" [minibuffer-completion-predicate minibuffer-completion-table completion-in-region-mode-predicate completion-in-region--data markerp copy-marker t completion-in-region-mode 1 completion--in-region-1] 8 "\n\n(fn START END COLLECTION PREDICATE)"](#<marker at 406 in *Python*> 410 #[771 "\211\242\301=\206\n\211\302=?\205+r\303 \304!\203\305!\202p\262q\210\306\300!$)\207" [(closure (t) (&rest args) (apply (quote python-shell-completion-get-completions) (quote #<process Python>) (quote "import nump") args)) boundaries metadata minibuffer-selected-window window-live-p window-buffer complete-with-action] 8 "\n\n(fn STRING PRED ACTION)"] nil)
  apply(#[1028 "\n\203!\304!\203\202\305!\305\306\"F\307\310!\210\311\"*\207" [minibuffer-completion-predicate minibuffer-completion-table completion-in-region-mode-predicate completion-in-region--data markerp copy-marker t completion-in-region-mode 1 completion--in-region-1] 8 "\n\n(fn START END COLLECTION PREDICATE)"] (#<marker at 406 in *Python*> 410 #[771 "\211\242\301=\206\n\211\302=?\205+r\303 \304!\203\305!\202p\262q\210\306\300!$)\207" [(closure (t) (&rest args) (apply (quote python-shell-completion-get-completions) (quote #<process Python>) (quote "import nump") args)) boundaries metadata minibuffer-selected-window window-live-p window-buffer complete-with-action] 8 "\n\n(fn STRING PRED ACTION)"] nil))
  #[771 ":\2030@\301=\203\300\242\302A\"\303#\207\304@\305\306\307\310\311\312\300!\313\"\314\315%A##\207\304\316\"\207" [(#0) t append nil apply apply-partially make-byte-code 642 "\300\242#\207" vconcat vector [] 7 "\n\n(fn FUNS GLOBAL &rest ARGS)" #[1028 "\n\203!\304!\203\202\305!\305\306\"F\307\310!\210\311\"*\207" [minibuffer-completion-predicate minibuffer-completion-table completion-in-region-mode-predicate completion-in-region--data markerp copy-marker t completion-in-region-mode 1 completion--in-region-1] 8 "\n\n(fn START END COLLECTION PREDICATE)"]] 12 "\n\n(fn FUNS GLOBAL ARGS)"](nil nil (#<marker at 406 in *Python*> 410 #[771 "\211\242\301=\206\n\211\302=?\205+r\303 \304!\203\305!\202p\262q\210\306\300!$)\207" [(closure (t) (&rest args) (apply (quote python-shell-completion-get-completions) (quote #<process Python>) (quote "import nump") args)) boundaries metadata minibuffer-selected-window window-live-p window-buffer complete-with-action] 8 "\n\n(fn STRING PRED ACTION)"] nil))
  completion--in-region(#<marker at 406 in *Python*> 410 #[771 "\211\242\301=\206\n\211\302=?\205+r\303 \304!\203\305!\202p\262q\210\306\300!$)\207" [(closure (t) (&rest args) (apply (quote python-shell-completion-get-completions) (quote #<process Python>) (quote "import nump") args)) boundaries metadata minibuffer-selected-window window-live-p window-buffer complete-with-action] 8 "\n\n(fn STRING PRED ACTION)"] nil)
  completion-in-region(#<marker at 406 in *Python*> 410 #[771 "\211\242\301=\206\n\211\302=?\205+r\303 \304!\203\305!\202p\262q\210\306\300!$)\207" [(closure (t) (&rest args) (apply (quote python-shell-completion-get-completions) (quote #<process Python>) (quote "import nump") args)) boundaries metadata minibuffer-selected-window window-live-p window-buffer complete-with-action] 8 "\n\n(fn STRING PRED ACTION)"] nil)
  completion-at-point()
  python-shell-completion-complete-or-indent()
  call-interactively(python-shell-completion-complete-or-indent nil nil)
  command-execute(python-shell-completion-complete-or-indent)

My current Emacs-fu is not enough to allow me to understand the problem from that stacktrace alone, but perhaps someone could?

  • 1
    To debug this, try setting debug-on-message to "No match" and try completing a module name; you should be able to use the backtrace to get to the source of the error. See Error Debugging for more. – Constantine Dec 6 '14 at 0:04
  • Thanks @Constantine, I have added the stacktrace above, does it give you an hint of what might be going wrong by any chance? – cjauvin Dec 6 '14 at 5:34
4

How to Debug?

It's tough to spot until you know what you're looking for, but in the middle of the stacktrace you see that the byte-compiled functions are calling python-shell-completion-get-completions.

You can step through this function with edebug to see what's happening, or you can appeal to divine inspiration to conclude that it ultimately sends the following to the IPython interpreter:

';'.join(get_ipython().Completer.all_completions('''import nump'''))

On my setup (Linux but with same Emacs, python, and IPython version numbers) this command yields an empty string. Hence why you're seeing a "No match" message.

So ... yay? It doesn't look like there's any more debugging to do within Emacs. Gotta figure out how to make that IPython completion command work, then adjust your configuration appropriately.

How to Fix?

I haven't looked at Emacs, python, and IPython in a while. I have the same configuration in my init file (I think the comments in python.el used to tell you to do that) but as of 24.4 it looks like a lot of IPython support is built into the default config.

So, remove the completion-related setq and you should be good to go. Works for me, at least.

(Side note: I think you can remove the prompt-related setq as well.)

  • Thanks @purple_arrows, that's exactly what I ended up doing: I only have (setq python-shell-interpreter "/usr/local/bin/ipython3") left, and everything else now just works. – cjauvin Dec 7 '14 at 16:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.