令人难以置信的简单问题。在Windows 7 64上使用Emacs 23.4.1中的CPerl模式,当我使用C-c c
运行脚本时,Emacs不会将路径包装在引号中,因此任何带空格的目录都会导致Perl无法找到该文件。
"C:/Perl64/bin\perl.exe -w g:/foo/bar/first second/myscript.pl"
生成此错误消息:
"Can't open perl script "g:/foo/bar/first": No such file or directory"
问题:在将文件名传递给Perl本身时,如何让Emacs使用引号?
编辑:出于某种原因,我无法评论(可能是浏览器问题)所以我正在编辑原始帖子以回应@legoscia的评论:“C-c c运行命令mode-compile”。在Perl菜单中,它被标记为“Run”。
答案 0 :(得分:2)
我只有mode-compile.el v2.29可用,但在该版本中,问题与您描述的完全一样,编译命令的参数未正确转义,并且没有启用它的选项。
这有点黑客但你应该能够通过.emacs
文件中的文件名正确转义来重新定义相关函数:
(eval-after-load 'mode-compile
'(progn
(defun mc--shell-compile (shell dbgflags &optional errors-regexp-alist)
;; Run SHELL with debug flags DBGFLAGS on current-buffer
(let* ((shcmd (or (mc--which shell)
(error "Compilation abort: command %s not found" shell)))
(shfile (or mc--remote-pathname (buffer-file-name)
(error "Compilation abort: Buffer %s has no filename"
(buffer-name))))
(run-cmd (concat shcmd " " dbgflags " " (shell-quote-argument shfile) " "
(setq mc--shell-args
(read-string (if mode-compile-expert-p
"Argv: "
(format "Arguments to %s %s script: "
shfile shell))
mc--shell-args)))))
;; Modify compilation-error-regexp-alist if needed
(if errors-regexp-alist
(progn
;; Set compilation-error-regexp-alist from compile
(or (listp errors-regexp-alist)
(error "Compilation abort: In mc--shell-compile errors-regexp-alist not a list."))
;; Add new regexp alist to compilation-error-regexp-alist
(mapcar '(lambda(x)
(if (mc--member x compilation-error-regexp-alist) nil
(setq compilation-error-regexp-alist
(append (list x)
compilation-error-regexp-alist))))
errors-regexp-alist)))
;; Run compile with run-cmd
(mc--compile run-cmd)))))
我改变的路线正在改变
(run-cmd (concat shcmd " " dbgflags " " shfile " "
到
(run-cmd (concat shcmd " " dbgflags " " (shell-quote-argument shfile) " "
更完整的解决方法是,也可以转义dbgflags
(无论它们设置在何处,只是转义整个变量都不正确)和mc--shell-args
,当它们也被设置时。< / p>