Created
August 20, 2013 06:09
-
-
Save amotoki/6277613 to your computer and use it in GitHub Desktop.
Compare the difference in PO fuzzy string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; po-fuzzy-diff.el --- Compare the difference in PO fuzzy string | |
;; Copyright (C) 2013 Akihiro Motoki <[email protected]> | |
;; Author: Akihiro Motoki <[email protected]> | |
;; Keywords: convenience po-mode | |
;; This file is free software; you can redistribute it and/or modify | |
;; it under the terms of the GNU General Public License as published by | |
;; the Free Software Foundation; either version 2, or (at your option) | |
;; any later version. | |
;; This file is distributed in the hope that it will be useful, | |
;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
;; GNU General Public License for more details. | |
;; You should have received a copy of the GNU General Public License | |
;; along with GNU Emacs; see the file COPYING. If not, write to | |
;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | |
;; Boston, MA 02110-1301, USA. | |
;;; Commentary: | |
;; po-fuzzy-diff makes it easier to check the difference | |
;; in a PO fuzzy msgid string. | |
;; This command works only in po-mode. | |
;; Run this command around fuzzy msgid string in a PO file. | |
;;; Installation | |
;; (require 'po-fuzzy-diff) | |
;; (define-key po-mode-map "\M-=" 'po-fuzzy-diff) | |
;;; History: | |
;; 1.0: Initial revision | |
;;; Code: | |
(defun po-fuzzy-diff () | |
"Check a difference in fuzzy contents." | |
(interactive) | |
(let (begin end prevfile newfile diffbuf) | |
(save-excursion | |
(re-search-backward "^$" nil t) | |
(setq begin (point)) | |
(re-search-forward "^msgstr " nil t) | |
(beginning-of-line) | |
(setq end (point)) | |
(goto-char begin) | |
(if (not (and (re-search-forward "^#| msgid " nil t) | |
(< (point) end))) | |
(error "Valid fuzzy section not found.")) | |
(beginning-of-line) | |
(setq begin (point)) | |
;; cut text from the original buffer | |
(kill-ring-save begin end) | |
;; previous string | |
(with-temp-buffer | |
(yank) | |
(goto-char (point-min)) | |
(re-search-forward "^msgid " nil t) | |
(move-beginning-of-line nil) | |
(kill-region (point) (point-max)) | |
(goto-char (point-min)) | |
(replace-regexp "^#| " "" nil (point-min) (point-max)) | |
(replace-regexp "^msgid " "" nil (point-min) (point-max)) | |
(replace-regexp "^\"" "" nil (point-min) (point-max)) | |
(replace-regexp "\"$" "" nil (point-min) (point-max)) | |
(setq prevfile (make-temp-file "podiff")) | |
(write-region (point-min) (point-max) prevfile)) | |
(with-temp-buffer | |
(yank) | |
(goto-char (point-min)) | |
(replace-regexp "^msgid " "" nil (point-min) (point-max)) | |
(replace-regexp "^\"" "" nil (point-min) (point-max)) | |
(replace-regexp "\"$" "" nil (point-min) (point-max)) | |
(setq newfile (make-temp-file "podiff")) | |
(write-region (point-min) (point-max) newfile)) | |
(setq diffbuf (diff prevfile newfile "-c" 'no-async)) | |
(set-buffer diffbuf) | |
(toggle-read-only t) | |
(set-buffer-modified-p nil) | |
(pop-to-buffer diffbuf) | |
(diff-hunk-next) | |
(delete-file prevfile) | |
(delete-file newfile)))) | |
(provide 'po-fuzzy-diff) | |
;;; po-fuzzy-diff.el ends here |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment