Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Click here to return to the 'Temp File Unnecessary -- summary' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Temp File Unnecessary -- summary
Authored by: chris2 on Oct 30, '05 07:08:02AM
a great tip! as a summary of the other suggestions, and extra code to resave in binary foramt where appropriate: (note 'write-file advise is commented out as an easy way to save as xml instead.

(add-to-list 'auto-mode-alist '(".plist'" . visit-bplist))
(defvar plist-converted-binary nil
  "Buffer local variable indicating if file came from binary-plist.")
(make-variable-buffer-local 'plist-converted-binary)

(defun visit-bplist ()
  (when (string-match "^bplist" (buffer-string))
    (message "Reading in binary plist")
     (point-min) (point-max)
     (format "/usr/bin/plutil -convert xml1 -o /dev/stdout %s"
	     (shell-quote-argument (buffer-file-name))) t t)
      (goto-char (point-max)) (previous-line 1)
      (if (looking-at "/dev/stdout: Operation not supported") (kill-line 1)))
    (set-buffer-modified-p nil)
    (setq buffer-undo-list nil)
    (setq plist-converted-binary t)))

(defadvice save-buffer (after convert-plist (&optional args))
  (when plist-converted-binary
     (format "/usr/bin/plutil -convert binary1 %s"
	     (shell-quote-argument (buffer-file-name))) nil nil)
    (message "Wrote bplist %s" (buffer-file-name))))
(ad-activate 'save-buffer)

;; (defadvice write-file (after convert-plist (filename &optional confirm))
;;   (if plist-converted-binary
;;       (shell-command
;;        (format "/usr/bin/plutil -convert binary1 %s"
;; 	       (shell-quote-argument filename))
;;        nil nil)))
;; (ad-activate 'write-file)

[ Reply to This | # ]