aboutsummaryrefslogtreecommitdiff
path: root/elisp
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2004-10-13 12:36:40 +0000
committerSergey Poznyakoff <gray@gnu.org.ua>2004-10-13 12:36:40 +0000
commitd6081cd2b6711030ff1f6d8849194bfeeba9cea3 (patch)
tree4d000ac151bdb5546fb0b6d172c9604c2cc89f7c /elisp
parent6e77e008302a7ed030f53c3a0234d730174f2ca9 (diff)
downloadellinika-d6081cd2b6711030ff1f6d8849194bfeeba9cea3.tar.gz
ellinika-d6081cd2b6711030ff1f6d8849194bfeeba9cea3.tar.bz2
Emacs mode for editing dictionaries
git-svn-id: file:///home/puszcza/svnroot/ellinika/trunk@231 941c8c0f-9102-463b-b60b-cd22ce0e6858
Diffstat (limited to 'elisp')
-rw-r--r--elisp/ellinika-dict-mode.el193
1 files changed, 193 insertions, 0 deletions
diff --git a/elisp/ellinika-dict-mode.el b/elisp/ellinika-dict-mode.el
new file mode 100644
index 0000000..af2ed7e
--- /dev/null
+++ b/elisp/ellinika-dict-mode.el
@@ -0,0 +1,193 @@
+;;; 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 "</[MKTXPF]>")
+ 'node)
+ ((or (looking-at "</NODE>") (looking-at "<DICT>"))
+ 'initial)
+ ((looking-at "<NODE>")
+ 'node)
+ ((looking-at "<M>")
+ '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-last-tag ">"))
+ (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>
+ <K></K>
+</NODE>"
+ 'node-init 0)
+ (define-abbrev ellinika-dict-mode-abbrev-table
+ "'m" "<M></M>"
+ 'back-4-ru 0)
+ (define-abbrev ellinika-dict-mode-abbrev-table
+ "'k" "<K></K>"
+ 'back-4-el 0)
+ (define-abbrev ellinika-dict-mode-abbrev-table
+ "'p" "<P></P>"
+ 'back-4-el 0)
+ (define-abbrev ellinika-dict-mode-abbrev-table
+ "'f" "<F></F>"
+ 'back-4-el 0)
+ (define-abbrev ellinika-dict-mode-abbrev-table
+ "'x" "<X></X>"
+ 'back-4-el 0)
+ (define-abbrev ellinika-dict-mode-abbrev-table
+ "'t" "<T></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
+

Return to:

Send suggestions and report system problems to the System administrator.