summaryrefslogtreecommitdiff
path: root/lisp/bookmark.el
diff options
context:
space:
mode:
authorEli Zaretskii <eliz@gnu.org>2017-01-10 17:47:10 +0200
committerEli Zaretskii <eliz@gnu.org>2017-01-10 17:47:10 +0200
commit560a384038845e37228226313eccfc8d70132553 (patch)
treebdd4bda64aa32f84e4c78a9cef02a90ec44022b4 /lisp/bookmark.el
parentef8c9f8fc922b615aca91b47820d1f1900fddc96 (diff)
downloademacs-560a384038845e37228226313eccfc8d70132553.tar.gz
Don't use unsafe encoding for the bookmark file
* lisp/bookmark.el (bookmark-write-file): Handle the case when the explicitly specified encoding of the bookmark file cannot encode the additional bookmarks just added. (Bug#25365)
Diffstat (limited to 'lisp/bookmark.el')
-rw-r--r--lisp/bookmark.el9
1 files changed, 8 insertions, 1 deletions
diff --git a/lisp/bookmark.el b/lisp/bookmark.el
index e18362bca95..02dd8a9f6fc 100644
--- a/lisp/bookmark.el
+++ b/lisp/bookmark.el
@@ -1432,13 +1432,20 @@ for a file, defaulting to the file defined by variable
;; arbitrary Lisp objects being stored in bookmark records,
;; and some users create objects containing circularities.
(print-circle t))
- (bookmark-insert-file-format-version-stamp coding-system-for-write)
(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.
(dolist (i bookmark-alist) (pp i (current-buffer)))
(insert ")")
+ ;; 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)