14
votes

I am using emacs-for-python provided by gabrielelanaro at this link.

Indentation doesn't seem to be working for me at all.

It doesn't happen automatically when I create a class, function or any other block of code that requires automatic indentation(if, for etc.) and press enter or Ctrl + j. Instead emacs says "Arithmetic Error".

It doesn't happen when I press Tab anywhere in a .py file. Again, every Tab press causes "Arithmetic error".

Also, when I manually indent code using spaces, I can't erase those spaces! Backspace-ing these indents also causes "Arithmetic Error".

This problem surfaces when I use the regular Python AC mode as well.

emacs : GNU Emacs 24.3.1 (x86_64-pc-linux-gnu, GTK+ Version 3.10.7) of 2014-03-07 on lamiak, modified by Debian

3
Related to this issue maybe? Hard to say without knowing your configuration.vikramls
@vikramls How can I provide you with my configuration? I am new to emacs.Flame of udun
What I meant was the other packages that you have installed - can you run emacs without any init.el processing (emacs -q) and try selectively enabling packages? Did the issue I linked help?vikramls
I am not sure how to do that. Here is my .emacs file : pastebin.com/EebZhxWP. I guess you can tell which packages I am using with this.Flame of udun

3 Answers

24
votes

Check the value of python-indent-offset. If it is 0, change it M-x set-variable RET python-indent-offset RET 4 RET.

Emacs tries to guess the offset used in a Python file when opening it. It might get confused and set that variable to 0 for some badly-formatted Python file. If this is indeed the problem, please do file a bug report using M-x report-emacs-bug and the text of the Python file so that the auto-detection can be fixed.

8
votes

It is related to this bug

http://debbugs.gnu.org/cgi/bugreport.cgi?bug=15975

The quickest workaround which I found was too add Jorgens Answer into .emacs file, add the following at the end of your .emacs file

(add-hook 'python-mode-hook
  (lambda () (setq python-indent-offset 4)))
1
votes

Can you comment the lines related to auto-complete in your init.el?

; (add-to-list 'load-path "~/.emacs.d/auto-complete-1.3.1")
; (require 'auto-complete)
; (add-to-list 'ac-dictionary-directories "~/.emacs.d/ac-dict")
; (require 'auto-complete-config)
; (ac-config-default)
; (global-auto-complete-mode t)