emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Bug: EOL needs to be converted to Unix for MobileOrg files [7.5 (release_7.5.147.g9ddc)]
@ 2011-04-07 14:06 Charles Sebold
  2011-05-03 16:57 ` charles.sebold
  0 siblings, 1 reply; 3+ messages in thread
From: Charles Sebold @ 2011-04-07 14:06 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 901 bytes --]

Second attempt to send this patch.

I primarily use Org-mode on Windows, and my org files mostly have DOS
line endings.  A while back a patch from me was accepted to convert the
checksum file to Unix EOLs (and Richard updated the iOS app to be
agnostic about it, I think, at the same time), which saved a lot of
syncing because the checksum file never looked right to MobileOrg.

However, the files themselves are irritating because they appear to have
double line feeds when they are viewed on the iOS device, and edits from
MobileOrg never sync because stray ^Ms creep in.

This patch makes all files pushed to MobileOrg into Unix files as far as
line endings go.

It's not a very elegant solution and my feelings won't be hurt if a
better way is proposed.

Emacs  : GNU Emacs 24.0.50.1 (i386-mingw-nt5.1.2600)
 of 2011-04-05 on CT-SEBOLDCR-T4C
Package: Org-mode version 7.5 (release_7.5.147.g9ddc)

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: patch to fix org-mobile.el --]
[-- Type: text/x-diff, Size: 2121 bytes --]

Changes in master
	Modified lisp/org-mobile.el
diff --git a/lisp/org-mobile.el b/lisp/org-mobile.el
index 83462f0..fa1d4f4 100644
--- a/lisp/org-mobile.el
+++ b/lisp/org-mobile.el
@@ -472,6 +472,12 @@ agenda view showing the flagged items."
 				   target-file)
       (org-mobile-cleanup-encryption-tempfile))))
 
+(defun org-mobile-copy-file (file newname)
+  "Copy file, converting to Unix line endings."
+  (with-temp-file newname
+    (set-buffer-file-coding-system 'undecided-unix nil)
+    (insert-file-contents file)))
+
 (defun org-mobile-copy-agenda-files ()
   "Copy all agenda files to the stage or WebDAV directory."
   (let ((files-alist org-mobile-files-alist)
@@ -485,7 +491,7 @@ agenda view showing the flagged items."
 	  (make-directory target-dir 'parents))
 	(if org-mobile-use-encryption
 	    (org-mobile-encrypt-and-move file target-path)
-	  (copy-file file target-path 'ok-if-exists))
+	  (org-mobile-copy-file file target-path))
 	(setq check (shell-command-to-string
 		     (concat org-mobile-checksum-binary " "
 			     (shell-quote-argument (expand-file-name file)))))
@@ -710,12 +716,15 @@ encryption program does not understand them."
 
 (defun org-mobile-encrypt-file (infile outfile)
   "Encrypt INFILE to OUTFILE, using `org-mobile-encryption-password'."
