annotate lisp/efs/dired-uu.el @ 42:8b8b7f3559a2 r19-15b104

Import from CVS: tag r19-15b104
author cvs
date Mon, 13 Aug 2007 08:54:51 +0200
parents 7e54bd776075
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2 ;;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3 ;; File: dired-uu.el
42
8b8b7f3559a2 Import from CVS: tag r19-15b104
cvs
parents: 40
diff changeset
4 ;; Dired Version: #Revision: 7.9 $
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5 ;; RCS:
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6 ;; Description: Commands for uuencoding/uudecoding marked files.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
7 ;; Author: Sandy Rutherford <sandy@math.ubc.ca>
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
8 ;;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
9 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
10
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
11 ;;; Requirements and provisions
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
12 (provide 'dired-uu)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
13 (require 'dired)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
14
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
15 (defvar dired-uu-files-to-decode nil)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
16 ;; Fluid var to pass data inside dired-create-files.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
17
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
18 (defun dired-uucode-file (file ok-flag)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
19 ;; uuencode or uudecode FILE.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
20 ;; Don't really support the ok-flag, but needed for compatibility
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
21 (let ((handler (find-file-name-handler file 'dired-uucode-file)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
22 (cond (handler
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
23 (funcall handler 'dired-uucode-file file ok-flag))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
24 ((or (file-symlink-p file) (file-directory-p file))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
25 nil)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
26 (t
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
27 (if (assoc file dired-uu-files-to-decode)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
28 (let ((default-directory (file-name-directory file)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
29 (if (dired-check-process
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
30 (concat "Uudecoding " file) shell-file-name "-c"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
31 (format "uudecode %s" file))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
32 (signal 'file-error (list "Error uudecoding" file))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
33 (let ((nfile (concat file ".uu")))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
34 (if (dired-check-process
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
35 (concat "Uuencoding " file) shell-file-name "-c"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
36 (format "uuencode %s %s > %s"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
37 file (file-name-nondirectory file) nfile))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
38 (signal 'file-error (list "Error uuencoding" file)))))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
39
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
40 (defun dired-uucode-out-file (file)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
41 ;; Returns the name of the output file for the uuencoded FILE.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
42 (let ((buff (get-buffer-create " *dired-check-process output*"))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
43 (case-fold-search t))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
44 (save-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
45 (set-buffer buff)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
46 (erase-buffer)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
47 (if (string-equal "18." (substring emacs-version 0 3))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
48 (call-process "head" file buff nil "-n" "1")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
49 (insert-file-contents file nil 0 80))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
50 (goto-char (point-min))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
51 (if (looking-at "begin [0-9]+ \\([^\n]*\\)\n")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
52 (expand-file-name
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
53 (buffer-substring (match-beginning 1) (match-end 1))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
54 (file-name-directory file))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
55 nil))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
56
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
57 (defun dired-do-uucode (&optional arg files to-decode)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
58 "Uuencode or uudecode marked (or next ARG) files."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
59 (interactive
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
60 (let* ((dir (dired-current-directory))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
61 (files (dired-get-marked-files nil current-prefix-arg))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
62 (arg (prefix-numeric-value current-prefix-arg))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
63 (total (length files))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
64 rfiles decoders ofile decode encode hint-p)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
65 (mapcar
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
66 (function
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
67 (lambda (fn)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
68 (if (setq ofile (dired-uucode-out-file fn))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
69 (setq decoders (cons (cons fn ofile) decoders)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
70 files)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
71 (setq decode (length decoders)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
72 encode (- total decode)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
73 hint-p (not (or (zerop decode) (zerop encode))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
74 (setq rfiles
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
75 (mapcar
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
76 (function
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
77 (lambda (fn)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
78 (if hint-p
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
79 (concat
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
80 (if (assoc fn decoders) " [de] " " [en] ")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
81 (dired-make-relative fn dir t))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
82 (dired-make-relative fn dir t))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
83 files))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
84 (or (memq 'uuencode dired-no-confirm)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
85 (dired-mark-pop-up nil 'uuencode rfiles 'y-or-n-p
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
86 (cond
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
87 ((null decoders)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
88 (if (= encode 1)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
89 (format "Uuencode %s? " (car rfiles))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
90 (format "Uuencode %d file%s? "
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
91 encode (dired-plural-s encode))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
92 ((zerop encode)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
93 (if (= decode 1)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
94 (format "Uudecode %s? " (car rfiles))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
95 (format "Uudecode %d file%s? "
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
96 decode (dired-plural-s decode))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
97 (t
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
98 (format "Uudecode %d and uuencode %d file%s? "
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
99 decode encode (dired-plural-s encode)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
100 (setq arg 0))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
101 (list arg files decoders)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
102 (let ((dired-uu-files-to-decode to-decode)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
103 out-file)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
104 (if (not (zerop arg))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
105 (dired-create-files
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
106 'dired-uucode-file
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
107 "Uuencode or Uudecode"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
108 files
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
109 (function
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
110 (lambda (fn)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
111 (if (setq out-file (assoc fn dired-uu-files-to-decode))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
112 (cdr out-file)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
113 (concat fn ".uu"))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
114 dired-keep-marker-uucode nil t))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
115
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
116 ;;; end of dired-uu.el