emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] Define new face for the contents of #+RESULTS drawers
@ 2023-09-16  9:38 Protesilaos Stavrou
  2023-09-16  9:49 ` Ihor Radchenko
  0 siblings, 1 reply; 8+ messages in thread
From: Protesilaos Stavrou @ 2023-09-16  9:38 UTC (permalink / raw)
  To: emacs-orgmode

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

Hello folks!

I propose the attached patch.  It gives users/themes the opportunity to
style the contents of #+RESULTS drawers differently than the face
applied to ~code~ elements.

To preserve the current style, I made the new face inherit 'org-code'.

What do you think?

All the best,
Protesilaos (or simply "Prot")

-- 
Protesilaos Stavrou
https://protesilaos.com

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Define-new-face-for-the-contents-of-RESULTS-drawers.patch --]
[-- Type: text/x-patch, Size: 1536 bytes --]

From 1ecd64bfe88d06684a9ad97c1ee6df0bdd2c1eb2 Mon Sep 17 00:00:00 2001
Message-ID: <1ecd64bfe88d06684a9ad97c1ee6df0bdd2c1eb2.1694856985.git.info@protesilaos.com>
From: Protesilaos Stavrou <info@protesilaos.com>
Date: Sat, 16 Sep 2023 12:36:18 +0300
Subject: [PATCH] Define new face for the contents of #+RESULTS drawers

* lisp/org-faces.el (org-code-results): Define new face.
* lisp/org.el (org-set-font-lock-defaults): Use it instead of the
generic 'org-code' face.
---
 lisp/org-faces.el | 5 +++++
 lisp/org.el       | 2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/lisp/org-faces.el b/lisp/org-faces.el
index 436552cb2..3d233eaff 100644
--- a/lisp/org-faces.el
+++ b/lisp/org-faces.el
@@ -409,6 +409,11 @@ (defface org-code '((t :inherit shadow))
   :group 'org-faces
   :version "22.1")
 
+(defface org-code-results '((t :inherit org-code))
+  "Face for the contents of #+RESULTS drawers."
+  :group 'org-faces
+  :version "30.1")
+
 (defface org-meta-line '((t :inherit font-lock-comment-face))
   "Face for meta lines starting with \"#+\"."
   :group 'org-faces
diff --git a/lisp/org.el b/lisp/org.el
index 84ac87438..6fb099618 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -5905,7 +5905,7 @@ (defun org-set-font-lock-defaults ()
 	  '(org-fontify-entities)
 	  '(org-raise-scripts)
 	  ;; Code
-	  '(org-activate-code (1 'org-code t))
+	  '(org-activate-code (1 'org-code-results t))
 	  ;; COMMENT
 	  (list (format
 		 "^\\*+\\(?: +%s\\)?\\(?: +\\[#[A-Z0-9]\\]\\)? +\\(?9:%s\\)\\(?: \\|$\\)"
-- 
2.42.0


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

* Re: [PATCH] Define new face for the contents of #+RESULTS drawers
  2023-09-16  9:38 [PATCH] Define new face for the contents of #+RESULTS drawers Protesilaos Stavrou
@ 2023-09-16  9:49 ` Ihor Radchenko
  2023-09-16 12:30   ` Protesilaos Stavrou
  0 siblings, 1 reply; 8+ messages in thread
From: Ihor Radchenko @ 2023-09-16  9:49 UTC (permalink / raw)
  To: Protesilaos Stavrou; +Cc: emacs-orgmode

Protesilaos Stavrou <info@protesilaos.com> writes:

> I propose the attached patch.  It gives users/themes the opportunity to
> style the contents of #+RESULTS drawers differently than the face
> applied to ~code~ elements.

Thanks for the patch!

> +(defface org-code-results '((t :inherit org-code))
> +  "Face for the contents of #+RESULTS drawers."
> +  :group 'org-faces
> +  :version "30.1")

I think there is some misunderstanding here.
#+RESULTS is not a drawer. A drawer would be

:results:
...
:end:

As for code evaluation results, it can be anything with #+results
keyword. Like

#+results:
: fixed width
: text

or

#+results:
#+begin_example
...
#+end_example

or

#+results:
Simple paragraph of text.

>  	  ;; Code
> -	  '(org-activate-code (1 'org-code t))
> +	  '(org-activate-code (1 'org-code-results t))

`org-activate-code' only affects fixed-width text

: like
: this
:
: one

It has no relation to code results, except that fixed width is often
(but not always) used as the default markup for results of evaluation.

