feat(lib): doom-file-write: separate :mode for directories
doom-file-write's :mode parameter now accepts a cons cell, whose CDR will determine the file mode for directories that get implicitly created by the function.
This commit is contained in:
parent
be90021330
commit
f1e77e6692
1 changed files with 17 additions and 13 deletions
|
@ -302,8 +302,10 @@ If CONTENTS is list of forms. Any literal strings in the list are inserted
|
||||||
verbatim, as text followed by a newline, with `insert'. Sexps are inserted with
|
verbatim, as text followed by a newline, with `insert'. Sexps are inserted with
|
||||||
`prin1'. BY is the function to use to emit
|
`prin1'. BY is the function to use to emit
|
||||||
|
|
||||||
MODE dictates the permissions of the file. If FILE already exists, its
|
MODE dictates the permissions of created file and directories. MODE is either an
|
||||||
permissions will be changed.
|
integer or a cons cell whose car is the mode for files and cdr the mode for
|
||||||
|
directories. If FILE already exists, its permissions will be changed. The
|
||||||
|
permissions of existing directories will never be changed.
|
||||||
|
|
||||||
CODING dictates the encoding to read/write with (see `coding-system-for-write').
|
CODING dictates the encoding to read/write with (see `coding-system-for-write').
|
||||||
This defaults to `utf-8'. If set to nil, `binary' is used.
|
This defaults to `utf-8'. If set to nil, `binary' is used.
|
||||||
|
@ -311,9 +313,10 @@ This defaults to `utf-8'. If set to nil, `binary' is used.
|
||||||
APPEND dictates where CONTENTS will be written. If neither is set,
|
APPEND dictates where CONTENTS will be written. If neither is set,
|
||||||
the file will be overwritten. If both are, the contents will be written to both
|
the file will be overwritten. If both are, the contents will be written to both
|
||||||
ends. Set either APPEND or PREPEND to `noerror' to silently ignore read errors."
|
ends. Set either APPEND or PREPEND to `noerror' to silently ignore read errors."
|
||||||
(doom--with-prepared-file-buffer file coding mode
|
(let ((mode (ensure-list mode))
|
||||||
(let ((contents (ensure-list contents))
|
(contents (ensure-list contents))
|
||||||
datum)
|
datum)
|
||||||
|
(doom--with-prepared-file-buffer file coding (car mode)
|
||||||
(while (setq datum (pop contents))
|
(while (setq datum (pop contents))
|
||||||
(cond ((stringp datum)
|
(cond ((stringp datum)
|
||||||
(funcall
|
(funcall
|
||||||
|
@ -332,14 +335,15 @@ ends. Set either APPEND or PREPEND to `noerror' to silently ignore read errors."
|
||||||
(print-escape-control-characters t)
|
(print-escape-control-characters t)
|
||||||
(print-escape-nonascii t)
|
(print-escape-nonascii t)
|
||||||
(print-escape-multibyte t))
|
(print-escape-multibyte t))
|
||||||
(funcall printfn datum))))))
|
(funcall printfn datum)))))
|
||||||
(let (write-region-annotate-functions
|
(let (write-region-annotate-functions
|
||||||
write-region-post-annotation-function)
|
write-region-post-annotation-function)
|
||||||
(when mkdir
|
(when mkdir
|
||||||
(make-directory (file-name-directory buffer-file-name)
|
(with-file-modes (or (cdr mode) (default-file-modes))
|
||||||
(eq mkdir 'parents)))
|
(make-directory (file-name-directory buffer-file-name)
|
||||||
(write-region nil nil buffer-file-name append :silent))
|
(eq mkdir 'parents))))
|
||||||
buffer-file-name))
|
(write-region nil nil buffer-file-name append :silent))
|
||||||
|
buffer-file-name)))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defmacro with-file-contents! (file &rest body)
|
(defmacro with-file-contents! (file &rest body)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue