Function: org-mobile-write-agenda-for-mobile

org-mobile-write-agenda-for-mobile is a byte-compiled function defined in org-mobile.el.gz.

Signature

(org-mobile-write-agenda-for-mobile FILE)

Source Code

;; Defined in /usr/src/emacs/lisp/org/org-mobile.el.gz
(defun org-mobile-write-agenda-for-mobile (file)
  (let ((all (buffer-string)) in-date id pl prefix line app short m sexp)
    (with-temp-file file
      (org-mode)
      (insert "#+READONLY\n")
      (insert all)
      (goto-char (point-min))
      (while (not (eobp))
	(cond
	 ((looking-at "[ \t]*$")) ; keep empty lines
	 ((looking-at "=+$")
	  ;; remove underlining
          (delete-region (point) (line-end-position)))
	 ((get-text-property (point) 'org-agenda-structural-header)
	  (setq in-date nil)
	  (setq app (get-text-property (point) 'org-agenda-title-append))
	  (setq short (get-text-property (point) 'short-heading))
	  (when (and short (looking-at ".+"))
	    (replace-match short nil t)
	    (beginning-of-line 1))
	  (when app
	    (end-of-line 1)
	    (insert app)
	    (beginning-of-line 1))
	  (insert "* "))
	 ((get-text-property (point) 'org-agenda-date-header)
	  (setq in-date t)
	  (insert "** "))
	 ((setq m (or (get-text-property (point) 'org-hd-marker)
		      (get-text-property (point) 'org-marker)))
	  (setq sexp (member (get-text-property (point) 'type)
			     '("diary" "sexp")))
          (if (setq pl (text-property-any (point) (line-end-position) 'org-heading t))
	      (progn
		(setq prefix (org-trim (buffer-substring
					(point) pl))
		      line (org-trim (buffer-substring
				      pl
                                      (line-end-position))))
                (delete-region (line-beginning-position) (line-end-position))
		(insert line "<before>" prefix "</before>")
		(beginning-of-line 1))
	    (and (looking-at "[ \t]+") (replace-match "")))
	  (insert (if in-date "***  " "**  "))
	  (end-of-line 1)
	  (insert "\n")
	  (unless sexp
	    (insert (org-agenda-get-some-entry-text
		     m 10 "   " 'planning)
		    "\n")
	    (when (setq id
			(if (bound-and-true-p
			     org-mobile-force-id-on-agenda-items)
			    (org-id-get m 'create)
			  (or (org-entry-get m "ID")
			      (org-mobile-get-outline-path-link m))))
	      (insert "   :PROPERTIES:\n   :ORIGINAL_ID: " id
		      "\n   :END:\n")))))
	(beginning-of-line 2))
      (push (cons "agendas.org" (md5 (buffer-string)))
	    org-mobile-checksum-files))
    (message "Agenda written to Org file %s" file)))