diff options
-rw-r--r-- | bookmark-conf.el | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/bookmark-conf.el b/bookmark-conf.el index f2a36b2..cd88eae 100644 --- a/bookmark-conf.el +++ b/bookmark-conf.el @@ -341,6 +341,83 @@ BOOKMARK should be set by `durand-set-external-bookmark'." "(External) cool ITA") )) +;;; A much quicker alternative to `bookmark-write-file' + +(defun durand-bookmark-write-file (file) + "Write `bookmark-alist' to FILE. +Modified by Durand to use `print' instead of `pp'. +-- 2022-07-16 13:09:22.777148" + (let ((reporter (make-progress-reporter + (format "Saving bookmarks to file %s..." file)))) + (with-current-buffer (get-buffer-create " *Bookmarks*") + (goto-char (point-min)) + (delete-region (point-min) (point-max)) + (let ((coding-system-for-write + (or coding-system-for-write + bookmark-file-coding-system 'utf-8-emacs)) + (print-length nil) + (print-level nil) + ;; See bug #12503 for why we bind `print-circle'. Users + ;; can define their own bookmark types, which can result in + ;; arbitrary Lisp objects being stored in bookmark records, + ;; and some users create objects containing circularities. + (print-circle t)) + (insert "(") + ;; Rather than a single call to `pp' we make one per bookmark. + ;; Apparently `pp' has a poor algorithmic complexity, so this + ;; scales a lot better. bug#4485. + ;; + ;; Using print is better. Durand -- 2022-07-16 13:10:25.084726 + (dolist (i bookmark-alist) (print i (current-buffer))) + (insert ")\n") + ;; Make sure the specified encoding can safely encode the + ;; bookmarks. If it cannot, suggest utf-8-emacs as default. + (with-coding-priority '(utf-8-emacs) + (setq coding-system-for-write + (select-safe-coding-system (point-min) (point-max) + (list t coding-system-for-write)))) + (goto-char (point-min)) + (bookmark-insert-file-format-version-stamp coding-system-for-write) + (let ((version-control + (cond + ((null bookmark-version-control) nil) + ((eq 'never bookmark-version-control) 'never) + ((eq 'nospecial bookmark-version-control) version-control) + (t t)))) + (condition-case nil + ;; There was a stretch of time (about 15 years) when we + ;; used `write-region' below instead of `write-file', + ;; before going back to `write-file' again. So if you're + ;; considering changing it to `write-region', please see + ;; https://debbugs.gnu.org/cgi/bugreport.cgi?bug=12507. + ;; That bug tells the story of how we first started using + ;; `write-region' in 2005... + ;; + ;; commit a506054af7cd86a63fda996056c09310966f32ef + ;; Author: Karl Fogel <kfogel@red-bean.com> + ;; AuthorDate: Sat Nov 12 20:30:22 2005 +0000 + ;; + ;; (bookmark-write-file): Don't visit the + ;; destination file, just write the data to it + ;; using write-region. This is similar to + ;; 2005-05-29T08:36:26Z!rms@gnu.org of saveplace.el, + ;; but with an additional change to avoid visiting + ;; the file in the first place. + ;; + ;; ...and of how further inquiry led us to investigate (in + ;; 2012 and then again in 2020) and eventually decide that + ;; matching the saveplace.el change doesn't make sense for + ;; bookmark.el. Therefore we reverted to `write-file', + ;; which means numbered backups may now be created, + ;; depending on `bookmark-version-control' as per above. + (write-file file) + (file-error (message "Can't write %s" file))) + (setq bookmark-file-coding-system coding-system-for-write) + (kill-buffer (current-buffer)) + (progress-reporter-done reporter)))))) + +(advice-add #'bookmark-write-file :override #'durand-bookmark-write-file) + (provide 'bookmark-conf) ;;; bookmark-conf.el ends here |