- (funcall indent-line-function))
-
-(defun indent-for-tab-command (&optional prefix-arg)
- "Indent line in proper way for current major mode."
+ (if (memq indent-line-function
+ '(indent-relative indent-relative-maybe))
+ ;; These functions are used for tabbing, but can't be used for
+ ;; indenting. Replace with something ad-hoc.
+ (let ((column (save-excursion
+ (beginning-of-line)
+ (skip-chars-backward "\n \t")
+ (beginning-of-line)
+ (current-indentation))))
+ (if (<= (current-column) (current-indentation))
+ (indent-line-to column)
+ (save-excursion (indent-line-to column))))
+ ;; The normal case.
+ (funcall indent-line-function)))
+
+(defun indent-for-tab-command (&optional arg)
+ "Indent line in proper way for current major mode or insert a tab.
+Depending on `tab-always-indent', either insert a tab or indent.
+If initial point was within line's indentation, position after
+the indentation. Else stay at same point in text.
+The function actually called to indent is determined by the value of
+`indent-line-function'."