all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Daniele Pizzolli <dan@toel.it>
To: emacs-orgmode@gnu.org
Subject: Tentative patch to keep org-babel-results-keyword when calling org-babel-remove-result
Date: Fri, 20 Sep 2013 22:28:37 +0200	[thread overview]
Message-ID: <523CAFF5.8090604@toel.it> (raw)

Hello @ll,

this is my fist post on the list.  Thanks to everybody for posting
interesting things and keeping org-mode improving!

I am seeking help because of my limited elisp knowledge.

This is my incomplete patch to extend org-babel-remove-result to keep
the org-babel-results-keyword when removing the results.

I need to keep the org-babel-results-keyword because I want to commit
to my dvcs a clean file and easily evaluate the results at any time
later.

Unfortunately running org-babel-remove-result on a snippet like the
following:

#+BEGIN_SRC octave :results value file
% at the end produce an image
#+END_SRC

#+ATTR_LATEX: :width 3cm
#+RESULTS:
[[file:image_01.png]]

Will output:

#+BEGIN_SRC octave :results value file
% at the end produce an image
#+END_SRC

#+ATTR_LATEX: :width 3cm

And a run of org-babel-execute-buffer will produce:

#+BEGIN_SRC octave :results value file
% at the end produce an image
#+END_SRC

#+RESULTS:
[[file:image_01.png]]

#+ATTR_LATEX: :width 3cm

changing the position of the LaTeX specific attribute #+ATTR_LATEX: in
way that it becomes useless.

The patch add an optional argument to org-babel-remove-result but
relies to an hard-coded value of the length of the default
org-babel-results-keyword plus syntax elements: "#+RESULTS:".

Instead of calculating lengths I think that is better to move to next
line.

I also skipped a deletion of the last char assuming that is always a
new line.  Is this assumption correct?  If we delete the last line
we can end with:

#+RESULTS:
** some other section

That will cause problem in the next evaluation.

I will appreciate your suggestions to improve the patch myself.  It
would be great also if anybody can implement it properly and get it merged.

Thanks in advance,
Daniele Pizzolli


diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index cc6b7a9..7517ebf 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -2159,15 +2159,18 @@ code ---- the results are extracted in the syntax of the source
  	  (set-marker visible-beg nil)
  	  (set-marker visible-end nil))))))

-(defun org-babel-remove-result (&optional info)
-  "Remove the result of the current source block."
+(defun org-babel-remove-result (&optional info keep-keyword)
+  "Remove the result of the current source block.  Optionally
+keep the result keyword."
    (interactive)
    (let ((location (org-babel-where-is-src-block-result nil info)) start)
      (when location
-      (setq start (- location 1))
+      (setq start (if keep-keyword (+ location 10) (- location 1)))
        (save-excursion
          (goto-char location) (forward-line 1)
-        (delete-region start (org-babel-result-end))))))
+        (delete-region
+	  start
+          (if keep-keyword (- (org-babel-result-end) 1) (org-babel-result-end)))))))

             reply	other threads:[~2013-09-20 20:29 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-20 20:28 Daniele Pizzolli [this message]
2013-09-20 21:13 ` Tentative patch to keep org-babel-results-keyword when calling org-babel-remove-result Eric Schulte
2013-09-20 21:56   ` Daniele Pizzolli
2013-09-20 22:30     ` Eric Schulte
2013-09-21  6:44       ` Daniele Pizzolli

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

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

  git send-email \
    --in-reply-to=523CAFF5.8090604@toel.it \
    --to=dan@toel.it \
    --cc=emacs-orgmode@gnu.org \
    /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 external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.