Browse Source

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.
Dan Davison 14 years ago
parent
commit
b61e0c4dfc
1 changed files with 19 additions and 0 deletions
  1. 19 0
      lisp/org-src.el

+ 19 - 0
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