[comp.emacs] Rmail modifications

john@wpi.wpi.edu (John F Stoffel) (02/15/89)

I'm havinbg a problem modifying RMAIL to use the '>' symbol when I'm
replying to a message and yanking it in to serve as reference.  RMAIL
just likes to indent with a TAB (or 4 or 5 spaces, doesn't matter,
same effect) and I'd like to change it to a more concise format.  If
you could please help me with this, I'd be in mucho debt to all of you
out there.  Thanks for your time and effort on this!

BTW, calendar is great!  Still learning it, but getting to like it
more and more!

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
	Boy... what we have here is a failure to communicate!
					- Warden of "Cool Hand Luke"
John Stoffel
BITNET   John@wpi.bitnet
INTERNET john@wpi.wpi.edu
UUCP     {husc6}!m2c!wpi!john
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Ram-Ashwin@cs.yale.edu (Ashwin Ram) (02/15/89)

In article <817@wpi.wpi.edu>, john@wpi.wpi.edu (John F Stoffel) writes:
> I'm havinbg a problem modifying RMAIL to use the '>' symbol when I'm
> replying to a message and yanking it in to serve as reference.

I think mail-yank-original ought to have a hook (say, mail-yank-hook) that
would allow the user to do stuff like this.  Anyway, I use a variable to
indicate the yank prefix (usually "   " by default, but you would setq it to
"> " or whatever).  In the code below, I have also added mail-yank-hook for
other customizations you might want to do.

-----------------------------------------------------------------------------
;; Ashwin Ram, 2/14/89.

(defvar mail-yank-prefix "> "
   "String to prefix every line in a yanked message.")

