-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreduce-ide.texinfo
2388 lines (2019 loc) · 101 KB
/
reduce-ide.texinfo
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
\input texinfo
@c %**start of header
@settitle GNU Emacs REDUCE Integrated Development Environment
@c Manual last updated:
@set UPDATED Time-stamp: <2024-12-16 15:18:12 franc>
@c Software version:
@set VERSION 1.13
@afourpaper
@c With different size paper the printed page breaks will need attention!
@c Look for @page and @need commands.
@setchapternewpage off
@paragraphindent 3
@c %**end of header
@dircategory GNU Emacs Lisp
@direntry
* REDUCE IDE: (reduce-ide). REDUCE Integrated Development Environment.
@end direntry
@copying
This manual is for REDUCE IDE (version @value{VERSION}, updated
@value{UPDATED}), which provides GNU Emacs major modes for editing and
running REDUCE source code.
Copyright @copyright{} 1994, 1996, 1999, 2012, 2017-2018, 2022-2024 Francis J. Wright
@quotation
This manual and the software that it describes are subject to the GNU
General Public License that is distributed with GNU Emacs -- see the
file @file{COPYING}.
Permission is granted to make and distribute verbatim copies of this
manual provided the copyright notice and this permission notice are
preserved on all copies.
@ignore
Permission is granted to process this file through TeX and print the
results, provided the printed document carries a copying permission
notice identical to this one except for the removal of this paragraph
(this paragraph not being relevant to the printed manual).
@end ignore
Permission is granted to copy and distribute modified versions of this
manual under the conditions for verbatim copying and provided that the
entire resulting derived work is distributed under the terms of a
permission notice identical to this one.
Permission is granted to copy and distribute translations of this manual
into another language, under the above conditions for modified
versions.
@end quotation
@end copying
@titlepage
@title GNU Emacs REDUCE IDE
@subtitle An Integrated Development Environment for REDUCE:
@subtitle Major modes for editing and running REDUCE source code
@subtitle Software version @value{VERSION}
@author @uref{https://sites.google.com/site/fjwcentaur, Francis J. Wright}
Manual last updated @value{UPDATED}
@c The following two commands start the copyright page.
@page
@vskip 0pt plus 1filll
@insertcopying
@end titlepage
@c Output the table of contents at the beginning.
@contents
@c ===================================================================
@ifnottex
@node Top, Introduction, (dir), (dir)
@top REDUCE Integrated Development Environment
@display
This manual is for REDUCE IDE, version @value{VERSION}.
GNU Emacs major modes for editing and running REDUCE source code
@uref{https://sites.google.com/site/fjwcentaur, Francis J. Wright}
Manual last updated @value{UPDATED}
@end display
@end ifnottex
@menu
* Introduction:: What is REDUCE IDE?
* Installation:: How to install REDUCE IDE
* General:: General features of REDUCE mode
* Statements:: Commands that operate on statements
* Procedures:: Commands that operate on procedures
* Comments:: Support for REDUCE comments
* Indentation:: Commands for automatic indentation
* Structures:: Structure templates
* Completion:: Completion and expansion of REDUCE keywords
* Font-Lock:: Font selection for syntactic highlighting
* Information:: Procedure, operator and variable information
* Running:: Running REDUCE in an Emacs window
* Miscellaneous:: Miscellaneous features
* Customization:: Options that control REDUCE IDE
* Feedback:: Bug reports, suggestions, comments, @dots{}
* Command Index:: Index of REDUCE IDE commands
* Variable Index:: Index of REDUCE IDE configuration variables
* Keystroke Index:: Index of REDUCE IDE keystrokes
* Concept Index:: Index of general REDUCE IDE concepts
@end menu
@c ===================================================================
@node Introduction, Installation, Top, Top
@chapter Introduction to REDUCE IDE
@cindex Introduction to REDUCE IDE
This manual documents the GNU Emacs Integrated Development Environment
(IDE) for REDUCE, which comprises a primary major mode for
syntax-directed editing of REDUCE source code (REDUCE mode) and a
subsidiary major mode for running REDUCE as an inferior process with
input and output via a buffer (REDUCE Run mode). REDUCE is a system
and language for algebraic computing developed originally by Anthony
C. Hearn, which is now Open Source and available from
@uref{https://sourceforge.net/projects/reduce-algebra/, SourceForge}.
It therefore shares the GNU spirit of collaborative software
development, which provided part of my motivation to begin this
project. Also, REDUCE is written in Lisp, as is (most of) Emacs.
However, the REDUCE user language is similar to
@uref{https://en.wikipedia.org/wiki/ALGOL_60, Algol 60}, an ancestor
of most current programming languages.
I began development of REDUCE mode tentatively in late 1992 and
seriously in early 1994, and I began adding REDUCE Run mode in late
1998. I have continued development sporadically. Comments,
suggestions, bug reports, etc.@: are welcome; @ref{Feedback}.
REDUCE IDE is released as an Emacs package; @ref{Installation,,
Installation of REDUCE IDE}. The latest development source code
(which may not work!)@: is available from
@uref{https://github.com/fjwright/REDUCE-IDE, GitHub}, where package
release versions are tagged (e.g.@: @code{v1.7}) and are available as
releases (e.g.@: @code{reduce-ide-1.7.tar}). The source code (only)
for the latest package release is also available from
@uref{https://sourceforge.net/p/reduce-algebra/code/HEAD/tree/trunk/generic/emacs/,
SourceForge}.
The current version of REDUCE IDE is intended for use with GNU Emacs
version 29 or later, which I will endeavour to support under recent
versions of Microsoft Windows and Linux. It should also run on other
platforms, but I may not be able to provide support.
This manual assumes that you are familiar in general with both Emacs
and REDUCE.
The purpose of REDUCE mode is to provide editing commands that are
aware of the syntax of the REDUCE language, and therefore allow
operations to be performed on the major syntactic elements, namely
statements, procedures and comments. To the reader who has never used
a syntax-directed editor, I can only say that it is surprisingly
useful! In particular, the automatic indentation code provides
valuable clues to potential REDUCE programming errors by showing how
the REDUCE parser is likely to interpret the code; @ref{Indentation,,
Indenting REDUCE code automatically}.
The purpose of REDUCE Run mode is to provide a friendly interface to a
@strong{command-line version} of REDUCE running as an inferior process
in an Emacs buffer. REDUCE Run mode inherits much of its
functionality from REDUCE mode and cannot be run alone. The
assumption is that normal use will involve editing one or more REDUCE
source files and running REDUCE simultaneously, and this is what
REDUCE Run mode aims to support. REDUCE Run mode is described in its
own chapter; @ref{Running, Running REDUCE in a buffer}.
@kindex C-h m
@findex describe-mode
All REDUCE IDE commands are self-documenting as usual in Emacs,
including in particular the modes themselves. Hence, for an overview
of REDUCE mode, select it in some buffer and then give the command
@kbd{C-h m} (@code{describe-mode}) or use the @kbd{Help} menu option
@kbd{Describe}.
@c ===================================================================
@node Installation, General, Introduction, Top
@chapter Installation of REDUCE IDE
@cindex Installation of REDUCE IDE
I recommend that you use the GNU Emacs package manager to install the
latest REDUCE IDE package as described in the
@uref{https://reduce-algebra.sourceforge.io/reduce-ide/#installation,
installation section of the main REDUCE IDE web page}. Alternatively,
releases as Emacs package (@code{.tar}) files are available from
@uref{https://github.com/fjwright/REDUCE-IDE/releases, GitHub} and via
the @uref{https://reduce-algebra.sourceforge.io/reduce-ide/, REDUCE
IDE home page}. You can download a package file to any convenient
directory and run the Emacs command @kbd{M-x package-install-file} on
it. For further details, @ref{Packages,,, emacs}. None of the manual
installation described below is then required.
The rest of this chapter, and the related section of the chapter on
REDUCE Run mode, are for users who want to install and configure
REDUCE IDE ``by hand'', or who want to understand the installation
process.
REDUCE mode is provided by files called @file{reduce-mode.el},
@file{reduce-delim.el} and @file{reduce-font-lock.el}, which are files
of Emacs Lisp source code. These files should be byte-compiled, and
the compiled (@file{.elc}) files installed in a directory from which
Emacs loads its Lisp code. If necessary, you can customize your Emacs
@code{load-path} so that Emacs can find the @file{.elc} files;
@ref{Customization,,,emacs, The Emacs Editor}.
Emacs initialization and customization is stored in a file that is
normally called @file{.emacs} and lives in your home directory. The
precise meaning of ``home directory'' depends on both your operating
system and Emacs version; the easiest way to find it in Emacs is to
visit the directory @file{~}, or just visit the file @file{~/.emacs}
directly. Your @file{.emacs} file is updated automatically by the
Emacs customization facility and you can also edit it by hand to add
other configuration. @xref{Init File,,,emacs,The Emacs Editor}.
@findex load-library
Before REDUCE mode can be used, the file @file{reduce-mode.elc} must
be loaded. (It will then normally load @file{reduce-delim.elc} and
@file{reduce-font-lock.elc} automatically.) This is necessary only
once per Emacs session. It can be loaded explicitly, most easily by
giving the command @kbd{M-x load-library reduce-mode}. However, you
will probably want @file{reduce-mode.elc} to be loaded automatically
the first time you (explicitly or implicitly) turn on REDUCE mode.
The way to do this is to put the following statement into your
@file{.emacs} file:
@findex autoload
@lisp
(autoload 'reduce-mode "reduce-mode"
"Major mode for REDUCE code editing" t)
@end lisp
This statement is completely innocuous and will have no effect unless
you select REDUCE mode. It could therefore quite safely be put in a
system-wide configuration file (e.g.@: @file{default.el} or
@file{site-start.el}). @xref{Init File,,,emacs,The Emacs Editor}.
It is also very convenient to have REDUCE mode turned on automatically
when editing a REDUCE source code file. This can be done based on the
``extension'' of the filename. Provided you end all REDUCE source code
file names with the standard extension @file{.red}, the following
statement in your @file{.emacs} file will have the desired effect:
@vindex auto-mode-alist
@lisp
(add-to-list 'auto-mode-alist '("\\.red\\'" . reduce-mode))
@end lisp
You can use other extensions as well or instead; if you use a different
file naming convention then make the appropriate change(s) to the above
statement. Emacs also provides other facilities that can be used for
controlling major modes.
Installation of REDUCE Run mode is documented separately; @ref{Running,,
Running REDUCE in a buffer}.
@c ===================================================================
@node General, Statements, Installation, Top
@chapter General features of REDUCE mode
@cindex General features
@cindex Features
@findex reduce-mode
REDUCE mode can be selected by giving the command @kbd{M-x
reduce-mode}, although normally it will be selected automatically,
probably via the filename extension; @ref{Installation,, Installation
of the REDUCE IDE}. REDUCE mode inherits from @code{prog-mode} and so
shares some basic functionality common to all Emacs programming modes.
The commands provided by REDUCE mode are aware of REDUCE syntax and
ignore the contents of strings and the case of characters. Except for
the special comment commands, they also ignore comments;
@ref{Comments,, Support for REDUCE comments}. The standard GNU Emacs
indentation (@pxref{Indentation,, Indenting REDUCE code
automatically}) and comment commands are supported, either via the
general Emacs mechanisms or by re-binding the standard keys to REDUCE
mode versions of standard commands. The design of this mode is
modelled primarily on Lisp mode and the %-comment conventions
basically follow those of Lisp mode. I have also taken some ideas
from FORTRAN mode.
The standard Emacs syntax tables are modified to reflect REDUCE syntax
so that, for example, Emacs knows that the REDUCE escape character is
@code{!}.
Blank lines separate ``paragraphs''.
Loading the REDUCE mode library runs any functions on
@code{reduce-mode-load-hook}, which can be used to customize global
features of REDUCE mode such as its key map. Entry to REDUCE mode
runs any functions on @code{prog-mode-hook} and then any functions on
@code{reduce-mode-hook}, which can be used to customize buffer-local
features of REDUCE mode, e.g.@: to turn on font-lock mode.
@xref{Installation,, Installation of the REDUCE IDE}.
@xref{Customization,, Options that control REDUCE IDE}.
REDUCE mode is intended to support both the algebraic and symbolic modes
of REDUCE@. It provides very limited support for Lisp syntax to the
extent that it is likely to be used in symbolic-mode code, and hence it
understands the significance of the quote symbol (@code{'}) to some
extent. Syntax-directed editing naturally works correctly only if the
syntax of the source code being edited is correct. If it is not then
strange things can happen, and the services of the Emacs undo facilities
may be required!
@c @table @kbd
@c @item <backspace>
@c @kindex <backspace>
@c @itemx M-x backward-delete-char-untabify
@c @findex backward-delete-char-untabify
@c Delete one character backwards, converting tabs to spaces if necessary.
@c @end table
A major mode menu provides convenient access to most of the major
facilities of REDUCE mode.
@c ===================================================================
@node Statements, Procedures, General, Top
@chapter Statement-oriented commands
@cindex Statements
@cindex Operations on Statements
The most basic facility provided by REDUCE mode is the ability to move
forwards and backwards by statements or expressions through a file of
REDUCE source code. Moving by one statement means moving to the
beginning or end of the @emph{logical} statement currently containing
(or respectively preceding or following) point, which may involve
skipping many actual statements that are contained within the current
statement. In particular, as REDUCE mode looks for the beginning or
end of a statement it will skip complete compound or block statements
(@code{begin @dots{} end}), group statements (@code{<< @dots{} >>}),
and bracketed expressions (@code{(@dots{})}, @code{@{@dots{}@}} and
@code{[@dots{}]}, although square brackets are not normally used in
REDUCE)@. Bracket skipping is controlled entirely by the Emacs syntax
table.
Hence, ``statement'' in this manual will normally mean a complete
@emph{logical statement}. A syntax-directed editor clearly must perform
a limited amount of parsing, but it must be remembered that a
syntax-directed editor has the following important differences from a
normal parser, because their basic purposes are different:
@itemize @bullet
@item
A syntax-directed editor must be able to parse both forwards @emph{and
backwards}.
@item
It will typically parse only locally for speed and must therefore parse
based on incomplete information.
@item
It is provided for the convenience of the user and therefore need not
obey precisely the full syntax of the language, provided it is
consistent and reliable.
@end itemize
In particular, the REDUCE-mode movement commands may fail if point is
within a comment or string, although they should skip complete
comments and strings.
REDUCE mode considers REDUCE statements to be terminated by either of
the characters @code{;} or @code{$}. It also considers statements
contained within any kind of brackets to be delimited by those
brackets, statements within compound or block statements (@code{begin
@dots{} end}) to be delimited by the @code{begin} and @code{end}
keywords, and statements within group statements (@code{<< @dots{}
>>}) to be delimited by the @code{<<} and @code{>>} tokens. Commas
are not considered to delimited statements.
More precisely, a statement is considered to begin at the first
non-white-space character following the previous statement terminator,
opening bracket, @code{begin} or @code{<<}. It is considered to end
immediately after the first statement terminator or immediately after
the last non-white-space character preceding a closing bracket,
@code{end} or @code{>>}. Comments are treated as white space by all
REDUCE-mode commands other than those specifically related to
comments; @ref{Comments,, Support for REDUCE comments}.
The current philosophy of REDUCE mode is that the statements within a
compound or group statement form an essentially isolated system, and
that the basic statement-oriented commands should not move point
either into or out of this system, for which separate commands are
provided. However, if you try hard enough, REDUCE mode will let a
simple statement-oriented command move out of (but never into) a
compound or group statement. Trying hard enough means repeating the
same command enough times, which is determined by the value of the
option @code{reduce-max-escape-tries}, which currently has the default
value 2; @ref{Customization,, Options that control REDUCE IDE}. The
overall effect of this is to enforce a brief pause (one ineffective
command execution) that serves to prevent you from skipping out of a
compound or group statement accidentally, but without causing any
serious inconvenience.
The following commands all accept a numerical argument, which defaults
to 1. The commands to move forwards or backwards by statements do not
move in the opposite direction if given a negative argument, in which
case they do not move at all. They contain special code to handle the
keyword @code{end} followed by a terminator when used as the
end-of-file marker, provided it appears at the start of a line
(optionally preceded by a terminator but no space), and they do not
regard comment statements as statements, i.e.@: they treat them as
white space. They report a user error if they fail.
@table @kbd
@item C-c C-n
@kindex C-c C-n
@itemx M-x reduce-forward-statement
@findex reduce-forward-statement
Move forwards to the end of the current statement if within a
statement or to the end of the following statement otherwise. With an
argument, do it that many times. If looking at the end of a block or
group, or the end-of-file marker, move over it after
@code{reduce-max-escape-tries} consecutive interactive tries.
@item C-c C-p
@kindex C-c C-p
@itemx M-x reduce-backward-statement
@findex reduce-backward-statement
Move backwards to the start of the current statement if within a
statement or to the start of the previous statement otherwise. With
an argument, do it that many times. If looking at the beginning of a
block or group move over it after @code{reduce-max-escape-tries}
consecutive interactive tries. The end-of-file marker is treated as a
statement.
@item C-c C-k
@kindex C-c C-k
@itemx M-x reduce-kill-statement
@findex reduce-kill-statement
Kill the rest of the current statement from point. With a prefix
argument, kill that many statements from point. Negative arguments
kill statements backwards, where the prefix argument minus (-) is
equivalent to -1.
@item C-c C-u
@kindex C-c C-u
@itemx M-x reduce-up-block-or-group
@findex reduce-up-block-or-group
Move backwards up one level of block or group, i.e.@: to the beginning
of the @code{begin} or @code{<<} at the start of the block or group
containing point. A universal argument means move forwards, i.e.@: to
the end of the @code{end} or @code{>>} at the end of the block or
group containing point. Report a user error if the move fails. With
a numeric argument, do it that many times, where a negative argument
means move forwards instead of backwards.
@item C-c C-d
@kindex C-c C-d
@itemx M-x reduce-down-block-or-group
@findex reduce-down-block-or-group
Move forwards down one level of block or group, i.e.@: to the end of
the nearest @code{begin} or @code{<<} within the current block or
group, if any. A universal argument means move backwards to the
beginning of the nearest @code{end} or @code{>>} within the current
block or group, if any. Report a user error if the move fails. With
a numeric argument, do it that many times, where a negative argument
means move backwards instead of forwards.
@end table
The following two commands move by ``balanced expression'', which
means a symbol, string, bracketed expression, block or group. A
symbol or bracketed expression may be quoted. The commands skip any
preceding or intervening white space or terminator characters, but
assume point is not in a string or comment.
@table @kbd
@item C-M-f
@kindex C-M-f
@itemx M-x reduce-forward-sexp
@findex reduce-forward-sexp
Move forwards across one ``balanced expression''. With a numeric
argument, move that many times, where a negative argument means move
backwards instead of forwards. This command is modelled on
@code{forward-sexp}.
@item C-M-b
@kindex C-M-b
@itemx M-x reduce-backward-sexp
@findex reduce-backward-sexp
Move backwards across one ``balanced expression''. With a numeric
argument, move that many times, where a negative argument means move
forwards instead of backwards. This command is modelled on
@code{backward-sexp}.
@end table
@c ===================================================================
@node Procedures, Comments, Statements, Top
@chapter Procedure-oriented commands
@cindex Procedures
@cindex Operations on Procedures
Files of REDUCE source code frequently consist mainly of procedure
definitions. This is certainly true of symbolic-mode code, and hence
it is true of most of the source code of the REDUCE system itself.
REDUCE mode provides the following operations on procedures. They
work on all kinds of REDUCE procedures provided they contain one of
the procedural keywords @code{procedure}, @code{listproc} or
@code{matrixproc} within their header. Procedure type declarations
(@code{symbolic}, @code{inline}, @code{real}, etc.@:) preceding the
procedural keyword are also supported.
A procedure is considered to begin at the first non-white-space
character of the definition, and to end after the statement defining
the procedure body. White space and the first newline after the
procedure body are always considered to be part of the procedure. The
commands to mark and kill a procedure also include @emph{all} blank
lines before the procedure definition. Many procedure-oriented
commands support a prefix argument.
The two commands for moving over procedures accept a positive integer
argument that indicates by how many procedures to move -- the default
is 1. These commands do not move in the opposite direction if given a
negative argument, in which case they do not move at all.
@table @kbd
@item C-M-e
@kindex C-M-e
@itemx M-x reduce-forward-procedure
@findex reduce-forward-procedure
Move forwards to the end of the procedure ending after point. With a
positive argument, do it that many times. If this fails, move
forwards by as many complete procedures as possible and report a user
error. Skip to the first following non-blank character or the next
line.
@item C-M-a
@kindex C-M-a
@itemx M-x reduce-backward-procedure
@findex reduce-backward-procedure
Move backwards to the start of the procedure starting before point.
With a positive argument, do it that many times. If this fails, move
backwards by as many complete procedures as possible and report a user
error. Skip to the start of any procedural types.
@end table
Regardless of whether point is within a procedure or not, these two
commands move respectively to the first following end of a procedure,
or the first preceding start of a procedure. One way to move to the
start of the next procedure is to move forwards to its end and then
move backwards to its start.
Marking is the basis for many operations on procedures.
@table @kbd
@item C-M-h
@kindex C-M-h
@itemx M-x reduce-mark-procedure
@findex reduce-mark-procedure
Mark the procedure ending after point. With a positive argument, mark
that many procedures ending after point. Put mark at the first
non-blank character or next line after the appropriate end of
procedure. If this fails, do not mark anything and report a user
error. Leave point at the start of the first procedure before any
preceding blank lines.
@item C-c k
@kindex C-c k
@itemx M-x reduce-kill-procedure
@findex reduce-kill-procedure
Kill the procedure ending after point. With a positive argument,
kill that many procedures ending after point, including any preceding
blank lines. If this fails, do not kill anything and report a user
error.
@item C-M-q
@kindex C-M-q
@itemx M-x reduce-indent-procedure
@findex reduce-indent-procedure
Indent the procedure (and trailing white space) ending after point.
@xref{Indentation,, Indenting REDUCE code automatically}.
@end table
It is often desirable to be able to see as much as possible of a
procedure definition within the current window. The standard Emacs
command @code{reposition-window} (@pxref{Scrolling,,, emacs, The Emacs
Editor}) attempts to do this for Lisp functions, and the command
@code{reduce-reposition-window} provides a harness to apply this
function to REDUCE procedures, to which the standard key @kbd{C-M-l} is
rebound.
@table @kbd
@item C-M-l
@kindex C-M-l
@itemx M-x reduce-reposition-window
@findex reduce-reposition-window
Reposition the procedure containing point to maximize its visibility
within the window. @xref{Scrolling,,, emacs, The Emacs Editor}, and see
the documentation for the function @code{reposition-window} for details.
@end table
To restrict all editing to a single REDUCE procedure, the standard Emacs
key @kbd{C-x n d} that runs the command @code{narrow-to-defun} is
rebound to a function to narrow to the current procedure.
@table @kbd
@item C-x n d
@kindex C-x n d
@itemx M-x reduce-narrow-to-procedure
@findex reduce-narrow-to-procedure
Narrow to the procedure ending after point. In other words, make all
text outside this procedure invisible. With a positive argument,
include that many procedures ending after point. Also include any
preceding blank lines. If narrowing fails, report a user error.
@xref{Narrowing,,, emacs, The Emacs Editor}.
@end table
@c ===================================================================
@node Comments, Indentation, Procedures, Top
@chapter Support for REDUCE comments
@cindex Comment support
There are three comment conventions used in REDUCE@. One is the
comment statement, which is a statement that begins with the keyword
@code{comment} and ends with a statement terminator. This is not used
much in modern REDUCE code. The most commonly used form of comment
begins with a @code{%} character and ends at the end of the line.
Hence, it can appear either on its own on a line or at the end of a
line after other code. C-style comments, which begin with @code{/*}
and end with @code{*/}, are also accepted although not (yet) widely
used. REDUCE mode highlights them all as comments.
Comments are ignored (skipped) by all syntax-directed commands. (This
is not trivial to achieve, since comments can contain essentially
arbitrary text including keywords, and @code{%} and @code{/**/}
comments can contain statement terminators that do not have any
syntactic significance.) There is currently no way to use any of the
REDUCE syntax-directed commands on comment statements.
The REDUCE mode indentation and fill commands support all three
comment types, but there is no other support for comment statements or
@code{/**/} comments. There is considerably more support for
%-comments, much of which is already built into Emacs because
%-comments are very similar to the comments used in Emacs Lisp.
Indeed, the comment conventions supported by REDUCE mode are modelled
primarily on those used in Emacs Lisp mode.
The comment commands are intimately related to the automatic comment
indentation conventions. (These are the indentation conventions
enforced by the Emacs comment and indentation commands, although the
user is not otherwise forced to follow them.) @xref{Indentation,,
Indenting REDUCE code automatically}.
The indentation of a @code{%}-comment that begins with no more than 2
@code{%} characters together and appears alone on a line is determined
by the previous non-blank line. If this is a procedure (header)
statement then the comment line is indented relative to it, otherwise
it has no indent relative to the previous line, and at the beginning
of a file it is not indented at all. A @code{%}-comment at the end of
a line of code is indented to the column specified by the value of the
standard Emacs buffer-local variable @code{comment-column}, which by
default is 40 (half way across a ``standard'' 80 column page), unless
the code extends beyond this column. In that case, the comment begins
one space later.
This convention can be over-ridden as follows. If the comment begins
with 3 or more @code{%} characters then the comment indentation is not
changed. This allows a comment to be placed anywhere on an empty line
without any risk of it being automatically re-indented.
A new single-@code{%}-comment can be introduced and/or automatically
indented by the standard Emacs command @code{comment-dwim}, normally
bound to the key @kbd{M-;}. An existing @code{%}-comment can be
automatically continued on the next line by the standard Emacs command
@code{default-indent-new-line}, normally bound to the keys @kbd{M-j}
and @kbd{C-M-j}. This will copy the structure of the @code{%}-comment
to be continued, including the number of @code{%} characters and the
indentation. All other indentation commands will also indent
@code{%}-comments, in particular those bound to the @kbd{@key{TAB}}
and @kbd{@key{BACKTAB}} (i.e.@: @kbd{S-@key{TAB}}) keys.
@xref{Indentation,, Indenting REDUCE code automatically}.
@table @kbd
@item M-;
@kindex M-;
@itemx M-x comment-dwim
@findex comment-dwim
Indent this line's comment appropriately, or insert an empty comment.
@item C-M-j
@kindex C-M-j
@item M-j
@kindex M-j
@itemx M-x default-indent-new-line
@findex default-indent-new-line
Break the line at point and indent, continuing a comment if presently
within one. The body of the continued comment is indented under the
previous comment line.
@end table
The only program text that it normally makes sense to fill or justify
is comment text. Hence, REDUCE mode rebinds the key @kbd{M-q} that
normally fills or justifies a paragraph to the command
@code{reduce-fill-comment}. This should be completely safe to use in
REDUCE code (unlike @code{fill-paragraph} etc., which would be a
potential disaster were there no undo facility!), and makes it easy to
keep comments formatted tidily.
@table @kbd
@item M-q
@kindex M-q
@itemx M-x reduce-fill-comment
@findex reduce-fill-comment
Fill a comment statement, successive @code{%}-comment lines or a
@code{/**/} comment around or immediately following point. A prefix
argument means justify as well.
@end table
REDUCE mode also provides commands for turning sections of text into
@code{%}-comments by adding @code{%} characters at the start of each
line, which will be referred to as ``start-comments''. These commands
are intended primarily for temporarily preventing REDUCE from
executing sections of code without actually removing them. Such a
section can be either the current region or the procedure ending after
point. By default, these commands automatically toggle the comment
status. When given an interactive argument, they remove any
start-commenting of the specified section of text if the argument is
negative (or null) and insert start-commenting if the argument is
positive. The precise text that is added to or removed from each line
is the value of the variable @code{reduce-comment-region-string},
which defaults to @samp{%% }.
@table @kbd
@item C-c ;
@kindex C-c ;
@itemx M-x reduce-comment-region
@findex reduce-comment-region
Comment/uncomment every line in the region. By default, it toggles
the commenting, i.e.@: it comments the region if it is uncommented and
uncomments if it is commented. With an interactive argument, comment
if non-negative, uncomment if null or negative (cf.@: toggling minor
modes). When commenting, it puts the value of the variable
@code{reduce-comment-region-string} at the beginning of every line in
the region.
@item C-c :
@kindex C-c :
@itemx M-x reduce-comment-procedure
@findex reduce-comment-procedure
As for @code{reduce-comment-region}, but applies to the procedure ending
after point.
@end table
@c ===================================================================
@node Indentation, Structures, Comments, Top
@chapter Indenting REDUCE code automatically
@cindex Indentation
Indentation refers to the white space at the left of a line, which
therefore determines the column in which the actual text of the line
begins. Indentation is used in normal English text to indicate the
beginning of paragraphs, quotations, lists, etc.@: and hence to indicate
the logical structure of a document.
It is very important to use systematic indentation to indicate the
logical structure of the source code of a computer program. Whilst the
general principles of indentation are largely agreed, precise
indentation conventions vary from author to author. The automatic
indentation currently provided by REDUCE mode is very inflexible and
reflects very much my own style of indentation. Future versions may
provide more flexible and customizable indentation.
Currently all indentation is done in steps consisting of a fixed
number of spaces determined by the value of the variable
@code{reduce-indentation}, the default value of which is 3;
@ref{Customization,, Options that control REDUCE IDE}. This is the
indentation recommended by A.@ C.@ Hearn (the principal author of
REDUCE) for the indentation of the first line after a procedure
(header) statement.
REDUCE mode provides fairly intelligent automatic indentation. The
style used is as follows, where the indentation of a child statement is
expressed relative to the parent statement. Each top-level statement is
indented to the left margin. Procedure bodies are indented by one step.
Bodies of multi-line compound and group statements are indented by one
step and labels are exdented to match the beginning of the enclosing
block. Lines that begin with @code{end} or @code{>>} are exdented to
match the line containing the matching @code{begin} or @code{<<}.
Bodies of control structures and lines that continue a previous
statement are indented by one step. As parts of larger statements,
compound and group statements themselves are generally not indented if
they occupy multiple lines (because their bodies are indented) but they
are indented if they occupy only a single line.
When a new line that is inserted is being indented, the indentation
can be based only on the preceding code, and not on the code that will
appear in the line. Therefore, it is often necessary to re-indent a
line in order to get consistent indentation. This may seem a little
strange, but it is unavoidable given the syntax of REDUCE and the
indentation style that I have chosen. It is for this reason that the
key @kbd{C-j} runs the command
@code{reindent-then-newline-and-indent} rather than just
@code{newline-and-indent}.
The command to indent, or re-indent, a line of text is
@code{reduce-indent-line}, normally bound (indirectly) to the key
@kbd{@key{TAB}}. The execution of @code{reduce-indent-line} is
independent of the position of point within the line. It does not
move point relative to the text around it unless point was within the
indentation, in which case it is left before the first non-blank
character (i.e.@: at the end of the indentation), or at the end of the
line if it contains only white space. Normally, however, the most
convenient way to use automatic indentation is to terminate each line
of code with @kbd{C-j} rather than @kbd{@key{RET}}.
@xref{Miscellaneous,, Miscellaneous features}.
When called with any argument, which is possible only via the direct
key binding @kbd{M-i}, @code{reduce-indent-line} will indent the
current line correctly and then re-indent the rest of the logical
statement containing point by the same amount that the current line
was re-indented. This is @emph{not} the same as correctly
re-indenting the subsequent lines -- it re-indents them rigidly,
without changing their relative indentations at all, and is much
faster.
@table @kbd
@item TAB
@kindex TAB
@item M-i
@kindex M-i
@itemx M-x reduce-indent-line
@findex reduce-indent-line
Indent or re-indent the current line as REDUCE code. Indents to a
fixed style determined by the current and previous non-blank lines.
With an interactive argument, indent any additional lines of the same
statement rigidly together with this one.
@item C-j
@kindex C-j
@itemx M-x reindent-then-newline-and-indent
@findex reindent-then-newline-and-indent
Re-indent the current line, insert a newline, then indent the new line.
Indentation of both lines is done using @code{reduce-indent-line}, which
is bound by default to @kbd{TAB}.
@end table
With the current indentation style, it is not possible in all cases to
determine the correct indentation until after some text has been
entered on a line. This applies to the terminal delimiter of a block
(@code{end}) or group (@code{>>}) and to an @code{else} clause.
Therefore, REDUCE mode can automatically re-indent the current line
once there is enough text to recognise that this is necessary. It
does this only when it is otherwise idle and only when the relevant
text has just been typed. It is not done if the cursor is later moved
onto such a line since it is assumed that the desired indentation has
been set by then. (The indentation of any text can, of course, be
changed at any time, but it will never be automatically changed
retrospectively!)
This facility can be turned on and off by the command
@code{reduce-auto-indent-mode}, and it is turned on automatically if
the value of the option @code{reduce-auto-indent-mode-on} is non-nil,
which it is by default. The length of idle time required before the
facility will operate is controlled by the option
@code{reduce-auto-indent-delay}, and whether the current line is
re-indented by this facility is controlled by the regular expression
that is the value of the option @code{reduce-auto-indent-regexp}.
Auto-indentation is on by default. @xref{Customization,,
Customization of the REDUCE IDE}.
@table @kbd
@item M-x reduce-auto-indent-mode
@findex reduce-auto-indent-mode
Toggle REDUCE Auto Indent mode. With a prefix argument, turn the mode
on if and only if the argument is positive. When REDUCE Auto Indent
mode is enabled, after @code{reduce-auto-indent-delay} seconds of Emacs
idle time re-indent the current line if the text just typed matches
@code{reduce-auto-indent-regexp}.
@end table
A section of code can be re-indented using one command if it is first
marked as the current region, or the whole buffer or a complete
procedure definition can be re-indented by a single command. The
latter command works by marking the procedure and then re-indenting
the region. Region (and hence procedure) indenting is currently
implemented inefficiently by applying the single-line indentation
algorithm line-by-line, and hence is very slow for a large region or
procedure. In some future version it may be re-implemented more
efficiently.
@table @kbd
@item C-M-\
@kindex C-M-\
@itemx M-x reduce-indent-region
@findex reduce-indent-region
Indent or re-indent the region as REDUCE source code by applying
@code{reduce-indent-line} to each line. With a prefix argument it
indents the whole buffer.
@item C-M-q
@kindex C-M-q
@itemx M-x reduce-indent-procedure
@findex reduce-indent-procedure
Indent or re-indent the procedure (and trailing white space) ending
after point by applying @code{reduce-indent-line} to each line.
@end table
The command @code{reduce-indent-line-always}, bound to
@kbd{C-@key{TAB}}, is analogous to @code{reduce-indent-line} but
always indents by precisely one additional step consisting of
@code{reduce-indentation} spaces. With an argument, it rigidly
indents by one step the current line and the rest of the logical
statement.
The command @code{reduce-unindent-line}, bound to @kbd{S-@key{TAB}}
(i.e.@: @kbd{@key{BACKTAB}}), is an inverse of
@code{reduce-indent-line-always} and decreases the indentation by one
step. With an argument, it rigidly unindents by one step the current
line and the rest of the logical statement.
@table @kbd
@item C-TAB
@kindex C-TAB
@itemx M-x reduce-indent-line-always
@findex reduce-indent-line-always
Indent the current line as REDUCE code by adding
@code{reduce-indentation} spaces at the beginning of the line. With
an interactive argument, indent any additional lines of the same
statement rigidly along with this one.
@item BACKTAB
@kindex BACKTAB
@item S-TAB
@kindex S-TAB
@itemx M-x reduce-unindent-line
@findex reduce-unindent-line
Unindent the current line as REDUCE code by deleting
@code{reduce-indentation} spaces (or as many as possible) from the
beginning of the line. With an interactive argument, unindent any
additional lines of the same statement rigidly along with this one.
@end table
@c ===================================================================
@node Structures, Completion, Indentation, Top
@chapter Templates for REDUCE structures
@cindex Templates for structures
@cindex Structure templates
Commands are provided to insert and format the major REDUCE language
structures; currently block or compound (@code{begin @dots{} end}),
group (@code{<< @dots{} >>}) and conditional (@code{if @dots{} then
@dots{} else @dots{}}) statements are supported. By default they are
formatted to be multi-line. If given a prefix argument, the commands to
insert block and group statements (composites) format them on a single
line (appropriate in some very simple cases).
If there is text on the line after where a composite is inserted then it
is moved into the body of the composite; if transient mark mode is on
and the mark is active then the whole region is moved into the
composite; the composite is then re-indented.
The cursor is left in place to enter the body statements of a group,
whereas a block is inserted complete with an empty @code{scalar}
declaration and the cursor is left in place to enter the names of the
scalar variables.
@table @kbd
@item C-c b
@kindex C-c b
@itemx M-x reduce-insert-block
@findex reduce-insert-block
Insert and indent a @code{begin scalar ; @dots{} end} block and position
point inside. With an argument put @code{begin} and @code{end} on the
same line.
@item C-c <
@kindex C-c <
@itemx M-x reduce-insert-group
@findex reduce-insert-group
Insert and indent a @code{<< @dots{} >>} group and position point
inside. With an argument put @code{<<} and @code{>>} on the same line.
@item C-c i
@kindex C-c i
@itemx M-x reduce-insert-if-then
@findex reduce-insert-if-then
Insert @code{if @dots{} then} and position point inside. With argument
include a correctly indented @code{else} on a second line.
@end table
Probably the easiest way to access these templates from the keyboard is
not directly as described above but via the generalized completion
facilities described in the next chapter. @xref{Completion,,Keyword
completion and abbreviation expansion,,}.
@c ===================================================================
@node Completion, Font-Lock, Structures, Top
@chapter Keyword completion and abbreviation expansion
@cindex Completion
@cindex Keyword completion
@cindex Expansion