FAQ
On Mon, 10 Nov 2003 00:41:35 GMT, G.A. wrote:
Rather than waiting around for an answer, I went ahead and made my
modifications to python-mode.el. While I've tweaked emacs lisp stuff in
the past, I've never been confidant about it, given the complexity of many
elisp packages. So now the question is whether they're good enough to put
back into the official version, and if so, how would I do that?

For what it's worth, I'm including the code below. It's relatively small,
a definition for py-tab-always-indent and a few lines changed in
py-indent-line.

Gary

(defcustom py-tab-always-indent t
"*Non-nil means TAB in Python mode should always reindent the current
line, regardless of where in the line point is when the TAB command is
used."
:type 'boolean
:group 'python)

(defun py-indent-line (&optional arg)
"Fix the indentation of the current line according to Python rules.
With \\[universal-argument] (programmatically, the optional argument
ARG non-nil), ignore dedenting rules for block closing statements
(e.g. return, raise, break, continue, pass)

This function is normally bound to `indent-line-function' so
\\[indent-for-tab-command] will call it."
(interactive "P")
(let* ((ci (current-indentation))
(move-to-indentation-p (<= (current-column) ci))
(need (py-compute-indentation (not arg))))
;; see if we need to dedent
(if (py-outdent-p)
(setq need (- need py-indent-offset)))
(if (or py-tab-always-indent
move-to-indentation-p)
(progn (if (/= ci need)
(save-excursion
(beginning-of-line)
(delete-horizontal-space)
(indent-to need)))
(if move-to-indentation-p (back-to-indentation)))
(insert-tab))))

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 2 of 3 | next ›
Discussion Overview
grouppython-list @
categoriespython
postedNov 10, '03 at 12:41a
activeNov 11, '03 at 9:53p
posts3
users2
websitepython.org

2 users in discussion

G.A.: 2 posts Skip Montanaro: 1 post

People

Translate

site design / logo © 2022 Grokbase