org-mode需要zip,如何解决?

8
我有一个org-mode文档,想要将其转换为开放文档格式。当我尝试这样做(ctrl+c+e+o)时,会出现一个错误信息:

需要“zip”可执行文件来创建OpenDocument文件。 终止。

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

如果您在命令行中运行zip(如果您使用的是Windows,则为dos-prompt),它是否将其识别为命令或程序? - Jonathan Leech-Pepin
如果你正在运行Debian或Ubuntu或一些类似的GNU/Linux衍生版,那么apt-get install zip unzip将会为你安装这些实用工具。 - phils
3个回答

7

您的 p7zip 可执行文件必须在 Emacs 的 exec-path 变量中,这样 Emacs 才能找到它。

此外,可执行文件必须被命名为“zip”,因为它在 org-odt-init-outfile 函数中硬编码了。

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

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

0
不需要外部程序p7zipinfo-zip,Emacs的deps内置了一个zip程序:minizip。(更多信息请参见安装Emacs Windows支持库的最简单方法
需要了解的一些情况:
  1. minizip不支持递归zip
  2. ox-odt.el中已经硬编码了zip
  3. minizip的选项与`zip'不兼容
所以我在elisp中生成了一个zip.bat批处理文件,然后将zip.bat的路径添加到%PATH%(用于org导出到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

生成zip.bat的函数make-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下。要了解更多更合理的Emacs:zip程序make-zip-bat也支持7-Zip

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接