all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [FR] Fontifying src-blocks with no language specified
@ 2023-02-16 10:49 carsten
  2023-02-17 12:20 ` [PATCH] " Ihor Radchenko
  0 siblings, 1 reply; 5+ messages in thread
From: carsten @ 2023-02-16 10:49 UTC (permalink / raw)
  To: emacs-orgmode

Fontifying src-blocks with a missing language would allow being able to 
theme src-blocks without having the unthemed text of languages fallback 
to whatever color the src-blocks are set to.
I envision this could be done with an empty string in 
org-src-block-faces.

See the below example where printf has the org-block face, in this case 
it would allow using a more normal color by default for org-blocks where 
the blocks without a language could use a more pronounced color.

#+BEGIN_SRC C
int main() {
     printf("Hello World\\n");
}
#+END_SRC

#+BEGIN_SRC
this is just a block of text
#+END_SRC



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH] [FR] Fontifying src-blocks with no language specified
  2023-02-16 10:49 [FR] Fontifying src-blocks with no language specified carsten
@ 2023-02-17 12:20 ` Ihor Radchenko
  2023-02-17 19:31   ` carsten
  0 siblings, 1 reply; 5+ messages in thread
From: Ihor Radchenko @ 2023-02-17 12:20 UTC (permalink / raw)
  To: carsten; +Cc: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 372 bytes --]

carsten@kragelund.me writes:

> Fontifying src-blocks with a missing language would allow being able to 
> theme src-blocks without having the unthemed text of languages fallback 
> to whatever color the src-blocks are set to.
> I envision this could be done with an empty string in 
> org-src-block-faces.

I do not see much problem adding this.
See the attached patch.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-fontify-meta-lines-and-blocks-1-Fontify-src-bloc.patch --]
[-- Type: text/x-patch, Size: 3256 bytes --]

From 9c9fa52b934390b9b07648fdf3a31c4baebac551 Mon Sep 17 00:00:00 2001
Message-Id: <9c9fa52b934390b9b07648fdf3a31c4baebac551.1676636352.git.yantar92@posteo.net>
From: Ihor Radchenko <yantar92@posteo.net>
Date: Fri, 17 Feb 2023 15:17:04 +0300
Subject: [PATCH] org-fontify-meta-lines-and-blocks-1: Fontify src blocks
 without lang

* lisp/org.el (org-fontify-meta-lines-and-blocks-1): Allow fontifying
src blocks with language specification missing.
* lisp/org-src.el (org-src-block-faces): Clarify in the docstring that
"" language name referes to src blocks with no language.  Remove
redundant :version tag.
* etc/ORG-NEWS (~org-src-block-faces~ now accepts empty string ~""~ as
language name): Announce the change.

Link: https://orgmode.org/list/99388ff3711696091f0312a5c3f0bcbd@kragelund.me
---
 etc/ORG-NEWS    | 15 +++++++++++++++
 lisp/org-src.el |  4 ++--
 lisp/org.el     |  2 +-
 3 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 87ecd77cd..5ab8d62c7 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -24,6 +24,21 @@ consider [[https://gitlab.com/jackkamm/ob-python-mode-mode][ob-python-mode-mode]
 has been ported to.
 
 ** New and changed options
+*** ~org-src-block-faces~ now accepts empty string ~""~ as language name
+
+It is now possible to customize face of source blocks without language specifier.
+
+: #+begin_src
+: Source block with no language
+: #+end_src
+
+For example, to set ~highlight~ face, use
+
+#+begin_src emacs-lisp
+(setq org-src-fontify-natively t)
+(add-to-list 'org-src-block-faces '(("" highlight))
+#+end_src
+
 *** New escape in ~org-beamer-environments-extra~ for labels in Beamer export
 The escape =%l= in ~org-beamer-environments-extra~ inserts the label
 obtained from ~org-beamer--get-label~.  This is added to the default
diff --git a/lisp/org-src.el b/lisp/org-src.el
index 9e4392811..2fab4020d 100644
--- a/lisp/org-src.el
+++ b/lisp/org-src.el
@@ -233,7 +233,8 @@ (defcustom org-src-block-faces nil
 
      (\"language\" FACE)
 
-Where FACE is either a defined face or an anonymous face.
+Where FACE is either a defined face or an anonymous face.  Empty
+language string refers to source blocks without specified language.
 
 For instance, the following would color the background of
 emacs-lisp source blocks and python source blocks in purple and
@@ -247,7 +248,6 @@ (defcustom org-src-block-faces nil
                        (choice
                         (face :tag "Face")
                         (sexp :tag "Anonymous face"))))
-  :version "26.1"
   :package-version '(Org . "9.0"))
 
 (defcustom org-src-tab-acts-natively t
diff --git a/lisp/org.el b/lisp/org.el
index 4d12084d9..777626dce 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -5409,7 +5409,7 @@ (defun org-fontify-meta-lines-and-blocks-1 (limit)
 	    (org-remove-flyspell-overlays-in beg bol-after-beginline)
 	    (org-remove-flyspell-overlays-in nl-before-endline end-of-endline)
 	    (cond
-	     ((and lang (not (string= lang "")) org-src-fontify-natively)
+	     (org-src-fontify-natively
 	      (save-match-data
                 (org-src-font-lock-fontify-block lang block-start block-end))
 	      (add-text-properties bol-after-beginline block-end '(src-block t)))
-- 
2.39.1


[-- Attachment #3: Type: text/plain, Size: 225 bytes --]



-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] [FR] Fontifying src-blocks with no language specified
  2023-02-17 12:20 ` [PATCH] " Ihor Radchenko
