Projects About AlBasmala
build status

Editor Comments

Article image
  

⭐ The code lives at github.com/alhassy/org-special-block-extras —star it, or discuss it there!

“Editor Comments” are intended to be top-level first-class comments in an article that are inline with the surrounding text and are delimited in such a way that they are visible but drawing attention. I first learned about this idea from Wolfram Kahl —who introduced me to Emacs many years ago. We

Example

This

In LaTeX, a =remark= appears inline with the text surrounding it.
#+begin_remark Bobert
org-mode is dope, yo!
#+replacewith:
Org-mode is essentially a path toward enlightenment.
#+end_remark
Unfortunately, in the HTML rendition, the =remark= is its own paragraph and thus
separated by new lines from its surrounding text.


Yields

In LaTeX, an remark appears inline with the text surrounding it.

[Bobert: Replace:

org-mode is dope, yo!

With:

Org-mode is essentially a path toward enlightenment.

]

Unfortunately, in the HTML rendition, the remark is its own paragraph and thus separated by new lines from its surrounding text.


Implementing ‘remark’, from §ection 1, with more bells and whistles
(defvar org-hide-editor-comments nil
  "Should editor comments be shown in the output or not.")

(org-defblock remark
      (&optional (editor "Editor Remark") &key (color "black") (signoff "") strong &context backend contents)
; :inline-please__see_margin_block_for_a_similar_incantation ; ⇒ crashes!
[:face '(:foreground "red" :weight bold)]
"Format CONTENTS as an first-class editor comment according to BACKEND.

The CONTENTS string has an optional switch: If it contains a line
with having only ‘#+replacewith:’, then the text preceding this
clause should be replaced by the text after it; i.e., this is
what the EDITOR (the person editing) intends and so we fromat the
replacement instruction (to the authour) as such.

In Emacs, as links, editor remarks are shown with a bold red; but
the exported COLOR of a remark is black by default and it is not
STRONG ---i.e., bold---. There is an optional SIGNOFF message
that is appended to the remark.
"
  (-let* (;; Are we in the html backend?
          (tex? (equal backend 'latex))

          ;; fancy display style
          (boxed (lambda (x)
                   (if tex?
                       (concat "\\fbox{\\bf " x "}")
                     (concat "<span style=\"border-width:1px"
                             ";border-style:solid;padding:5px\">"
                             "<strong>" x "</strong></span>"))))

          ;; Is this a replacement clause?
          ((this that) (s-split "\\#\\+replacewith:" contents))
          (replacement-clause? that) ;; There is a ‘that’
          (replace-keyword (if tex?
                             "\\underline{Replace:}" "&nbsp;<u>Replace:</u>"))
          (with-keyword    (if tex? "\\underline{With:}" "<u>With:</u>"
                             ))
          (editor (format "[%s:%s" editor
                          (if replacement-clause?
                              replace-keyword
                            "")))
          (contents′ (if replacement-clause?
                         (format "%s %s %s" this
                                 (org-export (funcall boxed with-keyword))
                                 that)
                       contents))

          ;; “[Editor Comment:”
          (edcomm-begin (funcall boxed editor))
          ;; “]”
          (edcomm-end (funcall boxed "]")))

    (setq org-export-allow-bind-keywords t) ;; So users can use “#+bind” immediately
    (if org-hide-editor-comments
        ""
      (format (pcase backend
                ('latex (format "{\\color{%%s}%s %%s %%s %%s %%s}" (if strong "\\bfseries" "")))
                (_ (format "<%s style=\"color: %%s;\">%%s %%s %%s %%s</%s>" (if strong "strong" "p") (if strong "strong" "p"))))
              color edcomm-begin contents′ signoff edcomm-end))))

In the HTML export, the edcomm special block is not in-line with the text surrounding it —ideally, it would be inline so that existing paragraphs are not split into multiple paragraphs but instead have an editor's comment indicating suggested alterations.

Let's have some sanity tests…

(deftest "The user's remark is enclosed in the default delimiters"
  [remark]
  (⇝ (⟰ "#+begin_remark
                   Here is some meta-commentary...
                  #+end_remark")
     (* anything) "[Editor Remark:"
     (* anything) "Here is some meta-commentary"
     (* anything)  "]"))

;; The other features of remark blocks should be tested;
;; but this is not a pressing, nor interesting, concern.

Example: No optional arguments

[Editor Remark:

Please change this section to be more, ya know, professional.

]


Source:

#+begin_remark
/Please/ *change* _this_ section to be more, ya know, professional.
#+end_remark
Example: Only providing a main argument ---i.e., the remark author, the editor

[Bobert:

Please change this section to be more, ya know, professional.

]


Source:

#+begin_remark Bobert
/Please/ *change* _this_ section to be more, ya know, professional.
#+end_remark
Example: Possibly with no contents:

[Bobert: ]


Source:

#+begin_remark Bobert
#+end_remark
Example: Empty contents, no authour, nothing

[Editor Remark: ]


Source:

#+begin_remark
#+end_remark
Example: Possibly with an empty new line

[Editor Remark: ]


Source:

#+begin_remark

#+end_remark
Example: With a “#+replacewith:” clause

[Editor Remark: Replace:

The two-dimensional notation; e.g., \(\sum_{i = 0}^n i^2\)

With:

A linear one-dimensional notation; e.g., \((\Sigma i : 0..n \;\bullet\; i^2)\)

]


Source:

#+begin_remark
The two-dimensional notation; e.g., $\sum_{i = 0}^n i^2$
#+replacewith:
A linear one-dimensional notation; e.g.,
$(\Sigma i : 0..n \;\bullet\; i^2)$
#+end_remark
Example: Possibly “malformed” replacement clauses

Forgot the thing to be replaced…

[Editor Remark: Replace: With:

A linear one-dimensional notation; e.g., \((\Sigma i : 0..n \;\bullet\; i^2)\)

]


Forgot the new replacement thing…

[Editor Remark: Replace:

The two-dimensional notation; e.g., \(\sum_{i = 0}^n i^2\)

With: ]


Completely lost one's train of thought…

[Editor Remark: Replace: With: ]

Source:

#+begin_remark
#+replacewith:
#+end_remark

A block to make an editorial comment could be overkill in some cases; luckily defblock automatically provides an associated link type for the declared special blocks.

Example: Terse remarks via links

[[edcomm:Jasim][Hello, where are you?]]

[Jasim: Hello, where are you? ]


The #+replacewith: switch —and usual Org markup— also works with these links:
[[remark:Qasim][/‘j’/ #+replacewith: /‘q’/]]


[Qasim: Replace: ‘j’ With: ‘q’ ]


All editor comments, remarks, are disabled by declaring, in your Org file:

#+bind: org-hide-editor-comments t

The #+bind: keyword makes Emacs variables buffer-local during export —it is evaluated after any src blocks. To use it, one must declare in their Emacs init file the following line, which our mode ensures is true.

(setq org-export-allow-bind-keywords t)
( Remember to C-c C-c the #+bind to activate it, the first time it is written. )

Generated by Emacs and Org-mode (•̀ᴗ•́)و
Creative Commons License
Life & Computing Science by Musa Al-hassy is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License