From ea846889f26e459398c659a11cd69923e8f2fb3f Mon Sep 17 00:00:00 2001 From: Carsten Dominik Date: Sun, 7 Jun 2009 23:10:36 +0200 Subject: [PATCH] Base block indentation after editing on #+begin line --- lisp/ChangeLog | 5 +++++ lisp/org-src.el | 24 +++++++++++++++++------- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index ca1ad0046..ced5f9f82 100755 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,8 @@ +2009-06-07 Carsten Dominik + + * org-src.el (org-edit-src-get-indentation): New function. + (org-edit-src-code): Base indentation on the begin line. + 2009-06-07 Tassilo Horn * org-gnus.el (org-gnus-store-link): Require message.el in diff --git a/lisp/org-src.el b/lisp/org-src.el index cd079bc37..2112ae214 100644 --- a/lisp/org-src.el +++ b/lisp/org-src.el @@ -135,6 +135,7 @@ the edited version." lang (nth 2 info) single (nth 3 info) lfmt (nth 4 info) + nindent (nth 5 info) lang-f (intern (concat lang "-mode")) begline (save-excursion (goto-char beg) (org-current-line))) (unless (functionp lang-f) @@ -164,7 +165,7 @@ the edited version." (insert code) (remove-text-properties (point-min) (point-max) '(display nil invisible nil intangible nil)) - (setq nindent (org-do-remove-indentation)) + (org-do-remove-indentation) (let ((org-inhibit-startup t)) (funcall lang-f)) (set (make-local-variable 'org-edit-src-force-single-line) single) @@ -231,11 +232,11 @@ the fragment in the Org-mode buffer." (if (looking-at "[ \t]*\\(\n\\|\\'\\)") (setq beg1 (point) end1 beg1) (save-excursion - (if (re-search-backward "^[ \t]*[^:]" nil 'move) + (if (re-search-backward "^[ \t]*[^: \t]" nil 'move) (setq beg1 (point-at-bol 2)) (setq beg1 (point)))) (save-excursion - (if (re-search-forward "^[ \t]*[^:]" nil 'move) + (if (re-search-forward "^[ \t]*[^: \t]" nil 'move) (setq end1 (1- (match-beginning 0))) (setq end1 (point)))) (goto-line line)) @@ -329,11 +330,12 @@ the language, a switch telling of the content should be in a single line." (setq match-re1 (match-string 0)) (setq beg (match-end 0) lang (org-edit-src-get-lang lang) - lfmt (org-edit-src-get-label-format match-re1)) + lfmt (org-edit-src-get-label-format match-re1) + ind (org-edit-src-get-indentation (match-beginning 0))) (if (and (re-search-forward re2 nil t) (>= (match-end 0) pos)) (throw 'exit (list beg (match-beginning 0) - lang single lfmt)))) + lang single lfmt ind)))) (if (or (looking-at re2) (re-search-forward re2 nil t)) (progn @@ -342,11 +344,13 @@ the language, a switch telling of the content should be in a single line." (<= (match-beginning 0) pos)) (progn (setq lfmt (org-edit-src-get-label-format - (match-string 0))) + (match-string 0)) + ind (org-edit-src-get-indentation + (match-beginning 0))) (throw 'exit (list (match-end 0) end (org-edit-src-get-lang lang) - single lfmt)))))))))))) + single lfmt ind)))))))))))) (defun org-edit-src-get-lang (lang) "Extract the src language." @@ -368,6 +372,12 @@ the language, a switch telling of the content should be in a single line." (if (string-match "-l[ \t]+\\\\?\"\\([^\t\r\n\"]+\\)\\\\?\"" s) (match-string 1 s)))) +(defun org-edit-src-get-indentation (pos) + "Extract the label format." + (save-match-data + (goto-char pos) + (org-get-indentation))) + (defun org-edit-src-exit () "Exit special edit and protect problematic lines." (interactive) -- 2.11.4.GIT