Oops.  I am using a bizarre frob you may not want.  I fixed the FSF emacs
just now; use this replacement function until the next release:

(defun mail-fcc (folder)
  "Add a new FCC field, with file name completion."
  (interactive "FFolder carbon copy: ")
  (expand-abbrev)
  (or (mail-position-on-field "fcc" t)  ;Put new field after exiting FCC.
      (mail-position-on-field "to"))
  (insert "\nFCC: " folder))

What I in fact use is this:

;;; vm-fcc.el -- mail-fcc command for VM users.
;;; Copyright (C) 1992 Roland McGrath
;;; Based on code from vm-summary.el, version 5.32 beta.
;;; Copyright (C) 1989, 1990 Kyle E. Jones
;;;
;;; This program is free software; you can redistribute it and/or modify
;;; it under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 2, or (at your option)
;;; any later version.
;;;
;;; This program is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; A copy of the GNU General Public License can be obtained from this
;;; program's author (send electronic mail to [EMAIL PROTECTED]) or
;;; from the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA
;;; 02139, USA.
;;;
;;; Send bug reports to [EMAIL PROTECTED]
;;;
;;; This is a mail-fcc function, bound to C-c C-f C-f in mail-mode,
;;; that gives you completion on the folder name, looking by default
;;; in your vm-folder-directory.  It uses vm-auto-folder-alist to pick
;;; a default folder.

;;; From vm-summary.el
(defun vm-match-data ()
  (let ((index '(9 8 7 6 5 4 3 2 1 0))
        (list))
    (while index
      (setq list (cons (match-beginning (car index))
                       (cons (match-end (car index)) list))
            index (cdr index)))
    list))

(defun mail-fcc-auto-select-folder (auto-folder-alist)
  (catch 'match
    (let (header alist tuple-list)
      (setq alist auto-folder-alist)
      (while alist
        (setq header (mail-get-header-contents (car (car alist))))
        (if (null header)
            ()
          (setq tuple-list (cdr (car alist)))
          (while tuple-list
            (if (let ((case-fold-search
                       (if (boundp 'vm-auto-folder-case-fold-search)
                           vm-auto-folder-case-fold-search
                         case-fold-search)))
                  (not (equal (mapcar (lambda (header)
                                        (string-match (car (car tuple-list))
                                                      header))
                                      header)
                              (make-list (length header) nil))))
                ;; Don't waste time eval'ing an atom.
                (if (atom (cdr (car tuple-list)))
                    (throw 'match (cdr (car tuple-list)))
                  (let* ((match-data (vm-match-data))
                         (buf (get-buffer-create " *VM scratch*"))
                         (result))
                    ;; Set up a buffer that matches our cached
                    ;; match data.
                    (save-excursion
                      (set-buffer buf)
                      (widen)
                      (erase-buffer)
                      (apply 'insert header)
                      ;; It appears that get-buffer-create clobbers the
                      ;; match-data.
                      ;;
                      ;; The match data is off by one because we matched
                      ;; a string and Emacs indexes strings from 0 and
                      ;; buffers from 1.
                      ;;
                      ;; Also store-match-data only accepts MARKERS!!
                      ;; AUGHGHGH!!
                      (store-match-data
                       (mapcar
                        (function (lambda (n) (and n (vm-marker n))))
                        (mapcar
                         (function (lambda (n) (and n (1+ n))))
                         match-data)))
                      (setq result (eval (cdr (car tuple-list))))
                      (throw 'match
                             (if (listp result)
                                 (mail-fcc-auto-select-folder result)
                               result))))))
            (setq tuple-list (cdr tuple-list))))
        (setq alist (cdr alist)))
      nil)))

(defvar mail-fcc-header "FCC"
  "*Header inserted by \\[mail-fcc].")

(defun mail-fcc (folder)
  "Add a new FCC field for FOLDER, with file name completion."
  (interactive (list (let ((default (mail-fcc-auto-select-folder
                                     vm-auto-folder-alist)))
                       (read-file-name
                        (if default
                            (format "Folder carbon copy (default %s): "
                                    default)
                          "Folder carbon copy: ")
                        vm-folder-directory 
                        (and default
                             (expand-file-name default
                                               vm-folder-directory))))))
  (expand-abbrev)
  (save-excursion
    (or (mail-position-on-field "fcc" t) ;Put new field after exiting FCC.
        (mail-position-on-field "to"))
    (insert "\n" mail-fcc-header ": " folder)))

(define-key mail-mode-map "\C-c\C-f\C-f" 'mail-fcc)

(provide 'vm-fcc)

Reply via email to