If what you are looking for is different formatting for code markup and
fixed-width markup, `org-fixed-width' would be a better face name.

If you are looking for formatting of results of evaluation, it would
need to be a completely new, non-trivial, font-lock-keyword.

-- 
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] 8+ messages in thread

* Re: [PATCH] Define new face for the contents of #+RESULTS drawers
  2023-09-16  9:49 ` Ihor Radchenko
@ 2023-09-16 12:30   ` Protesilaos Stavrou
  2023-09-16 12:44     ` Ihor Radchenko
  0 siblings, 1 reply; 8+ messages in thread
From: Protesilaos Stavrou @ 2023-09-16 12:30 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: emacs-orgmode

> From: Ihor Radchenko <yantar92@posteo.net>
> Date: Sat, 16 Sep 2023 09:49:50 +0000

> [... 9 lines elided]

>> +(defface org-code-results '((t :inherit org-code))
>> +  "Face for the contents of #+RESULTS drawers."
>> +  :group 'org-faces
>> +  :version "30.1")
>
> I think there is some misunderstanding here.
> #+RESULTS is not a drawer. A drawer would be
>
> :results:
> ...
> :end:

Oh, I see.  How do we describe it?  A keyword, perhaps?

> As for code evaluation results, it can be anything with #+results
> keyword. Like
>
> #+results:
> : fixed width
> : text
>
> or
>
> #+results:
> #+begin_example
> ...
> #+end_example
>
> or
>
> #+results:
> Simple paragraph of text.
>
>>  	  ;; Code
>> -	  '(org-activate-code (1 'org-code t))
>> +	  '(org-activate-code (1 'org-code-results t))
>
> `org-activate-code' only affects fixed-width text
>
> : like
> : this
> :
> : one
>
> It has no relation to code results, except that fixed width is often
> (but not always) used as the default markup for results of evaluation.
>
> If what you are looking for is different formatting for code markup and
> fixed-width markup, `org-fixed-width' would be a better face name.
>
> If you are looking for formatting of results of evaluation, it would
> need to be a completely new, non-trivial, font-lock-keyword.

Thank you for the explanation!  The case I had in mind was indeed the
one where the 'org-code' face now applies.

I am interested in making the results display as distinct elements.  The
reason is that it can sometimes be hard to tell what was there before
and what was generated by 'org-babel-execute-buffer' and related.

You are right to point out that adding font-lock rules for all the
possible #+results is not trivial.  Better leave it as-is.

-- 
Protesilaos Stavrou
https://protesilaos.com


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

* Re: [PATCH] Define new face for the contents of #+RESULTS drawers
  2023-09-16 12:30   ` Protesilaos Stavrou
@ 2023-09-16 12:44     ` Ihor Radchenko
  2023-09-16 12:52       ` Protesilaos Stavrou
  0 siblings, 1 reply; 8+ messages in thread
From: Ihor Radchenko @ 2023-09-16 12:44 UTC (permalink / raw)
  To: Protesilaos Stavrou; +Cc: emacs-orgmode

Protesilaos Stavrou <info@protesilaos.com> writes:

>> I think there is some misunderstanding here.
>> #+RESULTS is not a drawer. A drawer would be
>>
>> :results:
>> ...
>> :end:
>
> Oh, I see.  How do we describe it?  A keyword, perhaps?

Affiliated keyword.

Org allows attaching arbitrary metadata to syntax elements. For example,
we can assign name and header via affiliated keywords:

#+name: src-block-name
#+header: :var x=1
#+begin_src elisp
 (+ 1 x)
#+end_src

#+results is a special affiliated keyword that marks syntax elements
generated by evaluating code blocks:

#+results:
I am generated paragraph

#+results:
:drawer:
I am generated drawer
:end:

#+results:
: I am generated fixed-width

#+results:
#+begin_latex
I am generated latex snippet
#+end_latex

etc.

>> `org-activate-code' only affects fixed-width text
>>
>> : like
>> : this
>> :
>> : one
> ...
> Thank you for the explanation!  The case I had in mind was indeed the
> one where the 'org-code' face now applies.

