There are two major variants of
Also see ProgrammingWithPythonModeDotEl for the python-mode distributed with python.
In python-mode.el RET is bound to py-newline-and-indent, which indents the next line if necessary. In python.el this is bound to C-j instead. You can get the previous behavior with this in your InitFile:
(add-hook 'python-mode-hook '(lambda () (define-key python-mode-map "\C-m" 'newline-and-indent)))
Using python-complete-symbol in the inferior python buffer causes an infinite loop in python.el as of 080117, changing python-imports from the default nil to ‘None’ solves this. 2008-01-17, patch submitted.
:Iâm a little confused - It appears when I set flymake-mode to be automatically on for python mode, py-help-at-point doesnât work. I tried switching from python-mode.el to python.el, but not this doesnât seem to solve it; However, there is no advice here on how to use python.el, so Iâm not entirely sure Iâm doing it right…
see this post
‘python-describe-symbol’ tries to get doc in the context of what the source file imports (be sure to first run the Python interpreter [C-c !]).
CEDET is now part of emacs (but I still recommend getting the latest version). It includes things, like completion, and folding, such that some things here may not be required.
python.el includes a regexp for outliner-mode, and hs-mode too.
Since indentation is significant in python, correct indent functions are vital, thought these might overload the tab key.
python-end-of-block instead of py-next-block?
The following will integrate python.el completions with auto-complete. You need to have installed and loaded auto-complete.el first:
(defvar ac-source-python '((candidates . (lambda () (mapcar '(lambda (completion) (first (last (split-string completion "\\." t)))) (python-symbol-completions (python-partial-symbol)))))))
(add-hook 'python-mode-hook (lambda() (setq ac-sources '(ac-source-python))))
It seems like point has to be at the very bottom, with a clear prompt, for python-send-region to work. Here’s a quick hack that does that before calling the function, and puts it back the way it was afterwards:
(defadvice python-send-region (around advice-python-send-region-goto-end) "Fix a little bug if the point is not at the prompt when you do C-c C-[rc]" (let ((oldpoint (with-current-buffer (process-buffer (python-proc)) (point))) (oldinput (with-current-buffer (process-buffer (python-proc)) (goto-char (point-max)) ;; Do C-c C-u, but without modifying the kill ring: (let ((pmark (process-mark (get-buffer-process (current-buffer))))) (when (> (point) (marker-position pmark)) (let ((ret (buffer-substring pmark (point)))) (delete-region pmark (point)) ret)))))) ad-do-it (with-current-buffer (process-buffer (python-proc)) (when oldinput (insert oldinput)) (goto-char oldpoint)))) (ad-enable-advice 'python-send-region 'around 'advice-python-send-region-goto-end) (ad-activate 'python-send-region)