Embarassingly simple question. Using CPerl mode in Emacs 23.4.1 on Windows 7 64, when I use C-c c
to run the script Emacs doesn't wrap the path in quotes, so any directories with spaces cause Perl to be unable to find the file.
"C:/Perl64/bin\perl.exe -w g:/foo/bar/first second/myscript.pl"
generates this error message:
"Can't open perl script "g:/foo/bar/first": No such file or directory"
Question: how do I make Emacs use quotes when passing the file name to Perl itself?
Edit: for some reason I can't comment (perhaps a browser issue) so I am editing the original post in response to the comment from @legoscia: "C-c c runs the command mode-compile". In the Perl menu it is marked as "Run".
I only have mode-compile.el v2.29 available, but in that version the issue is exactly as you describe, the arguments to the compile command are not escaped properly, and there's no option to enable it.
It's a bit of hack but you should be able to redefine the relevant function with correct escaping for the filename with this in your .emacs
file:
(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)))))
The line I changed was changing
(run-cmd (concat shcmd " " dbgflags " " shfile " "
to
(run-cmd (concat shcmd " " dbgflags " " (shell-quote-argument shfile) " "
A more complete fix would be to also escape the dbgflags
(wherever they're set, just escaping the entire variable won't be right) and mc--shell-args
when they're set too.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With