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 to index and then write elisp DATA to FILE.

When optional argument NO-CIRCULAR is non-nil, do not bind print-circle to t. When optional argument PP is non-nil, pretty-print the data (slow on moderately large data).

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 to index and then write elisp DATA to FILE.
When optional argument NO-CIRCULAR is non-nil, do not bind
`print-circle' to t.
When optional argument PP is non-nil, pretty-print the data (slow on
moderately large data)."
  ;; 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))
        (tmp-file (make-temp-file "org-persist-")))
    (unless (file-exists-p (file-name-directory file))
      (make-directory (file-name-directory file) t))
    ;; Do not write to FILE directly.  Another Emacs instance may be
    ;; doing the same at the same time.  Instead, write to new
    ;; temporary file and then rename it (renaming is atomic
    ;; operation that does not create data races).
    ;; See https://debbugs.gnu.org/cgi/bugreport.cgi?bug=75209#35
    (with-temp-file tmp-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))))
    (rename-file tmp-file file 'overwrite)
    (org-persist--display-time
     (- (float-time) start-time)
     "Writing to %S" file)))