forked from mirrors/org-mode
org-persist: Set utf-8 coding when reading/writing
* lisp/org-persist.el (org-persist--write-elisp-file, org-persist--read-elisp-file): Instead of letting `find-auto-coding' be invoked to determine the coding for org-persist cache files (which can be surprisingly expensive), we simply set utf-8 coding when reading/writing.
This commit is contained in:
parent
e9c0696f79
commit
c8f88589cb
|
@ -386,14 +386,15 @@ FORMAT and ARGS are passed to `message'."
|
|||
|
||||
(defun org-persist--read-elisp-file (&optional buffer-or-file)
|
||||
"Read elisp data from BUFFER-OR-FILE or current buffer."
|
||||
(unless buffer-or-file (setq buffer-or-file (current-buffer)))
|
||||
(let (;; UTF-8 is explicitly used in `org-persist--write-elisp-file'.
|
||||
(coding-system-for-read 'utf-8)
|
||||
(buffer-or-file (or buffer-or-file (current-buffer))))
|
||||
(with-temp-buffer
|
||||
(if (bufferp buffer-or-file)
|
||||
(set-buffer buffer-or-file)
|
||||
(insert-file-contents buffer-or-file))
|
||||
(condition-case err
|
||||
(let ((coding-system-for-read 'utf-8)
|
||||
(read-circle t)
|
||||
(let ((read-circle t)
|
||||
(start-time (float-time)))
|
||||
;; FIXME: Reading sometimes fails to read circular objects.
|
||||
;; I suspect that it happens when we have object reference
|
||||
|
@ -416,7 +417,7 @@ FORMAT and ARGS are passed to `message'."
|
|||
buffer-or-file (error-message-string err))
|
||||
(warn "Emacs reader failed to read data in %S. The error was: %S"
|
||||
buffer-or-file (error-message-string err)))
|
||||
nil))))
|
||||
nil)))))
|
||||
|
||||
(defun org-persist--write-elisp-file (file data &optional no-circular pp)
|
||||
"Write elisp DATA to FILE."
|
||||
|
@ -432,6 +433,9 @@ FORMAT and ARGS are passed to `message'."
|
|||
;; To read more about this, see the comments in Emacs' fileio.c, in
|
||||
;; particular the large comment block in init_fileio.
|
||||
(let ((write-region-inhibit-fsync t)
|
||||
;; We set UTF-8 here and in `org-persist--read-elisp-file'
|
||||
;; to avoid the overhead from `find-auto-coding'.
|
||||
(coding-system-for-write 'utf-8)
|
||||
(print-circle (not no-circular))
|
||||
print-level
|
||||
print-length
|
||||
|
|
Loading…
Reference in a new issue