root/trunk/wenv/emacs/logtalk.el @ 5055

Revision 5055, 10.4 KB (checked in by pmoura, 14 months ago)

Updated text editor configuration files in order to remove references to the no longer used ".config" file name extension and to support syntax coloring and code completion of the multifile/1 and use_module/1-2 directives.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1;; logtalk.el -- font lock support for Logtalk (http://logtalk.org/)
2
3;; Copyright (C) 2003-2008 Paulo Moura
4
5;; Author: Paulo Moura <pmoura@logtalk.org>
6;; Creation date: November 15, 2003
7;; Last modification date: July 1, 20089
8;; Version: 1.9
9
10;; Installation:
11;;
12;; First, copy this file to the appropriated directory. For FSF Emacs this will
13;; probably be /usr/local/share/emacs/site-lisp. For XEmacs, the directory is
14;; usully /usr/local/lib/xemacs/site-lisp. You may also copy the file to a
15;; sub-directory in your home directory depending on your Emacs configuration.
16;; Type "C-h v load-path" in Emacs to find the list of paths that are searched
17;; for when looking for lisp files.
18;;
19;; Second, add the following lines in your Emacs init file, for example
20;; your ~/.emacs file:
21;;
22;; (autoload 'logtalk-mode "logtalk" "Major mode for editing Logtalk programs." t)
23;; (add-to-list 'auto-mode-alist '("\\.lgt\\'" . logtalk-mode))
24
25
26
27;; setup
28
29(defvar logtalk-mode-version "1.9"
30    "Logtalk mode version number")
31
32(defvar logtalk-mode-hook nil)
33
34(defvar logtalk-mode-map nil)
35
36(if logtalk-mode-map nil
37    (setq logtalk-mode-map (make-keymap)))
38
39
40
41;; syntax highlighting
42
43(defvar logtalk-font-lock-keywords nil)
44
45
46
47;; syntax table
48
49(defvar logtalk-mode-syntax-table
50    (let ((logtalk-mode-syntax-table (make-syntax-table)))
51        (modify-syntax-entry ?_ "w" logtalk-mode-syntax-table)
52        (modify-syntax-entry ?/ ". 14b" logtalk-mode-syntax-table)
53        (modify-syntax-entry ?* ". 23b" logtalk-mode-syntax-table)
54        (modify-syntax-entry ?% "<" logtalk-mode-syntax-table)
55        (modify-syntax-entry ?\n ">" logtalk-mode-syntax-table)
56        (modify-syntax-entry ?\' "w" logtalk-mode-syntax-table)
57        logtalk-mode-syntax-table)
58    "Syntax table for logtalk-mode")
59
60
61
62;; make logtalk font-lock-faces
63
64(make-face 'logtalk-default-face)
65(make-face 'logtalk-directive-face)
66(make-face 'logtalk-built-in-predicate-face)
67(make-face 'logtalk-built-in-method-face)
68(make-face 'logtalk-message-operator-face)
69(make-face 'logtalk-variable-face)
70(make-face 'logtalk-number-face)
71(make-face 'logtalk-comment-face)
72(make-face 'logtalk-string-face)
73
74;; set logtalk font-lock-faces
75
76(require 'font-lock)
77
78(copy-face 'default 'logtalk-default-face)
79(copy-face 'font-lock-keyword-face 'logtalk-directive-face)
80(copy-face 'font-lock-builtin-face 'logtalk-built-in-predicate-face)
81(copy-face 'font-lock-builtin-face 'logtalk-built-in-method-face)
82(copy-face 'font-lock-function-name-face 'logtalk-message-operator-face)
83(copy-face 'font-lock-variable-name-face 'logtalk-variable-face)
84(copy-face 'font-lock-constant-face 'logtalk-number-face)
85(copy-face 'font-lock-comment-face 'logtalk-comment-face)
86(copy-face 'font-lock-string-face 'logtalk-string-face)
87
88
89
90(setq logtalk-font-lock-strings
91    '(
92        ("\\(\"\\([^\n\"]\\|\\\\\"\\)*\"\\)" 1 'logtalk-string-face)
93        ("\\(^\\|[^0-9]\\)\\('\\([^\n']\\|\\\\'\\)*'\\)" 2 'logtalk-string-face)
94    ))
95
96
97(setq logtalk-font-lock-directives
98    '(
99        ("\\(:- \\)\\(\\(e\\(?:lse\\|nd\\(?:if\\|_\\(?:category\\|object\\|protocol\\)\\)\\)\\)\\)\\([\.]\\)" 2 'logtalk-directive-face)
100        ("\\(:- \\)\\(category\\|object\\|protocol\\|module\\)\\([(]\\)" 2 'logtalk-directive-face)
101        ("\\(:- \\)\\(p\\(?:r\\(?:ivate\\|otected\\)\\|ublic\\)\\)\\([(]\\)" 2 'logtalk-directive-face)
102        ("\\(:- \\)\\(alias\\|calls\\|d\\(?:iscontiguous\\|ynamic\\)\\|e\\(?:lif\\|n\\(?:coding\\|sure_loaded\\)\\|xport\\)\\|i\\(?:f\\|n\\(?:fo\\|itialization\\)\\)\\|m\\(?:\\(?:eta_predicat\\|od\\|ultifil\\)e\\)\\|op\\|use\\(?:s\\|_module\\)\\|synchronized\\)\\([(]\\)" 2 'logtalk-directive-face)
103        ("\\(:- \\)\\(dynamic\\|s\\(?:et_\\(?:logtalk\\|prolog\\)_flag\\|ynchronized\\)\\|threaded\\)\\([\.]\\)" 2 'logtalk-directive-face)
104        ("\\<\\(\\(?:complement\\|extend\\|i\\(?:mp\\(?:\\(?:lemen\\|or\\)t\\)\\|nstantiate\\)\\|specialize\\)s\\)\\([(]\\)" 1 'logtalk-directive-face)
105    ))
106
107
108(setq logtalk-font-lock-built-in-methods
109    '(
110        ("\\<\\(parameter\\|se\\(?:lf\\|nder\\)\\|this\\)\\([(]\\)" 1 'logtalk-built-in-method-face)
111        ("\\<\\(current_predicate\\|predicate_property\\)\\([(]\\)" 1 'logtalk-built-in-method-face)
112        ("\\<\\(a\\(?:bolish\\|ssert[az]\\)\\|clause\\|retract\\(?:all\\)?\\)\\([(]\\)" 1 'logtalk-built-in-method-face)
113        ("\\<\\(bagof\\|f\\(?:\\(?:ind\\|or\\)all\\)\\|setof\\)\\([(]\\)" 1 'logtalk-built-in-method-face)
114        ("\\<\\(after\\|before\\)\\([(]\\)" 1 'logtalk-built-in-method-face)
115        ("\\<\\(phrase\\|expand_\\(?:goal\\|term\\)\\|\\(?:goal\\|term\\)_expansion\\)\\([(]\\)" 1 'logtalk-built-in-method-face)
116    ))
117
118
119(setq logtalk-font-lock-built-in-predicates
120    '(
121        ("\\<\\(c\\(?:urrent\\|reate\\)_\\(?:category\\|object\\|protocol\\)\\)\\([(]\\)" 1 'logtalk-built-in-predicate-face)
122        ("\\<\\(abolish_\\(?:category\\|object\\|protocol\\)\\)\\([(]\\)" 1 'logtalk-built-in-predicate-face)
123        ("\\<\\(\\(?:category\\|object\\|protocol\\)_property\\)\\([(]\\)" 1 'logtalk-built-in-predicate-face)
124        ("\\<\\(complements_object\\|extends_\\(?:object\\|protocol\\|category\\)\\|i\\(?:mp\\(?:lements_protocol\\|orts_category\\)\\|nstantiates_class\\)\\|specializes_class\\)\\([(]\\)" 1 'logtalk-built-in-predicate-face)
125        ("\\<\\(\\(?:abolish\\|define\\)_events\\|current_event\\)\\([(]\\)" 1 'logtalk-built-in-predicate-face)
126        ("\\<\\(\\(?:curren\\|se\\)t_logtalk_flag\\)\\([(]\\)" 1 'logtalk-built-in-predicate-face)
127        ("\\<\\(logtalk_\\(?:compile\\|load\\|version\\|library_path\\)\\)\\([(]\\)" 1 'logtalk-built-in-predicate-face)
128        ("\\<\\(forall\\)\\([(]\\)" 1 'logtalk-built-in-predicate-face)
129        ("\\<\\(retractall\\)\\([(]\\)" 1 'logtalk-built-in-predicate-face)
130        ;;
131        ;; control constructs:
132        ;;
133        ("\\<\\(ca\\(?:ll\\|tch\\)\\|throw\\)\\([(]\\)" 1 'logtalk-built-in-predicate-face)
134        ("\\<\\(fail\\|true\\)\\>" 0 'logtalk-built-in-predicate-face)
135        ("\\(!\\|->\\|;\\)" 0 'logtalk-built-in-predicate-face)
136        ;;
137        ;; multi-threading:
138        ;;
139        ("\\<\\(threaded\\(_\\(?:call\\|once\\|ignore\\|exit\\|peek\\|wait\\|notify\\)\\)?\\)\\([(]\\)" 1 'logtalk-built-in-predicate-face)
140        ;;
141        ;; logic and control:
142        ;;
143        ("\\<\\(once\\)\\([(]\\)" 1 'logtalk-built-in-predicate-face)
144        ("\\\\\\+\\|\\<repeat\\>" 0 'logtalk-built-in-predicate-face)
145        ;;
146        ;; term testing:
147        ;;
148        ("\\<\\(atom\\(?:ic\\)?\\|compound\\|float\\|\\(?:intege\\|n\\(?:onva\\|umbe\\)\\|va\\)r\\)\\([(]\\)" 1 'logtalk-built-in-predicate-face)
149        ;;
150        ;; term comparison:
151        ;;
152        ("==\\|@\\(?:=<\\|>=\\|[<>]\\)\\|\\\\==" 0 'logtalk-built-in-predicate-face)
153        ;;
154        ;; term creation and decomposition:
155        ;;
156        ("\\<\\(arg\\|copy_term\\|functor\\)\\([(]\\)" 1 'logtalk-built-in-predicate-face)
157        ("=\\.\\." 0 'logtalk-built-in-predicate-face)
158        ;;
159        ;; arithemtic evaluation:
160        ;;
161        ("\\<is\\>" 0 'logtalk-built-in-predicate-face)
162        ;;
163        ;; arithmetic comparison:
164        ("=:=\\|\\(?:=<\\|>=\\|[<>]\\)\\|\\\\==" 0 'logtalk-built-in-predicate-face)
165        ;;
166        ;; term unification:
167        ;;
168        ("\\\\?=" 0 'logtalk-built-in-predicate-face)
169        ("\\<\\(unify_with_occurs_check\\)\\([(]\\)" 1 'logtalk-built-in-predicate-face)
170        ;;
171        ;; dcgs:
172        ;;
173        ("-->" 0 'logtalk-built-in-predicate-face)
174        ;;
175        ;; evaluable functors:
176        ;;
177        ("\\<\\(abs\\|ceiling\\|flo\\(?:at\\(?:_\\(?:\\(?:fractional\\|integer\\)_part\\)\\)?\\|or\\)\\|mod\\|r\\(?:em\\|ound\\)\\|sign\\|truncate\\)\\([(]\\)" 1 'logtalk-built-in-predicate-face)
178        ("//\\|[*/]" 0 'logtalk-built-in-predicate-face)
179        ("\\([^eE]\\)\\([+]\\)" 2 'logtalk-built-in-predicate-face)
180        ("\\([^:eE]\\)\\([-]\\)" 2 'logtalk-built-in-predicate-face)
181        ("\\<\\(rem\\|mod\\)\\>" 0 'logtalk-built-in-predicate-face)
182        ;;
183        ;; other arithemtic functors:
184        ;;
185        ("\\<\\(atan\\|cos\\|exp\\|log\\|s\\(?:in\\|qrt\\)\\)\\([(]\\)" 1 'logtalk-built-in-predicate-face)
186        ("\\*\\*" 1 'logtalk-built-in-predicate-face)
187        ;;
188        ;; stream selection and control:
189        ;;
190        ("\\<\\(at_end_of_stream\\|c\\(?:lose\\|urrent_\\(?:\\(?:in\\|out\\)put\\)\\)\\|flush_output\\|open\\|s\\(?:et_\\(?:input\\|output\\|stream_position\\)\\|tream_property\\)\\)\\([(]\\)" 1 'logtalk-built-in-predicate-face)
191        ("\\<\\(at_end_of_stream\\|flush_output\\)\\>" 0 'logtalk-built-in-predicate-face)
192        ;;
193        ;; character input/output:
194        ;;
195        ("\\<\\(get_c\\(?:har\\|ode\\)\\|nl\\|p\\(?:eek_c\\(?:har\\|ode\\)\\|ut_c\\(?:har\\|ode\\)\\)\\)\\([(]\\)" 1 'logtalk-built-in-predicate-face)
196        ("\\<nl\\>" 0 'logtalk-built-in-predicate-face)
197        ;;
198        ;; byte input/output:
199        ;;
200        ("\\<\\(\\(?:get\\|p\\(?:eek\\|ut\\)\\)_byte\\)\\([(]\\)" 1 'logtalk-built-in-predicate-face)
201        ;;
202        ;; term input/output:
203        ;;
204        ("\\<\\(c\\(?:har_conversion\\|urrent_\\(?:char_conversion\\|op\\)\\)\\|op\\|read\\(?:_term\\)?\\|write\\(?:_\\(?:canonical\\|term\\)\\|q\\)?\\)\\([(]\\)" 1 'logtalk-built-in-predicate-face)
205        ;;
206        ;; implementation defined hooks functions:
207        ;;
208        ("\\<\\(\\(?:curren\\|se\\)t_prolog_flag\\|halt\\)\\([(]\\)" 1 'logtalk-built-in-predicate-face)
209        ("\\<halt\\>" 0 'logtalk-built-in-predicate-face)
210        ;;
211        ;; atomic term processing:
212        ;;
213        ("\\<\\(atom_\\(?:c\\(?:hars\\|o\\(?:des\\|ncat\\)\\)\\|length\\)\\|char_code\\|number_c\\(?:\\(?:har\\|ode\\)s\\)\\|sub_atom\\)\\([(]\\)" 1 'logtalk-built-in-predicate-face)
214        ;;
215        ;; bitwise functors:
216        ;;
217        ("/\\\\|<<\\|>>\\|\\\\/" 0 'logtalk-built-in-predicate-face)
218        ("\\\\" 0 'logtalk-built-in-predicate-face)
219    ))
220
221
222(setq logtalk-font-lock-operators
223    '(
224        ;;
225        ;; clause operator:
226        ;;
227        (":-" 0 'logtalk-default-face)
228        ;;
229        ;; message sending operators:
230        ;;
231        ("::\\|\\^\\^\\|[{}]" 0 'logtalk-message-operator-face)
232        ;;
233        ;; category predicate direct call:
234        ;;
235        (":" 0 'logtalk-message-operator-face)
236        ;;
237        ;; mode operators:
238        ;;
239        ("[@?]" 0 'logtalk-built-in-predicate-face)
240    ))
241
242
243(setq logtalk-font-lock-numbers
244    '(
245        ("\\<\\(0x[a-fA-F0-9]+\\)\\>" 1 'logtalk-number-face)
246        ("\\<\\(0o[0-7]+\\)\\>" 1 'logtalk-number-face)
247        ("\\<\\(0b[0-1]+\\)\\>" 1 'logtalk-number-face)
248        ("\\<\\(0['].\\)\\>" 1 'logtalk-number-face)
249        ("\\<\\([0-9]+\\([.][0-9]+\\)?\\([eE][+-][0-9]+\\)?\\)\\>" 1 'logtalk-number-face)
250    ))
251
252
253(setq logtalk-font-lock-variables
254    '(
255        ("\\<\\([_A-Z][a-zA-Z0-9_]*\\)\\>" 1 'logtalk-variable-face)
256    ))
257
258
259(setq logtalk-font-lock-keywords
260    (append
261        logtalk-font-lock-strings
262        logtalk-font-lock-directives
263        logtalk-font-lock-built-in-methods
264        logtalk-font-lock-built-in-predicates
265        logtalk-font-lock-operators
266        logtalk-font-lock-variables
267        logtalk-font-lock-numbers
268    ))
269
270
271;; entry function
272
273(defun logtalk-mode ()
274    "Major mode for editing Logtalk files"
275    (interactive)
276    (kill-all-local-variables)
277    (setq tab-width 4)
278    (set-syntax-table logtalk-mode-syntax-table)
279    (set (make-local-variable 'font-lock-defaults) '(logtalk-font-lock-keywords))
280    (turn-on-font-lock)
281    (setq major-mode 'logtalk-mode)
282    (setq mode-name "Logtalk")
283    (run-hooks 'logtalk-mode-hook))
284
285(provide 'logtalk-mode)
Note: See TracBrowser for help on using the browser.