瀏覽代碼

Make "C-c '" also edit #+MACRO definitions, including multiline

Carsten Dominik 15 年之前
父節點
當前提交
e59e619a8f
共有 2 個文件被更改,包括 30 次插入14 次删除
  1. 4 0
      lisp/ChangeLog
  2. 26 14
      lisp/org-src.el

+ 4 - 0
lisp/ChangeLog

@@ -1,5 +1,9 @@
 2009-10-06  Carsten Dominik  <carsten.dominik@gmail.com>
 
+	* org-src.el (org-edit-src-code)
+	(org-edit-src-find-region-and-lang, org-edit-src-exit): Handle
+	macro editing.
+
 	* org-agenda.el (org-prefix-category-max-length): New variable.
 	(org-format-agenda-item): Use `org-prefix-category-max-length'.
 	(org-compile-prefix-format): Set `org-prefix-category-max-length'.

+ 26 - 14
lisp/org-src.el

@@ -199,6 +199,8 @@ the edited version."
 			   map))
 	(org-overlay-put ovl :read-only "Leave me alone")
 	(switch-to-buffer buffer)
+	(if (eq single 'macro-definition)
+	    (setq code (replace-regexp-in-string "\\\\n" "\n" code t t)))
 	(insert code)
 	(remove-text-properties (point-min) (point-max)
 				'(display nil invisible nil intangible nil))
@@ -360,6 +362,8 @@ the language, a switch telling of the content should be in a single line."
 	    ("^[ \t]*#\\+ascii:" "\n" "fundamental" single-line)
 	    ("^[ \t]*#\\+begin_ascii.*\n" "\n[ \t]*#\\+end_ascii" "fundamental")
 	    ("^[ \t]*#\\+docbook:" "\n" "xml" single-line)
+	    ("^[ \t]*#\\+macro:[ \t]+\\S-+\\( \\|$\\)"
+	     "\n" "fundamental" macro-definition)
 	    ("^[ \t]*#\\+begin_docbook.*\n" "\n[ \t]*#\\+end_docbook" "xml")
 	    )))
 	(pos (point))
@@ -428,28 +432,35 @@ the language, a switch telling of the content should be in a single line."
   (interactive)
   (unless org-edit-src-from-org-mode
     (error "This is not a sub-editing buffer, something is wrong..."))
-  (let ((beg org-edit-src-beg-marker)
-	(end org-edit-src-end-marker)
-	(ovl org-edit-src-overlay)
-	(buffer (current-buffer))
-	(nindent org-edit-src-nindent)
-	code line)
+  (let* ((beg org-edit-src-beg-marker)
+	 (end org-edit-src-end-marker)
+	 (ovl org-edit-src-overlay)
+	 (buffer (current-buffer))
+	 (single (org-bound-and-true-p org-edit-src-force-single-line))
+	 (macro (eq single 'macro-definition))
+	 (nindent org-edit-src-nindent)
+	 code line)
     (untabify (point-min) (point-max))
     (save-excursion
       (goto-char (point-min))
       (if (looking-at "[ \t\n]*\n") (replace-match ""))
-      (if (re-search-forward "\n[ \t\n]*\\'" nil t) (replace-match "")))
+      (unless macro
+	(if (re-search-forward "\n[ \t\n]*\\'" nil t) (replace-match ""))))
     (setq line (if (org-bound-and-true-p org-edit-src-force-single-line)
 		   1
 		 (org-current-line)))
-    (when (org-bound-and-true-p org-edit-src-force-single-line)
+    (when single
       (goto-char (point-min))
-      (while (re-search-forward "\n" nil t)
-	(replace-match " "))
+      (if (re-search-forward "\\s-+\\'" nil t) (replace-match ""))
       (goto-char (point-min))
-      (if (looking-at "\\s-*") (replace-match " "))
-      (if (re-search-forward "\\s-+\\'" nil t)
-	  (replace-match "")))
+      (let ((cnt 0))
+	(while (re-search-forward "\n" nil t)
+	  (setq cnt (1+ cnt))
+	  (replace-match (if macro "\\n" " ") t t))
+	(when (and macro (> cnt 0))
+	  (goto-char (point-max)) (insert "\\n")))
+      (goto-char (point-min))
+      (if (looking-at "\\s-*") (replace-match " ")))
     (when (org-bound-and-true-p org-edit-src-from-org-mode)
       (goto-char (point-min))
       (while (re-search-forward
@@ -460,7 +471,7 @@ the language, a switch telling of the content should be in a single line."
       (goto-char (point-min))
       (while (re-search-forward "^" nil t)
 	(replace-match ": ")))
-    (when nindent
+    (when (and nindent (not single))
       (setq nindent (make-string (+ org-edit-src-content-indentation nindent)
 				 ?\ ))
       (goto-char (point-min))
@@ -474,6 +485,7 @@ the language, a switch telling of the content should be in a single line."
     (delete-region beg end)
     (insert code)
     (goto-char beg)
+    (if single (just-one-space))
     (org-goto-line (1- (+ (org-current-line) line)))
     (move-marker beg nil)
     (move-marker end nil)))