From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id KOlWAbFt2mNHbQEAbAwnHQ (envelope-from ) for ; Wed, 01 Feb 2023 14:48:33 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id 2Dt8AbFt2mMPUAEA9RJhRA (envelope-from ) for ; Wed, 01 Feb 2023 14:48:33 +0100 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 3784D223D for ; Wed, 1 Feb 2023 14:48:32 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pNDT7-00023H-Qv; Wed, 01 Feb 2023 08:48:09 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pNDT0-00021U-C8 for guix-patches@gnu.org; Wed, 01 Feb 2023 08:48:02 -0500 Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pNDT0-0001Ru-25 for guix-patches@gnu.org; Wed, 01 Feb 2023 08:48:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pNDSz-0006im-Mb for guix-patches@gnu.org; Wed, 01 Feb 2023 08:48:01 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#60753] [PATCH] gnu: home: Add home-emacs-service-type. Resent-From: Andrew Tropin Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Wed, 01 Feb 2023 13:48:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 60753 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: Jelle Licht , Ludovic =?UTF-8?Q?Court=C3=A8s?= Cc: "\(" , David Wilson , 60753@debbugs.gnu.org Received: via spool by 60753-submit@debbugs.gnu.org id=B60753.167525923725625 (code B ref 60753); Wed, 01 Feb 2023 13:48:01 +0000 Received: (at 60753) by debbugs.gnu.org; 1 Feb 2023 13:47:17 +0000 Received: from localhost ([127.0.0.1]:56870 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pNDSG-0006fE-Ss for submit@debbugs.gnu.org; Wed, 01 Feb 2023 08:47:17 -0500 Received: from relay7-d.mail.gandi.net ([217.70.183.200]:44077) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pNDSB-0006ev-Sl for 60753@debbugs.gnu.org; Wed, 01 Feb 2023 08:47:16 -0500 Received: (Authenticated sender: andrew@trop.in) by mail.gandi.net (Postfix) with ESMTPSA id 674AE20008; Wed, 1 Feb 2023 13:47:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=trop.in; s=gm1; t=1675259225; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=gJnLTYs6Ci+cdnKK4ckETem1FtZiznxuIkoEihwAUYo=; b=ILhIgxA6tx1G6jtUsGijebpOCDxyaJppf5ytDCOUKjhpm9oP2CHJOSYgQeoC0YLFyxRLHg a0PyKBwDMKIc+ZvzZy3rZjZWJPYn3eFmqX+bk50fvIjxvmZAJx4OIefkWXUljPZO+K7Kab HtvfIpa2TSf4F74eF/P9rIBimOexLjGs8LhUWHcxVUF9gEqTbICbcxdPqUbIMTXeYhnupl LMTRSlRx2HWAXPEEfEorHSCRVGd6HTb00DmgkymnlnfLPMN5GEASJH1Fn3qdjhRk0ldzoT GuNFbwmXXtF/8zgPqmMJV4Hhx6MesaWcEnUL1Ylg82KjdWjj6bVfLbY2nHdwfw== From: Andrew Tropin In-Reply-To: <87lelhils1.fsf@posteo.net> References: <87edrzzw9w.fsf@daviwil.com> <87v8lby7jq.fsf@daviwil.com> <87k01p8086.fsf_-_@gnu.org> <87cz7g2pkz.fsf@trop.in> <87mt6hjzyx.fsf@gnu.org> <87wn5l8bhz.fsf@trop.in> <87ilgx4kqg.fsf@gnu.org> <87v8ktvq99.fsf@trop.in> <87lelhils1.fsf@posteo.net> Date: Wed, 01 Feb 2023 17:46:59 +0400 Message-ID: <87wn51qyzw.fsf@trop.in> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha512; protocol="application/pgp-signature" X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: guix-patches-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1675259312; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:resent-cc:resent-from:resent-sender: resent-message-id:in-reply-to:in-reply-to:references:references: list-id:list-help:list-unsubscribe:list-subscribe:list-post: dkim-signature; bh=gJnLTYs6Ci+cdnKK4ckETem1FtZiznxuIkoEihwAUYo=; b=tQjF4PmQrG2n4LEt4D85Y1z70SB3Gn8uwysgy1u1gKbbhdQKWCPKswGHWAdls0QWyjU6aa S7DRVz5A8bDHyamQlUBtN+TwdMIf3soPSWXyEFGteFGjGlCACDXBI0EWOM0desAtkLUBYM q2FhKMpH982Mw61E0YQHRjPQPvwM26SnHhS0hXop3NzjHpM9Bsra9pEhxnmyXxgN7n0qaP pTjRVDU5o6X+Fg91i0HuFW1AQ4leThbziCqCjGQLNoZjacb9gplZvcR6sKTq8Wn2y98i7W iBV4Bol5FPGYshQQJBKu+JPMlfHsEVRW9mC4KbkofiFneDOWwmviFmqTHjZuxg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=trop.in header.s=gm1 header.b=ILhIgxA6; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org"; dmarc=none ARC-Seal: i=1; s=key1; d=yhetil.org; t=1675259312; a=rsa-sha256; cv=none; b=n4xld1tdU4DXwx0o1yXcIzUwP4VQoNUWphNqE+GYATzl4OrpygTJaQ+zjJ5FCFydo7A+fD nLFXWbxT2V3IAHKGHwes+4pKrrjLMFWvs/epqxfniU+MFESPTbzTuCmZYO5rULybA3QiLB t/qRpEREWFBL7nGH2Ye1NcphA1FbAYR5v7oeLJ+GApgnWkU36Kb2YB8HPL0vMib+n3X1QV veZY3kmKnsTWeZ1aG0D/z8514MZU1JIKOnZySy8xpFOFSg6gRreZUan6UT7CeDU762Hjiv rpzHnWFlVXnjtlknZsVxEnZVBZOjpZUZ/+TZZX7RA0q3aM96vnvkqGu9rPxN2Q== Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=trop.in header.s=gm1 header.b=ILhIgxA6; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org"; dmarc=none X-Migadu-Scanner: scn0.migadu.com X-Spam-Score: -2.78 X-Migadu-Queue-Id: 3784D223D X-Migadu-Spam-Score: -2.78 X-TUID: R8GqLj/3xcMI --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 2023-02-01 12:59, Jelle Licht wrote: > Andrew Tropin writes: > >> On 2023-01-23 11:18, Ludovic Court=C3=A8s wrote: >> >>> Hi, >>> >>> Andrew Tropin skribis: >>> >>>> On 2023-01-17 10:02, Ludovic Court=C3=A8s wrote: >>>> >>>>> Hi, >>>>> >>>>> Andrew Tropin skribis: >>>>> >>>>>>> What about accepting sexps (or gexps) instead of strings? As in: >>>>>>> >>>>>>> (init-file '((require 'whatever) (setq something t))) >>>>>> >>>>>> A quick minor note on this approach: it won't be possible to use >>>>>> #'elisp-function inside such configuration because it will be >>>>>> interpreted by guile reader, but actually rde lives without this >>>>>> functionality completely ok. >>>>> >>>>> Specifically: >>>>> >>>>> (write '#'x) >>>>> |=3D (syntax x) >>>>> >>>>> But we can use (guix read-print) and ensure that it prints #'. >>>>> >>>> >>>> Do you have any links to docs/sample implementations on the topic of >>>> extending guile reader, so we have an example to start with? >>> >>> It=E2=80=99s not the reader but rather the writer that we=E2=80=99d wan= t to tweak. >> >> Right, it already can read #'x as (syntax x) and we can print it >> properly later, but AFAIK comments are ignored by the default reader. >> So I would expect to do something (very roughly) like this: >> >> --8<---------------cut here---------------start------------->8--- >> (parameterize (((@@ (guix gexp) read-procedure) read-with-comments)) >> #~(list 'hello ; Comment I would like to preserve during serialization >> 'guix)) >> --8<---------------cut here---------------end--------------->8--- >> >> Of course it doesn't work, but I hope demonstrates the idea. >> >>> >>> In (guix read-print), =E2=80=98pretty-print-with-comments=E2=80=99 alre= ady special >>> cases quasiquote etc. so that it prints =E2=80=98`=E2=80=99 (backtick) = and not >>> =E2=80=98quasiquote'. We=E2=80=99d add clauses for =E2=80=98syntax=E2= =80=99 and =E2=80=98quasisyntax=E2=80=99. >>> >> >> It seems ice-9 pretty-print also preserves backticks, but I see that >> pretty-print-with-comments also preserves gexps, which is cool. Adding >> syntax will make it even cooler. >> >>>> I think it will be cool to hook up a custom reader, ideally comment >>>> preserving, for emacs lisp inside scheme files. >>> >>> (guix read-print) is what you want. :-) >>> >> >> Can you give a hint on how to use it for preserving comments, please? >> >>>>>> Do we want something like this possible? >>>>>> >>>>>> (init-file `((require 'whatever) >>>>>> (setq something t) >>>>>> (load ,(local-file "old-init.el"))) >>>>> >>>>> It=E2=80=99d be nice. In that case, we=E2=80=99ll want it to be a ge= xp though: >>>>> >>>>> #~((require 'whatever) (load #$(local-file =E2=80=A6))) >>>>> >>>> >>>> gexps are nice, but do we really need/want them here? Do you have any >>>> thoughts on what are the benifits over quasiquotes in this case? Maybe >>>> some examples? >>> >>> The benefit in the example above is that the gexp would actually work >>> whereas the sexp wouldn=E2=80=99t :-), unless there=E2=80=99s code some= where to manually >>> traverse the sexp adn replace the record with its store >>> item (which is what gexps are about). >>> >>> I hope that makes sense! >> >> With this simple serializer we already achieved quite good results:=20 >> https://git.sr.ht/~abcdw/rde/tree/388d3ad95e8607543df3dcdf26d058b610e773= 89/src/rde/serializers/lisp.scm#L35 >> >> For this input >> --8<---------------cut here---------------start------------->8--- >> `((load ,(local-file "./feature-lists.scm")) >> ,#~(format #f "hello") ; top level gexps are evaluated >> (list ,#~(format #f "hello")) ; nested gexps are not >> ,#~";; hacky comment" >> ;; comment, which is not preserved >> #'hi-fn ; incorrectly serialized, but fixable by alternative >> ; pretty-print >> ) >> --8<---------------cut here---------------end--------------->8--- >> >> it provides quite satisfying results: >> --8<---------------cut here---------------start------------->8--- >> (load "/gnu/store/xb6ma0mcgg1zzq645s63arvy3qskmbiz-feature-lists.scm") >> hello >> (list (format #f "hello")) >> ;; hacky comment >> (syntax hi-fn) >> --8<---------------cut here---------------end--------------->8--- >> >> It's a little incosistent (top level gexp are evaluated, but nested are >> not), comments are not preserved and #' serialized incorrectly, but >> other than that it works very good. >> >> WDYT about overall approach used here? or we can do it radically >> better? > > Not saying it's better in any particular way, but I have had this locally > for all my elisp-read-by-guile-written-back-to-elisp needs: I saw it in guix-home-manager and probably you've made the thread on rde-devel too. I tried some parts of this code, but didn't succeed to get a complete working out of it, now I have a little more knowledge and hope will get better results :) > > --8<---------------cut here---------------start------------->8--- > (define-module (jlicht build elisp-write) > #:use-module (ice-9 match) > #:use-module (srfi srfi-1) > #:export (elisp-write)) > > (define (elisp-write in-list? exp port) > "Stack-blowing implementation that writes guile's internal elisp > representation to something that can be parsed by Emacs." > ;; Definitions from (language elisp parser)'s quotation-symbols:=20 > (define symbol-strings > '((#{`}# . "`") > (#{,}# . ",") > (#{,@}# . ",@"))) > (define (elisp-symbol? sym) > (assq sym symbol-strings)) > (define (write-elisp-symbol sym port) > (format port "~A" (assq-ref symbol-strings sym))) >=20=20=20 > (match exp > (((? elisp-symbol? sym) rest) > (write-elisp-symbol sym port) > (elisp-write in-list? rest port)) > ;; Vector expression > (#(vs ...) > (format port "[") > (elisp-write #t vs port) > (format port "]")) > ;; Guile elisp implementation detail > ('(%set-lexical-binding-mode #f) 'skip) > ;; List walker > ((e ...) > (when (not in-list?) (format port "(")) > (unless (null? e) > (elisp-write #f (car e) port) > (for-each (lambda (v) > (format port " ") > (elisp-write #f v port)) (cdr e))) > (when (not in-list?) (format port ")"))) > ;; dotted pair > ((and (? pair?) (? dotted-list? l)) > (format port "(") > (elisp-write #t (drop-right l 0) port) > (format port " . ") > (elisp-write #t (take-right l 0) port) > (format port ")")) > ;; Print simple primitives > (_ (write exp port)))) > --8<---------------cut here---------------end--------------->8--- > > On the reader side I just use guile's elisp reader: > > --8<---------------cut here---------------start------------->8--- > (define-module (jlicht test elisp) > #:use-module (language elisp parser) > #:use-module (jlicht build elisp-write) > #:use-module (srfi srfi-26) > #:use-module (srfi srfi-64)) > > (eval-when (expand load eval) > (read-hash-extend #\e (lambda (chr port) (read-elisp port)))) That's what I was looking for. If you have any links related to the topic of the reader extension, please let me know. > > (set! test-log-to-file #f) > > (define (roundtrip expr) > (let ((written (call-with-output-string (cut elisp-write #f expr <>)))) > (call-with-input-string written read-elisp))) > > (define-syntax test-roundtrip-equals > (syntax-rules () > ((_ expr) > (let ((e1 (roundtrip expr))) > (test-equal e1 (roundtrip e1)))))) > > (define runner (test-runner-simple)) > > (test-with-runner runner > (test-begin "roundtrip-elisp-fixed-point") > (test-roundtrip-equals 12) > (test-roundtrip-equals "hello") > (test-roundtrip-equals '#e#'my-fn) > (test-roundtrip-equals '#e[a b c]) > (test-roundtrip-equals '#e`(+ 1 2 ,@(a b) ,c)) It would be cool to make elisp-unquote for #e, but I think I can take a look at ungexp to understand how to implement it. > (test-end "roundtrip-elisp-fixed-point")) > > (exit (test-runner-fail-count runner)) > --8<---------------cut here---------------end--------------->8--- > > I've also hooked it up in combination with a sequence of calls to > `scheme-file' -> `computed-file' called `elisp-file', but that's a bit > more hacky and less relevant to the current discussion. > > - Jelle Thank you very much! =2D-=20 Best regards, Andrew Tropin --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEKEGaxlA4dEDH6S/6IgjSCVjB3rAFAmPabVMACgkQIgjSCVjB 3rCNKg/9HqXUnnKgo6sQGDDz8nkA0FkAsm0qCSS20Pa/vL3eZnD7umgSqADUXRyo b0N8Y/hhP/dU59AK/Lp3h4x9V6r/WmvK/oO2Ai9JQ2VLeeaUPwKDIlAOp/yBplDP zh/+xBcqy5lHfoTZI3TlgHDGTc0Ceb8L/PqGlc6kEwoOQP9VWg8XyoMpbvPp/m7u 7vQAHJZzK/WRN/NMxb4S6wTd22ZzP01Y5rRLdwiklGZM5U0osLcJCU2NaOiAJtWT HdbsA5S5auWeGTkk6pV9c3X4Qi7RTEm+M7/0piJE6pwmyw7LulDqZ/RczsxFnJrE z5hq7otbsBLMgsx3/7dcCwOTFTzgI0orw/tCHKq8Q1qqo7Rxizq5B9nuUKl/e1Ph yez13UTtCuuS2A6djyLHjD5sNIGCc/AEzdozauXvMKHQnRX8mEE0eSGCsu4FVqm0 pAYXvRrAxVsMjRmmklkIWETkqbbHbU2WT7cGs1i2gSlFPeljPbcLcFVp2PlL7GUt TvgpZ7hi3i2/n+UbeK0OlW+C+8KNuGBqitQwLeRzjDt8Np1FmT2ZahtRwwZ4ixs8 A5Lk7mvnMgDK06cjoOr8jDKgIkBDIKJHvoMINJ0ugAJV2MjTjv57YkGqIDR59+kS flGC+2qR+w57hGTcWZ67XorwpiwHQLOXNZ5/BPalmeycFpPsJEU= =JnjR -----END PGP SIGNATURE----- --=-=-=--