From mboxrd@z Thu Jan 1 00:00:00 1970 From: Alex Kost Subject: [PATCH 2/4] emacs: Extend 'guix-mapinsert'. Date: Sat, 28 May 2016 17:36:12 +0300 Message-ID: <1464446174-1868-2-git-send-email-alezost@gmail.com> References: <1464446174-1868-1-git-send-email-alezost@gmail.com> Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:42054) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b6fLn-00030x-9c for guix-devel@gnu.org; Sat, 28 May 2016 10:36:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b6fLf-0007HC-U6 for guix-devel@gnu.org; Sat, 28 May 2016 10:36:26 -0400 Received: from mail-lf0-x242.google.com ([2a00:1450:4010:c07::242]:33459) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b6fLf-0007H1-Mu for guix-devel@gnu.org; Sat, 28 May 2016 10:36:19 -0400 Received: by mail-lf0-x242.google.com with SMTP id w16so8678455lfd.0 for ; Sat, 28 May 2016 07:36:19 -0700 (PDT) Received: from localhost.localdomain ([217.107.192.156]) by smtp.gmail.com with ESMTPSA id u188sm1086937lja.11.2016.05.28.07.36.18 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 28 May 2016 07:36:18 -0700 (PDT) In-Reply-To: <1464446174-1868-1-git-send-email-alezost@gmail.com> List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: "Guix-devel" To: guix-devel@gnu.org * 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