From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id v/d2OGZiqWPCfwEAbAwnHQ (envelope-from ) for ; Mon, 26 Dec 2022 09:59:18 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id CODCNmZiqWNiZgAAauVa8A (envelope-from ) for ; Mon, 26 Dec 2022 09:59:18 +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 468A610B3F for ; Mon, 26 Dec 2022 09:59:18 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p9jJb-00089i-CY; Mon, 26 Dec 2022 03:58:35 -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 1p9jJY-00087t-3c for emacs-orgmode@gnu.org; Mon, 26 Dec 2022 03:58:32 -0500 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 1p9jJV-0004oF-30 for emacs-orgmode@gnu.org; Mon, 26 Dec 2022 03:58:31 -0500 Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id F37C124016E for ; Mon, 26 Dec 2022 09:58:26 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1672045107; bh=qTmxQJ2tFB/HN7gjWuSwcxH9j9Jhaa4OO9lO/pee6L0=; h=From:To:Cc:Subject:Date:From; b=mScI2oDFPcfMH5Zx3cMQd3CdyEjVY77stxobMtAN0N0KIfL7HctxNDogIXjX7QNK6 hBHzHeSaQpKumgCMPDoCyyLzEZqTAi6G1dYpdP73qRsGV5DT1myXIJJf4+oG0zPrGq yMFGK3FROpOaxQjeIQ8jpmwPmf0rR4HhMYimYcRbptiAL5w3f7Wg+Ts7O2Y4Xrr8nd ykYFFKR6Q6I6fmT7BIH1hC+gQcmbmZdAvy4CHv7lNqf50tFPpu3WnY5lk6Bwt+mlcS iF4qjDXqlRifavtsRHy75MleYiVT7nfedwWa5oNyJyU00ht0nn5YJlmif0PYqeOEfW 3V9aEcgnGabGw== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4NgWsZ0w5Fz6tmS; Mon, 26 Dec 2022 09:58:25 +0100 (CET) From: Ihor Radchenko To: duskhorn Cc: "emacs-orgmode@gnu.org" Subject: Re: [BUG] org-block face not working for "non-default" languages In-Reply-To: References: Date: Mon, 26 Dec 2022 08:58:20 +0000 Message-ID: <87o7rqr177.fsf@localhost> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" 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 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-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1672045158; 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=gg4KYYSKnl+gF+Pz6ZvgRToeymoXUuag1wBWkciCFzw=; b=EjijuUfFTd4zxE2SXb5GuBzvrMIMfJYZcB245LbZqqXlKl98D8cGL+Rx5TlwP7X/fXQ1mZ UxmdGtEUEE/rWQyijginwc9+BIuH+zimrM+vDvKrC+Sa6TJBDhYG/nYgTSrpaEw6P+wGfG DMejuWEz4e/wpsSr4fRKTCnwumrDB5FY8YVGAhDI1yiApKMR8kFKxI1tFxEFTrRtjuRuZB eAKwIih54IlaOp5jmOSEhj4iep3KZczEMRfDXWpZj56RhB2EknO5BaR0IHVtWvwj+hXR93 hcn36vgc7YZ2sRK4783Am+noeBp1bt7zRnkzP5oZH0hDyha6X+vCxPUPg9Q4eg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=mScI2oDF; 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"; dmarc=pass (policy=none) header.from=posteo.net ARC-Seal: i=1; s=key1; d=yhetil.org; t=1672045158; a=rsa-sha256; cv=none; b=n1c5gKAjgHqGK2UbITnp5XeBaNqbsHiUcPL3csaxqckY3U05Ce3If0cBCxK4SDAvnijPje z82QMpwZFrN9mJeI9xGqWTF7MxwzRh33L/aE9dIV/zXtavEjkcCyC27gmKWxt3wjcDvqz9 PhkKqyE5TeE1AUgY5Aex+i839ihONBtY/XRyRM5KeiXsjP3Zsr0qpYBMCV56jlNJoRTr9B OMuZ0x+Tbfo1QoeTTOlzfOgKP2w1Q2TSyEw3xFRAwTVim3Hs6IJoXheCfoMH1kVqpbIytd TW8b+LJnyTkw0unI7M0sDSZfU9ug0+3G6lWSV8tzh8hazXbtDyCI1sCVXCtv9w== X-Spam-Score: -5.97 X-Migadu-Queue-Id: 468A610B3F Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=mScI2oDF; 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"; dmarc=pass (policy=none) header.from=posteo.net X-Migadu-Scanner: scn1.migadu.com X-Migadu-Spam-Score: -5.97 X-TUID: uwOeIGxdU6Ve --=-=-= Content-Type: text/plain duskhorn writes: > I have set up my org-mode so that I use variable pitch fonts for most of the items and fixed pitch fonts for verbatim and src blocks. > > This works as expected for languages babel knows by default, for example emacs-lisp, python and c++. > > However, I get variable pitch fonts for when I use an unrecognized language, such as nim (in my case) or R. Can you try the attached patch? --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-org-src.el-Apply-common-faces-even-when-src-block-la.patch >From 16a73725e2f9291f614f5dd6c34b05ac68eebc74 Mon Sep 17 00:00:00 2001 Message-Id: <16a73725e2f9291f614f5dd6c34b05ac68eebc74.1672045049.git.yantar92@posteo.net> From: Ihor Radchenko Date: Mon, 26 Dec 2022 11:55:26 +0300 Subject: [PATCH] org-src.el: Apply common faces even when src block language mode is absent * lisp/org-src.el (org-src-font-lock-fontify-block): Apply `org-src-block-faces'/`org-block' faces even when no major mode is available for the src block language. Reported-by: duskhorn Link: https://orgmode.org/list/zCjC9UjXEgJk8kuyi8t2K2XzO3fL7pYWynHhoYWAes9eCA1FkomCY9bss4uKZfBg60M4xUisyDqFWKVMOn1r_XzUVE7gr3ci82MEOLjGIMk=@proton.me --- lisp/org-src.el | 154 ++++++++++++++++++++++++------------------------ 1 file changed, 77 insertions(+), 77 deletions(-) diff --git a/lisp/org-src.el b/lisp/org-src.el index 7d5f5d543..85262b32a 100644 --- a/lisp/org-src.el +++ b/lisp/org-src.el @@ -629,83 +629,83 @@ (defun org-src-font-lock-fontify-block (lang start end) "Fontify code block between START and END using LANG's syntax. This function is called by Emacs' automatic fontification, as long as `org-src-fontify-natively' is non-nil." - (let ((lang-mode (org-src-get-lang-mode lang))) - (when (fboundp lang-mode) - (let ((string (buffer-substring-no-properties start end)) - (modified (buffer-modified-p)) - (org-buffer (current-buffer))) - (remove-text-properties start end '(face nil)) - (with-current-buffer - (get-buffer-create - (format " *org-src-fontification:%s*" lang-mode)) - (let ((inhibit-modification-hooks nil)) - (erase-buffer) - ;; Add string and a final space to ensure property change. - (insert string " ")) - (unless (eq major-mode lang-mode) (funcall lang-mode)) - (font-lock-ensure) - (let ((pos (point-min)) next) - (while (setq next (next-property-change pos)) - ;; Handle additional properties from font-lock, so as to - ;; preserve, e.g., composition. - ;; FIXME: We copy 'font-lock-face property explicitly because - ;; `font-lock-mode' is not enabled in the buffers starting from - ;; space and the remapping between 'font-lock-face and 'face - ;; text properties may thus not be set. See commit - ;; 453d634bc. - (dolist (prop (append '(font-lock-face face) font-lock-extra-managed-props)) - (let ((new-prop (get-text-property pos prop))) - (when new-prop - (if (not (eq prop 'invisible)) - (put-text-property - (+ start (1- pos)) (1- (+ start next)) prop new-prop - org-buffer) - ;; Special case. `invisible' text property may - ;; clash with Org folding. Do not assign - ;; `invisible' text property directly. Use - ;; property alias instead. - (let ((invisibility-spec - (or - ;; ATOM spec. - (and (memq new-prop buffer-invisibility-spec) - new-prop) - ;; (ATOM . ELLIPSIS) spec. - (assq new-prop buffer-invisibility-spec)))) - (with-current-buffer org-buffer - ;; Add new property alias. - (unless (memq 'org-src-invisible - (cdr (assq 'invisible char-property-alias-alist))) - (setq-local - char-property-alias-alist - (cons (cons 'invisible - (nconc (cdr (assq 'invisible char-property-alias-alist)) - '(org-src-invisible))) - (remove (assq 'invisible char-property-alias-alist) - char-property-alias-alist)))) - ;; Carry over the invisibility spec, unless - ;; already present. Note that there might - ;; be conflicting invisibility specs from - ;; different major modes. We cannot do much - ;; about this then. - (when invisibility-spec - (add-to-invisibility-spec invisibility-spec)) - (put-text-property - (+ start (1- pos)) (1- (+ start next)) - 'org-src-invisible new-prop - org-buffer))))))) - (setq pos next))) - (set-buffer-modified-p nil)) - ;; Add Org faces. - (let ((src-face (nth 1 (assoc-string lang org-src-block-faces t)))) - (when (or (facep src-face) (listp src-face)) - (font-lock-append-text-property start end 'face src-face)) - (font-lock-append-text-property start end 'face 'org-block)) - ;; Clear abbreviated link folding. - (org-fold-region start end nil 'org-link) - (add-text-properties - start end - '(font-lock-fontified t fontified t font-lock-multiline t)) - (set-buffer-modified-p modified))))) + (let ((modified (buffer-modified-p))) + (remove-text-properties start end '(face nil)) + (let ((lang-mode (org-src-get-lang-mode lang))) + (when (fboundp lang-mode) + (let ((string (buffer-substring-no-properties start end)) + (org-buffer (current-buffer))) + (with-current-buffer + (get-buffer-create + (format " *org-src-fontification:%s*" lang-mode)) + (let ((inhibit-modification-hooks nil)) + (erase-buffer) + ;; Add string and a final space to ensure property change. + (insert string " ")) + (unless (eq major-mode lang-mode) (funcall lang-mode)) + (font-lock-ensure) + (let ((pos (point-min)) next) + (while (setq next (next-property-change pos)) + ;; Handle additional properties from font-lock, so as to + ;; preserve, e.g., composition. + ;; FIXME: We copy 'font-lock-face property explicitly because + ;; `font-lock-mode' is not enabled in the buffers starting from + ;; space and the remapping between 'font-lock-face and 'face + ;; text properties may thus not be set. See commit + ;; 453d634bc. + (dolist (prop (append '(font-lock-face face) font-lock-extra-managed-props)) + (let ((new-prop (get-text-property pos prop))) + (when new-prop + (if (not (eq prop 'invisible)) + (put-text-property + (+ start (1- pos)) (1- (+ start next)) prop new-prop + org-buffer) + ;; Special case. `invisible' text property may + ;; clash with Org folding. Do not assign + ;; `invisible' text property directly. Use + ;; property alias instead. + (let ((invisibility-spec + (or + ;; ATOM spec. + (and (memq new-prop buffer-invisibility-spec) + new-prop) + ;; (ATOM . ELLIPSIS) spec. + (assq new-prop buffer-invisibility-spec)))) + (with-current-buffer org-buffer + ;; Add new property alias. + (unless (memq 'org-src-invisible + (cdr (assq 'invisible char-property-alias-alist))) + (setq-local + char-property-alias-alist + (cons (cons 'invisible + (nconc (cdr (assq 'invisible char-property-alias-alist)) + '(org-src-invisible))) + (remove (assq 'invisible char-property-alias-alist) + char-property-alias-alist)))) + ;; Carry over the invisibility spec, unless + ;; already present. Note that there might + ;; be conflicting invisibility specs from + ;; different major modes. We cannot do much + ;; about this then. + (when invisibility-spec + (add-to-invisibility-spec invisibility-spec)) + (put-text-property + (+ start (1- pos)) (1- (+ start next)) + 'org-src-invisible new-prop + org-buffer))))))) + (setq pos next))) + (set-buffer-modified-p nil))))) + ;; Add Org faces. + (let ((src-face (nth 1 (assoc-string lang org-src-block-faces t)))) + (when (or (facep src-face) (listp src-face)) + (font-lock-append-text-property start end 'face src-face)) + (font-lock-append-text-property start end 'face 'org-block)) + ;; Clear abbreviated link folding. + (org-fold-region start end nil 'org-link) + (add-text-properties + start end + '(font-lock-fontified t fontified t font-lock-multiline t)) + (set-buffer-modified-p modified))) (defun org-fontify-inline-src-blocks (limit) "Try to apply `org-fontify-inline-src-blocks-1'." -- 2.38.1 --=-=-= Content-Type: text/plain -- Ihor Radchenko // yantar92, Org mode contributor, Learn more about Org mode at . Support Org development at , or support my work at --=-=-=--