需要org-mode zip,怎么过来?

时间:2011-12-24 15:19:29

标签: emacs org-mode opendocument

我有一个org-mode文档,我想将其转换为开放文档格式。当我尝试执行此操作时(ctrl + c + e + o),我收到错误消息:

  

创建OpenDocument文件需要可执行的“zip”。中止。

我的机器上安装了p7zip,但我不知道如何告诉emacs它在那里。我不确定org-mode想要做什么,所以我不确定在.emacs中配置什么。

由于

3 个答案:

答案 0 :(得分:6)

您的p7zip可执行文件必须位于Emacs exec-path变量中,以便Emacs可以找到它。

此外,必须将可执行文件称为“zip”,因为它在org-odt-init-outfile函数中是硬编码的。

首先检查exec-path的设置,确保其中包含zip可执行文件的位置。

`M-x customize-variable RET exec-path RET`

答案 1 :(得分:0)

您需要Info-ZIP。见http://lists.gnu.org/archive/html/emacs-orgmode/2011-07/msg00485.html

p7zip可能与zip命令行实用程序不兼容,如果我查看此帖子:http://sourceforge.net/projects/sevenzip/forums/forum/45797/topic/1521207?message=3786349。所以,我认为,p7zip可能不是一个可行的选择。

答案 2 :(得分:0)

