X-Git-Url: http://git.chise.org/gitweb/?p=elisp%2Fflim.git;a=blobdiff_plain;f=mel-u.el;h=c5f3fe179949d3cd582f4cf5aab701d5d1f13d02;hp=49d57330e117763e5af24b64d1da6d666aaaeb14;hb=refs%2Fheads%2Fflim-1_14-rfc2231-encoder;hpb=09986cc02a99ec95288aef3f2e890426ae252b54 diff --git a/mel-u.el b/mel-u.el index 49d5733..c5f3fe1 100644 --- a/mel-u.el +++ b/mel-u.el @@ -20,8 +20,8 @@ ;; You should have received a copy of the GNU General Public License ;; along with this program; see the file COPYING. If not, write to the -;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, -;; Boston, MA 02111-1307, USA. +;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +;; Boston, MA 02110-1301, USA. ;;; Code: @@ -51,11 +51,12 @@ This function uses external uuencode encoder which is specified by variable `uuencode-external-encoder'." (interactive "*r") (save-excursion - (as-binary-process - (apply (function call-process-region) - start end (car uuencode-external-encoder) - t t nil - (cdr uuencode-external-encoder))) + (let ((coding-system-for-read 'binary) + (coding-system-for-write 'binary)) + (apply (function call-process-region) + start end (car uuencode-external-encoder) + t t nil + (cdr uuencode-external-encoder))) ;; for OS/2 ;; regularize line break code (goto-char (point-min)) @@ -68,29 +69,29 @@ This function uses external uuencode decoder which is specified by variable `uuencode-external-decoder'." (interactive "*r") (save-excursion - (let ((filename (save-excursion - (save-restriction - (narrow-to-region start end) - (goto-char start) - (if (re-search-forward "^begin [0-9]+ " nil t) - (if (looking-at ".+$") - (buffer-substring (match-beginning 0) - (match-end 0))))))) - (default-directory temporary-file-directory)) - (if filename - (as-binary-process - (apply (function call-process-region) - start end (car uuencode-external-decoder) - t nil nil - (cdr uuencode-external-decoder)) - (as-binary-input-file (insert-file-contents filename)) - ;; The previous line causes the buffer to be made read-only, I - ;; do not pretend to understand the control flow leading to this - ;; but suspect it has something to do with image-mode. -slb - ;; Use `inhibit-read-only' to avoid to force - ;; buffer-read-only nil. - tomo. - (let ((inhibit-read-only t)) - (delete-file filename))))))) + (let ((filename (make-temp-file "x-uue"))) + (save-excursion + (save-restriction + (set-mark end) + (narrow-to-region start end) + (goto-char start) + (when (and (re-search-forward "^begin [0-9]+ " nil t) + (looking-at ".+$")) + (replace-match filename) + (let ((coding-system-for-read 'binary) + (coding-system-for-write 'binary)) + (apply (function call-process-region) + start (mark) (car uuencode-external-decoder) + t nil nil + (cdr uuencode-external-decoder))) + (insert-file-contents filename) + ;; The previous line causes the buffer to be made read-only, I + ;; do not pretend to understand the control flow leading to this + ;; but suspect it has something to do with image-mode. -slb + ;; Use `inhibit-read-only' to avoid to force + ;; buffer-read-only nil. - tomo. + (let ((inhibit-read-only t)) + (delete-file filename)))))))) (mel-define-method-function (mime-encode-region start end (nil "x-uue")) 'uuencode-external-encode-region) @@ -132,23 +133,26 @@ variable `uuencode-external-encoder'." START and END are buffer positions." (interactive "*r\nFWrite decoded region to file: ") (save-excursion - (let ((file (save-excursion - (save-restriction - (narrow-to-region start end) - (goto-char start) - (if (re-search-forward "^begin [0-9]+ " nil t) - (if (looking-at ".+$") - (buffer-substring (match-beginning 0) - (match-end 0))))))) - (default-directory temporary-file-directory)) - (if file - (as-binary-process - (apply (function call-process-region) - start end (car uuencode-external-decoder) - nil nil nil - (cdr uuencode-external-decoder)) - (rename-file file filename 'overwrites)))))) - + (let ((clone-buf (clone-buffer " *x-uue*")) + (file (make-temp-file "x-uue"))) + (save-excursion + (save-restriction + (set-buffer clone-buf) + (narrow-to-region start end) + (setq buffer-read-only nil) + (goto-char start) + (when (and (re-search-forward "^begin [0-9]+ " nil t) + (looking-at ".+$")) + (replace-match file) + (let ((coding-system-for-read 'binary) + (coding-system-for-write 'binary)) + (apply (function call-process-region) + (point-min) (point-max) (car uuencode-external-decoder) + nil nil nil + (cdr uuencode-external-decoder)) + (rename-file file filename 'overwrites) + (message (concat "Wrote " filename)))))) + (kill-buffer clone-buf)))) ;;; @ end ;;;