-  (shell-command
-   (format "openssl enc -aes-256-cbc -salt -pass %s -in %s -out %s"
-	   (shell-quote-argument (concat "pass:"
-					 (org-mobile-encryption-password)))
-	   (shell-quote-argument (expand-file-name infile))
-	   (shell-quote-argument (expand-file-name outfile)))))
+  (let ((tempfile (make-temp-file "orgmobile")))
+    (org-mobile-copy-file infile tempfile)
+    (shell-command
+     (format "openssl enc -aes-256-cbc -salt -pass %s -in %s -out %s"
+	     (shell-quote-argument (concat "pass:"
+					   (org-mobile-encryption-password)))
+	     (shell-quote-argument (expand-file-name tempfile))
+	     (shell-quote-argument (expand-file-name outfile))))
+    (delete-file tempfile)))
 
 (defun org-mobile-decrypt-file (infile outfile)
   "Decrypt INFILE to OUTFILE, using `org-mobile-encryption-password'."


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: Bug: EOL needs to be converted to Unix for MobileOrg files [7.5 (release_7.5.147.g9ddc)]
  2011-04-07 14:06 Bug: EOL needs to be converted to Unix for MobileOrg files [7.5 (release_7.5.147.g9ddc)] Charles Sebold
@ 2011-05-03 16:57 ` charles.sebold
  2011-05-04 14:29   ` Sebold, Charles
  0 siblings, 1 reply; 3+ messages in thread
From: charles.sebold @ 2011-05-03 16:57 UTC (permalink / raw)
  To: emacs-orgmode

On 7 Apr 2011, Charles Sebold wrote:

> Second attempt to send this patch.
>
> I primarily use Org-mode on Windows, and my org files mostly have DOS
> line endings.  A while back a patch from me was accepted to convert
> the checksum file to Unix EOLs (and Richard updated the iOS app to be
> agnostic about it, I think, at the same time), which saved a lot of
> syncing because the checksum file never looked right to MobileOrg.
>
> However, the files themselves are irritating because they appear to
> have double line feeds when they are viewed on the iOS device, and
> edits from MobileOrg never sync because stray ^Ms creep in.
>
> This patch makes all files pushed to MobileOrg into Unix files as far
> as line endings go.
>
> It's not a very elegant solution and my feelings won't be hurt if a
> better way is proposed.

I'm bumping this.  I think the patch attached to the last post could be
better, but failing a response for now, I've decided that rather than
drag my changes along, I'm just advising the necessary functions.

So, to get this to work for Emacs on Windows + MobileOrg, the following
is in my .emacs file.  Hopefully this will be helpful for somebody:

#+BEGIN_SRC emacs-lisp
; bug fix for org-mobile
(defun org-mobile-copy-file (file newname)
  "Copy file, converting to Unix line endings."
  (with-temp-file newname
    (set-buffer-file-coding-system 'undecided-unix nil)
    (insert-file-contents file)))

(eval-and-compile
  (require 'cl)) ; for flet

(defadvice org-mobile-copy-agenda-files (around
                                         crs-org-mobile-copy-agenda-files)
  "Copy agenda files to mobile device with Unix EOLs."
  (flet ((copy-file (file newname &optional ok-if-already-exists keep-time
                          preserve-uid-gid preserve-selinux-context)
                    (let ((tempfile (make-temp-file "orgmobile")))
                      (org-mobile-copy-file file tempfile)
                      (copy-file tempfile newname ok-if-already-exists
                                 keep-time preserve-uid-gid
                                 preserve-selinux-context)
                      (delete-file tempfile))))
    ad-do-it))

(defadvice org-mobile-encrypt-file (around crs-org-mobile-encrypt-file)
  "Encrypt INFILE to OUTFILE with Unix EOLs."
  (let ((tempfile (make-temp-file "orgmobile")))
    (org-mobile-copy-file infile tempfile)
    (ad-set-arg 0 tempfile)
    ad-do-it
    (delete-file tempfile)))

(ad-activate 'org-mobile-copy-agenda-files)
(ad-activate 'org-mobile-encrypt-file)
#+END_SRC
-- 
Charles Sebold                                          3rd of May, 2011
GNU Emacs 24.0.50.1 (i386-mingw-nt5.1.2600) | No Gnus v0.18 | org-mode 7.5
 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Bug: EOL needs to be converted to Unix for MobileOrg files [7.5 (release_7.5.147.g9ddc)]
  2011-05-03 16:57 ` charles.sebold
@ 2011-05-04 14:29   ` Sebold, Charles
  0 siblings, 0 replies; 3+ messages in thread
From: Sebold, Charles @ 2011-05-04 14:29 UTC (permalink / raw)
  To: emacs-orgmode; +Cc: tdavey

On 3 May 2011, charles sebold wrote:

> I'm bumping this.  I think the patch attached to the last post could
> be better, but failing a response for now, I've decided that rather
> than drag my changes along, I'm just advising the necessary functions.
>
> So, to get this to work for Emacs on Windows + MobileOrg, the
> following is in my .emacs file.  Hopefully this will be helpful for
> somebody:

What I attached didn't work; I ended up flet-ing copy-file just a little
too much.

I've had to fall back to essentially redefining
org-mobile-copy-agenda-files.  Here's what I've got in my .emacs now,
but it's subject to break if org-mobile-copy-agenda-files ever changes.

I would like somebody to consider forcing all the output files
(pre-encryption obviously, if encryption is enabled) to unix line
endings in some more correct way than I have done.

#+BEGIN_SRC emacs-lisp
; bug fix for org-mobile
(defun org-mobile-copy-file (file newname)
  "Copy file, converting to Unix line endings."
  (with-temp-file newname
    (set-buffer-file-coding-system 'undecided-unix nil)
    (insert-file-contents file)))

(eval-and-compile
  (require 'cl)) ; for flet

(defadvice org-mobile-copy-agenda-files (around
                                         crs-org-mobile-copy-agenda-files)
  "Copy agenda files to mobile device with Unix EOLs."
  (let ((files-alist org-mobile-files-alist)
	file buf entry link-name target-path target-dir check)
    (while (setq entry (pop files-alist))
      (setq file (car entry) link-name (cdr entry))
      (when (file-exists-p file)
	(setq target-path (expand-file-name link-name org-mobile-directory)
	      target-dir (file-name-directory target-path))
	(unless (file-directory-p target-dir)
	  (make-directory target-dir 'parents))
	(if org-mobile-use-encryption
	    (org-mobile-encrypt-and-move file target-path)
	  (org-mobile-copy-file file target-path 'ok-if-exists))
	(setq check (shell-command-to-string
		     (concat org-mobile-checksum-binary " "
			     (shell-quote-argument (expand-file-name file)))))
	(when (string-match "[a-fA-F0-9]\\{30,40\\}" check)
	  (push (cons link-name (match-string 0 check))
		org-mobile-checksum-files))))

    (setq file (expand-file-name org-mobile-capture-file
				 org-mobile-directory))
    (save-excursion
      (setq buf (find-file file))
      (when (and (= (point-min) (point-max))) 
	(insert "\n")
	(save-buffer)
	(when org-mobile-use-encryption
	  (write-file org-mobile-encryption-tempfile)
	  (org-mobile-encrypt-and-move org-mobile-encryption-tempfile file)))
      (push (cons org-mobile-capture-file (md5 (buffer-string)))
	    org-mobile-checksum-files))
    (org-mobile-cleanup-encryption-tempfile)
    (kill-buffer buf)))

(defadvice org-mobile-encrypt-file (around crs-org-mobile-encrypt-file)
  "Encrypt INFILE to OUTFILE with Unix EOLs."
  (let ((tempfile (make-temp-file "orgmobile")))
    (org-mobile-copy-file infile tempfile)
    (ad-set-arg 0 tempfile)
    ad-do-it
    (delete-file tempfile)))

(ad-activate 'org-mobile-copy-agenda-files)
(ad-activate 'org-mobile-encrypt-file)
#+END_SRC
-- 
Charles Sebold                                          4th of May, 2011
              GNU Emacs 24.0.50.1 (i386-mingw-nt5.1.2600)
     No Gnus v0.18 | Org-mode version 7.5 (release_7.5.249.gbf7ce)

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-05-04 14:29 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-04-07 14:06 Bug: EOL needs to be converted to Unix for MobileOrg files [7.5 (release_7.5.147.g9ddc)] Charles Sebold
2011-05-03 16:57 ` charles.sebold
2011-05-04 14:29   ` Sebold, Charles

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).