From 7c9663eb4add5f087e9ba8bd1745d2b55889d720 Mon Sep 17 00:00:00 2001 From: Bastien Guerry Date: Fri, 15 Feb 2013 22:59:13 +0100 Subject: [PATCH] org-src.el: Allow to abort editing with C-c k * org-src.el (org-src-mode-map): New binding C-c k to abort editing. (org-edit-src-code): Mention the keybinding to abort editing and go back to the correct position. (org-edit-src-abort): New command to abort editing. Thanks to Zech for suggesting this. --- lisp/org-src.el | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lisp/org-src.el b/lisp/org-src.el index 10ecb85ee..604588827 100644 --- a/lisp/org-src.el +++ b/lisp/org-src.el @@ -174,6 +174,7 @@ For example, there is no ocaml-mode in Emacs, but the mode to use is (defvar org-src-mode-map (make-sparse-keymap)) (define-key org-src-mode-map "\C-c'" 'org-edit-src-exit) +(define-key org-src-mode-map "\C-ck" 'org-edit-src-abort) (define-key org-src-mode-map "\C-x\C-s" 'org-edit-src-save) (defvar org-edit-src-force-single-line nil) @@ -241,8 +242,8 @@ the display of windows containing the Org buffer and the code buffer." end (move-marker end (nth 1 info)) msg (if allow-write-back-p (substitute-command-keys - "Edit, then exit with C-c ' (C-c and single quote)") - "Exit with C-c ' (C-c and single quote)") + "Edit, then exit with C-c ' (C-c and single quote) -- C-c k to abort") + "Exit with C-c ' (C-c and single quote) -- C-c k to abort") code (or code (buffer-substring-no-properties beg end)) lang (or (cdr (assoc (nth 2 info) org-src-lang-modes)) (nth 2 info)) @@ -712,8 +713,9 @@ with \",*\", \",#+\", \",,*\" and \",,#+\"." ;; Block is hidden; put point at start of block (beginning-of-line 0) ;; Block is visible, put point where it was in the code buffer - (org-goto-line (1- (+ (org-current-line) line))) - (org-move-to-column (if preserve-indentation col (+ col total-nindent delta)))) + (when allow-write-back-p + (org-goto-line (1- (+ (org-current-line) line))) + (org-move-to-column (if preserve-indentation col (+ col total-nindent delta))))) (unless (eq context 'save) (move-marker beg nil) (move-marker end nil))) @@ -722,6 +724,12 @@ with \",*\", \",#+\", \",,*\" and \",,#+\"." (set-window-configuration org-edit-src-saved-temp-window-config) (setq org-edit-src-saved-temp-window-config nil)))) +(defun org-edit-src-abort () + "Abort editing of the src code and return to the Org buffer." + (interactive) + (let (org-edit-src-allow-write-back-p) + (org-edit-src-exit 'exit))) + (defmacro org-src-in-org-buffer (&rest body) `(let ((p (point)) (m (mark)) (ul buffer-undo-list) msg) (save-window-excursion -- 2.11.4.GIT