* Tentative patch to keep org-babel-results-keyword when calling org-babel-remove-result
@ 2013-09-20 20:28 Daniele Pizzolli
2013-09-20 21:13 ` Eric Schulte
0 siblings, 1 reply; 5+ messages in thread
From: Daniele Pizzolli @ 2013-09-20 20:28 UTC (permalink / raw)
To: emacs-orgmode
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)))))))
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: Tentative patch to keep org-babel-results-keyword when calling org-babel-remove-result
2013-09-20 20:28 Tentative patch to keep org-babel-results-keyword when calling org-babel-remove-result Daniele Pizzolli
@ 2013-09-20 21:13 ` Eric Schulte
2013-09-20 21:56 ` Daniele Pizzolli
0 siblings, 1 reply; 5+ messages in thread
From: Eric Schulte @ 2013-09-20 21:13 UTC (permalink / raw)
To: Daniele Pizzolli; +Cc: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 205 bytes --]
Hi Daniele,
Thanks for the suggestion and the accompanying patch. I've just applied
a modified version of your patch (included below). Please let me know
if this is insufficient for your needs.
Best,
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-babel-remove-result-option-keep-result-keyword.patch --]
[-- Type: text/x-diff, Size: 1640 bytes --]
From 136bdc0e83358fa3f6af1d8b3b0cd71cace61efe Mon Sep 17 00:00:00 2001
From: Eric Schulte <schulte.eric@gmail.com>
Date: Fri, 20 Sep 2013 15:07:15 -0600
Subject: [PATCH] org-babel-remove-result option keep result keyword
This patch is based off of a request and an initial patch supplied by
Daniele Pizzolli.
* lisp/ob-core.el (org-babel-remove-result): Added an option to keep
the results keyword when removing the content of results.
---
lisp/ob-core.el | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index cc6b7a9..e2404c1 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -2159,15 +2159,17 @@ 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)
+(defun org-babel-remove-result (&optional info keep-keyword)
"Remove the result of the current source block."
(interactive)
- (let ((location (org-babel-where-is-src-block-result nil info)) start)
+ (let ((location (org-babel-where-is-src-block-result nil info)))
(when location
- (setq start (- location 1))
(save-excursion
- (goto-char location) (forward-line 1)
- (delete-region start (org-babel-result-end))))))
+ (goto-char location)
+ (when (looking-at org-babel-result-regexp)
+ (delete-region
+ (if keep-keyword (1+ (match-end 0)) (match-beginning 0))
+ (progn (forward-line 1) (org-babel-result-end))))))))
(defun org-babel-result-end ()
"Return the point at the end of the current set of results."
--
1.8.4
[-- Attachment #3: Type: text/plain, Size: 3056 bytes --]
Daniele Pizzolli <dan@toel.it> writes:
> 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)))))))
>
>
--
Eric Schulte
https://cs.unm.edu/~eschulte
PGP: 0x614CA05D
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: Tentative patch to keep org-babel-results-keyword when calling org-babel-remove-result
2013-09-20 21:13 ` Eric Schulte
@ 2013-09-20 21:56 ` Daniele Pizzolli
2013-09-20 22:30 ` Eric Schulte
0 siblings, 1 reply; 5+ messages in thread
From: Daniele Pizzolli @ 2013-09-20 21:56 UTC (permalink / raw)
To: emacs-orgmode
On 09/20/2013 11:13 PM, Eric Schulte wrote:
> Hi Daniele,
>
> Thanks for the suggestion and the accompanying patch. I've just applied
> a modified version of your patch (included below). Please let me know
> if this is insufficient for your needs.
Hello Eric,
Wonderful! Your patch is perfect for my use case. Thanks for the
quick improvement!
I just re-discovered the amazing feature of "named source blocks".
that unfortunately trigger a corner case:
#+NAME: fig1
#+BEGIN_SRC...
#+END_SRC
Some text
#+RESULTS: fig1
** Other section
After running:
(org-babel-map-src-blocks nil (org-babel-remove-result nil t))
Will result in:
#+NAME: fig1
#+BEGIN_SRC...
#+END_SRC
Some text
#+RESULTS: f
** Other section
I tried to look at the code, but the level of indirection you added
makes me feel lost. I would be happy to help in testing, even with
more use cases if needed. I just found that the section “Writing
tests with minimal Emacs-lisp knowledge” at
http://orgmode.org/worg/org-tests/index.html#sec-3 is not yet complete
but I can have a look at the source code and follow your advises or
examples.
Thanks again,
Daniele Pizzolli
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Tentative patch to keep org-babel-results-keyword when calling org-babel-remove-result
2013-09-20 21:56 ` Daniele Pizzolli
@ 2013-09-20 22:30 ` Eric Schulte
2013-09-21 6:44 ` Daniele Pizzolli
0 siblings, 1 reply; 5+ messages in thread
From: Eric Schulte @ 2013-09-20 22:30 UTC (permalink / raw)
To: Daniele Pizzolli; +Cc: emacs-orgmode
Hi Daniele,
Thanks for catching this very large edge case which I completely
ignored. I've just pushed up a fix.
Best,
Daniele Pizzolli <dan@toel.it> writes:
> On 09/20/2013 11:13 PM, Eric Schulte wrote:
>> Hi Daniele,
>>
>> Thanks for the suggestion and the accompanying patch. I've just applied
>> a modified version of your patch (included below). Please let me know
>> if this is insufficient for your needs.
>
> Hello Eric,
>
> Wonderful! Your patch is perfect for my use case. Thanks for the
> quick improvement!
>
> I just re-discovered the amazing feature of "named source blocks".
> that unfortunately trigger a corner case:
>
> #+NAME: fig1
> #+BEGIN_SRC...
> #+END_SRC
>
> Some text
>
> #+RESULTS: fig1
>
> ** Other section
>
> After running:
>
> (org-babel-map-src-blocks nil (org-babel-remove-result nil t))
>
> Will result in:
>
> #+NAME: fig1
> #+BEGIN_SRC...
> #+END_SRC
>
> Some text
>
> #+RESULTS: f
> ** Other section
>
> I tried to look at the code, but the level of indirection you added
> makes me feel lost. I would be happy to help in testing, even with
> more use cases if needed. I just found that the section “Writing
> tests with minimal Emacs-lisp knowledge” at
> http://orgmode.org/worg/org-tests/index.html#sec-3 is not yet complete
> but I can have a look at the source code and follow your advises or
> examples.
>
> Thanks again,
> Daniele Pizzolli
>
--
Eric Schulte
https://cs.unm.edu/~eschulte
PGP: 0x614CA05D
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Tentative patch to keep org-babel-results-keyword when calling org-babel-remove-result
2013-09-20 22:30 ` Eric Schulte
@ 2013-09-21 6:44 ` Daniele Pizzolli
0 siblings, 0 replies; 5+ messages in thread
From: Daniele Pizzolli @ 2013-09-21 6:44 UTC (permalink / raw)
To: emacs-orgmode
On 09/21/2013 12:30 AM, Eric Schulte wrote:
> Hi Daniele,
>
> Thanks for catching this very large edge case which I completely
> ignored. I've just pushed up a fix.
Hi Eric,
Thanks to you for fixing it. It never ceases to amaze me how many
clever thighs org-mode can do!
Regards,
Daniele Pizzolli
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2013-09-21 6:45 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-20 20:28 Tentative patch to keep org-babel-results-keyword when calling org-babel-remove-result Daniele Pizzolli
2013-09-20 21:13 ` Eric Schulte
2013-09-20 21:56 ` Daniele Pizzolli
2013-09-20 22:30 ` Eric Schulte
2013-09-21 6:44 ` Daniele Pizzolli
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.