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 ms9.migadu.com with LMTPS id GKxTEPVsLWT10AAASxT56A (envelope-from ) for ; Wed, 05 Apr 2023 14:43:33 +0200 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 GAZFEPVsLWTFPAAA9RJhRA (envelope-from ) for ; Wed, 05 Apr 2023 14:43:33 +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 C10DD264A for ; Wed, 5 Apr 2023 14:43:32 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pk2TT-0003OZ-SA; Wed, 05 Apr 2023 08:42:51 -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 1pk2TO-0003NE-Op for emacs-orgmode@gnu.org; Wed, 05 Apr 2023 08:42:46 -0400 Received: from mail-qv1-xf2f.google.com ([2607:f8b0:4864:20::f2f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pk2TL-0005Pi-LK for emacs-orgmode@gnu.org; Wed, 05 Apr 2023 08:42:46 -0400 Received: by mail-qv1-xf2f.google.com with SMTP id 6a1803df08f44-5a5d452f558so846276d6.0 for ; Wed, 05 Apr 2023 05:42:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1680698562; h=mime-version:message-id:date:subject:to:from:user-agent:from:to:cc :subject:date:message-id:reply-to; bh=Q6sQmzfVCndy63KQjVCimgFBQ9QU9nmWz8XIpG5Ajf8=; b=p8MOYhoqzTeLuKUZcCPTeWFZ7a52XiKXen6Zec7t3cS2Oc7ruV4HGBa0xNr+xBJNWa RdwDBQ9y6e+kyOF268wVKEYY92MOWv7bOx9ssVdGaTgrc3JOhCzRyIAtk2y6TcjmyZNi l5CqFRBWquRpL351d4MgJB0J09Lcgz7ih66Dfxsg8xRMd64K1jbjvQFFpvz2qpVbOctI TfDbbCtdJYBOjSRoa/V5RALM+YipmZ3zKE6ci9XpCwFr5NvFa2HquiTP6Kd9DlpXLGB5 CeJnh0XXKzr/oXwgFrD+N3865qeXI0n+xhcBBfuOLDjjOG8br+RCq58WaHII6F/abE9+ b2NQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680698562; h=mime-version:message-id:date:subject:to:from:user-agent :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Q6sQmzfVCndy63KQjVCimgFBQ9QU9nmWz8XIpG5Ajf8=; b=2pzdJRUFTAhpXrWADV+nx4SzPf1nTGrRAn8zgdtA3J2KmxPqn1GMTmc4GxZ88tG43v VYt47Kadq/gTW5Kijx6xbeSXyFGrCXOSl7RrLvZ+1mkhkmUvUg+bJz2QhIjjEI3Qa0b9 4xW3+RcQwcfn8fGPCMztuGP0TniLjvEVNYGEaPTs3CqPVT6zTVh3Klci3LgLIddrZKJs Jeeqyk1a/jAbNQ+PYlg2bySbaN7zzlTr1ue7Ef6n6T4wz8oo6KtYDy+DA8DoquvW+jJF 2X05r2dF0u+oQ4ZTHSA6Ri83abaqXJi2sNpYv603/PrGbyXbsgMuTQKOvG+zhP4XcBLZ c47A== X-Gm-Message-State: AAQBX9dcJstgXR5Jwg31PF7qIZ1wD04z7CpE8HmrW6QytFi3GDxPd7ho QiEbzKGB+MZto0cM4KUyuVOC3gC/3IQ= X-Google-Smtp-Source: AKy350biKg+bSiabpTGLy6KdWpYObStLQB8GaCDkzwRNusKfoU1SkcXzO4WPx1C95DNDDKBELKEU1w== X-Received: by 2002:a05:6214:301b:b0:532:141d:3750 with SMTP id ke27-20020a056214301b00b00532141d3750mr3107363qvb.2.1680698561547; Wed, 05 Apr 2023 05:42:41 -0700 (PDT) Received: from entropy ([2601:241:8c80:25a0::71d8]) by smtp.gmail.com with ESMTPSA id m1-20020a0cee41000000b005dd8b9345c7sm4173273qvs.95.2023.04.05.05.42.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 05:42:41 -0700 (PDT) User-agent: mu4e 1.8.13; emacs 30.0.50 From: Nathaniel Nicandro To: emacs-orgmode Subject: [PATCH] ANSI color on example blocks and fixed width elements Date: Wed, 05 Apr 2023 07:03:43 -0500 Message-ID: <874jpuijpc.fsf@gmail.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=2607:f8b0:4864:20::f2f; envelope-from=nathanielnicandro@gmail.com; helo=mail-qv1-xf2f.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-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=1680698613; a=rsa-sha256; cv=none; b=c+CTQeAlilN2A58qCRYIe/T+xUlWdObMCwzAf7xklz++MztX3/ikHEEGvKwTOd2lpFhMy7 1+mRRE4tiHoksmu4ylPlhEGiaj8e+a9dWoOTNL/TtURWqEPhDF+V0+BRlJbVACQItUOhXM v8Sit2/PwWD3SqrVMgSdKJIkRIGdMMQOjdJf4MEyPKs5xmvglkAB9mjxC/j9yTmCKVm2Qe Jg1b4aZ2aU6NZG3lzS4lBZVCOR2o0sKSC7ZEFmi9fMxFc7DIFxTPMA2FBntLav4C9/ymCh UVEIyQYwIMCwgqjrK23MKQDebcDUKEuh+PdvnS94t+GwfmtFQlPaBof0LaDO4Q== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=p8MOYhoq; dmarc=pass (policy=none) header.from=gmail.com; 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=1680698613; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=Q6sQmzfVCndy63KQjVCimgFBQ9QU9nmWz8XIpG5Ajf8=; b=Nj0fot5jyHwLa2eSF0t3xtU8mfc4Yj0E9s9Xmbg7G9zgcAVO5AUYL1/Wqzp7pzNvXqynS9 7wwR9z08WUvIrazkMPit3G5E5RzhyYy5LB1ezlrZdxGBU0uE8oGdvLhXi1vFLtlbcTvsqK pbScC94R1NlHOSrzIc58hAj0g3ycVJS6Fy7kg6GUdfOzJ/mB85+SQv5AcnkQUyUlMPk0c5 2QQRP4zcmGIDw9IrFPgBwaleV4l1W7LdGt+ZzCC+Q0N0csOGUOvPt+dpDG3Ljh2J4vyg2Z nF2Kuo2iz7Zi981FhOpAz3lM6rhb91lF2ejycOb8bz7FjdSt6ksrVgmoa4wRyA== Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=p8MOYhoq; dmarc=pass (policy=none) header.from=gmail.com; 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-Migadu-Scanner: scn0.migadu.com X-Migadu-Spam-Score: -7.75 X-Spam-Score: -7.75 X-Migadu-Queue-Id: C10DD264A X-TUID: U7KfKNMZjUB6 --=-=-= Content-Type: text/plain Hello, Attached is the patch. Without this patch, ANSI escape sequences generated by the output of a source block will be left in the buffer without any fontification. With this patch, the escaped text is nicely colored and escape sequences hidden using overlays. It works for Emacs versions which have the `PRESERVE-SEQUENCES` argument to the `ansi-color-apply-on-region` function. It's a bit slow due to the use of overlays. My implementation of this feature in Emacs-Jupyter supports older versions of Emacs without that argument, it relies on a custom version of that function though and uses text properties instead of overlays. Let me know what else could be done on my end to get this patch in. Thanks. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=ansi-color-example-blocks-and-fixed-width.patch Content-Description: ANSI color patch diff --git a/lisp/org.el b/lisp/org.el index 4d12084..24617ad 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -81,6 +81,7 @@ (eval-when-compile (require 'gnus-sum)) (require 'calendar) (require 'find-func) (require 'format-spec) +(require 'ansi-color) (condition-case nil (load (concat (file-name-directory load-file-name) @@ -5326,6 +5327,10 @@ (defsubst org-activate-links (limit) (defun org-activate-code (limit) (when (re-search-forward "^[ \t]*\\(:\\(?: .*\\|$\\)\n?\\)" limit t) (org-remove-flyspell-overlays-in (match-beginning 0) (match-end 0)) + (let ((ansi-color-apply-face-function + (lambda (beg end face) + (font-lock-prepend-text-property beg end 'face face)))) + (ansi-color-apply-on-region (match-beginning 0) (match-end 0) t)) (remove-text-properties (match-beginning 0) (match-end 0) '(display t invisible t intangible t)) t)) @@ -5421,7 +5426,12 @@ (defun org-fontify-meta-lines-and-blocks-1 (limit) (let ((face-name (intern (format "org-block-%s" lang)))) (append (and (facep face-name) (list face-name)) - '(org-block))))))) + '(org-block)))))) + (let ((ansi-color-apply-face-function + (lambda (beg end face) + (font-lock-prepend-text-property beg end 'face face)))) + (ansi-color-apply-on-region + bol-after-beginline beg-of-endline t))) ((not org-fontify-quote-and-verse-blocks)) ((string= block-type "quote") (add-face-text-property --=-=-= Content-Type: text/plain -- Nathaniel --=-=-=--