summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.emacs.d/init.el3
-rw-r--r--.emacs.d/lisp/bandali-po.el61
2 files changed, 64 insertions, 0 deletions
diff --git a/.emacs.d/init.el b/.emacs.d/init.el
index 47c254a..3257260 100644
--- a/.emacs.d/init.el
+++ b/.emacs.d/init.el
@@ -967,6 +967,9 @@ Make N (default: 1) copies of the current line or region."
(delight 'mml-mode " mml" "mml")
(delight 'yas-minor-mode "" "yasnippet"))
+;; po-mode
+(require 'bandali-po)
+
;;; Post initialization
diff --git a/.emacs.d/lisp/bandali-po.el b/.emacs.d/lisp/bandali-po.el
new file mode 100644
index 0000000..a31fee2
--- /dev/null
+++ b/.emacs.d/lisp/bandali-po.el
@@ -0,0 +1,61 @@
+;;; bandali-po.el --- bandali's po-mode setup -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2021 Amin Bandali
+
+;; Author: Amin Bandali <bandali@gnu.org>
+;; Keywords: i18n gettext
+
+;; This program 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 3 of the License, or
+;; (at your option) any later version.
+
+;; This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; My po-mode setup for editing PO translation files in GNU Emacs.
+
+;;; Code:
+
+(with-eval-after-load 'po-mode
+ ;; based on the `po-wrap' function from the GNUN manual:
+ ;; https://www.gnu.org/s/trans-coord/manual/gnun/html_node/Wrapping-Long-Lines.html
+ (defun b/po-wrap ()
+ "Run the current `po-mode' buffer through `msgcat' to wrap all
+lines."
+ (interactive)
+ (when (eq major-mode 'po-mode)
+ (let ((tmp-file (make-temp-file "po-wrap."))
+ (tmp-buffer (generate-new-buffer "*temp*")))
+ (unwind-protect
+ (progn
+ (write-region (point-min) (point-max) tmp-file nil 1)
+ (if (zerop
+ (call-process "msgcat" nil tmp-buffer t
+ (shell-quote-argument tmp-file)))
+ (let ((saved (point))
+ (inhibit-read-only t))
+ (delete-region (point-min) (point-max))
+ (insert-buffer-substring tmp-buffer)
+ (goto-char (min saved (point-max))))
+ (with-current-buffer tmp-buffer
+ (error (buffer-string)))))
+ (kill-buffer tmp-buffer)
+ (delete-file tmp-file)))))
+
+ (add-hook 'po-mode-hook (lambda nil (run-with-timer 0.1 nil 'View-exit)))
+ (define-key po-mode-map (kbd "M-q") #'b/po-wrap))
+
+(autoload #'po-mode "po-mode"
+ "Major mode for editing PO translation files" t)
+(add-to-list 'auto-mode-alist '("\\.po\\'\\|\\.po\\." . po-mode))
+
+(provide 'bandali-po)
+;;; bandali-po.el ends here