Browse Source

org-archive: fix archiving from an indirect buffer

* lisp/org-archive.el (org-extract-archive-file,
  org-extract-archive-heading, org-archive-subtree): buffer-file-name
  is nil in an indirect buffer. Thus,
  use (buffer-file-name (buffer-base-buffer)), which will, in any
  case, return the file-name.

Thanks to Ilya Shlyakhter for reporting and analyzing this.
Nicolas Goaziou 13 years ago
parent
commit
26ba1b3680
1 changed files with 6 additions and 4 deletions
  1. 6 4
      lisp/org-archive.el

+ 6 - 4
lisp/org-archive.el

@@ -165,10 +165,11 @@ if LOCATION is not given, the value of `org-archive-location' is used."
   (setq location (or location org-archive-location))
   (if (string-match "\\(.*\\)::\\(.*\\)" location)
       (if (= (match-beginning 1) (match-end 1))
-	  (buffer-file-name)
+	  (buffer-file-name (buffer-base-buffer))
 	(expand-file-name
 	 (format (match-string 1 location)
-		 (file-name-nondirectory buffer-file-name))))))
+		 (file-name-nondirectory
+		  (buffer-file-name (buffer-base-buffer))))))))
 
 (defun org-extract-archive-heading (&optional location)
   "Extract the heading from archive LOCATION.
@@ -176,7 +177,8 @@ if LOCATION is not given, the value of `org-archive-location' is used."
   (setq location (or location org-archive-location))
   (if (string-match "\\(.*\\)::\\(.*\\)" location)
       (format (match-string 2 location)
-	      (file-name-nondirectory buffer-file-name))))
+	      (file-name-nondirectory
+	       (buffer-file-name (buffer-base-buffer))))))
 
 (defun org-archive-subtree (&optional find-done)
   "Move the current subtree to the archive.
@@ -205,7 +207,7 @@ this heading."
 	   (this-buffer (current-buffer))
 	   ;; start of variables that will be used for saving context
 	   ;; The compiler complains about them - keep them anyway!
-	   (file (abbreviate-file-name (buffer-file-name)))
+	   (file (abbreviate-file-name (buffer-file-name (buffer-base-buffer))))
 	   (olpath (mapconcat 'identity (org-get-outline-path) "/"))
 	   (time (format-time-string
 		  (substring (cdr org-time-stamp-formats) 1 -1)