Thread View: fj.editor.mule
5 messages
5 total messages
Started by KANEMATSU Shin'ya
Tue, 29 May 2001 00:41
html-helper-modeでのbuffer-file-coding-systemの設定
Author: KANEMATSU Shin'ya
Date: Tue, 29 May 2001 00:41
Date: Tue, 29 May 2001 00:41
48 lines
3426 bytes
3426 bytes
どなたか以下に関して教えていただけないでしょうか?
html-helper-modeでtags-query-replaceをする際に、漢字コードの判定に失
敗することがよくあるので、
(add-hook 'html-helper-mode-hook
'(lambda ()
(setq buffer-file-coding-system 'iso-2022-jp-unix)))
と設定していました。
最近、主にWindows環境でsjis-dosなファイルを編集する人のことも考えて、
でも、word文書をできれば作りたくないとも思い、sjis-dosなhtml文書を作っ
ています。(前記add-hookは、それとは別の文書のための設定で、
iso-2022-jp-unixである必要があります。)
前述のadd-hook指定があると、sjis-dosである旨ファイル中に指定されてい
るファイルもiso-2022-jp-unixで開かれてしまいます。そうならない方法を教
えていただけないでしょうか。(いまは、とりあえずremove-hookして対処して
います。)
ところで、html-helper-modeの場合、以下のコメントを認識するようです。
<!--
%%% Local Variables:
%%% mode: outline-minor
%%% End:
-->
よって、たとえば、そこに「%%% coding: sjis-dos」とあったらそちらを優
先するとか、
<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
とあったら、そちらを優先してくれるとありがたいです。(そいうのがみつから
ない場合は、iso-2022-jp-unixになってほしい。)
できれば、html-helper-modeやemacsの標準配布ファイルをいじるのではな
かく、.emacs等の外にあるファイルで指定できるのがうれしいです。
# Elisp20.3のinfoを見たのですが、Local Variables:で指定されたcoding
# の値の参照方法さえ見付けることができませんでした。多分、前提知識が
# 足りないのでしょう。今回は関係ないのですが、mode: outline-minorをど
# うすれば参照できるのかも見付けられませんし。
html-helper-modeのバージョンは以下です。
;; $Id: html-helper-mode.el,v 2.19.1.1 1998/08/06 18:53:03 nelson Exp $
また、
emacs-version = "20.4.1"
mule-version = "4.0 (HANANOEN)"
です。
---
兼松 真哉 (かねまつ しんや)
Re: html-helper-modeでのbuffer-file-coding-systemの設定
Author: Seiichi Namba
Date: Tue, 29 May 2001 02:37
Date: Tue, 29 May 2001 02:37
88 lines
4130 bytes
4130 bytes
難波です。
KANEMATSU Shin'ya <kane@lp.nm.fujitsu.co.jp> さん writes:
> ところで、html-helper-modeの場合、以下のコメントを認識するようです。
>
> <!--
> %%% Local Variables:
> %%% mode: outline-minor
> %%% End:
> -->
>
> よって、たとえば、そこに「%%% coding: sjis-dos」とあったらそちらを優
普通は
local variables の方が html-helper-mode-hook よりも後に eval されるよう
に思うんですが違いましたか。
書き方が違う、ということかな。今、
(add-hook 'html-helper-mode-hook
'(lambda ()
(setq buffer-file-coding-system 'iso-2022-jp-unix)
(message "THEHOOK:%s" buffer-file-coding-system)))
と html-helper-mode-hook を設定した上、
<!
Local Variables:
mode: html-helper
buffer-file-coding-system: sjis-dos
coding-system: junet
version-control: never
End:
>
と書いたファイルを find-file したところ、coding-system は sjis-dos
になりました。
> <meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
> とあったら、そちらを優先してくれるとありがたいです。(そいうのがみつから
> ない場合は、iso-2022-jp-unixになってほしい。)
これはやはり mode の方が面倒を見るべき事項のように思われます。
つまり、バッファの内容を parse する関数を用意して
html-helper-mode-hook などで呼ぶんでしょうかね。
行きあたりばったりですが
(defun junkfun ()
(interactive)
(let ((case-fold-search t))
(save-excursion
(goto-char (point-min))
(search-forward-regexp "charset *= *\\([a-zA-Z _]+\\)" nil t)
(message "%s"
(buffer-substring (match-beginning 1) (match-end 1))))))
というような感じで、上の行の "Shift_JIS" というストリングは取り出せました。
あとはテーブルを作って emacs の coding-system に変換して
buffer-file-coding-system に setq する…?。ここから先はお任せします。
出来た奴を html-helper-mode.el の作者に送るといいのかもしれません。
これは世界共通の問題だと思うので。
上のような関数は html-helper-mode-hook に登録しておくか、
eval: (junkfun)
などと local variables に書いておいても呼べます(あまりお勧めしたくな
るような方法ではありませんが)。
> できれば、html-helper-modeやemacsの標準配布ファイルをいじるのではな
> かく、.emacs等の外にあるファイルで指定できるのがうれしいです。
.emacs等の外にあるファイルというのがよく判りませんが、上の
ような関数は .emacs(.el) に書いてもいいし、.emacs とは別のファイルに
書いておいてロードしてもどちらでもいいでしょう。
> emacs-version = "20.4.1"
> mule-version = "4.0 (HANANOEN)"
20.7 まで来てますよ(20.8 出てます?最近見てないや)。
> # Elisp20.3のinfoを見たのですが、Local Variables:で指定されたcoding
> # の値の参照方法さえ見付けることができませんでした。多分、前提知識が
これは上記の通りです。
Re: html-helper-modeでのbuffer-file-coding-systemの設定
Author: KANEMATSU Shin'ya
Date: Tue, 29 May 2001 04:54
Date: Tue, 29 May 2001 04:54
32 lines
2439 bytes
2439 bytes
御教示ありがとうございます。 >>>>> In <9ev217$j2a$1@sn.asahi-net.email.ne.jp> >>>>> Seiichi Namba <sn@asahi-net.email.ne.jp> wrote: Namba> 書き方が違う、ということかな。今、 「Local Variables:」設定行のコロンの左側に、 「buffer-file-coding-system」でなく「coding」と指定していたのがマズかっ たようです。 以下のように記述したら、希望どおりにbuffer-file-coding-systemが設定 されました。 <!-- %%% Local Variables: %%% mode: outline-minor %%% buffer-file-coding-system: sjis-dos %%% End: --> Namba> 行きあたりばったりですが ... 略 ... Namba> buffer-file-coding-system に setq する…?。ここから先はお任せします。 ここはまだ試してませんが、時間的余裕が出たらやってみます。 Namba> .emacs等の外にあるファイルというのがよく判りませんが、上の これは明解でない表現でした。「外にあるファイル」よりも「別ファイル」 の方がわかりやすかったと思います。 --- 兼松 真哉 (かねまつ しんや)
Re: html-helper-modeでのbuffer-file-coding-systemの設定
Author: Seiichi Namba
Date: Tue, 29 May 2001 10:29
Date: Tue, 29 May 2001 10:29
82 lines
4109 bytes
4109 bytes
難波です。
KANEMATSU Shin'ya <kane@lp.nm.fujitsu.co.jp> さん writes:
> 「buffer-file-coding-system」でなく「coding」と指定していたのがマズかっ
> たようです。
確かに、
> %%% mode: outline-minor
などという表記が許されることを考えるとなんとなくそんな風に書けそうにも
思えますね。さらに、さっきのテストファイルを
<!
Local Variables:
mode: html-helper
outline-minor-mode: t
mode: auto-fill
junkvar: qwer
buffer-file-coding-system: sjis-dos
version-control: never
End:
>
などとして観察してみたのですが、やはりこのあたりにはちょっとした癖がある
ようです(ソースを追ったわけではなく、観察だけなので不正確かもしれませんが)。
(0) コロンの左側は任意の buffer-local な変数名シンボルとして扱われる。が、
(1) minior mode については outline-minor-mode: t などという表記でも
うまくいく(、場合がある、だけかもしれません)。が、
(2) major mode については mode: xxxx と書く必要がある。
という感じのようです。また、
buffer-file-coding-system: sjis-dos
と書いておく方式にはそれなりの穴があるかもしれませんね。たとえば、こう書く
だけで save する時の buffer-file-coding-system の値が保証されるわけでなない
ですから(find-file した時に違う値になっている事は考えられる訳で)。
…別の案としては、次のようなコマンドを使うんですかね。
(defun sjis-html-find-file (file)
(interactive "Fsjis-html-file: ")
(let ((html-helper-mode-hook
'((lambda () (setq buffer-file-coding-system 'sjis-dos)))))
(find-file file)))
これもゼロから書き初める時しか有効じゃないか…。つまり、
間違って既に euc でセーブされているものは再度セーブしなおす操作が
無ければ救えない訳だし…。
セーブする時の coding-system を自動的にある(デフォルトとは違う)値に保
証するのって結構面倒ですね…。ええと…。
save-buffer-hook てのはあったっけ(もちろん、save-buffer-hook 的なもの
を利用するのであれば他のモードの事も考慮したコードを書く必要があります
ね)…。
捜せば hook は何かありそうですが、あまり時間を使いたくない時はテキトー
に自分でコマンドを書いてしまってもいいかも。
(defun html-save-buffer (&optional args)
(interactive "P")
(hack-local-variables)
(save-buffer args))
(define-key html-helper-mode-map "\C-x\C-s" 'html-save-buffer)
こうすれば少しは確実かな。つまり、後は編集中のいずれかの段階で
buffer-file-coding-system: xxxx
書くのを励行する、という事にすれば (hack-local-variables) を介して
その値を save-buffer の時の値に伝達することができます。
…ここまで書いて思い出した。advice.el を使う方が一般的かしら?
こっちはどなたか別の方にお任せします。
--
難波清一@東京西東京市 (http://www.asahi-net.or.jp/~pi9s-nnb/)
NAMBA Seiichi <sn@asahi-net.email.ne.jp>
Re: html-helper-modeでのbuffer-file-coding-systemの設定
Author: Seiichi Namba
Date: Thu, 31 May 2001 03:17
Date: Thu, 31 May 2001 03:17
49 lines
2821 bytes
2821 bytes
難波です。
Seiichi Namba <sn@asahi-net.email.ne.jp> さん writes:
> save-buffer-hook てのはあったっけ(もちろん、save-buffer-hook 的なもの
> を利用するのであれば他のモードの事も考慮したコードを書く必要があります
> ね)…。
>
> 捜せば hook は何かありそうですが、あまり時間を使いたくない時はテキトー
fj.editor.emacs の <tzg0dmjly9.wl@tenryu.tom.sfc.keio.ac.jp>
で、服部さんが書かれている
write-file-hooks
でしたね。
どの emacs でも同じかどうか判りませんが、 emacs-21.0.103 だと
save-buffer -> basic-save-buffer という順で実行され、
basic-save-buffer では
(or (run-hook-with-args-until-success 'write-contents-hooks)
(run-hook-with-args-until-success 'local-write-file-hooks)
(run-hook-with-args-until-success 'write-file-hooks)
;; If a hook returned t, file is already "written".
;; Otherwise, write it the usual way now.
(setq setmodes (basic-save-buffer-1)))
というくだりがあります。結構複雑ですね。
hack-local-variables を利用するとして、write-file-hooks を使う場合は
(add-hook 'write-file-hooks
(lambda ()
(and html-helper-mode
(hack-local-variables))))
ですかね。
advice.el を使うのであれば、
(defadvice save-buffer (before html-helper-ad activate)
(and html-helper-mode
(hack-local-variables)))
でしょうか。
hook は呼ばれるタイミングを一応確認しないと安心できませんが、
advice の方はタイミングを指定できるところが便利かもしれません。
いずれも実際に動かしてないのですが、間違ってたらご容赦。
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads