0

谁能帮我连接双引号:

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

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

我正在尝试使用:

(setq pdf-file
  (concat "\"" (car (split-string (buffer-file-name) "\\.tex")) ".pdf" "\""))

当我打电话(start-process "display" nil c:/SumatraPDF.exe pdf-file)时,pdf查看器会尝试打开它:

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

编辑:这是我试图修改的功能。正如我在下面的回答中所述,该错误是由于我无意中将文件名引号引起的 - 即,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)))))))))))
4

3 回答 3

2

我猜你想要:

(replace-regexp-in-string
 "\\.tex$"
 ".pdf"
 "c:/Documents and Settings/All Users/Desktop/foo.tex")    
于 2013-10-14T18:26:42.200 回答
2
(setq pdf-file (concat (file-name-sans-extension (buffer-file-name)) ".pdf"))

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

于 2013-10-15T08:19:18.570 回答
0

start-process将变量视为双引号。从本质上讲,我的变量最终被引号引用——这就是阻止我使用文件的绝对路径的原因。因此,简而言之,当使用带有 的变量时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 (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))))))))
于 2013-10-14T20:08:58.103 回答