From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Goaziou Subject: Re: [PATCH] inline src block results can be removed Date: Fri, 14 Nov 2014 21:39:00 +0100 Message-ID: <87sihltt3v.fsf@selenimh.mobile.lan> References: <87egt81acy.fsf@gmail.com> <8761ejq9ek.fsf@nicolasgoaziou.fr> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:37153) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XpNdL-0001yl-R5 for emacs-orgmode@gnu.org; Fri, 14 Nov 2014 15:38:27 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XpNdD-00005e-NG for emacs-orgmode@gnu.org; Fri, 14 Nov 2014 15:38:19 -0500 Received: from relay4-d.mail.gandi.net ([2001:4b98:c:538::196]:35115) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XpNdD-00005B-EM for emacs-orgmode@gnu.org; Fri, 14 Nov 2014 15:38:11 -0500 In-Reply-To: (Charles C. Berry's message of "Fri, 14 Nov 2014 09:43:16 -0800") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: "Charles C. Berry" Cc: Aaron Ecay , Andreas Leha , emacs-orgmode@gnu.org, Ista Zahn , mcg "Charles C. Berry" 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: > : @@ > > 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 > 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,