emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Michael Sperber <sperber@deinprogramm.de>
To: Carsten Dominik <carsten.dominik@gmail.com>
Cc: Dan Davison <davison@stats.ox.ac.uk>,
	mailing-list-org-mode Mode <emacs-orgmode@gnu.org>,
	"Dr. Volker Zell" <Dr.Volker.Zell@oracle.com>
Subject: Re: Xemacs incompatibilities
Date: Mon, 24 May 2010 16:22:50 +0200	[thread overview]
Message-ID: <y9leih1idl1.fsf@deinprogramm.de> (raw)
In-Reply-To: <21F52756-A6A2-4D14-B5F2-DE2B0A4714D8@gmail.com> (Carsten Dominik's message of "Mon, 17 May 2010 16:46:55 +0200")

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


Carsten Dominik <carsten.dominik@gmail.com> writes:

> On May 17, 2010, at 4:39 PM, Michael Sperber wrote:
>
>> In particular, fixing the require won't be enough: org-babel-python.el
>> uses `run-python' and interacts with the inferior Python, whereas
>> python-mode.el defines `py-shell'.
>>
>> Should I try to abstract over the differences?
>
> Yes, this would be much appreciated. (I think, Eric or Dan?)

OK, I've attached a patch that makes `org-babel-python' work on XEmacs.
Most of the issues are pure XEmacs issues.  Notes:

- XEmacs doesn't have [[:digit:]] - I hope to rectify this in the
  future, but it seems there's no downside in this particular case to
  replacing by [0-9].
- XEmacs doesn't have `move-end-of-line', but does have `end-of-line'.
  I don't understand the intent of having both of these, but the code
  seems fine with `end-of-line'.
- It seems there are way too few `require's throughout org-babel.  I
  don't know if it's OK to add the ones I needed.
- `org-babel-python-evaluate' looked broken as-is: It doesn't use the
  `body' argument properly, the result is (I think) processed in the
  wrong order and not properly split into lines.  I've fixed all these,
  but a review is probably in order.

-- 
Cheers =8-} Mike
Friede, Völkerverständigung und überhaupt blabla

[-- Attachment #2: Type: text/plain, Size: 12385 bytes --]

diff --git a/contrib/babel/lisp/langs/org-babel-R.el b/contrib/babel/lisp/langs/org-babel-R.el
index 289c73d..c1dd67a 100644
--- a/contrib/babel/lisp/langs/org-babel-R.el
+++ b/contrib/babel/lisp/langs/org-babel-R.el
@@ -89,7 +89,7 @@ called by `org-babel-execute-src-block'."
 	   vars)))
     (org-babel-comint-in-buffer session
       (mapc (lambda (var)
-              (move-end-of-line 1) (insert var) (comint-send-input nil t)
+              (end-of-line 1) (insert var) (comint-send-input nil t)
               (org-babel-comint-wait-for-output session)) var-lines))
     session))
 
diff --git a/contrib/babel/lisp/langs/org-babel-octave.el b/contrib/babel/lisp/langs/org-babel-octave.el
index 41a5be6..6cb244f 100644
--- a/contrib/babel/lisp/langs/org-babel-octave.el
+++ b/contrib/babel/lisp/langs/org-babel-octave.el
@@ -92,7 +92,7 @@ specifying a variable of the same value."
                      vars)))
     (org-babel-comint-in-buffer session
       (mapc (lambda (var)
-              (move-end-of-line 1) (insert var) (comint-send-input nil t)
+              (end-of-line 1) (insert var) (comint-send-input nil t)
               (org-babel-comint-wait-for-output session)) var-lines))
     session))
 
