Function: org-persist--write-elisp-file

org-persist--write-elisp-file is a byte-compiled function defined in org-persist.el.gz.

Signature

(org-persist--write-elisp-file FILE DATA &optional NO-CIRCULAR PP)

Documentation

Write elisp DATA to FILE.

Source Code

;; Defined in /usr/src/emacs/lisp/org/org-persist.el.gz
;; FIXME: `pp' is very slow when writing even moderately large datasets
;; We should probably drop it or find some fast formatter.
(defun org-persist--write-elisp-file (file data &optional no-circular pp)
  "Write elisp DATA to FILE."
  ;; Fsync slightly reduces the chance of an incomplete filesystem
  ;; write, however on modern hardware its effectiveness is
  ;; questionable and it is insufficient to guarantee complete writes.
  ;; Coupled with the significant performance hit if writing many
  ;; small files, it simply does not make sense to use fsync here,
  ;; particularly as cache corruption is only a minor inconvenience.
  ;; With all this in mind, we ensure `write-region-inhibit-fsync' is
  ;; set.
  ;;
  ;; To read more about this, see the comments in Emacs's 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 'emacs-internal)
        (print-circle (not no-circular))
        print-level
        print-length
        print-quoted
        (print-escape-control-characters t)
        (print-escape-nonascii t)
        (print-continuous-numbering t)
        print-number-table
        (start-time (float-time)))
    (unless (file-exists-p (file-name-directory file))
      (make-directory (file-name-directory file) t))
    ;; Force writing even when the file happens to be opened by
    ;; another Emacs process.
    (cl-letf (((symbol-function #'ask-user-about-lock)
               ;; FIXME: Emacs 27 does not yet have `always'.
               (lambda (&rest _) t)))
      (with-temp-file file
        (insert ";;   -*- mode: lisp-data; -*-\n")
        (if pp
            (let ((pp-use-max-width nil)) ; Emacs bug#58687
              (pp data (current-buffer)))
          (prin1 data (current-buffer)))))
    (org-persist--display-time
     (- (float-time) start-time)
     "Writing to %S" file)))