[PATCH] Pay more attention to the the locale's coding systems on startup

Aidan Kehoe kehoea at parhasard.net
Sun Nov 12 13:13:47 EST 2006


Problems with this patch: 

1. It doesn’t deal with the @modifier syntax in Unix locale specifications,
which are structured like so: 

        language[_territory][.codeset][@modifier]

2. It’s relatively complex code to be called so early on startup. 

Advantages to this patch: 

1. More stuff just works under Unix; in particular, the coding system
reflects the user’s environment much more consistently--it adds some support
for ISO-8859-15 locales, which previously were treated identically to
iso-8859-1.

2. It’s possible for me to start up in, for example, the directory
"/tmp/aidan/за родину!" with a LC_CTYPE setting of en_US.UTF-8, and have
XEmacs treat the current directory’s name as being encoded in UTF-8.

lisp/ChangeLog addition:

2006-11-12  Aidan Kehoe  <kehoea at parhasard.net>

	* mule/mule-cmds.el (get-language-environment-from-locale):
	If the Unix locale matches, and the language environment doesn't
	use the coding system specified in that locale, create a new one
	on the fly that does, and return that language environment. 
	

XEmacs Trunk source patch:
Diff command:   cvs -q diff -Nu
Files affected: lisp/mule/mule-cmds.el
===================================================================
RCS

Index: lisp/mule/mule-cmds.el
===================================================================
RCS file: /pack/xemacscvs/XEmacs/xemacs/lisp/mule/mule-cmds.el,v
retrieving revision 1.27
diff -u -u -r1.27 mule-cmds.el
--- lisp/mule/mule-cmds.el	2005/12/24 21:59:21	1.27
+++ lisp/mule/mule-cmds.el	2006/11/12 17:59:40
@@ -1018,23 +1018,64 @@
   "Convert LOCALE into a language environment.
 LOCALE is a C library locale string, as returned by `current-locale'.
 Uses the `locale' property of the language environment."
-  (or (gethash locale langenv-to-locale-hash)
-      (let ((retval
-	     (block langenv
-	       (dolist (langcons language-info-alist)
-		 (let* ((lang (car langcons))
-			(locs (get-language-info lang 'locale))
-			(case-fold-search t))
-		   (dolist (loc (if (listp locs) locs (list locs)))
-		     (if (cond ((functionp loc)
-				(funcall loc locale))
-			       ((stringp loc)
-				(string-match
-				 (concat "^" loc "\\([^A-Za-z0-9]\\|$\\)")
-				 locale)))
-			 (return-from langenv lang))))))))
-	(puthash locale retval langenv-to-locale-hash)
-	retval)))
+  (or 
+   (gethash locale langenv-to-locale-hash)
+   (let ((retval
+	  (block langenv
+	    (dolist (langcons language-info-alist)
+	      (let* ((lang (car langcons))
+		     (locs (get-language-info lang 'locale))
+		     (case-fold-search t)
+		     (coding-system-name ""))
+		(dolist (loc (if (listp locs) locs (list locs)))
+		  (if (cond ((functionp loc)
+			     (funcall loc locale))
+			    ((stringp loc)
+			     (when (string-match
+				    (concat "^" loc
+					    "\\([^A-Za-z0-9]\\|$\\)")
+				    locale)
+			       ; (debug-print "Dealing with language %s"
+			       ;	    loc)
+			       (setq coding-system-name
+				     (replace-in-string
+				      (replace-in-string
+				       (or
+					(downcase 
+					 (or (car-safe
+					      (nreverse
+					       (split-string locale "\\."
+							     t)))
+					     locale)) locale)
+				       "iso8859" "iso-8859" t)
+				      "euc\\([^-]\\)" "euc-\\1"))
+			       ; (debug-print "coding system name is %s"
+			       ; coding-system-name)
+			       (if (eq (find-coding-system
+					(intern coding-system-name))
+				       (get-language-info 
+					lang 'native-coding-system))
+				   lang
+				 (set-language-info-alist
+				  (setq lang (concat
+					      lang " ("
+					      coding-system-name ")"))
+				  (destructive-plist-to-alist
+				   (plist-put
+				    (plist-put
+				     (alist-to-plist (cdr langcons))
+				     'native-coding-system
+				     (intern coding-system-name))
+				    'coding-system
+				    (cons 
+				     (intern coding-system-name) 
+				     (cdr
+				      (assoc 'coding-system
+					     (cdr langcons))))))))
+			       t)))
+		      (return-from langenv lang))))))))
+     (puthash locale retval langenv-to-locale-hash)
+     retval)))
 
 (defun mswindows-get-language-environment-from-locale (ms-locale)
   "Convert MS-LOCALE (an MS Windows locale) into a language environment.

-- 
Santa Maradona, priez pour moi!



More information about the XEmacs-Patches mailing list