Perl:我如何让Emacs在Perl脚本的完整路径中添加引号?

Slo*_*ner 6 emacs perl

令人难以置信的简单问题.在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运行命令mode-compile".在Perl菜单中,它被标记为"运行".

Sam*_*ham 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 Code Online (Sandbox Code Playgroud)

我改变的线路正在改变

(run-cmd (concat shcmd " " dbgflags " " shfile " "
Run Code Online (Sandbox Code Playgroud)

(run-cmd (concat shcmd " " dbgflags " " (shell-quote-argument shfile) " "
Run Code Online (Sandbox Code Playgroud)

更完整的修复方法是同时转义dbgflags(无论它们在哪里设置,仅转义整个变量是不正确的)以及mc--shell-args它们何时设置。