Fix bug when commenting source code.

* org.el (org-babel-do-in-edit-buffer): Declare.
(org-babel-load-file, org-insert-comment)
(org-comment-or-uncomment-region): Don't require 'ob-core.
(org-mode-map): Remap `comment-dwim' to `org-comment-dwim'.
(org-comment-dwim): New command.

* ob-core.el (org-babel-do-in-edit-buffer): Make an autoload.

See http://lists.gnu.org/archive/html/emacs-devel/2013-12/msg00154.html
for a discussion about this bug.
This commit is contained in:
Bastien Guerry 2013-12-06 10:45:35 +01:00
parent 3a317abc23
commit 487c74580c
2 changed files with 12 additions and 7 deletions

View File

@ -972,6 +972,7 @@ with a prefix argument then this is passed on to
(org-edit-src-code)
(funcall swap-windows)))
;;;###autoload
(defmacro org-babel-do-in-edit-buffer (&rest body)
"Evaluate BODY in edit buffer if there is a code block at point.
Return t if a code block was found at point, nil otherwise."

View File

@ -124,6 +124,7 @@ Stars are put in group 1 and the trimmed body in group 2.")
(declare-function org-clock-sum-current-item "org-clock" (&optional tstart))
(declare-function org-babel-tangle-file "ob-tangle" (file &optional target-file lang))
(declare-function org-babel-do-in-edit-buffer "ob-core" (&rest body))
(declare-function orgtbl-mode "org-table" (&optional arg))
(declare-function org-clock-out "org-clock" (&optional switch-to-state fail-quietly at-time))
(declare-function org-beamer-mode "ox-beamer" ())
@ -201,7 +202,6 @@ and then loads the resulting file using `load-file'. With prefix
arg (noninteractively: 2nd arg) COMPILE the tangled Emacs Lisp
file to byte-code before it is loaded."
(interactive "fFile to load: \nP")
(require 'ob-core)
(let* ((age (lambda (file)
(float-time
(time-subtract (current-time)
@ -19215,6 +19215,7 @@ boundaries."
(org-defkey org-mode-map "\C-c\C-k" 'org-kill-note-or-show-branches)
(org-defkey org-mode-map "\C-c#" 'org-update-statistics-cookies)
(org-defkey org-mode-map [remap open-line] 'org-open-line)
(org-defkey org-mode-map [remap comment-dwim] 'org-comment-dwim)
(org-defkey org-mode-map [remap forward-paragraph] 'org-forward-paragraph)
(org-defkey org-mode-map [remap backward-paragraph] 'org-backward-paragraph)
(org-defkey org-mode-map "\C-m" 'org-return)
@ -20502,6 +20503,13 @@ If `org-special-ctrl-o' is nil, just call `open-line' everywhere."
(t
(open-line n))))
(defun org-comment-dwim (arg)
(interactive "*P")
"Call `comment-dwim' within a source edit buffer if needed"
(if (org-in-src-block-p)
(org-babel-do-in-edit-buffer (call-interactively #'comment-dwim))
(call-interactively #'comment-dwim)))
(defun org-return (&optional indent)
"Goto next table row or insert a newline.
Calls `org-table-next-row' or `newline', depending on context.
@ -22602,9 +22610,7 @@ major mode."
(skip-chars-backward " \r\t\n")
(line-beginning-position))
(point))))
(progn
(require 'ob-core)
(org-babel-do-in-edit-buffer (call-interactively #'comment-dwim)))
(org-babel-do-in-edit-buffer (call-interactively #'comment-dwim))
(beginning-of-line)
(if (looking-at "\\s-*$") (delete-region (point) (point-at-eol))
(open-line 1))
@ -22628,9 +22634,7 @@ strictly within a source block, use appropriate comment syntax."
(skip-chars-backward " \r\t\n")
(line-beginning-position))
end)))
(progn
(require 'ob-core)
(org-babel-do-in-edit-buffer (call-interactively #'comment-dwim)))
(org-babel-do-in-edit-buffer (call-interactively #'comment-dwim))
(save-restriction
;; Restrict region
(narrow-to-region (save-excursion (goto-char beg)