不需要p7zipinfo-zip外部程序,Emacs deps附带一个zip程序:minizip。 (有关更多信息,请参见Easiest way to install Emacs Windows support libraries

我们需要知道一些情况:

  1. minizip不支持递归zip
  2. zip已在ox-odt.el中被硬编码
  3. minizip的选项与`zip'不兼容

因此,我在zip.bat中生成了elisp批处理,然后将zip.bat的路径添加到%PATH%(用于将组织导出到odt)和exec-path(用于zip文件,dired-do-compress-to

zip.bat

@echo off
REM zip.bat for minizip on Windows
REM generated by More Reasonable Emacs https://github.com/junjiemars/.emacs.d

setlocal EnableDelayedExpansion

set _OPT=%*
set _ZIP=
set _ARGV=

REM parsing command line arguments

:getopt
if "%1"=="-mX0" set _OPT=%_OPT:-mX0=-0% & shift & goto :getopt

REM ignore options
if "%1"=="-r" set _OPT=%_OPT:-r=% & shift & goto :getopt
if "%1"=="--filesync" set _OPT=%_OPT:--filesync=% & shift & goto :getopt
if "%1"=="-rmTq" set _OPT=%_OPT:-rmTq=% & shift & goto :getopt

REM extract zip and argv
if not "%1"=="" (
  if "%_ZIP%"=="" (
    if "%_ARGV%"=="" (
      set _ZIP=%1
    )
  ) else (
    set _ARGV=%_ARGV% %1
  )
  set _OPT=!_OPT:%1=!
  shift
  goto :getopt
)

REM minizip recursive call

call :loop %_ARGV%
goto :end

:zip
set _file=%1
set _file=%_file:./=%
if not "%_file%"=="%_ZIP%" (
  if exist %_ZIP% (
    minizip %_OPT% -a %_ZIP% %_file%
  ) else (
    minizip %_OPT% %_ZIP% %_file%
  )
)
goto :end

:loop
for %%i in (%*) do (
  if exist "%%i/*" (
    for %%f in (%%i/*) do (
      call :loop %%i/%%f
    )
    for /d %%d in (%%i/*) do (
      call :loop %%i/%%d
    )
  ) else (
    call :zip %%i
  )
)

:end

生成make-zip-bat的函数zip.bat

(defun make-zip-bat (zip &rest ignore)
  "Make ZIP.bat in `exec-path' for minizip or 7za."
  (declare (indent 1))
  (when (stringp zip)
    (save-str-to-file
     (concat "@echo off\n"
                     (format "REM zip.bat for %s on Windows\n" zip)
                     "REM generated by More Reasonable Emacs https://github.com/junjiemars/.emacs.d\n\n"
                     (concat "REM local variable declaration\n\n"
                                     "setlocal EnableDelayedExpansion\n"
                                     "\n"
                                     "set _OPT=%*\n"
                                     "set _ZIP=\n"
                                     "set _ARGV=\n"
                                     "\n"
                                     "REM parsing command line arguments\n\n"
                                     ":getopt\n"
                                     (cond ((string= "minizip" zip)
                                                    "if \"%1\"==\"-mX0\" set _OPT=%_OPT:-mX0=-0% & shift & goto :getopt\n")
                                                 ((string= "7za" zip)
                                                    (concat
                                                     "if \"%1\"==\"-mX0\" set _OPT=%_OPT:-mX0=-mx0% & shift & goto :getopt\n"
                                                     "if \"%1\"==\"-0\" set _OPT=%_OPT:-0=-mx0% & shift & goto :getopt\n"
                                                     "if \"%1\"==\"-9\" set _OPT=%_OPT:-9=-mx9% & shift & goto :getopt\n")))
                                     "\n"
                                     "REM ignore options\n"
                                     (let ((options nil))
                                         (dolist (x (cond ((string= "minizip" zip)
                                                                             (append '("-r" "--filesync" "-rmTq") ignore))
                                                                            ((string= "7za" zip)
                                                                             (append '("-r" "--filesync" "-rmTq"))))
                                                                options)
                                             (setq options
                                                         (concat options
                                                                         (format "if \"%%1\"==\"%s\" set _OPT=%%_OPT:%s=%% & shift & goto :getopt\n" x x)))))
                                     "\n"
                                     "REM extract zip and argv\n"
                                     "if not \"%1\"==\"\" (\n"
                                     "  if \"%_ZIP%\"==\"\" (\n"
                                     "    if \"%_ARGV%\"==\"\" (\n"
                                     "      set _ZIP=%1\n"
                                     "    )\n"
                                     "  ) else (\n"
                                     "    set _ARGV=%_ARGV% %1\n"
                                     "  )\n"
                                     "  set _OPT=!_OPT:%1=!\n"
                                     "  shift\n"
                                     "  goto :getopt\n"
                                     ")\n\n")
                     (cond ((string= "7za" zip)
                                    (concat "REM 7za call\n"
                                                    "7za a %_OPT% -tzip -- %_ZIP% %_ARGV%\n"
                                                    "if exist %_ZIP% (\n"
                                                    "  7za d %_OPT% -tzip -- %_ZIP% %_ZIP%\n"
                                                    ")\n"))
                                 ((string= "minizip" zip)
                                    (concat "REM minizip recursive call\n\n"
                                                    "call :loop %_ARGV%\n"
                                                    "goto :end\n"
                                                    "\n:zip\n"
                                                    "set _file=%1\n"
                                                    "set _file=%_file:./=%\n"
                                                    "if not \"%_file%\"==\"%_ZIP%\" (\n"
                                                    "  if exist %_ZIP% (\n"
                                                    "    minizip %_OPT% -a %_ZIP% %_file%\n"
                                                    "  ) else (\n"
                                                    "    minizip %_OPT% %_ZIP% %_file%\n"
                                                    "  )\n"
                                                    ")\n"
                                                    "goto :end\n"
                                                    "\n:loop\n"
                                                    "for %%i in (%*) do (\n"
                                                    "  if exist \"%%i/*\" (\n"
                                                    "    for %%f in (%%i/*) do (\n"
                                                    "      call :loop %%i/%%f\n"
                                                    "    )\n"
                                                    "    for /d %%d in (%%i/*) do (\n"
                                                    "      call :loop %%i/%%d\n"
                                                    "    )\n"
                                                    "  ) else (\n"
                                                    "    call :zip %%i\n"
                                                    "  )\n"
                                                    ")\n"
                                                    "\n:end\n"))))
     (v-home% ".exec/zip.bat"))))

zip工作的简单方法是将zip.bat的内容复制到名为zip.bat的文件中,然后将该文件放在exec-path下。要查看更多More Reasonable Emacs: zip programmake-zip-bat也支持7-Zip