|
@@ -34,6 +34,8 @@
|
|
|
|
|
|
(require 'org-macs)
|
|
(require 'org-macs)
|
|
(require 'org-compat)
|
|
(require 'org-compat)
|
|
|
|
+(require 'ob-keys)
|
|
|
|
+(require 'ob-comint)
|
|
(eval-when-compile
|
|
(eval-when-compile
|
|
(require 'cl))
|
|
(require 'cl))
|
|
|
|
|
|
@@ -165,6 +167,7 @@ For example, there is no ocaml-mode in Emacs, but the mode to use is
|
|
|
|
|
|
(defvar org-src-mode-map (make-sparse-keymap))
|
|
(defvar org-src-mode-map (make-sparse-keymap))
|
|
(define-key org-src-mode-map "\C-c'" 'org-edit-src-exit)
|
|
(define-key org-src-mode-map "\C-c'" 'org-edit-src-exit)
|
|
|
|
+
|
|
(defvar org-edit-src-force-single-line nil)
|
|
(defvar org-edit-src-force-single-line nil)
|
|
(defvar org-edit-src-from-org-mode nil)
|
|
(defvar org-edit-src-from-org-mode nil)
|
|
(defvar org-edit-src-allow-write-back-p t)
|
|
(defvar org-edit-src-allow-write-back-p t)
|
|
@@ -181,6 +184,8 @@ For example, there is no ocaml-mode in Emacs, but the mode to use is
|
|
immediately; otherwise it will ask whether you want to return
|
|
immediately; otherwise it will ask whether you want to return
|
|
to the existing edit buffer.")
|
|
to the existing edit buffer.")
|
|
|
|
|
|
|
|
+(defvar org-src-babel-info nil)
|
|
|
|
+
|
|
(define-minor-mode org-src-mode
|
|
(define-minor-mode org-src-mode
|
|
"Minor mode for language major mode buffers generated by org.
|
|
"Minor mode for language major mode buffers generated by org.
|
|
This minor mode is turned on in two situations:
|
|
This minor mode is turned on in two situations:
|
|
@@ -189,7 +194,7 @@ This minor mode is turned on in two situations:
|
|
There is a mode hook, and keybindings for `org-edit-src-exit' and
|
|
There is a mode hook, and keybindings for `org-edit-src-exit' and
|
|
`org-edit-src-save'")
|
|
`org-edit-src-save'")
|
|
|
|
|
|
-(defun org-edit-src-code (&optional context code edit-buffer-name)
|
|
|
|
|
|
+(defun org-edit-src-code (&optional context code edit-buffer-name quietp)
|
|
"Edit the source code example at point.
|
|
"Edit the source code example at point.
|
|
The example is copied to a separate buffer, and that buffer is switched
|
|
The example is copied to a separate buffer, and that buffer is switched
|
|
to the correct language mode. When done, exit with \\[org-edit-src-exit].
|
|
to the correct language mode. When done, exit with \\[org-edit-src-exit].
|
|
@@ -203,6 +208,7 @@ the edited version. Optional argument CONTEXT is used by
|
|
(col (current-column))
|
|
(col (current-column))
|
|
(case-fold-search t)
|
|
(case-fold-search t)
|
|
(info (org-edit-src-find-region-and-lang))
|
|
(info (org-edit-src-find-region-and-lang))
|
|
|
|
+ (babel-info (org-babel-get-src-block-info))
|
|
(org-mode-p (eq major-mode 'org-mode))
|
|
(org-mode-p (eq major-mode 'org-mode))
|
|
(beg (make-marker))
|
|
(beg (make-marker))
|
|
(end (make-marker))
|
|
(end (make-marker))
|
|
@@ -272,6 +278,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-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-edit-src-allow-write-back-p) allow-write-back-p)
|
|
(set (make-local-variable 'org-src-preserve-indentation) preserve-indentation)
|
|
(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
|
|
(when lfmt
|
|
(set (make-local-variable 'org-coderef-label-format) lfmt))
|
|
(set (make-local-variable 'org-coderef-label-format) lfmt))
|
|
(when org-mode-p
|
|
(when org-mode-p
|
|
@@ -290,7 +298,7 @@ the edited version. Optional argument CONTEXT is used by
|
|
(set-buffer-modified-p nil)
|
|
(set-buffer-modified-p nil)
|
|
(and org-edit-src-persistent-message
|
|
(and org-edit-src-persistent-message
|
|
(org-set-local 'header-line-format msg)))
|
|
(org-set-local 'header-line-format msg)))
|
|
- (message "%s" msg)
|
|
|
|
|
|
+ (unless quietp (message "%s" msg))
|
|
t)))
|
|
t)))
|
|
|
|
|
|
(defun org-edit-src-continue (e)
|
|
(defun org-edit-src-continue (e)
|
|
@@ -321,6 +329,8 @@ the edited version. Optional argument CONTEXT is used by
|
|
(if (eq context 'edit) (delete-other-windows))
|
|
(if (eq context 'edit) (delete-other-windows))
|
|
(org-switch-to-buffer-other-window buffer)
|
|
(org-switch-to-buffer-other-window buffer)
|
|
(if (eq context 'exit) (delete-other-windows)))
|
|
(if (eq context 'exit) (delete-other-windows)))
|
|
|
|
+ ('switch-invisibly
|
|
|
|
+ (set-buffer buffer))
|
|
(t
|
|
(t
|
|
(message "Invalid value %s for org-src-window-setup"
|
|
(message "Invalid value %s for org-src-window-setup"
|
|
(symbol-name org-src-window-setup))
|
|
(symbol-name org-src-window-setup))
|
|
@@ -654,6 +664,55 @@ 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)
|
|
(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)
|
|
|
|
+(defmacro org-src-do-at-code-block (&rest body)
|
|
|
|
+ "Execute a command from an edit buffer in the Org-mode buffer."
|
|
|
|
+ `(let ((beg-marker org-edit-src-beg-marker))
|
|
|
|
+ (if beg-marker
|
|
|
|
+ (with-current-buffer (marker-buffer beg-marker)
|
|
|
|
+ (goto-char (marker-position beg-marker))
|
|
|
|
+ ,@body))))
|
|
|
|
+
|
|
|
|
+(defun org-src-do-key-sequence-at-code-block (&optional key)
|
|
|
|
+ "Execute key sequence at code block in the source Org buffer.
|
|
|
|
+The command bound to KEY in the Org-babel key map is executed
|
|
|
|
+remotely with point temporarily at the start of the code block in
|
|
|
|
+the Org buffer.
|
|
|
|
+
|
|
|
|
+This command is not bound to a key by default, to avoid conflicts
|
|
|
|
+with language major mode bindings. To bind it to C-c @ in all
|
|
|
|
+language major modes, you could use
|
|
|
|
+
|
|
|
|
+ (add-hook 'org-src-mode-hook
|
|
|
|
+ (lambda () (define-key org-src-mode-map \"\\C-c@\"
|
|
|
|
+ 'org-src-do-key-sequence-at-code-block)))
|
|
|
|
+
|
|
|
|
+In that case, for example, C-c @ t issued in code edit buffers
|
|
|
|
+would tangle the current Org code block, C-c @ e would execute
|
|
|
|
+the block and C-c @ h would display the other available
|
|
|
|
+Org-babel commands."
|
|
|
|
+ (interactive "kOrg-babel key: ")
|
|
|
|
+ (if (equal key (kbd "C-g")) (keyboard-quit)
|
|
|
|
+ (org-edit-src-save)
|
|
|
|
+ (org-src-do-at-code-block
|
|
|
|
+ (call-interactively
|
|
|
|
+ (lookup-key org-babel-map key)))))
|
|
|
|
+
|
|
|
|
+
|
|
(provide 'org-src)
|
|
(provide 'org-src)
|
|
|
|
|
|
;; arch-tag: 6a1fc84f-dec7-47be-a416-64be56bea5d8
|
|
;; arch-tag: 6a1fc84f-dec7-47be-a416-64be56bea5d8
|