;;; org-src.el --- Source code examples in Org
;;
-;; Copyright (C) 2004-2013 Free Software Foundation, Inc.
+;; Copyright (C) 2004-2015 Free Software Foundation, Inc.
;;
;; Author: Carsten Dominik <carsten at orgmode dot org>
;; Bastien Guerry <bzg@gnu.org>
This will save the content of the source code editing buffer into
a newly created file, not the base buffer for this source block.
-If you want to regularily save the base buffer instead of the source
+If you want to regularly save the base buffer instead of the source
code editing buffer, see `org-edit-src-auto-save-idle-delay' instead."
:group 'org-edit-structure
:version "24.4"
(condition-case e
(funcall lang-f)
(error
- (error "Language mode `%s' fails with: %S" lang-f (nth 1 e)))))
+ (message "Language mode `%s' fails with: %S" lang-f (nth 1 e)))))
(dolist (pair transmitted-variables)
(org-set-local (car pair) (cadr pair)))
;; Remove protecting commas from visible part of buffer.
(when (fboundp edit-prep-func)
(funcall edit-prep-func full-info)))
(or org-edit-src-code-timer
+ (zerop org-edit-src-auto-save-idle-delay)
(setq org-edit-src-code-timer
- (unless (zerop org-edit-src-auto-save-idle-delay)
- (run-with-idle-timer
- org-edit-src-auto-save-idle-delay t
- (lambda ()
- (cond
- ((and (string-match "\*Org Src" (buffer-name))
- (buffer-modified-p))
- (org-edit-src-save))
- ((not
- (delq nil (mapcar
- (lambda (b)
- (string-match "\*Org Src" (buffer-name b)))
- (buffer-list))))
- (cancel-timer org-edit-src-code-timer)
- (setq org-edit-src-code-timer)))))))))
- t)))
+ (run-with-idle-timer
+ org-edit-src-auto-save-idle-delay t
+ (lambda ()
+ (cond
+ ((org-string-match-p "\\`\\*Org Src" (buffer-name))
+ (when (buffer-modified-p) (org-edit-src-save)))
+ ((not (org-some (lambda (b)
+ (org-string-match-p "\\`\\*Org Src"
+ (buffer-name b)))
+ (buffer-list)))
+ (cancel-timer org-edit-src-code-timer)
+ (setq org-edit-src-code-timer nil))))))))
+ t)))
(defun org-edit-src-continue (e)
"Continue editing source blocks." ;; Fixme: be more accurate
(pos (point))
re1 re2 single beg end lang lfmt match-re1 ind entry)
(catch 'exit
- (when (org-at-table.el-p)
- (re-search-backward "^[\t]*[^ \t|\\+]" nil t)
- (setq beg (1+ (point-at-eol)))
- (goto-char beg)
- (or (re-search-forward "^[\t]*[^ \t|\\+]" nil t)
- (progn (goto-char (point-max)) (newline)))
- (setq end (1- (point-at-bol)))
- (throw 'exit (list beg end 'table.el nil nil 0)))
(while (setq entry (pop re-list))
(setq re1 (car entry) re2 (nth 1 entry) lang (nth 2 entry)
single (nth 3 entry))
(throw 'exit
(list (match-end 0) end
(org-edit-src-get-lang lang)
- single lfmt ind))))))))))))
+ single lfmt ind)))))))))
+ (when (org-at-table.el-p)
+ (re-search-backward "^[\t]*[^ \t|\\+]" nil t)
+ (setq beg (1+ (point-at-eol)))
+ (goto-char beg)
+ (or (re-search-forward "^[\t]*[^ \t|\\+]" nil t)
+ (progn (goto-char (point-max)) (newline)))
+ (setq end (1- (point-at-bol)))
+ (throw 'exit (list beg end 'table.el nil nil 0))))))
(defun org-edit-src-get-lang (lang)
"Extract the src language."
(unless (or single preserve-indentation (= total-nindent 0))
(setq indent (make-string total-nindent ?\ ))
(goto-char (point-min))
- (while (re-search-forward "^" nil t)
- (replace-match indent)))
+ (while (re-search-forward "\\(^\\).+" nil t)
+ (replace-match indent nil nil nil 1)))
(if (org-bound-and-true-p org-edit-src-picture)
(setq total-nindent (+ total-nindent 2)))
(setq code (buffer-string))
(kill-buffer buffer))
(goto-char beg)
(when allow-write-back-p
- (let ((buffer-undo-list t))
- (delete-region beg (max beg end))
- (unless (string-match "\\`[ \t]*\\'" code)
- (insert code))
- ;; Make sure the overlay stays in place
- (when (eq context 'save) (move-overlay ovl beg (point)))
- (goto-char beg)
- (if single (just-one-space))))
+ (undo-boundary)
+ (delete-region beg (max beg end))
+ (unless (string-match "\\`[ \t]*\\'" code)
+ (insert code))
+ ;; Make sure the overlay stays in place
+ (when (eq context 'save) (move-overlay ovl beg (point)))
+ (goto-char beg)
+ (if single (just-one-space)))
(if (memq t (mapcar (lambda (overlay)
(eq (overlay-get overlay 'invisible)
'org-hide-block))
(unless (eq context 'save)
(move-marker beg nil)
(move-marker end nil)))
- (when org-edit-src-code-timer
- (cancel-timer org-edit-src-code-timer)
- (setq org-edit-src-code-timer nil))
(unless (eq context 'save)
(when org-edit-src-saved-temp-window-config
(set-window-configuration org-edit-src-saved-temp-window-config)
(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)))))))
+ (let ((f (intern (format "org-babel-%s-associate-session"
+ (nth 0 info)))))
+ (and (fboundp f) (funcall f session))))))
(defun org-src-babel-configure-edit-buffer ()
(when org-src-babel-info
(delete-region (point-min) (point-max))
(insert string " ") ;; so there's a final property change
(unless (eq major-mode lang-mode) (funcall lang-mode))
- (font-lock-fontify-buffer)
+ (org-font-lock-ensure)
(setq pos (point-min))
(while (setq next (next-single-property-change pos 'face))
(put-text-property
LANG is a string, and the returned major mode is a symbol."
(intern
(concat
- ((lambda (l) (if (symbolp l) (symbol-name l) l))
- (or (cdr (assoc lang org-src-lang-modes)) lang)) "-mode")))
+ (let ((l (or (cdr (assoc lang org-src-lang-modes)) lang)))
+ (if (symbolp l) (symbol-name l) l))
+ "-mode")))
(provide 'org-src)