From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Timothy Newsgroups: gmane.emacs.devel Subject: Re: Core package offering - engrave-faces.el Date: Fri, 16 Jul 2021 21:08:15 +0800 Message-ID: <87h7guxv7k.fsf@gmail.com> References: <87y2afv122.fsf@gmail.com> <871r7yztf3.fsf@gmail.com> <7319ffa7-d566-41b8-b778-69db2f6becc9@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="563"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.4.15; emacs 28.0.50 Cc: Emacs developers To: =?utf-8?Q?Cl=C3=A9ment?= Pit-Claudel Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Jul 16 15:09:20 2021 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m4Nai-000AVx-85 for ged-emacs-devel@m.gmane-mx.org; Fri, 16 Jul 2021 15:09:20 +0200 Original-Received: from localhost ([::1]:48516 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m4Nah-0002uf-5z for ged-emacs-devel@m.gmane-mx.org; Fri, 16 Jul 2021 09:09:19 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:60944) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m4NZp-00029n-3H for emacs-devel@gnu.org; Fri, 16 Jul 2021 09:08:25 -0400 Original-Received: from mail-pg1-x536.google.com ([2607:f8b0:4864:20::536]:43990) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m4NZk-0004Ih-FP for emacs-devel@gnu.org; Fri, 16 Jul 2021 09:08:24 -0400 Original-Received: by mail-pg1-x536.google.com with SMTP id y4so9882305pgl.10 for ; Fri, 16 Jul 2021 06:08:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=references:user-agent:from:to:cc:subject:in-reply-to:message-id :date:mime-version:content-transfer-encoding; bh=/HbIib2rBnp2YuuCublu/EJ/GcRvO42UkUC/oHuatvk=; b=U1oq3JaCIIb+WowJAprG4H/4sgw0v/Su/bA36Bj9BSW+/4M5lPCXg/9sRoCzZZoen8 AQLRH1Zh3BAVKkli6N1Zp9vhPrX5UaMETmeRqI9UgPBATko2SVjZHSKBB7fNzOXqoy2a Aj+2p9Cd/25w0tTYZdviO9NWv6ACoCyT5YsMoj+ADEQC56Tic555JSnWS5ITGlyWuWbf YXO1Cooy8+pn+lYkCY37bhJGK9QKg0xf9jfJ5PvFG5dAQrzN31Zxdoy/pQfJkVqgsLQj /aHGZtgETqHeGP7ofkzMZqGsZ7z0QUDMLpXVyWI03PPaJIXTIQiRUoRZKdT/J4Mjd4dB 1Bpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:references:user-agent:from:to:cc:subject :in-reply-to:message-id:date:mime-version:content-transfer-encoding; bh=/HbIib2rBnp2YuuCublu/EJ/GcRvO42UkUC/oHuatvk=; b=oYQIDZaQjXKbENh6pFMnCx3cB2NTQbAaVSg9IwxNj33H0v55mgOdxkx72+6lTsCeff Kl9ZpTL22JzN5zxnrHuSjv1kpWfPjYPh0wUB/KThH5j1ThVU/r7wSmKuEP3DJqP9SdIz 4yUXxkUqh2t3RbWbO7j9d9ZRzKmOdisLeosHxJ9WASZ2jobHNuBqBmKshGW8T1Axg0IJ 5BLdigS7UOPIguzzfBgY6/ueEBSRrgSYK8WMxX46h8fTtraxWJ+/T7Np/NHsbHxNVGyA ol/CaVVibQktnE2RG7nceHlXx/oNYrcBn6iXIqK9g6G8OozPDnuoepg1xwJtYgUvNaFf heug== X-Gm-Message-State: AOAM533zva5mmzDSlpXATTTaizlXjJnzxtA1BeS3+ze/WP77CCBQa4/d TLvFnn7RWfTWvKHNEJmOy7Y= X-Google-Smtp-Source: ABdhPJyfck6xP+nuC1DOj87vzviudr0bZhuXpYl9f4OhRiI9E5pnwmC4cAlGMzwbL3SUpXOOkCLu5w== X-Received: by 2002:a63:1622:: with SMTP id w34mr9979772pgl.354.1626440899017; Fri, 16 Jul 2021 06:08:19 -0700 (PDT) Original-Received: from localhost (180-150-91-8.b4965b.per.nbn.aussiebb.net. [180.150.91.8]) by smtp.gmail.com with ESMTPSA id z3sm10140300pfa.67.2021.07.16.06.08.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Jul 2021 06:08:18 -0700 (PDT) In-reply-to: <7319ffa7-d566-41b8-b778-69db2f6becc9@gmail.com> Received-SPF: pass client-ip=2607:f8b0:4864:20::536; envelope-from=tecosaur@gmail.com; helo=mail-pg1-x536.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:271299 Archived-At: Hi Cl=C3=A9ment, thanks for your email. I'll paste your reply that you kind= ly linked and respond inline. Cl=C3=A9ment Pit-Claudel writes: >> Unlike htmlize, Engrave Faces provides general functionality to >> transform a buffer into another format with font-lock information. >> This core functionality is currently made us of in >> engrave-faces-latex.el, engrave-faces-ansi.el, and engrave-faces-html.el >> to provide exporters for LaTeX, ASCII/ANSI, and HTML. > > Neat! But, I'm not sure I understand what the package actually does. Can = you > give a short example of the API and the results it produces? Sure! So each of the engrave-faces-FORMAT.el files defines 1-2 user facing interactive functions: - engrave-faces-FORMAT-buffer, and maybe - engrave-faces-FORMAT-buffer-standalone These both return a new buffer which is an export of the current to FORMAT. So for example if I have an elisp buffer which only contains (funcall #'message "hi") and call M-x engrave-faces-latex-buffer I will be taken to a new buffer containing \color[HTML]{383a42}\textcolor[HTML]{4078f2}{(}\EFc{funcall} \EFhq{\#'}\E= Fhs{message} \EFs{"hi"}\textcolor[HTML]{4078f2}{)} and M-x engrave-faces-latex-buffer will give (funcall #'message "hi") While the -standalone variants will generate a valid LaTeX/HTML document with a preamble defining some of the commands/classes seen above. Meanwhile, the most notable part of the core library itself (engrave-faces.el) would be the macro `engrave-faces-define-backend'. This could really do with a good docstring, but it takes - a format name FORMAT - the file extension for FORMAT - a "face transforming" function What this "face transforming" function needs to do is given a list of faces applying to a certain content string, generate a new string that applies that information to the content in FORMAT. There's a rather nice helper function which I expect to be made use of here, `engrave-faces-merge-attributes' which will take a face spec list (as simple as "(default)" or complex as "((:weight bold :inherit default) warning highlight (:extend t))") and a list of attributes, and resolve all the attributes for that face spec while considering the 'saved' faces in `engrave-faces-preset-styles' -- returning a plist like: (:foreground #FCCE7B :background #51afef :slant nil :weight bold :height = nil :strike-through nil) This can then be used to create a transformed version of the content with face information in FORMAT like: c= ontent... With such a "face transforming" function `engrave-faces-define-backend' will create the user-facing function `engrave-faces-FORMAT-buffer' which will apply this transformation across the whole buffer. I hope this gives you a better idea of what this package is doing :) > If I understand correctly, the following may be relevant: > > https://github.com/cpitclaudel/esh (I mention it because it supports expo= rting > overlays to HTML and LaTeX, too, and it uses a tricky algorithm to correc= tly > handle overlapping fontification) > https://github.com/Lindydancer/faceup > https://github.com/Lindydancer/face-explorer Interesting. I have not seen many of these before. >> For comparison, htmlize.el is 1700 sloc and htmlfontify.el is 2200 sloc. > > My experience is that getting faces right is hard, so I'm not sure I'd as= sume > these thousands of lines are just due to bloat ^^ Regarding the the thousands of lines being "bloat", I do not think that this is the case, and I suspect that not (yet) handling overlays is has made my job much easier with engrave-faces.el. However, from my usage I have not found any clear failings with the current approach. To get a sample of how things look see the attachments to my original email. Should you be interested in seeing how a LaTeX export of some code looks, I can refer you to https://tecosaur.github.io/emacs-config/config.pd= f. This is mostly elisp but has a sprinkling of other languages too. Having looked at htmlize.el a bit I noticed that: - It was hard to get a clear picture of what's going on easily - The HTML generation and face-processing parts where deeply intertwined With this package I'm aiming to create: - A simpler, smaller (as much as possible), easier to understand core - Separate the concerns of processing face information and creating a representation in a certain format(s) - Have the face processing be generalised such that creating exporters in certain formats is a much easier task I expect the current state of affairs has room for improvement, but I feel it has also reached a state where it is plausibly useful :) Please let me know if this has answered your questions, and if you have any more. -- Timothy