all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Karl Eichwalder <ke@gnu.franken.de>
Cc: Eli Zaretskii <eliz@is.elta.co.il>, emacs-devel@gnu.org
Subject: Patch for GNU gettext (Re: PO files and Emacs)
Date: Sun, 17 Mar 2002 12:40:58 +0100	[thread overview]
Message-ID: <shhenffmlx.fsf_-_@tux.gnu.franken.de> (raw)
In-Reply-To: <shg02zvk7o.fsf@tux.gnu.franken.de> (Karl Eichwalder's message of "Sun, 17 Mar 2002 06:26:03 +0100")

Karl Eichwalder <ke@gnu.franken.de> 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  <ke@suse.de>

	* 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:
  \f
! (defconst po-mode-version-string "1.91" "\
  Version number of this version of po-mode.el.")
  
  ;;; Emacs portability matters - part I.
--- 50,56 ----
  
  ;;; Code:
  \f
! (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 ****
  \f
  ;;; 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 ----
  \f
  ;;; 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


  reply	other threads:[~2002-03-17 11:40 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-03-09 14:11 PO files and Emacs Karl Eichwalder
2002-03-10  5:03 ` Richard Stallman
2002-03-10  5:29   ` Karl Eichwalder
2002-03-11  9:00     ` Richard Stallman
2002-03-11 11:03       ` Eli Zaretskii
2002-03-11 17:54         ` Karl Eichwalder
2002-03-11 19:29           ` Andreas Schwab
2002-03-11 20:02       ` Karl Eichwalder
2002-03-12  5:53         ` Eli Zaretskii
2002-03-12 13:41           ` Bruno Haible
2002-03-12 15:53             ` Kim F. Storm
2002-03-12 16:25               ` Karl Eichwalder
2002-03-12 17:19               ` Bruno Haible
2002-03-12 17:20               ` Bruno Haible
2002-03-15 13:53                 ` Eli Zaretskii
2002-03-16  3:41                   ` Karl Eichwalder
2002-03-12 17:17             ` Eli Zaretskii
2002-03-15 13:54       ` Eli Zaretskii
2002-03-10 11:10   ` Neil Darlow
2002-03-11  5:46     ` Eli Zaretskii
2002-03-11  6:45       ` Karl Eichwalder
2002-03-11  6:53         ` Eli Zaretskii
2002-03-12 13:30 ` Bruno Haible
2002-03-15 13:29   ` Eli Zaretskii
2002-03-15 18:43     ` Bruno Haible
2002-03-16  4:36       ` Karl Eichwalder
2002-03-16  9:26         ` Eli Zaretskii
2002-03-16 13:05           ` Karl Eichwalder
2002-03-16 17:29             ` Eli Zaretskii
2002-03-16 18:41               ` Karl Eichwalder
2002-03-17  4:35                 ` Eli Zaretskii
2002-03-17  5:26                   ` Karl Eichwalder
2002-03-17 11:40                     ` Karl Eichwalder [this message]
2002-03-17 11:42                     ` Eli Zaretskii
2002-03-16 10:39       ` Alex Schroeder

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

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

  git send-email \
    --in-reply-to=shhenffmlx.fsf_-_@tux.gnu.franken.de \
    --to=ke@gnu.franken.de \
    --cc=eliz@is.elta.co.il \
    --cc=emacs-devel@gnu.org \
    --cc=keichwa@gmx.net \
    /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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.