(make-variable-buffer-local 'bbdb/news-auto-create-p)
(defsubst nix-backwards-string-match (string regexp)
"Like `string-match', but with inverted arguments."
(string-match regexp string))
(defadvice bbdb/gnus-update-records (around nix-bbdb-use-summary-buffer-news-auto-create-p activate preactivate)
"Propagate the value of `news-auto-create-p' from the Summary buffer.
This allows it to be buffer-local there, so that we can have different values of
this variable in different simultaneously active Summary buffers."
(let ((bbdb/news-auto-create-p
(symbol-value-in-buffer 'bbdb/news-auto-create-p gnus-summary-buffer)))
ad-do-it))
(defun nix-select-group-create-bbdb ()
"Set up this group to automatically create BBDB entries, if necessary.
Must be called from the `gnus-select-group-hook'."
(setq bbdb/news-auto-create-p
(if (and gnus-newsgroup-name
(not (member* gnus-newsgroup-name '("nnml:blockbox" "nnml:spambox" "nnmh:spambox-verified" "fm.announce"
"rec.humor.funny.reruns" "rec.humor.oracle") :test 'string=))
(not (member* gnus-newsgroup-name '("^nndoc:") :test 'nix-backwards-string-match)))
'bbdb-ignore-some-messages-hook nil)))
(defvar nix-bbdb-suppressed-groups '("nnml:blockbox" "nnml:spambox" "nnmh:spambox-verified")
"A list of newsgroups in which the BBDB is entirely deactivated.")
(defadvice bbdb/gnus-pop-up-bbdb-buffer (around nix-bbdb-suppress-bbdb activate preactivate)
"Suppress all BBDB operations in specific newsgroups."
(when (not (member gnus-newsgroup-name nix-bbdb-suppressed-groups))
ad-do-it))
(defvar nix-bbdb-make-permanent nil
"All BBDB records accessed while this is non-nil should be preserved forever.
You should bind or locally set this variable, never set it globally.")
(defun nix-bbdb-maybe-make-permanent (record)
"Make sure that the RECORD never expires."
(if (and nix-bbdb-make-permanent
(not (bbdb-record-getprop record 'permanent)))
(bbdb-record-putprop record 'permanent "t")))
(add-hook 'bbdb-notice-hook 'nix-bbdb-maybe-make-permanent)
(defadvice bbdb-annotate-message-sender (around nix-bbdb-use-summary-buffer-nix-bbdb-make-permanent activate preactivate)
"Propagate the value of `nix-bbdb-make-permanent' from the Summary buffer.
This allows it to be buffer-local there, so that we can have different values of
this variable in different simultaneously active Summary buffers."
(let ((nix-bbdb-make-permanent
(symbol-value-in-buffer 'nix-bbdb-make-permanent gnus-summary-buffer)))
ad-do-it))
(defun nix-select-group-permanent-bbdb ()
"BBDB entries seen in certain groups are never expired at all."
(if (string= gnus-newsgroup-name "nnml:Mailbox")
(progn (make-local-variable 'nix-bbdb-make-permanent)
(setq nix-bbdb-make-permanent t))))
(add-hook 'gnus-select-group-hook 'nix-select-group-create-bbdb)
(add-hook 'gnus-select-group-hook 'nix-select-group-permanent-bbdb)
(define-key message-minibuffer-local-map (kbd "<TAB>") 'bbdb-complete-name)
(provide 'dot-gnus-bbdb)