all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Patch to fix indent error when current line is in SRC block
@ 2008-09-08 12:46 S.P.Tseng
  2008-09-13 18:07 ` Carsten Dominik
  0 siblings, 1 reply; 2+ messages in thread
From: S.P.Tseng @ 2008-09-08 12:46 UTC (permalink / raw)
  To: emacs-orgmode


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 "\\<style=\"\\([^ \t\n\"]+\\)\"" m))
       (match-string 1 m))
      (t "fundamental"))))
-      
+
 (defun org-edit-src-exit ()
   "Exit special edit and protect problematic lines."
   (interactive)
@@ -7959,7 +7959,7 @@ operation has put the subtree."
 (defun org-olpath-completing-read (prompt collection &rest args)
   "Read an outline path like a file name."
   (let ((thetable collection))
-    (apply 
+    (apply
      'completing-read prompt
      (lambda (string predicate &optional flag)
        (let (rtn r s f (l (length string)))
@@ -8116,7 +8116,7 @@ This function can be used in a hook."
 
 (defcustom org-structure-template-alist
   '(
-    ("s" "#+begin_src ?\n\n#+end_src" 
+    ("s" "#+begin_src ?\n\n#+end_src"
          "<src lang=\"?\">\n\n</src>")
     ("e" "#+begin_example\n?\n#+end_example"
          "<example>\n?\n</example>")
@@ -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

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2008-09-13 19:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-09-08 12:46 Patch to fix indent error when current line is in SRC block S.P.Tseng
2008-09-13 18:07 ` Carsten Dominik

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.