-
Notifications
You must be signed in to change notification settings - Fork 4
/
gams-mode.el
17969 lines (16416 loc) · 623 KB
/
gams-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
;;; gams-mode.el --- Major mode for General Algebraic Modeling System (GAMS) -*- lexical-binding: t -*-
;; Author: Shiro Takeda
;; Maintainer: Shiro Takeda
;; Copyright (C) 2001-2024 Shiro Takeda
;; First Created: Sun Aug 19, 2001 12:48 PM
;; Version: 6.16
;; Package-Requires: ((emacs "24.3"))
;; Keywords: languages, tools, GAMS
;; URL: https://github.com/ShiroTakeda/gams-mode
;; This file is not part of any Emacs.
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; A copy of the GNU General Public License can be obtained from this
;; program's author or from the Free Software Foundation,
;; Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
;;; Commentary:
;; This package offers the Emacs Lisp program for using the numerical software
;; GAMS in Emacs (GAMS mode for Emacs).
;; To install and use this mode, you need to add some codes in init.el. For the
;; details, please see the following site
;; https://github.com/ShiroTakeda/gams-mode
;;
;; If you install this file from MLPA repository, gams-mode.el is downloaded
;; from GitHub <https://github.com/ShiroTakeda/gams-mode/tree/master>. Please
;; see CHANGELOG.md at GitHub for the latest changes.
;;; Code:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Code starts here.
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(eval-and-compile
(require 'easymenu)
(require 'align)
(require 'org))
(defsubst gams-oddp (x)
"Return t if X is odd."
(eq (logand x 1) 1))
(defsubst gams-evenp (x)
"Return t if X is even."
(eq (logand x 1) 0))
(defsubst gams-list-length (x)
"Return the length of a list X. Return nil if list is circular."
(let ((n 0) (fast x) (slow x))
(while (and (cdr fast) (not (and (eq fast slow) (> n 0))))
(setq n (+ n 2) fast (cdr (cdr fast)) slow (cdr slow)))
(if fast (if (cdr fast) nil (1+ n)) n)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Define variables.
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defconst gams-mode-version "6.16"
"Version of GAMS mode.")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Define customizable variables.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;; Define groups.
(defgroup gams nil
"Group of GAMS mode for Emacs."
:group 'applications)
(defgroup gams-faces nil
"Group of faces for GAMS mode."
:group 'gams
:group 'faces)
(defgroup gams-keys nil
"Group of keybindings for GAMS mode."
:group 'gams
:group 'keyboard)
;;;;; Customizable variables start here.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Variables for GAMS mode.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defcustom gams-system-directory "c:/GAMS/42/"
"*The GAMS system directory (the directory where GAMS is installed).
This must be assigned the proper value if you want to use
`gams-view-document' and `gams-model-library'."
:type 'file
:group 'gams)
(defcustom gams-process-command-name "gams"
"*GAMS program file name.
If you do not include the GAMS system directory in PATH environmental
variable, you must set the full path to GAMS in this variable like
\"c:/GAMS20.0/gams.exe.\"."
:type 'file
:group 'gams)
(defcustom gams-process-command-option "logOption=3 pageWidth=100"
"*The command line options passed to GAMS.
If you are Windows Emacs user, LogOption=3 (or lo=3) option is
necessary to show the GAMS process log.
For the details of GAMS command line options, see the following page:
https://www.gams.com/39/docs/UG_GamsCall.html#UG_GamsCall_ListOfCommandLineParameters"
:type 'string
:group 'gams)
(defcustom gams-statement-file (concat user-emacs-directory "gams-statement.txt")
"*The name of the file in which user specific statements are stored.
If you register new statements and dollar control options, they are saved
in the file specified by this variable."
:type 'file
:group 'gams)
(defcustom gams-completion-case 'CamelCase
"Controls the auto-completion casing.
A symbol which can be
- Camelcase
- lowercase
- UPPERCASE
The default casing follows GAMS Studio and is \\='CamelCase.
"
:type '(choice (const CamelCase) (const lowercase) (const UPPERCASE))
:group 'gams)
(defcustom gams-statement-upcase nil
"*Non-nil means that statement is inserted in upper case.
If you want to use lower case, set nil to this variable."
:type 'boolean
:group 'gams)
(defcustom gams-dollar-control-upcase nil
"*Non-nil means that dollar control option is inserted in upper case.
If you want to use lower case, set nil to this variable."
:type 'boolean
:group 'gams)
(defcustom gams-use-mpsge t
"*If you use MPSGE, set non-nil to this variable."
:type 'boolean
:group 'gams)
(defcustom gams-fill-column 80
"*The column number used for `fill-paragraph' and `auto-fill-mode'."
:type 'integer
:group 'gams)
(defcustom gams-recenter-font-lock t
"*If non-nil, `font-lock-fontify-block' when recentering.
If your computer is slow, you may better set this to nil."
:type 'boolean
:group 'gams)
(defcustom gams-file-extension '("gms")
"*List of gams program file extensions.
If you open a file with an extension included in this list, GAMS mode
starts automatically. It doen't matter whether upper case or lower
case. For example,
(setq gams-file-extension '(\"gms\" \"dat\"))'"
:type '(repeat (string :tag "value"))
:group 'gams)
(defcustom gams-mode-hook nil
"*Hook run when `gams-mode' starts."
:type 'hook
:group 'gams)
;; from yatex.el
(defcustom gams-close-paren-always t
"*Non-nil means that close parenthesis when you type `('."
:type 'boolean
:group 'gams)
(defcustom gams-close-double-quotation-always t
"*Non-nil means that close double quotation when you type `\"'."
:type 'boolean
:group 'gams)
(defcustom gams-close-single-quotation-always nil
"*Non-nil means that close quotation when you type `''."
:type 'boolean
:group 'gams)
(defcustom gams-statement-name "set"
"*The initial value of statement insertion."
:type 'string
:group 'gams)
(defcustom gams-dollar-control-name "exit"
"*The initial value of dollar control insertion."
:type 'string
:group 'gams)
(defcustom gams-user-comment
"
*------------------------------------------------------------------------
* %
*------------------------------------------------------------------------
"
"*User defined comment template.
You can insert the comment template defined in this variable by executing
`gams-insert-comment'. `%' in the string indicates the cursor place and
will disappear after template insertion. NB: If you want to include
double quoatations and backslashes in this variable, plese escape them
with a slash \."
:type 'string
:group 'gams)
(defcustom gams-comment-column 40
"*The default value of `comment-column' in GAMS mode."
:type 'integer
:group 'gams)
(defcustom gams-inlinecom-symbol-start-default "/*"
"*The default value for the inline comment start symbol.
You can insert the inline comment with `gams-comment-dwim-inline'."
:type 'string
:group 'gams)
(defcustom gams-inlinecom-symbol-end-default "*/"
"*The default value for the inline comment end symbol.
You can insert the inline comment with `gams-comment-dwim-inline'."
:type 'string
:group 'gams)
(defcustom gams-eolcom-symbol-default "#"
"*The default value for the end of line comment symbol.
You can insert the inline comment with `gams-comment-dwim'."
:type 'string
:group 'gams)
;;; from epolib.el
(defcustom gams-default-pop-window-height 15
"*The default GAMS process buffer height.
If integer, sets the window height of process buffer. If string, sets the
percentage of it. If nil, use default `pop-to-buffer'."
:type 'integer
:group 'gams)
(defcustom gams-docs-directory
(concat (file-name-as-directory gams-system-directory) "docs")
"*The GAMS document directory. By default, it is set to `gams-system-directory' + docs."
:type 'file
:group 'gams)
(defcustom gams-docs-url "https://www.gams.com/latest/docs/"
"*URL for the GAMS document."
:type 'url
:group 'gams)
(defcustom gams-model-library-url "https://www.gams.com/latest/docs/modlibs.html"
"*URL for the online GAMS model library."
:type 'url
:group 'gams)
(defcustom gams-insert-dollar-control-on nil
"*Non-nil means that $ key is binded to inserting dollar control options.
If nil, $ key is binded to inserting dollar itself."
:group 'gams
:type 'boolean)
(defcustom gams-always-popup-process-buffer t
"*Non-nil means popup always the GAMS process buffer when you run GAMS.
If nil, the GAMS process buffer does not popup unless you type `C-cC-l'."
:type 'boolean
:group 'gams)
(defcustom gams-gamslib-command "gamslib.exe"
"The file name of gamslib program.
If you do not include the GAMS system directory in PATH
environmental variable, you must set the full path to gamslib.exe
in this variable like
\"c:/GAMS23.1/gamslib.exe.\"."
:type 'file
:group 'gams)
(defcustom gams-special-comment-symbol "@"
"*The symbol that indicates the special comment."
:type 'string
:group 'gams)
(defcustom gams-display-small-logo t
"*If non-nil, display GAMS logo in the modeline."
:type 'boolean
:group 'gams)
(defcustom gams-align-default-spacing 3
"Spaces for `gams-align-block'."
:type 'integer
:group 'gams)
(defcustom gams-outline-regexp "\\*@+[ \t]"
"*Outline-regex for `gams-mode'.
Specify the regular expressions of the symbol used to represent headlines."
:type 'string
:group 'gams)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Variables for GAMS-TEMPLATE mode.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defcustom gams-template-file (concat user-emacs-directory "gams-template.txt")
"*The name of a file used to store templates."
:type 'file
:group 'gams)
(defcustom gams-save-template-change nil
"Determines the setting for saving a template file.
Nil means save the content of `gams-user-template-alist' into
`gams-template-file' only when you quit Emacs. If non-nil, save
`gams-user-template-alist' every time after you made any changes.
If your Emacs often crashes, you may had better set it to
non-nil."
:type 'boolean
:group 'gams)
(defcustom gams-template-cont-color t
"*Non-nil means colorization of *Template Content* buffer.
Non-nil may make the speed of template-mode slow."
:type 'boolean
:group 'gams)
(defcustom gams-template-mark "%c"
"*The mark that indicates the point of cursor in a template."
:type 'string
:group 'gams)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Variables for GAMS-SIL & SID.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defcustom gams-sil-follow-mode t
"If non-nil, follow mode is on in GAMS-SIL mode by default."
:type 'boolean
:group 'gams)
(defcustom gams-sil-window-height 15
"The default height of GAMS-SIL buffer."
:type 'number
:group 'gams)
(defcustom gams-sil-window-width 50
"The default width of GAMS-SIL buffer."
:type 'number
:group 'gams)
(defcustom gams-sid-tree-buffer-width 40
"Width of GAMS-SID Tree buffer."
:type 'integer
:group 'gams)
(defcustom gams-sid-position-symbol "=>"
"Symbol used to indicate the current position in GAMS-SID.
Up to two letters."
:type 'string
:group 'gams)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Variables for font-lock.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defcustom gams-font-lock-level 2
"*The default level of colring in GAMS mode.
0 => no color.
1 => minimum.
2 => maximize."
:group 'gams
:type 'integer)
(defcustom gams-lst-font-lock-level 2
"*The default level of coloring in GAMS-LST mdoe.
0 => no color.
1 => minimum.
2 => maximize."
:group 'gams
:type 'integer)
(defcustom gams-ol-font-lock-level 2
"*The default level of coloring in GAMS-OUTLINE mode.
0 => no color.
1 => minimum.
2 => maximize."
:group 'gams
:type 'integer)
(defcustom gams-lst-mode-hook nil
"*GAMS-LST mode hooks."
:type 'hook
:group 'gams)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Variables for GAMS-LST mode.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defvar gams-lst-gms-extention "gms"
"*GAMS program file extention.")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Variables for automatic indent.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defcustom gams-indent-on t
"*If non-nil, automatic indent for GAMS mode is enabled.
If nil, automatic indent doesn't work and tab key insert tab itself."
:type 'boolean
:group 'gams)
(defcustom gams-indent-number 4
"*Indent number for general statemets."
:type 'integer
:group 'gams)
(defcustom gams-indent-number-loop 4
"*Indent number in loop type environment.
loop type statement means \"loop\", \"if\", \"while\", \"for\" etc."
:type 'integer
:group 'gams)
(defcustom gams-indent-number-mpsge 4
"*Indent number in mpsge type environment.
MPSGE type statement means \"$sector:\", \"$commodities:\", \"$prod:\"
etc."
:type 'integer
:group 'gams)
(defcustom gams-indent-number-equation 4
"*Indent number for equation definition."
:type 'integer
:group 'gams)
(defcustom gams-indent-equation-on t
"*Non-nil means indent equation blocks.
If nil, already written equations are not affected by `gams-indent-line'."
:type 'boolean
:group 'gams)
(defcustom gams-indent-more-indent nil
"Non-nil means more indentation."
:type 'boolean
:group 'gams)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Variables for GAMS-OUTLINE mode.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defcustom gams-ol-height 15
"*The default height of the OUTLINE buffer with one LST buffer.
You can change the height of the OUTLINE buffer with
`gams-ol-narrow-one-line' and `gams-ol-widen-one-line'."
:type 'integer
:group 'gams)
(defcustom gams-ol-height-two 8
"*The default height of the OUTLINE buffer with two LST buffers.
You can change the height of the OUTLINE buffer with
`gams-ol-narrow-one-line' and `gams-ol-widen-one-line'."
:type 'integer
:group 'gams)
(defcustom gams-ol-view-item
'(("SUM" . t)
("VAR" . t)
("EQU" . t)
("PAR" . t)
("SET" . t)
("VRI" . t)
("LOO" . t)
("OTH" . t)
("COM" . t)
("INF" . t)
)
"The default alist of viewable items.
Each list consists of a pair of the item name and its flag
(\"ITEM_NAME\" . flag)
Non-nil of flag means the item is viewable by default.
The order of items has the meaning in this alist. Items are listed in the
SELECT-ITEM buffer according to this order. So, if you want to show MAR
on the top, you must write MAR at the fisrt in this alist."
:type '(repeat (cons :tag "option" (string :tag "item") (boolean :tag "flag")))
:group 'gams)
(defcustom gams-ol-item-name-width 20
"The width of item name field in GAMS-OUTLINE."
:type 'integer
:group 'gams)
(defcustom gams-ol-mode-hook nil
"*Hook run when GAMS-OUTLINE mode starts."
:type 'hook
:group 'gams)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Variables for GAMS-LXI mode.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defvar gams-lxi-maximum-line 1000000
"The maximum number of lines for GAMS-LXI mode.
This determines the maximum number of lines of the LST file that
GAMS LXI mode loads. If the number of lines of the LST file
exceeds this value, GAMS-LXI mode only loads a part of it.")
(defcustom gams-lxi-command-name "gamslxi.exe"
"*File name of external program for creating the LXI file.
If you want to use GAMS-LXI mode, you need to set the proper
value to this variable. If gamslxi.exe is placed at the
directory in PATH, you don't need change the default value. If
gamslxi.exe is not placed at the directory in PATH, you need to
set the full path to gamslxi.exe, for example,
(setq gams-lxi-command-name \"~/lisp/gams/gamslxi.exe\")
."
:type 'file
:group 'gams)
(defcustom gams-lxi-import-command-name "gamslxi-import.exe"
"*File name of external program for importing the LST file from GAMS-LXI mode.
If you want to use GAMS-LXI mode, you need to set the proper
value to this variable. If gamslxi-import.exe is placed at the
directory in PATH, you don't need change the default value. If
gamslxi-import.exe is not placed at the directory in PATH, you
need to set the full path to gamslxi-import.exe, for example,
(setq gams-lxi-command-name \"~/lisp/gams/gamslxi-import.exe\")
."
:type 'file
:group 'gams)
(defcustom gams-lxi-extension "lxi"
"The default extention used for the LXI file."
:type 'string
:group 'gams
)
(defcustom gams-lxi-width 40
"*The default width of the GAMS-LXI buffer.
You can change the width of the LXI buffer with
`gams-lxi-narrow-one-line' and `gams-lxi-widen-one-line'."
:type 'integer
:group 'gams)
(defcustom gams-lxi-mode-hook nil
"*GAMS-LXI mode hooks."
:type 'hook
:group 'gams)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Define customizable variables end here.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Other variables.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defvar gams-statement-up
'("SET" "SETS" "SCALAR" "SCALARS" "TABLE" "PARAMETER" "PARAMETERS"
"EQUATION" "EQUATIONS" "VARIABLE" "VARIABLES"
"POSITIVE VARIABLE" "POSITIVE VARIABLES"
"NONNEGATIVE VARIABLE" "NONNEGATIVE VARIABLES"
"NEGATIVE VARIABLE" "NEGATIVE VARIABLES"
"INTEGER VARIABLE" "INTEGER VARIABLES"
"BINARY VARIABLE" "BINARY VARIABLES"
"SINGLETON SET" "SINGLETON SETS"
"ALIAS"
"OPTION"
"EXECUTE_LOAD" "EXECUTE_UNLOAD"
"SOLVE" "MODEL" "DISPLAY" "LOOP" "IF" "SUM" "PROD")
"*The default list of GAMS statements.
Used for candidate of statement inserting. Use upper case to
register statements in this variable.")
(defvar gams-dollar-control-up
'("BATINCLUDE" "EXIT" "INCLUDE" "LIBINCLUDE"
"OFFTEXT" "ONTEXT" "SETGLOBAL" "SYSINCLUDE"
"TITLE" "MACRO")
"The default list of GAMS dollar control options.
Used for candidate of dollar control inserting. Use upper case to
register dollar control options in this variable.")
(defvar gams-statement-mpsge
'("auxiliaries:" "auxiliary:" "commodities:" "commodity:" "constraint:"
"consumer:" "consumers:" "demand:" "model:" "prod:" "report:" "sectors:")
"The default list of MPSGE statements.
Used for candidate of MPSGE dollar control inserting.")
(defvar gams-run-key ?s
"*Key to run GAMS in the process menu.")
(defvar gams-kill-key ?k
"*Key to kill GAMS process in the process menu.")
(defvar gams-option-key ?o
"*Key to select command option in the process menu.")
(defvar gams-change-command-key ?c
"*Key to select GAMS command in the process menu.")
;;;;; Key bindgings.
(defcustom gams-olk-1 "?"
"*Key for `gams-ol-help'."
:type 'string
:group 'gams-keys)
(defcustom gams-olk-4 "T"
"*Key for `gams-ol-select-item'."
:type 'string
:group 'gams-keys)
(defcustom gams-olk-5 " "
"*Key for `gams-ol-view-base'."
:type 'string
:group 'gams-keys)
(defcustom gams-olk-6 "q"
"*Key for `gams-ol-quit'."
:type 'string
:group 'gams-keys)
(defcustom gams-olk-7 "m"
"*Key for `gams-ol-mark'."
:type 'string
:group 'gams-keys)
(defcustom gams-olk-8 "t"
"*Key for `gams-ol-item'."
:type 'string
:group 'gams-keys)
;;; Key for GAMS-LST mode.
(defcustom gams-lk-1 "i"
"Key for `gams-lst-jump-to-input-file'."
:type 'string
:group 'gams-keys)
(defcustom gams-lk-2 "u"
"Key for `gams-lst-jump-to-error-file'."
:type 'string
:group 'gams-keys)
(defcustom gams-lk-3 "y"
"Key for `gams-lst-view-error'."
:type 'string
:group 'gams-keys)
(defcustom gams-lk-4 "b"
"Key for `gams-lst-jump-to-input-file-2'."
:type 'string
:group 'gams-keys)
(defcustom gams-lk-5 "l"
"Key for `gams-lst-jump-to-line'."
:type 'string
:group 'gams-keys)
(defcustom gams-choose-font-lock-level-key "\C-c\C-f"
"*The keybinding for `gams-choose-font-lock-level'."
:type 'string
:group 'gams-keys)
(defcustom gams-sil-expand-file-more t
"*If non-nil, expand more files in GAMS-SIL.
In GAMS-SIL mode, the contents of files included by $include
commands are usually expanded. For example,
$include zzz.gms
The content of zzz.gms is always expanded in GAMS-SIL.
$if exist xxx.gms $include xxx.gms
However, the content of xxx.gms is expanded only if
`gams-sil-expand-file-more' is non-nil."
:type 'boolean
:group 'gams)
(defcustom gams-sil-expand-batinclude t
"*If non-nil, GAMS-SIL mode expands files included by $batinclude.
In GAMS-SIL mode, the contents of files included by $include
commands are always expanded. But files included by $batinclude are
not expanded if `gams-sil-expand-batinclude' is nil."
:type 'boolean
:group 'gams)
(defcustom gams-sil-mode-hook nil
"*Hook run when GAMS-SIL mode starts."
:type 'hook
:group 'gams)
(defcustom gams-n-level-faces 8
"The number of different faces to be used for headlines.
Org-mode defines 8 different headline faces, so this can be at most 8.
If it is less than 8, the level-1 face gets re-used for level N+1 etc.
Taken from `org-n-level-faces'."
:type 'integer
:group 'gams)
(defcustom gams-cycle-level-faces t
"Non-nil means level styles cycle after level `gams-n-level-faces'.
Then so level gams-n-level-faces+1 is styled like level 1.
If nil, then all levels >=`gams-n-level-faces` are styled like
level `gams-n-level-faces`
Taken from `org-cycle-level-faces'."
:group 'gams
:type 'boolean)
(defcustom gams-level-color-stars-only nil
"Non-nil means fontify only the stars in each headline.
When nil, the entire headline is fontified. Changing it requires
restart of function `font-lock-mode' to become effective also in
regions already fontified.
Taken from `org-level-color-stars-only'."
:group 'gams
:type 'boolean)
(defcustom gams-outline-regexp-font-lock "^\\([*]\\@*\\)\\(\\@[ \t]\\)\\(.*\\)"
"*Regular expressions of headline for font-lock."
:type 'string
:group 'gams)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Non-customizable variables.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; It is not recommended to change the values of variables below.
;; They are basically intended to be used internally.
;;
(defvar gams-eolcom-symbol nil)
(defvar gams-inlinecom-symbol-start nil)
(defvar gams-inlinecom-symbol-end nil)
(setq-default gams-eolcom-symbol nil)
(setq-default gams-inlinecom-symbol-start nil)
(setq-default gams-inlinecom-symbol-end nil)
(defvar gams-statement-file-already-read nil)
(defvar gams-user-identifier-item-alist nil
"The list of combinations of items defined by users.")
(defvar gams-user-identifier-item-alist-initial nil)
(if (and (not gams-statement-file-already-read)
(file-exists-p gams-statement-file))
(condition-case err
(progn
(load-file gams-statement-file)
(setq gams-statement-file-already-read t))
(error
(message "Error(s) in %s! Need to check; %s"
gams-statement-file (error-message-string err))
(sleep-for 1))))
(setq gams-user-identifier-item-alist-initial
gams-user-identifier-item-alist)
;; Variables for Emacs version.
(defvar gams-win32 (memq system-type '(ms-dos windows-nt cygwin)))
(defun gams-convert-filename-gnupack (file)
"Convert FILE name to cygwin type."
(let ((fname file))
(when (string-match "^\\([a-zA-Z]\\):" fname)
(setq fname
(replace-match (concat "/" (match-string 1 fname)) t t fname))
(setq fname (replace-regexp-in-string "\\\\" "/" fname)))
fname))
;; (gams-convert-filename-gnupack "c:/gams/win64/24.1/gams.exe")
;; (gams-convert-filename-gnupack "c:\\gams\\win64\\24.1\\gams.exe")
;; (gams-convert-filename-gnupack "c:\\sample_gams_code\\./lst/test.lst")
;; (file-name-nondirectory "/c/gams/win64/24.1/gams.exe")
(defun gams-convert-filename-from-gnupack (file)
"Convert FILE name from cygwin type."
(let ((fname file))
(when (string-match "^\\(/\\)\\([a-zA-Z]\\)/" fname)
(setq fname
(replace-match (concat (match-string 2 fname) ":/") t t fname))
;;(setq fname (replace-regexp-in-string "\\\\" "/" fname))
)
fname))
;; (gams-convert-filename-from-gnupack "/c/gams/win64/24.1/gams.exe")
;;; If Emacs 20, define `gams-replace-regexp-in-string'. This code is
;;; `replace-regexp-in-string' from subr.el in the Emacs 21 distribution.
(if (fboundp 'replace-regexp-in-string)
(fset 'gams-replace-regexp-in-string 'replace-regexp-in-string)
(defun gams-replace-regexp-in-string (regexp rep string &optional
fixedcase literal subexp start)
"Replace all matches for REGEXP with REP in STRING.
This code is from subr.el in Emacs 21 distribution.
Return a new string containing the replacements.
Optional arguments FIXEDCASE, LITERAL and SUBEXP are like the
arguments with the same names of function `replace-match'. If START
is non-nil, start replacements at that index in STRING.
REP is either a string used as the NEWTEXT arg of `replace-match' or a
function. If it is a function it is applied to each match to generate
the replacement passed to `replace-match'; the match-data at this
point are such that match 0 is the function's argument.
To replace only the first match (if any), make REGEXP match up to \\'
and replace a sub-expression, e.g.
(replace-regexp-in-string \"\\(foo\\).*\\'\" \"bar\" \" foo foo\" nil nil 1)
=> \" bar foo\"
"
;; To avoid excessive consing from multiple matches in long strings,
;; don't just call `replace-match' continually. Walk down the
;; string looking for matches of REGEXP and building up a (reversed)
;; list MATCHES. This comprises segments of STRING which weren't
;; matched interspersed with replacements for segments that were.
;; [For a `large' number of replacments it's more efficient to
;; operate in a temporary buffer; we can't tell from the function's
;; args whether to choose the buffer-based implementation, though it
;; might be reasonable to do so for long enough STRING.]
(let ((l (length string))
(start (or start 0))
matches str mb me)
(save-match-data
(while (and (< start l) (string-match regexp string start))
(setq mb (match-beginning 0)
me (match-end 0))
;; If we matched the empty string, make sure we advance by one char
(when (= me mb) (setq me (min l (1+ mb))))
;; Generate a replacement for the matched substring.
;; Operate only on the substring to minimize string consing.
;; Set up match data for the substring for replacement;
;; presumably this is likely to be faster than munging the
;; match data directly in Lisp.
(string-match regexp (setq str (substring string mb me)))
(setq matches
(cons (replace-match (if (stringp rep)
rep
(funcall rep (match-string 0 str)))
fixedcase literal str subexp)
(cons (substring string start mb) ; unmatched prefix
matches)))
(setq start me))
;; Reconstruct a string from the pieces.
(setq matches (cons (substring string start l) matches)) ; leftover
(apply #'concat (nreverse matches))))))
;; For `find-lisp-find-files'.
(eval-and-compile
(require 'find-lisp))
(defvar gams-lst-extention "lst"
"GAMS LST file extention.")
(defvar gams-fill-prefix nil
"`fill-prefix` used for `auto-fill-mode`.
The default value is nil.")
(defvar gams-user-statement-list nil)
(defvar gams-user-dollar-control-list nil)
(defvar gams-paragraph-start nil)
(setq-default gams-paragraph-start "^\f\\|$\\|^[*]")
(defvar gams-command-process-buffer "*GAMS")
(defvar gams-statement-down
(mapcar 'downcase gams-statement-up))
(defvar gams-dollar-control-down
(mapcar 'downcase gams-dollar-control-up))
(defvar gams-statement-alist nil "?")
(defvar gams-dollar-control-alist nil "?")
(defvar gams-statement-regexp nil)
;;; From EPO.
(defconst gams-frame-feature-p
(and (fboundp 'make-frame) window-system))
;; This regular expression
(defsubst gams-regexp-opt (strings &optional paren)
"Create regular expression from STRINGS.
Optional PAREN specifies how the returned regexp is surrounded by
grouping constructs."
(regexp-opt strings paren))
(defvar gams-w32-system-shells
(if (boundp 'w32-system-shells)
(gams-regexp-opt w32-system-shells)
"command.com\\|cmd.exe\\|start.exe"))
(defsubst gams-get-id-name-without-index (name)
"Remove index from NAME."
(substring name 0 (string-match "(" name)))
;;; From yatexprc.el.
(defvar gams-shell-c
(or (and (boundp 'shell-command-option) shell-command-option)
(and (boundp 'shell-command-switch) shell-command-switch)
(if (string-match gams-w32-system-shells shell-file-name)
"/c" "-c"))
"Return shell option for command execution.")
;; Set `gams-buffer-substring' to `buffer-substring-no-properties' if it
;; exits. Otherwise set to `buffer-substring'.
(if (fboundp 'buffer-substring-no-properties)
(fset 'gams-buffer-substring 'buffer-substring-no-properties)
(fset 'gams-buffer-substring 'buffer-substring))
(cond
((fboundp 'screen-height)
(fset 'gams-screen-height 'screen-height)
(fset 'gams-screen-width 'screen-width))
((fboundp 'frame-height)
(fset 'gams-screen-height 'frame-height)
(fset 'gams-screen-width 'frame-width))
(t (error "I don't know how to run GAMS on this Emacs")))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; code for completion at point
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun gams-import-words-from-file (file)
"Import words from a text file and remove the double quotes."
(if (file-exists-p file)
(with-temp-buffer
(insert-file-contents file)
(let ((content (buffer-string)))
(split-string (replace-regexp-in-string "\"" "" content) "\n" t)))
(progn (message (concat file " file cannot be found."))
(sit-for 1)
nil)))
(defvar gams-commands
(or (gams-import-words-from-file
(expand-file-name
"gams-commands.txt"
(file-name-directory (or load-file-name default-directory))))
nil)
"List of GAMS commands for completion.")
(defvar gams-commands-dollar-if
'("if" "ifE" "ifI" "ifThen" "ifThenE" "ifThenI" "elseIf" "elseIfE" "elseIfI")
"List of $if commands")
(defvar gams-commands-dollar-conditional
'("acrType"
"decla_OK"
"declared"
"defined"
"dExist"
"dimension"
"empty"
"equType"
"errorFree"
"errorLevel"
"exist"
"filType"
"funType"
"gamsVersion"
"gdxDimension"
"gdxEquType"