From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#25365: 25.1; Coding system for bookmarks and desktop Date: Sat, 07 Jan 2017 14:46:19 +0200 Message-ID: <83pojzavhg.fsf@gnu.org> References: <87mvf57kdx.fsf@gmail.com> Reply-To: Eli Zaretskii NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=koi8-r Content-Transfer-Encoding: 8bit X-Trace: blaine.gmane.org 1483793246 12245 195.159.176.226 (7 Jan 2017 12:47:26 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 7 Jan 2017 12:47:26 +0000 (UTC) Cc: 25365-done@debbugs.gnu.org To: Dmitri Paduchikh Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Jan 07 13:47:16 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cPqOq-000126-7u for geb-bug-gnu-emacs@m.gmane.org; Sat, 07 Jan 2017 13:47:08 +0100 Original-Received: from localhost ([::1]:57427 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cPqOu-0001yx-8C for geb-bug-gnu-emacs@m.gmane.org; Sat, 07 Jan 2017 07:47:12 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:37793) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cPqOn-0001y9-Fd for bug-gnu-emacs@gnu.org; Sat, 07 Jan 2017 07:47:06 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cPqOk-00005a-AZ for bug-gnu-emacs@gnu.org; Sat, 07 Jan 2017 07:47:05 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:58539) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cPqOk-00005V-7R for bug-gnu-emacs@gnu.org; Sat, 07 Jan 2017 07:47:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1cPqOk-0002Vh-0y for bug-gnu-emacs@gnu.org; Sat, 07 Jan 2017 07:47:02 -0500 Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-To: bug-gnu-emacs@gnu.org Resent-Date: Sat, 07 Jan 2017 12:47:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: cc-closed 25365 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Mail-Followup-To: 25365@debbugs.gnu.org, eliz@gnu.org, dpaduchikh@gmail.com Original-Received: via spool by 25365-done@debbugs.gnu.org id=D25365.14837931709585 (code D ref 25365); Sat, 07 Jan 2017 12:47:01 +0000 Original-Received: (at 25365-done) by debbugs.gnu.org; 7 Jan 2017 12:46:10 +0000 Original-Received: from localhost ([127.0.0.1]:45704 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cPqNu-0002UX-0h for submit@debbugs.gnu.org; Sat, 07 Jan 2017 07:46:10 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:46672) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cPqNr-0002UC-UQ for 25365-done@debbugs.gnu.org; Sat, 07 Jan 2017 07:46:08 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cPqNi-0008EW-He for 25365-done@debbugs.gnu.org; Sat, 07 Jan 2017 07:46:02 -0500 Original-Received: from fencepost.gnu.org ([2001:4830:134:3::e]:46809) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cPqNi-0008ES-DD; Sat, 07 Jan 2017 07:45:58 -0500 Original-Received: from 84.94.185.246.cable.012.net.il ([84.94.185.246]:2365 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1cPqNh-0003Mh-NX; Sat, 07 Jan 2017 07:45:58 -0500 In-reply-to: <87mvf57kdx.fsf@gmail.com> (message from Dmitri Paduchikh on Thu, 05 Jan 2017 17:37:30 +0500) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:127876 Archived-At: > From: Dmitri Paduchikh > Date: Thu, 05 Jan 2017 17:37:30 +0500 > > It appears that all Cyrillic text in my bookmarks file has been > corrupted. I wasn't able to reproduce such a corruption using emacsš-Q, > so probably this is due to interference with my settings which I will > have to investigate. But in my opinion there is a problem with > bookmark.el as well since it ignores completely coding system when > saving bookmarks. Thus I have written the following two advices to fix > its behavior. It seems that they work as needed. > > (advice-add 'bookmark-write-file :around > #'(lambda (f &rest args) > (let ((coding-system-for-write (or coding-system-for-write 'utf-8-emacs))) > (apply f args))) > '((name . "coding"))) Thanks, I used something similar in the patch below, except that I think we should honor the existing coding cookie in the bookmark file, instead of forcing the user to override the default each time the file is saved. So we should record the encoding when we load the file, and apply it when saving. This way, the user could specify the non-default encoding only once, using "C-x RET c", and have that value honored by Emacs thereafter. > (advice-add 'bookmark-insert-file-format-version-stamp :before > #'(lambda (&rest args) > (when coding-system-for-write > (insert (format "\ > ;;;; Emacs Bookmark Format Version %d ;;;; > ;;; -*- coding: %S -*-\n" > bookmark-file-format-version > coding-system-for-write)))) > '((name . "coding"))) This is not quite right, as coding-system-for-write could be something inappropriate, like undecided or prefer-utf-8. And again, we should honor the existing encoding. So I modified this part to support that. I installed the patch below on the master branch. Please try it (after removing your advices) and see if it gives good results. If you see problems, please reopen this bug with the details. Thanks. > Besides, although desktop.el specifies coding system in its file, it is > old one - emacs-mule. Shouldn't this be utf-8-emacs these days instead? I'm not sure how many users share the desktop files with older Emacs versions that didn't support utf-8-emacs. There's nothing wrong with using emacs-mule in recent Emacs versions, for files that aren't supposed to be read by programs that are not Emacs. commit e272032769178768cf970839a9c22aba1f5b572e Author: Eli Zaretskii Date: Sat Jan 7 14:33:41 2017 +0200 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) diff --git a/lisp/bookmark.el b/lisp/bookmark.el index 3440a52..e18362b 100644 --- a/lisp/bookmark.el +++ b/lisp/bookmark.el @@ -267,6 +267,8 @@ bookmark-alist (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. @@ -689,7 +691,7 @@ bookmark-upgrade-file-format-from-0 (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)) @@ -726,11 +728,14 @@ bookmark-maybe-upgrade-file-format (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" ";;; " @@ -1417,14 +1422,17 @@ bookmark-write-file (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 @@ -1440,6 +1448,7 @@ bookmark-write-file (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))))) @@ -1521,7 +1530,8 @@ bookmark-load (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)