(defun mail-yank-original (arg)
  "Insert the message being replied to, if any (in rmail).
Puts point before the text and mark after.
Prefix each line with mail-yank-prefix.
Just \\[universal-argument] as argument means don't indent
and don't delete any header fields."
  (interactive "P")
  (if mail-reply-buffer
      (let ((start (point)))
	(delete-windows-on mail-reply-buffer)
	(insert-buffer mail-reply-buffer)
	(if (consp arg)
	    nil
	  (mail-yank-clear-headers start (mark)))
	(exchange-point-and-mark)
        (delete-region (point) ; Remove trailing blank lines.
                       (progn (re-search-backward "[^ \^I\^L\n]")
                              (end-of-line)
                              (point)))
        (mail-prefix-region (mark) (point)) ; Highlight original message.
        (insert ?\n)
        (run-hooks 'mail-yank-hook))))

(defun mail-yank-clear-headers (start end)
   (save-excursion
      (goto-char start)
      (if (search-forward "\n\n" end t)
          (delete-region start (point)))))

(defun mail-prefix-region (beg end)
   "Prefix region with mail-yank-prefix."
   (interactive "r")
   (save-excursion
      (save-restriction
         (narrow-to-region beg end)
         (goto-char (point-min))
         (while (re-search-forward "^" (point-max) t)
            (replace-match mail-yank-prefix t t)))))
-----------------------------------------------------------------------------

Hope this helps.

-- Ashwin.

neitzel@infbs.uucp (Martin Neitzel) (02/16/89)

>In article <817@wpi.wpi.edu> john@wpi.wpi.edu (John F Stoffel) writes:
john>	
john>	I'm having a problem modifying RMAIL to use the '>' symbol
john>	when I'm replying to a message and yanking it in to serve as
john>	reference.  RMAIL just likes to indent with a TAB (or 4 or 5
john>	spaces, doesn't matter, same effect) and I'd like to change it
john>	to a more concise format.

Simple problem, long discussion, simple solution.

Ashwin Ram had posted some code some time ago, that does just what
John is asking for.  Based on this re-write of mail-yank-original, I
was able to add support for my own preferred citation style.  You
have just seen it, and you will read a more elaborate rationale for it
later.

What follows are some notes how Ashwin's version relates to the
original and my to Ashwin's.  The remarks about my citation style are
obviously written with .PROSELYTIZE ON, but I beg you to read these
lines, too.  And after all this stuff, you get the code.  (Perhaps the
``GNU staff'' might consider if they want to join the Small-But-Growing-
Help-Stamp-Out-Nested-Citation-Movement and put this code in this form
or another into the distributed mail-yank-original.  They are invited
to do it.)

						   	Martin

>From: ram-ashwin@YALE.ARPA (Ashwin Ram)
>Newsgroups: gnu.emacs.bug
>Subject: MAIL-YANK-ORIGINAL enhancements
>Posted: Tue Oct 25 16:05:01 1988
Ashwin>	
Ashwin>	When replying to a mail message, it would be nice to have a
Ashwin>	way to highlight the original message with ">" in the first
Ashwin>	column as many mailers do.

I agree with Ashwin and John that the highlight prefix should be
choosable, at least something other than emacs' spaces.  However, I
can't stand those nested citations that the rest of the world seems to
love:

	   In article 123, foo writes:
	   >In article 122, bar writes:
	   >>In article 121, zonk writes:
	   >>> [emacs]
	   These bozos... [more lotsa stuff]
	   >> [vi]
	   > [Emacs]
	   >> [oh no not again]
	   I for one, must tell you...

Usually I loose track when the third person jumps into the discussion.
Often sooner.  WHO is saying WHAT about WHOM ???  (Nested citations
have their use in meta-discussions, but are often overused and seldom
necessary.)

As you might have noticed already, I usually put the author's initials
or something like that before all cited lines.  Lines that are already
citations stay untouched, so they don't get nested.  Only the lines by
the last author get their new prefix.

Obviously this is a little more than ``many mailers do'', and so
nobody cares about it.  Actually, it is only a 2-liner in "ed":

v/^[a-zA-Z]*>/s/^/Ashwin>	/
g/^Ashwin>	$/s///

Only a heuristic, but quite okay and adaptable.  Furthermore, I could
wrap it into a more user-friendly elisp-function.  I called it
mail-cite-region.

Ashwin>	mail-prefix-region is separated out since it is nice to bind it
Ashwin>	to a key so that you can mark a region and indent it by hand.
Ashwin>	^C^I (I for Indent) is the key I use for this.  (Idea stolen from
Ashwin>	gnews).

And it made it easy for me to clone mail-prefix-region into my
function mail-cite-region.  Since the mail-yank-prefix is very likely
to change from reply to reply, I dropped it again.


------ snip here, and call it mail-yank.el ("or Pinocchio or what?") -----
---- then, (require 'mail-yank) in your rmail-mode-hook ------------------

; Copyright (C) 1989 by Free Software Foundation, Ashwin Ram, Martin
; Neitzel.  The standard GNU General Public License applies.  Even if
; it is called something different this week...

; Make sure that we re-define the original mail-yank-original
(provide 'mail-yank)
(require 'sendmail)

(defvar mail-cited-line-re "[a-zA-Z]*>"

  "*Regexp that tells how the beginning of an already cited line in a
mail or news article looks like.  Used in mail-cite-region to prevent
nestings of already marked citations.  This regexp is only used at the
beginning of a line, so it needn't begin with a '^'.")

(defun mail-yank-original (arg)
  "Insert the message being replied to, if any (in rmail).
Puts point before the text and mark after.
Just \\[universal-argument] as argument means don't delete any header fields."
  (interactive "P")
  (if mail-reply-buffer
      (let ((start (point)))
	(delete-windows-on mail-reply-buffer)
	(insert-buffer mail-reply-buffer)
	(if (consp arg)
	    nil
	  (mail-yank-clear-headers start (mark)))
	(exchange-point-and-mark)
        (delete-region (point) ; Remove trailing blank lines.
                       (progn (re-search-backward "[^ \^I\^L\n]")
                              (end-of-line)
                              (point)))
        (insert ?\n)
	(call-interactively 'mail-cite-region)
        (run-hooks 'mail-yank-hook))))

(defun mail-cite-region (beg end authorname)
  "Prefix region with a citation mark, prevententing nested citations."
  (interactive "r\nsShort name or initials of Author? ")
  (setq authorname (concat authorname ">\t"))
  (save-excursion
    (save-restriction
      (narrow-to-region beg end)
      (goto-char beg)
      (while (not (eobp))
	(if (or (eolp) (looking-at mail-cited-line-re))
	    ()
	  (insert authorname))
	(forward-line 1)))))

;;; lucky guy!, the end-of-file hasn't been trunca
--
Martin Neitzel,  Techn. Univ. Braunschweig, W.Germany
BITNET/EARN:	neitzel@dbsinf6.bitnet	  (mail via bitnet preferred)
UUCP:		neitzel@infbs.uucp  (unido!infbs!neitzel)