diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2004-10-14 16:07:09 +0000 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2004-10-14 16:07:09 +0000 |
commit | 1b7f3c080397368a5710a4507fd95cc9eb4a29c8 (patch) | |
tree | 0f8bd944459d44337b1f2ad620d1cc9315ad2653 /elisp | |
parent | 68c70ca37b768c3bbe23fa5be3580ad350f07dfc (diff) | |
download | ellinika-1b7f3c080397368a5710a4507fd95cc9eb4a29c8.tar.gz ellinika-1b7f3c080397368a5710a4507fd95cc9eb4a29c8.tar.bz2 |
Heavily modified
git-svn-id: file:///home/puszcza/svnroot/ellinika/trunk@242 941c8c0f-9102-463b-b60b-cd22ce0e6858
Diffstat (limited to 'elisp')
-rw-r--r-- | elisp/ellinika-dict-mode.el | 283 |
1 files changed, 188 insertions, 95 deletions
diff --git a/elisp/ellinika-dict-mode.el b/elisp/ellinika-dict-mode.el index af2ed7e..c1e4719 100644 --- a/elisp/ellinika-dict-mode.el +++ b/elisp/ellinika-dict-mode.el @@ -36,80 +36,61 @@ (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))) + (while (search-backward-regexp "<\\(/?[^ >]+\\)\\(\\s +[^>]*\\)?>" + nil t) + (let ((tag (buffer-substring + (match-beginning 1) + (match-end 1)))) + (setq ellinika-last-tag tag) + (cond + ((string-equal tag "T") + (throw 'loop (ellinika-guess-syntax))) + ((looking-at "</[MKXPF]>") + (throw 'loop 'node)) + ((or (looking-at "</NODE>") (looking-at "<DICT>")) + (throw 'loop 'initial)) + ((looking-at "<M>") + (throw 'loop 'alternative-input)) + ((looking-at "<[KX]>") + (throw 'loop 'greek-input) + ((looking-at "<[PF]") + (throw 'loop 'ascii-input)) + ((looking-at "<[CE]>")) ;; continue + (t + (throw 'loop 'invalid-tag)))))) + 'initial))) + + +(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-select-input-method nil (let ((syntax (ellinika-guess-syntax))) (cond @@ -140,13 +121,136 @@ (defun ellinika-close-tag (arg) (interactive "p") + (let ((tag (ellinika-find-open-tag))) + (cond + (tag + (insert (concat "</" tag ">")) + (ellinika-select-input-method)) + (t + (message "No open tags"))))) + +(defun ellinika-begin-node (arg) + (interactive "p") + (let ((syntax (ellinika-guess-syntax))) + (cond + ((eq syntax 'initial) + (beginning-of-line) + (insert "<NODE>\n <K></K>\n</NODE>") + (forward-line -1) + (beginning-of-line) + (forward-char 4) + (greek-input nil)) + (t + (message "Cannot start node here"))))) + +(defun ellinika-init-block (tag &optional input-method) + (beginning-of-line) + (if (string-equal (ellinika-find-open-tag) "P") + (insert " ")) + (insert " <" tag "></" tag ">") + (backward-char (+ (length tag) 3)) + (when input-method + (set-input-method input-method))) + +(defun ellinika-begin-article (arg) + (interactive "p") (let ((syntax (ellinika-guess-syntax))) (cond - ((not ellinika-last-tag)) - ((char-equal (string-to-char ellinika-last-tag) ?\/)) + ((eq syntax 'node) + (ellinika-init-block "M" (if (boundp 'alternative-input-method) + alternative-input-method + nil))) (t - (insert (concat "</" ellinika-last-tag ">")) - (ellinika-select-input-method))))) + (message "Cannot start key here"))))) + +(defun ellinika-begin-key (arg) + (interactive "p") + (let ((syntax (ellinika-guess-syntax))) + (cond + ((eq syntax 'node) + (ellinika-init-block "K" 'greek)) + (t + (message "Cannot start key here"))))) + +(defun ellinika-begin-pos (arg) + (interactive "p") + (let ((syntax (ellinika-guess-syntax))) + (cond + ((eq syntax 'node) + (ellinika-init-block "P" 'greek)) + (t + (message "Cannot start pos here"))))) + +(defun ellinika-begin-forms (arg) + (interactive "p") + (let ((syntax (ellinika-guess-syntax))) + (cond + ((eq syntax 'node) + (ellinika-init-block "F" 'greek)) + (t + (message "Cannot start forms here"))))) + +(defun ellinika-begin-xref (arg) + (interactive "p") + (let ((syntax (ellinika-guess-syntax))) + (cond + ((eq syntax 'node) + (ellinika-init-block "X" 'greek)) + (t + (message "Cannot start xref here"))))) + +(defun ellinika-begin-ant (arg) + (interactive "p") + (let ((syntax (ellinika-guess-syntax))) + (cond + ((eq syntax 'node) + (ellinika-init-block "A" 'greek)) + (t + (message "Cannot start antonym here"))))) + +(defun ellinika-begin-topic (arg) + (interactive "p") + (let ((syntax (ellinika-guess-syntax))) + (cond + ((eq syntax 'initial) + (insert "<T ID=\"\">\n</T>") + (forward-line -1) + (forward-char 7) + (greek-input nil)) + ((eq syntax 'node) + (insert "<T ID=\"\" />") + (backward-char 4)) + (t + (message "Cannot start topic here"))))) + +(defun ellinika-begin-comment (arg) + (interactive "p") + (let ((tag (ellinika-find-open-tag))) + (cond + ((or (string-equal tag "M") + (string-equal tag "F")) + (insert "<C></C>") + (backward-char 4)) + (t + (message "Cannot start comment here"))))) + +(defun ellinika-begin-expl (arg) + (interactive "p") + (let ((tag (ellinika-find-open-tag))) + (cond + ((or (string-equal tag "M") + (string-equal tag "F")) + (insert "<E></E>") + (backward-char 4)) + (t + (message "Cannot start explanation here"))))) + +(defun ellinika-insert-include (arg) + (interactive "p") + (beginning-of-line) + (insert "<INCLUDE FILE=\"\" />") + (backward-char 4) + (inactivate-input-method)) ;;;###autoload (define-derived-mode ellinika-dict-mode sgml-mode "Ellinika-Dict" @@ -156,30 +260,19 @@ \\{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 "\C-c\C-b" 'ellinika-begin-node) + (define-key ellinika-dict-mode-map "\C-c\C-m" 'ellinika-begin-article) + (define-key ellinika-dict-mode-map "\C-c\C-k" 'ellinika-begin-key) + (define-key ellinika-dict-mode-map "\C-c\C-p" 'ellinika-begin-pos) + (define-key ellinika-dict-mode-map "\C-c\C-f" 'ellinika-begin-forms) + (define-key ellinika-dict-mode-map "\C-c\C-x" 'ellinika-begin-xref) + (define-key ellinika-dict-mode-map "\C-c\C-a" 'ellinika-begin-ant) + (define-key ellinika-dict-mode-map "\C-c\C-t" 'ellinika-begin-topic) + (define-key ellinika-dict-mode-map "\C-c\C-c" 'ellinika-begin-comment) + (define-key ellinika-dict-mode-map "\C-c\C-e" 'ellinika-begin-expl) + (define-key ellinika-dict-mode-map "\C-c\C-i" 'ellinika-insert-include) + (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) |