Add reverse mapping for EUDC attribute names

* lisp/net/eudc.el (eudc-translate-query): new optional parameter to
reverse the mapping direction
(eudc-translate-attribute-list): new optional parameter to
reverse the mapping direction
This commit is contained in:
Alexander Adolf 2022-07-02 17:27:55 +02:00 committed by Thomas Fitzsimmons
parent edaa7780fd
commit f1ae277e0b

View file

@ -383,32 +383,51 @@ accordingly. Otherwise it is set to its EUDC default binding."
(cons protocol eudc-known-protocols))))
(defun eudc-translate-query (query)
(defun eudc-translate-query (query &optional reverse)
"Translate attribute names of QUERY.
The translation is done according to
`eudc-protocol-attributes-translation-alist'."
`eudc-protocol-attributes-translation-alist'.
When REVERSE is nil or omitted, the attribute names are
translated from EUDC generic names to protocol-specific
names. When REVERSE is non-nil, the translation is from
protocol-specific names back to EUDC generic names."
(if eudc-protocol-attributes-translation-alist
(mapcar (lambda (attribute)
(let ((trans (assq (car attribute)
(symbol-value eudc-protocol-attributes-translation-alist))))
(let ((trans
(if reverse
(rassq (car attribute)
(symbol-value eudc-protocol-attributes-translation-alist))
(assq (car attribute)
(symbol-value eudc-protocol-attributes-translation-alist)))))
(if trans
(cons (cdr trans) (cdr attribute))
(cons (if reverse (car trans) (cdr trans))
(cdr attribute))
attribute)))
query)
query))
(defun eudc-translate-attribute-list (list)
(defun eudc-translate-attribute-list (list &optional reverse)
"Translate a list of attribute names LIST.
The translation is done according to
`eudc-protocol-attributes-translation-alist'."
`eudc-protocol-attributes-translation-alist'.
When REVERSE is nil or omitted, the attribute names are
translated from EUDC generic names to protocol-specific
names. When REVERSE is non-nil, the translation is from
protocol-specific names back to EUDC generic names."
(if eudc-protocol-attributes-translation-alist
(let (trans)
(mapcar (lambda (attribute)
(setq trans (assq attribute
(symbol-value eudc-protocol-attributes-translation-alist)))
(if trans
(cdr trans)
attribute))
(setq trans
(if reverse
(rassq attribute
(symbol-value eudc-protocol-attributes-translation-alist))
(assq attribute
(symbol-value eudc-protocol-attributes-translation-alist))))
(if trans
(if reverse (car trans) (cdr trans))
attribute))
list))
list))