~ubuntu-branches/ubuntu/trusty/agda/trusty

« back to all changes in this revision

Viewing changes to src/data/emacs-mode/agda2-highlight.el

  • Committer: Package Import Robot
  • Author(s): Iain Lane, Kiwamu Okabe, Iain Lane
  • Date: 2013-04-10 11:46:43 UTC
  • mfrom: (4.1.5 experimental)
  • Revision ID: package-import@ubuntu.com-20130410114643-prunhsz59f0fhrdn
Tags: 2.3.2-1
[ Kiwamu Okabe ]
* New patch: Extend haskell-src-exts dependency and fix type miss.

[ Iain Lane ]
* [dfbca48] Imported Upstream version 2.3.2
* [7746bcc] Remove all patches — all upstream.
* [2cdb691] Update build-deps to match control file
* [868ebf4] agda-mode no longer depends on haskell-mode or GHCi.
  Remove dependency and update .el file accordingly
* [9e0ba22] Add agda-bin package here, as the separate package has been
  removed
* [75a240f] agda-mode needs to depend on agda-bin
* [d290f95] Allow Quickcheck up to 2.7. Fix haskeline build-dep.
* [79190e6] Add missing geniplate and parallel BDs

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
  "Syntax highlighting for Agda."
16
16
  :group 'agda2)
17
17
 
 
18
(defcustom agda2-highlight-level 'non-interactive
 
19
  "How much syntax highlighting should be produced?
 
20
Interactive highlighting includes highlighting of the expression
 
21
that is currently being type-checked."
 
22
  :type '(choice
 
23
          (const :tag "None"            none)
 
24
          (const :tag "Non-interactive" non-interactive)
 
25
          (const :tag "Interactive"     interactive))
 
26
  :group 'agda2-highlight)
 
27
 
 
28
(defun agda2-highlight-level nil
 
29
  "Formats the highlighting level in a Haskelly way."
 
30
  (cond ((equal agda2-highlight-level 'none)            "None")
 
31
        ((equal agda2-highlight-level 'non-interactive) "NonInteractive")
 
32
        ((equal agda2-highlight-level 'interactive)     "Interactive")
 
33
        (t                                              "None")))
 
34
 
18
35
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
19
36
;; Functions for setting faces
20
37
 
101
118
            (agda2-highlight-unsolved-meta-face
102
119
             :foreground "black"
103
120
             :background "gold")
 
121
            (agda2-highlight-unsolved-constraint-face
 
122
             :foreground "black"
 
123
             :background "gold")
104
124
            (agda2-highlight-termination-problem-face
105
125
             :foreground "black"
106
126
             :background "red")
107
127
            (agda2-highlight-incomplete-pattern-face
108
128
             :foreground "black"
109
 
             :background "purple")))
 
129
             :background "purple")
 
130
            (agda2-highlight-typechecks-face
 
131
             :foreground "black"
 
132
             :background "light steel blue")))
110
133
         ((equal group 'default-faces)
111
134
          (list (cons 'agda2-highlight-keyword-face
112
135
                      (agda2-highlight-face-attributes
161
184
                       font-lock-function-name-face))
162
185
                (cons 'agda2-highlight-error-face
163
186
                      (agda2-highlight-face-attributes
164
 
                       font-lock-warning-face)))))))
 
187
                       font-lock-warning-face))
 
188
                (cons 'agda2-highlight-typechecks-face
 
189
                      (agda2-highlight-face-attributes
 
190
                       font-lock-type-face))
 
191
                (cons 'agda2-highlight-typechecking-face
 
192
                      (agda2-highlight-face-attributes
 
193
                       font-lock-preprocessor-face)))))))
165
194
 
166
195
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
167
196
;; Faces
168
197
 
