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 LispAdvent Calendar 2024

Day 8

Emacs Lisp 超初心者がコマンドを作ってみる 〜動く、動く〜

Last updated at Posted at 2024-12-18

前回までで、 previous msgid と msgid をそれぞれのバッファにいいかんじで持ってくることができました。

ということで、そろそろ ediff-regions-wordwise に繋ぎこんでみます。

さっそく動かしてみた

サンプル rev-list-options.po を開き、 previous msgid があるエントリに移動してから M-x po-ediff-previous-msgid として実行します。

動く、動く おー動いてる!

po-ediff-previous-msgid-buf-a.png

ここでキー入力待ちになりました。 C-M-c (CTRL+ALT+C) は押下しなければならないようです。

po-ediff-previous-msgid-buf-b.png

再びキー入力待ちになりました。 C-M-c 押下。

これでやっと目的のモノが表示されました。

po-ediff-previous-msgid-result.png

終了は q

po-ediff-previous-msgid-ask.png

qを押下して ediff を抜けます。

プログラム

po-previous-msgid.el
;;; po-ediff-previous-msgid.el --- ediff previous-msgid and msgid.
;;; Author: kuma35
;;; Created: 2024/12/18
;;; Commentary:
;; previous msgid is  '#|' marked in comment.
;;; Code:

(defcustom po-ediff-previous-msgid-buffer-a-name "*pepm-previous-msgid*"
  "'po-ediff-previous-msgid' BUFFER A name.  pepm is PoEdiffPreviousMsgid."
  :type 'string
  :require 'po-mode
  :group 'po)

(defcustom po-ediff-previous-msgid-buffer-b-name "*pepm-now-msgid*"
  "'po-ediff-previous-msgid' BUFFER A name.  pepm is PoEdiffPreviousMsgid."
  :type 'string
  :require 'po-mode
  :group 'po)


(defun po-extract-previous-msgid (buffer start end)
  "Delete '#|' marker and unquote text from BUFFER START END.
delete '^#| ' each line.  then unquote.
return is String with property."
  (with-temp-buffer
    (insert-buffer-substring buffer start end)
    (goto-char (point-min))
    (while (re-search-forward "^#\\(~\\)?|[ \t]*" nil t)
      (replace-match "" t t))
    (po-extract-unquoted (current-buffer) (point-min) (point-max))
    )
  )

(defun po-ediff-previous-msgid ()
  "Ediff previous msgid (marked #| ) and msgid."
  (interactive)
  (po-find-span-of-entry)
  (let (
	(oldbuf (current-buffer))
	(msgid (po-get-msgid))
	(untranslated-regions (po-previous-untranslated-regions))
	)
    (save-current-buffer
      (set-buffer (get-buffer-create
		   po-ediff-previous-msgid-buffer-a-name))
      (setq buffer-read-only nil)
      (erase-buffer)
      (dolist (region untranslated-regions)
	(insert (po-extract-previous-msgid oldbuf (car region) (cdr region)))
	)
      (goto-char (point-min))
      (push-mark (point-max) t t)
      (setq buffer-read-only t)
      (restore-buffer-modified-p nil))
    (save-current-buffer
      (set-buffer (get-buffer-create
		   po-ediff-previous-msgid-buffer-b-name))
      (setq buffer-read-only nil)
      (erase-buffer)
      (insert msgid)
      (goto-char (point-min))
      (push-mark (point-max) t t)
      (setq buffer-read-only t)
      (restore-buffer-modified-p nil)))
  (ediff-regions-wordwise
   po-ediff-previous-msgid-buffer-a-name
   po-ediff-previous-msgid-buffer-b-name)
  )


(provide 'po-ediff-previous-msgid)
;;; po-ediff-previous-msgid.el ends here

とりあえずは動いたけど

手動でやっていたころから比べると大幅な手間削減で、とりあえずはこれでいいんじゃないかとおもうのですが、まだ C-M-c を 2回キーインしなければなりません。これは次回以降でそのうち解決したいと思います。

今回はここまで。

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?