--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/misc/gadialog.el Sun Oct 18 12:25:22 2020 +0300
@@ -0,0 +1,91 @@
+;;; gadialog.el --- major mode for editing gadialog dialog files -*- lexical-binding: t -*-
+
+;; Copyright (C) 2019 by Oleksandr Gavenko <gavenkoa@gmail.com>
+
+;; You can do anything with this file without any warranty.
+
+;; Author: Oleksandr Gavenko <gavenkoa@gmail.com>
+;; Maintainer: Oleksandr Gavenko <gavenkoa@gmail.com>
+;; Created: 2019
+;; Version: 0.17
+;; Keywords: dict, dictionary
+
+;;; Commentary:
+;;
+;; Mode can be installed by:
+;;
+;; (autoload 'gadialog-mode "gadialog")
+;;
+;; File association can be registered by:
+;;
+;; (add-to-list 'auto-mode-alist (cons "\\.gadialog$" 'gadialog-mode))
+
+;;; Code:
+
+(defvar gadialog-font-lock-keywords
+ '(("^# [1-9][0-9]*" . font-lock-type-face)
+ ("^## [1-9][0-9]*" . font-lock-warning-face)
+ ("^- " . font-lock-keyword-face)))
+
+(defvar gadialog-syntax-table
+ (let ((table (make-syntax-table text-mode-syntax-table)))
+ (modify-syntax-entry ?' "w" table)
+ table))
+
+(defun gadialog-next-num ()
+ (save-excursion
+ (goto-char (point-min))
+ (let (beg end num)
+ (catch 'return
+ (when (looking-at "## \\([1-9][0-9]*\\)")
+ (setq beg (match-beginning 1)
+ end (match-end 1))
+ (setq num (string-to-number (buffer-substring beg end)))
+ (delete-region beg end)
+ (goto-char beg)
+ (setq num (1+ num))
+ (insert (int-to-string num))
+ (throw 'return num))
+ (insert "## 1\n")
+ 1))))
+
+(defun gadialog-cleaup-whitespaces-forward ()
+ (while (memq (char-before) '(?\ ?\n ?\t))
+ (delete-char -1)))
+
+(defun gadialog-insert-template ()
+ (interactive)
+ (forward-line 0)
+ (when (looking-at "# ")
+ (forward-line 1))
+ (unless (re-search-forward "^# " (+ (point) 10240) t)
+ (goto-char (point-max)))
+ (when (eobp) (insert-char ?\n))
+ (forward-line 0)
+ (gadialog-cleaup-whitespaces-forward)
+ (insert "\n# ")
+ (insert (int-to-string (gadialog-next-num)))
+ (insert "\n- \n")
+ (backward-char))
+
+(defun gadialog-insert-sentence ()
+ (interactive)
+ (forward-line 1)
+ (while (not (or (eobp)
+ (memq (char-after) (list ?- ?#))))
+ (forward-line 1))
+ (gadialog-cleaup-whitespaces-forward)
+ (insert "\n- \n")
+ (backward-char))
+
+
+(define-derived-mode gadialog-mode fundamental-mode "gadialog"
+ (setq font-lock-defaults '(gadialog-font-lock-keywords))
+ (define-key (current-local-map) [C-return] 'gadialog-insert-template)
+ (define-key (current-local-map) [S-return] 'gadialog-insert-sentence)
+ (set-syntax-table gadialog-syntax-table)
+ (setq paragraph-start "[#-]"))
+
+(provide 'gadialog)
+
+;;; gadialog.el ends here