unoffice

Reclaim text from office documents
git clone https://logand.com/git/unoffice.git/
Log | Files | Refs | README

unoffice.el (1243B)


      1 ;;; unoffice.el
      2 ;;;
      3 ;;; Reclaim text from office documents
      4 ;;;
      5 ;;; Author: Tomas Hlavaty <tom at logand dot com>
      6 ;;;
      7 ;;; License: GPL v3 or later
      8 
      9 (defcustom unoffice-unabw-program
     10   "unabw"
     11   "Path of the unabw program."
     12   :group 'unoffice
     13   :type 'string)
     14 
     15 (defcustom unoffice-undocx-program
     16   "undocx"
     17   "Path of the undocx program."
     18   :group 'unoffice
     19   :type 'string)
     20 
     21 (defcustom unoffice-unodt-program
     22   "unodt"
     23   "Path of the unodt program."
     24   :group 'unoffice
     25   :type 'string)
     26 
     27 (defun unoffice-buffer (program)
     28   (setq buffer-read-only nil)
     29   (let ((coding-system-for-read 'utf-8-unix))
     30     (shell-command-on-region (point-min)
     31                              (point-max)
     32                              (concat program " '" buffer-file-name "'")
     33                              t
     34                              t))
     35   (setq buffer-read-only t)
     36   (set-buffer-modified-p nil))
     37 
     38 (defun unabw ()
     39   (unoffice-buffer unoffice-unabw-program))
     40 
     41 (defun undocx ()
     42   (unoffice-buffer unoffice-undocx-program))
     43 
     44 (defun unodt ()
     45   (unoffice-buffer unoffice-unodt-program))
     46 
     47 (add-to-list 'auto-mode-alist '("\\.abw\\'" . unabw))
     48 (add-to-list 'auto-mode-alist '("\\.docx\\'" . undocx))
     49 (add-to-list 'auto-mode-alist '("\\.odt\\'" . unodt))
     50 
     51 (provide 'unoffice)