;; $Id: filehandler.el,v 1.1 2007/11/29 04:39:16 tag Exp $ ;;; filehandler.el - remote operations on files ;;; by TA Gonsalves, 20-Oct-07 ;;; ;; Last modified: Tue 11-Mar-2008 13:52:04 by tag ;;; ;(defvar host-handler-group-alist '(("bulbul" . "linux") ; ("beluga" . "macos") ; ) ; "*Used by \\[remote-file-open] to map hostname to OS type which is then used to select the application from \\[file-handler-alist]") ; ;(defvar file-handler-new-alist '("linux" . (("doc" . "oowriter") ; ("xls" . "oocalc") ; ("sxc" . "oocalc") ; ("odt" . "oowriter") ; ("pdf" . "acroread") ; ("ppt" . "ooimpress") ; ("jpg" . "display")) ; "macos" . (("doc" . "oowriter") ; ("xls" . "oocalc") ; ("sxc" . "oocalc") ; ("odt" . "oowriter") ; ("pdf" . "acroread") ; ("ppt" . "ooimpress") ; ("jpg" . "display")) ; "*Used by \\[remote-file-open] to choose the application for each file type.") (defvar file-handler-alist '(("doc" . "oowriter") ("xls" . "oocalc") ("sxc" . "oocalc") ("odt" . "oowriter") ("pdf" . "acroread") ("ppt" . "ooimpress") ("tif" . "display") ("jpg" . "display")) "*Used by \\[remote-file-open] to choose the application for each file type.") ;(defvar file-handler-default-alist '(("linux" . nil) ; ("macos" . "open") ; ("unknown" . nil)) ; "*Default values for applications not in \\[file-handler-alist]") (defvar remote-file-host "" "*Remote host name, used by \\[remote-file-open].") (defun remote-file-open (host file) "*Display file on host using the associated application from the variable file-handler-alist. file must be relative to the home or absolute. The file is copied to the same directory on the remote host, overwriting any existing file. Passwordless ssh must be enabled on host" (interactive (list (read-string "Remote host: " remote-file-host) ;; ;; Prompt with most recent filename (if any) or current buffer file name ;; (read-file-name "Display file: " (progn (setq f (or (car file-name-history) (file-name-directory buffer-file-name))) (file-name-directory f)) nil nil (file-name-nondirectory f)))) ; (let ((hostgroup "unknown") ; (condition-case (condition-case nil (and (call-process "bash" nil "*ssh output*" t "-c" (concat "scp -p " file " @" host ":" file)) (start-process "ssh" "*ssh output*" "ssh" "-X" host (cdr (assoc (downcase (substring file (+ 1 (string-match "\\.[^.]*$" file)))) file-handler-alist)) file)) (error (message "No application to open %s" file))) (setq remote-file-host host)) (defun remote-file-retrieve (host file) "*Retrieve file from host. file must be relative to the home or absolute. The file is copied to the same local directory, overwriting any existing file. Passwordless ssh must be enabled on host." (interactive (list (read-string "Remote host: " remote-file-host) ;; ;; Prompt with most recent filename (if any) or current buffer file name ;; (read-file-name "Retrieve file: " (progn (setq f (or (car file-name-history) (file-name-directory buffer-file-name))) (file-name-directory f)) nil nil (file-name-nondirectory f)))) (condition-case nil (and (call-process "bash" nil "*ssh output*" t "-c" (concat "scp -p @" host ":" file " " file)) (progn (call-process "bash" nil "*ssh output*" t "-c" (concat "ls -l " file)) (switch-to-buffer-other-window "*ssh output*" t) (other-window 1) t)) (error (message "Unable to retrieve %s from %s" file host))) (setq remote-file-host host)) (provide 'remote-file-open) ;;; $Log: filehandler.el,v $ ;;; Revision 1.1 2007/11/29 04:39:16 tag ;;; Initial version ;;; ;;; Local Variables: ;;; time-stamp-active: t ;;; time-stamp-line-limit: 20 ;;; time-stamp-start: "Last modified:[ ]+" ;;; time-stamp-format: "%3a %:d-%3b-%:y %02H:%02M:%02S by %u" ;;; time-stamp-end: "$" ;;; End: ;;; End of DONc.el -----------------------------------------------