From 81d5ebce8d1def44b59498baaaf15284b2612561 Mon Sep 17 00:00:00 2001 From: Bastien Guerry Date: Fri, 14 Dec 2012 10:10:40 +0100 Subject: [PATCH] org-src.el (org-edit-src-code): Check if we are in a source code block with `org-in-src-block-p'. * org-src.el (org-edit-src-code): Check if we are in a source code block with `org-in-src-block-p'. Slightly reformat the docstring. --- lisp/org-src.el | 68 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 33 insertions(+), 35 deletions(-) diff --git a/lisp/org-src.el b/lisp/org-src.el index 188f9d2bd..6937c59bc 100644 --- a/lisp/org-src.el +++ b/lisp/org-src.el @@ -201,41 +201,39 @@ There is a mode hook, and keybindings for `org-edit-src-exit' and `org-edit-src-save'") (defun org-edit-src-code (&optional context code edit-buffer-name) - "Edit the source CODE example at point. -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]. This will remove the original code in the -Org buffer, and replace it with the edited version. An optional -argument CONTEXT is used by \\[org-edit-src-save] when calling -this function. See `org-src-window-setup' to configure the -display of windows containing the Org buffer and the code -buffer." + "Edit the source CODE block at point. +The code is copied to a separate buffer and the appropriate mode +is turned on. When done, exit with \\[org-edit-src-exit]. This will +remove the original code in the Org buffer, and replace it with the +edited version. An optional argument CONTEXT is used by \\[org-edit-src-save] +when calling this function. See `org-src-window-setup' to configure +the display of windows containing the Org buffer and the code buffer." (interactive) - (unless (eq context 'save) - (setq org-edit-src-saved-temp-window-config (current-window-configuration))) - (let* ((mark (and (org-region-active-p) (mark))) - (case-fold-search t) - (info - ;; If the src region consists in no lines, we insert a blank - ;; line. - (let* ((temp (org-edit-src-find-region-and-lang)) - (beg (nth 0 temp)) - (end (nth 1 temp))) - (if (>= end beg) temp - (goto-char beg) - (insert "\n") - (org-edit-src-find-region-and-lang)))) - (full-info (org-babel-get-src-block-info 'light)) - (org-mode-p (derived-mode-p 'org-mode)) ;; derived-mode-p is reflexive - (beg (make-marker)) - ;; Move marker with inserted text for case when src block is - ;; just one empty line, i.e. beg == end. - (end (copy-marker (make-marker) t)) - (allow-write-back-p (null code)) - block-nindent total-nindent ovl lang lang-f single lfmt buffer msg - begline markline markcol line col transmitted-variables) - (if (not info) - nil + (if (not (org-in-src-block-p)) + (user-error "Not in a source code block") + (unless (eq context 'save) + (setq org-edit-src-saved-temp-window-config (current-window-configuration))) + (let* ((mark (and (org-region-active-p) (mark))) + (case-fold-search t) + (info + ;; If the src region consists in no lines, we insert a blank + ;; line. + (let* ((temp (org-edit-src-find-region-and-lang)) + (beg (nth 0 temp)) + (end (nth 1 temp))) + (if (>= end beg) temp + (goto-char beg) + (insert "\n") + (org-edit-src-find-region-and-lang)))) + (full-info (org-babel-get-src-block-info 'light)) + (org-mode-p (derived-mode-p 'org-mode)) ;; derived-mode-p is reflexive + (beg (make-marker)) + ;; Move marker with inserted text for case when src block is + ;; just one empty line, i.e. beg == end. + (end (copy-marker (make-marker) t)) + (allow-write-back-p (null code)) + block-nindent total-nindent ovl lang lang-f single lfmt buffer msg + begline markline markcol line col transmitted-variables) (setq beg (move-marker beg (nth 0 info)) end (move-marker end (nth 1 info)) msg (if allow-write-back-p @@ -244,7 +242,7 @@ buffer." "Exit with C-c ' (C-c and single quote)") code (or code (buffer-substring-no-properties beg end)) lang (or (cdr (assoc (nth 2 info) org-src-lang-modes)) - (nth 2 info)) + (nth 2 info)) lang (if (symbolp lang) (symbol-name lang) lang) single (nth 3 info) block-nindent (nth 5 info) -- 2.11.4.GIT