emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] ob-R.el: Add customizable R command primary prompt setting
@ 2014-08-23  1:30 Grant Rettke
  2014-08-23  8:34 ` Aaron Ecay
  0 siblings, 1 reply; 3+ messages in thread
From: Grant Rettke @ 2014-08-23  1:30 UTC (permalink / raw)
  To: emacs-orgmode@gnu.org

[-- Attachment #1: Type: text/plain, Size: 2264 bytes --]

 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)

 (defun org-babel-R-process-value-result (result column-names-p)
   "R-specific processing of return value.
--
1.9.2

[-- Attachment #2: 0001-ob-R.el-Add-customizable-R-command-primary-prompt-se.patch --]
[-- Type: application/octet-stream, Size: 2543 bytes --]

From f78dc8c0e48b9a77835d3611b4d15ab92f191177 Mon Sep 17 00:00:00 2001
From: Grant Rettke <gcr@wisdomandwonder.com>
Date: Fri, 22 Aug 2014 20:27:16 -0500
Subject: [PATCH] ob-R.el: Add customizable R command primary prompt setting
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* 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)
 
 (defun org-babel-R-process-value-result (result column-names-p)
   "R-specific processing of return value.
-- 
1.9.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] ob-R.el: Add customizable R command primary prompt setting
  2014-08-23  1:30 [PATCH] ob-R.el: Add customizable R command primary prompt setting Grant Rettke
@ 2014-08-23  8:34 ` Aaron Ecay
  2014-08-23 13:52   ` Grant Rettke
  0 siblings, 1 reply; 3+ messages in thread
From: Aaron Ecay @ 2014-08-23  8:34 UTC (permalink / raw)
  To: Grant Rettke, emacs-orgmode@gnu.org

Hi Grant,

We have some discussion of realted issues in the thread that starts at
<http://mid.gmane.org/CAN7vk5R+2DHRajUR8+NdmWSpLhjtodrdjXOO0v027cjHY7gFxw@mail.gmail.com>.

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
<http://mid.gmane.org/871ts7r4ho.fsf@gmail.com> for a different
approach.

-- 
Aaron Ecay

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] ob-R.el: Add customizable R command primary prompt setting
  2014-08-23  8:34 ` Aaron Ecay
@ 2014-08-23 13:52   ` Grant Rettke
  0 siblings, 0 replies; 3+ messages in thread
From: Grant Rettke @ 2014-08-23 13:52 UTC (permalink / raw)
  To: Grant Rettke, emacs-orgmode@gnu.org

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
gcr@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 <aaronecay@gmail.com> wrote:
> Hi Grant,
>
> We have some discussion of realted issues in the thread that starts at
> <http://mid.gmane.org/CAN7vk5R+2DHRajUR8+NdmWSpLhjtodrdjXOO0v027cjHY7gFxw@mail.gmail.com>.
>
> 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
> <http://mid.gmane.org/871ts7r4ho.fsf@gmail.com> for a different
> approach.
>
> --
> Aaron Ecay

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-08-23 13:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-23  1:30 [PATCH] ob-R.el: Add customizable R command primary prompt setting Grant Rettke
2014-08-23  8:34 ` Aaron Ecay
2014-08-23 13:52   ` Grant Rettke

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).