emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Nicolas Goaziou <mail@nicolasgoaziou.fr>
To: "Charles C. Berry" <ccberry@ucsd.edu>
Cc: Aaron Ecay <aaronecay@gmail.com>,
	Andreas Leha <andreas.leha@med.uni-goettingen.de>,
	emacs-orgmode@gnu.org, Ista Zahn <istazahn@gmail.com>,
	mcg <giepen.m@googlemail.com>
Subject: Re: [PATCH] inline src block results can be removed
Date: Fri, 14 Nov 2014 21:39:00 +0100	[thread overview]
Message-ID: <87sihltt3v.fsf@selenimh.mobile.lan> (raw)
In-Reply-To: <alpine.OSX.2.00.1411140906180.1154@charles-berrys-macbook.local> (Charles C. Berry's message of "Fri, 14 Nov 2014 09:43:16 -0800")

"Charles C. Berry" <ccberry@ucsd.edu> 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 <ccberry@ucsd.edu>
> 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,

  reply	other threads:[~2014-11-14 20:38 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-12  0:49 [PATCH] inline src block results can be removed Charles C. Berry
2014-11-12  1:10 ` Andreas Leha
2014-11-12  6:58   ` Charles C. Berry
2014-11-12 19:34 ` Aaron Ecay
2014-11-12 23:47   ` Charles C. Berry
2014-11-13 17:48     ` Nicolas Goaziou
2014-11-13 19:06       ` Andreas Leha
2014-11-14 17:43       ` Charles C. Berry
2014-11-14 20:39         ` Nicolas Goaziou [this message]
2014-11-14 23:04           ` Aaron Ecay
2014-11-16  0:10             ` Nicolas Goaziou
2014-11-15 20:22           ` Charles C. Berry
2014-11-16 23:23             ` Nicolas Goaziou
2014-11-24  9:48               ` Daniele Pizzolli
2014-11-24 10:18                 ` Andreas Leha
2015-01-13  0:48               ` New patches WAS " Charles C. Berry
2015-01-16 22:41                 ` Nicolas Goaziou
2015-01-19  3:22                   ` Charles C. Berry
2015-01-19 17:53                     ` Nicolas Goaziou
2015-01-19 19:31                       ` Charles C. Berry
2015-01-20 23:30                         ` Nicolas Goaziou
2015-01-22  3:07                           ` Charles C. Berry
2015-01-22 23:08                             ` Nicolas Goaziou
2015-01-24 22:47                               ` Charles C. Berry
2015-01-25  1:14                                 ` Aaron Ecay
2015-01-25  5:01                                   ` Charles C. Berry
2015-01-29 20:31                               ` Charles C. Berry
2015-01-17  3:22                 ` Aaron Ecay
2015-01-17 22:20                   ` Nicolas Goaziou
2015-01-18 19:13                     ` Aaron Ecay
2015-01-18 22:34                       ` Nicolas Goaziou
2015-01-18 22:55                         ` Aaron Ecay
  -- strict thread matches above, loose matches on Subject: below --
2014-11-24 11:12 Daniele Pizzolli
2014-11-25  8:04 ` Daniele Pizzolli
2014-11-25  9:52   ` Andreas Leha

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87sihltt3v.fsf@selenimh.mobile.lan \
    --to=mail@nicolasgoaziou.fr \
    --cc=aaronecay@gmail.com \
    --cc=andreas.leha@med.uni-goettingen.de \
    --cc=ccberry@ucsd.edu \
    --cc=emacs-orgmode@gnu.org \
    --cc=giepen.m@googlemail.com \
    --cc=istazahn@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).