From xemacs-m  Wed Apr  2 15:56:16 1997
Received: from CNRI.Reston.VA.US (CNRI.Reston.VA.US [132.151.1.1])
	by xemacs.org (8.8.5/8.8.5) with SMTP id PAA28563
	for <xemacs-beta@xemacs.org>; Wed, 2 Apr 1997 15:56:15 -0600 (CST)
Received: from newcnri.cnri.reston.va.us by CNRI.Reston.VA.US id aa19784;
          2 Apr 97 16:55 EST
Received: from anthem.CNRI.Reston.Va.US by newcnri.CNRI.Reston.Va.US (SMI-8.6/SMI-SVR4)
	id QAA18051; Wed, 2 Apr 1997 16:55:41 -0500
Received: by anthem.CNRI.Reston.Va.US (SMI-8.6/SMI-SVR4)
	id QAA12787; Wed, 2 Apr 1997 16:55:40 -0500
Date: Wed, 2 Apr 1997 16:55:40 -0500
Message-Id: <199704022155.QAA12787@anthem.CNRI.Reston.Va.US>
From: "Barry A. Warsaw" <bwarsaw@CNRI.Reston.VA.US>
MIME-Version: 1.0
Content-Type: multipart/mixed;
	boundary="fcn9rRZLYv6U6ITttoprCS6PQWy9ZqmFyyLroWB0"
Content-Transfer-Encoding: 7bit
To: wmperry@aventail.com
Cc: Kyle Jones <kyle_jones@wonderworks.com>, xemacs-beta@xemacs.org
Subject: Re: mail mode nit
References: <E0wCVFF-0000sf-00@neal.ctd.comsat.com>
	<199704021829.KAA18549@newman>
	<QQcjop16442.199704021947@crystal.WonderWorks.COM>
	<199704022045.MAA20582@newman>
X-Mailer: VM 6.22 under 19.15 XEmacs Lucid
Reply-To: bwarsaw@python.org
X-Attribution: BAW
X-Oblique-Strategy: Go outside. Shut the door.
X-Url: http://www.python.org/~bwarsaw


--fcn9rRZLYv6U6ITttoprCS6PQWy9ZqmFyyLroWB0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit


Never let a good idea go unhacked.  Here's what I came up with,
supporting wrapping in both directions (bind TAB to
mail-mode-smart-tab and SHIFT-TAB to mail-mode-smart-tab-backwards).

-Barry


--fcn9rRZLYv6U6ITttoprCS6PQWy9ZqmFyyLroWB0
Content-Type: text/plain
Content-Disposition: inline;
	filename="p1"
Content-Transfer-Encoding: 7bit

(defun mail-mode-smart-tab ()
  (interactive)
  (let ((text-start (save-excursion (mail-text) (point)))
	(cnt 1))
    (if (>= (point) text-start)
	(tab-to-tab-stop)
      (while (< 0 cnt)
	(if (re-search-forward "^[^ \t]" text-start t)
	    (if (not (looking-at "[^:\n]+: ?"))
		(goto-char (point-min))
	      (goto-char (match-end 0))
	      (setq cnt (1- cnt)))
	  (mail-text))))))

(defun mail-mode-smart-tab-backwards ()
  (interactive)
  (let ((text-start (save-excursion (mail-text) (point)))
	(cnt -1))
    (if (>= (point) text-start)
	(tab-to-tab-stop)
      (while (> 0 cnt)
	(beginning-of-line)
	(if (re-search-backward "^[^ \t]" (point-min) t)
	    (if (looking-at "[^:\n]+: ?")
		(progn (goto-char (match-end 0))
		       (setq cnt (1+ cnt))))
	  (mail-text))))))

--fcn9rRZLYv6U6ITttoprCS6PQWy9ZqmFyyLroWB0--

