From mboxrd@z Thu Jan 1 00:00:00 1970 From: Daniele Pizzolli Subject: Tentative patch to keep org-babel-results-keyword when calling org-babel-remove-result Date: Fri, 20 Sep 2013 22:28:37 +0200 Message-ID: <523CAFF5.8090604@toel.it> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:38658) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VN7K1-0007e1-2v for emacs-orgmode@gnu.org; Fri, 20 Sep 2013 16:29:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VN7Js-0002Th-T9 for emacs-orgmode@gnu.org; Fri, 20 Sep 2013 16:29:00 -0400 Received: from relay4-d.mail.gandi.net ([217.70.183.196]:32792) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VN7Js-0002TN-JT for emacs-orgmode@gnu.org; Fri, 20 Sep 2013 16:28:52 -0400 Received: from mfilter21-d.gandi.net (mfilter21-d.gandi.net [217.70.178.149]) by relay4-d.mail.gandi.net (Postfix) with ESMTP id 2CEB4172071 for ; Fri, 20 Sep 2013 22:28:41 +0200 (CEST) Received: from relay4-d.mail.gandi.net ([217.70.183.196]) by mfilter21-d.gandi.net (mfilter21-d.gandi.net [10.0.15.180]) (amavisd-new, port 10024) with ESMTP id c4Jf5A+X289j for ; Fri, 20 Sep 2013 22:28:39 +0200 (CEST) Received: from [10.0.0.235] (host159-38-static.38-79-b.business.telecomitalia.it [79.38.38.159]) (Authenticated sender: me@toel.it) by relay4-d.mail.gandi.net (Postfix) with ESMTPSA id 26B01172077 for ; Fri, 20 Sep 2013 22:28:38 +0200 (CEST) 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: emacs-orgmode@gnu.org 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)))))))