Open NightMachinery opened 3 years ago
Using :wrap results
seems to work, though I'm not sure if this will not have consequences elsewhere.
One problem with :wrap results
is that the the inserted content is not quoted for org-mode
, and this can cause re-evals of the block to keep inserting new result blocks.
I hacked together a solution which uses normal :wrap example
to use org
's builtin quoting, and then replaces the block with results
:
(defun night/babel-ansi2 ()
(interactive)
(when-let ((beg (org-babel-where-is-src-block-result nil nil)))
(save-excursion
(goto-char beg)
(when (looking-at org-babel-result-regexp)
(let* (
(end (org-babel-result-end)))
;; (z ectty (delete-and-extract-region (+ beg 7)
;; (+ beg 14)))
(when (search-forward "#+begin_example" nil t)
(replace-match "#+begin_results" nil t))
(while (search-forward "#+end_example" nil t))
(replace-match "#+end_results" nil t)
;; (replace-string "#+end_example" "#+end_results" t beg end)
(let* ((colored (xterm-color-filter (delete-and-extract-region beg end))))
(goto-char beg)
(insert colored)))))))
Seems to work well:
Update: You might prefer to escape the output manually with ... | command sd '^(\s*(?:\x1b\[33m)?)(\*|#)' '$1,$2'
, as the default escaping does not handle colored headings etc.
I have this function which applies the text properties correctly to the result blocks:
But because they are wrapped in
example
blocks, the colors are stripped. This 'bug' does not exist if I useansi-color
:But
ansi-color
does not support true colors. Any ideas? Thanks!