From cc77415053796b4bdfc67f9c35f1c674673ba90e Mon Sep 17 00:00:00 2001 From: Alex Kost Date: Thu, 27 Aug 2015 22:24:17 +0300 Subject: emacs: Remove leftover internal variable. This is a followup to commit 74cc67372ec3771b157c015da4ba7ed5d921799f. * emacs/guix-base.el (guix-define-buffer-type): Remove 'mode-map' variable. --- emacs/guix-base.el | 1 - 1 file changed, 1 deletion(-) (limited to 'emacs/guix-base.el') diff --git a/emacs/guix-base.el b/emacs/guix-base.el index fe89584f18..2212dd746f 100644 --- a/emacs/guix-base.el +++ b/emacs/guix-base.el @@ -392,7 +392,6 @@ following keywords are available: (prefix (concat "guix-" entry-type-str "-" buf-type-str)) (group (intern prefix)) (mode-map-str (concat prefix "-mode-map")) - (mode-map (intern mode-map-str)) (parent-mode (intern (concat "guix-" buf-type-str "-mode"))) (mode (intern (concat prefix "-mode"))) (mode-init-fun (intern (concat prefix "-mode-initialize"))) -- cgit v1.2.3 From 1ce96dd9271445133b920cff81bbb44085a5fe7c Mon Sep 17 00:00:00 2001 From: Alex Kost Date: Wed, 12 Aug 2015 15:44:22 +0300 Subject: emacs: Add and use 'guix-concat-strings'. * emacs/guix-utils.el (guix-concat-strings): New function. * emacs/guix-pcomplete.el (guix-pcomplete-short-options): Use it. * emacs/guix-base.el (guix-get-package-strings): Likewise. --- emacs/guix-base.el | 2 +- emacs/guix-pcomplete.el | 2 +- emacs/guix-utils.el | 16 ++++++++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) (limited to 'emacs/guix-base.el') diff --git a/emacs/guix-base.el b/emacs/guix-base.el index 2212dd746f..76974e12ab 100644 --- a/emacs/guix-base.el +++ b/emacs/guix-base.el @@ -913,7 +913,7 @@ ENTRIES is a list of package entries to get info about packages." (concat (guix-get-full-name entry) (when outputs (concat ":" - (mapconcat #'identity outputs ","))) + (guix-concat-strings outputs ","))) (when location (concat "\t(" location ")"))))))) specs))) diff --git a/emacs/guix-pcomplete.el b/emacs/guix-pcomplete.el index 0049c94d38..2b9249554b 100644 --- a/emacs/guix-pcomplete.el +++ b/emacs/guix-pcomplete.el @@ -147,7 +147,7 @@ subcommands, actions, etc. for this guix COMMAND." "Return a string with available short options for guix COMMAND." guix-pcomplete-parse-short-option-regexp (lambda (list) - (mapconcat #'identity list ""))) + (guix-concat-strings list ""))) (guix-memoized-defun guix-pcomplete-all-packages () "Return a list of all available Guix packages." diff --git a/emacs/guix-utils.el b/emacs/guix-utils.el index 8a0673a3a0..df6636c139 100644 --- a/emacs/guix-utils.el +++ b/emacs/guix-utils.el @@ -128,6 +128,22 @@ split it into several short lines." (fill-region (point-min) (point-max))) (buffer-string))) +(defun guix-concat-strings (strings separator &optional location) + "Return new string by concatenating STRINGS with SEPARATOR. +If LOCATION is a symbol `head', add another SEPARATOR to the +beginning of the returned string; if `tail' - add SEPARATOR to +the end of the string; if nil, do not add SEPARATOR; otherwise +add both to the end and to the beginning." + (let ((str (mapconcat #'identity strings separator))) + (cond ((null location) + str) + ((eq location 'head) + (concat separator str)) + ((eq location 'tail) + (concat str separator)) + (t + (concat separator str separator))))) + (defun guix-completing-read-multiple (prompt table &optional predicate require-match initial-input hist def inherit-input-method) -- cgit v1.2.3 From 056b5ceffce3d20b603567a8ce641ae8975f8d62 Mon Sep 17 00:00:00 2001 From: Alex Kost Date: Wed, 12 Aug 2015 14:36:41 +0300 Subject: emacs: Add 'guix-lint-checker-names'. * emacs/guix-main.scm: Use (guix scripts lint) module. (lint-checker-names): New procedure. * emacs/guix-base.el (guix-lint-checker-names): New function. --- emacs/guix-base.el | 9 ++++++++- emacs/guix-main.scm | 12 +++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) (limited to 'emacs/guix-base.el') diff --git a/emacs/guix-base.el b/emacs/guix-base.el index 76974e12ab..daf15bf45b 100644 --- a/emacs/guix-base.el +++ b/emacs/guix-base.el @@ -1,6 +1,6 @@ ;;; guix-base.el --- Common definitions -*- lexical-binding: t -*- -;; Copyright © 2014 Alex Kost +;; Copyright © 2014, 2015 Alex Kost ;; This file is part of GNU Guix. @@ -180,6 +180,13 @@ If PATH is relative, it is considered to be relative to (guix-find-location loc) (message "Couldn't find package location.")))) + +;;; Receivable lists of packages, lint checkers, etc. + +(guix-memoized-defun guix-lint-checker-names () + "Return a list of names of available lint checkers." + (guix-eval-read (guix-make-guile-expression 'lint-checker-names))) + ;;; Buffers and auto updating. diff --git a/emacs/guix-main.scm b/emacs/guix-main.scm index e0dc683d88..2c5b0baa65 100644 --- a/emacs/guix-main.scm +++ b/emacs/guix-main.scm @@ -1,5 +1,5 @@ ;;; GNU Guix --- Functional package management for GNU -;;; Copyright © 2014 Alex Kost +;;; Copyright © 2014, 2015 Alex Kost ;;; ;;; This file is part of GNU Guix. ;;; @@ -57,6 +57,7 @@ (guix licenses) (guix utils) (guix ui) + (guix scripts lint) (guix scripts package) (guix scripts pull) (gnu packages)) @@ -927,3 +928,12 @@ GENERATIONS is a list of generation numbers." (build-derivations store derivations)) (format #t "The source store path: ~a~%" (package-source-derivation->store-path derivation)))))) + + +;;; Lists of packages, lint checkers, etc. + +(define (lint-checker-names) + "Return a list of names of available lint checkers." + (map (lambda (checker) + (symbol->string (lint-checker-name checker))) + %checkers)) -- cgit v1.2.3 From 43b40c4b152a5d7113e3ee591f9f91a342c8fbac Mon Sep 17 00:00:00 2001 From: Alex Kost Date: Thu, 27 Aug 2015 22:47:26 +0300 Subject: emacs: Add 'guix-graph-type-names'. * emacs/guix-main.scm: Use (guix scripts graph) module. (graph-type-names): New procedure. * emacs/guix-base.el (guix-graph-type-names): New function. --- emacs/guix-base.el | 4 ++++ emacs/guix-main.scm | 5 +++++ 2 files changed, 9 insertions(+) (limited to 'emacs/guix-base.el') diff --git a/emacs/guix-base.el b/emacs/guix-base.el index daf15bf45b..1f4a00ce59 100644 --- a/emacs/guix-base.el +++ b/emacs/guix-base.el @@ -183,6 +183,10 @@ If PATH is relative, it is considered to be relative to ;;; Receivable lists of packages, lint checkers, etc. +(guix-memoized-defun guix-graph-type-names () + "Return a list of names of available graph node types." + (guix-eval-read (guix-make-guile-expression 'graph-type-names))) + (guix-memoized-defun guix-lint-checker-names () "Return a list of names of available lint checkers." (guix-eval-read (guix-make-guile-expression 'lint-checker-names))) diff --git a/emacs/guix-main.scm b/emacs/guix-main.scm index 2c5b0baa65..191aa8d5cf 100644 --- a/emacs/guix-main.scm +++ b/emacs/guix-main.scm @@ -57,6 +57,7 @@ (guix licenses) (guix utils) (guix ui) + (guix scripts graph) (guix scripts lint) (guix scripts package) (guix scripts pull) @@ -932,6 +933,10 @@ GENERATIONS is a list of generation numbers." ;;; Lists of packages, lint checkers, etc. +(define (graph-type-names) + "Return a list of names of available graph node types." + (map node-type-name %node-types)) + (define (lint-checker-names) "Return a list of names of available lint checkers." (map (lambda (checker) -- cgit v1.2.3 From 25a2839c9dfb72fc4eddf0621b80023f87fc2e2e Mon Sep 17 00:00:00 2001 From: Alex Kost Date: Wed, 12 Aug 2015 14:40:47 +0300 Subject: emacs: Add 'guix-package-names'. * emacs/guix-main.scm (package-names, package-names-lists): New procedures. * emacs/guix-base.el (guix-package-names): New function. --- emacs/guix-base.el | 14 ++++++++++++++ emacs/guix-main.scm | 11 +++++++++++ 2 files changed, 25 insertions(+) (limited to 'emacs/guix-base.el') diff --git a/emacs/guix-base.el b/emacs/guix-base.el index 1f4a00ce59..9cec510406 100644 --- a/emacs/guix-base.el +++ b/emacs/guix-base.el @@ -191,6 +191,20 @@ If PATH is relative, it is considered to be relative to "Return a list of names of available lint checkers." (guix-eval-read (guix-make-guile-expression 'lint-checker-names))) +(guix-memoized-defun guix-package-names () + "Return a list of names of available packages." + (sort + ;; Work around : + ;; list of strings is parsed much slower than list of lists, + ;; so we use 'package-names-lists' instead of 'package-names'. + + ;; (guix-eval-read (guix-make-guile-expression 'package-names)) + + (mapcar #'car + (guix-eval-read (guix-make-guile-expression + 'package-names-lists))) + #'string<)) + ;;; Buffers and auto updating. diff --git a/emacs/guix-main.scm b/emacs/guix-main.scm index 191aa8d5cf..341657d931 100644 --- a/emacs/guix-main.scm +++ b/emacs/guix-main.scm @@ -942,3 +942,14 @@ GENERATIONS is a list of generation numbers." (map (lambda (checker) (symbol->string (lint-checker-name checker))) %checkers)) + +(define (package-names) + "Return a list of names of available packages." + (delete-duplicates + (fold-packages (lambda (pkg res) + (cons (package-name pkg) res)) + '()))) + +;; See the comment to 'guix-package-names' function in "guix-popup.el". +(define (package-names-lists) + (map list (package-names))) -- cgit v1.2.3 From 51dac383392a723aa77b0496cf12c593b013cb2b Mon Sep 17 00:00:00 2001 From: Alex Kost Date: Sun, 16 Aug 2015 07:11:57 +0300 Subject: 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. --- emacs/guix-base.el | 22 +++++++++++----------- emacs/guix-info.el | 48 ++++++++++++++++++++++++------------------------ emacs/guix-list.el | 50 +++++++++++++++++++++++++------------------------- emacs/guix-messages.el | 8 ++++---- emacs/guix-utils.el | 27 +++++++++++++++++++-------- 5 files changed, 83 insertions(+), 72 deletions(-) (limited to 'emacs/guix-base.el') diff --git a/emacs/guix-base.el b/emacs/guix-base.el index 9cec510406..4c7782dd53 100644 --- a/emacs/guix-base.el +++ b/emacs/guix-base.el @@ -89,8 +89,8 @@ Each element of the list has a form: (defun guix-get-param-title (entry-type param) "Return title of an ENTRY-TYPE entry parameter PARAM." - (or (guix-get-key-val guix-param-titles - entry-type param) + (or (guix-assq-value guix-param-titles + entry-type param) (prog1 (symbol-name param) (message "Couldn't find title for '%S %S'." entry-type param)))) @@ -102,15 +102,15 @@ Each element of the list has a form: (defun guix-get-full-name (entry &optional output) "Return name specification of the package ENTRY and OUTPUT." - (guix-get-name-spec (guix-get-key-val entry 'name) - (guix-get-key-val entry 'version) + (guix-get-name-spec (guix-assq-value entry 'name) + (guix-assq-value entry 'version) output)) (defun guix-entry-to-specification (entry) "Return name specification by the package or output ENTRY." - (guix-get-name-spec (guix-get-key-val entry 'name) - (guix-get-key-val entry 'version) - (guix-get-key-val entry 'output))) + (guix-get-name-spec (guix-assq-value entry 'name) + (guix-assq-value entry 'version) + (guix-assq-value entry 'output))) (defun guix-entries-to-specifications (entries) "Return name specifications by the package or output ENTRIES." @@ -120,13 +120,13 @@ Each element of the list has a form: (defun guix-get-installed-outputs (entry) "Return list of installed outputs for the package ENTRY." (mapcar (lambda (installed-entry) - (guix-get-key-val installed-entry 'output)) - (guix-get-key-val entry 'installed))) + (guix-assq-value installed-entry 'output)) + (guix-assq-value entry 'installed))) (defun guix-get-entry-by-id (id entries) "Return entry from ENTRIES by entry ID." (cl-find-if (lambda (entry) - (equal id (guix-get-key-val entry 'id))) + (equal id (guix-assq-value entry 'id))) entries)) (defun guix-get-package-id-and-output-by-output-id (oid) @@ -934,7 +934,7 @@ ENTRIES is a list of package entries to get info about packages." (outputs (cdr spec)) (entry (guix-get-entry-by-id id entries))) (when entry - (let ((location (guix-get-key-val entry 'location))) + (let ((location (guix-assq-value entry 'location))) (concat (guix-get-full-name entry) (when outputs (concat ":" diff --git a/emacs/guix-info.el b/emacs/guix-info.el index f17ce01ab6..4bdd62a6a5 100644 --- a/emacs/guix-info.el +++ b/emacs/guix-info.el @@ -178,13 +178,13 @@ The order of displayed parameters is the same as in this list.") (defun guix-info-get-insert-methods (entry-type param) "Return list of insert methods for parameter PARAM of ENTRY-TYPE. See `guix-info-insert-methods' for details." - (guix-get-key-val guix-info-insert-methods - entry-type param)) + (guix-assq-value guix-info-insert-methods + entry-type param)) (defun guix-info-get-displayed-params (entry-type) "Return parameters of ENTRY-TYPE that should be displayed." - (guix-get-key-val guix-info-displayed-params - entry-type)) + (guix-assq-value guix-info-displayed-params + entry-type)) (defun guix-info-get-indent (&optional level) "Return `guix-info-indent' \"multiplied\" by LEVEL spaces. @@ -232,7 +232,7 @@ Use `guix-info-insert-ENTRY-TYPE-function' or "Insert title and value of a PARAM at point. ENTRY is alist with parameters and their values. ENTRY-TYPE is a type of ENTRY." - (let ((val (guix-get-key-val entry param))) + (let ((val (guix-assq-value entry param))) (unless (and guix-info-ignore-empty-vals (null val)) (let* ((title (guix-get-param-title entry-type param)) (insert-methods (guix-info-get-insert-methods entry-type param)) @@ -492,12 +492,12 @@ filling them to fit the window." (defun guix-package-info-insert-heading (entry) "Insert the heading for package ENTRY. Show package name, version, and `guix-package-info-heading-params'." - (guix-format-insert (concat (guix-get-key-val entry 'name) " " - (guix-get-key-val entry 'version)) + (guix-format-insert (concat (guix-assq-value entry 'name) " " + (guix-assq-value entry 'version)) 'guix-package-info-heading) (insert "\n\n") (mapc (lambda (param) - (let ((val (guix-get-key-val entry param)) + (let ((val (guix-assq-value entry param)) (face (guix-get-symbol (symbol-name param) 'info 'package))) (when val @@ -587,10 +587,10 @@ If nil, insert installed info in a default way.") (defun guix-package-info-insert-outputs (outputs entry) "Insert OUTPUTS from package ENTRY at point." - (and (guix-get-key-val entry 'obsolete) + (and (guix-assq-value entry 'obsolete) (guix-package-info-insert-obsolete-text)) - (and (guix-get-key-val entry 'non-unique) - (guix-get-key-val entry 'installed) + (and (guix-assq-value entry 'non-unique) + (guix-assq-value entry 'installed) (guix-package-info-insert-non-unique-text (guix-get-full-name entry))) (insert "\n") @@ -617,11 +617,11 @@ If nil, insert installed info in a default way.") Make some fancy text with buttons and additional stuff if the current OUTPUT is installed (if there is such output in `installed' parameter of a package ENTRY)." - (let* ((installed (guix-get-key-val entry 'installed)) - (obsolete (guix-get-key-val entry 'obsolete)) + (let* ((installed (guix-assq-value entry 'installed)) + (obsolete (guix-assq-value entry 'obsolete)) (installed-entry (cl-find-if (lambda (entry) - (string= (guix-get-key-val entry 'output) + (string= (guix-assq-value entry 'output) output)) installed)) (action-type (if installed-entry 'delete 'install))) @@ -655,8 +655,8 @@ ENTRY is an alist with package info." (current-buffer))) (concat type-str " '" full-name "'") 'action-type type - 'id (or (guix-get-key-val entry 'package-id) - (guix-get-key-val entry 'id)) + 'id (or (guix-assq-value entry 'package-id) + (guix-assq-value entry 'id)) 'output output))) (defun guix-package-info-insert-output-path (path &optional _) @@ -720,7 +720,7 @@ PACKAGE-ID is an ID of the package which source to show." (entries (cl-substitute-if new-entry (lambda (entry) - (equal (guix-get-key-val entry 'id) + (equal (guix-assq-value entry 'id) entry-id)) guix-entries :count 1))) @@ -746,9 +746,9 @@ SOURCE is a list of URLs." (guix-info-insert-indent) (if (null source) (guix-format-insert nil) - (let* ((source-file (guix-get-key-val entry 'source-file)) - (entry-id (guix-get-key-val entry 'id)) - (package-id (or (guix-get-key-val entry 'package-id) + (let* ((source-file (guix-assq-value entry 'source-file)) + (entry-id (guix-assq-value entry 'id)) + (package-id (or (guix-assq-value entry 'package-id) entry-id))) (if (null source-file) (guix-info-insert-action-button @@ -798,13 +798,13 @@ If nil, insert output in a default way.") "Insert output VERSION and obsolete text if needed at point." (guix-info-insert-val-default version 'guix-package-info-version) - (and (guix-get-key-val entry 'obsolete) + (and (guix-assq-value entry 'obsolete) (guix-package-info-insert-obsolete-text))) (defun guix-output-info-insert-output (output entry) "Insert OUTPUT and action buttons at point." - (let* ((installed (guix-get-key-val entry 'installed)) - (obsolete (guix-get-key-val entry 'obsolete)) + (let* ((installed (guix-assq-value entry 'installed)) + (obsolete (guix-assq-value entry 'obsolete)) (action-type (if installed 'delete 'install))) (guix-info-insert-val-default output @@ -874,7 +874,7 @@ If nil, insert generation in a default way.") (guix-switch-to-generation guix-profile (button-get btn 'number) (current-buffer))) "Switch to this generation (make it the current one)" - 'number (guix-get-key-val entry 'number)))) + 'number (guix-assq-value entry 'number)))) (provide 'guix-info) diff --git a/emacs/guix-list.el b/emacs/guix-list.el index e84d60a0aa..abb02326af 100644 --- a/emacs/guix-list.el +++ b/emacs/guix-list.el @@ -1,6 +1,6 @@ ;;; guix-list.el --- List buffers for displaying entries -*- lexical-binding: t -*- -;; Copyright © 2014 Alex Kost +;; Copyright © 2014, 2015 Alex Kost ;; This file is part of GNU Guix. @@ -110,13 +110,13 @@ parameters and their values).") (defun guix-list-get-param-title (entry-type param) "Return title of an ENTRY-TYPE entry parameter PARAM." - (or (guix-get-key-val guix-list-column-titles - entry-type param) + (or (guix-assq-value guix-list-column-titles + entry-type param) (guix-get-param-title entry-type param))) (defun guix-list-get-column-format (entry-type) "Return column format for ENTRY-TYPE." - (guix-get-key-val guix-list-column-format entry-type)) + (guix-assq-value guix-list-column-format entry-type)) (defun guix-list-get-displayed-params (entry-type) "Return list of parameters of ENTRY-TYPE that should be displayed." @@ -170,7 +170,7 @@ ENTRIES should have a form of `guix-entries'." Values are taken from ENTRIES which should have the form of `guix-entries'." (mapcar (lambda (entry) - (list (guix-get-key-val entry 'id) + (list (guix-assq-value entry 'id) (guix-list-get-tabulated-entry entry entry-type))) entries)) @@ -180,9 +180,9 @@ Parameters are taken from ENTRY of ENTRY-TYPE." (guix-list-make-tabulated-vector entry-type (lambda (param _) - (let ((val (guix-get-key-val entry param)) - (fun (guix-get-key-val guix-list-column-value-methods - entry-type param))) + (let ((val (guix-assq-value entry param)) + (fun (guix-assq-value guix-list-column-value-methods + entry-type param))) (if fun (funcall fun val entry) (guix-get-string val)))))) @@ -221,7 +221,7 @@ VAL may be nil." (guix-package-list-mode (guix-list-current-id)) (guix-output-list-mode - (guix-get-key-val (guix-list-current-entry) 'package-id)))) + (guix-assq-value (guix-list-current-entry) 'package-id)))) (defun guix-list-for-each-line (fun &rest args) "Call FUN with ARGS for each entry line." @@ -262,7 +262,7 @@ ARGS is a list of additional values.") (defsubst guix-list-get-mark (name) "Return mark character by its NAME." - (or (guix-get-key-val guix-list-mark-alist name) + (or (guix-assq-value guix-list-mark-alist name) (error "Mark '%S' not found" name))) (defsubst guix-list-get-mark-string (name) @@ -355,8 +355,8 @@ With ARG, unmark all lines." "Put marks according to `guix-list-mark-alist'." (guix-list-for-each-line (lambda () - (let ((mark-name (car (guix-get-key-val guix-list-marked - (guix-list-current-id))))) + (let ((mark-name (car (guix-assq-value guix-list-marked + (guix-list-current-id))))) (tabulated-list-put-tag (guix-list-get-mark-string (or mark-name 'empty))))))) @@ -524,16 +524,16 @@ likely)." Colorize it with `guix-package-list-installed' or `guix-package-list-obsolete' if needed." (guix-get-string name - (cond ((guix-get-key-val entry 'obsolete) + (cond ((guix-assq-value entry 'obsolete) 'guix-package-list-obsolete) - ((guix-get-key-val entry 'installed) + ((guix-assq-value entry 'installed) 'guix-package-list-installed)))) (defun guix-package-list-get-installed-outputs (installed &optional _) "Return string with outputs from INSTALLED entries." (guix-get-string (mapcar (lambda (entry) - (guix-get-key-val entry 'output)) + (guix-assq-value entry 'output)) installed))) (defun guix-package-list-marking-check () @@ -562,7 +562,7 @@ be separated with \",\")." (interactive "P") (guix-package-list-marking-check) (let* ((entry (guix-list-current-entry)) - (all (guix-get-key-val entry 'outputs)) + (all (guix-assq-value entry 'outputs)) (installed (guix-get-installed-outputs entry)) (available (cl-set-difference all installed :test #'string=))) (or available @@ -597,7 +597,7 @@ be separated with \",\")." (installed (guix-get-installed-outputs entry))) (or installed (user-error "This package is not installed")) - (when (or (guix-get-key-val entry 'obsolete) + (when (or (guix-assq-value entry 'obsolete) (y-or-n-p "This package is not obsolete. Try to upgrade it anyway? ")) (guix-package-list-mark-outputs 'upgrade installed @@ -611,14 +611,14 @@ accept an entry as argument." (guix-package-list-marking-check) (let ((obsolete (cl-remove-if-not (lambda (entry) - (guix-get-key-val entry 'obsolete)) + (guix-assq-value entry 'obsolete)) guix-entries))) (guix-list-for-each-line (lambda () (let* ((id (guix-list-current-id)) (entry (cl-find-if (lambda (entry) - (equal id (guix-get-key-val entry 'id))) + (equal id (guix-assq-value entry 'id))) obsolete))) (when entry (funcall fun entry))))))) @@ -682,7 +682,7 @@ The specification is suitable for `guix-process-package-actions'." (interactive) (guix-package-list-marking-check) (let* ((entry (guix-list-current-entry)) - (installed (guix-get-key-val entry 'installed))) + (installed (guix-assq-value entry 'installed))) (if installed (user-error "This output is already installed") (guix-list--mark 'install t)))) @@ -692,7 +692,7 @@ The specification is suitable for `guix-process-package-actions'." (interactive) (guix-package-list-marking-check) (let* ((entry (guix-list-current-entry)) - (installed (guix-get-key-val entry 'installed))) + (installed (guix-assq-value entry 'installed))) (if installed (guix-list--mark 'delete t) (user-error "This output is not installed")))) @@ -702,10 +702,10 @@ The specification is suitable for `guix-process-package-actions'." (interactive) (guix-package-list-marking-check) (let* ((entry (guix-list-current-entry)) - (installed (guix-get-key-val entry 'installed))) + (installed (guix-assq-value entry 'installed))) (or installed (user-error "This output is not installed")) - (when (or (guix-get-key-val entry 'obsolete) + (when (or (guix-assq-value entry 'obsolete) (y-or-n-p "This output is not obsolete. Try to upgrade it anyway? ")) (guix-list--mark 'upgrade t)))) @@ -777,8 +777,8 @@ VAL is a boolean value." "Switch current profile to the generation at point." (interactive) (let* ((entry (guix-list-current-entry)) - (current (guix-get-key-val entry 'current)) - (number (guix-get-key-val entry 'number))) + (current (guix-assq-value entry 'current)) + (number (guix-assq-value entry 'number))) (if current (user-error "This generation is already the current one") (guix-switch-to-generation guix-profile number (current-buffer))))) diff --git a/emacs/guix-messages.el b/emacs/guix-messages.el index bd985a0670..2bf99de6fa 100644 --- a/emacs/guix-messages.el +++ b/emacs/guix-messages.el @@ -1,6 +1,6 @@ ;;; guix-messages.el --- Minibuffer messages -;; Copyright © 2014 Alex Kost +;; Copyright © 2014, 2015 Alex Kost ;; This file is part of GNU Guix. @@ -186,14 +186,14 @@ (defun guix-result-message (profile entries entry-type search-type search-vals) "Display an appropriate message after displaying ENTRIES." - (let* ((type-spec (guix-get-key-val guix-messages - entry-type search-type)) + (let* ((type-spec (guix-assq-value guix-messages + entry-type search-type)) (fun-or-count-spec (car type-spec))) (if (functionp fun-or-count-spec) (funcall fun-or-count-spec profile entries search-vals) (let* ((count (length entries)) (count-key (if (> count 1) 'many count)) - (msg-spec (guix-get-key-val type-spec count-key)) + (msg-spec (guix-assq-value type-spec count-key)) (msg (car msg-spec)) (args (cdr msg-spec))) (mapc (lambda (subst) 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) @@ -223,6 +215,25 @@ Return nil otherwise." (or (funcall pred (car lst)) (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 -- cgit v1.2.3 From 5e53b0c5a9e1c693d46bdaf24e6b5ce498410da6 Mon Sep 17 00:00:00 2001 From: Alex Kost Date: Thu, 13 Aug 2015 10:51:31 +0300 Subject: emacs: Add code to run guix command in REPL. * emacs/guix-base.el (guix-run-command-in-repl, guix-command-output, guix-help-string): New functions. * emacs/guix-main.scm (guix-command, guix-command-output, help-string): New procedures. --- emacs/guix-base.el | 21 +++++++++++++++++++++ emacs/guix-main.scm | 18 ++++++++++++++++++ 2 files changed, 39 insertions(+) (limited to 'emacs/guix-base.el') diff --git a/emacs/guix-base.el b/emacs/guix-base.el index 4c7782dd53..d1593e285d 100644 --- a/emacs/guix-base.el +++ b/emacs/guix-base.el @@ -1084,6 +1084,27 @@ FILE. With a prefix argument, also prompt for PROFILE." (concat "--manifest=" file)) operation-buffer))) + +;;; Executing guix commands + +(defun guix-run-command-in-repl (args) + "Execute 'guix ARGS ...' command in Guix REPL." + (guix-eval-in-repl + (apply #'guix-make-guile-expression + 'guix-command args))) + +(defun guix-command-output (args) + "Return string with 'guix ARGS ...' output." + (guix-eval-read + (apply #'guix-make-guile-expression + 'guix-command-output args))) + +(defun guix-help-string (&optional commands) + "Return string with 'guix COMMANDS ... --help' output." + (guix-eval-read + (apply #'guix-make-guile-expression + 'help-string commands))) + ;;; Pull diff --git a/emacs/guix-main.scm b/emacs/guix-main.scm index 341657d931..bd42f8fc21 100644 --- a/emacs/guix-main.scm +++ b/emacs/guix-main.scm @@ -930,6 +930,24 @@ GENERATIONS is a list of generation numbers." (format #t "The source store path: ~a~%" (package-source-derivation->store-path derivation)))))) + +;;; Executing guix commands + +(define (guix-command . args) + "Run 'guix ARGS ...' command." + (catch 'quit + (lambda () (apply run-guix args)) + (const #t))) + +(define (guix-command-output . args) + "Return string with 'guix ARGS ...' output." + (with-output-to-string + (lambda () (apply guix-command args)))) + +(define (help-string . commands) + "Return string with 'guix COMMANDS ... --help' output." + (apply guix-command-output `(,@commands "--help"))) + ;;; Lists of packages, lint checkers, etc. -- cgit v1.2.3 From 7008dffff52b59bb37361e72f4319977a91db2f1 Mon Sep 17 00:00:00 2001 From: Alex Kost Date: Sun, 16 Aug 2015 13:55:25 +0300 Subject: emacs: Add code to run guix command in shell. * emacs/guix-base.el (guix-run-in-shell, guix-run-in-eshell, guix-run-command-in-shell): New functions. (guix-run-in-shell-function, guix-shell-buffer-name): New variables. --- emacs/guix-base.el | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'emacs/guix-base.el') diff --git a/emacs/guix-base.el b/emacs/guix-base.el index d1593e285d..4dff0d6170 100644 --- a/emacs/guix-base.el +++ b/emacs/guix-base.el @@ -1087,6 +1087,42 @@ FILE. With a prefix argument, also prompt for PROFILE." ;;; Executing guix commands +(defcustom guix-run-in-shell-function #'guix-run-in-shell + "Function used to run guix command. +The function is called with a single argument - a command line string." + :type '(choice (function-item guix-run-in-shell) + (function-item guix-run-in-eshell) + (function :tag "Other function")) + :group 'guix) + +(defcustom guix-shell-buffer-name "*shell*" + "Default name of a shell buffer used for running guix commands." + :type 'string + :group 'guix) + +(declare-function comint-send-input "comint" t) + +(defun guix-run-in-shell (string) + "Run command line STRING in `guix-shell-buffer-name' buffer." + (shell guix-shell-buffer-name) + (goto-char (point-max)) + (insert string) + (comint-send-input)) + +(declare-function eshell-send-input "esh-mode" t) + +(defun guix-run-in-eshell (string) + "Run command line STRING in eshell buffer." + (eshell) + (goto-char (point-max)) + (insert string) + (eshell-send-input)) + +(defun guix-run-command-in-shell (args) + "Execute 'guix ARGS ...' command in a shell buffer." + (funcall guix-run-in-shell-function + (guix-command-string args))) + (defun guix-run-command-in-repl (args) "Execute 'guix ARGS ...' command in Guix REPL." (guix-eval-in-repl -- cgit v1.2.3 From eb097f36b1c3e7a25f1ce212670e8a19788fd195 Mon Sep 17 00:00:00 2001 From: Alex Kost Date: Mon, 17 Aug 2015 12:05:05 +0300 Subject: emacs: Use prompt for packages instead popup for edit action. * emacs/guix-base.el (guix-package-location): New function. (guix-edit-package): Rename and move to ... * emacs/guix.el (guix-edit): ...here. Make it interactive. * emacs/guix-command.el (guix-edit-action): New function (alias to 'guix-edit') to override the popup for edit command in "M-x guix". * emacs/guix-list.el (guix-list-edit-package): Adjust for 'guix-edit' renaming. * emacs/guix-main.scm (package-location-string): Allow to accept package id or package name as argument. --- emacs/guix-base.el | 12 +++++------- emacs/guix-command.el | 2 ++ emacs/guix-list.el | 2 +- emacs/guix-main.scm | 7 ++++--- emacs/guix.el | 12 +++++++++++- 5 files changed, 23 insertions(+), 12 deletions(-) (limited to 'emacs/guix-base.el') diff --git a/emacs/guix-base.el b/emacs/guix-base.el index 4dff0d6170..3bee910b05 100644 --- a/emacs/guix-base.el +++ b/emacs/guix-base.el @@ -172,13 +172,11 @@ If PATH is relative, it is considered to be relative to (move-to-column col) (recenter 1)))) -(defun guix-edit-package (id) - "Edit (go to location of) package with ID." - (let ((loc (guix-eval-read (guix-make-guile-expression - 'package-location-string id)))) - (if loc - (guix-find-location loc) - (message "Couldn't find package location.")))) +(defun guix-package-location (id-or-name) + "Return location of a package with ID-OR-NAME. +For the meaning of location, see `guix-find-location'." + (guix-eval-read (guix-make-guile-expression + 'package-location-string id-or-name))) ;;; Receivable lists of packages, lint checkers, etc. diff --git a/emacs/guix-command.el b/emacs/guix-command.el index 97a88726df..139724d3d5 100644 --- a/emacs/guix-command.el +++ b/emacs/guix-command.el @@ -627,6 +627,8 @@ EXECUTOR function is called with the current command line arguments." ;;;###autoload (autoload 'guix "guix-command" "Popup window for 'guix'." t) (guix-command-define-popup-action guix) +(defalias 'guix-edit-action #'guix-edit) + (defvar guix-command-font-lock-keywords (eval-when-compile diff --git a/emacs/guix-list.el b/emacs/guix-list.el index abb02326af..9796464dbf 100644 --- a/emacs/guix-list.el +++ b/emacs/guix-list.el @@ -472,7 +472,7 @@ With prefix (if ARG is non-nil), describe entries marked with any mark." (defun guix-list-edit-package () "Go to the location of the current package." (interactive) - (guix-edit-package (guix-list-current-package-id))) + (guix-edit (guix-list-current-package-id))) ;;; Displaying packages diff --git a/emacs/guix-main.scm b/emacs/guix-main.scm index bd42f8fc21..fe224fb582 100644 --- a/emacs/guix-main.scm +++ b/emacs/guix-main.scm @@ -889,9 +889,10 @@ GENERATIONS is a list of generation numbers." (with-store store (delete-generations store profile generations))) -(define (package-location-string package-id) - "Return a location string of a package PACKAGE-ID." - (and-let* ((package (package-by-id package-id)) +(define (package-location-string id-or-name) + "Return a location string of a package with ID-OR-NAME." + (and-let* ((package (or (package-by-id id-or-name) + (first (packages-by-name id-or-name)))) (location (package-location package))) (location->string location))) diff --git a/emacs/guix.el b/emacs/guix.el index afe7285696..244696a184 100644 --- a/emacs/guix.el +++ b/emacs/guix.el @@ -1,6 +1,6 @@ ;;; guix.el --- Interface for GNU Guix package manager -;; Copyright © 2014 Alex Kost +;; Copyright © 2014, 2015 Alex Kost ;; Package-Requires: ((geiser "0.3")) ;; Keywords: tools @@ -32,6 +32,7 @@ (require 'guix-list) (require 'guix-info) (require 'guix-utils) +(require 'guix-read) (defgroup guix nil "Interface for Guix package manager." @@ -193,6 +194,15 @@ Interactively with prefix, prompt for PROFILE." (float-time from) (float-time to))) +;;;###autoload +(defun guix-edit (id-or-name) + "Edit (go to location of) package with ID-OR-NAME." + (interactive (list (guix-read-package-name))) + (let ((loc (guix-package-location id-or-name))) + (if loc + (guix-find-location loc) + (message "Couldn't find package location.")))) + (provide 'guix) ;;; guix.el ends here -- cgit v1.2.3