diff --git a/contrib/babel/lisp/langs/org-babel-python.el b/contrib/babel/lisp/langs/org-babel-python.el
index ea2a217..6c8e5de 100644
--- a/contrib/babel/lisp/langs/org-babel-python.el
+++ b/contrib/babel/lisp/langs/org-babel-python.el
@@ -30,6 +30,8 @@
 
 ;;; Code:
 (require 'org-babel)
+(require 'org-babel-tangle)
+(require 'org-babel-comint)
 (require (if (featurep 'xemacs) 'python-mode 'python))
 
 (org-babel-add-interpreter "python")
@@ -75,7 +77,7 @@ called by `org-babel-execute-src-block'."
                      vars)))
     (org-babel-comint-in-buffer session
       (mapc (lambda (var)
-              (move-end-of-line 1) (insert var) (comint-send-input nil t)
+              (end-of-line 1) (insert var) (comint-send-input)
               (org-babel-comint-wait-for-output session)) var-lines))
     session))
 
@@ -123,7 +125,21 @@ then create.  Return the initialized session."
   (save-window-excursion
     (let* ((session (if session (intern session) :default))
            (python-buffer (org-babel-python-session-buffer session)))
-      (run-python)
+      (cond
+       ((fboundp 'run-python) ; python.el
+	(run-python))
+       ((fboundp 'py-shell) ; python-mode.el
+	;; `py-shell' creates a buffer whose name is the value of
+	;; `py-which-bufname' with '*'s at the beginning and end
+	(let* ((bufname (if python-buffer
+			    (replace-regexp-in-string "^\\*\\([^*]+\\)\\*$" "\\1" python-buffer) ; zap surrounding *
+			  (concat "Python-" (symbol-name session))))
+	       (py-which-bufname bufname)) ; avoid making a mess with buffer-local
+	  (py-shell)
+	  (setq python-buffer (concat "*" bufname "*"))))
+       (t
+	(error "No function available for running an inferior python.")))
+	
       (setq org-babel-python-buffers (cons (cons session python-buffer)
 					   (assq-delete-all session org-babel-python-buffers)))
       session)))
@@ -200,19 +216,24 @@ last statement in BODY, as elisp."
     (org-babel-comint-in-buffer buffer
       (let* ((raw (org-babel-comint-with-output buffer org-babel-python-eoe-indicator t
                     ;; for some reason python is fussy, and likes enters after every input
-                    (mapc (lambda (statement) (insert statement) (comint-send-input nil t))
-                          (split-string (org-babel-trim full-body) "[\r\n]+"))
-                    (comint-send-input nil t) (comint-send-input nil t)
-                    (if (member "pp" result-params)
-                        (mapc (lambda (statement) (insert statement) (comint-send-input nil t))
-                              org-babel-python-pp-last-value-eval)
-                      (insert org-babel-python-last-value-eval))
-                    (comint-send-input nil t) (comint-send-input nil t)
-                    (insert org-babel-python-eoe-indicator)
-                    (comint-send-input nil t)))
+		    (let ((comint-process-echoes nil))
+		      (mapc (lambda (statement) (insert statement) (comint-send-input))
+			    (split-string (org-babel-trim body) "[\r\n]+"))
+		      (comint-send-input) (comint-send-input)
+		      (if (member "pp" result-params)
+			  (mapc (lambda (statement) (insert statement) (comint-send-input))
+				org-babel-python-pp-last-value-eval)
+			(insert org-babel-python-last-value-eval))
+		      (comint-send-input) (comint-send-input)
+		      (insert org-babel-python-eoe-indicator)
+		      (comint-send-input))))
+	     (raw (apply #'append ; split further
+			 (mapcar #'(lambda (r)
+				     (split-string r "[\r\n]+"))
+				 raw)))
              (results (delete org-babel-python-eoe-indicator
                               (cdr (member org-babel-python-eoe-indicator
-                                           (reverse (mapcar #'org-babel-trim raw)))))))
+                                           (mapcar #'org-babel-trim raw))))))
         (unless (or (member "code" result-params) (member "pp" result-params))
           (setq results (mapcar #'org-babel-python-read-string results)))
         (case result-type
diff --git a/contrib/babel/lisp/org-babel-lob.el b/contrib/babel/lisp/org-babel-lob.el
index 866585c..7bdca5d 100644
--- a/contrib/babel/lisp/org-babel-lob.el
+++ b/contrib/babel/lisp/org-babel-lob.el
@@ -90,7 +90,7 @@ should be renamed to bring out this similarity, perhaps involving
 the word 'call'."
   (let ((case-fold-search t))
     (save-excursion
-      (move-beginning-of-line 1)
+      (beginning-of-line 1)
       (if (looking-at org-babel-lob-one-liner-regexp)
           (mapcar #'org-babel-clean-text-properties 
 		  (list (format "%s(%s)" (match-string 1) (match-string 2))
diff --git a/contrib/babel/lisp/org-babel-tangle.el b/contrib/babel/lisp/org-babel-tangle.el
index e2aa44a..c86e6f8 100644
--- a/contrib/babel/lisp/org-babel-tangle.el
+++ b/contrib/babel/lisp/org-babel-tangle.el
@@ -158,8 +158,8 @@ references."
   (goto-char (point-min))
   (while (or (re-search-forward "\\[\\[file:.*\\]\\[.*\\]\\]" nil t)
              (re-search-forward "<<[^[:space:]]*>>" nil t))
-    (delete-region (save-excursion (move-beginning-of-line 1) (point))
-                   (save-excursion (move-end-of-line 1) (forward-char 1) (point)))))
+    (delete-region (save-excursion (beginning-of-line 1) (point))
+                   (save-excursion (end-of-line 1) (forward-char 1) (point)))))
 
 (defun org-babel-tangle-collect-blocks (&optional lang)
   "Collect all source blocks in the current org-mode file.
@@ -219,7 +219,7 @@ form
                          (when commentable
                            (insert "\n")
                            (comment-region (point) (progn (insert text) (point)))
-                           (move-end-of-line nil)
+                           (end-of-line nil)
                            (insert "\n"))))
     (let ((link (first spec))
           (source-name (second spec))
diff --git a/contrib/babel/lisp/org-babel.el b/contrib/babel/lisp/org-babel.el
index d4313b2..ce753b4 100644
--- a/contrib/babel/lisp/org-babel.el
+++ b/contrib/babel/lisp/org-babel.el
@@ -246,7 +246,7 @@ block."
           (if (and (not arg) new-hash (equal new-hash old-hash))
               (save-excursion ;; return cached result
                 (goto-char (org-babel-where-is-src-block-result nil info))
-                (move-end-of-line 1) (forward-char 1)
+                (end-of-line 1) (forward-char 1)
                 (setq result (org-babel-read-result))
                 (message (replace-regexp-in-string "%" "%%"
                                                    (format "%S" result))) result)
@@ -305,7 +305,7 @@ session.  After loading the body this pops open the session."
     (pop-to-buffer
      (funcall (intern (concat "org-babel-load-session:" lang))
               session body params))
-    (move-end-of-line 1)))
+    (end-of-line 1)))
 
 (defun org-babel-switch-to-session (&optional arg info)
   "Switch to the session of the current source-code block.
@@ -333,7 +333,7 @@ of the source block to the kill ring."
     (pop-to-buffer
      (funcall (intern (format "org-babel-%s-initiate-session" lang))
               session params))
-    (move-end-of-line 1)))
+    (end-of-line 1)))
 
 (defalias 'org-babel-pop-to-session 'org-babel-switch-to-session)
 
@@ -349,7 +349,7 @@ results already exist."
       (goto-char (or (and (not re-run) (org-babel-where-is-src-block-result))
                      (progn (org-babel-execute-src-block)
                             (org-babel-where-is-src-block-result))))
-      (move-end-of-line 1) (forward-char 1)
+      (end-of-line 1) (forward-char 1)
       ;; open the results
       (if (looking-at org-bracket-link-regexp)
           ;; file results
@@ -766,8 +766,8 @@ If the point is not on a source block then return nil."
         (re-search-backward "^[ \t]*#\\+begin_src" nil t) (setq top (point))
         (re-search-forward "^[ \t]*#\\+end_src" nil t) (setq bottom (point))
         (< top initial) (< initial bottom)
-        (goto-char top) (move-beginning-of-line 1)
-        (looking-at org-babel-src-block-regexp)
+        (progn (goto-char top) (beginning-of-line 1)
+	       (looking-at org-babel-src-block-regexp))
         (point))))))
 
 (defun org-babel-goto-named-source-block (&optional name)
@@ -800,7 +800,7 @@ buffer or nil if no such result exists."
     (when (re-search-forward
            (concat org-babel-result-regexp
                    "[ \t]" (regexp-quote name) "[ \t\n\f\v\r]") nil t)
-      (move-beginning-of-line 0) (point))))
+      (beginning-of-line 0) (point))))
 
 (defun org-babel-where-is-src-block-result (&optional insert info hash)
   "Return the point at the beginning of the result of the current
@@ -816,13 +816,13 @@ following the source block."
       (when head (goto-char head))
       (or (and name (org-babel-find-named-result name))
           (and (or on-lob-line (re-search-forward "^[ \t]*#\\+end_src" nil t))
-               (progn (move-end-of-line 1)
+               (progn (end-of-line 1)
 		      (if (eobp) (insert "\n") (forward-char 1))
 		      (setq end (point))
                       (or (and (not name)
 			       (progn ;; unnamed results line already exists
 				 (re-search-forward "[^ \f\t\n\r\v]" nil t)
-				 (move-beginning-of-line 1)
+				 (beginning-of-line 1)
                                  (looking-at
                                   (concat org-babel-result-regexp "\n"))))
 			  ;; or (with optional insert) back up and
@@ -835,7 +835,7 @@ following the source block."
                                             (when hash (concat "["hash"]"))
                                             ":"
                                             (when name (concat " " name)) "\n"))
-                            (move-beginning-of-line 0)
+                            (beginning-of-line 0)
                             (if hash (org-babel-hide-hash)) t)))
                (point))))))
 
@@ -1035,7 +1035,7 @@ directory then expand relative links."
 	    ((< size org-babel-min-lines-for-block-output)
 	     (goto-char beg)
 	     (dotimes (n size)
-	       (move-beginning-of-line 1) (insert ": ") (forward-line 1)))
+	       (beginning-of-line 1) (insert ": ") (forward-line 1)))
 	    (t
 	     (goto-char beg)
 	     (insert (if results-switches
@@ -1192,7 +1192,7 @@ block but are passed literally to the \"example-block\"."
             (setq prefix
                   (buffer-substring (match-beginning 0)
                                     (save-excursion
-                                      (move-beginning-of-line 1) (point)))))
+                                      (beginning-of-line 1) (point)))))
           ;; add interval to new-body (removing noweb reference)
           (goto-char (match-beginning 0))
           (nb-add (buffer-substring index (point)))
@@ -1260,7 +1260,7 @@ This is taken almost directly from `org-read-prop'."
 
 (defun org-babel-number-p (string)
   "Return t if STRING represents a number"
-  (if (and (string-match "^-?[[:digit:]]*\\.?[[:digit:]]*$" string)
+  (if (and (string-match "^-?[0-9]*\\.?[0-9]*$" string)
            (= (match-end 0) (length string)))
       (string-to-number string)))
 

[-- Attachment #3: Type: text/plain, Size: 201 bytes --]

_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

  parent reply	other threads:[~2010-05-24 14:22 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-11  9:04 Xemacs incompatibilities Dr. Volker Zell
2010-05-14 12:40 ` Carsten Dominik
2010-05-15 10:09   ` Leo
2010-05-17 14:39   ` Michael Sperber
2010-05-17 14:46     ` Carsten Dominik
2010-05-17 18:47       ` Dan Davison
2010-05-20  2:41         ` Dan Davison
2010-05-24 14:22       ` Michael Sperber [this message]
2010-05-20 16:31     ` Dr. Volker Zell
2010-05-24  8:39       ` PATCH: " Michael Sperber
2010-05-24 13:23         ` Dan Davison
2010-05-24  8:41       ` PATCH: Fix minor XEmacs compatibility issue Michael Sperber

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

  List information: https://www.orgmode.org/

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

  git send-email \
    --in-reply-to=y9leih1idl1.fsf@deinprogramm.de \
    --to=sperber@deinprogramm.de \
    --cc=Dr.Volker.Zell@oracle.com \
    --cc=carsten.dominik@gmail.com \
    --cc=davison@stats.ox.ac.uk \
    --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 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).