author | Oleksandr Gavenko <gavenkoa@gmail.com> |
Thu, 15 Sep 2016 20:13:18 +0300 | |
changeset 558 | 53fd793e345d |
parent 542 | b5197c70972c |
child 563 | e003bfd46c29 |
permissions | -rw-r--r-- |
381
1729e4655e4d
Fix (package-buffer-info) errors: "Package lacks a \"Version\" or \"Package-Version\" header"
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
380
diff
changeset
|
1 |
;;; gadict.el --- major mode for editing gadict dictionary source files -*- lexical-binding: t -*- |
320
4272023569f3
major mode for dict dictionary source files
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
2 |
|
361
6dee73a3e3cb
Basic adaptation to gadict format.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
335
diff
changeset
|
3 |
;; Copyright (C) 2016 by Oleksandr Gavenko <gavenkoa@gmail.com> |
320
4272023569f3
major mode for dict dictionary source files
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
4 |
|
4272023569f3
major mode for dict dictionary source files
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
5 |
;; You can do anything with this file without any warranty. |
4272023569f3
major mode for dict dictionary source files
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
6 |
|
4272023569f3
major mode for dict dictionary source files
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
7 |
;; Author: Oleksandr Gavenko <gavenkoa@gmail.com> |
4272023569f3
major mode for dict dictionary source files
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
8 |
;; Maintainer: Oleksandr Gavenko <gavenkoa@gmail.com> |
361
6dee73a3e3cb
Basic adaptation to gadict format.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
335
diff
changeset
|
9 |
;; Created: 2016 |
381
1729e4655e4d
Fix (package-buffer-info) errors: "Package lacks a \"Version\" or \"Package-Version\" header"
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
380
diff
changeset
|
10 |
;; Version: 0.1 |
320
4272023569f3
major mode for dict dictionary source files
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
11 |
;; Keywords: dict, dictionary |
4272023569f3
major mode for dict dictionary source files
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
12 |
|
4272023569f3
major mode for dict dictionary source files
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
13 |
;;; Commentary: |
4272023569f3
major mode for dict dictionary source files
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
14 |
;; |
510
212d9ff8725c
Mode can be installed by...
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
457
diff
changeset
|
15 |
;; Mode can be installed by: |
212d9ff8725c
Mode can be installed by...
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
457
diff
changeset
|
16 |
;; |
212d9ff8725c
Mode can be installed by...
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
457
diff
changeset
|
17 |
;; (autoload 'gadict-mode "gadict") |
212d9ff8725c
Mode can be installed by...
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
457
diff
changeset
|
18 |
;; |
361
6dee73a3e3cb
Basic adaptation to gadict format.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
335
diff
changeset
|
19 |
;; File association can be registered by: |
6dee73a3e3cb
Basic adaptation to gadict format.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
335
diff
changeset
|
20 |
;; |
6dee73a3e3cb
Basic adaptation to gadict format.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
335
diff
changeset
|
21 |
;; (add-to-list 'auto-mode-alist (cons "\\.gadict$" 'gadict-mode)) |
320
4272023569f3
major mode for dict dictionary source files
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
22 |
|
4272023569f3
major mode for dict dictionary source files
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
23 |
;;; Code: |
4272023569f3
major mode for dict dictionary source files
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
24 |
|
361
6dee73a3e3cb
Basic adaptation to gadict format.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
335
diff
changeset
|
25 |
(defvar gadict-font-lock-keywords |
378
8c629eb20c0b
Highlight other article headers.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
375
diff
changeset
|
26 |
'( ("^\\(__\\)\n\n\\(\\w.*\\)$" (1 font-lock-function-name-face) (2 font-lock-keyword-face)) |
8c629eb20c0b
Highlight other article headers.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
375
diff
changeset
|
27 |
("^ .*\n\\(\\w.*\\)" (1 font-lock-keyword-face)) |
373
51565d9fe630
Highlight comment syntax. Fix uncommenting.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
372
diff
changeset
|
28 |
("^#.*" . font-lock-comment-face) |
362
3d5c70256edf
Added regex to highlight most of gadict syntax.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
361
diff
changeset
|
29 |
("^ +\\[[^]\n]+]" . font-lock-type-face) |
3d5c70256edf
Added regex to highlight most of gadict syntax.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
361
diff
changeset
|
30 |
("^\\(?:en\\|ru\\|uk\\|la\\): " . font-lock-type-face) |
3d5c70256edf
Added regex to highlight most of gadict syntax.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
361
diff
changeset
|
31 |
("^\\(?:en\\|ru\\|uk\\|la\\)> " . font-lock-doc-face) |
3d5c70256edf
Added regex to highlight most of gadict syntax.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
361
diff
changeset
|
32 |
("^\\(?:topic\\|ant\\|syn\\): " . font-lock-doc-face) |
527
0a31299fad70
Add support for country spelling variant.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
510
diff
changeset
|
33 |
("^ +\\(?:v1\\|v2\\|v3\\|s\\|pl\\|male\\|female\\|abbr\\|comp\\|super\\|Am\\|Br\\|Au\\)$" . font-lock-doc-face) |
542
b5197c70972c
Add commonly used contractions.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
527
diff
changeset
|
34 |
("^\\(?:n\\|v\\|adj\\|adv\\|pron\\|prep\\|num\\|conj\\|int\\|phr\\|phr\\.v\\|contr\\|abbr\\|prefix\\)$" . font-lock-type-face) )) |
320
4272023569f3
major mode for dict dictionary source files
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
35 |
|
371
d5d1d3e6d11e
gadict-setup-fontlock
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
370
diff
changeset
|
36 |
(defun gadict-setup-fontlock () |
380
f0e2c538bf85
Add docs to functions to 100% satisfy checkdoc.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
379
diff
changeset
|
37 |
"Setup gadict fontlock." |
371
d5d1d3e6d11e
gadict-setup-fontlock
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
370
diff
changeset
|
38 |
(setq font-lock-defaults |
d5d1d3e6d11e
gadict-setup-fontlock
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
370
diff
changeset
|
39 |
'(gadict-font-lock-keywords |
d5d1d3e6d11e
gadict-setup-fontlock
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
370
diff
changeset
|
40 |
t nil nil nil |
d5d1d3e6d11e
gadict-setup-fontlock
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
370
diff
changeset
|
41 |
(font-lock-multiline . t) )) |
d5d1d3e6d11e
gadict-setup-fontlock
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
370
diff
changeset
|
42 |
(add-hook 'font-lock-extend-region-functions 'gadict-font-lock-extend-region t) ) |
d5d1d3e6d11e
gadict-setup-fontlock
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
370
diff
changeset
|
43 |
|
382
9a596f1366ac
Setup indenting for gdict mode.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
381
diff
changeset
|
44 |
(defun gadict-setup-syntax () |
9a596f1366ac
Setup indenting for gdict mode.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
381
diff
changeset
|
45 |
"Setup gadict characters syntax." |
9a596f1366ac
Setup indenting for gdict mode.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
381
diff
changeset
|
46 |
(modify-syntax-entry ?' "w")) |
9a596f1366ac
Setup indenting for gdict mode.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
381
diff
changeset
|
47 |
|
367
ba263c893207
Rename to gadict-setup-comment
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
366
diff
changeset
|
48 |
(defun gadict-setup-comment () |
380
f0e2c538bf85
Add docs to functions to 100% satisfy checkdoc.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
379
diff
changeset
|
49 |
"Setup gadict comment commands." |
370
04caf7b9657c
Use same code for setting local variables.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
369
diff
changeset
|
50 |
(set (make-local-variable 'comment-start) "#") |
04caf7b9657c
Use same code for setting local variables.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
369
diff
changeset
|
51 |
(set (make-local-variable 'comment-continue) nil) |
04caf7b9657c
Use same code for setting local variables.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
369
diff
changeset
|
52 |
(set (make-local-variable 'comment-end) "") |
04caf7b9657c
Use same code for setting local variables.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
369
diff
changeset
|
53 |
(set (make-local-variable 'comment-end-skip) nil) |
04caf7b9657c
Use same code for setting local variables.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
369
diff
changeset
|
54 |
(set (make-local-variable 'comment-multi-line) nil) |
373
51565d9fe630
Highlight comment syntax. Fix uncommenting.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
372
diff
changeset
|
55 |
(set (make-local-variable 'comment-use-syntax) nil) ) |
365
86acae5bd220
gadict-setup-comment-style
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
362
diff
changeset
|
56 |
|
368
9c6515663b38
Define paragraph/page break at "__" delimiter.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
367
diff
changeset
|
57 |
(defun gadict-setup-paragraph () |
380
f0e2c538bf85
Add docs to functions to 100% satisfy checkdoc.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
379
diff
changeset
|
58 |
"Setup gadict paragraph definition." |
370
04caf7b9657c
Use same code for setting local variables.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
369
diff
changeset
|
59 |
(set (make-local-variable 'paragraph-separate) "__$") |
04caf7b9657c
Use same code for setting local variables.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
369
diff
changeset
|
60 |
(set (make-local-variable 'paragraph-start) "__$") ) |
368
9c6515663b38
Define paragraph/page break at "__" delimiter.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
367
diff
changeset
|
61 |
|
9c6515663b38
Define paragraph/page break at "__" delimiter.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
367
diff
changeset
|
62 |
(defun gadict-setup-page () |
380
f0e2c538bf85
Add docs to functions to 100% satisfy checkdoc.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
379
diff
changeset
|
63 |
"Setup gadict page definition." |
370
04caf7b9657c
Use same code for setting local variables.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
369
diff
changeset
|
64 |
(set (make-local-variable 'page-delimiter) "__$") ) |
368
9c6515663b38
Define paragraph/page break at "__" delimiter.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
367
diff
changeset
|
65 |
|
382
9a596f1366ac
Setup indenting for gdict mode.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
381
diff
changeset
|
66 |
(defvar gadict-indent-offset 2 |
9a596f1366ac
Setup indenting for gdict mode.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
381
diff
changeset
|
67 |
"Indent level.") |
9a596f1366ac
Setup indenting for gdict mode.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
381
diff
changeset
|
68 |
|
9a596f1366ac
Setup indenting for gdict mode.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
381
diff
changeset
|
69 |
(defun gadict-indent-line () |
9a596f1366ac
Setup indenting for gdict mode.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
381
diff
changeset
|
70 |
"Indent line in gdict mode." |
390
7783ce39023d
Fix: Warning: Unused lexical variable `indent'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
382
diff
changeset
|
71 |
(if (eq (current-indentation) gadict-indent-offset) |
382
9a596f1366ac
Setup indenting for gdict mode.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
381
diff
changeset
|
72 |
(indent-line-to 0) |
390
7783ce39023d
Fix: Warning: Unused lexical variable `indent'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
382
diff
changeset
|
73 |
(indent-line-to gadict-indent-offset))) |
382
9a596f1366ac
Setup indenting for gdict mode.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
381
diff
changeset
|
74 |
|
9a596f1366ac
Setup indenting for gdict mode.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
381
diff
changeset
|
75 |
(defun gadict-setup-indent () |
9a596f1366ac
Setup indenting for gdict mode.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
381
diff
changeset
|
76 |
"Setup indenting for gdict mode." |
9a596f1366ac
Setup indenting for gdict mode.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
381
diff
changeset
|
77 |
(set (make-local-variable 'indent-line-function) 'gadict-indent-line)) |
369 | 78 |
|
374
aeaa3f721014
Add expand-region support.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
373
diff
changeset
|
79 |
(defun gadict-mark-article () |
380
f0e2c538bf85
Add docs to functions to 100% satisfy checkdoc.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
379
diff
changeset
|
80 |
"Mark current article." |
374
aeaa3f721014
Add expand-region support.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
373
diff
changeset
|
81 |
(end-of-line) |
aeaa3f721014
Add expand-region support.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
373
diff
changeset
|
82 |
(re-search-backward "^__$") |
aeaa3f721014
Add expand-region support.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
373
diff
changeset
|
83 |
(set-mark (point)) |
aeaa3f721014
Add expand-region support.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
373
diff
changeset
|
84 |
(forward-line) |
aeaa3f721014
Add expand-region support.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
373
diff
changeset
|
85 |
(if (re-search-forward "^__$" nil t) |
aeaa3f721014
Add expand-region support.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
373
diff
changeset
|
86 |
(forward-line 0) |
aeaa3f721014
Add expand-region support.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
373
diff
changeset
|
87 |
(goto-char (point-max))) |
aeaa3f721014
Add expand-region support.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
373
diff
changeset
|
88 |
(exchange-point-and-mark)) |
aeaa3f721014
Add expand-region support.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
373
diff
changeset
|
89 |
|
391
68d510b25621
Fix: Warning: assignment to free variable `er/try-expand-list'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
390
diff
changeset
|
90 |
(defvar er/try-expand-list) |
374
aeaa3f721014
Add expand-region support.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
373
diff
changeset
|
91 |
(defun gadict-setup-expansions () |
375
a2ec98ead57a
Fix warning from M-x checkdoc. Add lexical-binding: t.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
374
diff
changeset
|
92 |
"Add `gadict-mode' specific expansions." |
374
aeaa3f721014
Add expand-region support.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
373
diff
changeset
|
93 |
(set (make-local-variable 'er/try-expand-list) (list #'gadict-mark-article))) |
aeaa3f721014
Add expand-region support.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
373
diff
changeset
|
94 |
|
395 | 95 |
(defvar font-lock-beg) |
96 |
(defvar font-lock-end) |
|
361
6dee73a3e3cb
Basic adaptation to gadict format.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
335
diff
changeset
|
97 |
(defun gadict-font-lock-extend-region () |
6dee73a3e3cb
Basic adaptation to gadict format.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
335
diff
changeset
|
98 |
"Look for '__' expression and extend `font-lock-beg' and `font-lock-end'." |
329
410c26a389a6
Fix highlighting near beginning and end of buffer.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
328
diff
changeset
|
99 |
;; (message "%d:%d, %d lines" font-lock-beg font-lock-end (count-lines font-lock-beg font-lock-end)) |
328
80146b5ba6e6
Fix infinite invocation of 'dict-c5-font-lock-extend-region' by guarding condition.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
327
diff
changeset
|
100 |
(cond |
80146b5ba6e6
Fix infinite invocation of 'dict-c5-font-lock-extend-region' by guarding condition.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
327
diff
changeset
|
101 |
((and |
80146b5ba6e6
Fix infinite invocation of 'dict-c5-font-lock-extend-region' by guarding condition.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
327
diff
changeset
|
102 |
(< (count-lines font-lock-beg font-lock-end) 5) |
329
410c26a389a6
Fix highlighting near beginning and end of buffer.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
328
diff
changeset
|
103 |
(not (and (<= (point-max) font-lock-end) (<= font-lock-beg (point-min)) ))) |
325
e64b740278c5
Finally fix multiline highlighting.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
324
diff
changeset
|
104 |
(save-excursion |
e64b740278c5
Finally fix multiline highlighting.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
324
diff
changeset
|
105 |
(goto-char font-lock-beg) |
e64b740278c5
Finally fix multiline highlighting.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
324
diff
changeset
|
106 |
(forward-line -2) |
328
80146b5ba6e6
Fix infinite invocation of 'dict-c5-font-lock-extend-region' by guarding condition.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
327
diff
changeset
|
107 |
(setq font-lock-beg (point)) |
80146b5ba6e6
Fix infinite invocation of 'dict-c5-font-lock-extend-region' by guarding condition.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
327
diff
changeset
|
108 |
(goto-char font-lock-end) |
80146b5ba6e6
Fix infinite invocation of 'dict-c5-font-lock-extend-region' by guarding condition.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
327
diff
changeset
|
109 |
(forward-line 3) |
80146b5ba6e6
Fix infinite invocation of 'dict-c5-font-lock-extend-region' by guarding condition.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
327
diff
changeset
|
110 |
(setq font-lock-end (point)) |
327
21124e46bf6e
Return non-nil if region was adjusted.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
326
diff
changeset
|
111 |
) |
328
80146b5ba6e6
Fix infinite invocation of 'dict-c5-font-lock-extend-region' by guarding condition.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
327
diff
changeset
|
112 |
t) |
361
6dee73a3e3cb
Basic adaptation to gadict format.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
335
diff
changeset
|
113 |
(t nil) )) |
325
e64b740278c5
Finally fix multiline highlighting.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
324
diff
changeset
|
114 |
|
372
e14e384267ee
Article template automatically insert translation tags.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
371
diff
changeset
|
115 |
(defvar-local gadict-tr nil |
e14e384267ee
Article template automatically insert translation tags.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
371
diff
changeset
|
116 |
"Translation markers as string separated by comma. Define own |
e14e384267ee
Article template automatically insert translation tags.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
371
diff
changeset
|
117 |
values in .dir-local.el or as -*- gadict-tr: \"...\" -*- file prelude") |
379
c336b3ebd9df
Mark gadict-tr as safe variable.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
378
diff
changeset
|
118 |
(put 'gadict-tr 'safe-local-variable 'string-or-null-p) |
372
e14e384267ee
Article template automatically insert translation tags.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
371
diff
changeset
|
119 |
|
398
54ef571cf72a
Function to maintain articles in headword lexical order.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
395
diff
changeset
|
120 |
(defun gadict-insert-template (&optional headword) |
54ef571cf72a
Function to maintain articles in headword lexical order.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
395
diff
changeset
|
121 |
"Insert new article template after the current place." |
335 | 122 |
(interactive) |
361
6dee73a3e3cb
Basic adaptation to gadict format.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
335
diff
changeset
|
123 |
(if (re-search-forward "^__" nil t) |
335 | 124 |
(beginning-of-line) |
125 |
(goto-char (point-max))) |
|
126 |
(while (eq (char-before) ?\n) |
|
375
a2ec98ead57a
Fix warning from M-x checkdoc. Add lexical-binding: t.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
374
diff
changeset
|
127 |
(delete-char -1)) |
335 | 128 |
(insert-char ?\n) |
361
6dee73a3e3cb
Basic adaptation to gadict format.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
335
diff
changeset
|
129 |
(insert-char ?_ 2) |
335 | 130 |
(insert-char ?\n 3) |
372
e14e384267ee
Article template automatically insert translation tags.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
371
diff
changeset
|
131 |
(when (stringp gadict-tr) |
e14e384267ee
Article template automatically insert translation tags.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
371
diff
changeset
|
132 |
(mapc (lambda (tr) |
e14e384267ee
Article template automatically insert translation tags.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
371
diff
changeset
|
133 |
(insert-char ?\n) |
e14e384267ee
Article template automatically insert translation tags.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
371
diff
changeset
|
134 |
(insert tr) |
e14e384267ee
Article template automatically insert translation tags.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
371
diff
changeset
|
135 |
(insert ": ")) |
e14e384267ee
Article template automatically insert translation tags.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
371
diff
changeset
|
136 |
(split-string gadict-tr ",")) |
e14e384267ee
Article template automatically insert translation tags.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
371
diff
changeset
|
137 |
(insert-char ?\n) |
e14e384267ee
Article template automatically insert translation tags.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
371
diff
changeset
|
138 |
(re-search-backward "^$")) |
398
54ef571cf72a
Function to maintain articles in headword lexical order.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
395
diff
changeset
|
139 |
(backward-char) |
423
6a772e1fc63d
Add bracket for pronunciation if headword is provided. Recenter point for best view.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
420
diff
changeset
|
140 |
(when headword |
6a772e1fc63d
Add bracket for pronunciation if headword is provided. Recenter point for best view.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
420
diff
changeset
|
141 |
(insert headword) |
6a772e1fc63d
Add bracket for pronunciation if headword is provided. Recenter point for best view.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
420
diff
changeset
|
142 |
(insert "\n []") |
435
ca2c73d8698f
Recenter also if article is found.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
423
diff
changeset
|
143 |
(backward-char))) |
398
54ef571cf72a
Function to maintain articles in headword lexical order.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
395
diff
changeset
|
144 |
|
54ef571cf72a
Function to maintain articles in headword lexical order.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
395
diff
changeset
|
145 |
(defun gadict-search-floor (headword) |
440
fb584cf490db
Fix: very first word inserted in second position, should at first.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
435
diff
changeset
|
146 |
"Move to HEADWORD definition or place on posiiton for new corresponding |
fb584cf490db
Fix: very first word inserted in second position, should at first.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
435
diff
changeset
|
147 |
definition. Check for headwords ordering during search. |
398
54ef571cf72a
Function to maintain articles in headword lexical order.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
395
diff
changeset
|
148 |
|
54ef571cf72a
Function to maintain articles in headword lexical order.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
395
diff
changeset
|
149 |
Return `t' if definition found, `nil' if no such headword." |
54ef571cf72a
Function to maintain articles in headword lexical order.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
395
diff
changeset
|
150 |
(let ( prev curr ) |
54ef571cf72a
Function to maintain articles in headword lexical order.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
395
diff
changeset
|
151 |
(catch 'exit |
54ef571cf72a
Function to maintain articles in headword lexical order.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
395
diff
changeset
|
152 |
(goto-char (point-min)) |
54ef571cf72a
Function to maintain articles in headword lexical order.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
395
diff
changeset
|
153 |
(unless (re-search-forward "^__$" nil t) |
54ef571cf72a
Function to maintain articles in headword lexical order.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
395
diff
changeset
|
154 |
(throw 'exit nil)) |
54ef571cf72a
Function to maintain articles in headword lexical order.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
395
diff
changeset
|
155 |
(forward-line 2) |
54ef571cf72a
Function to maintain articles in headword lexical order.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
395
diff
changeset
|
156 |
(setq prev (buffer-substring-no-properties (point) (line-end-position))) |
54ef571cf72a
Function to maintain articles in headword lexical order.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
395
diff
changeset
|
157 |
(when (string= headword prev) |
54ef571cf72a
Function to maintain articles in headword lexical order.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
395
diff
changeset
|
158 |
(throw 'exit t)) |
54ef571cf72a
Function to maintain articles in headword lexical order.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
395
diff
changeset
|
159 |
(when (string< headword prev) |
440
fb584cf490db
Fix: very first word inserted in second position, should at first.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
435
diff
changeset
|
160 |
(goto-char (point-min)) |
398
54ef571cf72a
Function to maintain articles in headword lexical order.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
395
diff
changeset
|
161 |
(throw 'exit nil)) |
54ef571cf72a
Function to maintain articles in headword lexical order.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
395
diff
changeset
|
162 |
(while t |
54ef571cf72a
Function to maintain articles in headword lexical order.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
395
diff
changeset
|
163 |
(unless (re-search-forward "^__$" nil t) |
54ef571cf72a
Function to maintain articles in headword lexical order.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
395
diff
changeset
|
164 |
(throw 'exit nil)) |
54ef571cf72a
Function to maintain articles in headword lexical order.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
395
diff
changeset
|
165 |
(forward-line 2) |
54ef571cf72a
Function to maintain articles in headword lexical order.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
395
diff
changeset
|
166 |
(setq curr (buffer-substring-no-properties (point) (line-end-position))) |
54ef571cf72a
Function to maintain articles in headword lexical order.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
395
diff
changeset
|
167 |
(unless (string< prev curr) |
54ef571cf72a
Function to maintain articles in headword lexical order.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
395
diff
changeset
|
168 |
(error (format "%s < %s" curr prev))) |
54ef571cf72a
Function to maintain articles in headword lexical order.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
395
diff
changeset
|
169 |
(when (string= headword curr) |
54ef571cf72a
Function to maintain articles in headword lexical order.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
395
diff
changeset
|
170 |
(throw 'exit t)) |
54ef571cf72a
Function to maintain articles in headword lexical order.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
395
diff
changeset
|
171 |
(when (string< headword curr) |
54ef571cf72a
Function to maintain articles in headword lexical order.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
395
diff
changeset
|
172 |
(forward-line -2) |
54ef571cf72a
Function to maintain articles in headword lexical order.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
395
diff
changeset
|
173 |
(re-search-backward "^__$") |
54ef571cf72a
Function to maintain articles in headword lexical order.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
395
diff
changeset
|
174 |
(forward-line 2) |
54ef571cf72a
Function to maintain articles in headword lexical order.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
395
diff
changeset
|
175 |
(throw 'exit nil)) |
54ef571cf72a
Function to maintain articles in headword lexical order.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
395
diff
changeset
|
176 |
(setq prev curr)) ))) |
54ef571cf72a
Function to maintain articles in headword lexical order.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
395
diff
changeset
|
177 |
|
448
a61c140a4b6f
Recenter screen to article on search request.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
444
diff
changeset
|
178 |
(defun gadict-search (headword) |
a61c140a4b6f
Recenter screen to article on search request.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
444
diff
changeset
|
179 |
"Move to HEADWORD definition or place on posiiton for new corresponding |
a61c140a4b6f
Recenter screen to article on search request.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
444
diff
changeset
|
180 |
definition. Check for headwords ordering during search." |
a61c140a4b6f
Recenter screen to article on search request.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
444
diff
changeset
|
181 |
(interactive (list (read-string "Headword: "))) |
a61c140a4b6f
Recenter screen to article on search request.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
444
diff
changeset
|
182 |
(gadict-search-floor headword) |
453
ad2b19c9d05d
Fix: "recenter-top-bottom" => "recenter" to place view point at center of
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
448
diff
changeset
|
183 |
(recenter)) |
448
a61c140a4b6f
Recenter screen to article on search request.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
444
diff
changeset
|
184 |
|
398
54ef571cf72a
Function to maintain articles in headword lexical order.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
395
diff
changeset
|
185 |
(defun gadict-insert-template-in-order (headword) |
54ef571cf72a
Function to maintain articles in headword lexical order.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
395
diff
changeset
|
186 |
"Insert new article template with respect of headword order." |
54ef571cf72a
Function to maintain articles in headword lexical order.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
395
diff
changeset
|
187 |
(interactive (list (read-string "Headword: "))) |
54ef571cf72a
Function to maintain articles in headword lexical order.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
395
diff
changeset
|
188 |
(unless (gadict-search-floor headword) |
435
ca2c73d8698f
Recenter also if article is found.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
423
diff
changeset
|
189 |
(gadict-insert-template headword)) |
453
ad2b19c9d05d
Fix: "recenter-top-bottom" => "recenter" to place view point at center of
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
448
diff
changeset
|
190 |
(recenter)) |
335 | 191 |
|
366 | 192 |
(defun gadict-setup-keymap () |
380
f0e2c538bf85
Add docs to functions to 100% satisfy checkdoc.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
379
diff
changeset
|
193 |
"Setup gadict keymap." |
448
a61c140a4b6f
Recenter screen to article on search request.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
444
diff
changeset
|
194 |
(define-key (current-local-map) [S-return] 'gadict-search) |
398
54ef571cf72a
Function to maintain articles in headword lexical order.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
395
diff
changeset
|
195 |
(define-key (current-local-map) [C-return] 'gadict-insert-template-in-order)) |
335 | 196 |
|
320
4272023569f3
major mode for dict dictionary source files
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
197 |
;;;###autoload |
361
6dee73a3e3cb
Basic adaptation to gadict format.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
335
diff
changeset
|
198 |
(define-derived-mode gadict-mode fundamental-mode "gadict" |
6dee73a3e3cb
Basic adaptation to gadict format.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
335
diff
changeset
|
199 |
"Derived mode for editing gadict dictionary source files." |
371
d5d1d3e6d11e
gadict-setup-fontlock
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
370
diff
changeset
|
200 |
(gadict-setup-fontlock) |
366 | 201 |
(gadict-setup-keymap) |
369 | 202 |
(gadict-setup-syntax) |
368
9c6515663b38
Define paragraph/page break at "__" delimiter.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
367
diff
changeset
|
203 |
(gadict-setup-paragraph) |
9c6515663b38
Define paragraph/page break at "__" delimiter.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
367
diff
changeset
|
204 |
(gadict-setup-page) |
374
aeaa3f721014
Add expand-region support.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
373
diff
changeset
|
205 |
(gadict-setup-comment) |
382
9a596f1366ac
Setup indenting for gdict mode.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
381
diff
changeset
|
206 |
(gadict-setup-indent) |
374
aeaa3f721014
Add expand-region support.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
373
diff
changeset
|
207 |
(gadict-setup-expansions) ) |
361
6dee73a3e3cb
Basic adaptation to gadict format.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
335
diff
changeset
|
208 |
|
6dee73a3e3cb
Basic adaptation to gadict format.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
335
diff
changeset
|
209 |
(provide 'gadict) |
320
4272023569f3
major mode for dict dictionary source files
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
210 |
|
4272023569f3
major mode for dict dictionary source files
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
211 |
;;; dict-mode.el ends here |
375
a2ec98ead57a
Fix warning from M-x checkdoc. Add lexical-binding: t.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
374
diff
changeset
|
212 |
|
a2ec98ead57a
Fix warning from M-x checkdoc. Add lexical-binding: t.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
374
diff
changeset
|
213 |
(provide 'gadict) |
a2ec98ead57a
Fix warning from M-x checkdoc. Add lexical-binding: t.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
374
diff
changeset
|
214 |
|
a2ec98ead57a
Fix warning from M-x checkdoc. Add lexical-binding: t.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
374
diff
changeset
|
215 |
;;; gadict.el ends here |