From: Kenichi Handa <handa@m17n.org>
Cc: user42@zip.com.au, emacs-devel@gnu.org
Subject: Re: po file charset via auto-coding-functions
Date: Mon, 24 Oct 2005 10:39:16 +0900 [thread overview]
Message-ID: <E1ETrIy-0007uT-00@etlken> (raw)
In-Reply-To: <87k6g6e05k.fsf-monnier+emacs@gnu.org> (message from Stefan Monnier on Fri, 21 Oct 2005 22:50:12 -0400)
In article <87k6g6e05k.fsf-monnier+emacs@gnu.org>, Stefan Monnier <monnier@iro.umontreal.ca> writes:
>> environment. Hmmm, it seems that you are right. There's no
>> way to handle a tared/archived file in a function registered
>> in file-coding-system-alist.
> Provide a file-name-handler for tar files and archives would work
> around that problem.
Maybe, but I'm not sure. My gut feeling tells that it's not
easy to setup various handlers for an archive member already
setup in a (narrowed) buffer. We don't know what kind of
file operation a function in file-coding-system-alist
performs.
By the way, while considering the possibility of using
file-name-handler, I got this idea.
The correct operation in a handler for insert-file-contents
will be to find a buffer pretending to visit the file, and
insert that buffer contents. And, for that, we have to give
buffer-file-name (e.g. /home/handa/x.tgz!vi.po") not the
filename itself (e.g. vi.po) to
find-operation-coding-system. I think such a change is safe
because, at least, all current entries in
file-coding-system-alist checks only the tail of a filename.
But, if we have such a change, with a fairly simple change
to po.el, we can fix the current problem. So, I now propose
the attached change.
---
Kenichi Handa
handa@m17n.org
2005-10-24 Kenichi Handa <handa@m17n.org>
* arc-mode.el (archive-set-buffer-as-visiting-file): Give
buffer-file-name to find-operation-coding-system.
* tar-mode.el (tar-extract): Give buffer-file-name to
find-operation-coding-system.
* textmodes/po.el (po-find-charset): If there exists a buffer
visiting filename, check the contents of that buffer.
(po-find-file-coding-system-guts): Check if there exists a buffer
visiting filename.
Index: arc-mode.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/arc-mode.el,v
retrieving revision 1.68
diff -c -r1.68 arc-mode.el
*** arc-mode.el 16 Oct 2005 17:05:23 -0000 1.68
--- arc-mode.el 24 Oct 2005 01:33:13 -0000
***************
*** 877,883 ****
(let ((file-name-handler-alist
'(("" . archive-file-name-handler))))
(car (find-operation-coding-system 'insert-file-contents
! filename t))))))
(if (and (not coding-system-for-read)
(not enable-multibyte-characters))
(setq coding
--- 877,883 ----
(let ((file-name-handler-alist
'(("" . archive-file-name-handler))))
(car (find-operation-coding-system 'insert-file-contents
! buffer-file-name t))))))
(if (and (not coding-system-for-read)
(not enable-multibyte-characters))
(setq coding
Index: tar-mode.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/tar-mode.el,v
retrieving revision 1.103
diff -c -r1.103 tar-mode.el
*** tar-mode.el 22 Oct 2005 01:24:38 -0000 1.103
--- tar-mode.el 24 Oct 2005 01:33:14 -0000
***************
*** 737,743 ****
(funcall set-auto-coding-function
name (- (point-max) (point)))))
(car (find-operation-coding-system
! 'insert-file-contents name t))))
(multibyte enable-multibyte-characters)
(detected (detect-coding-region
(point-min)
--- 737,743 ----
(funcall set-auto-coding-function
name (- (point-max) (point)))))
(car (find-operation-coding-system
! 'insert-file-contents buffer-file-name t))))
(multibyte enable-multibyte-characters)
(detected (detect-coding-region
(point-min)
Index: textmodes/po.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/textmodes/po.el,v
retrieving revision 1.12
diff -c -r1.12 po.el
*** textmodes/po.el 6 Aug 2005 17:41:15 -0000 1.12
--- textmodes/po.el 24 Oct 2005 01:33:14 -0000
***************
*** 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"))
next prev parent reply other threads:[~2005-10-24 1:39 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-10-20 21:06 po file charset via auto-coding-functions Kevin Ryde
2005-10-21 2:18 ` Kenichi Handa
2005-10-21 22:46 ` Kevin Ryde
2005-10-22 1:43 ` Kenichi Handa
2005-10-22 2:01 ` Kevin Ryde
2005-10-22 2:39 ` Kenichi Handa
2005-10-22 2:50 ` Stefan Monnier
2005-10-22 22:44 ` Kevin Ryde
2005-10-24 1:39 ` Kenichi Handa [this message]
2005-10-22 15:51 ` Richard M. Stallman
2005-10-24 2:05 ` Kenichi Handa
2005-10-25 15:59 ` Richard M. Stallman
2005-11-02 10:27 ` Richard Stallman
2005-11-10 2:09 ` Richard Stallman
2005-11-10 3:49 ` Stefan Monnier
2005-11-10 17:49 ` Richard M. Stallman
2005-11-10 18:33 ` Stefan Monnier
2005-11-11 7:42 ` Richard M. Stallman
2005-11-18 13:08 ` Kenichi Handa
2005-11-18 17:21 ` Stefan Monnier
2005-11-19 0:30 ` Kenichi Handa
2005-11-20 1:16 ` Juri Linkov
2005-11-29 19:13 ` Kevin Rodgers
2005-11-30 2:45 ` Juri Linkov
2005-11-30 19:01 ` Richard M. Stallman
2005-11-19 23:27 ` Richard M. Stallman
2005-11-20 12:05 ` Kenichi Handa
2005-12-28 17:01 ` Richard M. Stallman
2005-12-29 11:47 ` Kenichi Handa
2005-12-30 2:18 ` Richard M. Stallman
2006-01-04 4:37 ` Kenichi Handa
2005-10-22 22:51 ` Kevin Ryde
2005-10-24 1:53 ` Kenichi Handa
2005-10-24 2:04 ` Kevin Ryde
2005-10-24 5:19 ` Kenichi Handa
2005-10-24 14:11 ` Stefan Monnier
2005-10-25 1:03 ` Kenichi Handa
2005-10-24 23:35 ` Juri Linkov
2005-10-25 6:42 ` Kenichi Handa
2005-10-25 20:27 ` Richard M. Stallman
2005-10-21 4:49 ` Richard M. Stallman
2005-10-21 21:07 ` Kevin Ryde
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=E1ETrIy-0007uT-00@etlken \
--to=handa@m17n.org \
--cc=emacs-devel@gnu.org \
--cc=user42@zip.com.au \
/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 public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).