;;; ellinika-dict-mode.el --- major mode for editing Ellinika dictionary files ;; Authors: 2004 Sergey Poznyakoff ;; Version: 1.0 ;; Keywords: Ellinika, greek, dictionary ;; $Id$ ;; This file is part of Ellinika. ;; Copyright (C) 2004 Sergey Poznyakoff. ;; Ellinika 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. ;; Ellinika 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 Ellinika; see the file COPYING. If not, write to the ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, ;; Boston, MA 02111-1307, USA. (defun greek-input (arg) (interactive "p") (set-input-method 'greek)) (defun alt-input (arg) (interactive "p") (if (boundp 'alternative-input-method) (set-input-method alternative-input-method) (inactivate-input-method))) (set-language-environment 'utf-8) ;;; Abbreviation stuff (defun node-init nil (forward-line -1) (beginning-of-line) (forward-char 4) (greek-input nil) t) (put 'node-init 'no-self-insert t) (defun back-4 nil (backward-char 4) t) (put 'back-4 'no-self-insert t) (defun back-4-ru nil (backward-char 4) (alt-input nil) t) (put 'back-4-ru 'no-self-insert t) (defun back-4-el nil (backward-char 4) (greek-input nil) t) (put 'back-4-el 'no-self-insert t) ;;; (defun ellinika-guess-line-syntax () (save-excursion (let ((bound (save-excursion (beginning-of-line) (point)))) (end-of-line) (if (not (search-backward-regexp "<\\(/?[^>]+\\)>" bound t)) nil (setq ellinika-last-tag (buffer-substring (match-beginning 1) (match-end 1))) (cond ((looking-at "") 'node) ((or (looking-at "") (looking-at "")) 'initial) ((looking-at "") 'node) ((looking-at "") 'alternative-input) ((looking-at "<[KX]>") 'greek-input) ((looking-at "<[TPF]") 'ascii-input) ((looking-at "<[CE]>") nil) (t 'unknown-tag)))))) (defun ellinika-guess-syntax () (setq ellinika-last-tag nil) (save-excursion (catch 'loop (while (not (bobp)) (let ((syntax (ellinika-guess-line-syntax))) (if syntax (throw 'loop syntax) (forward-line -1)))) nil))) (defun ellinika-select-input-method nil (let ((syntax (ellinika-guess-syntax))) (cond ((eq syntax 'ascii-input) (inactivate-input-method)) ((eq syntax 'alternative-input) (alt-input nil)) ((eq syntax 'greek-input) (greek-input nil)) ((or (eq syntax 'node) (eq syntax 'initial)) (inactivate-input-method))))) (defun ellinika-newline (arg) (interactive "p") (ellinika-select-input-method) (newline-and-indent)) (defun ellinika-electric-obrace (arg) (interactive "p") (inactivate-input-method) (self-insert-command arg)) (defun ellinika-electric-cbrace (arg) (interactive "p") (inactivate-input-method) (self-insert-command arg) (ellinika-select-input-method)) (defun ellinika-close-tag (arg) (interactive "p") (let ((syntax (ellinika-guess-syntax))) (cond ((not ellinika-last-tag)) ((char-equal (string-to-char ellinika-last-tag) ?\/)) (t (insert (concat "")) (ellinika-select-input-method))))) ;;;###autoload (define-derived-mode ellinika-dict-mode sgml-mode "Ellinika-Dict" "Major mode for editing Ellinika dictionary sources. Key bindings: \\{ellinika-dict-mode-map}" (make-variable-buffer-local 'ellinika-last-tag) (define-abbrev ellinika-dict-mode-abbrev-table "'n" " " 'node-init 0) (define-abbrev ellinika-dict-mode-abbrev-table "'m" "" 'back-4-ru 0) (define-abbrev ellinika-dict-mode-abbrev-table "'k" "" 'back-4-el 0) (define-abbrev ellinika-dict-mode-abbrev-table "'p" "

" 'back-4-el 0) (define-abbrev ellinika-dict-mode-abbrev-table "'f" "" 'back-4-el 0) (define-abbrev ellinika-dict-mode-abbrev-table "'x" "" 'back-4-el 0) (define-abbrev ellinika-dict-mode-abbrev-table "'t" "" 'back-4-el 0) (define-key ellinika-dict-mode-map "\M-g" 'greek-input) (define-key ellinika-dict-mode-map "\M-r" 'alt-input) (define-key ellinika-dict-mode-map "\C-c>" 'ellinika-close-tag) (define-key ellinika-dict-mode-map "<" 'ellinika-electric-obrace) (define-key ellinika-dict-mode-map ">" 'ellinika-electric-cbrace) (define-key ellinika-dict-mode-map "\C-m" 'ellinika-newline)) (provide 'ellinika-dict-mode) ;;;; End of ellinika-dict-mode.el