diff options
| author | Eli Zaretskii | 2017-01-07 14:33:41 +0200 |
|---|---|---|
| committer | Eli Zaretskii | 2017-01-07 14:33:41 +0200 |
| commit | e272032769178768cf970839a9c22aba1f5b572e (patch) | |
| tree | cc7e24310c5a874cef5e6acb910fb46ae9272d9a | |
| parent | 50fd04cd4b831a166db30292c4dc0c24be8e6e9d (diff) | |
| download | emacs-e272032769178768cf970839a9c22aba1f5b572e.tar.gz emacs-e272032769178768cf970839a9c22aba1f5b572e.zip | |
Specify encoding of the bookmark file
* lisp/bookmark.el (bookmark-insert-file-format-version-stamp):
Accept an argument CODING and include a 'coding:' cookie in the
bookmark file preamble.
(bookmark-upgrade-file-format-from-0): Call
'bookmark-insert-file-format-version-stamp' with the file buffer's
encoding, as detected when it was read.
(bookmark-file-coding-system): New variable.
(bookmark-load): Set bookmark-file-coding-system to the encoding
of the loaded file.
(bookmark-write-file): Bind coding-system-for-write to either the
user setting via "C-x RET c" or to the existing file encoding,
defaulting to 'utf-8-emacs'. Update the value of
bookmark-file-coding-system. (Bug#25365)
| -rw-r--r-- | lisp/bookmark.el | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/lisp/bookmark.el b/lisp/bookmark.el index 3440a52ad4d..e18362bca95 100644 --- a/lisp/bookmark.el +++ b/lisp/bookmark.el | |||
| @@ -267,6 +267,8 @@ or the deprecated form (BOOKMARK-NAME PARAM-ALIST). | |||
| 267 | (defvar bookmarks-already-loaded nil | 267 | (defvar bookmarks-already-loaded nil |
| 268 | "Non-nil if and only if bookmarks have been loaded from `bookmark-default-file'.") | 268 | "Non-nil if and only if bookmarks have been loaded from `bookmark-default-file'.") |
| 269 | 269 | ||
| 270 | (defvar bookmark-file-coding-system nil | ||
| 271 | "The coding-system of the last loaded or saved bookmark file.") | ||
| 270 | 272 | ||
| 271 | ;; more stuff added by db. | 273 | ;; more stuff added by db. |
| 272 | 274 | ||
| @@ -689,7 +691,7 @@ This expects to be called from `point-min' in a bookmark file." | |||
| 689 | (let* ((old-list (bookmark-alist-from-buffer)) | 691 | (let* ((old-list (bookmark-alist-from-buffer)) |
| 690 | (new-list (bookmark-upgrade-version-0-alist old-list))) | 692 | (new-list (bookmark-upgrade-version-0-alist old-list))) |
| 691 | (delete-region (point-min) (point-max)) | 693 | (delete-region (point-min) (point-max)) |
| 692 | (bookmark-insert-file-format-version-stamp) | 694 | (bookmark-insert-file-format-version-stamp buffer-file-coding-system) |
| 693 | (pp new-list (current-buffer)) | 695 | (pp new-list (current-buffer)) |
| 694 | (save-buffer)) | 696 | (save-buffer)) |
| 695 | (goto-char (point-min)) | 697 | (goto-char (point-min)) |
| @@ -726,11 +728,14 @@ This expects to be called from `point-min' in a bookmark file." | |||
| 726 | (error "Bookmark file format version strangeness"))))) | 728 | (error "Bookmark file format version strangeness"))))) |
| 727 | 729 | ||
| 728 | 730 | ||
| 729 | (defun bookmark-insert-file-format-version-stamp () | 731 | (defun bookmark-insert-file-format-version-stamp (coding) |
| 730 | "Insert text indicating current version of bookmark file format." | 732 | "Insert text indicating current version of bookmark file format. |
| 733 | CODING is the symbol of the coding-system in which the file is encoded." | ||
| 734 | (if (memq (coding-system-base coding) '(undecided prefer-utf-8)) | ||
| 735 | (setq coding 'utf-8-emacs)) | ||
| 731 | (insert | 736 | (insert |
| 732 | (format ";;;; Emacs Bookmark Format Version %d ;;;;\n" | 737 | (format ";;;; Emacs Bookmark Format Version %d ;;;; -*- coding: %S -*- \n" |
| 733 | bookmark-file-format-version)) | 738 | bookmark-file-format-version (coding-system-base coding))) |
| 734 | (insert ";;; This format is meant to be slightly human-readable;\n" | 739 | (insert ";;; This format is meant to be slightly human-readable;\n" |
| 735 | ";;; nevertheless, you probably don't want to edit it.\n" | 740 | ";;; nevertheless, you probably don't want to edit it.\n" |
| 736 | ";;; " | 741 | ";;; " |
| @@ -1417,14 +1422,17 @@ for a file, defaulting to the file defined by variable | |||
| 1417 | (with-current-buffer (get-buffer-create " *Bookmarks*") | 1422 | (with-current-buffer (get-buffer-create " *Bookmarks*") |
| 1418 | (goto-char (point-min)) | 1423 | (goto-char (point-min)) |
| 1419 | (delete-region (point-min) (point-max)) | 1424 | (delete-region (point-min) (point-max)) |
| 1420 | (let ((print-length nil) | 1425 | (let ((coding-system-for-write |
| 1426 | (or coding-system-for-write | ||
| 1427 | bookmark-file-coding-system 'utf-8-emacs)) | ||
| 1428 | (print-length nil) | ||
| 1421 | (print-level nil) | 1429 | (print-level nil) |
| 1422 | ;; See bug #12503 for why we bind `print-circle'. Users | 1430 | ;; See bug #12503 for why we bind `print-circle'. Users |
| 1423 | ;; can define their own bookmark types, which can result in | 1431 | ;; can define their own bookmark types, which can result in |
| 1424 | ;; arbitrary Lisp objects being stored in bookmark records, | 1432 | ;; arbitrary Lisp objects being stored in bookmark records, |
| 1425 | ;; and some users create objects containing circularities. | 1433 | ;; and some users create objects containing circularities. |
| 1426 | (print-circle t)) | 1434 | (print-circle t)) |
| 1427 | (bookmark-insert-file-format-version-stamp) | 1435 | (bookmark-insert-file-format-version-stamp coding-system-for-write) |
| 1428 | (insert "(") | 1436 | (insert "(") |
| 1429 | ;; Rather than a single call to `pp' we make one per bookmark. | 1437 | ;; Rather than a single call to `pp' we make one per bookmark. |
| 1430 | ;; Apparently `pp' has a poor algorithmic complexity, so this | 1438 | ;; Apparently `pp' has a poor algorithmic complexity, so this |
| @@ -1440,6 +1448,7 @@ for a file, defaulting to the file defined by variable | |||
| 1440 | (condition-case nil | 1448 | (condition-case nil |
| 1441 | (write-region (point-min) (point-max) file) | 1449 | (write-region (point-min) (point-max) file) |
| 1442 | (file-error (message "Can't write %s" file))) | 1450 | (file-error (message "Can't write %s" file))) |
| 1451 | (setq bookmark-file-coding-system coding-system-for-write) | ||
| 1443 | (kill-buffer (current-buffer)) | 1452 | (kill-buffer (current-buffer)) |
| 1444 | (bookmark-maybe-message | 1453 | (bookmark-maybe-message |
| 1445 | "Saving bookmarks to file %s...done" file))))) | 1454 | "Saving bookmarks to file %s...done" file))))) |
| @@ -1521,7 +1530,8 @@ unique numeric suffixes \"<2>\", \"<3>\", etc." | |||
| 1521 | (expand-file-name bookmark-default-file)) | 1530 | (expand-file-name bookmark-default-file)) |
| 1522 | file) | 1531 | file) |
| 1523 | (setq bookmarks-already-loaded t)) | 1532 | (setq bookmarks-already-loaded t)) |
| 1524 | (bookmark-bmenu-surreptitiously-rebuild-list)) | 1533 | (bookmark-bmenu-surreptitiously-rebuild-list) |
| 1534 | (setq bookmark-file-coding-system buffer-file-coding-system)) | ||
| 1525 | (error "Invalid bookmark list in %s" file))) | 1535 | (error "Invalid bookmark list in %s" file))) |
| 1526 | (kill-buffer (current-buffer))) | 1536 | (kill-buffer (current-buffer))) |
| 1527 | (if (null no-msg) | 1537 | (if (null no-msg) |