Question

I have an org-mode document that I want to convert to open Document format. When I try to do this (ctrl+c+e+o) I get an error message:

Executeable "zip" needed for creating OpenDocument files. Aborting.

I have p7zip installed on my machine but I don't know how to tell emacs it is there. I'm not sure what org-mode want to do so I'm not sure what to configure in .emacs.

Thanks

Was it helpful?

Solution

Your p7zip executable must be in Emacs exec-path variable, so that Emacs can find it.

Also, the executable must be called "zip" since it is hard-coded in the org-odt-init-outfile function.

So check the setting of exec-path first to make sure it includes the location of your zip executable.

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

OTHER TIPS

You need Info-ZIP. See http://lists.gnu.org/archive/html/emacs-orgmode/2011-07/msg00485.html

p7zip may not be compatible with zip command-line utility, if I go by this post: http://sourceforge.net/projects/sevenzip/forums/forum/45797/topic/1521207?message=3786349. So, I think, p7zip may not be a viable option here.

Do not need p7zip or info-zip external programs, Emacs deps ship with a zip program: minizip. (for more information, see Easiest way to install Emacs Windows support libraries)

The some situations we need to be known:

  1. minizip does not support recursive zip
  2. zip had been hard-coded in ox-odt.el
  3. minizip's options is not compatible with `zip'

So I generated a zip.bat batch in elisp then add the path of zip.bat to %PATH% (for org export to odt) and exec-path (for zip files, 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

The function make-zip-bat that generate 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"))))

The simple way to let zip works is to copy the content of zip.bat into a file named zip.bat and put that file under exec-path. To see more More Reasonable Emacs: zip program, make-zip-bat support 7-Zip too.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top