summaryrefslogtreecommitdiff
path: root/emacs
diff options
context:
space:
mode:
authorAlex Kost <alezost@gmail.com>2016-05-15 10:34:47 +0300
committerAlex Kost <alezost@gmail.com>2016-05-31 23:51:54 +0300
commit65e5fe54bae67fbd6de225fd8cc909401045a099 (patch)
tree85b3b82d01c28aad0feae90e080c376e18782276 /emacs
parentd01ebd05d11775dea7c8d0a084c3ab02b958e18b (diff)
downloadpatches-65e5fe54bae67fbd6de225fd8cc909401045a099.tar
patches-65e5fe54bae67fbd6de225fd8cc909401045a099.tar.gz
emacs: Extend 'guix-mapinsert'.
* emacs/guix-utils.el (guix-mapinsert): Add 'indent' and 'column' keyword arguments.
Diffstat (limited to 'emacs')
-rw-r--r--emacs/guix-utils.el33
1 files changed, 25 insertions, 8 deletions
diff --git a/emacs/guix-utils.el b/emacs/guix-utils.el
index ea9933f5c3..3e4ecc36ab 100644
--- a/emacs/guix-utils.el
+++ b/emacs/guix-utils.el
@@ -84,16 +84,33 @@ If FORMAT is non-nil, format VAL with FORMAT."
(format format str)
str))))
-(defun guix-mapinsert (function sequence separator)
+(cl-defun guix-mapinsert (function sequence separator &key indent column)
"Like `mapconcat' but for inserting text.
Apply FUNCTION to each element of SEQUENCE, and insert SEPARATOR
-at point between each FUNCTION call."
- (when sequence
- (funcall function (car sequence))
- (mapc (lambda (obj)
- (insert separator)
- (funcall function obj))
- (cdr sequence))))
+at point between each FUNCTION call.
+
+If INDENT is non-nil, it should be a number of spaces used to
+indent each line of the inserted text.
+
+If COLUMN is non-nil, it should be a column number which
+shouldn't be exceeded by the inserted text."
+ (pcase sequence
+ (`(,first . ,rest)
+ (let* ((indent (or indent 0))
+ (max-column (and column (- column indent))))
+ (guix-with-indent indent
+ (funcall function first)
+ (dolist (element rest)
+ (let ((before-sep-pos (and column (point))))
+ (insert separator)
+ (let ((after-sep-pos (and column (point))))
+ (funcall function element)
+ (when (and column
+ (> (current-column) max-column))
+ (save-excursion
+ (delete-region before-sep-pos after-sep-pos)
+ (goto-char before-sep-pos)
+ (insert "\n")))))))))))
(defun guix-insert-button (label &optional type &rest properties)
"Make button of TYPE with LABEL and insert it at point.