From mboxrd@z Thu Jan 1 00:00:00 1970 From: taylanbayirli@gmail.com ("Taylan Ulrich =?utf-8?Q?Bay=C4=B1rl=C4=B1?= =?utf-8?Q?=2FKammer=22?=) Subject: utils: Improve docstrings. Date: Tue, 25 Nov 2014 21:52:13 +0100 Message-ID: <87bnnv80le.fsf@taylan.uni.cx> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:48776) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XtN5u-0008Rb-Am for guix-devel@gnu.org; Tue, 25 Nov 2014 15:52:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XtN5t-0000uw-27 for guix-devel@gnu.org; Tue, 25 Nov 2014 15:52:18 -0500 Received: from mail-wi0-x22b.google.com ([2a00:1450:400c:c05::22b]:55569) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XtN5s-0000us-R1 for guix-devel@gnu.org; Tue, 25 Nov 2014 15:52:16 -0500 Received: by mail-wi0-f171.google.com with SMTP id bs8so10433100wib.10 for ; Tue, 25 Nov 2014 12:52:16 -0800 (PST) Received: from taylan.uni.cx (p200300514A0E18030213E8FFFEED36FB.dip0.t-ipconnect.de. [2003:51:4a0e:1803:213:e8ff:feed:36fb]) by mx.google.com with ESMTPSA id fm10sm3439577wjc.43.2014.11.25.12.52.14 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 25 Nov 2014 12:52:15 -0800 (PST) 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-bounces+gcggd-guix-devel=m.gmane.org@gnu.org To: guix-devel@gnu.org I just spend half an hour trying to find the bug in the following: (substitute* "Makefile.in" (("^(prefix=[[:blank:]]*)/usr/local$" all prefix) (string-append prefix (assoc-ref outputs "out")))) until I realized the lines of the file are represented as newline terminated strings and a $ in the regexp won't match a newline by default. The behavior could be changed, but it seems like it was explicitly programmed to work this way, and does make sense in a way, so I decided to add a warning about this into the docstrings of `substitute' and `substitute*'. WDYT? ===File /home/tub/media/src/guix/0001-utils-Improve-docstrings.patch=== >From 3f472e56c3fd9482e42fe8eecee5a857dbd2b8cc Mon Sep 17 00:00:00 2001 From: Taylan Ulrich B Date: Tue, 25 Nov 2014 21:25:16 +0100 Subject: [PATCH] utils: Improve docstrings. * guix/build/utils.scm (substitute): Clarify first sentence of docstring and add warning to the docstring about using '$' to match an end of line. (substitute*): Add warning to the docstring about using '$' to match an end of line. --- guix/build/utils.scm | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/guix/build/utils.scm b/guix/build/utils.scm index cda4fb1..d93366d 100644 --- a/guix/build/utils.scm +++ b/guix/build/utils.scm @@ -365,10 +365,11 @@ PROC's result is returned." (false-if-exception (delete-file template)))))) (define (substitute file pattern+procs) - "PATTERN+PROCS is a list of regexp/two-argument procedure. For each line -of FILE, and for each PATTERN that it matches, call the corresponding PROC -as (PROC LINE MATCHES); PROC must return the line that will be written as a -substitution of the original line." + "PATTERN+PROCS is a list of regexp/two-argument-procedure pairs. For each +line of FILE, and for each PATTERN that it matches, call the corresponding +PROC as (PROC LINE MATCHES); PROC must return the line that will be written as +a substitution of the original line. Be careful about using '$' to match the +end of a line; by itself it won't match the terminating newline of a line." (let ((rx+proc (map (match-lambda (((? regexp? pattern) . proc) (cons pattern proc)) @@ -428,7 +429,10 @@ When one of the MATCH-VAR is `_', no variable is bound to the corresponding match substring. Alternatively, FILE may be a list of file names, in which case they are -all subject to the substitutions." +all subject to the substitutions. + +Be careful about using '$' to match the end of a line; by itself it won't +match the terminating newline of a line." ((substitute* file ((regexp match-var ...) body ...) ...) (let () (define (substitute-one-file file-name) -- 2.1.2 ============================================================