0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Emacs Lisp 超初心者がコマンド作ってみる 〜今回作っていきたいもの po-modeで previous msgid(#|) と msgid の差分〜

Last updated at Posted at 2024-12-17

はじめに

超初心者ゆえ、 正確性よりも「こんな感じ」「あんな感じ」「これこれに似てる」という雰囲気で進みます。超初心者はメンタル豆腐ですので、それは違うそれはこうだとか怒らないで優しく優しく優しくご指導してもいいけどご鞭撻しないで

Emacs Lisp 永遠の初心者の kuma35 です。

今回は割とスクラッチ気味で Emacs Lisp でコマンドを作っていきたいと思います。毎回亀の歩みです。

さて、いままでは既存のコマンドをちょこっといじってコマンドを作ってきました。
例えばこんなのです(下記)。いじったのはこの中の1行2行とかそんなんです。

これは po-kill-ring-save-msgstr "Push the msgstr string from current entry on the kill ring." をちょこっとだけいじったもので、Lispとはどう動くのか、Emacs Lispはどう動くのか Emacs の機能をどうやって使うのかがまだサッパリ分かっていません。

どのような作業に使うものなのか

今回、最終的に作りたいのは po-mode 用のコマンドです。

Emacs の po-mode を活用してオレオレ翻訳を行っていまして、 例えば git のドキュメントをオレオレ翻訳しています。 翻訳は一度やればお終いではなくて、 git がバージョンアップするたびに既存のドキュメントの変更や新しいドキュメントが増えてそれに対応した新たな翻訳が必要になります。

その時 po-mode はある程度の支援をしてくれます。今回の原文と以前の原文を見比べて、全く同じものには以前の原文に対応した訳文を割り当てます。更に、似通ったものは fuzzy エントリ扱いにして、更にコメント欄に以前の原文を貼り付けてくれます。

翻訳作業としては、新規の翻訳を行うのはもちろんですが、 こういう以前の原文がコメントとして貼り付けられた fuzzy エントリも翻訳することになります。このエントリはしばしば typo 修正とか、単数形複数形間違ってました等、軽微な変更であることもあり、その場合は新しい原文をイチから訳さなくてもいいことが多いです。

しかし、それを知るためにはコメント欄の以前の原文(以後 previous msgid)と、今回の原文をじっくりと見比べて違いを調べなければなりません。

これは結構大変な作業でしたのでなんとか楽にならないかと思い思いついた方法が、手動で ediff-regions-wordwise を実行する方法です。

手動の手順→これをコマンドにしたい。

以下のエントリがあるとします(少しいじっていますが、 git/Document/rev-list-options.txtをpo4aを使って po ファイルに落とし込んだものです)

#. type: Plain text
#: ../Documentation-sedout/rev-list-options.txt:957
#, fuzzy
#| msgid ""
#| "The form '--filter=blob:limit=<n>[kmg]' omits blobs larger than n bytes "
#| "or units.  n may be zero.  The suffixes k, m, and g can be used to name "
#| "units in KiB, MiB, or GiB.  For example, 'blob:limit=1k' is the same as "
#| "'blob:limit=1024'."
msgid ""
"The form '--filter=blob:limit=<n>[kmg]' omits blobs of size at least n bytes "
"or units.  n may be zero.  The suffixes k, m, and g can be used to name "
"units in KiB, MiB, or GiB.  For example, 'blob:limit=1k' is the same as "
"'blob:limit=1024'."
msgstr ""
"`--filter=blob:limit=<n>[kmg]` の形式では、nバイトまたは指定の単位より大きい"
"ブロブが省略されます。nはゼロの場合があります。 接尾辞kとmとgを使用して、KiB"
"またはMiBまたはGiBの単位にすることができます。 たとえば、 `blob:limit=1k` は "
"`blob:limit=1024` と同じです。"

ここから、 前回の原文(previous msgid) (#! の部分) と 今回の原文 msgid
をコピペで scratch バッファにコピペします

#| msgid ""
#| "The form '--filter=blob:limit=<n>[kmg]' omits blobs larger than n bytes "
#| "or units.  n may be zero.  The suffixes k, m, and g can be used to name "
#| "units in KiB, MiB, or GiB.  For example, 'blob:limit=1k' is the same as "
#| "'blob:limit=1024'."
msgid ""
"The form '--filter=blob:limit=<n>[kmg]' omits blobs of size at least n bytes "
"or units.  n may be zero.  The suffixes k, m, and g can be used to name "
"units in KiB, MiB, or GiB.  For example, 'blob:limit=1k' is the same as "
"'blob:limit=1024'."

これを手動で編集してテキストにします。これがめんどくさい

The form '--filter=blob:limit=<n>[kmg]' omits blobs larger than n bytes or units.  n may be zero.  The suffixes k, m, and g can be used to name units in KiB, MiB, or GiB.  For example, 'blob:limit=1k' is the same as 'blob:limit=1024'.

The form '--filter=blob:limit=<n>[kmg]' omits blobs of size at least n bytes or units.  n may be zero.  The suffixes k, m, and g can be used to name units in KiB, MiB, or GiB.  For example, 'blob:limit=1k' is the same as 'blob:limit=1024'.

このテキストを ediff-regions-wordwise で ediff します。

M-x ediff-regions-wordwize → buffer-Aを選べ(*scratch) → buffer-B を選べ(必ず候補が scratch 以外になる。そこを頑張って回避して再び scratch を選ぶ)

更に 2つの region を scratch バッファで指定します。 CTRL+Space でマーク、 C-M-c(CTRL+ALT+C)で region-A 決定、もう一箇所を CTRL+Space ... C-M-C で、

これで ediff の画面になります。ここで差異を確認して ediff の通例どおり q で終了です。

今回はこの手動手順をコマンドにしていきたいと思います。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?