emacs: Rename internal procedures.

* emacs/guix-list.el (guix-list-get-param-title): Rename to...
  (guix-list-param-title): ... this.
  (guix-list-get-column-format): Rename to...
  (guix-list-format): ... this.
  (guix-list-get-displayed-params): Rename to...
  (guix-list-displayed-params): ... this.
  (guix-list-get-sort-key): Rename to...
  (guix-list-tabulated-sort-key): ... this.
  (guix-list-make-tabulated-vector): Rename to...
  (guix-list-tabulated-vector): ... this.
  (guix-list-get-list-format): Rename to...
  (guix-list-tabulated-format): ... this.
  (guix-list-get-tabulated-entries): Rename to...
  (guix-list-tabulated-entries): ... this.
  (guix-list-get-tabulated-entry): Rename to...
  (guix-list-tabulated-entry): ... this.
* emacs/guix-info.el (guix-info-get-displayed-params): Rename to...
  (guix-info-displayed-params): ... this.
* emacs/guix-base.el (guix-get-params-for-receiving): Adjust
  accordingly.
  (guix-get-name-spec): Rename to...
  (guix-package-name-specification): ... this.
  (guix-get-full-name): Merge this and...
  (guix-entry-to-specification): ... this into...
  (guix-package-entry->name-specification): ... this.
  (guix-get-installed-outputs): Rename to...
  (guix-package-installed-outputs): ... this.
  (guix-get-package-id-and-output-by-output-id): Rename to...
  (guix-package-id-and-output-by-output-id): ... this.
This commit is contained in:
Alex Kost 2015-11-18 11:36:27 +03:00
parent e86a43d471
commit 0b9cd3206a
3 changed files with 56 additions and 62 deletions

View File

