Function: sc-select-attribution
sc-select-attribution is a byte-compiled function defined in
supercite.el.gz.
Signature
(sc-select-attribution)
Documentation
Select an attribution from sc-attributions.
Variables involved in selection process include:
sc-preferred-attribution-list
sc-use-only-preference-p
sc-confirm-always-p
sc-default-attribution
sc-attrib-selection-list.
Runs the hook sc-attribs-preselect-hook before selecting an
attribution and the hook sc-attribs-postselect-hook after making the
selection but before querying is performed. During
sc-attribs-postselect-hook the variable citation is bound to the
auto-selected citation string and the variable attribution is bound
to the auto-selected attribution string.
Source Code
;; Defined in /usr/src/emacs/lisp/mail/supercite.el.gz
(defvar completer-disable) ;; From some `completer.el' package.
(defun sc-select-attribution ()
"Select an attribution from `sc-attributions'.
Variables involved in selection process include:
`sc-preferred-attribution-list'
`sc-use-only-preference-p'
`sc-confirm-always-p'
`sc-default-attribution'
`sc-attrib-selection-list'.
Runs the hook `sc-attribs-preselect-hook' before selecting an
attribution and the hook `sc-attribs-postselect-hook' after making the
selection but before querying is performed. During
`sc-attribs-postselect-hook' the variable `citation' is bound to the
auto-selected citation string and the variable `attribution' is bound
to the auto-selected attribution string."
(run-hooks 'sc-attribs-preselect-hook)
(with-suppressed-warnings ((lexical citation attribution))
(defvar citation) (defvar attribution))
(let ((query-p sc-confirm-always-p)
attribution citation
(attriblist sc-preferred-attribution-list))
;; first cruise through sc-preferred-attribution-list looking for
;; a match in either sc-attributions or sc-mail-info. if the
;; element is "sc-consult", then we have to do the alist
;; consultation phase
(while attriblist
(let* ((preferred (car attriblist)))
(cond
((string= preferred "sc-consult")
;; we've been told to consult the attribution vs. mail
;; header key alist. we do this until we find a match in
;; the sc-attrib-selection-list. if we do not find a match,
;; we continue scanning attriblist
(let ((attrib (sc-scan-info-alist sc-attrib-selection-list)))
(cond
((not attrib)
(setq attriblist (cdr attriblist)))
((stringp attrib)
(setq attribution attrib
attriblist nil))
((listp attrib)
(setq attribution (eval attrib t))
(if (stringp attribution)
(setq attriblist nil)
(setq attribution nil
attriblist (cdr attriblist))))
(t (error "%s did not evaluate to a string or list!"
"sc-attrib-selection-list")))))
((setq attribution (cdr (assoc preferred sc-attributions)))
(setq attriblist nil))
(t
(setq attriblist (cdr attriblist))))))
;; if preference was not found, we may use a secondary method to
;; find a valid attribution
(if (and (not attribution)
(not sc-use-only-preference-p))
;; secondary method tries to find a preference in this order
;; 1. sc-lastchoice
;; 2. x-attribution
;; 3. firstname
;; 4. lastname
;; 5. initials
;; 6. first non-empty attribution in alist
(setq attribution
(or (cdr (assoc "sc-lastchoice" sc-attributions))
(cdr (assoc "x-attribution" sc-attributions))
(cdr (assoc "firstname" sc-attributions))
(cdr (assoc "lastname" sc-attributions))
(cdr (assoc "initials" sc-attributions))
(cdr (car sc-attributions)))))
;; still couldn't find an attribution. we're now limited to using
;; the default attribution, but we'll force a query when this happens
(if (not attribution)
(setq attribution sc-default-attribution
query-p t))
;; create the attribution prefix
(setq citation (sc-make-citation attribution))
;; run the post selection hook before querying the user
(run-hooks 'sc-attribs-postselect-hook)
;; query for confirmation
(if query-p
(let* ((query-alist (mapcar (lambda (entry) (list (cdr entry)))
sc-attributions))
(minibuffer-local-completion-map
sc-minibuffer-local-completion-map)
(minibuffer-local-map sc-minibuffer-local-map)
(initial attribution)
(completer-disable t) ; in case completer.el is used
choice)
(setq sc-attrib-or-cite nil) ; nil==attribution, t==citation
(while
(catch 'sc-reconfirm
(progn
(setq choice
(if sc-attrib-or-cite
(read-string
"Enter citation prefix: "
citation
'sc-citation-confirmation-history)
(completing-read
"Complete attribution name: "
query-alist nil nil
(cons initial 0)
'sc-attribution-confirmation-history)))
nil)))
(if sc-attrib-or-cite
;; since the citation was chosen, we have to guess at
;; the attribution
(setq citation choice
attribution (or (sc-guess-attribution citation)
citation))
(setq citation (sc-make-citation choice)
attribution choice))))
;; its possible that the user wants to downcase the citation and
;; attribution
(if sc-downcase-p
(setq citation (downcase citation)
attribution (downcase attribution)))
;; set up mail info alist
(let* ((ckey "sc-citation")
(akey "sc-attribution")
(ckeyval (assoc ckey sc-mail-info))
(akeyval (assoc akey sc-mail-info)))
(if ckeyval
(setcdr ckeyval citation)
(push (cons ckey citation) sc-mail-info))
(if akeyval
(setcdr akeyval attribution)
(push (cons akey attribution) sc-mail-info)))
;; set the sc-lastchoice attribution
(let* ((lkey "sc-lastchoice")
(lastchoice (assoc lkey sc-attributions)))
(if lastchoice
(setcdr lastchoice attribution)
(push (cons lkey attribution) sc-attributions)))))