3

file-exists-pこの print-to-pdf 関数の対話型リスト内にif 条件を追加しようとすると問題が発生します。エラー メッセージは次のとおり file-name-sans-extension: Wrong type argument: stringp, tです。機能するセクションをコメントアウトしましたが、それでも、はいまたはいいえのプロンプトを表示せずに既存のファイルを上書きします。に置き換えてみましhello-worldpdf-file-nameが、エラーは修正されませんでした。

Emacs Trunk 開発者ビルド --with-ns OSX で を使用して、関数に追加が含まれてい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))
)
4

1 に答える 1

4

interactiveそもそもなぜ追加したいのですか?このようなものはあなたにとってうまくいきませんか?

(defun print-to-pdf (pdf-file-name)
  "Print the current buffer to the given file as PDF."
  (interactive (list (ns-read-file-name "Write PDF file: " "~/" nil ".pdf")))
  (when (and pdf-file-name
             (or (not (file-exists-p pdf-file-name))
                 (yes-or-no-p "File exists. Overwrite? ")))
    (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))))
于 2013-06-13T01:12:56.837 に答える