Rod> Jamie, do you intend to include the second part of the patch
    Rod> in BBDB distribution (the part that allows the STRING field
    Rod> of the auto-notes-alist record to be a string, integer or
    Rod> function) ?

    Jamie> Sure, looks fine.

    Joe> Here is a small suggestion.  If the item is a function, the
    Joe> function should be called with a buffer and region rather
    Joe> than with a string, to avoid making strings.

My intention is to allow the user to either:

1/ Munge the string returned from the field before it is stored in the
   BBDB record (i.e. add spaces after the commas in a `Newsgroups:'
   field).

2/ Generate a completely new string to be stored in the BBDB record
   (i.e. extract the value of an `Archive-name:' auxiliary header).

As `fieldval' is already available as a string (it is made on line 345
of bbdb-hooks.el), why is it better to pass a buffer and region ?

Jamie, here is a reworked patch for bbdb-hooks (against virgin 1.48)
which adds the new function calling stuff (I fixed a few bugs), and
also defines a function that can be used to extract auxiliary headers
(i.e.  the `Archive-name:' header):

===================================================================
RCS file: /home/bing/rwhitby/src/elib/bbdb/RCS/bbdb-hooks.el,v
retrieving revision 1.1.1.2
diff -c -r1.1.1.2 /home/bing/rwhitby/src/elib/bbdb/bbdb-hooks.el
*** 1.1.1.2     1993/04/07 01:08:35
--- /home/bing/rwhitby/src/elib/bbdb/bbdb-hooks.el      1993/08/05 05:45:19
***************
*** 114,119 ****
--- 114,136 ----
      done))
  
  
+ (defun bbdb-extract-auxiliary-field-value (field-name)
+   "Given the name of a auxiliary field (like \"Archive-name\") this returns
+ the value of that field in the current message, or nil.  This works whether
+ you're in GNUS, Rmail, or VM.  This works on multi-line fields, but if more
+ than one auxiliary field of the same name is present, only the last is
+ returned.  It is expected that the current buffer has a message in it, and
+ that (point) is at the beginning of the message headers."
+   ;; Skip to the start of the body
+   (re-search-forward "\n\n" (point-max) 'move)
+   ;; Skip any extra empty lines
+   (while (looking-at "^$")
+     (forward-line 1))
+   ;; Extract the auxiliary field
+   (bbdb-extract-field-value field-name)
+   )
+ 
+ 
  (defvar bbdb-ignore-most-messages-alist '()
    "*An alist describing which messages to automatically create BBDB
  records for.  This only works if bbdb/news-auto-create-p or 
***************
*** 226,236 ****
--- 243,260 ----
          (\"Organization\" (\".*\" company \"\\\\&\"))
  
  \(Note you need two \\ to get a single \\ into a lisp string literal.\)
+ 
  If STRING is an integer N, the N'th matching subexpression is used, so
  the above example could be written more efficiently as
  
          (\"Organization\" (\".*\" company 0))
  
+ If STRING is neither a string or an integer, it should be a function
+ which is called with the contents of the field, and the result of the
+ function call is used.  So the above example could also be written as
+ 
+         (\"Organization\" (\".*\" company '(lambda (fieldval) fieldval)))
+ 
  If REPLACE-P is t, the string replaces the old contents instead of
  being appended to it.
  
***************
*** 340,354 ****
                                  (not (string-match re fieldval))
                                t)))))
                  ;; An integer as STRING is an index into match-data: 
                  (if did-match
                      (setq string
!                           (if (integerp string) ; backward compat
!                               (substring fieldval
!                                          (match-beginning string)
!                                          (match-end string))
!                             (bbdb-auto-expand-newtext fieldval string))))
                  ;; need expanded version of STRING here:
                  (if (and did-match
                           (not (and notes
                                     ;; check that STRING is not already
                                     ;; present in the NOTES field
--- 364,385 ----
                                  (not (string-match re fieldval))
                                t)))))
                  ;; An integer as STRING is an index into match-data: 
+                 ;; A function as STRING calls the function on fieldval: 
                  (if did-match
                      (setq string
!                           (cond ((integerp string) ; backward compat
!                                  (substring fieldval
!                                             (match-beginning string)
!                                             (match-end string)))
!                                 ((stringp string)
!                                  (bbdb-auto-expand-newtext fieldval string))
!                                 (t
!                                  (goto-char marker)
!                                  (funcall string fieldval))
!                                 )))
                  ;; need expanded version of STRING here:
                  (if (and did-match
+                          string ; A function as STRING may return nil
                           (not (and notes
                                     ;; check that STRING is not already
                                     ;; present in the NOTES field
===================================================================

--
--------------------------------------------- _--_|\  |
Rod Whitby ([EMAIL PROTECTED])    /      \ |
Canon Information Systems Research Australia \_.--._/ |
1 Thomas Holt Drive, North Ryde, N.S.W., 2113.     v  |

Reply via email to