169
198
(defcustom agda2-highlight-face-groups nil
170
199
  "Colour scheme used in Agda buffers.
171
 
Note that changing this option does not remove the customisations
172
 
below; you can get them back by resetting this option and
173
 
restarting Emacs. If you are using the default-faces option and
174
 
change your colour theme the changes may not take effect in Agda
175
 
buffers until you have restarted Emacs."
 
200
Changes to this variable may not take full effect until you have
 
201
restarted Emacs. Note also that if you are using the
 
202
default-faces option and change your colour theme, then the
 
203
changes may not take effect in Agda buffers until you have
 
204
restarted Emacs."
176
205
  :type '(choice
177
 
            (const :tag "Use the settings below." nil)
178
 
            (const :tag "Use an approximation of Conor McBride's colour scheme."
179
 
                   conor)
180
 
            (const :tag "Use simplified highlighting and default font-lock faces."
181
 
                   default-faces))
 
206
          (const :tag "Use the settings in the \"Agda2 Highlight Faces\" subgroup." nil)
 
207
          (const :tag "Use an approximation of Conor McBride's colour scheme."
 
208
                 conor)
 
209
          (const :tag "Use simplified highlighting and default font-lock faces."
 
210
                 default-faces))
182
211
  :group 'agda2-highlight
183
212
  :set 'agda2-highlight-set-faces)
