LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1883|回复: 4

如何在emacs中直接查看doc文件

[复制链接]
发表于 2006-9-2 09:47:20 | 显示全部楼层 |阅读模式
如何才能在emacs中直接查看word文档。比如在dired模式下,直接将word文档转成文本文件,方便查看。我知道有软件wv可以将word文档转成文本文件,但在emacs下应当如何实现呢
发表于 2006-9-2 21:08:17 | 显示全部楼层
这个也可以呀?
第一次听说
回复 支持 反对

使用道具 举报

发表于 2006-9-2 22:23:13 | 显示全部楼层
M-x hexl-find
...
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-9-3 08:34:21 | 显示全部楼层

从网上找到tv-convert.el,这个软件

从网上找到tv-convert.el这个软件,但不能加载。从说明上看,这个软件就是用于对word文档进行转换的。不知如何更改可以让这个软件起作用,多谢

  1. ;;; Start
  2. ;;;      Filename: tx-convert.el
  3. ;;; Creation Date: Sunday, 25 July 2004 06:40 PM EST
  4. ;;; Last Modified: Sunday, 10 April 2005 07:28 PM EST
  5. ;;;        Author: Tim Cross <tcross@pobox.une.edu.au>
  6. ;;;   Description: Collection of functions to convert doc/pdf/ppt/ps files
  7. ;;;                to text from within dired
  8. ;;;
  9. ;;; Copyright (C) 2005. Tim Cross <tcross@une.edu.au>
  10. ;;; All Rights Reserved.
  11. ;;;
  12. ;;; This file is not part of GNU Emacs, but the same permissions apply.
  13. ;;;
  14. ;;; GNU Emacs is free software; you can redistribute it and/or modify
  15. ;;; it under the terms of the GNU General Public License as published by
  16. ;;; the Free Software Foundation; either version 2, or (at your option)
  17. ;;; any later version.
  18. ;;;
  19. ;;; GNU Emacs is distributed in the hope that it will be useful,
  20. ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  22. ;;; GNU General Public License for more details.
  23. ;;;
  24. ;;; You should have received a copy of the GNU General Public License
  25. ;;; along with GNU Emacs; see the file COPYING.  If not, write to
  26. ;;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  27. ;;;
  28. ;;; Commenta
  29. ;;; The simple idea wiht this very basic bits of code bits was to make
  30. ;;; life just a little bit easier and require me to convert files in a
  31. ;;; shell prior to being able to view them within emacspeak and have them
  32. ;;; make any sense.
  33. ;;;
  34. ;;; You need the following packages (or at least utilities which will
  35. ;;; do the same thing). Most of these are fairly standard with many Linux
  36. ;;; distros these days.
  37. ;;; The wv utilities which contain wvText for converting MS Word docs
  38. ;;; The xpdf utilities which include pdftotext for converting PDF to text
  39. ;;; The Ghostscript package which contains pstotext for converting PS to text
  40. ;;; The ppthtml utility for converting MS Power Point files to html
  41. ;;; A configured and working browse-url setup. I use w3m as my browser
  42. ;;;
  43. ;;; Installation
  44. ;;; Pretty straight forward. Place this file somewhere in your load path
  45. ;;; and put a (require 'tx-convert) in your .emacs. You may want to byte
  46. ;;; compile this file.
  47. ;;; I bind the function tx-dired-view-file to a key in dired so that I
  48. ;;; can view any of the 'special' files with a single key press e.g.
  49. ;;;(add-hook 'dired-mode-hook
  50. ;;;           (function (lambda ()
  51. ;;;           (local-set-key [f6] 'tx-dired-view-file))))
  52. ;;;
  53. ;;; This is the first bit of elisp I've allowed out into the world and
  54. ;;; while I am really learning to love both elisp and cl lisp, I'm still
  55. ;;; very much a novice. Therefore, there IS bugs and probably some pretty
  56. ;;; poor style within this stuff. Feedback, bug reports and suggestions
  57. ;;; always welcome.
  58. ;;;
  59. ;;; Emacpseka Users Note - I've not attempted to enhance this code to provide
  60. ;;; better spoken or audio icon feedback. When the code matures a bit and
  61. ;;; once I get some feedback, I will see if a re-worked version can be
  62. ;;; included in emacspeak. In the meantime, feel free to use 'advice' to
  63. ;;; improve things.

  64. ;;(require 'tx-convert)
  65. ;;(add-hook 'dired-mode-hook
  66.             ;;(function (lambda ()
  67.             ;;(local-set-key [f4] 'tx-dired-view-file))))


  68. (defvar tx-msword-to-text-prog "/usr/bin/wvText"
  69.   "Program used to convert Word document to plain text.")

  70. (defvar tx-pdf-to-text-prog "/usr/bin/pdftotext"
  71.   "Program used to convert PDF files to plain ttext.")

  72. (defvar tx-ps-to-text-prog "/usr/bin/pstotext"
  73.   "Program used to convert PS files to plain text.")

  74. (defvar tx-ppt-to-html-prog "/usr/bin/ppthtml"
  75.   "Program used to convert PowerPoint slides to HTML.")

  76. (defun tx-do-file-translate (cmd arg1 arg2)
  77.   "Do the actual conversion of a word doc."
  78.   (message (format "Cmd %s Arg1 %s Arg2 %s" cmd arg1 arg2))
  79.   (if (= 0 (shell-command (format "%s %s %s" cmd arg1 arg2)
  80.                                                   "*Translate Output*"))
  81.           t
  82.         nil))

  83. (defun tx-expand-quote-filename (filename)
  84.   "Quote shell meta characters and expand filename."
  85.   (shell-quote-argument (expand-file-name filename)))

  86. (defun tx-doc-to-text (word-doc)
  87.   "Convert MS Word document to text and display."
  88.   (interactive "fView MS Word doc file: ")
  89.   (let ((output-file (concat word-doc ".txt")))
  90.         (if (and (file-readable-p word-doc)
  91.                          (tx-do-file-translate tx-msword-to-text-prog
  92.                                                                    (tx-expand-quote-filename word-doc)
  93.                                                                    (tx-expand-quote-filename output-file)))
  94.                 (view-file output-file)
  95.           (error "Could not translate %s from MS Word format to text" word-doc))))

  96. (defun tx-pdf-to-text (pdf-file)
  97.   "Convert a PDF file to plain text and view it."
  98.   (interactive "fView PDF file: ")
  99.   (let ((output-file (concat pdf-file ".txt")))
  100.         (if (and (file-readable-p pdf-file)
  101.                          (tx-do-file-translate tx-pdf-to-text-prog
  102.                                                                    (tx-expand-quote-filename pdf-file)
  103.                                                                    (tx-expand-quote-filename output-file)))
  104.                 (view-file output-file)
  105.           (error "Could not translate %s from PDF to text" pdf-file))))

  106. (defun tx-ps-to-text (ps-file)
  107.   "Convert a PS file to plain text and view it."
  108.   (interactive "fView PostScript file: ")
  109.   (let ((output-file (concat ps-file ".txt")))
  110.         (if (and (file-readable-p ps-file)
  111.                          (tx-do-file-translate
  112.                           tx-ps-to-text-prog
  113.                           (concat "-output " (tx-expand-quote-filename output-file))
  114.                           (tx-expand-quote-filename ps-file)))
  115.                 (view-file output-file)
  116.           (error "Could not translate %s from PS to text" ps-file))))

  117. (defun tx-ppt-to-html (ppt-file)
  118.   "convert a PPT file to HTML and view it."
  119.   (interactive "fView PPT file: ")
  120.   (let ((output-file (concat ppt-file ".html")))
  121.         (if (and (file-readable-p ppt-file)
  122.                          (tx-do-file-translate
  123.                           tx-ppt-to-html-prog
  124.                           (tx-expand-quote-filename ppt-file)
  125.                           (concat "> " (tx-expand-quote-filename output-file))))
  126.                 (browse-url-of-file (expand-file-name output-file))
  127.           (error "Could not translate %s from PPT to HTML" ppt-file))))

  128. (defun tx-dired-view-file ()
  129.   "View files within dired, possibly requiring translation."
  130.   (interactive)
  131.   (let ((dired-file (dired-get-filename)))
  132.         (cond
  133.          ((string-match "\\.doc$" dired-file)
  134.           (tx-doc-to-text dired-file))
  135.          ((string-match "\\.pdf$" dired-file)
  136.           (tx-pdf-to-text dired-file))
  137.          ((string-match "\\.ps$" dired-file)
  138.           (tx-ps-to-text dired-file))
  139.          ((string-match "\\.ppt$" dired-file)
  140.           (tx-ppt-to-html dired-file))
  141.          ((string-match "\\.htm$\\|\\.html$" dired-file)
  142.           (browse-url-of-file dired-file))
  143.          (t
  144.           (dired-view-file)))))


  145. ;;(provide 'tc-convert)

  146. ;;; End
复制代码
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-9-5 16:16:26 | 显示全部楼层
顶一下!!!!!!!!!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表