1
0
mirror of https://git.savannah.gnu.org/git/emacs/org-mode.git synced 2025-01-15 17:00:45 +00:00

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.
This commit is contained in:
Bastien Guerry 2012-12-14 10:10:40 +01:00
parent a7afe7df1a
commit 81d5ebce8d

View File

@ -201,41 +201,39 @@ 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)
"Edit the source CODE example at point. "Edit the source CODE block at point.
The example is copied to a separate buffer, and that buffer is The code is copied to a separate buffer and the appropriate mode
switched to the correct language mode. When done, exit with is turned on. When done, exit with \\[org-edit-src-exit]. This will
\\[org-edit-src-exit]. This will remove the original code in the remove the original code in the Org buffer, and replace it with the
Org buffer, and replace it with the edited version. An optional edited version. An optional argument CONTEXT is used by \\[org-edit-src-save]
argument CONTEXT is used by \\[org-edit-src-save] when calling when calling this function. See `org-src-window-setup' to configure
this function. See `org-src-window-setup' to configure the the display of windows containing the Org buffer and the code buffer."
display of windows containing the Org buffer and the code
buffer."
(interactive) (interactive)
(unless (eq context 'save) (if (not (org-in-src-block-p))
(setq org-edit-src-saved-temp-window-config (current-window-configuration))) (user-error "Not in a source code block")
(let* ((mark (and (org-region-active-p) (mark))) (unless (eq context 'save)
(case-fold-search t) (setq org-edit-src-saved-temp-window-config (current-window-configuration)))
(info (let* ((mark (and (org-region-active-p) (mark)))
;; If the src region consists in no lines, we insert a blank (case-fold-search t)
;; line. (info
(let* ((temp (org-edit-src-find-region-and-lang)) ;; If the src region consists in no lines, we insert a blank
(beg (nth 0 temp)) ;; line.
(end (nth 1 temp))) (let* ((temp (org-edit-src-find-region-and-lang))
(if (>= end beg) temp (beg (nth 0 temp))
(goto-char beg) (end (nth 1 temp)))
(insert "\n") (if (>= end beg) temp
(org-edit-src-find-region-and-lang)))) (goto-char beg)
(full-info (org-babel-get-src-block-info 'light)) (insert "\n")
(org-mode-p (derived-mode-p 'org-mode)) ;; derived-mode-p is reflexive (org-edit-src-find-region-and-lang))))
(beg (make-marker)) (full-info (org-babel-get-src-block-info 'light))
;; Move marker with inserted text for case when src block is (org-mode-p (derived-mode-p 'org-mode)) ;; derived-mode-p is reflexive
;; just one empty line, i.e. beg == end. (beg (make-marker))
(end (copy-marker (make-marker) t)) ;; Move marker with inserted text for case when src block is
(allow-write-back-p (null code)) ;; just one empty line, i.e. beg == end.
block-nindent total-nindent ovl lang lang-f single lfmt buffer msg (end (copy-marker (make-marker) t))
begline markline markcol line col transmitted-variables) (allow-write-back-p (null code))
(if (not info) block-nindent total-nindent ovl lang lang-f single lfmt buffer msg
nil begline markline markcol line col transmitted-variables)
(setq beg (move-marker beg (nth 0 info)) (setq beg (move-marker beg (nth 0 info))
end (move-marker end (nth 1 info)) end (move-marker end (nth 1 info))
msg (if allow-write-back-p msg (if allow-write-back-p
@ -244,7 +242,7 @@ buffer."
"Exit with C-c ' (C-c and single quote)") "Exit with C-c ' (C-c and single quote)")
code (or code (buffer-substring-no-properties beg end)) code (or code (buffer-substring-no-properties beg end))
lang (or (cdr (assoc (nth 2 info) org-src-lang-modes)) 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) lang (if (symbolp lang) (symbol-name lang) lang)
single (nth 3 info) single (nth 3 info)
block-nindent (nth 5 info) block-nindent (nth 5 info)