emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] /srv/bzr/emacs/trunk r103717: Use utf-8 if safe for writin


From: Leo Liu
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r103717: Use utf-8 if safe for writing to abbrev file
Date: Tue, 22 Mar 2011 23:38:40 +0800
User-agent: Bazaar (2.0.3)

------------------------------------------------------------
revno: 103717
committer: Leo Liu <address@hidden>
branch nick: trunk
timestamp: Tue 2011-03-22 23:38:40 +0800
message:
  Use utf-8 if safe for writing to abbrev file
  
  and fall back on emacs-mule or utf-8-emacs.
modified:
  lisp/ChangeLog
  lisp/abbrev.el
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2011-03-22 15:15:21 +0000
+++ b/lisp/ChangeLog    2011-03-22 15:38:40 +0000
@@ -1,3 +1,9 @@
+2011-03-22  Leo Liu  <address@hidden>
+
+       * abbrev.el (write-abbrev-file): Use utf-8 for writing if it can
+       encode all chars in abbrevs; otherwise use emacs-mule or
+       utf-8-emacs.  (Bug#8308)
+
 2011-03-22  Juanma Barranquero  <address@hidden>
 
        * simple.el (backward-delete-char-untabify):

=== modified file 'lisp/abbrev.el'
--- a/lisp/abbrev.el    2011-01-25 04:08:28 +0000
+++ b/lisp/abbrev.el    2011-03-22 15:38:40 +0000
@@ -225,21 +225,29 @@
                    abbrev-file-name)))
   (or (and file (> (length file) 0))
       (setq file abbrev-file-name))
-  (let ((coding-system-for-write 'emacs-mule))
-    (with-temp-file file
-      (insert ";;-*-coding: emacs-mule;-*-\n")
+  (let ((coding-system-for-write 'utf-8))
+    (with-temp-buffer
       (dolist (table
-               ;; We sort the table in order to ease the automatic
-               ;; merging of different versions of the user's abbrevs
-               ;; file.  This is useful, for example, for when the
-               ;; user keeps their home directory in a revision
-               ;; control system, and is therefore keeping multiple
-               ;; slightly-differing copies loosely synchronized.
-               (sort (copy-sequence abbrev-table-name-list)
-                     (lambda (s1 s2)
-                       (string< (symbol-name s1)
-                                (symbol-name s2)))))
-       (insert-abbrev-table-description table nil)))))
+              ;; We sort the table in order to ease the automatic
+              ;; merging of different versions of the user's abbrevs
+              ;; file.  This is useful, for example, for when the
+              ;; user keeps their home directory in a revision
+              ;; control system, and is therefore keeping multiple
+              ;; slightly-differing copies loosely synchronized.
+              (sort (copy-sequence abbrev-table-name-list)
+                    (lambda (s1 s2)
+                      (string< (symbol-name s1)
+                               (symbol-name s2)))))
+       (insert-abbrev-table-description table nil))
+      (when (unencodable-char-position (point-min) (point-max) 'utf-8)
+       (setq coding-system-for-write
+             (if (> emacs-major-version 24)
+                 'utf-8-emacs
+               ;; For compatibility with Emacs 22 (See Bug#8308)
+               'emacs-mule)))
+      (goto-char (point-min))
+      (insert (format ";;-*-coding: %s;-*-\n" coding-system-for-write))
+      (write-region nil nil file nil 0))))
 
 (defun add-mode-abbrev (arg)
   "Define mode-specific abbrev for last word(s) before point.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]