@ 2023-02-17 19:31   ` carsten
  2023-02-18 10:48     ` Ihor Radchenko
  0 siblings, 1 reply; 5+ messages in thread
From: carsten @ 2023-02-17 19:31 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: emacs-orgmode

Ihor Radchenko skrev den 2023-02-17 13:20:
> carsten@kragelund.me writes:
> 
>> Fontifying src-blocks with a missing language would allow being able 
>> to
>> theme src-blocks without having the unthemed text of languages 
>> fallback
>> to whatever color the src-blocks are set to.
>> I envision this could be done with an empty string in
>> org-src-block-faces.
> 
> I do not see much problem adding this.
> See the attached patch.

Hey, this patch works great, minor issue, I believe
the line (add-to-list 'org-src-block-faces '(("" highlight))
in ORG-NEWS has an extra opening parenthesis and should
be (add-to-list 'org-src-block-faces '("" highlight))


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] [FR] Fontifying src-blocks with no language specified
  2023-02-17 19:31   ` carsten
@ 2023-02-18 10:48     ` Ihor Radchenko
  2023-04-02 14:33       ` Ihor Radchenko
  0 siblings, 1 reply; 5+ messages in thread
From: Ihor Radchenko @ 2023-02-18 10:48 UTC (permalink / raw)
  To: carsten; +Cc: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 385 bytes --]

carsten@kragelund.me writes:

>> I do not see much problem adding this.
>> See the attached patch.
>
> Hey, this patch works great, minor issue, I believe
> the line (add-to-list 'org-src-block-faces '(("" highlight))
> in ORG-NEWS has an extra opening parenthesis and should
> be (add-to-list 'org-src-block-faces '("" highlight))

Indeed.
Attaching an updated version of the patch.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: v2-0001-org-fontify-meta-lines-and-blocks-1-Fontify-src-b.patch --]
[-- Type: text/x-patch, Size: 3392 bytes --]

From 392a075bb2a75fe16e275745c80d83e7c13fc91d Mon Sep 17 00:00:00 2001
Message-Id: <392a075bb2a75fe16e275745c80d83e7c13fc91d.1676717280.git.yantar92@posteo.net>
From: Ihor Radchenko <yantar92@posteo.net>
Date: Fri, 17 Feb 2023 15:17:04 +0300
Subject: [PATCH v2] org-fontify-meta-lines-and-blocks-1: Fontify src blocks
 without lang

* lisp/org.el (org-fontify-meta-lines-and-blocks-1): Allow fontifying
src blocks with language specification missing.
* lisp/org-src.el (org-src-block-faces): Clarify in the docstring that
"" language name referes to src blocks with no language.  Remove
redundant :version tag.
* etc/ORG-NEWS (~org-src-block-faces~ now accepts empty string ~""~ as
language name): Announce the change.

Link: https://orgmode.org/list/99388ff3711696091f0312a5c3f0bcbd@kragelund.me
---
 etc/ORG-NEWS    | 15 +++++++++++++++
 lisp/org-src.el |  4 ++--
 lisp/org.el     |  4 ++--
 3 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 87ecd77cd..90663ab5a 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -24,6 +24,21 @@ consider [[https://gitlab.com/jackkamm/ob-python-mode-mode][ob-python-mode-mode]
 has been ported to.
 
 ** New and changed options
+*** ~org-src-block-faces~ now accepts empty string ~""~ as language name
+
+It is now possible to customize face of source blocks without language specifier.
+
+: #+begin_src
+: Source block with no language
+: #+end_src
+
+For example, to set ~highlight~ face, use
+
+#+begin_src emacs-lisp
+(setq org-src-fontify-natively t)
+(add-to-list 'org-src-block-faces '("" highlight))
+#+end_src
+
 *** New escape in ~org-beamer-environments-extra~ for labels in Beamer export
 The escape =%l= in ~org-beamer-environments-extra~ inserts the label
 obtained from ~org-beamer--get-label~.  This is added to the default
diff --git a/lisp/org-src.el b/lisp/org-src.el
index 9e4392811..2fab4020d 100644
--- a/lisp/org-src.el
+++ b/lisp/org-src.el
@@ -233,7 +233,8 @@ (defcustom org-src-block-faces nil
 
      (\"language\" FACE)
 
-Where FACE is either a defined face or an anonymous face.
+Where FACE is either a defined face or an anonymous face.  Empty
+language string refers to source blocks without specified language.
 
 For instance, the following would color the background of
 emacs-lisp source blocks and python source blocks in purple and
@@ -247,7 +248,6 @@ (defcustom org-src-block-faces nil
                        (choice
                         (face :tag "Face")
                         (sexp :tag "Anonymous face"))))
-  :version "26.1"
   :package-version '(Org . "9.0"))
 
 (defcustom org-src-tab-acts-natively t
diff --git a/lisp/org.el b/lisp/org.el
index cc2c09e3a..d148a14bb 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -5409,9 +5409,9 @@ (defun org-fontify-meta-lines-and-blocks-1 (limit)
 	    (org-remove-flyspell-overlays-in beg bol-after-beginline)
 	    (org-remove-flyspell-overlays-in nl-before-endline end-of-endline)
 	    (cond
-	     ((and lang (not (string= lang "")) org-src-fontify-natively)
+	     (org-src-fontify-natively
 	      (save-match-data
-                (org-src-font-lock-fontify-block lang block-start block-end))
+                (org-src-font-lock-fontify-block (or lang "") block-start block-end))
 	      (add-text-properties bol-after-beginline block-end '(src-block t)))
 	     (quoting
 	      (add-text-properties
-- 
2.39.1


[-- Attachment #3: Type: text/plain, Size: 224 bytes --]


-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] [FR] Fontifying src-blocks with no language specified
  2023-02-18 10:48     ` Ihor Radchenko
@ 2023-04-02 14:33       ` Ihor Radchenko
  0 siblings, 0 replies; 5+ messages in thread
From: Ihor Radchenko @ 2023-04-02 14:33 UTC (permalink / raw)
  To: carsten; +Cc: emacs-orgmode

Ihor Radchenko <yantar92@posteo.net> writes:

> Attaching an updated version of the patch.
>

Applied, onto main.
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=c2ffc6b60
Done.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-04-02 14:31 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-02-16 10:49 [FR] Fontifying src-blocks with no language specified carsten
2023-02-17 12:20 ` [PATCH] " Ihor Radchenko
2023-02-17 19:31   ` carsten
2023-02-18 10:48     ` Ihor Radchenko
2023-04-02 14:33       ` Ihor Radchenko

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.