[Python-mode] [ python-mode-Patches-875046 ] py-tab-always-indent implementation

SourceForge.net noreply at sourceforge.net
Sun Jan 11 15:29:39 EST 2004


Patches item #875046, was opened at 2004-01-11 15:29
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=581351&aid=875046&group_id=86916

Category: None
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Gary Feldman (garyfx)
Assigned to: Nobody/Anonymous (nobody)
Summary: py-tab-always-indent implementation

Initial Comment:
This patch address the issue I raised in
http://groups.google.com/groups?hl=en&threadm=mrb2rvk73vu4jfebaelglq257n2p7q5gaf%404ax.com
, specifically to provide behavior similar to the C
mode c-tab-always-indent, because the previous
implementation had no way of setting the tab key to
insert tabs in the body of a """ string while keeping
the automatic indentation behavior at the beginning of
the line.

I've attached a diff file for the differences against
4.49, but for ease of reading, and because the patch is
so small, here are the changes:

(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))))

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=581351&aid=875046&group_id=86916



More information about the Python-mode mailing list