Browse Source

Don't create UID for the entire file when write an agenda to .ics

* org-agenda.el (org-agenda-collect-markers)
(org-create-marker-find-array): Move to ox-icalendar.el.
(org-agenda-marker-table, org-check-agenda-marker-table):
Delete.

* ox-icalendar.el (org-icalendar-create-uid): New parameter
H-MARKERS to only update some headlines, not the whole file.
(org-icalendar--combine-files): When exporting to an .ics file
only add UID to the headlines shown in the agenda buffer.
(org-agenda-collect-markers, org-create-marker-find-array):
Move here.
Bastien Guerry 12 years ago
parent
commit
ccc7383890
2 changed files with 39 additions and 50 deletions
  1. 0 37
      lisp/org-agenda.el
  2. 39 13
      lisp/ox-icalendar.el

+ 0 - 37
lisp/org-agenda.el

@@ -3432,43 +3432,6 @@ removed from the entry content.  Currently only `planning' is allowed here."
 		(setq txt (buffer-substring (point-min) (point)))))))))
 		(setq txt (buffer-substring (point-min) (point)))))))))
     txt))
     txt))
 
 
-(defun org-agenda-collect-markers ()
-  "Collect the markers pointing to entries in the agenda buffer."
-  (let (m markers)
-    (save-excursion
-      (goto-char (point-min))
-      (while (not (eobp))
-	(when (setq m (or (org-get-at-bol 'org-hd-marker)
-			  (org-get-at-bol 'org-marker)))
-	  (push m markers))
-	(beginning-of-line 2)))
-    (nreverse markers)))
-
-(defun org-create-marker-find-array (marker-list)
-  "Create a alist of files names with all marker positions in that file."
-  (let (f tbl m a p)
-    (while (setq m (pop marker-list))
-      (setq p (marker-position m)
-	    f (buffer-file-name (or (buffer-base-buffer
-				     (marker-buffer m))
-				    (marker-buffer m))))
-      (if (setq a (assoc f tbl))
-	  (push (marker-position m) (cdr a))
-	(push (list f p) tbl)))
-    (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
-	    tbl)))
-
-(defvar org-agenda-marker-table nil) ; dynamically scoped parameter
-(defun org-check-agenda-marker-table ()
-  "Check of the current entry is on the marker list."
-  (let ((file (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
-	a)
-    (and (setq a (assoc file org-agenda-marker-table))
-	 (save-match-data
-	   (save-excursion
-	     (org-back-to-heading t)
-	     (member (point) (cdr a)))))))
-
 (defun org-check-for-org-mode ()
 (defun org-check-for-org-mode ()
   "Make sure current buffer is in org-mode.  Error if not."
   "Make sure current buffer is in org-mode.  Error if not."
   (or (derived-mode-p 'org-mode)
   (or (derived-mode-p 'org-mode)

+ 39 - 13
lisp/ox-icalendar.el

@@ -285,20 +285,23 @@ re-read the iCalendar file.")
 
 
 ;;; Internal Functions
 ;;; Internal Functions
 
 
-(defun org-icalendar-create-uid (file &optional bell)
+(defun org-icalendar-create-uid (file &optional bell h-markers)
   "Set ID property on headlines missing it in FILE.
   "Set ID property on headlines missing it in FILE.
 When optional argument BELL is non-nil, inform the user with
 When optional argument BELL is non-nil, inform the user with
-a message if the file was modified."
+a message if the file was modified.  With optional argument
-  (let (modified-flag)
+H-MARKERS non-nil, it is a list of markers for the headlines
+which will be updated."
+  (let (modified-flag pt)
+    (when h-markers (setq pt (goto-char (car h-markers))))
     (org-map-entries
     (org-map-entries
      (lambda ()
      (lambda ()
        (let ((entry (org-element-at-point)))
        (let ((entry (org-element-at-point)))
-	 (unless (org-element-property :ID entry)
+	 (unless (or (< (point) pt) (org-element-property :ID entry))
 	   (org-id-get-create)
 	   (org-id-get-create)
 	   (setq modified-flag t)
 	   (setq modified-flag t)
 	   (forward-line))
 	   (forward-line))
-	 (when (eq (org-element-type entry) 'inlinetask)
+	 (setq org-map-continue-from
-	   (setq org-map-continue-from (org-element-property :end entry)))))
+	       (if h-markers (pop h-markers) (point-max)))))
      nil nil 'comment)
      nil nil 'comment)
     (when (and bell modified-flag)
     (when (and bell modified-flag)
       (message "ID properties created in file \"%s\"" file)
       (message "ID properties created in file \"%s\"" file)
@@ -888,8 +891,32 @@ The file is stored under the name chosen in
 	  `(apply 'org-icalendar--combine-files nil ',files)))
 	  `(apply 'org-icalendar--combine-files nil ',files)))
     (apply 'org-icalendar--combine-files nil (org-agenda-files t))))
     (apply 'org-icalendar--combine-files nil (org-agenda-files t))))
 
 
-(declare-function org-agenda-collect-markers "org-agenda" ())
+(defun org-agenda-collect-markers ()
-(declare-function org-create-marker-find-array "org-agenda" (marker-list))
+  "Collect the markers pointing to entries in the agenda buffer."
+  (let (m markers)
+    (save-excursion
+      (goto-char (point-min))
+      (while (not (eobp))
+	(when (setq m (or (org-get-at-bol 'org-hd-marker)
+			  (org-get-at-bol 'org-marker)))
+	  (push m markers))
+	(beginning-of-line 2)))
+    (nreverse markers)))
+
+(defun org-create-marker-find-array (marker-list)
+  "Create an alist of files names with all marker positions in that file."
+  (let (f tbl m a p)
+    (while (setq m (pop marker-list))
+      (setq p (marker-position m)
+	    f (buffer-file-name
+	       (or (buffer-base-buffer (marker-buffer m))
+		   (marker-buffer m))))
+      (if (setq a (assoc f tbl))
+	  (push (marker-position m) (cdr a))
+	(push (list f p) tbl)))
+    (mapcar (lambda (x) (setcdr x (sort (copy-sequence (cdr x)) '<)) x)
+	    tbl)))
+
 (defun org-icalendar-export-current-agenda (file)
 (defun org-icalendar-export-current-agenda (file)
   "Export current agenda view to an iCalendar FILE.
   "Export current agenda view to an iCalendar FILE.
 This function assumes major mode for current buffer is
 This function assumes major mode for current buffer is
@@ -930,11 +957,10 @@ files to build the calendar from."
 		(catch 'nextfile
 		(catch 'nextfile
 		  (org-check-agenda-file file)
 		  (org-check-agenda-file file)
 		  (with-current-buffer (org-get-agenda-file-buffer file)
 		  (with-current-buffer (org-get-agenda-file-buffer file)
-		    ;; Create ID if necessary.
+		    (let ((marks (cdr (assoc (expand-file-name file) restriction))))
-		    (when org-icalendar-store-UID
+		      ;; Create ID if necessary.
-		      (org-icalendar-create-uid file))
+		      (when org-icalendar-store-UID
-		    (let ((marks (cdr (assoc (expand-file-name file)
+			(org-icalendar-create-uid file t marks))
-					     restriction))))
 		      (unless (and restriction (not marks))
 		      (unless (and restriction (not marks))
 			;; Add a hook adding :ICALENDAR_MARK: property
 			;; Add a hook adding :ICALENDAR_MARK: property
 			;; to each entry appearing in agenda view.
 			;; to each entry appearing in agenda view.