Emacs 如何连接要在启动进程中使用的双引号

Emacs 如何连接要在启动进程中使用的双引号,emacs,elisp,Emacs,Elisp,谁能帮我把双引号连起来: 在本例中,我正在编写一个函数,用于Windows操作系统上的Emacs。带空格的文件名需要用双引号括起来 缓冲区文件名为:c:/Documents and Settings/All Users/Desktop/foo.tex 我正在尝试使用: (setq pdf-file (concat "\"" (car (split-string (buffer-file-name) "\\.tex")) ".pdf" "\"")) 当我调用(启动进程“display”nil

谁能帮我把双引号连起来:

在本例中,我正在编写一个函数,用于Windows操作系统上的Emacs。带空格的文件名需要用双引号括起来

缓冲区文件名为:
c:/Documents and Settings/All Users/Desktop/foo.tex

我正在尝试使用:

(setq pdf-file
  (concat "\"" (car (split-string (buffer-file-name) "\\.tex")) ".pdf" "\""))
当我调用
(启动进程“display”nil c:/SumatraPDF.exe pdf文件)
时,pdf查看器会尝试打开此文件:

c:\Documents and Settings\All Users\Desktop"c:\Documents and Settings\All Users\Desktop\foo.pdf"

编辑:这是我试图修改的函数。正如我在下面的回答中所述,错误是由于我无意中引用了文件名而引起的,double-double——也就是说,
start-process
将变量视为双引号,因此我不需要连接另一组双引号

(defun latexmk ()
".latexmkrc contains the following entries:
  $pdflatex = 'pdflatex -file-line-error -synctex=1 %O %S';
  $pdf_mode = 1;
  $recorder = 0;
  $clean_ext = 'synctex.gz synctex.gz(busy) aux fdb_latexmk log';"
(interactive)
  (setq tex-file (file-name-nondirectory buffer-file-name))
  (setq base-file (car (split-string (file-name-nondirectory buffer-file-name) "\\.tex")))
  (setq pdf-file (concat base-file ".pdf"))
  (setq line (format "%d" (line-number-at-pos)))
  (setq sumatra "C:/SumatraPDF/SumatraPDF.exe")
  (setq tex-output (concat "*" (file-name-nondirectory buffer-file-name) "*") )
  (setq latexmk "c:/texlive/2013/bin/win32/latexmk.exe")
  (setq latexmkrc "c:/Documents and Settings/Administrator/Application Data/.emacs.d/.latexmkrc")
  (if (buffer-modified-p)
    (save-buffer))
  (delete-other-windows)
  (set-window-buffer (split-window-horizontally) (get-buffer-create tex-output))
  (with-current-buffer tex-output (erase-buffer))
  (start-process "tskill" nil "c:/WINDOWS/system32/tskill.exe" "SumatraPDF")
  (set-process-sentinel 
     (start-process "deep-clean" nil latexmk "-C" "-r" latexmkrc tex-file)
     (lambda (p e) (when (= 0 (process-exit-status p))
       (set-process-sentinel 
         (start-process "compile" tex-output latexmk "-r" latexmkrc tex-file)
         (lambda (p e) (when (= 0 (process-exit-status p))
       (set-process-sentinel 
           (start-process "displayline" nil sumatra "-forward-search" tex-file line pdf-file)
           (lambda (p e) (when (= 0 (process-exit-status p))
             (start-process "clean" nil latexmk "-c" "-r" latexmkrc tex-file)
             (switch-to-buffer (get-file-buffer tex-file))
             (if (get-buffer-process (get-buffer tex-output))
               (process-kill-without-query (get-buffer-process (get-buffer tex-output))))
             (kill-buffer tex-output)
             (delete-other-windows)))))))))))

我猜你想要:

(replace-regexp-in-string
 "\\.tex$"
 ".pdf"
 "c:/Documents and Settings/All Users/Desktop/foo.tex")    

我猜你想要:

(replace-regexp-in-string
 "\\.tex$"
 ".pdf"
 "c:/Documents and Settings/All Users/Desktop/foo.tex")    

启动过程
将变量视为双引号。本质上,我的变量以双引号结束——这就是阻止我使用文件的绝对路径的原因。因此,简言之,当将变量与
启动进程
一起使用时,它不需要双引号

感谢所有帮助我解决问题的人,非常感谢

以下是修订后的工作职能:

(defun latexmk ()
".latexmkrc contains the following entries:
  $pdflatex = 'pdflatex -file-line-error -synctex=1 %O %S';
  $pdf_mode = 1;
  $recorder = 0;
  $clean_ext = 'synctex.gz synctex.gz(busy) aux fdb_latexmk log';"
(interactive)
  (setq tex-file (buffer-file-name))
  (setq base-file (car (split-string (buffer-file-name) "\\.tex")))
  (setq pdf-file (concat base-file ".pdf"))
  (setq line (format "%d" (line-number-at-pos)))
  (setq sumatra "c:/Program Files/SumatraPDF/SumatraPDF.exe")
  (setq tex-output (concat "*" (file-name-nondirectory buffer-file-name) "*") )
  (setq latexmk "c:/texlive/2013/bin/win32/latexmk.exe")
  (setq latexmkrc "c:/Documents and Settings/Administrator/Application Data/.emacs.d/.latexmkrc")
  (if (buffer-modified-p)
    (save-buffer))
  (delete-other-windows)
  (set-window-buffer (split-window-horizontally) (get-buffer-create tex-output))
  (with-current-buffer tex-output (erase-buffer))
  (start-process "tskill" nil "c:/WINDOWS/system32/tskill.exe" "SumatraPDF")
  (set-process-sentinel 
     (start-process "deep-clean" nil latexmk "-C" "-r" latexmkrc tex-file)
     (lambda (p e) (when (= 0 (process-exit-status p))
       (set-process-sentinel 
         (start-process "compile" tex-output latexmk "-r" latexmkrc tex-file)
         (lambda (p e) (when (= 0 (process-exit-status p))
          (start-process "displayline" nil sumatra "-forward-search" tex-file line pdf-file)
          (start-process "clean" nil latexmk "-c" "-r" latexmkrc tex-file)
          (switch-to-buffer (get-file-buffer tex-file))
          (if (get-buffer-process (get-buffer tex-output))
            (process-kill-without-query (get-buffer-process (get-buffer tex-output))))
          (kill-buffer tex-output)
          (delete-other-windows))))))))

启动过程
将变量视为双引号。本质上,我的变量以双引号结束——这就是阻止我使用文件的绝对路径的原因。因此,简言之,当将变量与
启动进程
一起使用时,它不需要双引号

感谢所有帮助我解决问题的人,非常感谢

以下是修订后的工作职能:

(defun latexmk ()
".latexmkrc contains the following entries:
  $pdflatex = 'pdflatex -file-line-error -synctex=1 %O %S';
  $pdf_mode = 1;
  $recorder = 0;
  $clean_ext = 'synctex.gz synctex.gz(busy) aux fdb_latexmk log';"
(interactive)
  (setq tex-file (buffer-file-name))
  (setq base-file (car (split-string (buffer-file-name) "\\.tex")))
  (setq pdf-file (concat base-file ".pdf"))
  (setq line (format "%d" (line-number-at-pos)))
  (setq sumatra "c:/Program Files/SumatraPDF/SumatraPDF.exe")
  (setq tex-output (concat "*" (file-name-nondirectory buffer-file-name) "*") )
  (setq latexmk "c:/texlive/2013/bin/win32/latexmk.exe")
  (setq latexmkrc "c:/Documents and Settings/Administrator/Application Data/.emacs.d/.latexmkrc")
  (if (buffer-modified-p)
    (save-buffer))
  (delete-other-windows)
  (set-window-buffer (split-window-horizontally) (get-buffer-create tex-output))
  (with-current-buffer tex-output (erase-buffer))
  (start-process "tskill" nil "c:/WINDOWS/system32/tskill.exe" "SumatraPDF")
  (set-process-sentinel 
     (start-process "deep-clean" nil latexmk "-C" "-r" latexmkrc tex-file)
     (lambda (p e) (when (= 0 (process-exit-status p))
       (set-process-sentinel 
         (start-process "compile" tex-output latexmk "-r" latexmkrc tex-file)
         (lambda (p e) (when (= 0 (process-exit-status p))
          (start-process "displayline" nil sumatra "-forward-search" tex-file line pdf-file)
          (start-process "clean" nil latexmk "-c" "-r" latexmkrc tex-file)
          (switch-to-buffer (get-file-buffer tex-file))
          (if (get-buffer-process (get-buffer tex-output))
            (process-kill-without-query (get-buffer-process (get-buffer tex-output))))
          (kill-buffer tex-output)
          (delete-other-windows))))))))
此外,如果需要引用传递给shell的参数,请使用
shell quote-argument


另外,如果需要引用传递给shell的参数,请使用
shell quote-argument

(concat(car(分割字符串(缓冲区文件名)\\.tex”)))“.pdf”)
正确更改文件名,但添加双引号时会出现问题,在文件名包含空格的Windows操作系统上使用时,启动进程所需的
命令。感谢您提供了更改文件名的替代方法,再次感谢您提供了
(shell命令(concat“pdflatex--shell escape\”(缓冲区文件名)”)
,这最终帮助我理解了为什么我的变量不能正确使用
启动进程
(concat(car(split string(buffer file name)\\\.tex”))“.pdf”)
正确地更改了文件名,但添加双引号时会出现问题,在文件名包含空格的Windows操作系统上使用时,启动进程所需的
命令。感谢您提供了更改文件名的替代方法,再次感谢您提供了
(shell命令(concat“pdflatex--shell escape\”(缓冲区文件名)”)
,这最终帮助我理解了为什么我的变量在
start process
中无法正常工作。尽管您可以用@abo abo建议的
replace regexp in string
更简单,但您的e-lisp代码可以正确地在文件名周围加引号。我想问题在于调用可执行文件。“c:/SumatraPDF.exe”不应该在引号中吗?您是否尝试过在pdf文件周围不使用额外引号?如果文件夹名称中没有空格,并且我只使用基本文件名(没有绝对路径),但如果存在空格,则需要使用双引号,则可以正确显示pdf文件(不使用双引号)。如果有一种方法可以作为
启动过程的一部分转到root,那么这可能会解决它。可执行文件的路径是有效的,这可能是因为可执行文件的文件名中没有空格——如果有空格,那么可能还需要双引号。我用工作函数更新了这个问题,我正试图修改它,以使用带双引号的绝对文件路径,而不仅仅是基本文件名。我有一些使用Windows时留下的代码:
(shell命令(concat“pdflatex--shell escape\”(缓冲区文件名)”)
。你能试试吗?是的,那很好用!感谢您提供的工作示例。我查看了
simple.el中的
shell命令
,它使用
启动进程
。因此,当使用变量时,
start process
似乎会自动插入引号。如果我从变量中去掉双引号,只让
启动进程
完成它的工作,这似乎修复了我的函数,使我能够使用带有完整
缓冲区文件名的绝对路径
。不管您可以做得更简单,使用@abo abo建议的
替换字符串中的regexp
,您的e-lisp代码正常,并且正确地在文件名周围加上引号。我想问题在于调用可执行文件。“c:/SumatraPDF.exe”不应该在引号中吗?您是否尝试过在pdf文件周围不使用额外引号?如果文件夹名称中没有空格,并且我只使用基本文件名(没有绝对路径),但如果存在空格,则需要使用双引号,则可以正确显示pdf文件(不使用双引号)。如果有一种方法可以作为
启动过程的一部分转到root,那么这可能会解决它。可执行文件的路径是有效的,这可能是因为可执行文件的文件名中没有空格——如果有空格,那么可能还需要双引号。我用工作函数更新了这个问题,我正在尝试修改它