I am a bit confused. Now, `org-code' applies to all fixed-width
constructs, not just the ones generated by code blocks.

: I can just manually write this, and it will have ~code-block~ face.

#+begin_src ...
...
#+end_src

#+results:
: And this is generated src block result.
: It is also using ~code-block~ face (as all fixed-width blocks do).

> I am interested in making the results display as distinct elements.  The
> reason is that it can sometimes be hard to tell what was there before
> and what was generated by 'org-babel-execute-buffer' and related.
>
> You are right to point out that adding font-lock rules for all the
> possible #+results is not trivial.  Better leave it as-is.

Not very hard. Basically, we can write a custom activate function that
will search for "^#\\+results:" lines and prepend/append an extra custom
face to whatever that #+results is a part of (affiliated keyword is
never standalone - it is attached to whatever is a result of evaluation).

I am still not 100% sure what exactly you want to achieve - just
highlight evaluation results that are _also_ fixed-width or all kinds of
evaluation results.

-- 
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] 8+ messages in thread

* Re: [PATCH] Define new face for the contents of #+RESULTS drawers
  2023-09-16 12:44     ` Ihor Radchenko
@ 2023-09-16 12:52       ` Protesilaos Stavrou
  2023-09-17  9:53         ` Ihor Radchenko
  0 siblings, 1 reply; 8+ messages in thread
From: Protesilaos Stavrou @ 2023-09-16 12:52 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: emacs-orgmode

> From: Ihor Radchenko <yantar92@posteo.net>
> Date: Sat, 16 Sep 2023 12:44:37 +0000

> [... 79 lines elided]

> I am still not 100% sure what exactly you want to achieve - just
> highlight evaluation results that are _also_ fixed-width or all kinds of
> evaluation results.

The goal is to make all kinds of evaluation results distinct from their
manually written counterparts.  This is for users who read/interact with
a document and are given basic instructions on what to do while still
not knowing everything Org has to offer.

Though I understand now that there are more cases involved than I had
anticipated.  I will need to review everything on offer.  Let's abort
this effort for now.

Thank you for your time!

-- 
Protesilaos Stavrou
https://protesilaos.com


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

* Re: [PATCH] Define new face for the contents of #+RESULTS drawers
  2023-09-16 12:52       ` Protesilaos Stavrou
@ 2023-09-17  9:53         ` Ihor Radchenko
  2023-09-17 21:36           ` Samuel Wales
  0 siblings, 1 reply; 8+ messages in thread
From: Ihor Radchenko @ 2023-09-17  9:53 UTC (permalink / raw)
  To: Protesilaos Stavrou; +Cc: emacs-orgmode

Protesilaos Stavrou <info@protesilaos.com> writes:

> Though I understand now that there are more cases involved than I had
> anticipated.  I will need to review everything on offer.  Let's abort
> this effort for now.

Ok. Closing.
Canceled.

-- 
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] 8+ messages in thread

* Re: [PATCH] Define new face for the contents of #+RESULTS drawers
  2023-09-17  9:53         ` Ihor Radchenko
@ 2023-09-17 21:36           ` Samuel Wales
  2023-09-18  8:39             ` Ihor Radchenko
  0 siblings, 1 reply; 8+ messages in thread
From: Samuel Wales @ 2023-09-17 21:36 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Protesilaos Stavrou, emacs-orgmode

perhaps a face for results to indicate that it is generated?


On 9/17/23, Ihor Radchenko <yantar92@posteo.net> wrote:
> Protesilaos Stavrou <info@protesilaos.com> writes:
>
>> Though I understand now that there are more cases involved than I had
>> anticipated.  I will need to review everything on offer.  Let's abort
>> this effort for now.
>
> Ok. Closing.
> Canceled.
>
> --
> 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>
>
>


-- 
The Kafka Pandemic

A blog about science, health, human rights, and misopathy:
https://thekafkapandemic.blogspot.com


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

* Re: [PATCH] Define new face for the contents of #+RESULTS drawers
  2023-09-17 21:36           ` Samuel Wales
@ 2023-09-18  8:39             ` Ihor Radchenko
  0 siblings, 0 replies; 8+ messages in thread
From: Ihor Radchenko @ 2023-09-18  8:39 UTC (permalink / raw)
  To: Samuel Wales; +Cc: Protesilaos Stavrou, emacs-orgmode

Samuel Wales <samologist@gmail.com> writes:

> perhaps a face for results to indicate that it is generated?

May you please elaborate what you mean?

-- 
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] 8+ messages in thread

end of thread, other threads:[~2023-09-18  8:39 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-16  9:38 [PATCH] Define new face for the contents of #+RESULTS drawers Protesilaos Stavrou
2023-09-16  9:49 ` Ihor Radchenko
2023-09-16 12:30   ` Protesilaos Stavrou
2023-09-16 12:44     ` Ihor Radchenko
2023-09-16 12:52       ` Protesilaos Stavrou
2023-09-17  9:53         ` Ihor Radchenko
2023-09-17 21:36           ` Samuel Wales
2023-09-18  8:39             ` Ihor Radchenko

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).