emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* How to execute org babel src block  line by line?
@ 2016-04-18  8:44 Xor3
  2016-04-19 19:05 ` Eduardo Ochs
  0 siblings, 1 reply; 2+ messages in thread
From: Xor3 @ 2016-04-18  8:44 UTC (permalink / raw)
  To: emacs-orgmode

Hi community,
   I want to execute org babel src block one line a time. 
   Here is what I have tried.
   I use `isend' to send things to REPL buffer. When "C-<return>"  is pressed at first time,  a REPL buffer which is decided by  `lang' params  is startd. Then everything send to that buffer. An additional param `:dir' is configured to decide the starting `default-directry' of the REPL command.  
  
=================================================
(eval-after-load "org"
      '(progn
        ;; ;; (org-defkey org-mode-map (kbd "C-<return>") 'org-isend-send)
        (define-key org-mode-map (kbd "C-<return>") 'org-isend-send)

        (defun org-isend-send()
          (interactive)
          (let* ((oldbuf (current-buffer))
                 (info (org-babel-get-src-block-info))
                 (lang (nth 0 info))
                 (body (nth 1 info))
                 (params (nth 2 info))
                 (session (cdr (assoc :session params)))
                 (dir (cdr (assoc :dir params)))
                 (isend--command-buffer (concat "*" session "*"))
                 (working-directory
                  (or (and dir (file-name-as-directory dir)) default-directory)))
            (when  (not (get-buffer isend--command-buffer))
              (cond
               ((string-equal lang "python") (save-current-buffer
                                               (let ((default-directory working-directory))
                                                 (call-interactively 'run-python)
                                                 (with-current-buffer "*Python*"
                                                   (rename-buffer isend--command-buffer)))))
               ((string-equal lang "sh") (save-current-buffer
                                           (let ((default-directory working-directory))
                                             (if (string-equal session "eshell")
                                                 (eshell)
                                               (progn
                                                 (shell)
                                                 (with-current-buffer "*shell*"
                                                   (rename-buffer isend--command-buffer)))))))
               (t (error "session?")))
              (require 'isend)
              (require 'isend-mode)
              (when (not isend-mode)
                (isend-mode 1)
                (make-local-variable 'isend-mode-map)
                (define-key isend-mode-map (kbd "C-<return>") nil)
                (local-set-key (kbd "C-<return>") 'org-isend-send))
              (cond
               ((string-equal lang "python") (isend-ipython-setup))
               (t (isend-shell-setup)))
              )
            ;; (display-buffer isend--command-buffer)
            (isend-display-buffer)
            (call-interactively 'isend-send)
            ;; (with-current-buffer isend--command-buffer
            ;;   (goto-char (point-max))
            ;;   (comint-send-input)
            ;;   (funcall (key-binding (kbd "RET")))
            ;;   )
            ))))
  ========================================

  I want to execute my shells/python/ruby scirpts  this way by writing out them first, then `C-<return>' doing the rest.

  Does anyone know a better or more native `org' way to do this?
  Thank you for your help.

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

end of thread, other threads:[~2016-04-19 19:05 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-04-18  8:44 How to execute org babel src block line by line? Xor3
2016-04-19 19:05 ` Eduardo Ochs

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).