help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: emacs rmail. How to convert .doc to plain text


From: Benjamin Riefenstahl
Subject: Re: emacs rmail. How to convert .doc to plain text
Date: 24 Nov 2002 18:08:22 +0100
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2

Hi,

Puff Addison <puff@theaddisons.demon.co.uk> writes:
> Yes, please post your Emacs integration code.

Ok, see below.  I should note that it is probably also possible to
(ab-)use jka-compr for this, which would make my two functions
obsolete.

so long, benny

>>>>>>>

(defun benny-antiword-file-handler (operation &rest args)
  ;; First check for the specific operations
  ;; that we have special handling for.
  (cond ((eq operation 'insert-file-contents)
         (apply 'benny-antiword-insert-file args))
        ((eq operation 'file-writable-p)
         nil)
        ((eq operation 'write-region)
         (error "Word documents can't be written"))
        ;; Handle any operation we don't know about.
        (t (let ((inhibit-file-name-handlers
                  (cons 'benny-antiword-file-handler
                        (and (eq inhibit-file-name-operation operation)
                             inhibit-file-name-handlers)))
                 (inhibit-file-name-operation operation))
             (apply operation args)))))

(defun benny-antiword-insert-file (filename &optional visit beg end replace)
  (set-buffer-modified-p nil)
  (setq buffer-file-name (file-truename filename))
  (setq buffer-read-only t)
  (let ((start (point))
        (inhibit-read-only t))
    (if replace (delete-region (point-min) (point-max)))
    (save-excursion
      (let ((coding-system-for-read 'utf-8)
            (filename (encode-coding-string
                       buffer-file-name
                       (or file-name-coding-system
                           default-file-name-coding-system))))
        (call-process "antiword" nil t nil "-m" "UTF-8.txt"
                      filename))
      (list buffer-file-name (- (point) start)))))

(setq file-name-handler-alist
      (cons '("\\.doc\\'" . benny-antiword-file-handler)
            file-name-handler-alist))

<<<<<<<



reply via email to

[Prev in Thread] Current Thread [Next in Thread]