summaryrefslogtreecommitdiff
path: root/emacs/guix-utils.el
diff options
context:
space:
mode:
authorAlex Kost <alezost@gmail.com>2015-11-20 00:13:19 +0300
committerAlex Kost <alezost@gmail.com>2016-01-02 17:25:35 +0300
commit2c7ed388cf403120c17b5e222ac5dda093f5ad94 (patch)
tree9e38f1f4f1457e6938add0a9a3875ee1ca5880e6 /emacs/guix-utils.el
parent25d2fe8bef7539e70fdd3b8785254037a6dbe25d (diff)
downloadpatches-2c7ed388cf403120c17b5e222ac5dda093f5ad94.tar
patches-2c7ed388cf403120c17b5e222ac5dda093f5ad94.tar.gz
emacs: info: Generalize inserting and formatting.
* emacs/guix-info.el: Use a more flexible format for inserting any data. (guix-info-ignore-empty-vals): Rename to... (guix-info-ignore-empty-values): ... this. (guix-info-insert-methods): Merge this and... (guix-info-displayed-params): ... this into... (guix-info-format): ... this. Change format specifications. (guix-info-title-aliases, guix-info-value-aliases): New variables. (guix-info-displayed-params): Adjust for the new format. (guix-info-insert-entry): Likewise. (guix-package-info-fill-heading): Replace with... (guix-info-fill): ... this. (guix-info-insert-param): Replace with... (guix-info-insert-entry-unit): ... this. (guix-info-insert-title-default): Replace with... (guix-info-insert-title-format): ... this. (guix-info-insert-val-default): Replace with... (guix-info-insert-value-format): ... this. (guix-info-insert-val-simple): Replace with... (guix-info-insert-value-indent): ... this. (guix-package-info-insert-source): Adjust accordingly. (guix-package-info-insert-heading): Insert only name and version. (guix-package-info-define-insert-inputs): Do not generate 'guix-package-info-insert-ENTRY-TYPE-inputs' procedures. (guix-info-fill-column, guix-info-insert-entry-default) (guix-info-method-funcall, guix-info-insert-file-path) (guix-info-insert-url, guix-info-insert-package-function) (guix-info-insert-installed-function) (guix-info-insert-output-function) (guix-info-insert-generation-function) (guix-package-info-heading-params) (guix-package-info-insert-with-heading) (guix-package-info-insert-description) (guix-package-info-insert-location) (guix-package-info-insert-full-names) (guix-package-info-insert-source-url): Remove. (guix-info-fill-column, guix-info-param-title) (guix-info-title-function, guix-info-value-function) (guix-info-title-method->function) (guix-info-value-method->function) (guix-info-insert-value-simple): New procedures. * emacs/guix-utils.el (guix-buttonize, guix-button-type?): New procedures. (guix-split-string): Split multi-line strings and ignore empty lines. * doc/emacs.texi (Emacs Appearance): Adjust accordingly.
Diffstat (limited to 'emacs/guix-utils.el')
-rw-r--r--emacs/guix-utils.el35
1 files changed, 27 insertions, 8 deletions
diff --git a/emacs/guix-utils.el b/emacs/guix-utils.el
index fbe0a613da..3c75417a08 100644
--- a/emacs/guix-utils.el
+++ b/emacs/guix-utils.el
@@ -104,6 +104,28 @@ See `insert-text-button' for the meaning of PROPERTIES."
:type (or type 'button)
properties)))
+(defun guix-buttonize (value button-type separator &rest properties)
+ "Make BUTTON-TYPE button(s) from VALUE.
+Return a string with button(s).
+
+VALUE should be a string or a list of strings. If it is a list
+of strings, buttons are separated with SEPARATOR string.
+
+PROPERTIES are passed to `guix-insert-button'."
+ (with-temp-buffer
+ (let ((labels (if (listp value) value (list value))))
+ (guix-mapinsert (lambda (label)
+ (apply #'guix-insert-button
+ label button-type properties))
+ labels
+ separator))
+ (buffer-substring (point-min) (point-max))))
+
+(defun guix-button-type? (symbol)
+ "Return non-nil, if SYMBOL is a button type."
+ (and symbol
+ (get symbol 'button-category-symbol)))
+
(defun guix-split-insert (val &optional face col separator)
"Convert VAL into a string, split it and insert at point.
@@ -122,14 +144,11 @@ Separate inserted lines with SEPARATOR."
(defun guix-split-string (str &optional col)
"Split string STR by lines and return list of result strings.
-If COL is non-nil and STR is a one-line string longer than COL,
-split it into several short lines."
- (let ((strings (split-string str "\n *")))
- (if (and col
- (null (cdr strings)) ; if not multi-line
- (> (length str) col))
- (split-string (guix-get-filled-string str col) "\n")
- strings)))
+If COL is non-nil, fill STR to this column."
+ (let ((str (if col
+ (guix-get-filled-string str col)
+ str)))
+ (split-string str "\n *" t)))
(defun guix-get-filled-string (str col)
"Return string by filling STR to column COL."