Browse Source

Fix a giant, horrible bug in org-publish.

When publishing, org was more or less trying to export random files.
Carsten Dominik 16 years ago
parent
commit
337d2f2762
2 changed files with 32 additions and 26 deletions
  1. 3 1
      lisp/org-exp.el
  2. 29 25
      lisp/org-publish.el

+ 3 - 1
lisp/org-exp.el

@@ -1054,7 +1054,9 @@ value of `org-export-run-in-background'."
     (setq r2 (if (< r1 27) (+ r1 96) r1))
     (unless (setq ass (assq r2 cmds))
       (error "No command associated with key %c" r1))
-    (if (and bg (nth 2 ass))
+    (if (and bg (nth 2 ass)
+	     (not (buffer-base-buffer))
+	     (not (org-region-active-p)))
 	;; execute in background
 	(let ((p (start-process
 		  (concat "Exporting " (file-name-nondirectory (buffer-file-name)))

+ 29 - 25
lisp/org-publish.el

@@ -479,31 +479,35 @@ PUB-DIR is the publishing directory."
   (require 'org)
   (unless (file-exists-p pub-dir)
     (make-directory pub-dir t))
-  (let* ((visiting (find-buffer-visiting filename))
-	 (plist (cons :buffer-will-be-killed (cons t plist)))
-	 (init-buf (or visiting (find-file filename)))
-	 (init-point (point))
-	 (init-buf-string (buffer-string)) export-buf-or-file)
-    ;; run hooks before exporting
-    (run-hooks 'org-publish-before-export-hook)
-    ;; export the possibly modified buffer
-    (setq export-buf-or-file
-	  (funcall (intern (concat "org-export-as-" format))
-		   (plist-get plist :headline-levels)
-		   nil plist nil nil pub-dir))
-    (when (and (bufferp export-buf-or-file) (buffer-live-p export-buf-or-file))
-      (set-buffer export-buf-or-file)
-      ;; run hooks after export and save export
-      (and (run-hooks 'org-publish-after-export-hook)
-	   (if (buffer-modified-p) (save-buffer)))
-      (kill-buffer export-buf-or-file))
-    ;; maybe restore buffer's content
-    (set-buffer init-buf)
-    (when (buffer-modified-p init-buf)
-      (erase-buffer)
-      (insert init-buf-string)
-      (save-buffer)
-      (goto-char init-point))
+  (let ((visiting (find-buffer-visiting filename)))
+    (save-excursion
+      (switch-to-buffer (or visiting (find-file visiting)))
+      (let* ((plist (cons :buffer-will-be-killed (cons t plist)))
+	     (init-buf (current-buffer))
+	     (init-point (point))
+	     (init-buf-string (buffer-string))
+	     export-buf-or-file)
+	;; run hooks before exporting
+	(run-hooks 'org-publish-before-export-hook)
+	;; export the possibly modified buffer
+	(setq export-buf-or-file
+	      (funcall (intern (concat "org-export-as-" format))
+		       (plist-get plist :headline-levels)
+		       nil plist nil nil pub-dir))
+	(when (and (bufferp export-buf-or-file)
+		   (buffer-live-p export-buf-or-file))
+	  (set-buffer export-buf-or-file)
+	  ;; run hooks after export and save export
+	  (and (run-hooks 'org-publish-after-export-hook)
+	       (if (buffer-modified-p) (save-buffer)))
+	  (kill-buffer export-buf-or-file))
+	;; maybe restore buffer's content
+	(set-buffer init-buf)
+	(when (buffer-modified-p init-buf)
+	  (erase-buffer)
+	  (insert init-buf-string)
+	  (save-buffer)
+	  (goto-char init-point))))
     (unless visiting
       (kill-buffer init-buf))))