@ -61,35 +61,31 @@ Each element of the list has a form:
entry-type param) entry-type param)
(guix-symbol-title param))) (guix-symbol-title param)))
(defun guix-get-name-spec (name version &optional output) (defun guix-package-name-specification (name version &optional output)
"Return Guix package specification by its NAME, VERSION and OUTPUT." "Return Guix package specification by its NAME, VERSION and OUTPUT."
(concat name "-" version (concat name "-" version
(when output (concat ":" output)))) (when output (concat ":" output))))
(defun guix-get-full-name (entry &optional output) (defun guix-package-entry->name-specification (entry &optional output)
"Return name specification of the package ENTRY and OUTPUT." "Return name specification of the package ENTRY and OUTPUT."
(guix-get-name-spec (guix-entry-value entry 'name) (guix-package-name-specification
(guix-entry-value entry 'name)
(guix-entry-value entry 'version) (guix-entry-value entry 'version)
output)) (or output (guix-entry-value entry 'output))))
(defun guix-entry-to-specification (entry) (defun guix-package-entries->name-specifications (entries)
"Return name specification by the package or output ENTRY."
(guix-get-name-spec (guix-entry-value entry 'name)
(guix-entry-value entry 'version)
(guix-entry-value entry 'output)))
(defun guix-entries-to-specifications (entries)
"Return name specifications by the package or output ENTRIES." "Return name specifications by the package or output ENTRIES."
(cl-remove-duplicates (mapcar #'guix-entry-to-specification entries) (cl-remove-duplicates (mapcar #'guix-package-entry->name-specification
entries)
:test #'string=)) :test #'string=))
(defun guix-get-installed-outputs (entry) (defun guix-package-installed-outputs (entry)
"Return list of installed outputs for the package ENTRY." "Return list of installed outputs for the package ENTRY."
(mapcar (lambda (installed-entry) (mapcar (lambda (installed-entry)
(guix-entry-value installed-entry 'output)) (guix-entry-value installed-entry 'output))
(guix-entry-value entry 'installed))) (guix-entry-value entry 'installed)))
(defun guix-get-package-id-and-output-by-output-id (oid) (defun guix-package-id-and-output-by-output-id (oid)
"Return list (PACKAGE-ID OUTPUT) by output id OID." "Return list (PACKAGE-ID OUTPUT) by output id OID."
(cl-multiple-value-bind (pid-str output) (cl-multiple-value-bind (pid-str output)
(split-string oid ":") (split-string oid ":")
@ -567,7 +563,7 @@ If NO-DISPLAY is non-nil, do not switch to the buffer."
(required (symbol-value required-var))) (required (symbol-value required-var)))
(unless (equal required 'all) (unless (equal required 'all)
(cl-union required (cl-union required
(funcall (guix-get-symbol "get-displayed-params" (funcall (guix-get-symbol "displayed-params"
buffer-type) buffer-type)
entry-type))))) entry-type)))))
@ -596,7 +592,8 @@ See `revert-buffer' for the meaning of NOCONFIRM."
(eq guix-entry-type 'output))) (eq guix-entry-type 'output)))
(progn (progn
(setq search-type 'name (setq search-type 'name
search-vals (guix-entries-to-specifications search-vals
(guix-package-entries->name-specifications
guix-entries)) guix-entries))
(guix-get-entries (guix-get-entries
guix-profile guix-entry-type guix-profile guix-entry-type
@ -902,7 +899,7 @@ ENTRIES is a list of package entries to get info about packages."
(entry (guix-entry-by-id id entries))) (entry (guix-entry-by-id id entries)))
(when entry (when entry
(let ((location (guix-entry-value entry 'location))) (let ((location (guix-entry-value entry 'location)))
(concat (guix-get-full-name entry) (concat (guix-package-entry->name-specification entry)
(when outputs (when outputs
(concat ":" (concat ":"
(guix-concat-strings outputs ","))) (guix-concat-strings outputs ",")))

View File

@ -187,13 +187,13 @@ Each element of the list should have a form:
The order of displayed parameters is the same as in this list.") The order of displayed parameters is the same as in this list.")
(defun guix-info-get-insert-methods (entry-type param) (defun guix-info-insert-methods (entry-type param)
"Return list of insert methods for parameter PARAM of ENTRY-TYPE. "Return list of insert methods for parameter PARAM of ENTRY-TYPE.
See `guix-info-insert-methods' for details." See `guix-info-insert-methods' for details."
(guix-assq-value guix-info-insert-methods (guix-assq-value guix-info-insert-methods
entry-type param)) entry-type param))
(defun guix-info-get-displayed-params (entry-type) (defun guix-info-displayed-params (entry-type)
"Return parameters of ENTRY-TYPE that should be displayed." "Return parameters of ENTRY-TYPE that should be displayed."
(guix-assq-value guix-info-displayed-params (guix-assq-value guix-info-displayed-params
entry-type)) entry-type))
@ -224,7 +224,7 @@ number of `guix-info-indent' spaces."
guix-info-indent) guix-info-indent)
(mapc (lambda (param) (mapc (lambda (param)
(guix-info-insert-param param entry entry-type)) (guix-info-insert-param param entry entry-type))
(guix-info-get-displayed-params entry-type)))) (guix-info-displayed-params entry-type))))
(defun guix-info-insert-entry (entry entry-type &optional indent-level) (defun guix-info-insert-entry (entry entry-type &optional indent-level)
"Insert ENTRY of ENTRY-TYPE into the current info buffer. "Insert ENTRY of ENTRY-TYPE into the current info buffer.
@ -245,7 +245,7 @@ ENTRY-TYPE is a type of ENTRY."
(let ((val (guix-entry-value entry param))) (let ((val (guix-entry-value entry param)))
(unless (and guix-info-ignore-empty-vals (null val)) (unless (and guix-info-ignore-empty-vals (null val))
(let* ((title (guix-get-param-title entry-type param)) (let* ((title (guix-get-param-title entry-type param))
(insert-methods (guix-info-get-insert-methods entry-type param)) (insert-methods (guix-info-insert-methods entry-type param))
(val-method (car insert-methods)) (val-method (car insert-methods))
(title-method (cadr insert-methods))) (title-method (cadr insert-methods)))
(guix-info-method-funcall title title-method (guix-info-method-funcall title title-method
@ -525,7 +525,7 @@ Show package name, version, and `guix-package-info-heading-params'."
(unless (or (memq param '(name version)) (unless (or (memq param '(name version))
(memq param guix-package-info-heading-params)) (memq param guix-package-info-heading-params))
(guix-info-insert-param param entry 'package))) (guix-info-insert-param param entry 'package)))
(guix-info-get-displayed-params 'package))) (guix-info-displayed-params 'package)))
(defun guix-package-info-insert-description (desc &optional _) (defun guix-package-info-insert-description (desc &optional _)
"Insert description DESC at point." "Insert description DESC at point."
@ -601,7 +601,7 @@ If nil, insert installed info in a default way.")
(and (guix-entry-value entry 'non-unique) (and (guix-entry-value entry 'non-unique)
(guix-entry-value entry 'installed) (guix-entry-value entry 'installed)
(guix-package-info-insert-non-unique-text (guix-package-info-insert-non-unique-text
(guix-get-full-name entry))) (guix-package-entry->name-specification entry)))
(insert "\n") (insert "\n")
(mapc (lambda (output) (mapc (lambda (output)
(guix-package-info-insert-output output entry)) (guix-package-info-insert-output output entry))
@ -653,7 +653,7 @@ current OUTPUT is installed (if there is such output in
TYPE is one of the following symbols: `install', `delete', `upgrade'. TYPE is one of the following symbols: `install', `delete', `upgrade'.
ENTRY is an alist with package info." ENTRY is an alist with package info."
(let ((type-str (capitalize (symbol-name type))) (let ((type-str (capitalize (symbol-name type)))
(full-name (guix-get-full-name entry output))) (full-name (guix-package-entry->name-specification entry output)))
(guix-info-insert-action-button (guix-info-insert-action-button
type-str type-str
(lambda (btn) (lambda (btn)

View File

@ -117,27 +117,19 @@ function is called with 2 arguments: the first one is the value
of the parameter; the second argument is an entry info (alist of of the parameter; the second argument is an entry info (alist of
parameters and their values).") parameters and their values).")
(defun guix-list-get-param-title (entry-type param) (defun guix-list-param-title (entry-type param)
"Return title of an ENTRY-TYPE entry parameter PARAM." "Return column title of an ENTRY-TYPE parameter PARAM."
(or (guix-assq-value guix-list-column-titles (or (guix-assq-value guix-list-column-titles
entry-type param) entry-type param)
(guix-get-param-title entry-type param))) (guix-get-param-title entry-type param)))
(defun guix-list-get-column-format (entry-type) (defun guix-list-format (entry-type)
"Return column format for ENTRY-TYPE." "Return column format for ENTRY-TYPE."
(guix-assq-value guix-list-column-format entry-type)) (guix-assq-value guix-list-column-format entry-type))
(defun guix-list-get-displayed-params (entry-type) (defun guix-list-displayed-params (entry-type)
"Return list of parameters of ENTRY-TYPE that should be displayed." "Return a list of ENTRY-TYPE parameters that should be displayed."
(mapcar #'car (mapcar #'car (guix-list-format entry-type)))
(guix-list-get-column-format entry-type)))
(defun guix-list-get-sort-key (entry-type param &optional invert)
"Return suitable sort key for `tabulated-list-sort-key'.
Define column title by ENTRY-TYPE and PARAM. If INVERT is
non-nil, invert the sort."
(when (memq param (guix-list-get-displayed-params entry-type))
(cons (guix-list-get-param-title entry-type param) invert)))
(defun guix-list-sort-numerically (column a b) (defun guix-list-sort-numerically (column a b)
"Compare COLUMN of tabulated entries A and B numerically. "Compare COLUMN of tabulated entries A and B numerically.
@ -169,7 +161,14 @@ See `guix-list-define-numerical-sorter' for details."
(guix-list-define-numerical-sorters 9) (guix-list-define-numerical-sorters 9)
(defun guix-list-make-tabulated-vector (entry-type fun) (defun guix-list-tabulated-sort-key (entry-type param &optional invert)
"Return suitable sort key for `tabulated-list-sort-key'.
Define column title by ENTRY-TYPE and PARAM. If INVERT is
non-nil, invert the sort."
(when (memq param (guix-list-displayed-params entry-type))
(cons (guix-list-param-title entry-type param) invert)))
(defun guix-list-tabulated-vector (entry-type fun)
"Call FUN on each column specification for ENTRY-TYPE. "Call FUN on each column specification for ENTRY-TYPE.
FUN is called with 2 argument: parameter name and column FUN is called with 2 argument: parameter name and column
@ -179,36 +178,34 @@ Return a vector made of values of FUN calls."
(apply #'vector (apply #'vector
(mapcar (lambda (col-spec) (mapcar (lambda (col-spec)
(funcall fun (car col-spec) (cdr col-spec))) (funcall fun (car col-spec) (cdr col-spec)))
(guix-list-get-column-format entry-type)))) (guix-list-format entry-type))))
(defun guix-list-get-list-format (entry-type) (defun guix-list-tabulated-format (entry-type)
"Return ENTRY-TYPE list specification for `tabulated-list-format'." "Return ENTRY-TYPE list specification for `tabulated-list-format'."
(guix-list-make-tabulated-vector (guix-list-tabulated-vector
entry-type entry-type
(lambda (param spec) (lambda (param spec)
(cons (guix-list-get-param-title entry-type param) (cons (guix-list-param-title entry-type param)
spec)))) spec))))
(defun guix-list-insert-entries (entries entry-type) (defun guix-list-insert-entries (entries entry-type)
"Display ENTRIES of ENTRY-TYPE in the current list buffer. "Display ENTRIES of ENTRY-TYPE in the current list buffer.
ENTRIES should have a form of `guix-entries'." ENTRIES should have a form of `guix-entries'."
(setq tabulated-list-entries (setq tabulated-list-entries
(guix-list-get-tabulated-entries entries entry-type)) (guix-list-tabulated-entries entries entry-type))
(tabulated-list-print)) (tabulated-list-print))
(defun guix-list-get-tabulated-entries (entries entry-type) (defun guix-list-tabulated-entries (entries entry-type)
"Return list of values of ENTRY-TYPE for `tabulated-list-entries'. "Return a list of ENTRY-TYPE values for `tabulated-list-entries'."
Values are taken from ENTRIES which should have the form of
`guix-entries'."
(mapcar (lambda (entry) (mapcar (lambda (entry)
(list (guix-entry-id entry) (list (guix-entry-id entry)
(guix-list-get-tabulated-entry entry entry-type))) (guix-list-tabulated-entry entry entry-type)))
entries)) entries))
(defun guix-list-get-tabulated-entry (entry entry-type) (defun guix-list-tabulated-entry (entry entry-type)
"Return array of values for `tabulated-list-entries'. "Return array of values for `tabulated-list-entries'.
Parameters are taken from ENTRY of ENTRY-TYPE." Parameters are taken from ENTRY-TYPE ENTRY."
(guix-list-make-tabulated-vector (guix-list-tabulated-vector
entry-type entry-type
(lambda (param _) (lambda (param _)
(let ((val (guix-entry-value entry param)) (let ((val (guix-entry-value entry param))
@ -472,10 +469,10 @@ This macro defines the following functions:
,(concat "Initial settings for `" mode-str "'.") ,(concat "Initial settings for `" mode-str "'.")
,(when sort-key ,(when sort-key
`(setq tabulated-list-sort-key `(setq tabulated-list-sort-key
(guix-list-get-sort-key (guix-list-tabulated-sort-key
',entry-type ',sort-key ,invert-sort))) ',entry-type ',sort-key ,invert-sort)))
(setq tabulated-list-format (setq tabulated-list-format
(guix-list-get-list-format ',entry-type)) (guix-list-tabulated-format ',entry-type))
(setq-local guix-list-mark-alist (setq-local guix-list-mark-alist
(append guix-list-mark-alist ,marks-var)) (append guix-list-mark-alist ,marks-var))
(tabulated-list-init-header))))) (tabulated-list-init-header)))))
@ -595,7 +592,7 @@ be separated with \",\")."
(guix-package-list-marking-check) (guix-package-list-marking-check)
(let* ((entry (guix-list-current-entry)) (let* ((entry (guix-list-current-entry))
(all (guix-entry-value entry 'outputs)) (all (guix-entry-value entry 'outputs))
(installed (guix-get-installed-outputs entry)) (installed (guix-package-installed-outputs entry))
(available (cl-set-difference all installed :test #'string=))) (available (cl-set-difference all installed :test #'string=)))
(or available (or available
(user-error "This package is already installed")) (user-error "This package is already installed"))
@ -611,7 +608,7 @@ be separated with \",\")."
(interactive "P") (interactive "P")
(guix-package-list-marking-check) (guix-package-list-marking-check)
(let* ((entry (guix-list-current-entry)) (let* ((entry (guix-list-current-entry))
(installed (guix-get-installed-outputs entry))) (installed (guix-package-installed-outputs entry)))
(or installed (or installed
(user-error "This package is not installed")) (user-error "This package is not installed"))
(guix-package-list-mark-outputs (guix-package-list-mark-outputs
@ -626,7 +623,7 @@ be separated with \",\")."
(interactive "P") (interactive "P")
(guix-package-list-marking-check) (guix-package-list-marking-check)
(let* ((entry (guix-list-current-entry)) (let* ((entry (guix-list-current-entry))
(installed (guix-get-installed-outputs entry))) (installed (guix-package-installed-outputs entry)))
(or installed (or installed
(user-error "This package is not installed")) (user-error "This package is not installed"))
(when (or (guix-entry-value entry 'obsolete) (when (or (guix-entry-value entry 'obsolete)
@ -662,7 +659,7 @@ accept an entry as argument."
(lambda (entry) (lambda (entry)
(apply #'guix-list--mark (apply #'guix-list--mark
'upgrade nil 'upgrade nil
(guix-get-installed-outputs entry))))) (guix-package-installed-outputs entry)))))
(defun guix-list-execute-package-actions (fun) (defun guix-list-execute-package-actions (fun)
"Perform actions on the marked packages. "Perform actions on the marked packages.
@ -758,7 +755,7 @@ Return nil, if there are no outputs marked with ACTION-TYPE.
The specification is suitable for `guix-process-output-actions'." The specification is suitable for `guix-process-output-actions'."
(let ((ids (guix-list-get-marked-id-list action-type))) (let ((ids (guix-list-get-marked-id-list action-type)))
(and ids (cons action-type (and ids (cons action-type
(mapcar #'guix-get-package-id-and-output-by-output-id (mapcar #'guix-package-id-and-output-by-output-id
ids))))) ids)))))
(defun guix-output-list-describe (&optional arg) (defun guix-output-list-describe (&optional arg)
@ -773,7 +770,7 @@ Also see `guix-package-info-type'."
(unless arg '(general))) (unless arg '(general)))
(list (guix-list-current-id)))) (list (guix-list-current-id))))
(pids (mapcar (lambda (oid) (pids (mapcar (lambda (oid)
(car (guix-get-package-id-and-output-by-output-id (car (guix-package-id-and-output-by-output-id
oid))) oid)))
oids))) oids)))
(guix-list-describe-maybe 'package (cl-remove-duplicates pids))))) (guix-list-describe-maybe 'package (cl-remove-duplicates pids)))))