1

I often write python code in which a function returns a value. Often I will define that value higher up in the code as "returnvalue" or some similar name.

Then the next line is indented differently. This is because emacs believes (falsely) that I just used the command "return value"

I end up with things like this:

def square(x):
    returnvalue = x*x
return returnvalue

where it should be

def square(x):
    returnvalue = x*x
    return returnvalue

Since indentation level is fundamentally important for python, this is a big deal.

I really like the auto-indenting, but I'd either like to somehow get it to recognize that if return isn't followed by white space, it should treat it as any other line of code. Alternately I'd like it to simply not treat return as a special word at all. Is this possible?

More information:

For what it's worth, I'm using Aquamacs (on Mac OS X). In ~/Library/Preferences/Aquamacs Emacs/ it says

(custom-set-variables
  ;; custom-set-variables was added by Custom.
  ;; If you edit it by hand, you could mess it up, so be careful.
  ;; Your init file should contain only one such instance.
  ;; If there is more than one, they won't work right.
 '(aquamacs-additional-fontsets nil t)
 '(aquamacs-customization-version-id 215 t)
 '(aquamacs-tool-bar-user-customization nil t)
 '(default-frame-alist (quote ((fringe) (right-fringe) (left-fringe . 1) (internal-border-width . 0) (vertical-scroll-bars . right) (cursor-type . box) (menu-bar-lines . 1) (tool-bar-lines . 1) (background-color . "black") (background-mode . dark) (border-color . "black") (cursor-color . "yellow") (foreground-color . "white") (mouse-color . "sienna1"))))
 '(ns-tool-bar-display-mode (quote both) t)
 '(ns-tool-bar-size-mode (quote regular) t)
 '(visual-line-mode nil t))
(custom-set-faces
  ;; custom-set-faces was added by Custom.
  ;; If you edit it by hand, you could mess it up, so be careful.
  ;; Your init file should contain only one such instance.
  ;; If there is more than one, they won't work right.
 '(autoface-default ((t (:inherit default))))
 '(fundamental-mode-default ((t (:inherit autoface-default))) t))

I don't have a .emacs file and ~/Library/Preferences/Aquamacs Emacs/Preferences.el is empty. When I run emacs from the terminal command line it opens in the window and doesn't automatically indent.

  • This could be helpful: emacs.stackexchange.com/questions/9563/… – Konstantin Morenko Jul 25 '16 at 17:04
  • I can't reproduce this in Emacs 25.1 (release candidate). When I type returnvalue = x*x and press return, it stays indented. It's only after the return returnvalue line that it stops indenting. – amitp Jul 25 '16 at 17:56
  • @amitp Here is the version I've got (from "about"): "Aquamacs is a distribution of GNU Emacs that is adapted for Mac users. GNU Emacs 23.3.50.1 (i386-apple-darwin9.8.0, NS apple-appkit-949.54) of 2011-10-25 on braeburn.aquamacs.org - Aquamacs Distribution 2.4 Copyright (C) 2011 Free Software Foundation, Inc." I don't believe I've done anything interesting to the configurations. – Joel Jul 25 '16 at 18:03
  • 1
    @Joel It's quite possible they've fixed a bug since 2011. However I also tested with Emacs 22.1.1 and didn't have the problem there either. Are you testing with emacs -q? – amitp Jul 25 '16 at 22:19
  • Thanks @amitp I've edited to explain how I'm running, but basically I don't open from the command line. I'm using Aquamacs. – Joel Jul 26 '16 at 2:09

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.