[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [O] [PATCH] inline src block results can be removed
From: |
Nicolas Goaziou |
Subject: |
Re: [O] [PATCH] inline src block results can be removed |
Date: |
Fri, 14 Nov 2014 21:39:00 +0100 |
"Charles C. Berry" <address@hidden> writes:
> More patches (as you can see). Now ox.el, ob-core.el, and ob-exp.el
> are patched.
Thanks.
> Also, the user can customize org-babel-inline-result-wrap to always
> get verbatim or otherwise wrap the contents of the macro.
I don't think this is a good idea.
If we rely on the macro recognition to properly inline results, setting
to anything else would break Org. It should be a defconst or we are
bound to shoot ourselves in the foot.
If a user wants verbatim output, he will have to somehow generate
{{{results:=output=}}}, e.g., through appropriate code or parameters.
>
> `:wrap latex' results in @@latex: ... @@.
I was thinking to {{{results(@@latex:...@@)}}}. A bit more verbose, but
you can also replace :wrap latex results.
> `:results latex' results in
> : @@LaTeX:
> : <results>@@
>
> which is a bit unsightly, but can be parsed and removed.
It is important to remove the spurious newline character, as it could
break the surrounding structure.
> I have not touched
> - :RESULTS drawers
> - lists
> - tables
These have to be ignored. An inline element cannot generate a non-inline
element. At least, we shouldn't make it easy to do that. There are
plenty other ways to generate those.
> From b369b0a1e69fd2b91c8f4eb7d824dcd18232917b Mon Sep 17 00:00:00 2001
> From: chasberry <address@hidden>
> Date: Thu, 13 Nov 2014 20:45:01 -0800
> Subject: [PATCH 1/3] lisp/ob-core.el: Replace inline `results' macro call or
> export-snippet
>
> * lisp/ob-core.el (org-babel-inline-result-wrap): Default is
> "{{{results(%s)}}}".
As written earlier, I highly suggest to make it a defconst.
> * lisp/ob-core.el (org-babel-insert-result): Delete any `results'
> macro or export-snippet immediately following inline src block;
> insert current value in 'results' macro or export snippet if :wrap
> header argument is given. Escape commas in the result with
> backslashes if the macro form is used.
You also need to escape backslash characters before commas, per
(info "(org) Macro replacement")
> * lisp/ob-core.el (org-babel-delete-babel-snippet): Add function to
> delete "{{{results(.*)}}}" macro calls or "@@backend:.*@@" provided
> they follow inline src blocks. Adding extra spaces between an
> export snippet and its inline src block will protect it from
> removal.
With {{{results(@@backend:...@@)}}}, we don't need the extra trick. Even
if it is more verbose, I think a regular syntax is better.
> + ;; escape commas, e.g. {{{results(a\,b)}}}
Missing capital and final dot.
> + ((and inlinep
> + (equal '("replace") result-params)
Spurious space.
> + (not (assoc :wrap (nth 2 info))))
`assq'
> (cond
> ((assoc :wrap (nth 2 info))
> (let ((name (or (cdr (assoc :wrap (nth 2 info))) "RESULTS")))
> - (funcall wrap (concat "#+BEGIN_" name)
> - (concat "#+END_" (car (org-split-string name))))))
> + (if inlinep
> + (funcall wrap (concat "@@" name ":") "@@" nil t)
> + (funcall wrap (concat "#+BEGIN_" name)
> + (concat "#+END_" (car (org-split-string
> name)))))))
> ((member "html" result-params)
> - (funcall wrap "#+BEGIN_HTML" "#+END_HTML"))
> - ((member "latex" result-params)
> - (funcall wrap "#+BEGIN_LaTeX" "#+END_LaTeX"))
> + (if inlinep
> + (funcall wrap "@@HTML:" "@@")
> + (funcall wrap "#+BEGIN_HTML" "#+END_HTML")))
> + ((member "latex" result-params)
> + (if inlinep
> + (funcall wrap "@@LaTeX:" "@@")
I'd rather have back-end names lowercase @@html:...@@ and @@latex:...@@
even though they are case insensitive anyway.
Also, you can avoid repeating "funcall wrap":
(apply wrap (if inlinep '("@@latex:" "@@") '("#+begin_latex" "#+end_latex")))
> +(defun org-babel-delete-babel-snippet (&optional info)
> + "When point is in an inline src block, delete an export-snippet
> +or `results' macro call just after it. To protect export snippets
> +from removal, add extra spaces between the src block and the
> +snippet."
> + (let ((location (org-babel-where-is-src-block-result nil info)))
> + (when location
> + (save-excursion
> + (goto-char location)
> + (cond
> + ((looking-at "\\([ ]\\{1,2\\}\\)\\(@\\)")
> + (goto-char (match-end 1))
> + (let ((export-snippet (org-element-export-snippet-parser)))
Don't call dedicated parser functions directly. The public functions are
`org-element-at-point' and `org-element-context'.
Anyway, this is not useful if we don't write directly export snippets.
> + (if export-snippet
> + (let ((start (org-element-property :begin export-snippet))
> + (end (org-element-property :end export-snippet)))
> + (delete-region start end)))))
> + ((looking-at "\\([[:space:]]*\\)\\({{{results(.*?)}}}\\)")
> + (delete-region (match-end 1) (match-end 2))))))))
Using `org-element-context' may be better.
WDYT?
Regards,
- [O] [PATCH] inline src block results can be removed, Charles C. Berry, 2014/11/11
- Re: [O] [PATCH] inline src block results can be removed, Andreas Leha, 2014/11/11
- Re: [O] [PATCH] inline src block results can be removed, Aaron Ecay, 2014/11/12
- Re: [O] [PATCH] inline src block results can be removed, Charles C. Berry, 2014/11/12
- Re: [O] [PATCH] inline src block results can be removed, Nicolas Goaziou, 2014/11/13
- Re: [O] [PATCH] inline src block results can be removed, Andreas Leha, 2014/11/13
- Re: [O] [PATCH] inline src block results can be removed, Charles C. Berry, 2014/11/14
- Re: [O] [PATCH] inline src block results can be removed,
Nicolas Goaziou <=
- Re: [O] [PATCH] inline src block results can be removed, Aaron Ecay, 2014/11/14
- Re: [O] [PATCH] inline src block results can be removed, Nicolas Goaziou, 2014/11/15
- Re: [O] [PATCH] inline src block results can be removed, Charles C. Berry, 2014/11/15
- Re: [O] [PATCH] inline src block results can be removed, Nicolas Goaziou, 2014/11/16
- Re: [O] [PATCH] inline src block results can be removed, Daniele Pizzolli, 2014/11/24
- Re: [O] [PATCH] inline src block results can be removed, Andreas Leha, 2014/11/24