From mboxrd@z Thu Jan 1 00:00:00 1970 From: Michael Sperber Subject: Re: Xemacs incompatibilities Date: Mon, 24 May 2010 16:22:50 +0200 Message-ID: References: <7z632uzu5k.fsf@vzell-de.de.oracle.com> <21F52756-A6A2-4D14-B5F2-DE2B0A4714D8@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from [140.186.70.92] (port=38606 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OGYYU-0003T4-AR for emacs-orgmode@gnu.org; Mon, 24 May 2010 10:22:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OGYYR-0000wC-Ep for emacs-orgmode@gnu.org; Mon, 24 May 2010 10:22:58 -0400 Received: from h615406.serverkompetenz.net ([81.169.143.132]:56215) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OGYYQ-0000vm-Qt for emacs-orgmode@gnu.org; Mon, 24 May 2010 10:22:55 -0400 In-Reply-To: <21F52756-A6A2-4D14-B5F2-DE2B0A4714D8@gmail.com> (Carsten Dominik's message of "Mon, 17 May 2010 16:46:55 +0200") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Carsten Dominik Cc: Dan Davison , mailing-list-org-mode Mode , "Dr. Volker Zell" --=-=-= Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable Carsten Dominik 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. --=20 Cheers =3D8-} Mike Friede, V=F6lkerverst=E4ndigung und =FCberhaupt blabla --=-=-= Content-Disposition: inline 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))) --=-=-= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ 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 --=-=-=--