unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Dmitri Paduchikh <dpaduchikh@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 25365@debbugs.gnu.org
Subject: bug#25365: 25.1; Coding system for bookmarks and desktop
Date: Mon, 09 Jan 2017 22:07:49 +0500	[thread overview]
Message-ID: <874m18yxei.fsf@gmail.com> (raw)
In-Reply-To: <83k2a5blo9.fsf@gnu.org> (Eli Zaretskii's message of "Sun, 08 Jan 2017 17:45:10 +0200")

Eli Zaretskii <eliz@gnu.org> wrote:

[...]

>> Also setting coding system through coding-system-for-write will make
>> non-encodable characters replaced by spaces.

EZ> This option exists for users who really know what they are doing; the
EZ> default utf-8-emacs encoding is safe for any and all characters Emacs
EZ> supports.

It may be hard to know what is happening if it is designed to happen
automatically. So, if you insist on supporting user choice here, please
consider the following patch. It adds the check of workability of the chosen
codec unless it is given directly by user in which case the usual procedure
applies, or the codec is omnipotent. In the case of encodability problems it
will fallback to utf-8-emacs.

I hope it is trivial enough as I did not sign papers.

diff --git a/lisp/bookmark.el b/lisp/bookmark.el
index e18362bca9..87638cdf1e 100644
--- a/lisp/bookmark.el
+++ b/lisp/bookmark.el
@@ -1432,13 +1432,21 @@ 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 ")")
+      ;; Check that coding system is safe unless it is given directly by
+      ;; user or is omnipotent. Silently fallback to utf-8-emacs in a case.
+      (unless (or coding-system-require-warning ; coding is given by user
+                  (memq 'emacs (coding-system-charset-list coding-system-for-write)))
+        (setq coding-system-for-write
+              (select-safe-coding-system (point-min) (point-max)
+                                         (list coding-system-for-write 'utf-8-emacs) t)))
+      (goto-char (point-min))
+      (bookmark-insert-file-format-version-stamp coding-system-for-write)
       (let ((version-control
              (cond
               ((null bookmark-version-control) nil)

With best regards
Dmitri Paduchikh








  parent reply	other threads:[~2017-01-09 17:07 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-05 12:37 bug#25365: 25.1; Coding system for bookmarks and desktop Dmitri Paduchikh
2017-01-06 14:56 ` Dmitri Paduchikh
2017-01-07 12:46 ` Eli Zaretskii
     [not found]   ` <87d1fxzy9d.fsf@gmail.com>
     [not found]     ` <83k2a5blo9.fsf@gnu.org>
2017-01-09 17:07       ` Dmitri Paduchikh [this message]
2017-01-09 18:49         ` Eli Zaretskii
2017-01-09 20:34           ` Dmitri Paduchikh
2017-01-10 15:49             ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=874m18yxei.fsf@gmail.com \
    --to=dpaduchikh@gmail.com \
    --cc=25365@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).