From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ricardo Wurmus Subject: Re: Fwd: Re: Patch file for colorize module Date: Sat, 02 Jun 2018 17:01:35 +0200 Message-ID: <87a7sdb5bk.fsf@elephly.net> References: <8ea5d026-fab9-7b12-198e-610ad7743cb2@swecha.net> <87zi28kt82.fsf@elephly.net> <8573e97d-d107-cde6-cd17-35f4ef6d2de3@swecha.net> <87k1takumm.fsf@elephly.net> <87o9hycwl6.fsf@elephly.net> <87r2mhdeap.fsf@elephly.net> <618c131c-6ba6-e525-aefc-72acca1c910f@swecha.net> <87a7suwtp7.fsf@elephly.net> <149bfb8c-22b5-797d-e88a-ca4077b0a4cc@swecha.net> <87d0xmok8e.fsf@elephly.net> <87k1rsb9ex.fsf@elephly.net> <3e099b0b-e3ec-2bbb-6d10-5b7e48c4dff6@swecha.net> <300fd917-6742-3ef1-044d-4b0f38a44250@swecha.net> <87a7sm4v5j.fsf@elephly.net> <3d5eca09-7730-bd38-265b-7942d0ea16ed@swecha.net> <878t864i59.fsf@elephly.net> <87o9gwpcmx.fsf@elephly.net> <2f71be8d-c672-c66a-0b16-bc3abc748754@swecha.net> <877enjpquf.fsf@elephly.net> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:48591) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fP83W-0001UG-3c for guix-devel@gnu.org; Sat, 02 Jun 2018 11:02:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fP83U-00039u-0g for guix-devel@gnu.org; Sat, 02 Jun 2018 11:02:58 -0400 Received: from sender-of-o51.zoho.com ([135.84.80.216]:21024) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fP83T-000383-PQ for guix-devel@gnu.org; Sat, 02 Jun 2018 11:02:55 -0400 In-reply-to: <877enjpquf.fsf@elephly.net> 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: Sahitihi Cc: guix-devel Hi Sahithi, do you have any questions about the next steps outlined in the email below? Cheers, Ricardo Ricardo Wurmus writes: > Hi Sahithi, > >>> Have you started on working on this yet? If so,could you please give us >>> an update on your progress via email? >>> >> I have started out using different functions like >> >> |1) regexp-match 2) ||string-contains which resulted same output for >> strings > > The procedures tell you if something matched. > >> then i tried 1) >> string-match 2) string-substitute ended up using string substitute so >> that the result can be colored one. > > =E2=80=9Cstring-match=E2=80=9D either returns #f if the expression didn= =E2=80=99t match or it > returns a match structure that tells you *how* the expression was > matched. It is especially useful with match groups that are marked with > parentheses in the regular expression. See below for an example. > >> But I failed executing it. File is >> attached, Can u suggest where I went wrong. > > One obvious failing is in the arguments to =E2=80=9Cmake-soft-port=E2=80= =9D. It takes a > vector of five procedures, but you gave it a vector of one procedure > followed by an expression beginning with =E2=80=9Cregexp-substitute/globa= l=E2=80=9D and > then three more procedures. > > You need to give it five procedures wrapped in a vector. > > How about doing it this way: > > --8<---------------cut here---------------start------------->8--- > ;; The port to which we write our potentially colorized strings > (define target-port (current-output-port)) > > (define (handle-string str) > "Match on the input string STR and return a new string with added > color sequences." > ;; TODO: match on str and pass the modified string to the output port > (display str target-port)) > > (define my-colorful-port > (make-soft-port > (vector > (lambda (c) (write c target-port)) > handle-string > (lambda () (display "." target-port)) > (lambda () (char-upcase (read-char))) > (lambda () (display "@" target-port))) > "rw")) > > ;;;; Some tests! > > (display "Hello there!" my-colorful-port) ; no colours > (display "starting phase =E2=80=9CBig gorilla=E2=80=9D =E2=80=94 watch ou= t!" my-colorful-port) > (display "phase =E2=80=9CBig gorilla=E2=80=9D failed" my-colorful-port) > (display "I heard phase =E2=80=9CBig gorilla=E2=80=9D failed" my-colorful= -port) ; no colours here > ;;; =E2=80=A6and so on=E2=80=A6 > --8<---------------cut here---------------end--------------->8--- > > Now all you need to do is work on the =E2=80=9Chandle-string=E2=80=9D pro= cedure. > > I suggest using simpler matching procedures at first. To get started > try =E2=80=9Cstring-prefix?=E2=80=9D and use it with the string =E2=80=9C= starting phase=E2=80=9D. This > won=E2=80=99t work with regular expressions, though. > > While you *can* use =E2=80=9Cregexp-substitute/global=E2=80=9D, I don=E2= =80=99t think it=E2=80=99s a > good fit here, because we may want to extend the string matching > features, which is difficult to do with =E2=80=9Cregexp-substitute/global= =E2=80=9D. > Instead, try to match regular expressions one by one with =E2=80=9Cstring= -match=E2=80=9D > and then operate on the match structure it returns. If it returns #f > you can move on to the next expression. If none match you just return > the original string. If one matches you *rebuild* the string, but with > colours applied. > > Here=E2=80=99s an example: > > (define str "My name is Al Jarreau and I=E2=80=99m 76 years old.") > (define expr "(My name is )(.*)( and I=E2=80=99m )(.*)( years old.)") > > These are five match groups and we want to modify the second and fourth, > so we can do this: > > (or (and=3D> (string-match expr str) > (lambda (m) > (string-append > (match:substring m 1) > (string-upcase (match:substring m 2)) > (match:substring m 3) > (string-reverse (match:substring m 4)) > (match:substring m 5)))) > ;; Didn=E2=80=99t match, so return unmodified string. > str) > > If you don=E2=80=99t understand this example please look up the procedure= s in > the Guile manual. > >> As per IRC discussion with Ricardo, I tried installing emacs and >> running a shell. > > That is correct. We were trying to take a look at the features > guix-build-log-minor-mode provides, but we didn=E2=80=99t get that far. -- Ricardo