aboutsummaryrefslogtreecommitdiff
path: root/emacs/guix-utils.el
diff options
context:
space:
mode:
authorAlex Kost <alezost@gmail.com>2015-08-16 07:11:57 +0300
committerAlex Kost <alezost@gmail.com>2015-08-30 18:26:02 +0300
commit51dac383392a723aa77b0496cf12c593b013cb2b (patch)
tree25eb7bccd6d92235c25d54f31cded6eab4f4910d /emacs/guix-utils.el
parentd007d8a10cbc3100fe71b61add8eb7723a1c93e8 (diff)
downloadgnu-guix-51dac383392a723aa77b0496cf12c593b013cb2b.tar
gnu-guix-51dac383392a723aa77b0496cf12c593b013cb2b.tar.gz
emacs: Add and use alist accessors.
* emacs/guix-utils.el (guix-define-alist-accessor): New macro. (guix-assq-value, guix-assoc-value): New functions. (guix-get-key-val): Remove. * emacs/guix-base.el: Replace 'guix-get-key-val' with 'guix-assq-value' everywhere. * emacs/guix-info.el: Likewise. * emacs/guix-list.el: Likewise. * emacs/guix-messages.el: Likewise.
Diffstat (limited to 'emacs/guix-utils.el')
-rw-r--r--emacs/guix-utils.el27
1 files changed, 19 insertions, 8 deletions
diff --git a/emacs/guix-utils.el b/emacs/guix-utils.el
index 0b8a760af8..78ea3545c6 100644
--- a/emacs/guix-utils.el
+++ b/emacs/guix-utils.el
@@ -193,14 +193,6 @@ Return time value."
(require 'org)
(org-read-date nil t nil prompt))
-(defun guix-get-key-val (alist &rest keys)
- "Return value from ALIST by KEYS.
-ALIST is alist of alists of alists ... which can be consecutively
-accessed with KEYS."
- (let ((val alist))
- (dolist (key keys val)
- (setq val (cdr (assq key val))))))
-
(defun guix-find-file (file)
"Find FILE if it exists."
(if (file-exists-p file)
@@ -224,6 +216,25 @@ Return nil otherwise."
(guix-any pred (cdr lst)))))
+;;; Alist accessors
+
+(defmacro guix-define-alist-accessor (name assoc-fun)
+ "Define NAME function to access alist values using ASSOC-FUN."
+ `(defun ,name (alist &rest keys)
+ ,(format "Return value from ALIST by KEYS using `%s'.
+ALIST is alist of alists of alists ... which can be consecutively
+accessed with KEYS."
+ assoc-fun)
+ (if (or (null alist) (null keys))
+ alist
+ (apply #',name
+ (cdr (,assoc-fun (car keys) alist))
+ (cdr keys)))))
+
+(guix-define-alist-accessor guix-assq-value assq)
+(guix-define-alist-accessor guix-assoc-value assoc)
+
+
;;; Diff
(defvar guix-diff-switches "-u"