Emacs python mode equivalent to c-tab-always-indent

Discussion in 'Python' started by G.A., Nov 10, 2003.

  1. G.A.

    G.A. Guest

    Does anyone have a modification to python-mode.el that implements something
    along the lines of c-tab-always-indent? Currently, it a) gets the
    indentation wrong inside of """ module strings; and b) reindents the line
    if I try to use tabs inside subsequent lines of the """ comment string.

    I can live with the first problem but not the second. With c/c++ my
    solution is to set c-tab-always-indent to nil, which changes the behavior
    so that it only reindents the line if the cursor is in the leading
    whitespace, and otherwise it inserts a real tab (though a virtual tab is
    fine, too).

    Thanks,

    Gary
     
    G.A., Nov 10, 2003
    #1
    1. Advertising

  2. G.A.

    G.A. Guest

    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))))
     
    G.A., Nov 11, 2003
    #2
    1. Advertising

  3. Gary> Rather than waiting around for an answer, I went ahead and made my
    Gary> modifications to python-mode.el.

    Can you submit your patch to the python-mode project on SF:

    http://sf.net/projects/python-mode

    ?

    Thx,

    Skip
     
    Skip Montanaro, Nov 11, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Fouhy

    Emacs python mode indent levels

    John Fouhy, Jul 15, 2004, in forum: Python
    Replies:
    2
    Views:
    847
    John Lenton
    Jul 15, 2004
  2. dt
    Replies:
    4
    Views:
    495
    CBFalconer
    Dec 31, 2006
  3. Steven W. Orr
    Replies:
    4
    Views:
    314
    Carl Banks
    Apr 1, 2008
  4. Mike Shire
    Replies:
    6
    Views:
    265
    Carlo E. Prelz
    Apr 20, 2005
  5. Joe Peterson
    Replies:
    0
    Views:
    164
    Joe Peterson
    Dec 28, 2006
Loading...

Share This Page