aboutsummaryrefslogtreecommitdiff
path: root/elisp/ellinika-mode.el
blob: 9ca7d6d0012e5f191528e8e10bbddc3db05753bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
;;; 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
   (if (boundp 'greek-input-method)
       greek-input-method
       'greek)))

(defun ancient-greek-input (arg)
  (interactive "p")
  (set-input-method
   (if (boundp 'ancient-greek-input-method)
       ancient-greek-input-method
     'greek-ibycus4)))
  
(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 'greek-input-method)
  (make-variable-buffer-local 'ancient-greek-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 "\C-c\M-g" 'ancient-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.