(defvar bookmarks-already-loaded nil
"Non-nil if and only if bookmarks have been loaded from `bookmark-default-file'.")
+(defvar bookmark-file-coding-system nil
+ "The coding-system of the last loaded or saved bookmark file.")
;; more stuff added by db.
(let* ((old-list (bookmark-alist-from-buffer))
(new-list (bookmark-upgrade-version-0-alist old-list)))
(delete-region (point-min) (point-max))
- (bookmark-insert-file-format-version-stamp)
+ (bookmark-insert-file-format-version-stamp buffer-file-coding-system)
(pp new-list (current-buffer))
(save-buffer))
(goto-char (point-min))
(error "Bookmark file format version strangeness")))))
-(defun bookmark-insert-file-format-version-stamp ()
- "Insert text indicating current version of bookmark file format."
+(defun bookmark-insert-file-format-version-stamp (coding)
+ "Insert text indicating current version of bookmark file format.
+CODING is the symbol of the coding-system in which the file is encoded."
+ (if (memq (coding-system-base coding) '(undecided prefer-utf-8))
+ (setq coding 'utf-8-emacs))
(insert
- (format ";;;; Emacs Bookmark Format Version %d ;;;;\n"
- bookmark-file-format-version))
+ (format ";;;; Emacs Bookmark Format Version %d ;;;; -*- coding: %S -*- \n"
+ bookmark-file-format-version (coding-system-base coding)))
(insert ";;; This format is meant to be slightly human-readable;\n"
";;; nevertheless, you probably don't want to edit it.\n"
";;; "
(with-current-buffer (get-buffer-create " *Bookmarks*")
(goto-char (point-min))
(delete-region (point-min) (point-max))
- (let ((print-length nil)
+ (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))
- (bookmark-insert-file-format-version-stamp)
+ (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
(condition-case nil
(write-region (point-min) (point-max) file)
(file-error (message "Can't write %s" file)))
+ (setq bookmark-file-coding-system coding-system-for-write)
(kill-buffer (current-buffer))
(bookmark-maybe-message
"Saving bookmarks to file %s...done" file)))))
(expand-file-name bookmark-default-file))
file)
(setq bookmarks-already-loaded t))
- (bookmark-bmenu-surreptitiously-rebuild-list))
+ (bookmark-bmenu-surreptitiously-rebuild-list)
+ (setq bookmark-file-coding-system buffer-file-coding-system))
(error "Invalid bookmark list in %s" file)))
(kill-buffer (current-buffer)))
(if (null no-msg)