summaryrefslogtreecommitdiffstats
path: root/.emacs.d/lisp/bandali-po.el
diff options
context:
space:
mode:
authorAmin Bandali <bandali@kelar.org>2025-01-30 22:55:32 -0500
committerAmin Bandali <bandali@kelar.org>2025-01-30 22:55:32 -0500
commitc7b47e03e0ac16d6db84d59d8cff58291b22fbaa (patch)
tree64997f5e10d25897966d496d905aa6ff835f5f94 /.emacs.d/lisp/bandali-po.el
parent563fb78037f21c6503c6489758e8f0d86173bb7e (diff)
downloadconfigs-c7b47e03e0ac16d6db84d59d8cff58291b22fbaa.tar.gz
configs-c7b47e03e0ac16d6db84d59d8cff58291b22fbaa.tar.xz
configs-c7b47e03e0ac16d6db84d59d8cff58291b22fbaa.zip
Break out .emacs.d/init.el into .emacs.d/lisp/bandali-*.el again
Having used the monolithic init.el approach, I found it somewhat unwieldy, especially as the file grows larger and larger.
Diffstat (limited to '')
-rw-r--r--.emacs.d/lisp/bandali-po.el62
1 files changed, 62 insertions, 0 deletions
diff --git a/.emacs.d/lisp/bandali-po.el b/.emacs.d/lisp/bandali-po.el
new file mode 100644
index 0000000..982225f
--- /dev/null
+++ b/.emacs.d/lisp/bandali-po.el
@@ -0,0 +1,62 @@
+;;; bandali-po.el --- bandali's po-mode setup -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2021 Amin Bandali <bandali@gnu.org>
+
+;; 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 () (run-with-timer 0.1 nil #'View-exit)))
+ (b/keymap-set po-mode-map "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