# HG changeset patch # User Oleksandr Gavenko # Date 1478717688 -7200 # Node ID fa97354a56d3ec8ac1daea55fd77be4d673ddaa7 # Parent 08417d7454ec324c5759abd38a83cfaa7cc92356 Insert translation template with using value of `gadict-tr'. diff -r 08417d7454ec -r fa97354a56d3 contrib/gadict.el --- a/contrib/gadict.el Wed Nov 09 12:45:30 2016 +0200 +++ b/contrib/gadict.el Wed Nov 09 20:54:48 2016 +0200 @@ -22,10 +22,13 @@ ;;; Code: +(defconst gadict--pos '("n" "v" "adj" "adv" "pron" "prep" "num" "conj" "int" "phr" "phr.v" "contr" "abbr" "prefix") + "Defined parts of speech.") + (defconst gadict--art-lang-regex (regexp-opt '("en" "ru" "uk" "la"))) (defconst gadict--art-rel-regex (regexp-opt '("ant" "syn" "rel" "topic" "hyper" "hypo"))) (defconst gadict--art-var-regex (regexp-opt '("rare" "v1" "v2" "v3" "s" "pl" "male" "female" "abbr" "comp" "super" "Am" "Br" "Au"))) -(defconst gadict--art-pos-regex (regexp-opt '("n" "v" "adj" "adv" "pron" "prep" "num" "conj" "int" "phr" "phr.v" "contr" "abbr" "prefix"))) +(defconst gadict--art-pos-regex (regexp-opt gadict--pos)) (defgroup gadict nil "gadict-mode customization." @@ -210,9 +213,41 @@ (gadict-insert-template headword)) (recenter)) +(defun gadict--find-headword-end () + (save-excursion + (end-of-line) + (re-search-backward "^__$") + (re-search-forward "^$") + (forward-char) + (re-search-forward "^$") + (point))) + +(defun gadict-insert-translation (pos) + "Insert translation template with using value of `gadict-tr'." + (interactive (list (completing-read "POS: " gadict--pos nil t))) + (let ( (headword-end (gadict--find-headword-end)) ) + (if (< (point) headword-end) + (goto-char headword-end) + (re-search-forward "^\\(?:\\|__\\)$") + (when (eq (char-before) ?_) + (beginning-of-line) + ;; (newline) + ;; (backward-char) + )) + (insert-char ?\n) + (insert pos) + (insert-char ?\n) + (save-excursion + (mapc (lambda (lang) + (insert lang) + (insert ": \n")) + (split-string gadict-tr ","))) + (end-of-line) )) + (defun gadict-setup-keymap () "Setup gadict keymap." - (define-key (current-local-map) [S-return] 'gadict-search) + (define-key (current-local-map) [M-return] 'gadict-search) + (define-key (current-local-map) [S-return] 'gadict-insert-translation) (define-key (current-local-map) [C-return] 'gadict-insert-template-in-order)) ;;;###autoload