初稿: 2018-07-23 Mon 13:57
最終更新日: 2018-12-14 Fri 20:44
ホーム | 文書トップ | 目次

with-temp-file
ファイルを開く

with-temp-file はファイル名を指定して開く関数です。

with-temp-file is a Lisp macro in ‘subr.el’.

(with-temp-file FILE &rest BODY)

Create a new buffer, evaluate BODY there, and write the buffer to FILE. The value returned is the value of the last form in BODY. See also ‘with-temp-buffer’.

 1: (defmacro with-temp-file (file &rest body)
 2:   "Create a new buffer, evaluate BODY there, and write the buffer to FILE.
 3: The value returned is the value of the last form in BODY.
 4: See also `with-temp-buffer'."
 5:   (declare (indent 1) (debug t))
 6:   (let ((temp-file (make-symbol "temp-file"))
 7:         (temp-buffer (make-symbol "temp-buffer")))
 8:     `(let ((,temp-file ,file)
 9:            (,temp-buffer
10:             (get-buffer-create (generate-new-buffer-name " *temp file*"))))
11:        (unwind-protect
12:            (prog1
13:                (with-current-buffer ,temp-buffer
14:                  ,@body)
15:              (with-current-buffer ,temp-buffer
16:                (write-region nil nil ,temp-file nil 0)))
17:          (and (buffer-name ,temp-buffer)
18:               (kill-buffer ,temp-buffer))))))

日付: 2018-07-23 Mon 13:57

著者: conao

Created: 2018-12-14 Fri 21:04

Validate