emacs-devel
[Top][All Lists]
Advanced

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

Re: po file charset via auto-coding-functions


From: Kenichi Handa
Subject: Re: po file charset via auto-coding-functions
Date: Thu, 29 Dec 2005 20:47:38 +0900
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)

In article <address@hidden>, "Richard M. Stallman" <address@hidden> 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
address@hidden

*** 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"))




reply via email to

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