From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Kenichi Handa Newsgroups: gmane.emacs.devel Subject: Re: po file charset via auto-coding-functions Date: Thu, 29 Dec 2005 20:47:38 +0900 Message-ID: References: <87zmp399ue.fsf@zip.com.au> <87ll0ma3ow.fsf@zip.com.au> <87fyqu9ung.fsf@zip.com.au> <877jbhrwox.fsf-monnier+emacs@gnu.org> <87psp8qrz9.fsf-monnier+emacs@gnu.org> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 (generated by SEMI 1.14.3 - "Ushinoya") Content-Type: text/plain; charset=US-ASCII X-Trace: sea.gmane.org 1135860611 11746 80.91.229.2 (29 Dec 2005 12:50:11 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 29 Dec 2005 12:50:11 +0000 (UTC) Cc: user42@zip.com.au, monnier@iro.umontreal.ca, emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Dec 29 13:50:07 2005 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1ErxEJ-0007HW-C1 for ged-emacs-devel@m.gmane.org; Thu, 29 Dec 2005 13:50:03 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1ErxFf-000843-9c for ged-emacs-devel@m.gmane.org; Thu, 29 Dec 2005 07:51:27 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1ErwJv-00083V-Fb for emacs-devel@gnu.org; Thu, 29 Dec 2005 06:51:48 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1ErwJV-0007vD-HG for emacs-devel@gnu.org; Thu, 29 Dec 2005 06:51:24 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1ErwHR-0007WF-8T for emacs-devel@gnu.org; Thu, 29 Dec 2005 06:49:13 -0500 Original-Received: from [192.47.44.130] (helo=tsukuba.m17n.org) by monty-python.gnu.org with esmtp (TLS-1.0:DHE_RSA_3DES_EDE_CBC_SHA:24) (Exim 4.34) id 1ErwHk-0006qP-E3; Thu, 29 Dec 2005 06:49:33 -0500 Original-Received: from nfs.m17n.org (nfs.m17n.org [192.47.44.7]) by tsukuba.m17n.org (8.13.4/8.13.4/Debian-3) with ESMTP id jBTBlfw7007961; Thu, 29 Dec 2005 20:47:41 +0900 Original-Received: from etlken (etlken.m17n.org [192.47.44.125]) by nfs.m17n.org (8.13.4/8.13.4/Debian-3) with ESMTP id jBTBlefe021477; Thu, 29 Dec 2005 20:47:40 +0900 Original-Received: from handa by etlken with local (Exim 3.36 #1 (Debian)) id 1ErwFu-00042M-00; Thu, 29 Dec 2005 20:47:38 +0900 Original-To: rms@gnu.org In-reply-to: (rms@gnu.org) User-Agent: SEMI/1.14.3 (Ushinoya) FLIM/1.14.2 (Yagi-Nishiguchi) APEL/10.2 Emacs/22.0.50 (i686-pc-linux-gnu) MULE/5.0 (SAKAKI) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:48485 Archived-At: In article , "Richard M. Stallman" writes: > Please forgive the delay in my response. >> Binding buffer-file-name is rather unclean. >> And I don't see a reason to do it. >> so that find-operation-coding-system (called in >> decode-coding-inserted-region) can surely find >> po-find-file-coding-system to be called, and it can surely >> find the current buffer by get-file-buffer. >> decode-coding-inserted-region passes its FILENAME arg to >> find-operation-coding-system. So all you need to do is to pass >> this funny file name to decode-coding-inserted-region. >> There is no need to bind buffer-file-name. >> Why are you concerned about whether get-file-buffer can be used with >> this funny file name? > A function registered in find-operation-coding-system have > to find which buffer is pretending to visit FILENAME if > FILENAME doesn't exist. And, get-file-buffer is the only > (or at least the very natural) way for that. > Could you give me an example or two? > Which filename handler function does this? > Looking at an example, I can understand the issue. The attached in the patch for po.el I posted. This change utilizes get-file-buffer to check if there is a buffer visiting (or pretending to visit) FILENAME. --- Kenichi Handa handa@m17n.org *** po.el 08 Aug 2005 10:13:42 +0900 1.12 --- po.el 18 Nov 2005 21:08:50 +0900 *************** *** 44,55 **** "Return PO charset value for FILENAME." (let ((charset-regexp "^\"Content-Type:[ \t]*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 --- 44,59 ---- "Return PO charset value for FILENAME." (let ((charset-regexp "^\"Content-Type:[ \t]*text/plain;[ \t]*charset=\\(.*\\)\\\\n\"") + (buf (get-file-buffer filename)) (short-read nil)) + (when buf + (set-buffer buf) + (goto-char (point-min))) ;; 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) buf)) (save-excursion (goto-char (point-max)) (let ((pair (insert-file-contents-literally filename nil *************** *** 57,63 **** (1- (+ (point) 4096))))) (setq short-read (< (nth 1 pair) 4096))))) (cond ((re-search-forward charset-regexp nil t) (match-string 1)) ! (short-read nil) ;; 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. --- 61,67 ---- (1- (+ (point) 4096))))) (setq short-read (< (nth 1 pair) 4096))))) (cond ((re-search-forward charset-regexp nil t) (match-string 1)) ! ((or short-read buf) nil) ;; 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. *************** *** 74,80 **** Do so according to FILENAME's declared charset." (and (eq operation 'insert-file-contents) ! (file-exists-p filename) (with-temp-buffer (let* ((coding-system-for-read 'no-conversion) (charset (or (po-find-charset filename) "ascii")) --- 78,84 ---- Do so according to FILENAME's declared charset." (and (eq operation 'insert-file-contents) ! (or (get-file-buffer filename) (file-exists-p filename)) (with-temp-buffer (let* ((coding-system-for-read 'no-conversion) (charset (or (po-find-charset filename) "ascii"))