emacs: Extend 'guix-mapinsert'.
* emacs/guix-utils.el (guix-mapinsert): Add 'indent' and 'column' keyword arguments.
This commit is contained in:
parent
d01ebd05d1
commit
65e5fe54ba
|
@ -84,16 +84,33 @@ If FORMAT is non-nil, format VAL with FORMAT."
|
||||||
(format format str)
|
(format format str)
|
||||||
str))))
|
str))))
|
||||||
|
|
||||||
(defun guix-mapinsert (function sequence separator)
|
(cl-defun guix-mapinsert (function sequence separator &key indent column)
|
||||||
"Like `mapconcat' but for inserting text.
|
"Like `mapconcat' but for inserting text.
|
||||||
Apply FUNCTION to each element of SEQUENCE, and insert SEPARATOR
|
Apply FUNCTION to each element of SEQUENCE, and insert SEPARATOR
|
||||||
at point between each FUNCTION call."
|
at point between each FUNCTION call.
|
||||||
(when sequence
|
|
||||||
(funcall function (car sequence))
|
If INDENT is non-nil, it should be a number of spaces used to
|
||||||
(mapc (lambda (obj)
|
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)
|
(insert separator)
|
||||||
(funcall function obj))
|
(let ((after-sep-pos (and column (point))))
|
||||||
(cdr sequence))))
|
(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)
|
(defun guix-insert-button (label &optional type &rest properties)
|
||||||
"Make button of TYPE with LABEL and insert it at point.
|
"Make button of TYPE with LABEL and insert it at point.
|
||||||
|
|
Loading…
Reference in New Issue