- (if (<= pos-offset indent-column)
- (setq pos-offset indent-column))
-
- (while (< 0 indent-column)
- (insert " ")
- (setq indent-column (- indent-column 1)))
+(defun nagios-indent-to(indent-column)
+ "Indent the current line to column indent-column."
+ ;; Store the point in orig-pos.
+ (let ((orig-point (point)))
+
+ ;; And store the offset of the first character (with respect to the
+ ;; beginning of the line) in orig-first-char-offset.
+ (let ((orig-first-char-offset (nagios-first-char-offset)))
+
+ ;; Delete any leading whitespace, and move the point to the
+ ;; beginning of the line.
+ (delete-region (nagios-beginning-of-line-pos) (nagios-first-char-pos))
+ (beginning-of-line)
+
+ ;; Now insert indent-column spaces.
+ (let ((indent-remaining indent-column))
+ (while (< 0 indent-remaining)
+ (insert " ")
+ (setq indent-remaining (- indent-remaining 1)))
+ )
+
+ ;; The text on the current line just moved left/right some amount;
+ ;; call it text-delta. We want to move the point that same distance.
+ (let ((text-delta (- (nagios-first-char-offset) orig-first-char-offset)))
+ (goto-char (+ orig-point text-delta))
+ )
+
+ ;; The point should never wind up to the left of indent-column, so
+ ;; if it's there, move it over to indent-column.
+ (if (< (nagios-point-offset) indent-column)
+ (goto-char (+ (nagios-beginning-of-line-pos) indent-column))
+ )
+ )
+ )
+)