Ticket #322 (closed 不具合: fixed)

Opened 2 years ago

Last modified 1 year ago

tar-mode で coding-system が常に sjis になる

Reported by: anonymous Assigned to:
Priority: major Milestone: ver 3.00
Component: Emacs Lisp Version: 3.00 (開発中)
Keywords: Cc:

Description

tar-mode でサブファイルを開くとサブファイルの内容によらず buffer-file-coding-system が japanese-shift-jis-* になる。

ただし、なぜか *.tex だと buffer-file-coding-system が正しく設定される。

Attachments

ticket-322.tar.gz (244 bytes) - added by gotoh on 07/31/06 21:58:17.
症状再現の為の tar ファイル (sjis/euc/jis)

Change History

07/31/06 01:53:47 changed by anonymous2

tar-mode.elのtar-extractの (if coding を (if (and coding (null (string-match "undecided" (symbol-name coding)))) くらいにすればいいと思う。 texで設定できているのは、ファイル中に文字セットが明示されているのでは?

07/31/06 21:53:25 changed by gotoh

未対処だけど、一応メモとして。 anonymous2さんの修正は正しいと思います。 ちょっと書き直して以下のように。

Index: tar-mode.el
===================================================================
--- tar-mode.el	(revision 4132)
+++ tar-mode.el	(working copy)
@@ -742,7 +742,8 @@
 			(detected (detect-coding-region
 				   (point-min)
 				   (min (+ (point-min) 16384) (point-max)) t)))
-		    (if coding
+		    (if (and coding
+			     (not (eq (coding-system-base coding) 'undecided)))
 			(or (numberp (coding-system-eol-type coding))
 			    (vectorp (coding-system-eol-type detected))
 			    (setq coding (coding-system-change-eol-conversion

ただ、この codingなのですが、修正部分の少し前で find-operation-coding-system<f>undecided を 返すことが正しくないような気がしてるけど未調査。 くわえて#184の問題とも関連があったりしないかな、という気も少々。

07/31/06 21:58:17 changed by gotoh

  • attachment ticket-322.tar.gz added.

症状再現の為の tar ファイル (sjis/euc/jis)

08/01/06 00:04:04 changed by anonymous

シンプルにこうしちゃった方が良いと思うな。

  • tar-mode.el

    old new  
    727727                  (setq buffer-file-name new-buffer-file-name) 
    728728                  (setq buffer-file-truename 
    729729                        (abbreviate-file-name buffer-file-name)) 
    730                   ;; We need to mimic the parts of insert-file-contents 
    731                   ;; which determine the coding-system and decode the text. 
    732                   (let ((coding 
    733                          (or coding-system-for-read 
    734                              (and set-auto-coding-function 
    735                                   (save-excursion 
    736                                     (funcall set-auto-coding-function 
    737                                              name (- (point-max) (point))))) 
    738                              (car (find-operation-coding-system 
    739                                    'insert-file-contents 
    740                                    (cons name (current-buffer)) t)))) 
    741                         (multibyte enable-multibyte-characters) 
    742                         (detected (detect-coding-region 
    743                                    (point-min) 
    744                                    (min (+ (point-min) 16384) (point-max)) t))) 
    745                     (if coding 
    746                         (or (numberp (coding-system-eol-type coding)) 
    747                             (vectorp (coding-system-eol-type detected)) 
    748                             (setq coding (coding-system-change-eol-conversion 
    749                                           coding 
    750                                           (coding-system-eol-type detected)))) 
    751                       (setq coding 
    752                             (find-new-buffer-file-coding-system detected))) 
    753                     (if (or (eq coding 'no-conversion) 
    754                             (eq (coding-system-type coding) 5)) 
    755                         (setq multibyte (set-buffer-multibyte nil))) 
    756                     (or multibyte 
    757                         (setq coding 
    758                               (coding-system-change-text-conversion 
    759                                coding 'raw-text))) 
    760                     (decode-coding-region (point-min) (point-max) coding) 
    761                     (set-buffer-file-coding-system coding)) 
     730                  (decode-coding-inserted-region 
     731                   (point-min) (point-max) buffer-file-name t) 
     732                  (after-insert-file-set-coding (buffer-size) t) 
    762733                  ;; Set the default-directory to the dir of the 
    763734                  ;; superior buffer. 
    764735                  (setq default-directory 

(follow-up: ↓ 5 ) 08/01/06 03:13:08 changed by anonymous2

どうせ直すなら、上記のさらに15行ほど後方も、 (set-buffer-multibyte tar-buffer-multibyte) (narrow-to-region (point-min) (byte-to-position tar-header-offset)) にしちゃった方がいいかもしれません。

(in reply to: ↑ 4 ) 08/01/06 10:39:18 changed by gotoh

Replying to anonymous2:
comment:3 に加えて以下の修正を、ということですね。 どちらの修正も適切に思えます。

  • tar-mode.el

    old new  
    775746                  (set-buffer-modified-p nil)) 
    776747                (tar-subfile-mode 1)) 
    777748              (set-buffer tar-buffer)) 
    778           (narrow-to-region (point-min) tar-header-offset
    779           (set-buffer-multibyte tar-buffer-multibyte))) 
     749          (set-buffer-multibyte tar-buffer-multibyte
     750          (narrow-to-region (point-min) (byte-to-position tar-header-offset)))) 
    780751      (if view-p 
    781752          (view-buffer buffer (and just-created 'kill-buffer)) 
    782753        (if (eq other-window-p 'display) 

comment:3decode-coding-inserted-region<f>の内容も確認してみましたが、 修正前コードを内包していることは確認しました。よさげ。 comment:4 の内容もtar-mode.elのほかの部分と同様のコードなわけですからよさそ。

(follow-up: ↓ 7 ) 08/01/06 20:26:20 changed by anonymous

narrow-to-region と set-buffer-multibyte を入れ替える意図はよくわからないな。

tar-subfile-save-buffer で coding-system-for-write が無視されることと セーブ後に undo できなくなってしまうことに対するパッチも示しておきます。

  • tar-mode.el

    old new  
    11181118  (save-excursion 
    11191119  (let ((subfile (current-buffer)) 
    11201120        (subfile-multibyte enable-multibyte-characters) 
    1121         (coding buffer-file-coding-system) 
     1121        (coding (funcall select-safe-coding-system-function 
     1122                         (point-min) (point-max) 
     1123                         (if coding-system-for-write 
     1124                             (list t coding-system-for-write) 
     1125                           buffer-file-coding-system) 
     1126                         nil buffer-file-name)) 
    11221127        (descriptor tar-superior-descriptor) 
     1128        (buffer-undo-list-bak buffer-undo-list) 
    11231129        subfile-size) 
    11241130    ;; We must make the current buffer unibyte temporarily to avoid 
    11251131    ;; multibyte->unibyte conversion in `insert-buffer-substring'. 
     
    12181224    (set-buffer-modified-p nil) ; mark the tar subfile as unmodified 
    12191225    (message "Saved into tar-buffer `%s'.  Be sure to save that buffer!" 
    12201226             (buffer-name tar-superior-buffer)) 
    1221     ;; Prevent basic-save-buffer from changing our coding-system. 
    1222     (setq last-coding-system-used buffer-file-coding-system) 
     1227    (setq buffer-undo-list buffer-undo-list-bak) 
    12231228    ;; Prevent ordinary saving from happening. 
    12241229    t))) 
    12251230 

(in reply to: ↑ 6 ; follow-up: ↓ 8 ) 08/01/06 23:28:00 changed by gotoh

Replying to anonymous:

narrow-to-region と set-buffer-multibyte を入れ替える意図はよくわからないな。

comment:4 の指摘に従ったというだけで順序そのものに意図は無いです。 byte-to-positionを塚照る限りどちらでもよいかとは思う。 tar-mode.el内にはどっちのケースもありますね。

tar-subfile-save-buffer で coding-system-for-write が無視されることと セーブ後に undo できなくなってしまうことに対するパッチも示しておきます。

すいませんが、これらは別件ですよね。 であれば、別のチケットを作ってくれませんか。 というか、そこまではっきりとしたパッチがあるならば、bug-gnu-emacs@gnu.org に 出していただけたほうが助かります。meadow独自に上記修正をするかどうかは現状不明ですし、 本家が直ってくれるのがsync作業の面でも助かるので、是非。

p.s.
anonymousと対話するのはなんか疲れる...

(in reply to: ↑ 7 ) 08/02/06 01:40:40 changed by anonymous2

Replying to gotoh:

comment:4 の指摘に従ったというだけで順序そのものに意図は無いです。

この順序でないとだめです。ファイル名にMBCを使った場合のバグの修正ですので、実は別件です。

anonymousと対話するのはなんか疲れる...

ごめんちゃい

07/07/07 11:41:57 changed by gotoh

  • status changed from new to closed.
  • resolution set to fixed.
  • milestone set to ver 3.00.

この件は r4213 では直っているのを確認しました。よってクローズ ただ、添付のサンプルファイルはEUC-JPのテキストだけは化けてしまいましたが、 これはtar外の通常ファイルでもcoding検出できていないので、別のも問題です。


Add/Change #322 (tar-mode で coding-system が常に sjis になる)




Change Properties
Action