From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms9.migadu.com with LMTPS id CP5fHNd/ZmTDyQAASxT56A (envelope-from ) for ; Thu, 18 May 2023 21:43:19 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id 0MEzHNd/ZmTZEwAAauVa8A (envelope-from ) for ; Thu, 18 May 2023 21:43:19 +0200 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 C83B92AEA0 for ; Thu, 18 May 2023 21:43:18 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pzjW0-0001gv-Gx; Thu, 18 May 2023 15:42:20 -0400 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 1pzjVy-0001gm-5I for emacs-orgmode@gnu.org; Thu, 18 May 2023 15:42:18 -0400 Received: from mout02.posteo.de ([185.67.36.66]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pzjVv-000142-DL for emacs-orgmode@gnu.org; Thu, 18 May 2023 15:42:17 -0400 Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id B1A8F240103 for ; Thu, 18 May 2023 21:42:12 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1684438932; bh=MdhFC9qoLmDeaEZih4Y3TMExgOTD9rBXRZtVPnmRXSc=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:From; b=IO9T1P9/7/1B3z82T8uIHweaS4kIo15709fqpOOfmz902WgaQIqmrShQYn7Ri1BHb ANnzcjExq/SBrSOKK8UfgOA4UmV5bQhlnc6aNiwinebraQu3+wo6A4sVsG5M6TVDzF TDve8HxxCe3cIFdE8X9y7OM1C7Ubnd2ZqhnOybXJVclEBvZWjlR3FJhRrO+O6iv8Up zMBkpQEvsrxHF1oCYsGKTrb3X74QnIqW1cypsZ0RTthguby/oE3EwRvYjjurpAL62T +icf+jDiDe5XSljiC8X6aaPX5pUhvr9jGDToML5mBpyK17bnhcOWSeVrdSAIjuim9M ET3gOgrSHTnbA== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4QMgNN1F8Nz6txD; Thu, 18 May 2023 21:42:12 +0200 (CEST) From: Ihor Radchenko To: Nathaniel Nicandro Cc: emacs-orgmode Subject: Re: [PATCH] Highlight ANSI sequences in the whole buffer (was [PATCH] ANSI color on example blocks and fixed width elements) In-Reply-To: <877ct5fzt6.fsf@gmail.com> References: <874jpuijpc.fsf@gmail.com> <87y1n6igvo.fsf@localhost> <878rev1q0k.fsf@gmail.com> <877cueonkj.fsf@localhost> <87zg6dez93.fsf@gmail.com> <871qjobhwa.fsf@localhost> <877ct5fzt6.fsf@gmail.com> Date: Thu, 18 May 2023 19:45:39 +0000 Message-ID: <87a5y1mnj0.fsf@localhost> MIME-Version: 1.0 Content-Type: text/plain Received-SPF: pass client-ip=185.67.36.66; envelope-from=yantar92@posteo.net; helo=mout02.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: emacs-orgmode-bounces+larch=yhetil.org@gnu.org X-Migadu-Country: US X-Migadu-Flow: FLOW_IN ARC-Seal: i=1; s=key1; d=yhetil.org; t=1684438999; a=rsa-sha256; cv=none; b=C2J7CYcdYThee3MjN+PAppTEtLwRFGHFijEgnnZl1BadVPPJ/xF6kUDS5I5HcYoiYIRh1Z /VrjPF1qEQKSwcCJhATR2adLBhoObumB34ZoVDF/TiTdSakqesuAjZiR0x6e+YWg/9Wuvt 7UeoQye6OFNamDeNiHH/Vxq7HC8qTYgNGYcoF0aD8h8ZZAgO3tl0KwuHeUKcv60uyb/7d+ zi/jPigpHtoGfwH08O63ra/jBKRPiP75Wk3EokmuzeR8Gi0BLaVbn7rvf0kmGISV6pBZhw 69xHRKu1c9K9KbXHvpUi27oMCkFDEHezQ3O9o6eK9qQ1XMCbYdjhbUoQqwB3Bw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b="IO9T1P9/"; dmarc=pass (policy=none) header.from=posteo.net; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1684438999; 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:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=isXXDIa+jUyAIFig1BmJ7ypAAIh5JLl6Hs7m7h8i+Tc=; b=JmyaQMA3vfRPljmUNQYsiOulB/bs0BoyTrUtWSI+QFb4XU0ocC6WICncSe9qWnzJ1MTK0S uKW+2HIkwk1zhfe4qfZn6STydsThwYUzzFFoZ+QEOlsSiqisDHdvr1nlkhpRPZOkFzKFLH 1I5MclbArF08+gc5GoqSwDqZ2nBRQiELy0DHZtWLmoJT6FVISaJPmofkcZFwjqLnf8auod +ZdsDFB4ekd89YI95SHfRL2DxQCQqu4UfXpD5sT5/wFGho+AtglNEQg9DADfzDHfN6AKm7 irerUrHYu1PAj2+BHtSk6ak6oQz/g4xLsxnG9YA6544JI+SwN1I6wwmTr4Uxzw== X-Migadu-Spam-Score: -6.39 X-Spam-Score: -6.39 X-Migadu-Queue-Id: C83B92AEA0 X-Migadu-Scanner: scn0.migadu.com Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b="IO9T1P9/"; dmarc=pass (policy=none) header.from=posteo.net; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-TUID: v1FOl5pOUaIG Nathaniel Nicandro writes: >> 1. Do not allow ANSI sequences to intersect markup boundaries of the >> same AST depth: >> *bold * plain text should not trigger fontification >> *bold /italic/ * should trigger >> plain text *bold* plain text also should > > Just to make sure I'm getting you right. You're saying that > fontification should trigger if the sequences live in the same > org-element-context? > What about cases like: > > *bold* plain text > plain text *bold * paragraph end > > In the first case, should only "bold" be fontified? Since the sequence > lives in the bold context. > In the second, should only "text"? Since the sequence lives at a higher > depth (the paragraph context, compared to the bold context). Or should > it be that the fontification should extend to the end of the paragraph > because the sequence lives at a higher depth? I completely missed the point that codes are not pairs, but switches; this is completely different from Org syntax. So, let me re-consider where codes are likely to be used in practice: 1. Inside shell code blocks (src-block element) 2. Inside results of evaluation, which are usually fixed-width element, but might also be example-block, export-block, drawer, table, or other element. 3. Inside shell inline code blocks (inline-src-block object) 4. Inside results of evaluation of an inline code block - usually code/verbatim markup. I think that the most reasonable approach to fontify ANSI sequences will be the following: 1. We will consider ANSI within (a) all greater elements and lesser elements that have RESULTS affiliated keyword (indicating that they are result of code block evaluation); (b) otherwise, just lesser elements, like paragraph, src block, example block, export block, etc., but _not_ tables (c) otherwise, within verbatim-like objects, like code, export-snippet, inline-src-block, table-cell, verbatim. The three groups above should be declared via variables, so that users can tweak them as necessary. 2. If ANSI sequence is encountered inside a verbatim-like object and we did not see any ANSI sequences within parent element or greater element, limit ANSI triggers to the current object. Example: #+RESULTS: Lorem upsum =valor=. Some more text. (only "valor" will be affected) 3. If the first ANSI sequence is encountered inside element and outside verbatim-like object, the rest of the element is affected, including all the objects. Example: #+RESULTS: Lorem upsum =valor=. Some more text. (the first ANSI affects everything, including verbatim; the second ANSI also affects everything) 4. If the first ANSI sequence is encountered inside greater element with RESULTS affiliated keyword, all the lesser elements inside will be affected. Example: #+RESULTS: :drawer: Lorem upsum =valor=. Some more text. Another paragraph inside drawer. :end: (everything down to :end: is affected) or #+RESULTS: - list - one - two - three (everything is affected down to the end of the list) Does it make sense? >>> + (cl-letf (((symbol-function #'delete-region) >>> + (lambda (beg end) >>> + (add-text-properties beg end '(invisible t)))) >> >> This is fragile and relies on internal implementation details of >> ansi-color.el. Is there another way? > > Since the context in which the sequences live in need to be considered, > it doesn't look like ansi-color-apply-on-region can be used any more > since it isn't aware of Org objects. > > I've come up with a function that calculates the highlightable regions > (considering contexts) and fontifies them, but it requires the use of > private functions from ansi-color. Specifically > ansi-color--face-vec-face, ansi-color--update-face-vec, and > ansi-color--code-as-hex (used internally by ansi-color--face-vec-face). > Does it make sense to copy over these functions into Org for the > purposes of handling ANSI escapes? There would be some backward > compatibility issues, e.g. ansi-color only started using faces as colors > in Emacs 28. If we really need to, we can propose an extension of ansi-color-apply-on-region upstream for Emacs itself. -- Ihor Radchenko // yantar92, Org mode contributor, Learn more about Org mode at . Support Org development at , or support my work at