aboutsummaryrefslogtreecommitdiff
path: root/elisp
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2004-10-16 14:54:19 +0000
committerSergey Poznyakoff <gray@gnu.org.ua>2004-10-16 14:54:19 +0000
commita5d39b70625b2bc344d31a6742ecfbd4cb2bff9a (patch)
tree6c31e2fd7711f602443a808dbd26b3e1b8d6be41 /elisp
parent428ccba9bdd1e95b4640aaa2d6417ca6168b795e (diff)
downloadellinika-a5d39b70625b2bc344d31a6742ecfbd4cb2bff9a.tar.gz
ellinika-a5d39b70625b2bc344d31a6742ecfbd4cb2bff9a.tar.bz2
Base mode for editing Ellinika XML files
git-svn-id: file:///home/puszcza/svnroot/ellinika/trunk@251 941c8c0f-9102-463b-b60b-cd22ce0e6858
Diffstat (limited to 'elisp')
-rw-r--r--elisp/ellinika-mode.el154
1 files changed, 154 insertions, 0 deletions
diff --git a/elisp/ellinika-mode.el b/elisp/ellinika-mode.el
new file mode 100644
index 0000000..9549201
--- /dev/null
+++ b/elisp/ellinika-mode.el
@@ -0,0 +1,154 @@
+;;; ellinika-dict-mode.el --- major mode for editing Ellinika dictionary files
+
+;; Authors: 2004 Sergey Poznyakoff
+;; Version: 1.0
+;; Keywords: Ellinika, greek
+;; $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)
+
+
+;;;;
+
+(defcustom ellinika-close-tag-hook nil
+ "Hook function run upon closing of a tag")
+
+(defun ellinika-set-close-tag-hook (hook)
+ (setq ellinika-close-tag-hook hook))
+
+(defun ellinika-find-open-tag-internal ()
+ (catch 'loop
+ (let ((tag-list nil))
+ (while (search-backward-regexp "<\\(/?[^ >]+\\)\\(\\s +[^>]*\\)?>"
+ nil t)
+ (let ((tag (buffer-substring
+ (match-beginning 1)
+ (match-end 1))))
+ (cond
+ ((char-equal (string-to-char tag) ?\/)
+ (setq tag-list (cons (substring tag 1)
+ tag-list)))
+ ((looking-at "<!"))
+ ((looking-at "<[^ >]+\\(\\s +[^>]*\\)?/>"))
+ ((string-equal (car tag-list) tag)
+ (setq tag-list (cdr tag-list)))
+ (t
+ (throw 'loop tag))))))))
+
+(defun ellinika-find-open-tag (&optional move-point)
+ (if move-point
+ (ellinika-find-open-tag-internal)
+ (save-excursion
+ (ellinika-find-open-tag-internal))))
+
+(defun ellinika-close-tag (arg)
+ (interactive "p")
+ (let ((tag (ellinika-find-open-tag)))
+ (cond
+ (tag
+ (insert (concat "</" tag ">"))
+ (and ellinika-close-tag-hook (funcall ellinika-close-tag-hook)))
+ (t
+ (message "No open tags")))))
+
+(defun ellinika-insert-include (arg)
+ (interactive "p")
+ (beginning-of-line)
+ (insert "<INCLUDE FILE=\"\" />")
+ (backward-char 4)
+ (inactivate-input-method))
+
+(defcustom alternative-input-method nil
+ "Defines input-method for non-greek text in this buffer.")
+
+(defcustom alternative-dictionary nil
+ "Defines alternative (non-greek) spell-checking dictionary for this buffer.")
+
+(defun ellinika-run-ispell (dict)
+ (let ((ispell-skip-html t)
+ (ispell-local-dictionary dict))
+ (ispell)))
+
+(defun ellinika-ispell-greek (arg)
+ (interactive "p")
+ (ellinika-run-ispell "greek"))
+
+(defun ellinika-ispell-alt (arg)
+ (interactive "p")
+ (ellinika-run-ispell (if alternative-dictionary
+ alternative-dictionary
+ (error "Alternative dictionary not defined"))))
+
+(defun ellinika-ispell (arg)
+ (interactive "p")
+ (ellinika-run-ispell (if (> arg 0)
+ "greek"
+ (if alternative-dictionary
+ alternative-dictionary
+ (error "Alternative dictionary not defined")))))
+
+(defun ellinika-electric-obrace (arg)
+ (interactive "p")
+ (inactivate-input-method)
+ (self-insert-command arg))
+
+(defun ellinika-electric-cbrace (arg)
+ (interactive "p")
+ (self-insert-command arg)
+ (and ellinika-close-tag-hook (funcall ellinika-close-tag-hook)))
+
+
+;;;###autoload
+(define-derived-mode ellinika-mode sgml-mode "Ellinika"
+ "Base major mode for editing Ellinika XML sources. All major modes
+are derived from this one.
+
+ Key bindings:
+\\{ellinika-mode-map}"
+
+ (make-variable-buffer-local 'alternative-input-method)
+ (make-variable-buffer-local 'alternative-dictionary)
+ (make-variable-buffer-local 'ellinika-close-tag-hook)
+
+ (define-key ellinika-mode-map "\C-c\C-i" 'ellinika-insert-include)
+ (define-key ellinika-mode-map "\C-c\C-g" 'ellinika-ispell-greek)
+ (define-key ellinika-mode-map "\C-c\C-s" 'ellinika-ispell-alt)
+
+ (define-key ellinika-mode-map "\M-g" 'greek-input)
+ (define-key ellinika-mode-map "\M-r" 'alt-input)
+ (define-key ellinika-mode-map "<" 'ellinika-electric-obrace)
+ (define-key ellinika-mode-map ">" 'ellinika-electric-cbrace)
+ (define-key ellinika-mode-map "\C-c>" 'ellinika-close-tag))
+
+(provide 'ellinika-mode)
+
+;;;; End of ellinika-mode.el
+

Return to:

Send suggestions and report system problems to the System administrator.