我在尝试在file-exists-p
此 print-to-pdf 函数的交互式列表中添加 if 条件时遇到了困难。错误信息是: file-name-sans-extension: Wrong type argument: stringp, t
。我已经注释掉了有效的部分,但是它覆盖了现有文件而不提示是或否。我试过用 替换hello-world
,pdf-file-name
但这并没有解决错误。
Emacs Trunk 开发人员在 OSX 上构建 --with-ns,使用, 喜欢在不提示的情况下覆盖文件,除非函数中包含ns-read-file-name
附加内容。file-exists-p
(defun print-to-pdf (pdf-file-name)
"Print the current file to the given file."
;; (interactive (list (ns-read-file-name "Write PDF file: " "~/" nil ".pdf")
(interactive (list
(let ((hello-world (ns-read-file-name "Write PDF file: " "~/" nil ".pdf")))
(if (file-exists-p hello-world)
(or (yes-or-no-p (format "File %s exists. Save anyway? " hello-world))
(error ""))))
))
(let (
(ps-file-name (concat (file-name-sans-extension pdf-file-name) ".ps"))
(wbuf (generate-new-buffer "*Wrapped*"))
(sbuf (current-buffer)))
(jit-lock-fontify-now)
(save-current-buffer
(set-buffer wbuf)
(insert-buffer sbuf)
(longlines-mode t)
(harden-newlines)
(message (buffer-name sbuf))
(spool-buffer-given-name (buffer-name sbuf))
(kill-buffer wbuf)
(switch-to-buffer "*PostScript*")
(write-file ps-file-name)
(kill-buffer (current-buffer)))
(call-process "/usr/local/bin/ps2pdf14" nil nil nil ps-file-name pdf-file-name)
(delete-file ps-file-name)
(message "PDF saved to %s" pdf-file-name))
)