Gnus development mailing list
 help / color / mirror / Atom feed
* Re: [Message/code] Changing the subject to "new subject (was: old subject)" (was: ...)
       [not found] <wtn66y0o0fy.fsf@licia.dtek.chalmers.se>
@ 2000-01-11 12:31 ` Toby Speight
  0 siblings, 0 replies; only message in thread
From: Toby Speight @ 2000-01-11 12:31 UTC (permalink / raw)


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")))))




^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2000-01-11 12:31 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <wtn66y0o0fy.fsf@licia.dtek.chalmers.se>
2000-01-11 12:31 ` [Message/code] Changing the subject to "new subject (was: old subject)" (was: ...) Toby Speight

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).