emacs-devel
[Top][All Lists]
Advanced

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

Patch for GNU gettext (Re: PO files and Emacs)


From: Karl Eichwalder
Subject: Patch for GNU gettext (Re: PO files and Emacs)
Date: Sun, 17 Mar 2002 12:40:58 +0100
User-agent: Gnus/5.090006 (Oort Gnus v0.06) Emacs/21.2.50 (i686-pc-linux-gnu)

Karl Eichwalder <address@hidden> 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  <address@hidden>

        * 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



-- 
address@hidden (work) / address@hidden (home):              |
http://www.suse.de/~ke/                                  |      ,__o
Free Translation Project:                                |    _-\_<,
http://www.iro.umontreal.ca/contrib/po/HTML/             |   (*)/'(*)



reply via email to

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