184
213
 
 
214
(defgroup agda2-highlight-faces nil
 
215
  "Faces used to highlight Agda code.
 
216
If `agda2-highlight-face-groups' is nil."
 
217
  :group 'agda2-highlight)
 
218
 
185
219
(defface agda2-highlight-keyword-face
186
220
  '((t (:foreground "DarkOrange3")))
187
221
  "The face used for keywords."
188
 
  :group 'agda2-highlight)
 
222
  :group 'agda2-highlight-faces)
189
223
 
190
224
(defface agda2-highlight-string-face
191
225
  '((t (:foreground "firebrick")))
192
226
  "The face used for strings."
193
 
  :group 'agda2-highlight)
 
227
  :group 'agda2-highlight-faces)
194
228
 
195
229
(defface agda2-highlight-number-face
196
230
  '((t (:foreground "purple")))
197
231
  "The face used for numbers."
198
 
  :group 'agda2-highlight)
 
232
  :group 'agda2-highlight-faces)
199
233
 
200
234
(defface agda2-highlight-symbol-face
201
235
  '((((background light))
203
237
    (((background dark))
204
238
     (:foreground "gray75")))
205
239
  "The face used for symbols like forall, =, ->, etc."
206
 
  :group 'agda2-highlight)
 
240
  :group 'agda2-highlight-faces)
207
241
 
208
242
(defface agda2-highlight-primitive-type-face
209
243
  '((t (:foreground "medium blue")))
210
244
  "The face used for primitive types (like Set and Prop)."
211
 
  :group 'agda2-highlight)
 
245
  :group 'agda2-highlight-faces)
212
246
 
213
247
(defface agda2-highlight-bound-variable-face
214
248
  '((t nil))
215
249
  "The face used for bound variables."
216
 
  :group 'agda2-highlight)
 
250
  :group 'agda2-highlight-faces)
217
251
 
218
252
(defface agda2-highlight-inductive-constructor-face
219
253
  '((t (:foreground "green4")))
220
254
  "The face used for inductive constructors."
221
 
  :group 'agda2-highlight)
 
255
  :group 'agda2-highlight-faces)
222
256
 
223
257
(defface agda2-highlight-coinductive-constructor-face
224
258
  '((t (:foreground "gold4")))
225
259
  "The face used for coinductive constructors."
226
 
  :group 'agda2-highlight)
 
260
  :group 'agda2-highlight-faces)
227
261
 
228
262
(defface agda2-highlight-datatype-face
229
263
  '((t (:foreground "medium blue")))
230
264
  "The face used for datatypes."
231
 
  :group 'agda2-highlight)
 
265
  :group 'agda2-highlight-faces)
232
266
 
233
267
(defface agda2-highlight-field-face
234
268
  '((t (:foreground "DeepPink2")))
235
269
  "The face used for record fields."
236
 
  :group 'agda2-highlight)
 
270
  :group 'agda2-highlight-faces)
237
271
 
238
272
(defface agda2-highlight-function-face
239
273
  '((t (:foreground "medium blue")))
240
274
  "The face used for functions."
241
 
  :group 'agda2-highlight)
 
275
  :group 'agda2-highlight-faces)
242
276
 
243
277
(defface agda2-highlight-module-face
244
278
  '((t (:foreground "purple")))
245
279
  "The face used for module names."
246
 
  :group 'agda2-highlight)
 
280
  :group 'agda2-highlight-faces)
247
281
 
248
282
(defface agda2-highlight-postulate-face
249
283
  '((t (:foreground "medium blue")))
250
284
  "The face used for postulates."
251
 
  :group 'agda2-highlight)
 
285
  :group 'agda2-highlight-faces)
252
286
 
253
287
(defface agda2-highlight-primitive-face
254
288
  '((t (:foreground "medium blue")))
255
289
  "The face used for primitive functions."
256
 
  :group 'agda2-highlight)
 
290
  :group 'agda2-highlight-faces)
257
291
 
258
292
(defface agda2-highlight-record-face
259
293
  '((t (:foreground "medium blue")))
260
294
  "The face used for record types."
261
 
  :group 'agda2-highlight)
 
295
  :group 'agda2-highlight-faces)
262
296
 
263
297
(defface agda2-highlight-dotted-face
264
298
  '((t nil))
265
299
  "The face used for dotted patterns."
266
 
  :group 'agda2-highlight)
 
300
  :group 'agda2-highlight-faces)
267
301
 
268
302
(defface agda2-highlight-operator-face
269
303
  '((t nil))
270
304
  "The face used for operators."
271
 
  :group 'agda2-highlight)
 
305
  :group 'agda2-highlight-faces)
272
306
 
273
307
(defface agda2-highlight-error-face
274
308
  '((t (:foreground "red" :underline t)))
275
309
  "The face used for errors."
276
 
  :group 'agda2-highlight)
 
310
  :group 'agda2-highlight-faces)
277
311
 
278
312
(defface agda2-highlight-unsolved-meta-face
279
313
  '((t (:background "yellow"
280
314
        :foreground "black")))
281
315
  "The face used for unsolved meta variables."
282
 
  :group 'agda2-highlight)
 
316
  :group 'agda2-highlight-faces)
 
317
 
 
318
(defface agda2-highlight-unsolved-constraint-face
 
319
  '((t (:background "yellow"
 
320
        :foreground "black")))
 
321
  "The face used for unsolved constraints which are not connected to metas."
 
322
  :group 'agda2-highlight-faces)
283
323
 
284
324
(defface agda2-highlight-termination-problem-face
285
325
  '((t (:background "light salmon"
286
326
        :foreground "black")))
287
327
  "The face used for termination problems."
288
 
  :group 'agda2-highlight)
 
328
  :group 'agda2-highlight-faces)
289
329
 
290
330
(defface agda2-highlight-incomplete-pattern-face
291
331
  '((t (:background "wheat"
292
332
        :foreground "black")))
293
333
  "The face used for incomplete patterns. (Currently unused.)"
294
 
  :group 'agda2-highlight)
 
334
  :group 'agda2-highlight-faces)
 
335
 
 
336
(defface agda2-highlight-typechecks-face
 
337
  '((t (:background "light blue"
 
338
        :foreground "black")))
 
339
  "The face used for code which is being type-checked."
 
340
  :group 'agda2-highlight-faces)
295
341
 
296
342
(defvar agda2-highlight-faces
297
343
  '((keyword                . agda2-highlight-keyword-face)
313
359
    (operator               . agda2-highlight-operator-face)
314
360
    (error                  . agda2-highlight-error-face)
315
361
    (unsolvedmeta           . agda2-highlight-unsolved-meta-face)
 
362
    (unsolvedconstraint     . agda2-highlight-unsolved-constraint-face)
316
363
    (terminationproblem     . agda2-highlight-termination-problem-face)
317
 
    (incompletepattern      . agda2-highlight-incomplete-pattern-face))
 
364
    (incompletepattern      . agda2-highlight-incomplete-pattern-face)
 
365
    (typechecks             . agda2-highlight-typechecks-face))
318
366
  "Alist mapping code aspects to the face used when displaying them.
319
367
 
320
368
The aspects currently recognised are the following:
339
387
`string'                 Strings.
340
388
`symbol'                 Symbols like forall, =, ->, etc.
341
389
`terminationproblem'     Termination problems.
 
390
`typechecks'             Code which is being type-checked.
 
391
`unsolvedconstraint'     Unsolved constraints, not connected to meta
 
392
                           variables.
342
393
`unsolvedmeta'           Unsolved meta variables.
343
394
 
344
395
The following aspect is ignored:
349
400
table). The face `font-lock-comment-face' is used for comments.")
350
401
 
351
402
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
403
;; Variables
 
404
 
 
405
(defvar agda2-highlight-in-progress nil
 
406
  "If nil, then highlighting annotations are not applied.")
 
407
(make-variable-buffer-local 'agda2-highlight-in-progress)
 
408
 
 
409
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
352
410
;; Functions
353
411
 
354
412
(defun agda2-highlight-setup nil
355
413
  "Set up the `annotation' library for use with `agda2-mode'."
356
 
  (font-lock-mode 0)
357
414
  (setq annotation-bindings agda2-highlight-faces))
358
415
 
359
 
(defun agda2-highlight-load (file &optional keep)
 
416
(defun agda2-highlight-apply (&rest cmds)
 
417
  "Adds the syntax highlighting information in the annotation list CMDS.
 
418
 
 
419
Old syntax highlighting information is not removed."
 
420
  (let (;; Ignore read-only status, otherwise this function may fail.
 
421
        (inhibit-read-only t))
 
422
    (apply 'annotation-load
 
423
           "Click mouse-2 to jump to definition"
 
424
           cmds)))
 
425
 
 
426
(defun agda2-highlight-add-annotations (&rest cmds)
 
427
  "Like `agda2-highlight-apply'.
 
428
But only if `agda2-highlight-in-progress' is non-nil."
 
429
  (if agda2-highlight-in-progress
 
430
      (apply 'agda2-highlight-apply cmds)))
 
431
 
 
432
(defun agda2-highlight-load (file)
360
433
  "Load syntax highlighting information from FILE.
361
 
Old syntax highlighting information is first removed, unless KEEP
 
434
 
 
435
Old syntax highlighting information is not removed."
 
436
  (let* ((coding-system-for-read 'utf-8)
 
437
         (cmds (with-temp-buffer
 
438
                 (insert-file-contents file)
 
439
                 (goto-char (point-min))
 
440
                 (read (current-buffer)))))
 
441
      (apply 'agda2-highlight-apply cmds)))
 
442
 
 
443
(defun agda2-highlight-load-and-delete-action (file)
 
444
  "Like `agda2-highlight-load', but deletes FILE when done.
 
445
And highlighting is only updated if `agda2-highlight-in-progress'
362
446
is non-nil."
363
 
  (let ((coding-system-for-read 'utf-8)
364
 
        ;; Ignore read-only status, otherwise this function may fail.
365
 
        (inhibit-read-only t))
366
 
    (annotation-load-file file (lambda (anns) (not keep))
367
 
                          "Click mouse-2 to jump to definition")))
 
447
  (unwind-protect
 
448
      (if agda2-highlight-in-progress
 
449
          (agda2-highlight-load file))
 
450
    (delete-file file)))
368
451
 
369
452
(defun agda2-highlight-clear nil
370
453
  "Remove all syntax highlighting added by `agda2-highlight-reload'."