summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Davison <davison@stats.ox.ac.uk>2010-08-16 20:55:24 -0400
committerDan Davison <davison@stats.ox.ac.uk>2010-08-17 17:32:23 -0400
commitb61e0c4dfc1176d2745368e728f1cbf3e5cfede3 (patch)
tree841c96013fa091f78e0de8f766cce5aa4adf2c74
parentb05f8c91fed5d743adf5df787f2b28fb58274bf5 (diff)
downloadorg-mode-b61e0c4dfc1176d2745368e728f1cbf3e5cfede3.tar.gz
Associate code edit buffer with babel comint session, if one exists.
* org-src.el (org-edit-src-code): If at src block, store babel info as buffer local variable. (org-src-associate-babel-session): New function to associate code edit buffer with comint session. Does nothing unless a language-specific function named `org-babel-LANG-associate-session' exists. (org-src-babel-configure-edit-buffer): New function to be called in `org-src-mode-hook'. (org-src-mode-hook): add `org-src-babel-configure-edit-buffer' to hook.
-rw-r--r--lisp/org-src.el19
1 files changed, 19 insertions, 0 deletions
diff --git a/lisp/org-src.el b/lisp/org-src.el
index baa2b11..e029bf3 100644
--- a/lisp/org-src.el
+++ b/lisp/org-src.el
@@ -203,6 +203,7 @@ the edited version. Optional argument CONTEXT is used by
(col (current-column))
(case-fold-search t)
(info (org-edit-src-find-region-and-lang))
+ (babel-info (org-babel-get-src-block-info))
(org-mode-p (eq major-mode 'org-mode))
(beg (make-marker))
(end (make-marker))
@@ -272,6 +273,8 @@ the edited version. Optional argument CONTEXT is used by
(set (make-local-variable 'org-edit-src-from-org-mode) org-mode-p)
(set (make-local-variable 'org-edit-src-allow-write-back-p) allow-write-back-p)
(set (make-local-variable 'org-src-preserve-indentation) preserve-indentation)
+ (when babel-info
+ (set (make-local-variable 'org-src-babel-info) babel-info))
(when lfmt
(set (make-local-variable 'org-coderef-label-format) lfmt))
(when org-mode-p
@@ -654,6 +657,22 @@ the language, a switch telling if the content should be in a single line."
(org-add-hook 'org-src-mode-hook 'org-src-mode-configure-edit-buffer)
+
+(defun org-src-associate-babel-session (info)
+ "Associate edit buffer with comint session."
+ (interactive)
+ (let ((session (cdr (assoc :session (nth 2 info)))))
+ (and session (not (string= session "none"))
+ (org-babel-comint-buffer-livep session)
+ ((lambda (f) (and (fboundp f) (funcall f session)))
+ (intern (format "org-babel-%s-associate-session" (nth 0 info)))))))
+
+(defun org-src-babel-configure-edit-buffer ()
+ (when org-src-babel-info
+ (org-src-associate-babel-session org-src-babel-info)))
+
+(org-add-hook 'org-src-mode-hook 'org-src-babel-configure-edit-buffer)
+
(provide 'org-src)
;; arch-tag: 6a1fc84f-dec7-47be-a416-64be56bea5d8