From: Alex Kost <alezost@gmail.com>
To: guix-devel@gnu.org
Subject: [PATCH 2/4] emacs: Extend 'guix-mapinsert'.
Date: Sat, 28 May 2016 17:36:12 +0300 [thread overview]
Message-ID: <1464446174-1868-2-git-send-email-alezost@gmail.com> (raw)
In-Reply-To: <1464446174-1868-1-git-send-email-alezost@gmail.com>
* emacs/guix-utils.el (guix-mapinsert): Add 'indent' and 'column'
keyword arguments.
---
emacs/guix-utils.el | 33 +++++++++++++++++++++++++--------
1 file changed, 25 insertions(+), 8 deletions(-)
diff --git a/emacs/guix-utils.el b/emacs/guix-utils.el
index ea9933f..3e4ecc3 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.
--
2.7.3
next prev parent reply other threads:[~2016-05-28 14:36 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-28 14:36 [PATCH 1/4] emacs: Show built output directories in Package Info Alex Kost
2016-05-28 14:36 ` Alex Kost [this message]
2016-05-30 21:14 ` [PATCH 2/4] emacs: Extend 'guix-mapinsert' Ludovic Courtès
2016-05-28 14:36 ` [PATCH 3/4] emacs: Add "Build" button to Package Info Alex Kost
2016-05-30 21:15 ` Ludovic Courtès
2016-05-28 14:36 ` [PATCH 4/4] emacs: Add "Build Log" " Alex Kost
2016-05-30 21:17 ` Ludovic Courtès
2016-05-31 21:09 ` Alex Kost
2016-06-01 21:04 ` Ludovic Courtès
2016-05-30 21:13 ` [PATCH 1/4] emacs: Show built output directories in " Ludovic Courtès
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1464446174-1868-2-git-send-email-alezost@gmail.com \
--to=alezost@gmail.com \
--cc=guix-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/guix.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.