首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何连接要在开始进程中使用的双引号

如何连接要在开始进程中使用的双引号
EN

Stack Overflow用户
提问于 2013-10-14 18:18:11
回答 3查看 554关注 0票数 0

有人能帮我把双引号连起来吗?

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

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

我试着用:

代码语言:javascript
复制
(setq pdf-file
  (concat "\"" (car (split-string (buffer-file-name) "\\.tex")) ".pdf" "\""))

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

代码语言:javascript
复制
c:\Documents and Settings\All Users\Desktop"c:\Documents and Settings\All Users\Desktop\foo.pdf"

编辑:这是我试图修改的函数。正如我在下面的回答中所述,错误是由我无意中让double-double-quoted文件名--即,start-process将一个变量视为双引号--造成的,所以我根本不需要连接另一组双引号。

代码语言:javascript
复制
(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)))))))))))
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2013-10-14 20:08:58

start-process将变量视为双引号。本质上,我的变量是double-double-quoted --这就是阻止我使用文件的绝对路径的原因。因此,简单地说,在使用带有start-process的变量时,不需要重复引用。

感谢每一个帮助我解决这个问题的人--非常感谢!

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

代码语言:javascript
复制
(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))))))))
票数 0
EN

Stack Overflow用户

发布于 2013-10-14 18:26:42

我猜你想:

代码语言:javascript
复制
(replace-regexp-in-string
 "\\.tex$"
 ".pdf"
 "c:/Documents and Settings/All Users/Desktop/foo.tex")    
票数 2
EN

Stack Overflow用户

发布于 2013-10-15 08:19:18

代码语言:javascript
复制
(setq pdf-file (concat (file-name-sans-extension (buffer-file-name)) ".pdf"))

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19366559

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档