20 ;; |
20 ;; |
21 ;; (add-to-list 'auto-mode-alist (cons "\\.gadict$" 'gadict-mode)) |
21 ;; (add-to-list 'auto-mode-alist (cons "\\.gadict$" 'gadict-mode)) |
22 |
22 |
23 ;;; Code: |
23 ;;; Code: |
24 |
24 |
|
25 (defconst gadict--pos '("n" "v" "adj" "adv" "pron" "prep" "num" "conj" "int" "phr" "phr.v" "contr" "abbr" "prefix") |
|
26 "Defined parts of speech.") |
|
27 |
25 (defconst gadict--art-lang-regex (regexp-opt '("en" "ru" "uk" "la"))) |
28 (defconst gadict--art-lang-regex (regexp-opt '("en" "ru" "uk" "la"))) |
26 (defconst gadict--art-rel-regex (regexp-opt '("ant" "syn" "rel" "topic" "hyper" "hypo"))) |
29 (defconst gadict--art-rel-regex (regexp-opt '("ant" "syn" "rel" "topic" "hyper" "hypo"))) |
27 (defconst gadict--art-var-regex (regexp-opt '("rare" "v1" "v2" "v3" "s" "pl" "male" "female" "abbr" "comp" "super" "Am" "Br" "Au"))) |
30 (defconst gadict--art-var-regex (regexp-opt '("rare" "v1" "v2" "v3" "s" "pl" "male" "female" "abbr" "comp" "super" "Am" "Br" "Au"))) |
28 (defconst gadict--art-pos-regex (regexp-opt '("n" "v" "adj" "adv" "pron" "prep" "num" "conj" "int" "phr" "phr.v" "contr" "abbr" "prefix"))) |
31 (defconst gadict--art-pos-regex (regexp-opt gadict--pos)) |
29 |
32 |
30 (defgroup gadict nil |
33 (defgroup gadict nil |
31 "gadict-mode customization." |
34 "gadict-mode customization." |
32 :group 'wp) |
35 :group 'wp) |
33 |
36 |
208 (interactive (list (read-string "Headword: "))) |
211 (interactive (list (read-string "Headword: "))) |
209 (unless (gadict-search-floor headword) |
212 (unless (gadict-search-floor headword) |
210 (gadict-insert-template headword)) |
213 (gadict-insert-template headword)) |
211 (recenter)) |
214 (recenter)) |
212 |
215 |
|
216 (defun gadict--find-headword-end () |
|
217 (save-excursion |
|
218 (end-of-line) |
|
219 (re-search-backward "^__$") |
|
220 (re-search-forward "^$") |
|
221 (forward-char) |
|
222 (re-search-forward "^$") |
|
223 (point))) |
|
224 |
|
225 (defun gadict-insert-translation (pos) |
|
226 "Insert translation template with using value of `gadict-tr'." |
|
227 (interactive (list (completing-read "POS: " gadict--pos nil t))) |
|
228 (let ( (headword-end (gadict--find-headword-end)) ) |
|
229 (if (< (point) headword-end) |
|
230 (goto-char headword-end) |
|
231 (re-search-forward "^\\(?:\\|__\\)$") |
|
232 (when (eq (char-before) ?_) |
|
233 (beginning-of-line) |
|
234 ;; (newline) |
|
235 ;; (backward-char) |
|
236 )) |
|
237 (insert-char ?\n) |
|
238 (insert pos) |
|
239 (insert-char ?\n) |
|
240 (save-excursion |
|
241 (mapc (lambda (lang) |
|
242 (insert lang) |
|
243 (insert ": \n")) |
|
244 (split-string gadict-tr ","))) |
|
245 (end-of-line) )) |
|
246 |
213 (defun gadict-setup-keymap () |
247 (defun gadict-setup-keymap () |
214 "Setup gadict keymap." |
248 "Setup gadict keymap." |
215 (define-key (current-local-map) [S-return] 'gadict-search) |
249 (define-key (current-local-map) [M-return] 'gadict-search) |
|
250 (define-key (current-local-map) [S-return] 'gadict-insert-translation) |
216 (define-key (current-local-map) [C-return] 'gadict-insert-template-in-order)) |
251 (define-key (current-local-map) [C-return] 'gadict-insert-template-in-order)) |
217 |
252 |
218 ;;;###autoload |
253 ;;;###autoload |
219 (define-derived-mode gadict-mode fundamental-mode "gadict" |
254 (define-derived-mode gadict-mode fundamental-mode "gadict" |
220 "Derived mode for editing gadict dictionary source files." |
255 "Derived mode for editing gadict dictionary source files." |