From 1b7f3c080397368a5710a4507fd95cc9eb4a29c8 Mon Sep 17 00:00:00 2001 From: Sergey Poznyakoff Date: Thu, 14 Oct 2004 16:07:09 +0000 Subject: Heavily modified git-svn-id: file:///home/puszcza/svnroot/ellinika/trunk@242 941c8c0f-9102-463b-b60b-cd22ce0e6858 --- elisp/ellinika-dict-mode.el | 283 +++++++++++++++++++++++++++++--------------- 1 file 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 "") - '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))) + (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 "") + (throw 'loop 'node)) + ((or (looking-at "") (looking-at "")) + (throw 'loop 'initial)) + ((looking-at "") + (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 "]+\\(\\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 @@ -139,14 +120,137 @@ (ellinika-select-input-method)) (defun ellinika-close-tag (arg) + (interactive "p") + (let ((tag (ellinika-find-open-tag))) + (cond + (tag + (insert (concat "")) + (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 "\n \n") + (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 ">") + (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-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 "\n") + (forward-line -1) + (forward-char 7) + (greek-input nil)) + ((eq syntax 'node) + (insert "") + (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 "") + (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 "") + (backward-char 4)) + (t + (message "Cannot start explanation here"))))) + +(defun ellinika-insert-include (arg) + (interactive "p") + (beginning-of-line) + (insert "") + (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-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 "\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) -- cgit v1.2.1