From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Karl Eichwalder Newsgroups: gmane.emacs.devel Subject: Patch for GNU gettext (Re: PO files and Emacs) Date: Sun, 17 Mar 2002 12:40:58 +0100 Sender: emacs-devel-admin@gnu.org Message-ID: References: <15502.734.892880.44892@honolulu.ilog.fr> <3405-Fri15Mar2002152940+0200-eliz@is.elta.co.il> <15506.16597.304994.7358@honolulu.ilog.fr> <4634-Sat16Mar2002112609+0200-eliz@is.elta.co.il> <1858-Sat16Mar2002192901+0200-eliz@is.elta.co.il> <557-Sun17Mar2002063542+0200-eliz@is.elta.co.il> Reply-To: Karl Eichwalder NNTP-Posting-Host: localhost.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: main.gmane.org 1016367005 13518 127.0.0.1 (17 Mar 2002 12:10:05 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Sun, 17 Mar 2002 12:10:05 +0000 (UTC) Cc: Eli Zaretskii , emacs-devel@gnu.org Original-Received: from quimby.gnus.org ([80.91.224.244]) by main.gmane.org with esmtp (Exim 3.33 #1 (Debian)) id 16mZUD-0003Vw-00 for ; Sun, 17 Mar 2002 13:10:05 +0100 Original-Received: from fencepost.gnu.org ([199.232.76.164]) by quimby.gnus.org with esmtp (Exim 3.12 #1 (Debian)) id 16mZXz-0006uU-00 for ; Sun, 17 Mar 2002 13:14:00 +0100 Original-Received: from localhost ([127.0.0.1] helo=fencepost.gnu.org) by fencepost.gnu.org with esmtp (Exim 3.34 #1 (Debian)) id 16mZTL-0000Iq-00; Sun, 17 Mar 2002 07:09:11 -0500 Original-Received: from dns.franken.de ([193.175.24.33] helo=elvis.franken.de) by fencepost.gnu.org with esmtp (Exim 3.34 #1 (Debian)) id 16mZ3f-0007Eb-00 for ; Sun, 17 Mar 2002 06:42:40 -0500 Original-Received: from uucp by elvis.franken.de with local-rmail (Exim 3.22 #1) id 16mZ3e-0008RX-00; Sun, 17 Mar 2002 12:42:38 +0100 Original-Received: by tux.gnu.franken.de (Postfix, from userid 270) id B7BC1A4453; Sun, 17 Mar 2002 11:40:58 +0000 (UTC) Original-To: haible@ilog.fr In-Reply-To: (Karl Eichwalder's message of "Sun, 17 Mar 2002 06:26:03 +0100") Original-Lines: 432 User-Agent: Gnus/5.090006 (Oort Gnus v0.06) Emacs/21.2.50 (i686-pc-linux-gnu) Errors-To: emacs-devel-admin@gnu.org X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.0.5 Precedence: bulk List-Help: List-Post: List-Subscribe: , List-Id: Emacs development discussions. List-Unsubscribe: , List-Archive: Xref: main.gmane.org gmane.emacs.devel:1983 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:1983 Karl Eichwalder writes: > Now I'll try to find a way make it load gettext's po-mode.el in addition. A special hook isn't required; applying the appended patch against gettext's po-mode.el works for me. Poeple wanting to use it for Emacs < 21.2.50 or for XEmacs must change this line in their .emacs: (autoload 'po-find-file-coding-system "po-mode") This `po-find-file-coding-system' now comes with po-compat.el. 2002-03-17 Karl Eichwalder * po-compat.el: New file. Copy compatibility variables from po-mode.el. (po-content-type-charset-alist): Takeover from po-mode.el. (po-find-charset): Likewise. (po-find-file-coding-system-guts): Likewise. * po-mode (po-content-type-charset-alist): Delete. (po-find-charset): Likewise. (po-find-file-coding-system-guts): Likewise. Check for `po-find-file-coding-system'; on Emacs < 21.2.50 and XEmacs load po-compat.el. *** gettext/misc/po-mode.el Sat Mar 16 15:28:09 2002 --- gettext/misc/po-mode.el Sun Mar 17 12:15:03 2002 *************** *** 38,46 **** ;; (setq auto-mode-alist (cons '("\\.po\\'\\|\\.po\\." . po-mode) ;; auto-mode-alist)) ;; ! ;; To use the right coding system automatically under Emacs 20, also add: ;; ! ;; (autoload 'po-find-file-coding-system "po-mode") ;; (modify-coding-system-alist 'file "\\.po\\'\\|\\.po\\." ;; 'po-find-file-coding-system) ;; --- 38,47 ---- ;; (setq auto-mode-alist (cons '("\\.po\\'\\|\\.po\\." . po-mode) ;; auto-mode-alist)) ;; ! ;; To use the right coding system automatically under Emacs 20.x, 21.1, ! ;; and 21.2, also add: ;; ! ;; (autoload 'po-find-file-coding-system "po-compat") ;; (modify-coding-system-alist 'file "\\.po\\'\\|\\.po\\." ;; 'po-find-file-coding-system) ;; *************** *** 49,55 **** ;;; Code: ! (defconst po-mode-version-string "1.91" "\ Version number of this version of po-mode.el.") ;;; Emacs portability matters - part I. --- 50,56 ---- ;;; Code: ! (defconst po-mode-version-string "2.00" "\ Version number of this version of po-mode.el.") ;;; Emacs portability matters - part I. *************** *** 774,860 **** (_"Type 'C-c C-c' once done, or 'C-c C-k' to abort edit") "Message to post in the minibuffer when an edit buffer is displayed.") - ; Make the cpnnn codesets available. - (if po-EMACS20 - (mapc #'codepage-setup (mapcar #'car (cp-supported-codepages)))) - - (defconst po-content-type-charset-alist - '(; Note: Emacs 21 doesn't support all encodings, thus the missing entries. - (ASCII . undecided) - (ANSI_X3.4-1968 . undecided) - (US-ASCII . undecided) - (ISO-8859-1 . iso-8859-1) - (ISO_8859-1 . iso-8859-1) - (ISO-8859-2 . iso-8859-2) - (ISO_8859-2 . iso-8859-2) - (ISO-8859-3 . iso-8859-3) - (ISO_8859-3 . iso-8859-3) - (ISO-8859-4 . iso-8859-4) - (ISO_8859-4 . iso-8859-4) - (ISO-8859-5 . iso-8859-5) - (ISO_8859-5 . iso-8859-5) - ;(ISO-8859-6 . ??) - ;(ISO_8859-6 . ??) - (ISO-8859-7 . iso-8859-7) - (ISO_8859-7 . iso-8859-7) - (ISO-8859-8 . iso-8859-8) - (ISO_8859-8 . iso-8859-8) - (ISO-8859-9 . iso-8859-9) - (ISO_8859-9 . iso-8859-9) - ;(ISO-8859-13 . ??) - ;(ISO_8859-13 . ??) - (ISO-8859-15 . iso-8859-15) ; requires Emacs 21 - (ISO_8859-15 . iso-8859-15) ; requires Emacs 21 - (KOI8-R . koi8-r) - ;(KOI8-U . ??) - (CP437 . cp437) ; requires Emacs 20 - (CP775 . cp775) ; requires Emacs 20 - (CP850 . cp850) ; requires Emacs 20 - (CP852 . cp852) ; requires Emacs 20 - (CP855 . cp855) ; requires Emacs 20 - ;(CP856 . ??) - (CP857 . cp857) ; requires Emacs 20 - (CP861 . cp861) ; requires Emacs 20 - (CP862 . cp862) ; requires Emacs 20 - (CP864 . cp864) ; requires Emacs 20 - (CP865 . cp865) ; requires Emacs 20 - (CP866 . cp866) ; requires Emacs 21 - (CP869 . cp869) ; requires Emacs 20 - ;(CP874 . ??) - ;(CP922 . ??) - ;(CP932 . ??) - ;(CP943 . ??) - ;(CP949 . ??) - ;(CP950 . ??) - ;(CP1046 . ??) - ;(CP1124 . ??) - ;(CP1129 . ??) - (CP1250 . cp1250) ; requires Emacs 20 - (CP1251 . cp1251) ; requires Emacs 20 - (CP1252 . iso-8859-1) ; approximation - (CP1253 . cp1253) ; requires Emacs 20 - (CP1254 . iso-8859-9) ; approximation - (CP1255 . iso-8859-8) ; approximation - ;(CP1256 . ??) - (CP1257 . cp1257) ; requires Emacs 20 - (GB2312 . cn-gb-2312) ; also named 'gb2312' in XEmacs 21 or Emacs 21 - ; also named 'euc-cn' in Emacs 20 or Emacs 21 - (EUC-JP . euc-jp) - (EUC-KR . euc-kr) - ;(EUC-TW . ??) - (BIG5 . big5) - ;(BIG5-HKSCS . ??) - ;(GBK . ??) - ;(GB18030 . ??) - (SHIFT_JIS . shift_jis) - ;(JOHAB . ??) - (TIS-620 . tis-620) ; requires Emacs 20 or Emacs 21 - (VISCII . viscii) ; requires Emacs 20 or Emacs 21 - (UTF-8 . utf-8) ; requires Mule-UCS in Emacs 20, or Emacs 21 - ) - "How to convert a GNU libc/libiconv canonical charset name as seen in - Content-Type into a Mule coding system.") - (defvar po-auxiliary-list nil "List of auxiliary PO files, in completing read format.") --- 775,780 ---- *************** *** 931,1001 **** ;;; Mode activation. ! (defun po-find-charset (filename) ! "Return PO file charset value." ! (interactive) ! (let ((charset-regexp ! "^\"Content-Type: text/plain;[ \t]*charset=\\(.*\\)\\\\n\"") ! (short-read nil)) ! ;; Try the first 4096 bytes. In case we cannot find the charset value ! ;; within the first 4096 bytes (the PO file might start with a long ! ;; comment) try the next 4096 bytes repeatedly until we'll know for sure ! ;; we've checked the empty header entry entirely. ! (while (not (or short-read (re-search-forward "^msgid" nil t))) ! (save-excursion ! (goto-char (point-max)) ! (let ((pair (insert-file-contents-literally filename nil ! (1- (point)) ! (1- (+ (point) 4096))))) ! (setq short-read (< (nth 1 pair) 4096))))) ! (cond (short-read nil) ! ((re-search-forward charset-regexp nil t) (match-string 1)) ! ;; We've found the first msgid; maybe, only a part of the msgstr ! ;; value was loaded. Load the next 1024 bytes; if charset still ! ;; isn't available, give up. ! (t (save-excursion ! (goto-char (point-max)) ! (insert-file-contents-literally filename nil ! (1- (point)) ! (1- (+ (point) 1024)))) ! (if (re-search-forward charset-regexp nil t) ! (match-string 1)))))) ! ! (eval-and-compile ! (if (or po-EMACS20 po-XEMACS) ! (defun po-find-file-coding-system-guts (operation filename) ! "\ ! Return a Mule (DECODING . ENCODING) pair, according to PO file charset. ! Called through file-coding-system-alist, before the file is visited for real." ! (and (eq operation 'insert-file-contents) ! (file-exists-p filename) ! (po-with-temp-buffer ! (let ((coding-system-for-read 'no-conversion)) ! (let* ((charset (or (po-find-charset filename) ! "ascii")) ! (charset-upper (intern (upcase charset))) ! (charset-lower (intern (downcase charset)))) ! (list (or (cdr (assq charset-upper ! po-content-type-charset-alist)) ! (if (memq charset-lower (coding-system-list)) ! charset-lower ! 'no-conversion))))))))) ! ! (if po-EMACS20 ! (defun po-find-file-coding-system (arg-list) ! "\ ! Return a Mule (DECODING . ENCODING) pair, according to PO file charset. ! Called through file-coding-system-alist, before the file is visited for real." ! (po-find-file-coding-system-guts (car arg-list) (car (cdr arg-list))))) ! ! (if po-XEMACS ! (defun po-find-file-coding-system (operation filename) ! "\ ! Return a Mule (DECODING . ENCODING) pair, according to PO file charset. ! Called through file-coding-system-alist, before the file is visited for real." ! (po-find-file-coding-system-guts operation filename))) ! ! ) (defvar po-mode-abbrev-table nil "Abbrev table used while in PO mode.") --- 851,859 ---- ;;; Mode activation. ! ;; Emacs 21.2.50 comes with po-find-file-coding-system ! (if (not (fboundp 'po-find-file-coding-system)) ! (require 'po-compat)) (defvar po-mode-abbrev-table nil "Abbrev table used while in PO mode.") *** /dev/null Mon Sep 24 03:54:15 2001 --- gettext/misc/po-compat.el Sun Mar 17 12:10:54 2002 *************** *** 0 **** --- 1,178 ---- + (eval-and-compile + (cond ((string-match "XEmacs\\|Lucid" emacs-version) + (setq po-EMACS20 nil po-XEMACS t)) + ((and (string-lessp "19" emacs-version) (featurep 'faces)) + (setq po-EMACS20 t po-XEMACS nil)) + (t (setq po-EMACS20 nil po-XEMACS nil)))) + + ;; Handle missing 'with-temp-buffer' function. + (eval-and-compile + (if (fboundp 'with-temp-buffer) + (fset 'po-with-temp-buffer (symbol-function 'with-temp-buffer)) + + (defmacro po-with-temp-buffer (&rest forms) + "Create a temporary buffer, and evaluate FORMS there like 'progn'." + (let ((curr-buffer (make-symbol "curr-buffer")) + (temp-buffer (make-symbol "temp-buffer"))) + `(let ((,curr-buffer (current-buffer)) + (,temp-buffer (get-buffer-create + (generate-new-buffer-name " *po-temp*")))) + (unwind-protect + (progn + (set-buffer ,temp-buffer) + ,@forms) + (set-buffer ,curr-buffer) + (and (buffer-name ,temp-buffer) + (kill-buffer ,temp-buffer)))))))) + + ; Make the cpnnn codesets available. + (if po-EMACS20 + (mapc #'codepage-setup (mapcar #'car (cp-supported-codepages)))) + + (defconst po-content-type-charset-alist + '(; Note: Emacs 21 doesn't support all encodings, thus the missing entries. + (ASCII . undecided) + (ANSI_X3.4-1968 . undecided) + (US-ASCII . undecided) + (ISO-8859-1 . iso-8859-1) + (ISO_8859-1 . iso-8859-1) + (ISO-8859-2 . iso-8859-2) + (ISO_8859-2 . iso-8859-2) + (ISO-8859-3 . iso-8859-3) + (ISO_8859-3 . iso-8859-3) + (ISO-8859-4 . iso-8859-4) + (ISO_8859-4 . iso-8859-4) + (ISO-8859-5 . iso-8859-5) + (ISO_8859-5 . iso-8859-5) + ;(ISO-8859-6 . ??) + ;(ISO_8859-6 . ??) + (ISO-8859-7 . iso-8859-7) + (ISO_8859-7 . iso-8859-7) + (ISO-8859-8 . iso-8859-8) + (ISO_8859-8 . iso-8859-8) + (ISO-8859-9 . iso-8859-9) + (ISO_8859-9 . iso-8859-9) + ;(ISO-8859-13 . ??) + ;(ISO_8859-13 . ??) + (ISO-8859-15 . iso-8859-15) ; requires Emacs 21 + (ISO_8859-15 . iso-8859-15) ; requires Emacs 21 + (KOI8-R . koi8-r) + ;(KOI8-U . ??) + (CP437 . cp437) ; requires Emacs 20 + (CP775 . cp775) ; requires Emacs 20 + (CP850 . cp850) ; requires Emacs 20 + (CP852 . cp852) ; requires Emacs 20 + (CP855 . cp855) ; requires Emacs 20 + ;(CP856 . ??) + (CP857 . cp857) ; requires Emacs 20 + (CP861 . cp861) ; requires Emacs 20 + (CP862 . cp862) ; requires Emacs 20 + (CP864 . cp864) ; requires Emacs 20 + (CP865 . cp865) ; requires Emacs 20 + (CP866 . cp866) ; requires Emacs 21 + (CP869 . cp869) ; requires Emacs 20 + ;(CP874 . ??) + ;(CP922 . ??) + ;(CP932 . ??) + ;(CP943 . ??) + ;(CP949 . ??) + ;(CP950 . ??) + ;(CP1046 . ??) + ;(CP1124 . ??) + ;(CP1129 . ??) + (CP1250 . cp1250) ; requires Emacs 20 + (CP1251 . cp1251) ; requires Emacs 20 + (CP1252 . iso-8859-1) ; approximation + (CP1253 . cp1253) ; requires Emacs 20 + (CP1254 . iso-8859-9) ; approximation + (CP1255 . iso-8859-8) ; approximation + ;(CP1256 . ??) + (CP1257 . cp1257) ; requires Emacs 20 + (GB2312 . cn-gb-2312) ; also named 'gb2312' in XEmacs 21 or Emacs 21 + ; also named 'euc-cn' in Emacs 20 or Emacs 21 + (EUC-JP . euc-jp) + (EUC-KR . euc-kr) + ;(EUC-TW . ??) + (BIG5 . big5) + ;(BIG5-HKSCS . ??) + ;(GBK . ??) + ;(GB18030 . ??) + (SHIFT_JIS . shift_jis) + ;(JOHAB . ??) + (TIS-620 . tis-620) ; requires Emacs 20 or Emacs 21 + (VISCII . viscii) ; requires Emacs 20 or Emacs 21 + (UTF-8 . utf-8) ; requires Mule-UCS in Emacs 20, or Emacs 21 + ) + "How to convert a GNU libc/libiconv canonical charset name as seen in + Content-Type into a Mule coding system.") + + (defun po-find-charset (filename) + "Return PO file charset value." + (interactive) + (let ((charset-regexp + "^\"Content-Type: text/plain;[ \t]*charset=\\(.*\\)\\\\n\"") + (short-read nil)) + ;; Try the first 4096 bytes. In case we cannot find the charset value + ;; within the first 4096 bytes (the PO file might start with a long + ;; comment) try the next 4096 bytes repeatedly until we'll know for sure + ;; we've checked the empty header entry entirely. + (while (not (or short-read (re-search-forward "^msgid" nil t))) + (save-excursion + (goto-char (point-max)) + (let ((pair (insert-file-contents-literally filename nil + (1- (point)) + (1- (+ (point) 4096))))) + (setq short-read (< (nth 1 pair) 4096))))) + (cond (short-read nil) + ((re-search-forward charset-regexp nil t) (match-string 1)) + ;; We've found the first msgid; maybe, only a part of the msgstr + ;; value was loaded. Load the next 1024 bytes; if charset still + ;; isn't available, give up. + (t (save-excursion + (goto-char (point-max)) + (insert-file-contents-literally filename nil + (1- (point)) + (1- (+ (point) 1024)))) + (if (re-search-forward charset-regexp nil t) + (match-string 1)))))) + + + (eval-and-compile + (if (or po-EMACS20 po-XEMACS) + (defun po-find-file-coding-system-guts (operation filename) + "\ + Return a Mule (DECODING . ENCODING) pair, according to PO file charset. + Called through file-coding-system-alist, before the file is visited for real." + (and (eq operation 'insert-file-contents) + (file-exists-p filename) + (po-with-temp-buffer + (let ((coding-system-for-read 'no-conversion)) + (let* ((charset (or (po-find-charset filename) + "ascii")) + (charset-upper (intern (upcase charset))) + (charset-lower (intern (downcase charset)))) + (list (or (cdr (assq charset-upper + po-content-type-charset-alist)) + (if (memq charset-lower (coding-system-list)) + charset-lower + 'no-conversion))))))))) + + (if po-EMACS20 + (defun po-find-file-coding-system (arg-list) + "\ + Return a Mule (DECODING . ENCODING) pair, according to PO file charset. + Called through file-coding-system-alist, before the file is visited for real." + (po-find-file-coding-system-guts (car arg-list) (car (cdr arg-list))))) + + (if po-XEMACS + (defun po-find-file-coding-system (operation filename) + "\ + Return a Mule (DECODING . ENCODING) pair, according to PO file charset. + Called through file-coding-system-alist, before the file is visited for real." + (po-find-file-coding-system-guts operation filename))) + + ) + + (provide 'po-compat) + + ;; end of file po-compat.el -- ke@suse.de (work) / keichwa@gmx.net (home): | http://www.suse.de/~ke/ | ,__o Free Translation Project: | _-\_<, http://www.iro.umontreal.ca/contrib/po/HTML/ | (*)/'(*) _______________________________________________ Emacs-devel mailing list Emacs-devel@gnu.org http://mail.gnu.org/mailman/listinfo/emacs-devel