author | Oleksandr Gavenko <gavenkoa@gmail.com> |
Thu, 20 Dec 2012 23:42:25 +0200 | |
changeset 1013 | e88896e74332 |
parent 907 | 8a6c364061e2 |
child 1243 | 10a201706f1c |
permissions | -rw-r--r-- |
690
90d155b82954
major mode for dict dictionary source files
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
1 |
;;; dict-mode.el --- major mode for dict dictionary source files |
90d155b82954
major mode for dict dictionary source files
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
2 |
|
90d155b82954
major mode for dict dictionary source files
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
3 |
;; Copyright (C) 2011 by Oleksandr Gavenko <gavenkoa@gmail.com> |
90d155b82954
major mode for dict dictionary source files
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
4 |
|
90d155b82954
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. |
90d155b82954
major mode for dict dictionary source files
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
6 |
|
90d155b82954
major mode for dict dictionary source files
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
7 |
;; Author: Oleksandr Gavenko <gavenkoa@gmail.com> |
90d155b82954
major mode for dict dictionary source files
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
8 |
;; Maintainer: Oleksandr Gavenko <gavenkoa@gmail.com> |
90d155b82954
major mode for dict dictionary source files
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
9 |
;; Created: 2011-09-04 |
90d155b82954
major mode for dict dictionary source files
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
10 |
;; Version: 0.1 |
90d155b82954
major mode for dict dictionary source files
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
11 |
;; Keywords: dict, dictionary |
90d155b82954
major mode for dict dictionary source files
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
12 |
|
90d155b82954
major mode for dict dictionary source files
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
13 |
;;; Commentary: |
90d155b82954
major mode for dict dictionary source files
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
14 |
;; |
90d155b82954
major mode for dict dictionary source files
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
15 |
;; Very pure release. |
90d155b82954
major mode for dict dictionary source files
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
16 |
|
90d155b82954
major mode for dict dictionary source files
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
17 |
;;; Code: |
90d155b82954
major mode for dict dictionary source files
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
18 |
|
90d155b82954
major mode for dict dictionary source files
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
19 |
(setq dict-c5-mode-map (make-sparse-keymap)) |
90d155b82954
major mode for dict dictionary source files
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
20 |
;; (define-key dict-c5-mode-map (kbd "RET") 'my-xxx) |
90d155b82954
major mode for dict dictionary source files
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
21 |
|
848
8125f4d8b6d4
Rewrite code to use 'define-derived-mode'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
846
diff
changeset
|
22 |
(defvar dict-c5-font-lock-keywords |
855 | 23 |
'( |
24 |
("^\\(_\\{5,\\}\\)\n\n\\(\\w.*\\)$" |
|
25 |
(1 font-lock-function-name-face) (2 font-lock-keyword-face)) |
|
859
0d89e5e07baa
Remove newline from allowed transcription chars.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
855
diff
changeset
|
26 |
("\\[[^]\n]+]" . font-lock-type-face) |
855 | 27 |
)) |
690
90d155b82954
major mode for dict dictionary source files
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
28 |
|
849
c34dc5f47510
Finally fix multiline highlighting.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
848
diff
changeset
|
29 |
(defun dict-c5-font-lock-extend-region () |
850 | 30 |
"Look for '_____' expression and extend `font-lock-beg' and `font-lock-end'." |
853
626114dd8100
Fix highlighting near beginning and end of buffer.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
852
diff
changeset
|
31 |
;; (message "%d:%d, %d lines" font-lock-beg font-lock-end (count-lines font-lock-beg font-lock-end)) |
852
571e98c6d3c2
Fix infinite invocation of 'dict-c5-font-lock-extend-region' by guarding condition.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
851
diff
changeset
|
32 |
(cond |
571e98c6d3c2
Fix infinite invocation of 'dict-c5-font-lock-extend-region' by guarding condition.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
851
diff
changeset
|
33 |
((and |
571e98c6d3c2
Fix infinite invocation of 'dict-c5-font-lock-extend-region' by guarding condition.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
851
diff
changeset
|
34 |
(< (count-lines font-lock-beg font-lock-end) 5) |
853
626114dd8100
Fix highlighting near beginning and end of buffer.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
852
diff
changeset
|
35 |
(not (and (<= (point-max) font-lock-end) (<= font-lock-beg (point-min)) ))) |
849
c34dc5f47510
Finally fix multiline highlighting.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
848
diff
changeset
|
36 |
(save-excursion |
c34dc5f47510
Finally fix multiline highlighting.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
848
diff
changeset
|
37 |
(goto-char font-lock-beg) |
c34dc5f47510
Finally fix multiline highlighting.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
848
diff
changeset
|
38 |
(forward-line -2) |
852
571e98c6d3c2
Fix infinite invocation of 'dict-c5-font-lock-extend-region' by guarding condition.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
851
diff
changeset
|
39 |
(setq font-lock-beg (point)) |
571e98c6d3c2
Fix infinite invocation of 'dict-c5-font-lock-extend-region' by guarding condition.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
851
diff
changeset
|
40 |
(goto-char font-lock-end) |
571e98c6d3c2
Fix infinite invocation of 'dict-c5-font-lock-extend-region' by guarding condition.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
851
diff
changeset
|
41 |
(forward-line 3) |
571e98c6d3c2
Fix infinite invocation of 'dict-c5-font-lock-extend-region' by guarding condition.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
851
diff
changeset
|
42 |
(setq font-lock-end (point)) |
851
1c6bb299d28b
Return non-nil if region was adjusted.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
850
diff
changeset
|
43 |
) |
852
571e98c6d3c2
Fix infinite invocation of 'dict-c5-font-lock-extend-region' by guarding condition.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
851
diff
changeset
|
44 |
t) |
571e98c6d3c2
Fix infinite invocation of 'dict-c5-font-lock-extend-region' by guarding condition.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
851
diff
changeset
|
45 |
(t nil) |
571e98c6d3c2
Fix infinite invocation of 'dict-c5-font-lock-extend-region' by guarding condition.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
851
diff
changeset
|
46 |
)) |
849
c34dc5f47510
Finally fix multiline highlighting.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
848
diff
changeset
|
47 |
|
690
90d155b82954
major mode for dict dictionary source files
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
48 |
;;;###autoload |
848
8125f4d8b6d4
Rewrite code to use 'define-derived-mode'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
846
diff
changeset
|
49 |
(define-derived-mode dict-c5-mode fundamental-mode "Dict-c5" |
8125f4d8b6d4
Rewrite code to use 'define-derived-mode'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
846
diff
changeset
|
50 |
"Derived mode for editing C5 dictd source file." |
8125f4d8b6d4
Rewrite code to use 'define-derived-mode'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
846
diff
changeset
|
51 |
(add-to-list 'auto-mode-alist (cons "\\.dict-c5$" 'dict-c5-mode)) |
8125f4d8b6d4
Rewrite code to use 'define-derived-mode'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
846
diff
changeset
|
52 |
(setq font-lock-defaults |
8125f4d8b6d4
Rewrite code to use 'define-derived-mode'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
846
diff
changeset
|
53 |
'(dict-c5-font-lock-keywords |
8125f4d8b6d4
Rewrite code to use 'define-derived-mode'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
846
diff
changeset
|
54 |
t nil nil nil |
8125f4d8b6d4
Rewrite code to use 'define-derived-mode'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
846
diff
changeset
|
55 |
(font-lock-multiline . t) |
8125f4d8b6d4
Rewrite code to use 'define-derived-mode'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
846
diff
changeset
|
56 |
)) |
8125f4d8b6d4
Rewrite code to use 'define-derived-mode'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
846
diff
changeset
|
57 |
(use-local-map dict-c5-mode-map) |
8125f4d8b6d4
Rewrite code to use 'define-derived-mode'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
846
diff
changeset
|
58 |
(modify-syntax-entry ?' ".") |
8125f4d8b6d4
Rewrite code to use 'define-derived-mode'.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
846
diff
changeset
|
59 |
(modify-syntax-entry ?\" ".") |
907
8a6c364061e2
Prevent wrap '_____' keyword.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
859
diff
changeset
|
60 |
(make-local-variable 'paragraph-separate) |
8a6c364061e2
Prevent wrap '_____' keyword.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
859
diff
changeset
|
61 |
(setq paragraph-separate "\\([ \t\f]*\\|_\\{5,\\}\\)$") |
8a6c364061e2
Prevent wrap '_____' keyword.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
859
diff
changeset
|
62 |
(make-local-variable 'paragraph-start) |
8a6c364061e2
Prevent wrap '_____' keyword.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
859
diff
changeset
|
63 |
(setq paragraph-start paragraph-separate) |
849
c34dc5f47510
Finally fix multiline highlighting.
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
848
diff
changeset
|
64 |
(add-hook 'font-lock-extend-region-functions 'dict-c5-font-lock-extend-region t) |
690
90d155b82954
major mode for dict dictionary source files
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
65 |
) |
90d155b82954
major mode for dict dictionary source files
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
66 |
|
90d155b82954
major mode for dict dictionary source files
Oleksandr Gavenko <gavenkoa@gmail.com>
parents:
diff
changeset
|
67 |
;;; dict-mode.el ends here |