Gnus development mailing list
 help / color / mirror / Atom feed
From: Toby Speight <Toby.Speight@streapadair.freeserve.co.uk>
Subject: Re: [Message/code] Changing the subject to "new subject (was: old subject)" (was: ...)
Date: 11 Jan 2000 12:31:43 +0000	[thread overview]
Message-ID: <upuv823io.fsf@lanber.cam.eu.citrix.com> (raw)
In-Reply-To: <wtn66y0o0fy.fsf@licia.dtek.chalmers.se>

Jonas> Jonas Steverud <URL:mailto:d4jonas@dtek.chalmers.se>

0> In article <wtn66y0o0fy.fsf@licia.dtek.chalmers.se>, Jonas wrote:

Jonas> Something I sometimes do is changing a subject from "Re: old"
Jonas> to "new (was: Re: old)". I have now written a function that
Jonas> does it for me.  js-gnus-message-change-subject-was is used
Jonas> when you speak other language then English.

I have a longer version of this function, which does the above but
doesn't include any "Re: " in the old-subject part - readers can infer
that.  It also offers to strip the (was...) part from an existing
subject (useful when the thread has drifted completely away from the
original topic, and you don't want it to be affected by people's score
files for the original).  And it shortens the old subject to fit it
onto one reasonable-length line, if possible.

To change this to use a variable for the word "was" would be easy;
adjusting the "(was...)" stripping regexps to remove other variants
may be tricky.

The code is suitable for use in `message-send-hook'; I recommend that
if you also spell-check your articles, you ensure that this function
appears first in the hook.


(defun message-change-subject-interactively (&optional new-subj)
  "Change the Subject, bracketing with \"(was...)\" if necessary."
  (interactive "*")
  (undo-boundary)
  (save-excursion
    (message-narrow-to-headers-or-head)
    (let* ((subject (message-fetch-field "Subject"))
           (case-fold-search t))
    (if (null subject)
        (setq new-subj (read-from-minibuffer "New Subject: "))
      ;; There was already a subject
      (when (string-match "\\s-+\\'" subject) ; remove trailing spaces
        (setq subject (replace-match "" t t subject)))
      (if (and (not new-subj) (string-match "^[Rr][Ee]\\>" subject))
          ;; only ask if it wasn't our subject
          (setq new-subj
                (read-from-minibuffer (concat "New Subject: (was " subject ") "))))
      ;; new-subj is nil if we already have an original subject (not starting with "Re:")
      ;; It is a string if we are following-up (so might want to remove "(was ...)")
      (if (and new-subj
               (or                      ;(re-search-forward "\\s-*\\((was\\>.*\\)" subject-end t)
                (string-match "\\s-*[[(,;]\\s-*\\(was\\>.*\\)" subject)
                (string-match "\\s-*\\<\\(was:?\\s-+[Rr][Ee]:.*\\)" subject)
                (string-match "\\s-*[[(,;]\\s-*\\([Rr][Ee]:.*\\)" subject))
               (or (not (string= new-subj "")) ; if replacing, force removal
                   (y-or-n-p (concat "Remove \"" (match-string 1) "\" from Subject: line? "))))
          (setq new-subj (replace-match "" t t subject)
                subject ""))
      (when (or (null new-subj) (string= "" new-subj))
        (setq new-subj subject
              subject ""))
      ;; undo RFC-822 line-wrap
      (while (string-match "\n[ \t]" subject)
        (setq subject (replace-match " " t t subject)))
      ;; might be a followup to a forwarded message, so trim [...] too
      (while (string-match "\\`\\(\\(Re\\|Fwd\\|AW\\)\\>[.:]?\\|\\[[^][]+\\]\\|[ \t\r]+\\)" subject)
        (setq subject (replace-match "" t t subject)))
      ;; Trim subject line to 75 chars (leaving room for a recipient to add "Re: ")
      ;; "Subject: "(9) + new-subj + "(was: "(6) + subject + "...)"(1 or 4)  <=75
      ;; means subject<=(59 - new-subj) or trim to (56 - new-subj)
      (if (> (length subject) (- 59 (length new-subj)))
        (let ((maxlen (- 56 (length new-subj))))
          (if (<= maxlen 0)
              (setq subject "...")
            ;; keep one extra char, so we know if last char is a word-boundary
            (setq subject (substring subject 0 (1+ maxlen)))
            (if (string-match "\\s-*\\(\\B.\\|\\<.\\)*\\'" subject)
                (setq subject (replace-match "" t t subject)))))))
    (widen)
    (when new-subj
      (if (and subject (not (string= "" subject)))
          (setq new-subj (concat new-subj " (was: " subject ")")))
      (message-goto-subject)
      (message-delete-line)
      (insert "Subject: " new-subj "\n")))))




           reply	other threads:[~2000-01-11 12:31 UTC|newest]

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <wtn66y0o0fy.fsf@licia.dtek.chalmers.se>]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=upuv823io.fsf@lanber.cam.eu.citrix.com \
    --to=toby.speight@streapadair.freeserve.co.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).