From mboxrd@z Thu Jan 1 00:00:00 1970 From: S.P.Tseng Subject: Patch to fix indent error when current line is in SRC block Date: Mon, 08 Sep 2008 20:46:54 +0800 Message-ID: <8563p6x0sh.fsf@modprobe.cn> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Kcg9g-0005BN-No for emacs-orgmode@gnu.org; Mon, 08 Sep 2008 08:47:44 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Kcg9e-0005Aq-DL for emacs-orgmode@gnu.org; Mon, 08 Sep 2008 08:47:43 -0400 Received: from [199.232.76.173] (port=51523 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Kcg9e-0005An-7s for emacs-orgmode@gnu.org; Mon, 08 Sep 2008 08:47:42 -0400 Received: from main.gmane.org ([80.91.229.2]:43808 helo=ciao.gmane.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1Kcg9d-00007J-3F for emacs-orgmode@gnu.org; Mon, 08 Sep 2008 08:47:42 -0400 Received: from list by ciao.gmane.org with local (Exim 4.43) id 1Kcg9T-00045j-LM for emacs-orgmode@gnu.org; Mon, 08 Sep 2008 12:47:31 +0000 Received: from 222.214.144.52 ([222.214.144.52]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 08 Sep 2008 12:47:31 +0000 Received: from deftsp by 222.214.144.52 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 08 Sep 2008 12:47:31 +0000 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org I add function 'org-edit-src-find-region-and-lang' to the begin of the 'org-indent-line-function'. When current line is in SRC block do nothing. So, you can use below code to indent the whole buffer. ,---- | (defun my-iwb () | "indent whole buffer" | (interactive) | (delete-trailing-whitespace) | (indent-region (point-min) (point-max) nil) | (untabify (point-min) (point-max))) `---- --- lisp/org.el | 141 ++++++++++++++++++++++++++++++----------------------------- 1 files changed, 71 insertions(+), 70 deletions(-) diff --git a/lisp/org.el b/lisp/org.el index 26e8117..1ac78b0 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -1647,7 +1647,7 @@ end of the second format." org-mode generates a time duration." :group 'org-time :type 'string) - + (defcustom org-deadline-warning-days 14 "No. of days before expiration during which a deadline becomes active. This variable governs the display in sparse trees and in the agenda. @@ -2512,7 +2512,7 @@ Otherwise, return nil." (<= org-clock-marker (point-at-eol))) ;; The clock is running here (setq org-clock-start-time - (apply 'encode-time + (apply 'encode-time (org-parse-time-string (match-string 1)))) (org-update-mode-line))) (t @@ -2683,8 +2683,8 @@ collapsed state." ;; Autoload ID code (org-autoload "org-id" - '(org-id-get-create org-id-new org-id-copy org-id-get - org-id-get-with-outline-path-completion + '(org-id-get-create org-id-new org-id-copy org-id-get + org-id-get-with-outline-path-completion org-id-get-with-outline-drilling org-id-goto org-id-find)) @@ -5572,7 +5572,7 @@ the language, a switch telling of the content should be in a single line." (string-match "\\\n\n") ("e" "#+begin_example\n?\n#+end_example" "\n?\n") @@ -8179,7 +8179,7 @@ expands them." (t (newline)))) (setq start (point)) (if (string-match "%file" rpl) - (setq rpl (replace-match + (setq rpl (replace-match (concat "\"" (save-match-data @@ -8188,7 +8188,7 @@ expands them." t t rpl))) (insert rpl) (if (re-search-backward "\\?" start t) (delete-char 1)))) - + (defun org-complete (&optional arg) "Perform completion on word at point. @@ -8587,7 +8587,7 @@ For calling through lisp, arg is also interpreted in the following way: (condition-case nil (outline-forward-same-level 1) (error (end-of-line 1))))) - (replace-match + (replace-match (if is-percent (format "[%d%%]" (/ (* 100 cnt-done) (max 1 cnt-all))) (format "[%d/%d]" cnt-done cnt-all))) @@ -8609,7 +8609,7 @@ when there is a statistics cookie in the headline! (let (org-log-done org-log-states) ; turn off logging (org-todo (if (= n-not-done 0) \"DONE\" \"TODO\")))) ") - + (defun org-local-logging (value) "Get logging settings from a property VALUE." (let* (words w a) @@ -10195,12 +10195,12 @@ the scanner. The following items can be given here: ((eq match t) (setq matcher t)) ((eq match nil) (setq matcher t)) (t (setq matcher (if match (org-make-tags-matcher match) t)))) - + (when (eq scope 'tree) (org-back-to-heading t) (org-narrow-to-subtree) (setq scope nil)) - + (if (not scope) (progn (org-prepare-agenda-buffers @@ -10489,7 +10489,7 @@ If yes, return this value. If not, return the current value of the variable." (move-marker org-entry-property-inherited-from (point)) (throw 'ex tmp)) (or (org-up-heading-safe) (throw 'ex nil))))) - (or tmp + (or tmp (cdr (assoc property org-file-properties)) (cdr (assoc property org-global-properties)) (cdr (assoc property org-global-properties-fixed)))))) @@ -12021,11 +12021,11 @@ If EXCLUDE-TMP is non-nil, ignore temporary buffers." (lambda (b) (string-match "\*Org .*Export" (buffer-name b)))) ((eq predicate 'agenda) (lambda (b) - (with-current-buffer b + (with-current-buffer b (and (eq major-mode 'org-mode) (setq bfn (buffer-file-name b)) (member (file-truename bfn) agenda-files))))) - (t (lambda (b) (with-current-buffer b + (t (lambda (b) (with-current-buffer b (or (eq major-mode 'org-mode) (string-match "\*Org .*Export" (buffer-name b))))))))) @@ -12243,7 +12243,7 @@ When a buffer is unmodified, it is just killed. When modified, it is saved (append org-done-keywords-for-agenda org-done-keywords)) (setq org-todo-keyword-alist-for-agenda (append org-todo-keyword-alist-for-agenda org-todo-key-alist)) - (setq org-tag-alist-for-agenda + (setq org-tag-alist-for-agenda (append org-tag-alist-for-agenda org-tag-alist)) (save-excursion @@ -14108,59 +14108,60 @@ which make use of the date at the cursor." (defun org-indent-line-function () "Indent line like previous, but further if previous was headline or item." (interactive) - (let* ((pos (point)) - (itemp (org-at-item-p)) - column bpos bcol tpos tcol bullet btype bullet-type) - ;; Find the previous relevant line - (beginning-of-line 1) - (cond - ((looking-at "#") (setq column 0)) - ((looking-at "\\*+ ") (setq column 0)) - (t - (beginning-of-line 0) - (while (and (not (bobp)) (looking-at "[ \t]*[\n:#|]")) - (beginning-of-line 0)) - (cond - ((looking-at "\\*+[ \t]+") - (if (not org-adapt-indentation) - (setq column 0) - (goto-char (match-end 0)) - (setq column (current-column)))) - ((org-in-item-p) - (org-beginning-of-item) -; (looking-at "[ \t]*\\(\\S-+\\)[ \t]*") - (looking-at "[ \t]*\\(\\S-+\\)[ \t]*\\(\\[[- X]\\][ \t]*\\|.*? :: \\)?") - (setq bpos (match-beginning 1) tpos (match-end 0) - bcol (progn (goto-char bpos) (current-column)) - tcol (progn (goto-char tpos) (current-column)) - bullet (match-string 1) - bullet-type (if (string-match "[0-9]" bullet) "n" bullet)) - (if (> tcol (+ bcol org-description-max-indent)) - (setq tcol (+ bcol 5))) - (if (not itemp) - (setq column tcol) - (goto-char pos) - (beginning-of-line 1) - (if (looking-at "\\S-") - (progn - (looking-at "[ \t]*\\(\\S-+\\)[ \t]*") - (setq bullet (match-string 1) - btype (if (string-match "[0-9]" bullet) "n" bullet)) - (setq column (if (equal btype bullet-type) bcol tcol))) - (setq column (org-get-indentation))))) - (t (setq column (org-get-indentation)))))) - (goto-char pos) - (if (<= (current-column) (current-indentation)) - (org-indent-line-to column) - (save-excursion (org-indent-line-to column))) - (setq column (current-column)) - (beginning-of-line 1) - (if (looking-at - "\\([ \t]+\\)\\(:[-_0-9a-zA-Z]+:\\)[ \t]*\\(\\S-.*\\(\\S-\\|$\\)\\)") - (replace-match (concat "\\1" (format org-property-format - (match-string 2) (match-string 3))) - t nil)) - (org-move-to-column column))) + (unless (org-edit-src-find-region-and-lang) + (let* ((pos (point)) + (itemp (org-at-item-p)) + column bpos bcol tpos tcol bullet btype bullet-type) + ;; Find the previous relevant line + (beginning-of-line 1) + (cond + ((looking-at "#") (setq column 0)) + ((looking-at "\\*+ ") (setq column 0)) + (t + (beginning-of-line 0) + (while (and (not (bobp)) (looking-at "[ \t]*[\n:#|]")) + (beginning-of-line 0)) + (cond + ((looking-at "\\*+[ \t]+") + (if (not org-adapt-indentation) + (setq column 0) + (goto-char (match-end 0)) + (setq column (current-column)))) + ((org-in-item-p) + (org-beginning-of-item) + ; (looking-at "[ \t]*\\(\\S-+\\)[ \t]*") + (looking-at "[ \t]*\\(\\S-+\\)[ \t]*\\(\\[[- X]\\][ \t]*\\|.*? :: \\)?") + (setq bpos (match-beginning 1) tpos (match-end 0) + bcol (progn (goto-char bpos) (current-column)) + tcol (progn (goto-char tpos) (current-column)) + bullet (match-string 1) + bullet-type (if (string-match "[0-9]" bullet) "n" bullet)) + (if (> tcol (+ bcol org-description-max-indent)) + (setq tcol (+ bcol 5))) + (if (not itemp) + (setq column tcol) + (goto-char pos) + (beginning-of-line 1) + (if (looking-at "\\S-") + (progn + (looking-at "[ \t]*\\(\\S-+\\)[ \t]*") + (setq bullet (match-string 1) + btype (if (string-match "[0-9]" bullet) "n" bullet)) + (setq column (if (equal btype bullet-type) bcol tcol))) + (setq column (org-get-indentation))))) + (t (setq column (org-get-indentation)))))) + (goto-char pos) + (if (<= (current-column) (current-indentation)) + (org-indent-line-to column) + (save-excursion (org-indent-line-to column))) + (setq column (current-column)) + (beginning-of-line 1) + (if (looking-at + "\\([ \t]+\\)\\(:[-_0-9a-zA-Z]+:\\)[ \t]*\\(\\S-.*\\(\\S-\\|$\\)\\)") + (replace-match (concat "\\1" (format org-property-format + (match-string 2) (match-string 3))) + t nil)) + (org-move-to-column column)))) (defun org-set-autofill-regexps () (interactive) -- 1.5.6.5