-
Notifications
You must be signed in to change notification settings - Fork 2
/
pasc-mode.el
3299 lines (2979 loc) · 121 KB
/
pasc-mode.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
;;; pasc-mode.el -- Pascal mode -- Major mode for editing Pascal programs.
;; Copyright (c) 1990 - 2001 Inge Frick
;;; LCD Archive Entry:
;; pasc-mode|Inge Frick|inge@kth.nada.se|Pascal mode
;; |$Date 01/11/20 $|$Revision: 1.13 $|
;; Author: Inge Frick (inge@nada.kth.se)
;; Created: June 1990
;; Version: 1.13
;; Keywords: pascal languages
;; Last edited: Tue Nov 20 16:52:57 2001 by Inge Frick <inge@nada.kth.se>
;; This pascal-mode has borrowed and changed a lot from the pascal-mode by
;; Glen J. Ditchfield (gjditchfield@violet.uwaterloo.ca), some ideas come
;; from the pascal-mode by Magnus Hyllander and
;; Bjorn Gronvall (bjorng@nada.kth.se). Things have also been borrowed
;; from the pascal-mode by Espen Skoglund (espensk@stud.cs.uit.no).
;; This file is not part of GNU Emacs (yet).
;; This file is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY. Neither the author nor any distributor
;; accepts responsibility to anyone for the consequences of using it
;; or for whether it serves any particular purpose or works at all,
;; unless he says so in writing. Refer to the GNU Emacs General Public
;; License for full details.
;; Everyone is granted permission to copy, modify and redistribute
;; this file, but only under the conditions described in the
;; GNU Emacs General Public License. A copy of this license is
;; supposed to have been given to you along with GNU Emacs so you
;; can know your rights and responsibilities. It should be in a
;; file named COPYING. Among other things, the copyright notice
;; and this notice must be preserved on all copies.
;;; Commentary:
;;
;; Pascal-mode can do the following:
;; Indent Pascal code correctly. The indentation style can be changed.
;; Movement, marking and deletion by procedure, sentence and expression.
;; Templates for insertion of all syntactic constructs.
;; Some further commands. See the documentation string for `pascal-mode'.
;;; Change Log:
;;
;; Version 1.13
;; Minor changes in comments and comment strings.
;; Switched meaning for pascal-return so that by default
;; <nl> indents and <cr> doesn't.
;; Changed custom method for indents. Indents can now be absolute or
;; a multiple of new variabel pascal-default-indent. Coversion from
;; from multiple to absolute is done by new function pascal-get-indent.
;; (pascal-indent-end, pascal-indent-relative, pascal-add-indent,
;; pascal-indent-in-do, pascal-block-follow) use pascal-get-indent.
;; (pascal-indent-else, pascal-indent-then, pascal-indent-in-if):
;; change pascal-match-if to pascal-find-matching-if.
;; New variable pascal-start-ignored-line.
;; pascal-white-forward: use pascal-start-ignored-line intead of
;; calling pascal-ignore-line.
;; pascal-do-fill: bind fill-column temprorarily instead of setting
;; and the resetting it.
;; pascal-transpose-procedures, pascal-transpose-sentences,
;; pascal-transpose-sexps: argument is now optional.
;; pascal-upcase-keywords, pascal-capitalize-standardnames are
;; now marked interactive "*r".
;; Moved pascal-indent-fn and pascal-do-calculate-indent forward
;; a bit.
;; pascal-find-dekl: use regexp-opt.
;;
;; Version 1.12
;; Make pascal ignore line that start matching pascal-dont-indent.
;; (pascal-search-ignore-backward, pascal-search-ignore-forward): new
;; functions that are called instead of re-search-backward and
;; re-search-forward.
;; (pascal-beginnify-region, pascal-search-back-skip-general-paren,
;; pascal-search-backward, pascal-in-paren, pascal-skip-comment-backward,
;; pascal-point-in-comment-or-string): use pascal-search-ignore-backward
;; instead of re-search-backward.
;; (pascal-comment-out-lines, pascal-set-comment-delim, pascal-end-snts,
;; pascal-search-forward, pascal-set-bracket, pascal-skip-comment-forward
;; pascal-point-in-comment-or-string): use pascal-search-ignore-forward
;; instead of re-search-forward.
;; (pascal-white-forward, pascal-white-backward): ignore dont-indet lines.
;; (pascal-indent-fn): no indentation for lines starting with linefeed.
;;
;; Version 1.11
;; Variables are now customizable.
;; pascal-extra-keywords, pascal-keywords, pascal-extra-standardnames
;; and pascal-standardnames are now lists of strings and not regular
;; expressions.
;; regexp-opt is used to set pascal-relative-indents,
;; pascal-indent-parens, pascal-font-lock-keywords,
;; pascal-sentence-left-delim, pascal-contain-sentence-left-delim,
;; pascal-continued-statement-start, pascal-procedure-forward-regex,
;; pascal-head-backward-regex and pascal-head-regex.
;; Use defconst instead of defvar to define pascal-number-regexp.
;; Define pascal-mode-map entirely by its defvar definition.
;; Correct key-bindings for pascal-end-sentence and
;; pascal-beginning-sentence.
;; Define pascal-syntax-table entirely by its defvar definition.
;; Make pasc-mode usable for XEmacs:
;; Define zmacs-activate-region for Emacs and use it in
;; pascal-mark-procedure, pascal-mark-sentence and pascal-mark-sexp.
;; Define region-exists-p for Emacs and buffer-substring-no-properties
;; for Xemacs. Use easy-menu to define the pascal menu.
;; (pascal-upcase-keywords); use regexp-opt to make regexp from
;; pascal-standard-keywords and pascal-extra-keywords.
;; (pascal-capitalize-standardnames); use regexp-opt to make regexp from
;; pascal-standard-standardnames and pascal-extra-standardnames.
;; (pascal-uncomment-out-lines): new command.
;;
;; Version 1.10
;; New commands: pascal-indent-procedure indents lines in the procedure
;; surrounding point. pascal-transpose-procedures is similar to
;; transpose-words but transposes procedures or functions instead.
;; A transpose entry in the pascal menu.
;; Fixed bugs in pascal-end-sentence and pascal-skip-procedure:
;; now a semicolon after a sentence is always included in the sentence,
;; this means that pascal-transpose-sentences now works.
;;
;; Version 1.09
;; Support for pasc-semicolon.el which is paren.el hacked to show
;; sentence start and end. Load pasc-semicolon.el and when point is
;; immediately after a semicolon, then the semicolon and the start of
;; the sentence ended by that semicolon is highlighted. A new variable
;; pascal-blink-sentence-start-on-screen that is turned off by
;; pasc-semicolon.el.
;; A new command: pascal-run which is similar to pascal-compile, but
;; runs a command in a shell buffer. This can be used to run pascal
;; programs in a shell buffer. The error message parsing supporting the
;; next-error command can be done in this buffer. With the proper
;; regular expressions, run time errors can also be found. pascal-run
;; requires compile-in-shell.el and a modified compile.el that supports
;; the compilation-shell-minor-mode.
;; A new variable pascal-error-regexp-alist which if not nil is used
;; instead of compilation-error-regexp-alist for parsing error
;; messages.
;; A number of new key bindings and a menu-bar menu for most commands.
;;
;; Version 1.08
;; To make it easier to adjust for different pascals there are some
;; new variables.
;; pascal-number-regexp recognizes a pascal number.
;; pascal-equal-ops contains a list of single characters like ?+ that
;; can be combined in C-like constructs like +=. Used in
;; pascal-electric-equal.
;; pascal-extra-keywords and pascal-extra-standardnames matches
;; extra words for pascal-keywords resp pascal-standardnames.
;; Improved pattern in pascal-font-lock-keywords.
;; To support a pascal-label-regexp that could recognize labels, change
;; in pascal-indent-label, pascal-find-declaration, pascal-find-dekl
;; and pascal-indent-after-semi.
;; Use buffer-substring-no-properties instead of buffer-substring in
;; most cases.
;; Syntax table changed a little. Use word syntax more.
;; Removed reference to some old emacs18 variables: comment-indent-hook,
;; auto-fill-hook and screen-width. These references have only been
;; commented out you can still find them in the code.
;; The default for pascal-blink-sentence-start and
;; pascal-comment-default have changed.
;;
;; Version 1.07
;; A new command pascal-comment-out-lines. See its documentation
;; string for details.
;;
;; Version 1.06
;; The help string for pascal-mode now gives the version number.
;; Changed comments after end in pascal-electric-semi.
;; The blinking at matching '[' or '(' is now done by the new
;; function 'pascal-blink-paren'. The only exterior change is
;; that no blinking is done if 'blink-paren-function' is nil.
;;
;; Version 1.05
;;
;; Small change in pascal-keywords. Some keywords where not recognized
;; and therefore not converted to upper case by pascal-upcase-keywords.
;; A number of spelling errors have been corrected.
;;
;; Version 1.04
;; Added commands pascal-upcase-keywords and
;; pascal-capitalize-standardnames.
;; Added customization variable pascal-ignore-block-after-do. This
;; replaces pascal-block-indent, that now has no effect.
;; Fixed bug in pascal-electric-semi.
;;
;; Version 1.03
;; Extensive changes.
;;; Todo:
;;
;; The code for special abbrevs should be replaced by dmacros using
;; dmacro by Wayne Mesard.
;(require 'dmacro)
;;
;; More intelligent indentation of labels, cases and record fields.
;;
;; Pascal-complete-symbol similar to lisp-complete-symbol (and bound to
;; the same key). This requires parsing of declarations so that a
;; database of symbols can be built and it requires a function that
;; finds out what type of symbol is expected at the current position in
;; the code.
;; To get reasonable speed, the idea is to have a database that is not
;; aware of the pascal block structure, instead all definitions of a
;; symbol are available at the same time. If the database is to know about
;; blockstructure so that only one (or no) definition is available at a
;; time, then the position in the block structure will have to be
;; recomputed every time the database is queried.
;;; Code:
(require 'idcase) ; This defines the minor mode id-case-significant.
(require 'easymenu) ; Define menu items for both emacs 19 and xemacs.
;; Some code for compatibility between emacs 19 and xemacs.
(or (fboundp 'region-exists-p)
(defun region-exists-p () mark-active))
(or (fboundp 'zmacs-activate-region)
(defun zmacs-activate-region () (setq mark-active t)))
;; XEmacs apparently call this `buffer-substring-without-properties',
;; sigh.
(or (fboundp 'buffer-substring-no-properties)
(fset 'buffer-substring-no-properties
(if (fboundp 'buffer-substring-without-properties)
'buffer-substring-without-properties
'buffer-substring)))
;; Customization variables:
(defgroup pascal nil
"Major mode for editing Pascal programs."
:prefix "pascal-"
:group 'languages)
(defgroup pascal-indent nil
"Indentation settings"
:group 'pascal)
;; The following variables are only used once, most of them when pascal mode
;; is started. If you change them after pascal mode has been started, then you
;; have to execute some command or restart pascal mode (by the pascal-mode
;; command) for the change to take effect.
;; Change the following two properties if you use other names for the
;; distributed template files.
;; File containing default templates for pascal when case is insignificant.
(put 'pascal-nocase-template-table 'file "pasc-1tmpl")
;; File containing default templates for pascal when case is significant.
(put 'pascal-case-template-table 'file "pasc-2tmpl")
;; If you mainly use a pascal where case is significant, set the following
;; variable to t, otherwise set it to nil. This variable is used to set the
;; minor mode id-case-significant when pascal-mode is started. To change it
;; after pascal-mode has been started, use the command id-case-significant.
(defcustom pascal-case-significant nil
"Default value for minor-mode id-case-significant in pascal mode.
If nil, map all words to lower case. Command `id-case-significant' toggles.
If T, BEGIN etc. are not keywords. Also affects which templates are used."
:type '(choice :tag "Case":value nil
(const :tag "Case insignificant" nil)
(const :tag "Case significant" t))
:group 'pascal)
;; This variable is used when pascal-mode is started.
;; The default value of pascal-return is nil, which means that <nl> first
;; indents then gets a new indented line and <cr> only gets a new line.
;; In my opinion the normal action which is indent, should be bound to the
;; easier accessed key <cr>, but the present default is chosen to agree with
;; other language modes like c-mode and lisp-mode.
(defcustom pascal-return nil
"Determine if <cr> or <nl> will indent current and next line.
nil means <nl> indents and <cr> not.
The command `pascal-return' reverses this."
:type '(choice :tag "Who indents" :value nil
(const :tag "<nl> indents" nil)
(const :tag "<cr> indents" t))
:group 'pascal)
;; The first time comment-start is needed (in indent-for-comment) then the
;; function pascal-set-comment-delim is called automatically and sets
;; comment-start from pascal-comment-start-international or from
;; pascal-comment-start-ascii. At the same time comment-end is set from
;; pascal-comment-end-international or pascal-comment-end-ascii. Which
;; alternative that is used depends on the first comment delimiter that is
;; found in the buffer or the value of the variable pascal-comment-default.
;; The following five variables are only used to set comment-start and
;; comment-end once for each buffer. If you want to change comment-start or
;; comment-end after that, then you have to call pascal-set-comment-delim
;; again.
;; The following variable is consulted by the function pascal-set-comment-delim
;; if there is no comment delimiter in the buffer.
(defvar pascal-comment-default 0 ; 0 means use { as a delimiter
"Determine what comment delimiter to use in buffer with no previous comment.
If nil then ask, else if > 0, use (* for comment, else use {.")
;; The following variables define comment delimiters.
(defvar pascal-comment-start-international "(* "
"Preferred international comment opener.")
(defvar pascal-comment-end-international " *)"
"Preferred international comment closer.")
(defvar pascal-comment-start-ascii "{ "
"Preferred ascii comment opener.")
(defvar pascal-comment-end-ascii " }"
"Preferred ascii comment closer.")
(defvar pascal-mode-hook nil
"Functions to run when entering pascal mode.")
;; The following variables are referred to many times by pascal mode. A change
;; to a variable any time affects the future of pascal mode.
;; The following string describes the command to compile a file that is used
;; by the pascal-compile command. It is a format string that is given the
;; name of the file to compile as argument. It can be changed by the user,
;; but should originally contain a default. Change it to contain a suitable
;; default for your installation.
(defcustom pascal-compile-format "compile %s"
"*Compile command format."
:type 'string
:group 'pascal)
(defcustom pascal-run-format "run %s"
"*Run command format."
:type 'string
:group 'pascal)
(defvar pascal-error-regexp-alist nil "\
Nil or an alist of regular expressions matching compilation or running errors.
If not nil this is used instead of `compilation-error-regexp-alist' in
Pascal Compile or Pascal Run. See `compilation-error-regexp-alist'.")
(defcustom pascal-put-end-comment nil
"*Control automatic comment at `end;'.
If nil do nothing, if t put name at procedure end, otherwise put comment at all
`end;'."
:type '(choice :value nil
(const :tag "No comment" nil)
(const :tag "Name at procedure end" t)
(const :tag "Comment after all end;" 1))
:group 'pascal)
(defcustom pascal-auto-newline nil
"*If non-nil, `;' at the end of a line causes a newline to be inserted."
:type 'boolean
:group 'pascal)
(defcustom pascal-blink-sentence-start t
"*If non-nil, ';' causes matching sentence start to be shown."
:type 'boolean
:group 'pascal)
(defcustom pascal-blink-sentence-start-on-screen t
"*If non-nil, ';' causes matching sentence start to be shown, if on screen."
:type 'boolean
:group 'pascal)
(defcustom pascal-auto-string nil
"*If non-nil, a ' in code will insert '' with point in between."
:type 'boolean
:group 'pascal)
(defcustom pascal-auto-paren nil
"*If non-nil, a ( in code will insert () with point in between."
:type 'boolean
:group 'pascal)
(defvar pascal-auto-bracket nil
"*Determine what will be inserted in code by the keys `[' or `]'.
If nil then insert `[' resp `]'.
If non-nil insert `[' resp `]' or `(.' resp `.)' depending on what has been
used before.
If non-nil and not t, then the key `[' will insert `['`]' or `(.'`.)' with
point in between.")
(defvar pascal-auto-curly nil
"*Determine what will be inserted in code by the keys `{' or `}'.
If nil then insert `{' resp `}'.
If non-nil insert `{' resp `}' or `(*' resp `*)' depending on what has been
used before.
If non-nil and not t, then the key `{' will insert `{'`}' or `(*'`*)' with
point in between.")
;; Parsing of declarations not implemented yet. Do not change this variable.
(defconst pascal-parse nil)
(defcustom pascal-tab-always-indent t
"*Non-nil means TAB in pascal mode always re-indents the current line,
regardless of where in the line point is when the TAB command is used.
nil means, TAB indents the current line only if point is at the left margin
or in the line's indentation; otherwise a tab is inserted."
:type 'boolean
:group 'pascal)
(defconst pascal-indent-type
'(choice (const :tag "pascal-default-indent" +)
(const :tag "2 * pascal-default-indent" ++)
(const :tag "pascal-default-indent / 2" *)
(const :tag "- pascal-default-indent" -)
(const :tag "-2 * pascal-default-indent" --)
(const :tag "- pascal-default-indent / 2" /)
(const :tag "no extra indentation" 0)
integer))
;; The following variables defines how much to indent.
(defcustom pascal-default-indent 2
"*Default indent. Other indents can be absolute value or a factor times this."
:type 'integer
:group 'pascal-indent)
(defcustom pascal-program-decl-indent 0
"*Indentation of top level LABEL, CONST, TYPE and VAR."
:type pascal-indent-type
:group 'pascal-indent)
(defcustom pascal-procedure-decl-indent '+ "\
*Indentation of LABEL, CONST, TYPE and VAR with respect to current procedure."
:type pascal-indent-type
:group 'pascal-indent)
(defcustom pascal-decl-decl-indent '+ "\
*Indentation for declarations relative to preceding LABEL, CONST, TYPE or VAR."
:type pascal-indent-type
:group 'pascal-indent)
(defcustom pascal-record-field-indent '+
"*Extra indentation of RECORD fields."
:type pascal-indent-type
:group 'pascal-indent)
(defcustom pascal-of-type-indent '+
"*Indentation of type with relative start of array or set-declaration."
:type pascal-indent-type
:group 'pascal-indent)
(defcustom pascal-program-procedure-indent 0
"*Indentation of top level procedure."
:type pascal-indent-type
:group 'pascal-indent)
(defcustom pascal-procedure-procedure-indent '+
"*Indentation of procedure inside procedure."
:type pascal-indent-type
:group 'pascal-indent)
(defcustom pascal-program-block-indent 0
"*Indentation of top block of program."
:type pascal-indent-type
:group 'pascal-indent)
(defcustom pascal-procedure-block-indent '+
"*Indentation of top block relative to start of procedure."
:type pascal-indent-type
:group 'pascal-indent)
(defcustom pascal-block-statement-indent '+
"*Indentation of statements relative surrounding block."
:type pascal-indent-type
:group 'pascal-indent)
(defcustom pascal-block-end-indent 0
"*Indentation of end or until relative start of block."
:type pascal-indent-type
:group 'pascal-indent)
(defcustom pascal-if-then-indent '+
"*Indentation of consequent relative start of if-statement."
:type pascal-indent-type
:group 'pascal-indent)
(defcustom pascal-if-else-indent 0
"*Indentation of else relative start of if-statement."
:type pascal-indent-type
:group 'pascal-indent)
(defcustom pascal-do-indent '+
"*Indentation of statement relative start of while, for or with-statement."
:type pascal-indent-type
:group 'pascal-indent)
(defcustom pascal-continued-list-indent '*
"*Indentation of list element relative beginning of list."
:type pascal-indent-type
:group 'pascal-indent)
(defcustom pascal-continued-statement-indent '+
"*Extra indentation of other statement continuations."
:type pascal-indent-type
:group 'pascal-indent)
(defcustom pascal-ignore-block-after-do nil
"*If true, BEGIN--END have no affect on indentation, after THEN, ELSE or DO."
:type 'boolean
:group 'pascal-indent)
;; This is a list of single characters like ?+ that can be combined in
;; C-like constructs like +=. Add extra characters for your pascal.
(defvar pascal-equal-ops '(?\+ ?\- ?\* ?\/ ?\& ?\! ?\|)
"List of characters that can be combined in C-like constructs as += .")
;; Change this for your pascal. Used in pascal-upcase-keywords.
(defcustom pascal-extra-keywords
'("extern" "external" "others" "otherwise")
"*List of extra keywords for this pascal."
:type '(repeat string)
:group 'pascal)
;; This recognizes all standard pascal keywords.
(defvar pascal-standard-keywords
'("program"
"label" "const" "type" "var"
"packed" "array" "record" "set" "file"
"function" "procedure" "forward"
"begin" "end" "while" "do" "repeat" "until" "for" "to" "downto"
"if" "then" "else" "case" "of" "goto" "with"
"not" "and" "or" "in" "div" "mod"
"nil"))
;; Change this for your pascal. Used in pascal-capitalize-standardnames.
(defcustom pascal-extra-standardnames '()
"*List of strings: extra standard names for this pascal."
:type '(repeat string)
:group 'pascal)
;; This recognizes all standard pascal predefined standard names.
(defvar pascal-standard-standardnames
'("integer" "real" "char" "boolean" "text"
"true" "false" "maxint"
"input" "output"
"reset" "rewrite" "eof" "eoln" "page"
"read" "readln" "write" "writeln" "get" "put"
"chr" "ord" "pred" "succ"
"trunc" "round" "abs" "sqr" "odd"
"sqrt" "sin" "cos" "arctan" "ln" "exp"
"new" "dispose"))
;; The following regular expression recognizes keywords for which
;; indentation is done relative to where they are and not relative to
;; where they would be if there was only white space in front of them
;; on the line.
(defvar pascal-relative-indents
(concat
"[([]\\|"
(regexp-opt
'("record")
t)
"\\>")
"*Regular expression recognizing keywords with relative indentation.")
;; The following regular expression recognizes keywords and characters such
;; that if they are followed on the same line by a sentence, then the
;; following lines are indented so that sentences are placed directly under
;; this first sentence.
(defvar pascal-indent-parens
(concat
"[[(:]\\|"
(regexp-opt
'("label" "const" "type" "var"
"function" "procedure" "program"
"record"
"begin" "repeat" "of")
t)
"\\>")
"*Regular expression recognizing indentation parenthesis.")
(defcustom pascal-indent-comments-separately t
"*What to do with right margin comments when indenting code.
If nil, move comments with code when indenting, if t try to keep current
column. If not t or nil, indent comment to `comment column'."
:type `(choice (const :tag "Move comments with code" nil)
(const :tag "Try to keep current column" t)
(const :tag "Indent to `comment column'" 1))
:group 'pascal-indent)
(defcustom pascal-right-margin 78
"If `pascal-fix-comment' is a number use this as comment margin."
:type 'integer
:group 'pascal-indent)
(defcustom pascal-fix-comment 8
"Determine if to stay within `pascal-right-margin'.
Must be nil or a positive integer N. If not nil, try to keep the end of the
line within `pascal-right-margin' by either (if possible) indenting a comment
to a position that is an integer multiple of `pascal-fix-comment' left of
`comment-column' , or (if necessary) indent the comment with just one space
after the code."
:type '(choice (integer :tag "Comment backtab")
(const :tag "Don't stay within margin" nil))
:group 'pascal-indent)
(defcustom pascal-indent-comment-fn 'pascal-calculate-indent-within-comment
"*Nil or function to call to indent block comments."
:type '(choice (const nil) function)
:group 'pascal-indent)
(defcustom pascal-star-starts '(?* ?! ?| ?+)
"*List of chars that frame block comments."
:type '(repeat char)
:group 'pascal)
(defcustom pascal-dont-indent "#"
"Regular expression used as last argument to `indent-code-rigidly'.
If matched at the beginning of a line, this means don't indent that line
and ignore this line when indenting next line."
:type '(choice (const nil) regexp)
:group 'pascal-indent)
(defcustom pascal-start-ignored-line "^#"
"nil or regular expression matching beginning of an ignored line."
:type '(choice (const nil) regexp)
:group 'pascal-indent)
;;If comment-multi-line-ok is false, pascal-point-in-comment-or-string
;; will not expect multi line comments. This will speed things up a little but
;; it means that various routines might be confused by a multi line comment.
(defcustom comment-multi-line-ok t
"False means don't expect multi-line comments.
This will speed up things a little but it means that various routines
might be confused by a multi line comment."
:type 'boolean
:group 'pascal)
(defcustom pascal-keywords-only nil
"If true only keywords are fontified."
:type 'boolean
:group 'pascal)
;; This is modified from the pascal.el by Espen Skoglund.
(defvar pascal-font-lock-keywords
(list
'("\\<\\(function\\|pro\\(cedure\\|gram\\)\\)\\>[ \t]*\\(\\w+\\)?"
(1 font-lock-keyword-face) (3 font-lock-function-name-face nil t))
(cons (concat
"\\<"
(regexp-opt
'("integer" "real" "char" "boolean" "text"
"packed" "array" "record" "set" "file")
t)
"\\>")
'font-lock-type-face)
'("\\<\\([0-9]+\\)[ \t]*:" 1 font-lock-reference-face)
(cons (concat
"\\<"
(regexp-opt
'("label" "const" "type" "var"
"forward" "extern" "external"
"begin" "end" "while" "do" "repeat" "until" "for" "to" "downto"
"if" "then" "else" "case" "of" "with"
"not" "and" "or" "in" "div" "mod"
"nil")
t)
"\\>")
`font-lock-keyword-face)
'("\\<\\(goto\\)\\>[ \t]*\\([0-9]+\\)?"
(1 font-lock-keyword-face) (2 font-lock-reference-face nil t)))
"Additional expressions to highlight in Pascal mode.")
(defcustom pascal-comment-out-start "(*% "
"\\<pascal-mode-map>String inserted by \\[pascal-comment-out-lines] to start commenting out code.
This string may not appear for any other purpose in the program."
:type 'string
:group 'pascal)
(defcustom pascal-comment-out-end " %*)"
"\\<pascal-mode-map>String inserted by \\[pascal-comment-out-lines] to end commenting out code.
This string may not appear for any other purpose in the program."
:type 'string
:group 'pascal)
;; End of customization variables.
;; The rest of the variables here are not intended to be changed.
;; An unsigned integer or floating point number.
;; The first subexpression must recognize an integer.
(defconst pascal-number-regexp
"\\([0-9]+\\)\\(\\.[0-9]+\\)?\\([eE][-+]?[0-9]+\\)?")
;; Generalized right parenthesis.
(defconst pascal-general-right-paren "[]'})]\\|\\(end\\|until\\)\\>")
;; Pattern for beginning of a sentence. ;
(defconst pascal-sentence-left-delim
(concat
"[')};]"
"\\|\\<"
(regexp-opt
'("label" "const" "type" "var"
"record"
"begin" "end" "repeat" "until" "case")
t)
"\\>"))
;; Pattern for beginning of a composite sentence. ]([
(defconst pascal-contain-sentence-left-delim
(concat
"[]')}([]"
"\\|\\<"
(regexp-opt
'("label" "const" "type" "var"
"record"
"begin" "end" "repeat" "until" "case")
t)
"\\>"))
;; Pattern for position relative which to indent a continued statement
(defconst pascal-continued-statement-start
(concat
"[]')}:;[(]"
"\\|:="
"\\|(\\."
"\\|\\<"
(regexp-opt
'("program"
"label" "const" "type" "var"
"packed" "array" "record" "set" "file"
"function" "procedure" "forward" "extern" "external"
"begin" "end" "while" "do" "repeat" "until" "for" "to" "downto"
"if" "then" "else" "case" "of" "goto" "with")
t)
"\\>"))
;; Pattern for beginning of an assignment statement. Must contain '})
(defconst pascal-assignment-start
"['}:;)]\\|\\<\\(begin\\|repeat\\|do\\|then\\|else\\|otherwise\\)\\>")
;; (defconst pascal-statement-end "['{(;]\\|\\<\\(end\\|until\\|else\\)\\>"
;; "Regular expression describing delimiters for statement end")
;; Pattern for label
(defconst pascal-label-regexp
"\\([0-9]+\\)\\([ \t]*:\\)\\([ \t]*\\)")
;; Pattern for skipping procedure forward
(defconst pascal-procedure-forward-regex
(concat
"['{(]"
"\\|\\<"
(regexp-opt
'("begin" "extern" "external" "function" "forward" "procedure")
t)
"\\>"))
;; Pattern for backward head search
(defconst pascal-head-backward-regex
(concat
"['})]"
"\\|\\<"
(regexp-opt
'("begin" "end" "extern" "external" "forward" "function"
"procedure" "program")
t)
"\\>"))
;; Pattern for seeing head
(defconst pascal-head-regex
(concat (regexp-opt '("program" "procedure" "function") t) "\\>"))
;; Simplified pascal-head-backward-regex
(defconst pascal-head-back-regex
(concat "['})]\\|\\<" pascal-head-regex))
;; Pattern for finding current function or procedure.
(defconst pascal-proc-head
(concat "['{(]\\|\\<" pascal-head-regex))
;; Pattern for id declaration
(defconst pascal-id-declare-regex
"[[.,;(]\\|\\(record\\|label\\|const\\|type\\|var\\|procedure\\|function\\)\\>"
)
;; Pattern for parameter types
(defconst pascal-param-type-regex "\\(var\\|procedure\\|function\\)\\>")
;; white space characters
(defconst pascal-white " \t\n\^l\^m")
;; white space characters on a line
(defconst pascal-white-ln " \t")
(defconst pascal-comment-start-regexp "{\\|(\\*")
(defconst pascal-comment-end-regexp "}\\|\\*)")
(defvar pascal-bracket-start nil)
(defvar pascal-bracket-end nil)
(defvar pascal-comment-start nil)
(defvar pascal-comment-end nil)
;; Last known status (comment, string or code).
(defvar pascal-last-state nil)
;; Position where last known status was computed.
(defvar pascal-state-pos nil)
(defvar pascal-mode-map
(progn
(setq pascal-mode-map (make-sparse-keymap))
;; The key definitions are printed in reverse order in the help string
(define-key pascal-mode-map "\e\C-h" 'pascal-mark-procedure)
(define-key pascal-mode-map "\e\C-e" 'pascal-end-procedure)
(define-key pascal-mode-map "\e\C-a" 'pascal-beginning-procedure)
(define-key pascal-mode-map "\C-xt" 'pascal-transpose-sentences)
(define-key pascal-mode-map "\C-x\C-?" 'pascal-backward-kill-sentence)
(define-key pascal-mode-map "\ek" 'pascal-kill-sentence)
(define-key pascal-mode-map "\C-x@" 'pascal-mark-sentence)
(define-key pascal-mode-map "\ee" 'pascal-end-sentence)
(define-key pascal-mode-map "\ea" 'pascal-beginning-sentence)
;; (define-key pascal-mode-map "\e\C-u" 'pascal-back-up-level)
(define-key pascal-mode-map "\e\C-t" 'pascal-transpose-sexps)
(define-key pascal-mode-map "\e\C-k" 'pascal-kill-sexp)
(define-key pascal-mode-map "\e\C-@" 'pascal-mark-sexp)
(define-key pascal-mode-map "\e\C-b" 'pascal-backward-sexp)
(define-key pascal-mode-map "\e\C-f" 'pascal-forward-sexp)
(define-key pascal-mode-map "\en" 'pascal-find-template-mark)
(define-key pascal-mode-map "\ep" 'pascal-template-expand)
(define-key pascal-mode-map "\e;" 'pascal-indent-for-comment)
(define-key pascal-mode-map "\e\C-q" 'pascal-indent-sentence)
(define-key pascal-mode-map "\e\C-g" 'pascal-indent-procedure)
(define-key pascal-mode-map "\C-c(" 'pascal-beginnify-region)
(define-key pascal-mode-map "\C-c;" 'pascal-insert-end-comment)
(define-key pascal-mode-map "\C-c\}" 'pascal-uncomment-out-lines)
(define-key pascal-mode-map "\C-c\{" 'pascal-comment-out-lines)
(define-key pascal-mode-map "\C-c=" 'pascal-find-declaration)
(define-key pascal-mode-map "\C-c^" 'pascal-upcase-keywords)
(define-key pascal-mode-map "\C-c!" 'pascal-capitalize-standardnames)
(define-key pascal-mode-map "\C-c\C-i" 'indent-buffer)
(define-key pascal-mode-map "\C-c\C-n" 'next-error)
(define-key pascal-mode-map "\C-c\C-r" 'pascal-run)
(define-key pascal-mode-map "\C-c\C-c" 'pascal-compile)
(define-key pascal-mode-map ";" 'pascal-electric-semi)
(define-key pascal-mode-map "." 'pascal-electric-period)
(define-key pascal-mode-map "=" 'pascal-electric-equal)
(define-key pascal-mode-map "'" 'pascal-electric-string)
(define-key pascal-mode-map "(" 'pascal-electric-left-paren)
(define-key pascal-mode-map ")" 'pascal-electric-right-paren)
(define-key pascal-mode-map "[" 'pascal-electric-left-bracket)
(define-key pascal-mode-map "]" 'pascal-electric-right-bracket)
(define-key pascal-mode-map "{" 'pascal-electric-left-curly)
(define-key pascal-mode-map "}" 'pascal-electric-right-curly)
(define-key pascal-mode-map "\177" 'backward-delete-char-untabify)
(define-key pascal-mode-map "\C-m" 'newline)
(define-key pascal-mode-map "\C-j" 'pascal-newline-check-and-indent)
(define-key pascal-mode-map "\t" 'pascal-indent-command)
(easy-menu-define pascal-menu pascal-mode-map "Menu for pascal mode"
'("Pascal"
("Indent"
["line" pascal-indent-command (not buffer-read-only)]
["sentence" pascal-indent-sentence (not buffer-read-only)]
["procedure" pascal-indent-procedure (not buffer-read-only)]
["region" indent-region (not buffer-read-only)]
["buffer" indent-buffer (not buffer-read-only)])
("Go beginning of"
["line" beginning-of-line t]
["expression" pascal-backward-sexp t]
["sentence" pascal-beginning-sentence t]
["procedure" pascal-beginning-procedure t])
("Go end of"
["line" end-of-line t]
["expression" pascal-forward-sexp t]
["sentence" pascal-end-sentence t]
["procedure" pascal-end-procedure t])
("Mark"
["expression" pascal-mark-sexp t]
["sentence" pascal-mark-sentence t]
["procedure" pascal-mark-procedure t])
("Transpose"
["expression" pascal-transpose-sexps (not buffer-read-only)]
["sentence" pascal-transpose-sentences (not buffer-read-only)]
["procedure" pascal-transpose-procedures (not buffer-read-only)])
"--"
["Compile" pascal-compile t]
("Error"
["next" next-error
(and (featurep 'compile) (compilation-errors-exist-p))]
["previous" previous-error
(and (featurep 'compile) (compilation-errors-exist-p))]
["first" first-error
(and (featurep 'compile) (compilation-errors-exist-p))])
"--"
["Find definition" pascal-find-declaration t]
["Comment out region" pascal-comment-out-lines
(and (not buffer-read-only) (region-exists-p))]
["Restore commented out region" pascal-uncomment-out-lines
(and (not buffer-read-only) (region-exists-p))]
["Capitalize standardnames" pascal-capitalize-standardnames
(and (not buffer-read-only) (region-exists-p))]
["Upcase keywords" pascal-upcase-keywords
(and (not buffer-read-only) (region-exists-p))]
["Wrap BEGIN END around region" pascal-beginnify-region
(and (not buffer-read-only) (region-exists-p))]))
pascal-mode-map)
"Keymap used in Pascal mode.")
(defvar pascal-syntax-table
(let ((table (make-syntax-table)))
(modify-syntax-entry ?\' "\"" table)
(modify-syntax-entry ?\" "\"" table)
(modify-syntax-entry ?\( "()1" table)
(modify-syntax-entry ?\) ")(4" table)
(modify-syntax-entry ?\* ".23" table)
(modify-syntax-entry ?\+ "." table)
(modify-syntax-entry ?\- "." table)
(modify-syntax-entry ?\/ "." table)
(modify-syntax-entry ?\< "." table)
(modify-syntax-entry ?\= "." table)
(modify-syntax-entry ?\> "." table)
(modify-syntax-entry ?\% "." table)
(modify-syntax-entry ?\[ "(]" table)
(modify-syntax-entry ?\] ")[" table)
(modify-syntax-entry ?\{ "<" table)
(modify-syntax-entry ?\} ">" table)
table)
"Syntax table used in Pascal mode.")
(defvar pascal-case-template-table nil
"Abbrev table in use in Pascal-mode buffers with case significant.")
(defvar pascal-nocase-template-table nil
"Abbrev table in use in Pascal-mode buffers with case not significant.")
(defvar pascal-mode-abbrev-table nil)
(defvar pascal-template-table nil
"Abbrev table in use in Pascal-mode buffers.")
(make-variable-buffer-local 'pascal-template-table)
(defvar pascal-token-end nil)
(defun pascal-mode-case ()
"Start pascal mode with option `id-case-significant' true."
(interactive)
(pascal-mode 1))
(defun pascal-mode-no-case ()
"Start pascal mode with option `id-case-significant' false."
(interactive)
(pascal-mode 0))
(defun pascal-mode (&optional case)
"Major mode for editing Pascal programs. Version 1.12.
If optional argument CASE is not nil, then it must be numeric and
id-case-significant is set to true if CASE > 0 else to false.
\\<pascal-mode-map>
Knows about procedure (program, procedure or function), sentence (delimited at
the end by end, until or ; and at the beginning by label, const, type, var,
record, begin, repeat and ;) and expression (word, string, function or
procedure call, array reference and parenthesis expression).
Indent by line '\\[pascal-indent-command]', sentence '\\[pascal-indent-sentence]', region '\\[indent-region]' and whole
buffer '\\[indent-buffer]'.
'\\[pascal-newline-check-and-indent]' indents current line, does some checking and gets a new indented line.
'\\[newline]' will just get a new line (use this if you don't want an indented line).
If the variable `pascal-indent-comments-separately' is false then the whole
line including comments at the end is moved as a unit when code at the
beginning of the line is indented.
If `pascal-indent-comments-separately' is t (default),comments try to stay
where they are.
If `pascal-indent-comments-separately' is neither false or t, then comments
are moved to comment-column.
If `pascal-fix-comment' and `pascal-indent-comments-separately' are true then
comment position is adjusted in increments of `pascal-fix-comment' to keep
comment end within `pascal-right-margin'.
Move forward and backward by expression '\\[pascal-forward-sexp]' and '\\[pascal-backward-sexp]',
sentence '\\[pascal-beginning-sentence]' and '\\[pascal-end-sentence]', and procedure '\\[pascal-beginning-procedure]' and '\\[pascal-end-procedure]'.
Mark expression '\\[pascal-mark-sexp]', sentence '\\[pascal-mark-sentence]' and procedure '\\[pascal-mark-procedure]'.
Kill to end of expression '\\[pascal-kill-sexp]' and sentence '\\[pascal-kill-sentence]'.
Kill to beginning of sentence '\\[pascal-backward-kill-sentence]'.
Transpose expressions '\\[pascal-transpose-sexps]' and sentences '\\[pascal-transpose-sentences]'.
If the preceding word is end or a top-level begin, '\\[pascal-insert-end-comment]' will insert a
comment indicating what was ended (or begun).
When ';' is inserted the cursor will momentarily move back to the beginning of
the sentence that was ended by the ';'. If pasc-semicolon is loaded then the
the beginning and end of a sentence is highlighted whenever point is just
after a semicolon.
If `pascal-put-end-comment' is true, ';' after 'end' will do a '\\[pascal-insert-end-comment]'. If
`pascal-put-end-comment' is t (default) this is only done when ending a
function or procedure. If it is not false or t, then this is done after each
'end'.
If pascal-auto-newline is non-nil (default nil), ';' at the end of a line
will do a '\\[pascal-newline-check-and-indent]' to insert a new line.
'x+=' is expanded to 'x:=x+' and 'x +=' is expanded to 'x := x + ' where x
is anything and '+' is '^.' or any character in `pascal-equal-ops' like '+'.
'\\[pascal-template-expand]' inserts Pascal templates. '~<..>' is used as a mark to indicate where