diff options
author | Bastien Guerry <bzg@altern.org> | 2012-07-11 20:45:17 +0200 |
---|---|---|
committer | Bastien Guerry <bzg@altern.org> | 2012-07-11 20:45:17 +0200 |
commit | be56d706aebab0c3d0d372354f699b6f3d1893ff (patch) | |
tree | 6d9bc3bf3d3cec88157b521102be3250e7236e0b | |
parent | afe5eb140e4b47f3a587278bbe07dca738e70272 (diff) | |
download | org-mode-be56d706aebab0c3d0d372354f699b6f3d1893ff.tar.gz |
org.el: New function `org-indent-region'.
* org.el (org-mode): Set `indent-region-function'.
(org-indent-region): New function.
(org-fill-paragraph): When in a src block, use `indent-region'
to indent the whole source code instead of falling back on
`fill-paragraph', as this function messes up the code.
-rw-r--r-- | lisp/org.el | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/lisp/org.el b/lisp/org.el index 04a3c55..5880435 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -5041,7 +5041,8 @@ The following commands are available: (org-add-hook 'kill-buffer-hook 'org-check-running-clock nil 'local) ;; Paragraphs and auto-filling (org-set-autofill-regexps) - (setq indent-line-function 'org-indent-line) + (org-set-local 'indent-line-function 'org-indent-line) + (org-set-local 'indent-region-function 'org-indent-region) (org-update-radio-target-regexp) ;; Beginning/end of defun (org-set-local 'beginning-of-defun-function 'org-beginning-of-defun) @@ -20643,6 +20644,17 @@ If point is in an inline task, mark that task instead." (when folded (org-cycle))) (message "Block at point indented")) +(defun org-indent-region (start end) + "Indent region." + (interactive "r") + (save-excursion + (let ((line-end (org-current-line end))) + (goto-char start) + (while (< (org-current-line) line-end) + (cond ((org-in-src-block-p) (org-src-native-tab-command-maybe)) + (t (call-interactively 'org-indent-line))) + (move-beginning-of-line 2))))) + ;; For reference, this is the default value of adaptive-fill-regexp ;; "[ \t]*\\([-|#;>*]+[ \t]*\\|(?[0-9]+[.)][ \t]*\\)*" (defvar org-adaptive-fill-regexp-backup adaptive-fill-regexp @@ -20724,13 +20736,18 @@ the functionality can be provided as a fall-back.") "Re-align a table, pass through to fill-paragraph if no table." (let ((table-p (org-at-table-p)) (table.el-p (org-at-table.el-p)) - (itemp (org-in-item-p))) + (itemp (org-in-item-p)) + (srcp (org-in-src-block-p))) (cond ((and (equal (char-after (point-at-bol)) ?*) (save-excursion (goto-char (point-at-bol)) (looking-at org-outline-regexp))) t) ; skip headlines (table.el-p t) ; skip table.el tables (table-p (org-table-align) t) ; align Org tables + (srcp ; indent entire src block to prevent + (save-excursion ; fill-paragraph-as-region to mess up + (org-babel-do-in-edit-buffer + (indent-region (point-min) (point-max))))) (itemp ; align text in items (let* ((struct (save-excursion (goto-char itemp) (org-list-struct))) |