-
Notifications
You must be signed in to change notification settings - Fork 6
/
mizar.el
6622 lines (5864 loc) · 235 KB
/
mizar.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;;; mizar.el --- mizar.el -- Mizar Mode for Emacs
;;
;;; License: GPL (GNU GENERAL PUBLIC LICENSE)
;;
;;; Commentary:
;;
;; Emacs mode for authoring Mizar (www.mizar.org) articles.
;; Run C-h f mizar-mode for overview of commands.
;; Complete info, html, pdf and ps documentation is
;; downloadable from http://kti.ms.mff.cuni.cz/~urban/MizarModeDoc.tar.gz .
;; Browse it at http://ktilinux.ms.mff.cuni.cz/~urban/MizarModeDoc/html .
;;; History:
;;
;; Started by Bob Beck, [email protected] (beck@alberta) as
;; a mode for Unix version of Mizar-MSE.
;;
;; Since April 3 2000, rewritten and maintained by
;; Josef Urban (Josef do Urban at gmail dot com) for use with Mizar Version >= 6.
;;
;; Go to https://github.com/JUrban/mizarmode
;; to see complete revision history. The latest release is at
;; https://raw.github.com/JUrban/mizarmode/master/mizar.el .
;;; Usage
;;
;; If you obtained this with your Mizar distribution, just append
;; the .emacs file enclosed there to your .emacs.
;; Otherwise, the latest version of .emacs is downloadable from
;; https://raw.github.com/JUrban/mizarmode/master/.emacs .
;;; TODO:
;;
;; better indentation,
(defvar mizar-emacs
(if (featurep 'xemacs)
'xemacs
(if (featurep 'dos-w32)
'winemacs
'gnuemacs))
"The variant of Emacs we're running.
Valid values are 'gnuemacs,'Xemacs and 'winemacs.")
(eval-when-compile
(require 'compile)
(require 'font-lock)
(require 'imenu)
(require 'info)
(require 'shell)
)
(require 'comint)
(require 'cl)
(require 'easymenu)
(require 'etags)
(require 'hideshow)
(require 'dabbrev)
(require 'executable)
(require 'term)
(require 'imenu)
(if (eq mizar-emacs 'xemacs)
(require 'speedbar) ;; no NOERROR in xemacs
(require 'speedbar nil t)) ;;noerror if not present
;;;; variables and customization
(defgroup mizar nil
"Major mode for authoring Mizar articles"
:group 'languages)
(defgroup mizar-running nil
"Running the Mizar utilities"
:group 'mizar)
(defgroup mizar-indenting nil
"Indenting in the Mizar mode"
:group 'mizar)
(defgroup mizar-files nil
"Files and paths settings in the Mizar mode"
:group 'mizar)
(defgroup mizar-grep nil
"Grepping in the Mizar mode"
:group 'mizar)
(defgroup mizar-faces nil
"Faces for Mizar keywords"
:group 'mizar)
(defgroup mizar-constructor-explanations nil
"Constructor explanations for the Mizar mode"
:group 'mizar)
(defgroup mizar-mml-query nil
"Support for MML Query in the Mizar mode"
:group 'mizar)
(defgroup mizar-proof-advisor nil
"Mizar Proof Advisor settings"
:group 'mizar)
(defgroup mizar-skeletons nil
"Skeleton settings for the Mizar mode"
:group 'mizar)
(defgroup mizar-speedbar nil
"Speedbar support for the Mizar mode"
:group 'mizar)
(defgroup mizar-education nil
"Options for nonstandard Mizaring used when teaching Mizar"
:group 'mizar)
(defgroup mizar-remote nil
"Options for running Mizar and related utilities remotely"
:group 'mizar)
(defcustom mizar-newline-indents nil
"*Newline indents."
:type 'boolean
:group 'mizar-indenting)
(defcustom mizar-semicolon-indents nil
"*Semicolon indents."
:type 'boolean
:group 'mizar-indenting)
(defcustom mizar-indent-width 2
"*Indentation width for Mizar articles."
:type 'integer
:group 'mizar-indenting)
(defcustom mizar-align-labels nil
"*Indenting puts labels at the beginning of lines."
:type 'boolean
:group 'mizar-indenting)
(defcustom mizar-abstracts-use-view t
"*View-mode is used for Mizar abstracts."
:type 'boolean
:group 'mizar)
(defcustom mizar-launch-speedbar nil
"Launch speedbar upon entering mizar-mode for the first time.
Speedbar can be (de)activated later by running the command `speedbar'."
:type 'boolean
:group 'mizar-speedbar)
(defcustom mizar-show-output 4
"*Determines the size of the output window after processing.
Possible values: \"none\", 4, 10, \"all\"."
:type '(choice (const :tag "no output" "none")
(const :tag "all output" "all")
(const :tag "4 lines" 4)
(const :tag "10 lines" 10))
:group 'mizar-running)
(defcustom mizar-goto-error "next"
"*What error to move to after processing.
Possible values are none, first, next, previous."
:type '(choice (const :tag "next error after point" "next")
(const :tag "first error in the article" "first")
(const :tag "first error before point" "previous")
(const :tag "no movement" "none"))
:group 'mizar-running)
(defcustom mizar-verifier "verifier"
"*The default Mizar verifier used to check Mizar articles.
This is used in the `mizar-it' function."
:type 'string
:group 'mizar-running)
(defcustom makeenv "makeenv"
"*Program used for creating the article environment.
This is used in the `mizar-it' function."
:type 'string
:group 'mizar-running)
(defcustom mizar-parallel-options " -j2 -e1 "
"*Options passed to the mizp.pl Mizar parallizer.
This is used in the `mizar-it-parallel' function.
Run mizp.pl --man to get overview of the options."
:type 'string
:group 'mizar-running)
(defcustom mizfiles
(file-name-as-directory (substitute-in-file-name "$MIZFILES"))
"The directory where MML is installed."
:type 'string
:group 'mizar-files)
(defcustom mizar-allow-long-lines t
"*Makes Mizar verifier and other utilities allow lines longer than 80 chars.
This is useful when writing an article, however, you should
remove long lines before submitting your article to MML."
:type 'boolean
:group 'mizar-running)
(defcustom mizar-quick-run t
"*Speeds up verifier by not displaying its intermediate output.
Can be toggled from the menu, however the nil value is no
longer supported and may be deprecated (e.g. on Windows)."
:type 'boolean
:group 'mizar-running)
(defcustom mizar-grep-case-sensitive t
"*Tells if MML grepping is case sensitive or not."
:type 'boolean
:group 'mizar-grep
)
(defcustom mizar-sb-in-abstracts t
"Tells if we use speedbar for Mizar abstracts."
:type 'boolean
:group 'mizar-speedbar)
(defcustom mizar-sb-in-mmlquery t
"Tells if we use speedbar for MMLQuery abstracts."
:type 'boolean
:group 'mizar-speedbar)
(defcustom mizar-do-expl nil
"*Use constructor explanations.
Put constructor format of 'by' items as properties after verifier run.
The constructor representation can then be displayed
\(according to the value of `mizar-expl-kind') and queried."
:type 'boolean
:group 'mizar-constructor-explanations)
(defcustom mizar-expl-kind 'sorted
"*Variable controlling the display of constructor representation of formulas.
Has effect iff `mizar-do-expl' is non-nil.
Possible values are now
'sorted for sorted list of constructors in absolute notation.
'constructors for list of constructors in absolute notation,
'mmlquery behaves as 'sorted, but constructors are inserted
directly into the *mmlquery* input buffer.
The mmlquery interpreter has to be installed for this,
see `mmlquery-program-name'.
'translate for expanded formula in absolute notation,
'raw for the internal Mizar representation,
'xml for xml internal Mizar representation
The values 'xml and 'raw are for debugging only, do
not use them to get constructor explanations."
:type '(choice (const :tag "sorted list of constructors" sorted)
(const :tag "unsorted list of constructors" constructor)
(const :tag "mmlquery input" mmlquery)
(const :tag "translated formula" translate)
(const :tag "nontranslated (raw) formula" raw)
(const :tag "nontranslated (xml) formula" xml))
:group 'mizar-constructor-explanations)
(defcustom mizar-underline-expls nil
"*If t, the clickable explanation spots in mizar buffer are underlined.
Has effect iff `mizar-do-expl' is non-nil."
:type 'boolean
:group 'mizar-constructor-explanations)
(defcustom byextent 1
"Size of the clickable constructor explanation region.
`mizar-do-expl' has to be non-nil for this.
When `mizar-underline-expls' is non-nil, it is also underlined."
:type 'integer
:group 'mizar-constructor-explanations)
(defvar merak-url "http://merak.pb.bialystok.pl/cgi-bin/mmlquery/")
(defvar megrez-url "http://megrez.mizar.org/cgi-bin/")
(defcustom query-url merak-url
"*URL for the MMLQuery HTML browser."
:type 'string
:group 'mizar-mml-query)
(defcustom query-text-output nil
"If non-nil, text output is required from MML Query."
:type 'boolean
:group 'mizar-mml-query)
(defcustom mizar-query-browser nil
"*Browser for MML Query, we allow 'w3 or default."
:type 'symbol
:group 'mizar-mml-query)
(defcustom mmlquery-abstracts (concat mizfiles "gab/")
"*Directory containing the mmlquery abstracts for browsing."
:type 'string
:group 'mizar-files
:group 'mizar-mml-query)
;; (defcustom advisor-url "http://lipa.ms.mff.cuni.cz/cgi-bin/mycgi1.cgi"
;; "*URL for the Mizar Proof Advisor."
;; :type 'string
;; :group 'mizar-proof-advisor)
(defcustom advisor-server "lipa.ms.mff.cuni.cz"
"Server for the Mizar Proof Advisor."
:type 'string
:group 'mizar-proof-advisor)
(defcustom advisor-cgi "/cgi-bin/mycgi1.cgi"
"Path to the advisor CGI script on `advisor-server'."
:type 'string
:group 'mizar-proof-advisor)
(defcustom advisor-limit 30
"*The number of hits you want Mizar Proof Advisor to send you."
:type 'integer
:group 'mizar-proof-advisor)
(defcustom mizar-use-momm nil
"*If t, errors *4 are clickable, trying to get MoMM's hints.
MoMM should be installed for this."
:type 'boolean
:group 'mizar-running)
(defcustom mizar-momm-dir (concat mizfiles "MoMM/")
"*Directory containing the MoMM distribution."
:type 'string
:group 'mizar-files)
(defvar mizar-mode-abbrev-table nil
"Abbrev table in use in Mizar-mode buffers.")
(define-abbrev-table 'mizar-mode-abbrev-table ())
(defcustom mizar-main-color (face-foreground font-lock-function-name-face)
"*Color used for `mizar-main-keywords'."
:type 'color
:group 'mizar-faces)
(defcustom mizar-block-color (face-foreground font-lock-keyword-face)
"*Color used for `mizar-block-keywords'."
:type 'color
:group 'mizar-faces)
(defcustom mizar-normal-color
(face-foreground font-lock-variable-name-face)
"*Color used for `mizar-normal-keywords'."
:type 'color
:group 'mizar-faces)
(defcustom mizar-skeleton-color mizar-normal-color
"*Color used for `mizar-skeleton-keywords'."
:type 'color
:group 'mizar-faces)
(defcustom mizar-formula-color
(if (and (boundp 'font-lock-background-mode)
(eq font-lock-background-mode 'dark))
"LightSkyBlue" "Orchid")
"*Color used for `mizar-formula-keywords'."
:type 'color
:group 'mizar-faces)
(defcustom mizar-environment-keywords
(list "schemes" "constructors" "definitions"
"theorems" "vocabularies" "requirements" "registrations"
"notations" "equalities" "expansions")
"*Keywords starting mizar environmental items."
:type '(repeat string)
:group 'mizar-faces)
(defcustom mizar-main-keywords
(list "theorem" "scheme" "definition" "registration" "notation" "axiom")
"*Keywords starting main mizar text items."
:type '(repeat string)
:group 'mizar-faces)
(defcustom mizar-block-keywords
(list "proof" "now" "end" "hereby" "case" "suppose")
"*Keywords for Mizar block starts and ends."
:type '(repeat string)
:group 'mizar-faces)
(defcustom mizar-formula-keywords
(list "for" "ex" "not" "&" "or" "implies" "iff" "st" "holds" "being" "does")
"*Keywords for logical symbols in Mizar formulas."
:type '(repeat string)
:group 'mizar-faces)
(defcustom mizar-skeleton-keywords
(list "assume" "cases" "given" "hence" "let" "per" "take" "thus")
"*Keywords denoting skeleton proof steps."
:type '(repeat string)
:group 'mizar-faces)
(defcustom mizar-normal-keywords
(list
"and" "antonym" "attr" "as" "be" "begin" "canceled" "cluster"
"coherence" "compatibility" "consider" "consistency"
"contradiction" "correctness" "def" "deffunc"
"defpred" "environ" "equals" "existence"
"func" "if" "identify" "irreflexivity"
"it" "means" "mode" "of" "otherwise" "over"
"pred" "provided" "qua" "reconsider" "redefine" "reduce" "reducibility" "reflexivity"
"reserve" "struct" "such" "synonym"
"that" "then" "thesis" "when" "where" "with""is"
"associativity" "commutativity" "connectedness" "irreflexivity" "to"
"reflexivity" "symmetry" "sethood" "uniqueness" "transitivity" "idempotence"
"asymmetry" "projectivity" "involutiveness")
"*Mizar keywords not mentioned in other place."
:type '(repeat string)
:group 'mizar-faces)
(defvar mizar-mode-syntax-table nil)
(defvar mizar-mode-abbrev-table nil)
(defvar mizar-mode-map nil "Keymap used by mizar mode..")
;; current xemacs has no custom-set-default
(if (fboundp 'custom-set-default)
(progn
; ;; this gets rid of the "Keep current list of tag tables" message
; ;; when working with two tag tables
(custom-set-default 'tags-add-tables nil)
; ;; this shows all comment lines when hiding proofs
(custom-set-default 'hs-hide-comments-when-hiding-all nil)
; ;; this prevents the default value, which is hs-hide-initial-comment-block
(custom-set-default 'hs-minor-mode-hook nil))
(custom-set-variables
'(tags-add-tables nil)
'(hs-hide-comments-when-hiding-all nil)
'(hs-minor-mode-hook nil)))
(defun mizar-set-indent-width (to)
"Set indent width to TO."
(interactive)
(setq mizar-indent-width to))
(if mizar-mode-syntax-table
()
(let ((table (make-syntax-table)))
(modify-syntax-entry ?\" "_" table)
(modify-syntax-entry ?: ". 12" table)
(modify-syntax-entry ?\n "> " table)
(modify-syntax-entry ?\^m "> " table)
(setq mizar-mode-syntax-table table)))
(define-abbrev-table 'mizar-mode-abbrev-table ())
(defun mizar-mode-variables ()
"The variables used by mizar-mode."
(set-syntax-table mizar-mode-syntax-table)
(setq local-abbrev-table mizar-mode-abbrev-table)
(make-local-variable 'paragraph-start)
(setq paragraph-start (concat "^::::\\|^$\\|" page-delimiter)) ;'::..'
(make-local-variable 'paragraph-separate)
(setq paragraph-separate paragraph-start)
(make-local-variable 'paragraph-ignore-fill-prefix)
(setq paragraph-ignore-fill-prefix t)
(make-local-variable 'indent-line-function)
(setq indent-line-function 'mizar-indent-line)
(make-local-variable 'comment-start)
(setq comment-start "::")
(make-local-variable 'comment-start-skip)
(setq comment-start-skip "::+ *")
(make-local-variable 'comment-column)
(setq comment-column 48)
(make-local-variable 'comment-indent-function)
(setq comment-indent-function 'mizar-comment-indent)
(setq tags-case-fold-search nil)
; (set (make-local-variable 'tool-bar-map) mizar-tool-bar-map)
(make-local-variable 'font-lock-defaults)
(setq font-lock-defaults
'(mizar-font-lock-keywords nil nil ((?_ . "w"))))
)
(defun mizar-mode-commands (map)
"Set up some initial key bindings (in the keymap MAP) for
common mizar editing functions."
(define-key map "\t" 'mizar-indent-line)
(define-key map ";" 'mizar-semicolon)
(define-key map "\r" 'mizar-newline))
(if mizar-mode-map
nil
(setq mizar-mode-map (make-sparse-keymap))
(define-key mizar-mode-map "\C-c\C-m" 'mizar-it)
(define-key mizar-mode-map "\C-cj" 'mizar-it-parallel)
(define-key mizar-mode-map "\C-cc" 'mizar-compile)
(define-key mizar-mode-map "\C-c\C-n" 'mizar-next-error)
(define-key mizar-mode-map "\C-c\C-p" 'mizar-previous-error)
(define-key mizar-mode-map "\C-c\C-e" 'mizar-strip-errors)
(define-key mizar-mode-map "\C-c\C-d" 'mizar-hide-proofs)
(define-key mizar-mode-map "\C-cp" 'mizar-hide-all-proofs)
(define-key mizar-mode-map "\C-cg" 'mizar-grep-abs)
(define-key mizar-mode-map "\C-c\C-g" 'mizar-grep-full)
(define-key mizar-mode-map "\C-cb" 'mizar-grep-gab)
(define-key mizar-mode-map "\C-ci" 'mizar-grep-abs-full-items)
(define-key mizar-mode-map "\C-c\C-c" 'comment-region)
(define-key mizar-mode-map "\C-c\C-f" 'mizar-findvoc)
(define-key mizar-mode-map "\C-c\C-l" 'mizar-listvoc)
(define-key mizar-mode-map "\C-c\C-t" 'mizar-constr)
(define-key mizar-mode-map "\C-c\C-h" 'mizar-irrths)
(define-key mizar-mode-map "\C-c\C-v" 'mizar-irrvoc)
(define-key mizar-mode-map "\C-c\C-i" 'mizar-relinfer)
(define-key mizar-mode-map "\C-c\C-o" 'mizar-trivdemo)
(define-key mizar-mode-map "\C-c\C-s" 'mizar-reliters)
(define-key mizar-mode-map "\C-c\C-b" 'mizar-chklab)
(define-key mizar-mode-map "\C-c\C-y" 'mizar-relprem)
(define-key mizar-mode-map "\C-c\C-a" 'mizar-inacc)
(define-key mizar-mode-map "\C-c\C-z" 'mizar-make-theorem-summary)
(define-key mizar-mode-map "\C-c\C-r" 'mizar-make-reserve-summary)
(define-key mizar-mode-map "\C-cr" 'mizar-it-remote)
(define-key mizar-mode-map "\C-ca" 'mizar-remote-solve-atp)
(define-key mizar-mode-map "\C-ch" 'mizar-browse-remote)
(define-key mizar-mode-map "\C-ce" 'mizar-show-environ)
(define-key mizar-mode-map "\C-cs" 'mizar-insert-skeleton)
(define-key mizar-mode-map "\C-ct" 'mizar-tex-remote)
(define-key mizar-mode-map "\C-cu" 'mizar-run-all-irr-utils)
(define-key mizar-mode-map "\M-;" 'mizar-symbol-def)
(define-key mizar-mode-map "\M-\C-i" 'mizar-ref-complete)
(define-key mizar-mode-map "\C-c\C-q" 'query-start-entry)
(if (eq mizar-emacs 'xemacs)
(progn
(define-key mizar-mode-map [button3] 'mizar-mouse-symbol-def)
(define-key mizar-mode-map [(shift button3)] 'mizar-mouse-direct-symbol-def)
(define-key mizar-mode-map [(shift button1)] 'mizar-mouse-direct-show-ref)
; (define-key mizar-mode-map [(shift button2)] 'mouse-find-tag-history)
)
(define-key mizar-mode-map [mouse-3] 'mizar-mouse-symbol-def)
(define-key mizar-mode-map [(shift down-mouse-3)] 'mizar-mouse-direct-symbol-def)
(define-key mizar-mode-map [(shift down-mouse-1)] 'mizar-mouse-direct-show-ref)
; (define-key mizar-mode-map [(shift down-mouse-2)] 'mouse-find-tag-history)
; (define-key mizar-mode-map [double-mouse-1] 'mizar-mouse-ref-constrs)
)
(define-key mizar-mode-map "\M-." 'mizar-show-ref)
(define-key mizar-mode-map "\C-c." 'mizar-show-ref-constrs)
(mizar-mode-commands mizar-mode-map))
(defvar mizar-tag-ending ";"
"End of the proper tag name in mizsymbtags and mizreftags.
Used for exact completion.")
(defun miz-complete ()
"Used for exact tag completion."
(interactive )
(if (active-minibuffer-window)
(progn
(set-buffer (window-buffer (active-minibuffer-window)))
(insert mizar-tag-ending)
(minibuffer-completion-help))))
(define-key minibuffer-local-completion-map ";" 'miz-complete)
;;;;;;;;;;;;;;;;;;;;; utilities ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; destructive!
(defun unique (l1)
(let ((l1 l1))
(while l1
(setq l1 (setcdr l1 (delete (car l1) (cdr l1))))))
l1)
(defun file-size (fname)
"Size of a file FNAME."
(elt (file-attributes fname) 7))
(defun file-mtime (fname)
"Modification time of a file FNAME."
(elt (file-attributes fname) 5))
(defun test-list1 (test l1)
"Returns the sublist of L1 consisting of those elements satisfying TEST."
;; Loop without recursion probably better than previous
(let ((l2 ()))
(while l1
(if (funcall test (car l1))
(setq l2 (cons (car l1) l2)))
(setq l1 (cdr l1)))
(reverse l2)))
(defun remove-from (pos l1)
"Destructively deletes members from POS on in L1."
(let* ((l2 l1)
(end (nthcdr (- pos 1) l2)))
(if (consp end)
(setcdr end nil))
l2))
;; reporting stuff stolen from delphi.el
(defvar mizar-progress-last-reported-point nil
"The last point at which progress was reported.")
(defun mizar-progress-start ()
"Initialize progress reporting."
(setq mizar-progress-last-reported-point nil))
(defun mizar-progress-done (&rest msgs)
"Finalizes progress reporting; contents of MSGS are output as messages."
(setq mizar-progress-last-reported-point nil)
(if (null msgs)
(message "")
(apply #'message msgs)))
(defun mizar-step-progress (p desc step-size)
;; If enough distance has elapsed since the last reported point,
;; then report the current progress to the user.
(cond ((null mizar-progress-last-reported-point)
;; This is the first progress step.
(setq mizar-progress-last-reported-point p))
(;(and mizar-verbose
(>= (abs (- p mizar-progress-last-reported-point)) step-size)
;; Report the percentage complete.
(setq mizar-progress-last-reported-point p)
(message "%s %s ... %d%%"
desc (buffer-name) (/ (* 100 p) (point-max))))))
;;;;;;;;;;;; indentation (pretty poor) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defvar mizar-label-regexp "\\b[a-zA-Z_'0-9]+:"
"A regexp matching mizar labels.")
(defun mizar-indent-line ()
"Indent current line as Mizar code."
(interactive)
(let ((indent (mizar-indent-level))
(pos (- (point-max) (point))) beg)
(beginning-of-line)
(setq beg (point))
(skip-chars-forward " \t")
(if (and mizar-align-labels (looking-at mizar-label-regexp))
(let ((lab (match-string 0)))
(goto-char (match-end 0))
(skip-chars-forward " \t")
(delete-region beg (point))
(insert lab)
(if ( > indent (length lab))
(mizar-indent-to (- indent (length lab)))
(insert " ")))
(if (zerop (- indent (current-column)))
nil
(delete-region beg (point))
(mizar-indent-to indent)))
; (indent-to (+ 3 indent)))
(if (> (- (point-max) pos) (point))
(goto-char (- (point-max) pos)))
))
(defun mizar-indent-to (indent)
"Insert a space using INDENT."
(insert-char 32 indent) ) ; 32 is space...cannot use tabs
(defvar mizar-environment-kw-regexp
(concat "\\b" (regexp-opt mizar-environment-keywords t) "\\b")
"Regexp matching environmental keywords.")
(defvar mizar-main-kw-regexp
(concat "\\b" (regexp-opt mizar-main-keywords t) "\\b")
"Regexp matching main keywords.")
(defun mizar-indent-level ()
"Compute mizar indentation level."
(save-excursion
(beginning-of-line)
(skip-chars-forward " \t")
(cond
((looking-at "::::::") 0) ;Large comment starts
((looking-at "::") (current-column)) ;Small comment starts
((looking-at mizar-main-kw-regexp) 0)
((looking-at mizar-environment-kw-regexp) 1)
((looking-at "\\b\\(environ\\|reserve\\|begin\\)\\b") 0)
((bobp) 0) ;Beginning of buffer
(t
(let ((empty t) ind more less res)
;; See previous indentation
(cond ((looking-at "end;") (setq less t))
((looking-at
"\\b\\(proof\\|now\\|hereby\\|case\\|suppose\\)\\b")
(setq more (match-string 0))))
;; Find previous noncommented line
(while empty
(forward-line -1)
(beginning-of-line)
(cond
((bobp) (setq empty nil))
((and mizar-align-labels (looking-at mizar-label-regexp))
(goto-char (match-end 0))
(skip-chars-forward " \t")
(setq empty nil))
(t
(skip-chars-forward " \t")
(if (not (looking-at "\\(::\\|\n\\)"))
(setq empty nil)))))
(if (bobp)
(setq ind 0) ;Beginning of buffer
(setq ind (current-column))) ;Beginning of clause
;; See its beginning
; (if (and more (= ind 2) (string-equal more "proof"))
; 0 ;proof begins inside theorem
;; Real mizar code
(cond ((looking-at "\\b\\(proof\\|now\\|hereby\\|case\\|suppose\\)\\b")
(setq res (+ ind mizar-indent-width)))
((or (looking-at mizar-main-kw-regexp)
(looking-at mizar-environment-kw-regexp)
(looking-at "\\b\\(reserve\\|begin\\)\\b"))
(setq res (+ ind 2)))
(t (setq res ind)))
(if less (max (- ind mizar-indent-width) 0)
res)
))
;)
)))
(defun mizar-comment-indent ()
"Compute mizar comment indentation."
(cond ((looking-at "::::::") 0)
((looking-at "::::") (mizar-indent-level))
(t
(save-excursion
(skip-chars-backward " \t")
;; Insert one space at least, except at left margin.
(max (+ (current-column) (if (bolp) 0 1))
comment-column)))
))
(defun mizar-indent-buffer ()
"Indent the entire mizar buffer."
(interactive )
( indent-region (point-min) (point-max) nil))
(defun mizar-newline ()
"Terminate the current line with a newline and indent the next."
(interactive "*")
;; Remove trailing spaces
(delete-horizontal-space)
(newline)
(mizar-bubble-ref-incremental)
;; Indent both the (now) previous and current line first.
(when mizar-newline-indents
(save-excursion
(previous-line 1)
(mizar-indent-line))
(mizar-indent-line)))
(defun mizar-semicolon (&optional arg)
"Indent if `mizar-semicolon-indents' and insert ARG semicolons."
(interactive "*p")
(self-insert-command (prefix-numeric-value arg))
(if mizar-atp-completion
(mizar-atp-autocomplete))
(mizar-bubble-ref-incremental)
(if mizar-semicolon-indents
(mizar-indent-line)))
;;;;;;;;;;;;;;;; end of indentation ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;; skeletons ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Special lisp parser "lisppars" is used for this
;;; Howto TEST changes to this:
;; * Run lisppars on all accommodated articles - creates .lsp
;; * cat all .lsp into 00all.lsp - quite big
;; * Try Elisp 'read on all lines of 00all.lsp - e.g.
;; (while (not (eobp)) (read (current-buffer)) (forward-line))
;; if OK, lisparse produces only valid lisp expressions
;; * Try calling the rest of functions used for creating
;; the skeleton string - see 'mizar-insert-skeleton for them -
;; ** mainly: mizar-parse-fla:
;; (while (not (eobp))
;; (mizar-parse-fla (cdr (read (current-buffer)))) (forward-line))
;; ** then mizar-default-skeleton-items:
;; (while (not (eobp)) (mizar-default-skeleton-items
;; (car (mizar-parse-fla (cdr (read (current-buffer)))))) (forward-line))
;; ** and finally mizar-skeleton-string:
;; (while (not (eobp)) (mizar-skeleton-string (mizar-default-skeleton-items
;; (car (mizar-parse-fla (cdr (read (current-buffer))))))) (forward-line))
;; * the resulting strings should be valid proof skeletons giving only *4
;; errors, but I haven't written the script which would actually
;; check this so far
;;; TODO:
;; * Have some language for specifying skeleton-creating
;; functions, to allow users (and machines) to define their
;; own custom skeletons.
;;
;; * Our parsing ends at the level of atomic formulas now, both because
;; it is much easier to implement within the current Mizar parser,
;; and because it simplifies the pretty printing in Emacs.
;; So we should extend it to full parsing eventually.
;;
;; * Add e.g. definitional expansions, when the full parsing is done.
;; * Handle thesis in cases, when it is not explicit - e.g. correctness
;; conditions.
;;
;; * When both the macro language and the full parsing is done,
;; do machine learning of optimal skeletons on MML, and be adaptive.
(defvar mizar-binary-connectives '(iff implies or &))
(defvar mizar-quantifiers '(for ex))
(defvar mizar-logical-constants '(thesis contradiction \?))
(defvar mizar-connectives
(append mizar-binary-connectives mizar-quantifiers mizar-logical-constants
'(st holds not))
"Symbols for Mizar logical connectives.")
(defun parse-fla-with (fla connectives)
"The connectives CONNECTIVES come from the lowest priority here, i.e. 'iff comes first."
(if connectives
(let* (tmp (conn1 (car connectives)) (restconn (cdr connectives))
(fla (parse-fla-with fla restconn))
(beg (car fla)) (conn (cadr fla)))
(if (eq conn conn1)
(progn
(setq beg (cons conn (list beg))
fla (cdr fla))
(while (eq conn conn1)
(setq tmp (parse-fla-with (cdr fla) restconn)
beg (append beg (list (car tmp)))
fla (cdr tmp)
conn (if fla (car fla) nil)))
(cons beg fla))
fla))
(get-first-formula fla)))
(defun get-first-formula (fla)
"Parse the first quantified, atomic, bracketed or negated FLA into a list.
Return list of the rest unparsed, with added car being the parsed first."
(let ((beg (car fla)))
(cond
((listp beg) fla)
((or (stringp beg) (memq beg mizar-logical-constants))
(cons (list beg) (cdr fla)))
((eq 'not beg)
(let ((cont (get-first-formula (cdr fla))))
(cons (list 'not (car cont)) (cdr cont))))
((and (eq 'does beg) (eq 'not (cadr fla)))
(let ((cont (get-first-formula (cddr fla))))
(cons (list 'does 'not (car cont)) (cdr cont))))
((eq 'ex beg)
(let ((tmp (parse-formula (cdddr fla))))
(cons (list 'ex (cadr fla) 'st (car tmp)) (cdr tmp))))
((eq 'for beg)
(let (rest (start (list 'for (cadr fla))))
(if (eq 'st (third fla))
(setq fla (parse-formula (cdddr fla))
start (nconc start (list 'st (car fla)))
rest (cdr fla))
(setq rest (cddr fla)))
(if (eq 'holds (car rest))
(setq start (nconc start (list 'holds))
rest (cdr rest)))
(setq rest (parse-formula rest))
(cons (nconc start (list (car rest))) (cdr rest))))
(t (error "Bad formula: %s" (prin1-to-string fla))))))
(defun parse-formula (fla)
"Return the tree of the longest parsable initial segment of FLA.
The rest is returned as cdr.
The lists arising from having parenthesis must have already been handled here."
(let ((res (get-first-formula fla)))
(if (cdr res)
(parse-fla-with res mizar-binary-connectives)
res)))
(defun mizar-parse-protect-brackets (fla)
"Replace sublists in FLA with parsed sublists beginning with
'PAR recursively. Exceptions are sublist starting with 'Q, which
denote qualified segments."
(if (or (not (listp fla)) (eq 'Q (car fla))) fla
(cons 'PAR (parse-formula (mapcar 'mizar-parse-protect-brackets fla)))))
(defun mizar-parse-fla (fla)
"The top-level function for parsing lisppars output."
(parse-formula (mapcar 'mizar-parse-protect-brackets fla)))
(defun current-line ()
"Return current line number."
(+ (count-lines 1 (point))
(if (= (current-column) 0) 1 0)))
(defun mizar-tmp-being-hack (txt)
"Replace occurrences of `be' by `being' in the text TXT.
This is a temporary hack; it won't be needed after the be2being
fixes to Mizar parser are published."
(replace-regexp-in-string " +be " " being " txt))
(defun mizar-parse-region-fla (beg end)
"Call the lisppars utility to parse a Mizar formula starting at BEG.
BEG must be a start of a top-level sentence, parsing subformulas or
definiens formulas is not handled now.
END is not needed for parsing but for annotating the result
with the position, where the skeleton of its proof should start.
See `mizar-insert-skeleton' for more."
(interactive "r")
(save-excursion
(goto-char beg)
(let (fla (bline (current-line)) (bcol (+ 1 (current-column)))
(lspname (concat (file-name-sans-extension (buffer-file-name))
".lsp" )))
(mizar-it "lisppars" nil nil t)
(or (file-readable-p lspname)
(error "The lisppars utility failed, unknown error!"))
(with-temp-buffer
(insert-file-contents lspname)
(goto-char (point-min))
(unless (re-search-forward (concat "^((pos " (int-to-string bline) " .*")
(point-max) t)
(error "No formula starting at line %d" bline))
;; car is position
(setq fla (mizar-parse-fla
(cdr (read (mizar-tmp-being-hack (match-string 0)))))))
(goto-char end)
(list end (car fla))))) ;; fla is singleton
(defun mizar-pp-types (types)
(or (eq 'Q (car types))
(error "Bad qualified segment: %s" (prin1-to-string types)))
(mapconcat 'car (cdr types) ""))
(defun mizar-pp-parsed-fla (fla)
(if (stringp fla) (concat fla " ")
(let ((beg (car fla)))
(cond
((stringp beg) beg)
((eq 'PAR beg)
(concat "(" (mizar-pp-parsed-fla (cadr fla)) ")"))
((eq 'Q beg)
(mizar-pp-types fla))
((eq 'not beg)
(concat "not " (mizar-pp-parsed-fla (cadr fla))))
((and (eq 'does beg) (eq 'not (cadr fla)))
(concat "does not " (mizar-pp-parsed-fla (caddr fla))))
((memq beg mizar-logical-constants) (symbol-name beg))
((memq beg mizar-binary-connectives)
(mapconcat 'mizar-pp-parsed-fla (cdr fla)
(concat " " (symbol-name beg) " ")))
((eq 'ex beg)
(concat "ex " (mizar-pp-types (cadr fla)) "st "
(mizar-pp-parsed-fla (fourth fla))))
((eq 'for beg)
(let* ((st_occurs (eq 'st (third fla)))
(rest (if st_occurs (cddddr fla) (cddr fla))))
(concat
"for " (mizar-pp-types (cadr fla))
(if st_occurs (concat "st " (mizar-pp-parsed-fla (fourth fla))) " ")
(if (eq 'holds (car rest))
(concat "holds " (mizar-pp-parsed-fla (cadr rest)))
(mizar-pp-parsed-fla (car rest))))))
(t (error "Unexpected formula: %s" (prin1-to-string fla)))
))))
(defvar mizar-replace-dupl-spaces-skeletons t)
(defun mizar-skelitem-string (item)
"A string representation of the skeleton item ITEM."
(let ((res (replace-regexp-in-string
" *; *$" ";" (mapconcat 'mizar-pp-parsed-fla item " "))))
(if mizar-replace-dupl-spaces-skeletons
(replace-regexp-in-string " +" " " res)
res)))
(defun mizar-skeleton-string (skel)
"Print the proof skeleton for parsed formula FLA into a string.
The skeleton SKEL is a list of of items, each item is a list of either strings
or lists containing parsed formulas, which are later handed over to
`mizar-pp-parsed-fla'."