Function: org-mobile-create-index-file

org-mobile-create-index-file is a byte-compiled function defined in org-mobile.el.gz.

Signature

(org-mobile-create-index-file)

Documentation

Write the index file in the WebDAV directory.

Source Code

;; Defined in /usr/src/emacs/lisp/org/org-mobile.el.gz
(defun org-mobile-create-index-file ()
  "Write the index file in the WebDAV directory."
  (let ((files-alist (sort (copy-sequence org-mobile-files-alist)
			   (lambda (a b) (string< (cdr a) (cdr b)))))
	(def-todo (default-value 'org-todo-keywords))
	(def-tags org-tag-alist)
	(target-file (expand-file-name org-mobile-index-file
				       org-mobile-directory))
	todo-kwds done-kwds tags)
    (when (stringp (car def-todo))
      (setq def-todo (list (cons 'sequence def-todo))))
    (org-agenda-prepare-buffers (mapcar 'car files-alist))
    (setq done-kwds (org-uniquify org-done-keywords-for-agenda))
    (setq todo-kwds (org-delete-all
		     done-kwds
		     (org-uniquify org-todo-keywords-for-agenda)))
    (setq tags (mapcar 'car (org-global-tags-completion-table
			     (mapcar 'car files-alist))))
    (with-temp-file (if org-mobile-use-encryption org-mobile-encryption-tempfile
		      target-file)
      (insert "#+READONLY\n")
      (dolist (entry def-todo)
	(let ((kwds (mapcar (lambda (x)
			      (if (string-match "(" x)
				  (substring x 0 (match-beginning 0))
				x))
			    (cdr entry))))
	  (insert "#+TODO: " (mapconcat #'identity kwds " ") "\n")
	  (let* ((dwds (or (member "|" kwds) (last kwds)))
		 (twds (org-delete-all dwds kwds)))
	    (setq todo-kwds (org-delete-all twds todo-kwds))
	    (setq done-kwds (org-delete-all dwds done-kwds)))))
      (when (or todo-kwds done-kwds)
	(insert "#+TODO: " (mapconcat 'identity todo-kwds " ") " | "
		(mapconcat 'identity done-kwds " ") "\n"))
      (setq def-tags (split-string (org-tag-alist-to-string def-tags t)))
      (setq tags (org-delete-all def-tags tags))
      (setq tags (sort tags (lambda (a b) (string< (downcase a) (downcase b)))))
      (setq tags (append def-tags tags nil))
      (insert "#+TAGS: " (mapconcat 'identity tags " ") "\n")
      (insert "#+ALLPRIORITIES: " org-mobile-allpriorities "\n")
      (when (file-exists-p (expand-file-name
			    "agendas.org" org-mobile-directory))
	(insert "* [[file:agendas.org][Agenda Views]]\n"))
      (pcase-dolist (`(,_ . ,link-name) files-alist)
	(insert (format "* [[file:%s][%s]]\n" link-name link-name)))
      (push (cons org-mobile-index-file (md5 (buffer-string)))
	    org-mobile-checksum-files))
    (when org-mobile-use-encryption
      (org-mobile-encrypt-and-move org-mobile-encryption-tempfile
				   target-file)
      (org-mobile-cleanup-encryption-tempfile))))