Browse Source

org-mobile.el: More flexibility to add files

The new variable org-mobile-files can now be configured to include
non-agenda files into the staging area for MobileOrg.  Furthermore,
files that are located in a subdirectory of `org-directory' will also
end up in a sub-directory in the staging area.
Carsten Dominik 15 years ago
parent
commit
d90df8b147
4 changed files with 105 additions and 21 deletions
  1. 4 0
      doc/ChangeLog
  2. 20 16
      doc/org.texi
  3. 9 0
      lisp/ChangeLog
  4. 72 5
      lisp/org-mobile.el

+ 4 - 0
doc/ChangeLog

@@ -1,3 +1,7 @@
+2009-09-28  Carsten Dominik  <carsten.dominik@gmail.com>
+
+	* org.texi (Pushing to MobileOrg): Document `org-mobile-files'.
+
 2009-09-26  Carsten Dominik  <carsten.dominik@gmail.com>
 
 	* org.texi (Processing LaTeX fragments): Document that the size of

+ 20 - 16
doc/org.texi

@@ -11680,10 +11680,10 @@ operation of @i{MobileOrg} itself (see @uref{http://ncogni.to/mobileorg/}).
 @node Setting up the staging area, Pushing to MobileOrg, MobileOrg, MobileOrg
 @section Setting up the staging area
 
-Org-mode has commands to prepare a directory with files for @i{MobileOrg}, and to
-read captured notes from there.  If Emacs can directly write to the WebDAV
-directory accessed by @i{MobileOrg}, all you need to do is to point to this
-directory using the variable @code{org-mobile-directory}.
+Org-mode has commands to prepare a directory with files for @i{MobileOrg},
+and to read captured notes from there.  If Emacs can directly write to the
+WebDAV directory accessed by @i{MobileOrg}, all you need to do is to point to
+this directory using the variable @code{org-mobile-directory}.
 
 If Emacs cannot access the WebDAV directory directly, you can use a local
 directory for staging.  Other means must then be used to keep this directory
@@ -11707,18 +11707,22 @@ from the WebDAV directory using @file{scp}.
 @node Pushing to MobileOrg, Pulling from MobileOrg, Setting up the staging area, MobileOrg
 @section Pushing to MobileOrg
 
-
-This operation copies all files currently listed in @code{org-agenda-files}
-to the directory @code{org-mobile-directory}.  It also creates (in the same
-directory) a special Org file @file{agendas.org}.  This file is an Org-mode
-style outline, containing every custom agenda view defined by the user.
-While creating the agendas, Org-mode will force@footnote{See the variable
-@code{org-mobile-force-id-on-agenda-items}.} an ID property on all entries
-referenced by the agendas, so that these entries can be uniquely identified
-if @i{MobileOrg} flags them for further action.  Finally, Org writes the file
-@file{index.org}, containing links to all other files.  If @i{MobileOrg} is
-configured to request this file from the WebDAV server, all agendas and Org
-files will be downloaded to the iPhone.
+This operation copies all files currently listed in @code{org-mobile-files}
+to the directory @code{org-mobile-directory}.  By default this list contains
+all agenda files (as listed in @code{org-agenda-files}), but additional files
+can be included by customizing @code{org-mobiles-files}.  The push operation
+also creates (in the same directory) a special Org file @file{agendas.org}.
+This file is an Org-mode style outline, containing every custom agenda view
+defined by the user.  While creating the agendas, Org-mode will
+force@footnote{See the variable @code{org-mobile-force-id-on-agenda-items}.}
+an ID property on all entries referenced by the agendas, so that these
+entries can be uniquely identified if @i{MobileOrg} flags them for further
+action.  Finally, Org writes the file @file{index.org}, containing links to
+all other files.  If @i{MobileOrg} is configured to request this file from
+the WebDAV server, all agendas and Org files will be downloaded to the
+iPhone.  To speed up the download, MobileOrg will only read files whose
+checksums@footnote{stored automatically in the file @file{checksums.dat}}
+have changed.
 
 @node Pulling from MobileOrg,  , Pushing to MobileOrg, MobileOrg
 @section Pulling from MobileOrg

+ 9 - 0
lisp/ChangeLog

@@ -2,6 +2,15 @@
 
 	* org-mobile.el (org-mobile-files-alist): Add the list of tags to
 	the index file.
+	(org-mobile-files): New option.
+	(org-mobile-files-alist, org-mobile-checksum-files): New variable.
+	(org-mobile-prepare-file-lists, org-mobile-files-alist): New
+	functions.
+	(org-mobile-push): Start by creating the files lists.
+	(org-mobile-copy-agenda-files): Move killing the buffer to after
+	the save-excursion has exited.
+	(org-mobile-write-checksums): Write checksums also for files in
+	sub-directories.
 
 	* org.el (org-ctrl-c-ctrl-c): Pass prefix arg to
 	org-table-recalculate when cursor is in TBLFM line.

+ 72 - 5
lisp/org-mobile.el

@@ -27,7 +27,9 @@
 ;;
 ;; This file contains the code to interact with Richard Moreland's iPhone
 ;; application MobileOrg.  This code is documented in Appendix B of the
-;; Org-mode manual.
+;; Org-mode manual.  The code is not specific for the iPhone, however.
+;; Any external viewer and flagging application that uses the same
+;; conventions could be used.
 
 (require 'org)
 (require 'org-agenda)
@@ -37,6 +39,26 @@
   :tag "Org Mobile"
   :group 'org)
 
+(defcustom org-mobile-files '(org-agenda-files)
+  "Files to be staged for MobileOrg.
+This is basically a list of filesand directories.  Files will be staged
+directly.  Directories will be search for files with the extension `.org'.
+In addition to this, the list may also contain the following symbols:
+
+org-agenda-files
+     This means, include the complete, unrestricted list of files given in
+     the variable `org-agenda-files'.
+org-agenda-text-search-extra-files
+     Include the files given in the variable
+     `org-agenda-text-search-extra-files'"
+  :group 'org-mobile
+  :type '(list :greedy t
+	       (option (const :tag "org-agenda-files" org-agenda-files))
+	       (option (const :tag "org-agenda-text-search-extra-files"
+			      org-agenda-text-search-extra-files))
+	       (repeat :inline t :tag "Additional files"
+		       (file))))
+
 (defcustom org-mobile-directory ""
   "The WebDAV directory where the interaction with the mobile takes place."
   :group 'org-mobile
@@ -115,6 +137,43 @@ using `rsync' or `scp'.")
 (defvar org-mobile-last-flagged-files nil
   "List of files containing entreis flagged in the latest pull.")
 
+(defvar org-mobile-files-alist nil)
+(defvar org-mobile-checksum-files nil)
+
+(defun org-mobile-prepare-file-lists ()
+  (setq org-mobile-files-alist (org-mobile-files-alist))
+  (setq org-mobile-checksum-files (mapcar 'cdr org-mobile-files-alist)))
+
+(defun org-mobile-files-alist ()
+  "Expand the list in `org-mobile-files' to a list of existing files."
+  (let* ((files
+	  (apply 'append (mapcar
+			  (lambda (f)
+			    (cond
+			     ((eq f 'org-agenda-files) (org-agenda-files t))
+			     ((eq f 'org-agenda-text-search-extra-files)
+			      org-agenda-text-search-extra-files)
+			     ((and (stringp f) (file-directory-p f))
+			      (directory-files f 'full "\\.org\\'"))
+			     ((and (stringp f) (file-exists-p f))
+			      (list f))
+			     (t nil)))
+			  org-mobile-files)))
+	 (orgdir-uname (file-name-as-directory (file-truename org-directory)))
+	 (orgdir-re (concat "\\`" (regexp-quote orgdir-uname)))
+	 uname seen rtn)
+    ;; Make the files unique, and determine the name under which they will
+    ;; be listed.
+    (while (setq file (pop files))
+      (setq uname (file-truename file))
+      (unless (member uname seen)
+	(push uname seen)
+	(if (string-match orgdir-re uname)
+	    (setq link-name (substring uname (match-end 0)))
+	  (setq link-name (file-name-nondirectory uname)))
+	(push (cons file link-name) rtn)))
+    (nreverse rtn)))
+
 ;;;###autoload
 (defun org-mobile-push ()
   "Push the current state of Org affairs to the WebDAV directory.
@@ -122,6 +181,7 @@ This will create the index file, copy all agenda files there, and also
 create all custom agenda views, for upload to the mobile phone."
   (interactive)
   (org-mobile-check-setup)
+  (org-mobile-prepare-file-lists)
   (run-hooks 'org-mobile-pre-push-hook)
   (org-mobile-create-sumo-agenda)
   (org-save-all-org-buffers) ; to save any IDs created by this process
@@ -222,8 +282,8 @@ agenda view showing the flagged items."
       (save-excursion
 	(setq buf (find-file file))
 	(insert "\n")
-	(save-buffer)
-      (kill-buffer buf)))))
+	(save-buffer))
+      (kill-buffer buf))))
 
 (defun org-mobile-write-checksums ()
   "Create checksums for all files in `org-mobile-directory'.
@@ -231,12 +291,19 @@ The table of checksums is written to the file mobile-checksums."
   (let ((cmd (cond ((executable-find "shasum"))
 		   ((executable-find "sha1sum"))
 		   ((executable-find "md5sum"))
-		   ((executable-find "md5")))))
+		   ((executable-find "md5"))))
+	(files org-mobile-checksum-files))
     (if (not cmd)
 	(message "Checksums could not be generated: no executable")
       (with-temp-buffer
 	(cd org-mobile-directory)
-	(if (equal 0 (shell-command (concat cmd " *.org > checksums.dat")))
+	(if (file-exists-p "agendas.org")
+	    (push "agendas.org" files))
+	(if (file-exists-p "mobileorg.org")
+	    (push "mobileorg.org" files))
+	(setq cmd (concat cmd " " (mapconcat 'shell-quote-argument files " ")
+			  " > checksums.dat"))
+	(if (equal 0 (shell-command cmd))
 	    (message "Checksums written")
 	  (message "Checksums could not be generated"))))))