2

I have installed “Jedi” mode in Emacs but am finding that it auto-inserts the word elif every time I create a new line and then type e l s e : Enter because the colon character apparently kicks off Jedi’s completion logic with elif suggested as the top suggestion, and my pressing Enter apparently selects it. So I always, every time I try to type an else clause, have to backspace over the extraneous elif before continuing.

Is this problem unique to me? I activate Jedi by closely following the documentation:

(add-hook 'python-mode-hook 'jedi:setup)                                        
(setq jedi:complete-on-dot t)                                                   
(setq jedi:get-in-function-call-delay 200)                                      
(setq jedi:tooltip-method nil)                                                  

You can find my entire .emacs.d/init.el under version control on GitHub:

https://github.com/brandon-rhodes/dot-emacs

The current version of Jedi and its associated tools on my system is:

(:emacs-version "24.3.1" :jedi-version "0.2.0alpha2")
((:version "3.4.0 |Continuum Analytics, Inc.| (default, Mar 17 2014, 16:13:08) \n[GCC 4.1.2 20080704 (Red Hat 4.1.2-52)]" :file nil :name "sys")
 (:version "0.8.0-final0" :file "/home/brandon/.v/fopnp-py3/lib/python3.4/site-packages/jedi/__init__.py" :name "jedi")
 (:version "0.0.5" :file "/home/brandon/.v/fopnp-py3/lib/python3.4/site-packages/epc/__init__.py" :name "epc")
 (:version "0.0.3" :file "/home/brandon/.v/fopnp-py3/lib/python3.4/site-packages/sexpdata.py" :name "sexpdata"))

I note that the : character is bound to the Emacs function python-indent-electric-colon but I am not sure how to determine whether that function is somehow setting off Jedi’s completion logic without meaning to.

Drew
  • 29,895
  • 7
  • 74
  • 104
Brandon Rhodes
  • 83,755
  • 16
  • 106
  • 147
  • And, if I keep typing once the `else:elif` construct is on my screen, it does not get retroactively fixed or corrected or removed. I just have the line `else:elif` in the middle of my Python. – Brandon Rhodes May 08 '14 at 20:11
  • Is there a newer version of Emacs available for your platform? The `python.el` shipped with my Emacs does not appear to contain a `python-indent-electric-colon` function. I can find it [in the `python.el` GitHub repository](https://github.com/fgallina/python.el/blob/master/python.el#L1056), but the latest revision there is a year old. The GNU Emacs source [does not seem to include that function anymore](http://bzr.savannah.gnu.org/lh/emacs/trunk/annotate/head:/lisp/progmodes/python.el#L1078). (I am also unable to reproduce your problem on my Emacs.) – ChrisGPT was on strike May 09 '14 at 00:48
  • The function `python-indent-electric-colon` is, on Ubuntu 14.04, defined in the file `/usr/share/emacs/24.3/lisp/progmodes/python.el.gz` which belongs to the package `emacs24-el` and it seems to be Emacs’s default mode now for editing Python. – Brandon Rhodes May 09 '14 at 01:03
  • It slipped my mind earlier, but I am not using the `emacs` package (version 24.3.1) but the `emacs-snapshot` package (version 24.3.50.1). `emacs-snapshot` does not have that function defined. Though even when I install and run the `emacs` version I am not seeing your described behaviour... – ChrisGPT was on strike May 09 '14 at 02:23

1 Answers1

1

I think this is a bug with the python-mode: tab-always-indent value is true but the behavior is the same that it was before.

https://www.gnu.org/software/emacs/manual/html_node/emacs/Indent-Convenience.html

My solution:

(add-hook 'python-mode-hook
    (lambda ()
        (setq-local electric-indent-chars (remq ?: electric-indent-chars))
    )
)
JAL
  • 41,701
  • 23
  • 172
  • 300
djangoliv
  • 1,698
  • 14
  • 26