[O] [RFC] [PATCH] ox-latex: support :float no with caption for minted listings

2014-08-23 Thread Aaron Ecay
* lisp/ox-latex.el (org-latex-src-block): Support :float no with
caption for minted.
(org-latex-listings): Edit docstring to describe this usecase.

This takes advantage of the caption package’s \captionof command,
which allows to insert a caption (with autogenerated number and
\ref-able label) without creating a floating environment.  One example
of where this is useful is in the case of a minted source code listing
that spans more than one page.  (Latex floats can’t be larger than a
page, generally speaking.)

I haven’t done much testing, but the documentation of the listings
package seems to indicate that it already handles this case without
any special arrangement by org.
---
 lisp/ox-latex.el | 26 +-
 1 file changed, 25 insertions(+), 1 deletion(-)

diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index c14d6dc..e29c6d2 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -727,6 +727,26 @@ using customize, or with
   \(require 'ox-latex)
   \(add-to-list 'org-latex-packages-alist '(\"\" \"minted\"))

+You can have listings with a caption which nonetheless do not
+float.  This is useful in case the source code takes up more than
+a page, in which case trying to float it will also truncate it.
+To achieve this, you should specifying the following attributes
+on the source block:
+
+  #+caption: ...
+  #+attr_latex: :float no
+  #+begin_src
+...
+  #+end_src
+
+In this case, if you are using minted you must add the
+\"caption\" latex package to your document:
+
+  \(add-to-list 'org-latex-packages-alist '(\"\" \"caption\"))
+
+The listings package handles this case correctly with no
+additional packages.
+
 In addition, it is necessary to install pygments
 \(http://pygments.org), and to configure the variable
 `org-latex-pdf-process' so that the -shell-escape option is
@@ -2301,7 +2321,11 @@ contextual information."
((eq listings 'minted)
(let* ((caption-str (org-latex--caption/label-string src-block info))
   (float-env
-   (cond ((and (not float) (plist-member attributes :float)) "%s")
+   (cond ((and (string= "no" float) caption)
+  (format "%%s\n%s" (replace-regexp-in-string
+ "caption" "\\captionof{listing}"
+ caption-str t t)))
+ ((string= "no" float) "%s")
  ((string= "multicolumn" float)
   (format "\\begin{listing*}\n%%s\n%s\\end{listing*}"
   caption-str))
--
2.0.4



[O] [RFC] [PATCH] org-table: introduce an upper bound on the number of lines `org-table-convert-region-max-lines' will attempt.

2014-08-23 Thread Aaron Ecay
* lisp/org-table.el (org-table-convert-region-max-lines): New
defcustom.
(org-table-convert-region): Use it.

This is useful primarily for babel results.  If a large table-like
object is returned by a code block, this function will become bogged
down in trying to read it, and hang emacs (necessitating a C-g).  This
situation most commonly arises when a :results none header has been
ommitted.  With the patch, the user will not experience a hang, but
rather an error message.
---
 lisp/org-table.el | 95 +++
 1 file changed, 54 insertions(+), 41 deletions(-)

diff --git a/lisp/org-table.el b/lisp/org-table.el
index 06a1008..bf88d11 100644
--- a/lisp/org-table.el
+++ b/lisp/org-table.el
@@ -366,6 +366,16 @@ available parameters."
   :group 'org-table-import-export
   :type 'string)

+(defcustom org-table-convert-region-max-lines 999
+  "Max lines that `org-table-convert-region' will attempt to process.
+
+The function can be slow on larger regions; this safety feature
+prevents it from hanging emacs."
+  :group 'org-table-import-export
+  :type 'integer
+  :version "24.5"
+  :package-version '(Org . "8.4"))
+
 (defconst org-table-auto-recalculate-regexp "^[ \t]*| *# *\\(|\\|$\\)"
   "Detects a table line marked for automatic recalculation.")
 (defconst org-table-recalculate-regexp "^[ \t]*| *[#*] *\\(|\\|$\\)"
@@ -566,49 +576,52 @@ nil  When nil, the command tries to be smart and 
figure out the
   (let* ((beg (min beg0 end0))
 (end (max beg0 end0))
 re)
-(if (equal separator '(64))
-   (setq separator (read-regexp "Regexp for field separator")))
-(goto-char beg)
-(beginning-of-line 1)
-(setq beg (point-marker))
-(goto-char end)
-(if (bolp) (backward-char 1) (end-of-line 1))
-(setq end (point-marker))
-;; Get the right field separator
-(unless separator
+(if (> (count-lines beg end) org-table-convert-region-max-lines)
+   (user-error "Region is longer than `org-table-convert-region-max-lines' 
(%s) lines; not converting"
+   org-table-convert-region-max-lines)
+  (if (equal separator '(64))
+ (setq separator (read-regexp "Regexp for field separator")))
   (goto-char beg)
-  (setq separator
+  (beginning-of-line 1)
+  (setq beg (point-marker))
+  (goto-char end)
+  (if (bolp) (backward-char 1) (end-of-line 1))
+  (setq end (point-marker))
+  ;; Get the right field separator
+  (unless separator
+   (goto-char beg)
+   (setq separator
+ (cond
+  ((not (re-search-forward "^[^\n\t]+$" end t)) '(16))
+  ((not (re-search-forward "^[^\n,]+$" end t)) '(4))
+  (t 1
+  (goto-char beg)
+  (if (equal separator '(4))
+ (while (< (point) end)
+   ;; parse the csv stuff
(cond
-((not (re-search-forward "^[^\n\t]+$" end t)) '(16))
-((not (re-search-forward "^[^\n,]+$" end t)) '(4))
-(t 1
-(goto-char beg)
-(if (equal separator '(4))
-   (while (< (point) end)
- ;; parse the csv stuff
- (cond
-  ((looking-at "^") (insert "| "))
-  ((looking-at "[ \t]*$") (replace-match " |") (beginning-of-line 2))
-  ((looking-at "[ \t]*\"\\([^\"\n]*\\)\"")
-   (replace-match "\\1")
-   (if (looking-at "\"") (insert "\"")))
-  ((looking-at "[^,\n]+") (goto-char (match-end 0)))
-  ((looking-at "[ \t]*,") (replace-match " | "))
-  (t (beginning-of-line 2
-  (setq re (cond
-   ((equal separator '(4)) "^\\|\"?[ \t]*,[ \t]*\"?")
-   ((equal separator '(16)) "^\\|\t")
-   ((integerp separator)
-(if (< separator 1)
-(user-error "Number of spaces in separator must be >= 1")
-  (format "^ *\\| *\t *\\| \\{%d,\\}" separator)))
-   ((stringp separator)
-(format "^ *\\|%s" separator))
-   (t (error "This should not happen"
-  (while (re-search-forward re end t)
-   (replace-match "| " t t)))
-(goto-char beg)
-(org-table-align)))
+((looking-at "^") (insert "| "))
+((looking-at "[ \t]*$") (replace-match " |") (beginning-of-line 2))
+((looking-at "[ \t]*\"\\([^\"\n]*\\)\"")
+ (replace-match "\\1")
+ (if (looking-at "\"") (insert "\"")))
+((looking-at "[^,\n]+") (goto-char (match-end 0)))
+((looking-at "[ \t]*,") (replace-match " | "))
+(t (beginning-of-line 2
+   (setq re (cond
+ ((equal separator '(4)) "^\\|\"?[ \t]*,[ \t]*\"?")
+ ((equal separator '(16)) "^\\|\t")
+ ((integerp separator)
+  (if (< separator 1)
+  (user-error "Number of spaces in separator must be >= 1")
+(format "^ *\\| *\t *\\| \\

[O] Only show in the agenda for today?

2014-08-23 Thread Sharon Kimble
I have got several TODO's which are set to repeat after one day, like
this one -
--8<---cut here---start->8---
** TODO ditto beeb 
SCHEDULED: <2014-08-22 Fri +1d>
--8<---cut here---end--->8---

How can I get them to show in the agenda just for today only please, yet
still retain their ability to repeat?

Thanks
Sharon. 
-- 
A taste of linux = http://www.sharons.org.uk
my git repo = https://bitbucket.org/boudiccas/dots
TGmeds = http://www.tgmeds.org.uk
Debian testing, fluxbox 1.3.5, emacs 24.3.93.1


signature.asc
Description: PGP signature


Re: [O] R code block produces only partial output

2014-08-23 Thread Aaron Ecay
2014ko abuztuak 19an, Achim Gratz-ek idatzi zuen:
> 
> Aaron Ecay writes:
>> R is capable of installing packages to a user-specified directory,
>> without requiring root or any other special privileges.  So IT cannot
>> literally prevent R users from installing their own packages;
> 
> They can, all they have to do is to take away the ability to connect to
> the outside network and that's what is increasingly being done (for
> other reasons, mind you).
> 
>> the requirement must rather come as a statement of policy.
> 
> That is another common thing, if only to shift the responsibility if the
> other measures don't actually prevent that.
> 
>> I’d like to
>> understand more about how such regimes work and how org could work
>> with them, ideally from people who have direct experience with them.
> 
> Ideally, don't require the use of a non-core package.  The beef with
> things like CTAN, CRAN or CPAN is that they require extra maintenance
> beyond the pure installation of some software and some specific
> knowledge of the software in question and that's just not going to
> happen in some places.
> 
>> Otherwise, it would be disappointing if the fear that an unidentifiable
>> somebody somewhere might not be able to install R packages derailed the
>> improvement of babel’s R support.
> 
> The request was to keep a fallback to core.  I have no comment at this
> time if it would be possible or not.  Since ultimately it's the session
> support of Emacs that is clunky (and that affects most other languages
> as well), maybe an effort to improve that would be more generally
> helpful than working around it in different ways in each language.

Well, I think that it’s going to be difficult to make babel a better
literate programming solution for R if we restrict ourselves not to
use the state-of-the-art R package for low-level literate programming
support.  Org is full of features which one needs to install other
software to use, and I’m comfortable with the idea that babel’s R
support should require the evaluate package.  However, it’s difficult
to argue this point of view when no one has spoken up about their own
requirements, and a spirit of conservatism in the face of vague
imagined difficulties persists.

The attached patch fixes the problem that touched off this thread.
It’s only debatably nicer than the present approach, but it has the
independently desirable property of segregating babel-driven output
from the session buffer.  It incorporates what I think is a fix for
the tramp bug Charles pointed out.

It’s as yet only lightly tested, and as always comments are welcome.
>From 5f3b4ec203b8bc14c3da975368481c3767ab6f02 Mon Sep 17 00:00:00 2001
From: Aaron Ecay 
Date: Sat, 16 Aug 2014 00:49:05 -0400
Subject: [PATCH] ob-R: overhaul handling of :output results type in a session
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* (org-babel-R-evaluate-session): Capture output using ‘ess-execute’.

This function dumps the output from R into a buffer; we then use some
tricks to clean it of spurious text.
---
 lisp/ob-R.el | 63 +++-
 1 file changed, 45 insertions(+), 18 deletions(-)

diff --git a/lisp/ob-R.el b/lisp/ob-R.el
index 41b943c..2d8220b 100644
--- a/lisp/ob-R.el
+++ b/lisp/ob-R.el
@@ -364,9 +364,10 @@ last statement in BODY, as elisp."
 (output (org-babel-eval org-babel-R-command body
 
 (defvar ess-eval-visibly-p)
+(defvar ess-execute-in-process-buffer)
 
 (defun org-babel-R-evaluate-session
-  (session body result-type result-params column-names-p row-names-p)
+(session body result-type result-params column-names-p row-names-p)
   "Evaluate BODY in SESSION.
 If RESULT-TYPE equals 'output then return standard output as a
 string.  If RESULT-TYPE equals 'value then return the value of the
@@ -396,23 +397,49 @@ last statement in BODY, as elisp."
 	  (org-babel-import-elisp-from-file tmp-file '(16)))
 	column-names-p)))
 (output
- (mapconcat
-  'org-babel-chomp
-  (butlast
-   (delq nil
-	 (mapcar
-	  (lambda (line) (when (> (length line) 0) line))
-	  (mapcar
-	   (lambda (line) ;; cleanup extra prompts left in output
-		 (if (string-match
-		  "^\\([ ]*[>+\\.][ ]?\\)+\\([[0-9]+\\|[ ]\\)" line)
-		 (substring line (match-end 1))
-		   line))
-	   (org-babel-comint-with-output (session org-babel-R-eoe-output)
-		 (insert (mapconcat 'org-babel-chomp
-(list body org-babel-R-eoe-indicator)
-"\n"))
-		 (inferior-ess-send-input)) "\n"
+ (let* ((sentinel-file (org-babel-temp-file "R-")))
+   ;; This code borrowed from
+   ;; `org-babel-comint-eval-invisibly-and-wait-for-file'
+   (unless (org-babel-comint-buffer-livep session)
+	 (error "Buffer %s does not exist or has no process" session))
+   (if (file-exists-p sentinel-file) (delete-file sentinel-file))
+   (with-current-buffer session
+	 (let ((ess-execute-in-

Re: [O] [PATCH] ob-R.el: Add customizable R command primary prompt setting

2014-08-23 Thread Aaron Ecay
Hi Grant,

We have some discussion of realted issues in the thread that starts at
.

2014ko abuztuak 22an, Grant Rettke-ek idatzi zuen:
> 
>  list/ob-R.el (org-babel-R-command-primary-prompt,
> org-babel-R-evaluate-session): Former adds customizable prompt value
> the latter utilizes it.
> 
> My R prompt looks like this "ℝ> ".  Babel needs to know more how to
> handle various situations so the
> regex used in `org-babel-R-evaluate-session' to identify the prompt
> looks like this "^\\([ ]*[ℝ>+\\.][ ]?\\)+\\([[0-9]+\\|[ ]\\)".
> It is required to handle various R prompt situations correctly.  It
> may change over time to handle more situations.  The
> user doesn't need to know about those details.  The user only cares
> about the R prompt alone.  For example, when
> they set the prompt in R it looks like this =options(prompt="ℝ> ")=,
> it is very simple.  It should be this simple for bable, too.
> 
> This change adds a user customizable variable for the prompt from user
> perspective `org-babel-R-command-primary-prompt'.  That variable is
> utilized in `org-babel-R-evaluate-session' where the full regular
> expression to match the prompt is constructed.  This makes it very
> easy to handle a custom prompt since from the R side of things, the
> value of `org-babel-R-command-primary-prompt' is the only thing that
> the user needs to know to set.  Via custom it looks like this
> '(org-babel-R-command-primary-prompt "ℝ>").
> 
> TINYCHANGE
> ---
>  lisp/ob-R.el | 6 ++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/lisp/ob-R.el b/lisp/ob-R.el
> index 41b943c..1cb675b 100644
> --- a/lisp/ob-R.el
> +++ b/lisp/ob-R.el
> @@ -87,6 +87,11 @@ this variable.")
>:version "24.1"
>:type 'string)
> 
> +(defcustom org-babel-R-command-primary-prompt ">"
> +  "User configurable portion of the primary prompt."
> +  :group 'org-babel
> +  :type 'string)
> +
>  (defvar ess-local-process-name) ; dynamically scoped
>  (defun org-babel-edit-prep:R (info)
>(let ((session (cdr (assoc :session (nth 2 info)
> @@ -413,6 +418,7 @@ last statement in BODY, as elisp."
>  (list body org-babel-R-eoe-indicator)
>  "\n"))
>   (inferior-ess-send-input)) "\n"
> +  (concat  "^\\([ ]*[" 
> org-babel-R-command-primary-prompt "+\\.][ ]?\\)+\\([[0-9]+\\|[ ]\\)") line)

I don’t think this does what you want it to: you’re inserting the
contents of the variable inside a regex character class (delimited by
[]).

See the patch I just sent
 for a different
approach.

-- 
Aaron Ecay



Re: [O] Proposal to replace the prefix repetition with whitespace during expansion of noweb references

2014-08-23 Thread Aaron Ecay
Hello,

2014ko abuztuak 18an, Sebastien Vauban-ek idatzi zuen:
> 
> Pierre-Henry FRÖHRING wrote:
>> I would like to back this proposition with our use case :
>> 
>> #+BEGIN_SRC js
>> REACTIVE_STATE = TYPE_BUILDER(
>> <>
>> , "reactive_state"
>> , <>
>> )
>> #+END_SRC
>> 
>> Where `<>` is expanded as expected,
>> and `, <>` is not, leading to `,  ` prefixing all
>> lines.
> 
> See https://lists.gnu.org/archive/html/emacs-orgmode/2014-03/msg01606.html
> for some context about that.
> 
> As I wrote, yes, I think it makes sense to do such a change.

FWIW, I also think the present behavior is too magical, and am in favor
of the proposed change.

-- 
Aaron Ecay



Re: [O] R code block produces only partial output

2014-08-23 Thread Andreas Kiermeier
Hi Aaron,
thanks for keeping on this.
I personally don't have a problem with requiring an R package.
In fact, users will have a rather limited experience with R if they cannot
install add-on packages (for whatever reason) - this is one of the things
that makes R such an attractive option for data analysis.
While there might be some IT departments that are very restrictive, I also
think (no data behind this) that the majority of our users are not in that
situation.
Anyway, that's my two cents worth.
​Cheers,
Andreas


On 23 August 2014 18:02, Aaron Ecay  wrote:

> 2014ko abuztuak 19an, Achim Gratz-ek idatzi zuen:
> >
> > Aaron Ecay writes:
> >> R is capable of installing packages to a user-specified directory,
> >> without requiring root or any other special privileges.  So IT cannot
> >> literally prevent R users from installing their own packages;
> >
> > They can, all they have to do is to take away the ability to connect to
> > the outside network and that's what is increasingly being done (for
> > other reasons, mind you).
> >
> >> the requirement must rather come as a statement of policy.
> >
> > That is another common thing, if only to shift the responsibility if the
> > other measures don't actually prevent that.
> >
> >> I’d like to
> >> understand more about how such regimes work and how org could work
> >> with them, ideally from people who have direct experience with them.
> >
> > Ideally, don't require the use of a non-core package.  The beef with
> > things like CTAN, CRAN or CPAN is that they require extra maintenance
> > beyond the pure installation of some software and some specific
> > knowledge of the software in question and that's just not going to
> > happen in some places.
> >
> >> Otherwise, it would be disappointing if the fear that an unidentifiable
> >> somebody somewhere might not be able to install R packages derailed the
> >> improvement of babel’s R support.
> >
> > The request was to keep a fallback to core.  I have no comment at this
> > time if it would be possible or not.  Since ultimately it's the session
> > support of Emacs that is clunky (and that affects most other languages
> > as well), maybe an effort to improve that would be more generally
> > helpful than working around it in different ways in each language.
>
> Well, I think that it’s going to be difficult to make babel a better
> literate programming solution for R if we restrict ourselves not to
> use the state-of-the-art R package for low-level literate programming
> support.  Org is full of features which one needs to install other
> software to use, and I’m comfortable with the idea that babel’s R
> support should require the evaluate package.  However, it’s difficult
> to argue this point of view when no one has spoken up about their own
> requirements, and a spirit of conservatism in the face of vague
> imagined difficulties persists.
>
> The attached patch fixes the problem that touched off this thread.
> It’s only debatably nicer than the present approach, but it has the
> independently desirable property of segregating babel-driven output
> from the session buffer.  It incorporates what I think is a fix for
> the tramp bug Charles pointed out.
>
> It’s as yet only lightly tested, and as always comments are welcome.
>
> --
> Aaron Ecay
>
>


Re: [O] babel: ob-C with Visual C++ and compilation-mode

2014-08-23 Thread Ernesto Durante
Eric Schulte  writes:

> Hi Ernesto,
>
> This looks like a good change and I'd like to apply it.  Could you
> re-submit this commit after doing the following.
>
> 1. ensure no lines go beyond 80 characters in length
> 2. remove all lines which include only closing parens
>(such lines are generally considered bad lisp style)
> 3. commit to your local git repository with "git commit"
> 4. format the patch with "git format-patch"
>
> Thanks,
> Eric
>

Hi Eric,

First, SORRY I didn't see you replay to my email (I am new to GNUS). Second, I 
would like
to thank you for this great environment which is Babel: original and
and extremly powerful.

Finally, I will follow your instruction and re-submit soon.

Best
Ernesto



Re: [O] [PATCH] ob-R.el: Add customizable R command primary prompt setting

2014-08-23 Thread Grant Rettke
Gotcha.

I wasn't tracking that thread. My desires was independent, I had just
wanted supported for a non-standard prompt because my source block
evaluation obviously quit working.

Good to know it is addressed!

Have a great day.
Grant Rettke | ACM, ASA, FSF, IEEE, SIAM
g...@wisdomandwonder.com | http://www.wisdomandwonder.com/
“Wisdom begins in wonder.” --Socrates
((λ (x) (x x)) (λ (x) (x x)))
“Life has become immeasurably better since I have been forced to stop
taking it seriously.” --Thompson


On Sat, Aug 23, 2014 at 3:34 AM, Aaron Ecay  wrote:
> Hi Grant,
>
> We have some discussion of realted issues in the thread that starts at
> .
>
> 2014ko abuztuak 22an, Grant Rettke-ek idatzi zuen:
>>
>>  list/ob-R.el (org-babel-R-command-primary-prompt,
>> org-babel-R-evaluate-session): Former adds customizable prompt value
>> the latter utilizes it.
>>
>> My R prompt looks like this "ℝ> ".  Babel needs to know more how to
>> handle various situations so the
>> regex used in `org-babel-R-evaluate-session' to identify the prompt
>> looks like this "^\\([ ]*[ℝ>+\\.][ ]?\\)+\\([[0-9]+\\|[ ]\\)".
>> It is required to handle various R prompt situations correctly.  It
>> may change over time to handle more situations.  The
>> user doesn't need to know about those details.  The user only cares
>> about the R prompt alone.  For example, when
>> they set the prompt in R it looks like this =options(prompt="ℝ> ")=,
>> it is very simple.  It should be this simple for bable, too.
>>
>> This change adds a user customizable variable for the prompt from user
>> perspective `org-babel-R-command-primary-prompt'.  That variable is
>> utilized in `org-babel-R-evaluate-session' where the full regular
>> expression to match the prompt is constructed.  This makes it very
>> easy to handle a custom prompt since from the R side of things, the
>> value of `org-babel-R-command-primary-prompt' is the only thing that
>> the user needs to know to set.  Via custom it looks like this
>> '(org-babel-R-command-primary-prompt "ℝ>").
>>
>> TINYCHANGE
>> ---
>>  lisp/ob-R.el | 6 ++
>>  1 file changed, 6 insertions(+)
>>
>> diff --git a/lisp/ob-R.el b/lisp/ob-R.el
>> index 41b943c..1cb675b 100644
>> --- a/lisp/ob-R.el
>> +++ b/lisp/ob-R.el
>> @@ -87,6 +87,11 @@ this variable.")
>>:version "24.1"
>>:type 'string)
>>
>> +(defcustom org-babel-R-command-primary-prompt ">"
>> +  "User configurable portion of the primary prompt."
>> +  :group 'org-babel
>> +  :type 'string)
>> +
>>  (defvar ess-local-process-name) ; dynamically scoped
>>  (defun org-babel-edit-prep:R (info)
>>(let ((session (cdr (assoc :session (nth 2 info)
>> @@ -413,6 +418,7 @@ last statement in BODY, as elisp."
>>  (list body org-babel-R-eoe-indicator)
>>  "\n"))
>>   (inferior-ess-send-input)) "\n"
>> +  (concat  "^\\([ ]*[" 
>> org-babel-R-command-primary-prompt "+\\.][ ]?\\)+\\([[0-9]+\\|[ ]\\)") line)
>
> I don’t think this does what you want it to: you’re inserting the
> contents of the variable inside a regex character class (delimited by
> []).
>
> See the patch I just sent
>  for a different
> approach.
>
> --
> Aaron Ecay



Re: [O] R code block produces only partial output

2014-08-23 Thread Aaron Ecay
Here’s another version of the previous patch which fixes a couple bugs
related to
1) changing the window configuration unwarrantedly
2) syntactically invalid R code (mismatched parens or quotes) could hang
   emacs

It’s easy to get R to throw an error in the mismatched-parens case, but
more difficult to recover from the mismatched-quotes one.  Thus, when
babel detects such a case it bails and signals a user-error in emacs.

(Under the present code in master, both the mismatched-parens and
mismatched-quotes cases hang emacs pending a manual C-g.)

The patch is now firmly into the territory of gross hacks, so I’d much
prefer the evaluate-based approach if it can be made palatable.

>From afa24835f2a170c59a044dcf3bcf0ee765e8b568 Mon Sep 17 00:00:00 2001
From: Aaron Ecay 
Date: Sat, 16 Aug 2014 00:49:05 -0400
Subject: [PATCH] ob-R: overhaul handling of :output results type in a session
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* (org-babel-R-evaluate-session): Capture output using ‘ess-execute’.

This function dumps the output from R into a buffer; we then use some
tricks to clean it of spurious text.
---
 lisp/ob-R.el | 69 
 1 file changed, 51 insertions(+), 18 deletions(-)

diff --git a/lisp/ob-R.el b/lisp/ob-R.el
index 41b943c..fbd4af4 100644
--- a/lisp/ob-R.el
+++ b/lisp/ob-R.el
@@ -364,9 +364,10 @@ last statement in BODY, as elisp."
 (output (org-babel-eval org-babel-R-command body
 
 (defvar ess-eval-visibly-p)
+(defvar ess-execute-in-process-buffer)
 
 (defun org-babel-R-evaluate-session
-  (session body result-type result-params column-names-p row-names-p)
+(session body result-type result-params column-names-p row-names-p)
   "Evaluate BODY in SESSION.
 If RESULT-TYPE equals 'output then return standard output as a
 string.  If RESULT-TYPE equals 'value then return the value of the
@@ -396,23 +397,55 @@ last statement in BODY, as elisp."
 	  (org-babel-import-elisp-from-file tmp-file '(16)))
 	column-names-p)))
 (output
- (mapconcat
-  'org-babel-chomp
-  (butlast
-   (delq nil
-	 (mapcar
-	  (lambda (line) (when (> (length line) 0) line))
-	  (mapcar
-	   (lambda (line) ;; cleanup extra prompts left in output
-		 (if (string-match
-		  "^\\([ ]*[>+\\.][ ]?\\)+\\([[0-9]+\\|[ ]\\)" line)
-		 (substring line (match-end 1))
-		   line))
-	   (org-babel-comint-with-output (session org-babel-R-eoe-output)
-		 (insert (mapconcat 'org-babel-chomp
-(list body org-babel-R-eoe-indicator)
-"\n"))
-		 (inferior-ess-send-input)) "\n"
+ (let* ((sentinel-file (org-babel-temp-file "R-")))
+   ;; This code borrowed from
+   ;; `org-babel-comint-eval-invisibly-and-wait-for-file'
+   (unless (org-babel-comint-buffer-livep session)
+	 (error "Buffer %s does not exist or has no process" session))
+   (if (file-exists-p sentinel-file) (delete-file sentinel-file))
+   (with-current-buffer session
+	 (let ((ess-execute-in-process-buffer nil)
+	   (temp-buffer-show-function #'ignore))
+	   (ess-execute (format
+			 "
+.org.old.opts <- options(prompt = \"# Org babel prompt\\n\", continue = \"# Org babel prompt\\n\")
+cat(\"# Org babel begin output\n\")
+{
+%s
+#ORG-BABEL-OOPS\"#'
+}
+cat(\"# Org babel end output\n\")
+options(.org.old.opts)
+rm(.org.old.opts)
+file.create(%S)
+"
+			 (org-babel-chomp body)
+			 (if (tramp-tramp-file-p sentinel-file)
+			 (tramp-file-name-localname
+			  (tramp-dissect-file-name sentinel-file))
+			   sentinel-file))
+			nil "org-babel-R-output"))
+	 ;; From Tramp 2.1.19 the following cache flush is not necessary
+	 (if (file-remote-p default-directory)
+	 (let (v)
+	   (with-parsed-tramp-file-name default-directory nil
+		 (tramp-flush-directory-property v "")
+   (while (not (file-exists-p sentinel-file)) (sit-for 0.25))
+   ;; End borrowed code.
+   (with-current-buffer "*org-babel-R-output*"
+	 (goto-char (point-min))
+	 (when (search-forward "ORG-BABEL-OOPS")
+	   (user-error "Mismatched quotation marks in babel code; could not parse output."))
+	 (search-forward "# Org babel begin output")
+	 (delete-region (point-min) (1+ (point)))
+	 (goto-char (point-max))
+	 (search-backward "# Org babel end output")
+	 (delete-region (point) (point-max))
+	 (goto-char (point-min))
+	 (flush-lines "^$")
+	 (flush-lines "^# Org babel prompt$")
+	 (delete-trailing-whitespace)
+	 (buffer-string))
 
 (defun org-babel-R-process-value-result (result column-names-p)
   "R-specific processing of return value.
-- 
2.0.4

-- 
Aaron Ecay


Re: [O] Only show in the agenda for today?

2014-08-23 Thread Fletcher Charest
Hi,

I think org-habit might correspond to your needs.

** TODO ditto beeb
SCHEDULED: <2014-08-22 Fri +1d>
:PROPERTIES:
:STYLE:habit
:END:

This should appear only today in the agenda.

Cheers,

FC


On Sat, Aug 23, 2014 at 10:12 AM, Sharon Kimble 
wrote:

> I have got several TODO's which are set to repeat after one day, like
> this one -
> --8<---cut here---start->8---
> ** TODO ditto beeb
> SCHEDULED: <2014-08-22 Fri +1d>
> --8<---cut here---end--->8---
>
> How can I get them to show in the agenda just for today only please, yet
> still retain their ability to repeat?
>
> Thanks
> Sharon.
> --
> A taste of linux = http://www.sharons.org.uk
> my git repo = https://bitbucket.org/boudiccas/dots
> TGmeds = http://www.tgmeds.org.uk
> Debian testing, fluxbox 1.3.5, emacs 24.3.93.1
>


Re: [O] R code block produces only partial output

2014-08-23 Thread Thomas S. Dye
Aaron Ecay  writes:

> Well, I think that it’s going to be difficult to make babel a better
> literate programming solution for R if we restrict ourselves not to
> use the state-of-the-art R package for low-level literate programming
> support.  Org is full of features which one needs to install other
> software to use, and I’m comfortable with the idea that babel’s R
> support should require the evaluate package.  However, it’s difficult
> to argue this point of view when no one has spoken up about their own
> requirements, and a spirit of conservatism in the face of vague
> imagined difficulties persists.

As a regular user of babel, including ob-R, I do want to see it mature
into a state-of-the-art, productive literate programming environment.
I've followed babel development for a long time and my sense is that
responsible experimentation is the norm, backed up by the ability to
revert commits that end up causing undue headaches.  If Aaron's good
work on ob-R raises howls of protest from users with restrictive IT
managers, or the evaluate package somehow becomes a pariah, then at some
point ob-R would have to drop the evaluate package requirement.  If not,
then the rest of us can enjoy the benefits of Aaron's labor (hopefully
on master and not as a series of patches, which are a real pain for us
non-programmer types to maintain).

My $0.02.

Tom

-- 
Thomas S. Dye
http://www.tsdye.com



Re: [O] R code block produces only partial output

2014-08-23 Thread Ista Zahn
On Sat, Aug 23, 2014 at 2:35 PM, Thomas S. Dye  wrote:
> Aaron Ecay  writes:
>
>> Well, I think that it’s going to be difficult to make babel a better
>> literate programming solution for R if we restrict ourselves not to
>> use the state-of-the-art R package for low-level literate programming
>> support.  Org is full of features which one needs to install other
>> software to use, and I’m comfortable with the idea that babel’s R
>> support should require the evaluate package.  However, it’s difficult
>> to argue this point of view when no one has spoken up about their own
>> requirements, and a spirit of conservatism in the face of vague
>> imagined difficulties persists.
>
> As a regular user of babel, including ob-R, I do want to see it mature
> into a state-of-the-art, productive literate programming environment.
> I've followed babel development for a long time and my sense is that
> responsible experimentation is the norm, backed up by the ability to
> revert commits that end up causing undue headaches.  If Aaron's good
> work on ob-R raises howls of protest from users with restrictive IT
> managers, or the evaluate package somehow becomes a pariah, then at some
> point ob-R would have to drop the evaluate package requirement.  If not,
> then the rest of us can enjoy the benefits of Aaron's labor (hopefully
> on master and not as a series of patches, which are a real pain for us
> non-programmer types to maintain).
>
> My $0.02.

+1.

R has considerable infrastructure to support litterarate programming,
and it makes little sense to avoid using it because a) some
hypothetical users will have difficulty installing the software or b)
because other languages supported by babel lack similar functionality.
We are currently missing out on some useful things available in other
literate programming systems for R, such as the ability to easily
return interleaved input and output, and I would really like to see R
support in babel take advantage of existing R features to provide a
first-class R literate programming environment.

Best,
Ista

>
> Tom
>
> --
> Thomas S. Dye
> http://www.tsdye.com
>



Re: [O] Only show in the agenda for today?

2014-08-23 Thread Sharon Kimble
Fletcher Charest  writes:

> Hi,
>
> I think org-habit might correspond to your needs.
>
> ** TODO ditto beeb
> SCHEDULED: <2014-08-22 Fri +1d>
> :PROPERTIES:
> :STYLE:    habit
> :END:
>
> This should appear only today in the agenda.
>
Thanks for this Fletcher.

It still appeared on every day, but I've found a way round it. Assign a
deadline to the task/TODO, which limits its display quite a lot and is
acceptable as there is quite a severe deadline for the majority of the
tasks - my new cooker coming next Friday morning! :)

Thanks
Sharon.

>
> On Sat, Aug 23, 2014 at 10:12 AM, Sharon Kimble  
> wrote:
>
> I have got several TODO's which are set to repeat after one day, like
> this one -
> --8<---cut here---start->8---
> ** TODO ditto beeb
> SCHEDULED: <2014-08-22 Fri +1d>
> --8<---cut here---end--->8---
>
> How can I get them to show in the agenda just for today only please, yet
> still retain their ability to repeat?
>
> Thanks
> Sharon.
-- 
A taste of linux = http://www.sharons.org.uk
my git repo = https://bitbucket.org/boudiccas/dots
TGmeds = http://www.tgmeds.org.uk
Debian testing, fluxbox 1.3.5, emacs 24.3.93.1


signature.asc
Description: PGP signature


Re: [O] [RFC] [PATCH] ox-latex: support :float no with caption for minted listings

2014-08-23 Thread Nicolas Goaziou
Hello,

Aaron Ecay  writes:

> * lisp/ox-latex.el (org-latex-src-block): Support :float no with
> caption for minted.
> (org-latex-listings): Edit docstring to describe this usecase.

There is already :float nil, which is documented in the manual.

> + (cond ((and (string= "no" float) caption)
> +(format "%%s\n%s" (replace-regexp-in-string
> +   "caption" "\\captionof{listing}"
> +   caption-str t t)))

I think this should be a (trivial) filter. Is there any reason to
support "captionof" package out of the box?


Regards,

-- 
Nicolas Goaziou



Re: [O] [RFC] [PATCH] ox-latex: support :float no with caption for minted listings

2014-08-23 Thread Aaron Ecay
Hi Nicolas,

2014ko abuztuak 23an, Nicolas Goaziou-ek idatzi zuen:
> 
> Hello,
> 
> Aaron Ecay  writes:
> 
>> * lisp/ox-latex.el (org-latex-src-block): Support :float no with
>> caption for minted.
>> (org-latex-listings): Edit docstring to describe this usecase.
> 
> There is already :float nil, which is documented in the manual.

You’re right – this was confusion on my part induced by babel header
args, which use yes and no instead of t and nil.  I’ll fix it.

> 
>> +(cond ((and (string= "no" float) caption)
>> +   (format "%%s\n%s" (replace-regexp-in-string
>> +  "caption" "\\captionof{listing}"
>> +  caption-str t t)))
> 
> I think this should be a (trivial) filter. Is there any reason to
> support "captionof" package out of the box?

It’s not adding any new functionality to the exporter, but rather
covering one particular combination of already-existing options (caption
provided, :float nil, org-latex-listings = minted) that does not produce
sensible output presently.  Should I fix the nil/no issue and send a new
patch?

Thanks for your feedback,

-- 
Aaron Ecay



[O] org-project or something like it?

2014-08-23 Thread John Kitchin
Hi all,

I have been mulling an idea in my mind on using a set of org-files as a
research notebook. We basically already do this, but what I was thinking
is how to define this set as a "project" or "notebook" that would have
its own (temporarily defined) set of org-agenda-files, with some
functionality like jumping to the most recent timestamp, or generating
an overall timeline, table of contents, etc... You would use a minor-mode to 
temporarily
set the org-agenda-files, for example.

does anything like this already exist? I am not to familiar with other
project-based tools, e.g. projectile. It seems to have some good
capabilities for project navigation, but not the org-capabilities I am
thinking of.

Is anyone already doing anything that sounds like this? Thanks,


-- 
---
John Kitchin
Professor




[O] narrow window, tag prompt partially obscured

2014-08-23 Thread Brady Trainor

I am using org-version 7.9.3f-17-g7524ef.

When the window is narrow, and I use C-c C-c to set tags in headline, 
the tag-selection prompt does not show all candidates.


Is there a way around this? I'm using a narrow org buffer to mirror my 
directory structure for visualization, and org tags is part of this 
workflow.





[O] orgtbl-to-latex creates enumerate environment

2014-08-23 Thread Robert McDonald
Radio tables creates a latex table including an enumerate environment,
which will not compile. This occurs if a numeric entry within the table
ends in a period. The problem does not occur without the period. It seems
possible that this is working as designed, but it is sure a surprise in
context.

Using org 8.2.4 (8/18/2014), here is a complete  example:





C-c C-c on the SEND line produces this:


\begin{tabular}{r}
\begin{enumerate}
\item
\end{enumerate} \\
\end{tabular}




Re: [O] [RFC] [PATCH] ox-latex: support :float no with caption for minted listings

2014-08-23 Thread Nicolas Goaziou
Aaron Ecay  writes:

> It’s not adding any new functionality to the exporter,

Well, it is, since "captionof" command doesn't exist in Org default
packages.

> but rather covering one particular combination of already-existing
> options (caption provided, :float nil, org-latex-listings = minted)
> that does not produce sensible output presently. Should I fix the
> nil/no issue and send a new patch?

With your patch, when encountering the combination above, the export
back-end will introduce a "captionof" command, which requires loading
"caption" package with a specific option (i.e., compatibility=false).

If this is explained nowhere, it is hardly a fix. If you document it,
you introduce support for "caption" package in Org. Is there a strong
reason for that?


Regards,

-- 
Nicolas Goaziou



Re: [O] R code block produces only partial output

2014-08-23 Thread Charles C. Berry


Aaron,

Some comments inline.

A patch that modifies what you have done is attached. Apart from adding 
`org-babel-local-file-name' in two places, I think it is functionally 
that same as yours, but I find the R code easier to follow.



On Sat, 16 Aug 2014, Aaron Ecay wrote:


Hi Chuck,

Thanks for your feedback.

2014ko abuztuak 16an, "Charles C. Berry"-ek idatzi zuen:

Aaron,

I think doing something along these lines makes sense. evaluate() obviates
the need for tryCatch() and capture.output(), and it makes customizing
error/warning/message stuff clean. Its use might also lead to cleaner code
for R graphics handling.

But adding a dependency on the evaluate package is a significant step.
This could be a nuisance for users whose code runs just fine right now. It
would need to be installed anywhere R is executed, e.g. in remote
sessions. The user would need to install it in her private directory if it
is not on the system; some shops actually discourage this.

   ^^^

That’s ... special.  Do you have experience with such environments?


Not really. Just seen complaints...





So, making it optional might be necessary.


I don’t like this idea; it means that we’d have to support the old,
hacky way of doing things indefinitely.  I’d like to hear more from
people for whom local installation of R packages creates an issue.



The old hacky way works pretty well most of the time. I suspect that it 
will be hard to get folks to really test a new ob-R.el in advance of its 
moving to maint. ./lisp/test-ob-R.el only has one :session src block and 
a few other src blocks...


I was thinking of having a drop in replacement for the each of the two 
functions that are changed and maybe selecting which version to use with 
defalias. If there is a slicker way to enable a user to revert to an 
earlier version without having good git skills, fine. But I think the 
possibility of breaking something that someone needs and not noticing till 
the changes go to maint is high.




---

I looked at the patch briefly. Some comments:

- You can ditch tryCatch and capture.output. You might browse
   knitr:::block_exec to see how it uses evaluate().


I’m not sure I see what you mean.  The tryCatch exists to ensure that
the sentinel file is created, to signal emacs that the R code is done
running.  It might not be strictly necessary, as long as the rest of
babel’s injected code is error-free (evaluate takes care of catching
errors in user code).  But emacs will busy-wait indefinitely if the
creation of that file does not happen, so I have tried to play it safe.



Not sure I get why the sentinel file is needed, but the patch here uses 
on.exit(file.create(...)) to ensure that that file is created. One hiccup 
(not sure if it exists in master,too) is that starting a remote session 
and then trying to run src blocks from a buffer for a local file will hang 
(because a local temp file is used for sentinel). So there is still stuff 
to do.



As for capture.output, the knitr function you reference is doing a lot
of heavy lifting; I don’t understand it all.  I just need to get the
result of evaluate() into a file somehow.  There are other ways of doing
this than capture.output + replay, but it seems like they’d be just as
complicated.


After looking more at evaluate and that knitr function, I am not keen to 
replace replay() to obviate sink() or capture.output(). I had thought that 
the output_handler arg offered more potential that it actually does. If 
you ever feel the need to revise how graphics handling is done, it might 
be worth working thru what Yihui does there.






- Wrap the code in local() to keep objects you create from persisting
   where they might not be wanted. I think using
local({ res <- evaluate(input, envir=parent.frame(2),...); <...>})
   will get assignments from `input' properly placed.


I omitted to rm() .org.eval.result for debugging purposes, but in the
final patch I will do so.  I much prefer an explicit variable creation /
rm() to environment-hacking.



Putting objects in userspace is considered poor practice. FWIW, CRAN 
disallows it. `environment-hacking' as you call it underlies much of R. If 
you must create and hold variables use the attach(NULL,name="org-vars") 
trick.





- let stop_on_error, keep_warning, and keep_message args be customizable
   or depend on a header arg. (Then I can stop wrapping require() in
   suppressPackageStartupMessages() which I always misspell. Argh!)


I don’t like this, since it would not carry over to the other 3/4
cases (value results in a session; either type of result outside of a
session).  I’d like to get this patch working first, and then focus on
the others.  It may be that we want to move to using the evaluate
package in all cases, in which case this suggestion would be workable.


Fair enough.

Best,

ChuckFrom e51c092cc455f9deee8d3d5b413493aff84b38c3 Mon Sep 17 00:00:00 2001
From: chasberry 
Da

Re: [O] [RFC] [PATCH] ox-latex: support :float no with caption for minted listings

2014-08-23 Thread Aaron Ecay
Hi Nicolas,

2014ko abuztuak 23an, Nicolas Goaziou-ek idatzi zuen:
> 
> Aaron Ecay  writes:
> 
>> It’s not adding any new functionality to the exporter,
> 
> Well, it is, since "captionof" command doesn't exist in Org default
> packages.

I guess this was unclear.  What I meant was that the patch is not
introducing any new expressivity on the org-mode side.  There is a
situation (described in my previous mail) that is a valid combination of
org configuration variables and buffer text, which produces inconsistent
latex output.  This patch fixes that.

> 
>> but rather covering one particular combination of already-existing
>> options (caption provided, :float nil, org-latex-listings = minted)
>> that does not produce sensible output presently. Should I fix the
>> nil/no issue and send a new patch?
> 
> With your patch, when encountering the combination above, the export
> back-end will introduce a "captionof" command, which requires loading
> "caption" package with a specific option (i.e., compatibility=false).

Why is the compatibility=false option needed?  I can’t figure this
out.

> 
> If this is explained nowhere, it is hardly a fix. If you document it,
> you introduce support for "caption" package in Org. Is there a strong
> reason for that?

“Pretty” source code export in all cases requires adding certain packages
to the default, as explained in the docstring of ‘org-latex-listings’.
The patch adds discussion of the caption requirement there, so there is
no “if” about the documentation.

I don’t understand what you’re saying about introducing “support” for
the caption package.  The patch uses one specific feature of the caption
package in one specific place to accomplish one specific goal.  There
are no other changes needed anywhere else in the codebase than these
couple of lines in one function (plus the documentation).

The motivating reason is described in my first paragraph above – making
the output consistent for all combinations of options.

Thanks,

-- 
Aaron Ecay



Re: [O] Running Node.js and exporting css.

2014-08-23 Thread Eric Schulte
Josh Berry  writes:

> Couple of weeks ago, I accidentally spammed the message board with several
> attempts to send up a couple of patches for some problems I was seeing.
>  So, firstly, apologies for the spam.
>
> The two problems I was seeing were related to executing js using node.js,
> and exporting css with vendor properties.
>
> The node.js problem is that it will start putting in newlines if a
> structure is past some size.  I think this may be "fixable" by changing
> some settings in node.js, but it was also easy enough to change the regex
> to look past newlines in org.  An example of the problem can be seen by
> running the following
>
>   #+BEGIN_SRC js
> return [[1, 2],[1, 2],[1, 2],[1, 2],[1, 2],[1, 2],[1,2]]
>   #+END_SRC
>
>
> If you remove just one of the inner arrays, it will work as desired.
>

Thanks for the report Josh, I just pushed up an improved regexp for the
parsing of multi-line js results.

Best -- Eric

>
> The other problem is just as short.  Simply export the following when
> you have org-src-fontify-natively set.
>
>   #+BEGIN_SRC css
> foo {
>   -webkit-appearance: none;
> }
>   #+END_SRC
>
> I cobbled a small change that seemed to fix that.
>
> At any rate, again apologies for the previous spam.  I didn't want to just
> respam immediately with an apology.
>
> Thanks!
>
> --
> josh
>

-- 
Eric Schulte
https://cs.unm.edu/~eschulte
PGP: 0x614CA05D (see https://u.fsf.org/yw)



Re: [O] [RFC] [PATCH] ox-latex: support :float no with caption for minted listings

2014-08-23 Thread Nicolas Richard
Aaron Ecay  writes:

>> With your patch, when encountering the combination above, the export
>> back-end will introduce a "captionof" command, which requires loading
>> "caption" package with a specific option (i.e., compatibility=false).
>
> Why is the compatibility=false option needed?  I can’t figure this
> out.

I didn't read the rest of this thread, but if all we need is \captionof,
please use the capt-of package instead. It'll avoid compatibility issues
with other classes/packages a user might load.

-- 
Nico.