mirror of
https://git.savannah.gnu.org/git/emacs/org-mode.git
synced 2024-12-28 10:56:57 +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:
parent
a7afe7df1a
commit
81d5ebce8d
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user