forked from technomancy/emacs-starter-kit
/
quack.el
4698 lines (4182 loc) · 189 KB
/
quack.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
;;; quack.el --- enhanced support for editing and running Scheme code
;; http://www.neilvandyke.org/quack/quack.el
(defconst quack-copyright "Copyright (C) 2002-2010 Neil Van Dyke")
(defconst quack-copyright-2 "Portions Copyright (C) Free Software Foundation")
;; Emacs-style font-lock specs adapted from GNU Emacs 21.2 scheme.el.
;; Scheme Mode menu adapted from GNU Emacs 21.2 cmuscheme.el.
(defconst quack-version "0.40")
(defconst quack-author-name "Neil Van Dyke")
(defconst quack-author-email "neil@neilvandyke.org")
(defconst quack-web-page "http://www.neilvandyke.org/quack/")
(defconst quack-legal-notice
"This 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 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. See
http://www.gnu.org/licenses/ for details. For other licenses and consulting,
please contact Neil Van Dyke.")
(defconst quack-cvsid "$Id: quack.el,v 1.469 2010/12/23 00:01:33 neilpair Exp $")
;;; Commentary:
;; INTRODUCTION:
;;
;; Quack enhances Emacs support for Scheme programming.
;;
;; Install Quack rather than following non-Quack-based tutorials on how to
;; set up Emacs for Scheme.
;;
;; The name "Quack" was a play on "DrScheme".
;;
;; Quack is dedicated to Yosh, naturally.
;; COMPATIBILITY:
;;
;; GNU Emacs 22 -- Yes. Quack is now developed under GNU Emacs 22 on a
;; GNU/Linux system, which is the preferred platform for Quacksmokers.
;; Quack should work under GNU Emacs 22 on any Un*x-like OS. Reportedly,
;; Quack also works with GNU Emacs 22 on Apple Mac OS X and Microsoft
;; Windows (NT, 2000, XP), but the author has no means of testing on those
;; platforms.
;;
;; GNU Emacs 22 -- Yes.
;;
;; GNU Emacs 21 -- Probably, but no longer tested.
;;
;; GNU Emacs 20 -- Probably mostly. When last tested. Some of the menus do
;; not work properly, due to a bug in easymenu.el (which the FSF will not
;; fix, since they no longer support Emacs 20). Nested block comments are
;; not fontified correctly. Pretty-lambda does not work. Quack runs less
;; efficiently in 20 than 21, due to the lack of standard hash tables.
;;
;; XEmacs 21 -- Probably mostly, but no longer tested. Block comment
;; fontification is not yet supported under XEmacs 21, due to what appears
;; to be a bug in 21.4 font-lock. Pretty-lambda does not work. XEmacs
;; Quacksmokers who always want the latest and greatest Quack should
;; consider GNU Emacs 21 -- Quack treats XEmacs like a high-maintenance
;; redheaded stepchild.
;; INSTALLATION:
;;
;; To install, put this file (`quack.el') somewhere in your Emacs load
;; path, and add the following line to your `.emacs' file:
;;
;; (require 'quack)
;;
;; If you don't know what your Emacs load path is, try invoking the command
;; "C-h v load-path RET" or consulting the Emacs manual.
;;
;; Note to advanced Emacsers: Byte-compiled `quack.elc' files generally are
;; *not* portable between Emacs implementations, nor between different
;; versions of the same implementation.
;;
;; You will also need the GNU `wget' program, which Quack uses for
;; downloading SRFI indexes. This popular program is included in most
;; GNU/Linux distributions and is available for most other platforms.
;;
;; Note to PLT Scheme users: If you do not already have the PLT manuals
;; installed, they can be downloaded from
;; `http://download.plt-scheme.org/doc/' and installed in your PLT `doc'
;; collection. If Quack is not finding installed PLT manuals, then be sure
;; that the `quack-pltcollect-dirs' variable contains the appropriate
;; collection directory (if it does not, then either set the `PLTHOME'
;; and/or `PLTCOLLECTS' environment variables appropriately, or set
;; `quack-pltcollect-dirs').
;; KEY BINDINGS:
;;
;; The key bindings that Quack adds to `scheme-mode' include:
;;
;; C-c C-q m View a manual in your Web browser.
;; C-c C-q k View the manual documentation for a keyword
;; (currently only works for PLT manuals).
;; C-c C-q s View an SRFI.
;; C-c C-q r Run an inferior Scheme process.
;; C-c C-q f Find a file using context of point for default.
;; C-c C-q l Toggle `lambda' syntax of `define'-like form.
;; C-c C-q t Tidy the formatting of the buffer.
;;
;; One additional command that does not currently have a standard binding
;; is `quack-dired-pltcollect', which prompts for a PLT collection name and
;; creates a Dired buffer on the collection's directory. (A future version
;; of Quack may integrate this functionality into a more generalized
;; documentation navigation interface.)
;; RELEASE ANNOUNCEMENTS EMAIL:
;;
;; To receive email notification when a new Quack version is released, ask
;; neil@neilvandyke.org to add you to the moderated `scheme-announce' list.
;; HISTORY:
;;
;; Version 0.40 (2010-12-22)
;; * Added indent rules for Racket `let:', `let*:', and `match'. And
;; a provisional rule for `define:'.
;;
;; Version 0.39 (2010-10-18)
;; * Renamed "typed/scheme" to "typed/racket".
;;
;; Version 0.38 (2010-10-14)
;; * Replaced old PLT Scheme programs in `quack-programs' with Racket.
;; * Added Racket ".rkt" and ".rktd" filename extensions.
;; * Added some Racket keywords for fontifying.
;;
;; Version 0.37 (2009-06-29)
;; * Disabled highlighting of "Compilation started at" lines.
;;
;; Version 0.36 (2009-05-27)
;; * Made `#:' ``colon keywords'' fontify in PLT-ish mode.
;; * Added PLT `r6rs' and `typed-scheme' languages to `quack-programs'.
;;
;; Version 0.35 (2009-02-24)
;; * Added `interpreter-mode-alist' support, so Scheme scripts with "#!"
;; start in `scheme-mode'.
;; * Added PLT `parameterize-break'.
;; * Improved `compile' mode for PLT 4.x tracebacks when there is only
;; file, line, and column, but no additional information.
;;
;; Version 0.34 (2009-02-19)
;; * Added fontify and indent support for PLT `define/kw', `lambda/kw',
;; `parameterize*'.
;; * Fontify Unix "#!" cookie in PLT-ish font-lock.
;; * Changed reference to `quack-announce' email list to
;; `scheme-announce'.
;; * Added PLT `default-load-handler' to
;; `quack-compilation-error-regexp-alist-additions'
;; * Changed some face ":height" attributes.
;;
;; Version 0.33 (2008-07-31)
;; * Added handlers for some PLT 4.0.1 "setup-plt" messages.
;;
;; Version 0.32 (2008-06-19)
;; * Added to `quack-programs'.
;; * Updated compatibility comments.
;; * Added indent rule for `for/fold'.
;;
;; Version 0.31 (2008-05-03)
;; * Added `defvar' for `quack-pltish-font-lock-keywords', so that the
;; GNU Emacs 22.1 compiler doesn't complain about assignment to a free
;; variable.
;; * Changed banner regexp for MzScheme for v3.99.x.
;; * Set `dynamic-wind' `scheme-indent-function to 0, when the default
;; is 3. It was just taking up too much space. DrScheme's
;; indentation seems to be equivalent -1, so there is precedent for
;; something different. We generally respect Emacs indentation
;; convention.
;; * Added fontifying and indent for PLT `define-for-syntax',
;; `define-values-for-syntax', `quasisyntax', `quasisyntax/loc',
;; `syntax', `syntax/loc', `define-parameters'.
;; * Advise `scheme-interactively-start-process' for GNU Emacs 22.
;; * Removed TODO comment that mentioned using `(current-eventspace
;; (make-eventspace))' under `mred', as Robby Findler has indicated
;; that is not good advice.
;;
;; Version 0.30 (2007-06-27)
;; * Emacs 22 compatibility change: `string-to-number' instead of
;; `string-to-int'. Thanks to Charles Comstock.
;;
;; Version 0.29 (2006-11-12)
;; * Fixed `quack-bar-syntax-string', which caused vertical bar
;; characters to be treated as whitespace. Thanks to Eric Hanchrow
;; for reporting.
;;
;; Version 0.28 (2005-05-14)
;; * Added `quack-smart-open-paren-p'.
;; * Changed `scheme-indent-function' for `parameterize' from `defun'
;; to `1'.
;; * In `quack-pltish-keywords-to-fontify': added `quasiquote',
;; `unquote', and `unquote-splicing'.
;; * Added ".mzschemerc" to `auto-mode-alist'.
;; * Added a little extra threesemi fontification for Funcelit and
;; similar Texinfo markup formats.
;;
;; Version 0.27 (2004-12-19)
;; * For Gambit-C, added REPL banner fontifying, `quack-manuals' entry,
;; and "gsi ~~/syntax-case.scm -" `quack-programs' entry.
;; * Changed "[PLT]" prefix on PLT manuals to "PLT", to make it easier
;; to type.
;; * Minor changes to reflect "MIT Scheme" becoming "MIT/GNU Scheme".
;;
;; Version 0.26 (2004-07-14)
;; * Added fontifying of a bunch of "define-"* syntax from Chicken.
;;
;; Version 0.25 (2004-07-09)
;; * Added `define-record-type' to `quack-pltish-keywords-to-fontify'.
;; * Added "csi -hygienic" to `quack-programs'.
;; * In `quack-manuals', replaced PLT-specific `r5rs' and `t-y-scheme'
;; with generic ones.
;; * Updated URL in `quack-manuals' for 3rd ed. of `tspl'.
;; * `quack-view-manual' completions no longer include symbols.
;; * `quack-view-manual' completion default is now "R5RS".
;;
;; Version 0.24 (2004-05-09)
;; * Made `quack-pltish-keywords-to-fontify' and
;; `quack-emacs-keywords-to-fontify' custom changes update
;; immediately. Bug reported by Taylor Campbell.
;; * Removed some non-syntax names from
;; `quack-pltish-keywords-to-fontify'.
;; * Documentation changes.
;;
;; Version 0.23 (2003-11-11)
;; * `quack-local-keywords-for-remote-manuals-p' can now have the value
;; of the symbol `always', to work around a defect in some versions
;; of Microsoft Windows. Thanks to Bill Clementson.
;; * `quack-w3m-browse-url-other-window' no longer splits a `*w3m*'
;; buffer.
;; * Added indent and `quack-pltish-keywords-to-fontify' rules for
;; `c-lambda' and `c-declare'.
;;
;; Version 0.22 (2003-07-03)
;; * `quack-newline-behavior' controls the RET key behavior in Scheme
;; buffers.
;; * In `quack-manuals', added Chez Scheme, and updated Chicken.
;; * Added error message navigation to `compile' for PLT `setup-plt'.
;; * Partial fix for Quack global menu disappearing from the main menu
;; bar in XEmacs. Thought it used to work, but it doesn't in XEmacs
;; 21.4.12.
;;
;; Version 0.21 (2003-05-28)
;; * `quack-find-file' is faster in many cases due to fix to
;; `quack-backward-sexp'.
;; * Added auto-mode-alist for `.ccl', `.stk', and `.stklos' files.
;; * Indent rule additions/changes for `chicken-setup' and `unit/sig'.
;;
;; Version 0.20 (2003-05-04)
;; * Added indent and fontify for SRFI-8 "receive".
;; * Added indent and fontify for additional PLT syntax.
;; * Added `quack-fontify-threesemi-p'.
;; * `quack-tidy-buffer' sets `fill-prefix' to nil when running.
;; * Added messages to `run-scheme', if only to get rid of annoying
;; "Mark set" message.
;; * Added "mzscheme -M errortrace" to `quack-programs'.
;; * `quack-dired-pltcollect' prompt defaults to `mzlib'.
;; * "Update SRFI Index" menu item has moved to top of menu, mainly to
;; avoid usability issue in a particular Emacs menu implementation.
;; * Several code quality improvements sent by Stefan Monnier will be
;; in the next release.
;;
;; Version 0.19 (2003-03-04)
;; * Commands such as `scheme-load-file' now start a Scheme process if
;; none is found.
;; * Bugfix for using `match-string-no-properties' when we meant
;; `quack-match-string-no-properties'. (Thanks to Noel Welsh.)
;;
;; Version 0.18 (2003-05-02)
;; * Removed uses of `(regexp-opt LIST t)', since XEmacs21 does not
;; create match data. (Thanks to Garrett Mitchener for debugging.)
;; * Added to `quack-programs' and `quack-manuals'.
;; * Added pretty-case-lambda.
;; * Changed PLT documentation URL function.
;;
;; Version 0.17 (2003-01-03)
;; * Pretty-lambda is supported well under GNU Emacs 21, when using PLT
;; Style fontification. Enable via the Options menu. (Based on
;; approach by Stefan Monnier; suggested by Ray Racine.)
;; * Various faces now have separate defaults for `light' and `dark'
;; backgrounds, so may now look better on dark backgrounds.
;; (Suggested by Eli Barzilay.)
;; * `quack-find-file' now respects `insert-default-directory' when
;; there is no default file. (Thanks to Eli Barzilay.)
;; * Most of the special w3m support has been moved to a separate
;; package, `w3mnav' (`http://www.neilvandyke.org/w3mnav/').
;; `quack-w3m-browse-url-other-window' has been added.
;;
;; Version 0.16 (2002-12-16)
;; * `quack-insert-closing' now calls `blink-paren-function'. (Thanks
;; to Guillaume Marceau and Steve Elkins for reporting this.)
;; * Now uses PLT 202 manuals. Added "PLT Framework" manual.
;; * Added `quack-pltish-module-defn-face'.
;; * Added some PLTish font-lock keywords.
;;
;; Version 0.15 (2002-11-21)
;; * "Keywords" are now fontified in PLT Style fontification mode.
;; * Definition names are now blue by default in PLT Style.
;; * Symbol literals with vertical bars are now fontified in PLT Style.
;; * New `quack-manuals-webjump-sites' function for people who prefer
;; to use the `webjump' package for invoking manuals.
;; * New `quack-quiet-warnings-p' option.
;; * New `quack-pltish-class-defn-face' face.
;;
;; Version 0.14 (2002-10-18)
;; * Fix for `quack-view-manual' interactive prompting (thanks to Marko
;; Slyz for reporting this).
;; * `quack-emacsw3m-go-next' and `quack-emacsw3m-go-prev' now work
;; with GTK reference documentation (not that this has anything to do
;; with Scheme).
;; * Added SLIB to `quack-manuals'.
;; * Added comment about installing PLT manuals (thanks to Marko).
;; * We now call the canonical version of Emacs "GNU Emacs," instead of
;; "FSF Emacs".
;;
;; Version 0.13 (2002-09-21)
;; * Bugfix: No longer drop SRFI index entries on the floor.
;;
;; Version 0.12 (2002-09-20)
;; * New "View SRFI" menu. Select "Update SRFI Index" if the submenus
;; "Draft", "Final", and "Withdrawn" are disabled.
;; * Most options are now settable via "Options" menu.
;; * PLT collections are no longer scanned when building "View Manuals"
;; menu.
;; * "View Keyword Docs..." back on Scheme Mode menu in addition to
;; Quack menu.
;; * Various `defcustom' variables have been made to dynamically update
;; relevant program state when changed.
;; * Under GNU Emacs 20, dynamic menus still do not work -- they now
;; display, but do not perform the selected action. Will do more
;; debugging after this release.
;; * '[' and ']' keys work in emacs-w3m of MIT Scheme manuals.
;;
;; Version 0.11 (2002-09-17)
;; * Menus now work under XEmacs. Also now partly broken for Emacs 20.
;; * New global "Quack" menu. Disable with `quack-global-menu-p'.
;; * New "View Manual" submenu under GNU Emacs 21 and XEmacs (GNU Emacs
;; 20 is stuck with the old "View Manual..." menu item).
;; * Fix for `quack-pltcollects-alist' to include PLT `doc' collection,
;; which was preventing local manuals from being used.
;; * `quack-manuals' now includes `t-y-scheme'.
;; * `quack-view-in-different-browser' command that spawns alternative
;; Web browser from the special emacs-w3m support, bound to `B'. For
;; when you normally view manuals in an Emacs window, but
;; occasionally want to view a particular page in normal Web browser.
;; * More `scheme-indent-function' properties set.
;; * `quack-about' command.
;; * Fix to `quack-keyword-at-point'.
;;
;; Version 0.10 (2002-09-11)
;; * `quack-view-srfi' now prompts with completion, including titles
;; for all SRFIs. The SRFI titles are fetched from the official SRFI
;; Web site using the GNU Wget program, and cached locally.
;; * `quack-view-srfi' also now defaults to the SRFI number at or near
;; the point.
;; * `quack-dir' variable specifies a directory where Quack should
;; store its persistent data files (e.g., cached SRFI indexes), and
;; defaults to "~/.quack/".
;; * New `quack-tidy-buffer' command. [C-c C-q t] is now bound to
;; this; [C-c C-q l] ("l" as in "lambda) is now the official binding
;; for `quack-toggle-lambda'.
;; * `quack-find-file' now recognizes PLT `dynamic-require' form.
;; * Fix to make `quack-looking-at-backward' preserve match data.
;; * Fix for benign bug in `quack-parent-sexp-search'.
;;
;; Version 0.9 (2002-09-04)
;; * Quack now works under XEmacs 21, except no menus are currently
;; defined (that will come in a later version) and block comments
;; aren't fontified.
;; * `quack-toggle-lambda' command toggles a `define' form between
;; explicit and implicit `lambda' syntax.
;; * `quack-dired-pltcollect' feature prompts for a PLT collection name
;; and creates a Dired on the collection.
;; * `)' and `]' keys are bound to insert a closing character that
;; agrees with the opening character of the sexp.
;; * Nested `#|' comment blocks are now fontified mostly correctly
;; under GNU Emacs 21.
;; * Fix to `quack-parent-sexp-search'.
;; * Fix for PLT manual keywords lookup under Emacs 20.
;; * `quack-manuals' URLs for assorted implementation manuals now point
;; to canonical Web copies.
;; * No longer warns about PLT manual keywords file found without HTML.
;; * `find-file' key bindings are automatically remapped to
;; `quack-find-file' in Scheme buffers.
;; * Both PLT-style and Emacs-style fontification now work with the
;; `noweb-mode' package. Tested under GNU Emacs 21 with
;; Debian `nowebm' package version 2.10c-1.
;; * Added to `quack-emacsish-keywords-to-fontify'.
;; * Disabled fontification of named `let'.
;; * Renamed "collect" in PLT identifiers to "pltcollect".
;; * `auto-mode-alist' set more aggressively.
;;
;; Version 0.8 (2002-08-25)
;; * PLT package file viewing mode. This is mainly used to easily
;; inspect a ".plt" package before installing it via DrScheme or
;; "setup-plt".
;; * No longer warns about `font-lock-keywords' when `noweb-mode'
;; package is installed.
;;
;; Version 0.7 (2002-08-22)
;; * Now works on GNU Emacs 20 (though people are still encouraged to
;; upgrade to GNU Emacs 21 if they are able).
;; * `quack-manuals' now includes MIT Scheme and Chicken manuals
;; (currently where Debian GNU/Linux puts them).
;; * `quack-view-srfi' command.
;; * Named-`let' name is fontified like a PLTish definition name.
;; * `define-record' and `define-opt' fontified.
;; * Scheme Mode is forced in `auto-mode-alist' for ".sch" files.
;; * Fix to `quack-backward-sexp'.
;; * `quack-warning' messages get your attention.
;; * `quack-pltrequire-at-point-data-1' search depth limited.
;;
;; Version 0.6 (2002-08-20)
;; * `quack-find-file' now supports multi-line PLT `require' forms.
;; * When `emacs-w3m' is used, the keys "[", "]", and "t" are bound to
;; navigate through PLT manuals like in Info mode.
;; * Names highlighted in PLT-style fontification of `defmacro',
;; `defmacro-public', `defsyntax'.
;; * Advised `run-scheme' no longer prompts when there is already a
;; running Scheme.
;; * "csi" (Chicken interpreter) added to `quack-programs' default.
;; * Forces `auto-mode-alist' for ".scm" files to `scheme-mode'
;; (two can play at that game, `bee-mode'!).
;; * To-do comments moved from the top of the file to throughout code.
;;
;; Version 0.5 (2002-08-15)
;; * New `quack-find-file' permits quick navigation to files indicated
;; by a PLT Scheme `require' form under the point. Currently only
;; works when the "(require" string is on the same line as point.
;; * Improved PLT-style fontification. Most noticeable difference is
;; that names in many definition forms are boldfaced. See
;; `quack-pltish-fontify-definition-names-p' option.
;; * `quack-collects-alist' added.
;; * "~/plt/" has been removed from `quack-collect-dirs' default.
;; * Unnecessary syntax table settings have been removed.
;; * Reduced memory usage in some cases, via explicit GC calls.
;;
;; Version 0.4 (2002-08-07)
;; * Functionality adapted from author's `giguile.el' package:
;; - Enhanced `run-scheme' behavior. `quack-run-mzscheme',
;; `quack-run-mred', and `quack-remove-run-scheme-menu-item-p'
;; are obsolete.
;; - Enhanced `switch-to-scheme' behavior.
;; - Options menu.
;; - Indent rules for a few Guile-isms.
;; * Inferior Scheme Mode now uses the preferred fontification method.
;; * Now uses the PLT-bundled version of R5RS manual, which permits
;; keyword searching.
;; * `quack-banner-face' for the MzScheme/MrEd banner in REPL buffer.
;; * This code includes a start on toolbars and XEmacs21 portability,
;; but neither feature is yet functional.
;;
;; Version 0.3 (2002-08-01)
;; * PLT-style fontification added, except for quoted lists. Emacs-
;; style fontification still available; see `quack-fontify-style'.
;; * `emacs-w3m' package support for lightweight viewing of PLT manuals
;; in Emacs window. If you install the `emacs-w3m' package, then you
;; can change the new `quack-browse-url-browser-function' option to
;; use it.
;; * Quack menu items added to Scheme Mode menu. "Run Scheme" item
;; is removed by default; see `quack-remove-run-scheme-menu-item-p'.
;; * MrEd REPL supported with `quack-run-mred'.
;; * Better default for `quack-collect-dirs'.
;; * More `scheme-indent-function' settings.
;; * Bugfix for `quack-prompt-for-kwmatch-choice'.
;; * Bugfix for font-lock keywords getting set too early.
;; * Now byte-compiles without warnings/errors.
;;
;; Version 0.2 (2002-07-28)
;; * Manual keywords lookup.
;; * Other minor changes.
;;
;; Version 0.1 (2002-07-18)
;; * Initial release.
;; ADMONISHMENT TO IMPRESSIONABLE YOUNG SCHEME STUDENTS:
;;
;; Quack should by no means be construed as a model of good programming,
;; much less of good software engineering. Emacs is by nature a complex
;; system of interacting kludges. To get Emacs to do useful new things is
;; to artfully weave one's extensions into a rich tapestry of sticky duct
;; tape. Also, Quack usually only got hacked on when I was stuck in a busy
;; lobby for an hour with a laptop and unable to do real work.
;;; Code:
;; Dependencies:
(require 'advice)
(require 'cmuscheme)
(require 'compile)
(require 'custom)
(require 'easymenu)
(require 'font-lock)
(require 'scheme)
(require 'thingatpt)
(unless (fboundp 'customize-save-variable)
(autoload 'customize-save-variable "cus-edit"))
;; Custom Variables:
(defgroup quack nil
"Enhanced support for editing and running Scheme code."
:group 'scheme
:prefix "quack-"
:link '(url-link "http://www.neilvandyke.org/quack/"))
(defcustom quack-dir "~/.quack"
"*Directory where Quack stores various persistent data in file format."
:type 'string
:group 'quack)
(defcustom quack-scheme-mode-keymap-prefix "\C-c\C-q"
"*Keymap prefix string for `quack-scheme-mode-keymap'.
One of the nice things about having C-q in the prefix is that it is unlikely to
be already be in use, due to the historical reality of software flow control
\(and the fact that it is hard to type). If your C-q doesn't seem to be going
through, then you have several options: disable flow control (if it is safe to
do so), change the value of this variable, or see the Emacs documentation for
`enable-flow-control-on'."
:type 'string
:group 'quack)
(defcustom quack-remap-find-file-bindings-p t
"Whether to remap `find-file' key bindings to `quack-find-file'.
The local map in Scheme Mode and Inferior Scheme Mode buffers is used."
:type 'boolean
:group 'quack)
(defcustom quack-global-menu-p t
"*Whether to have a \"Quack\" menu always on the menu bar."
:type 'boolean :group 'quack)
(defcustom quack-tabs-are-evil-p t
"*Whether Quack should avoid use of Tab characters in indentation."
:type 'boolean
:group 'quack)
(defcustom quack-browse-url-browser-function nil
"*Optional override for `browse-url-browser-function'.
If non-nil, overrides that variable for URLs viewed by `quack-browse-url'."
:type '(choice (const :tag "Do Not Override" nil)
(function :tag "Function")
(alist :tag "Regexp/Function Association List"
:key-type regexp :value-type function))
:group 'quack)
(defcustom quack-manuals ; TODO: Options menu.
;; TODO: If we make this so users are likely to want to override parts of it,
;; then introduce `quack-manuals-defaults' variable with this in it,
;; and let users edit `quack-manuals-overrides' which are keyed on the
;; ID symbol.
;; TODO: Have a way for finding docs on the local filesystem, and/or
;; permitting a user to easily specify location.
;; TODO: Provide a way of specifying alternative access means so that, for
;; example, we can look for R5RS first in locally-installed PLT
;; collection, then in one of various non-PLT directories it might be
;; mirrored, then remote PLT copy using local PLT keywords file, then
;; the canonical HTML copy on the Web... Maybe even permit Info
;; format. Let's just reinvent the Web, while we're at it.
'(
(r5rs "R5RS"
"http://www.schemers.org/Documents/Standards/R5RS/HTML/"
nil)
(bigloo
"Bigloo"
"http://www-sop.inria.fr/mimosa/fp/Bigloo/doc/bigloo.html"
;;"file:///usr/share/doc/bigloo/manuals/bigloo.html"
nil)
(chez
"Chez Scheme User's Guide"
"http://www.scheme.com/csug/index.html"
nil)
(chicken
"Chicken User's Manual"
"http://www.call-with-current-continuation.org/manual/manual.html"
;;"file:///usr/share/doc/chicken/manual.html"
nil)
(gambit
"Gambit-C home page"
"http://www.iro.umontreal.ca/~gambit/")
(gauche
"Gauche Reference Manual"
"http://www.shiro.dreamhost.com/scheme/gauche/man/gauche-refe.html"
nil)
(mitgnu-ref
"MIT/GNU Scheme Reference"
"http://www.gnu.org/software/mit-scheme/documentation/scheme.html"
;;"http://www.swiss.ai.mit.edu/projects/scheme/documentation/scheme.html"
;;"file:///usr/share/doc/mit-scheme/html/scheme.html"
nil)
(mitgnu-user
"MIT/GNU Scheme User's Manual"
"http://www.gnu.org/software/mit-scheme/documentation/user.html"
;;"http://www.swiss.ai.mit.edu/projects/scheme/documentation/user.html"
;;"file:///usr/share/doc/mit-scheme/html/user.html"
nil)
(mitgnu-sos
"MIT/GNU Scheme SOS Reference Manual"
"http://www.gnu.org/software/mit-scheme/documentation/sos.html"
;;"http://www.swiss.ai.mit.edu/projects/scheme/documentation/sos.html"
;;"file:///usr/share/doc/mit-scheme/html/sos.html"
nil)
(plt-mzscheme "PLT MzScheme: Language Manual" plt t)
(plt-mzlib "PLT MzLib: Libraries Manual" plt t)
(plt-mred "PLT MrEd: Graphical Toolbox Manual" plt t)
(plt-framework "PLT Framework: GUI Application Framework" plt t)
(plt-drscheme "PLT DrScheme: Programming Environment Manual" plt nil)
(plt-insidemz "PLT Inside PLT MzScheme" plt nil)
(plt-tools "PLT Tools: DrScheme Extension Manual" plt nil)
(plt-mzc "PLT mzc: MzScheme Compiler Manual" plt t)
(plt-r5rs "PLT R5RS" plt t)
(scsh
"Scsh Reference Manual"
"http://www.scsh.net/docu/html/man-Z-H-1.html"
;;"file:///usr/share/doc/scsh-doc/scsh-manual/man-Z-H-1.html"
nil)
(sisc
"SISC for Seasoned Schemers"
"http://sisc.sourceforge.net/manual/html/"
nil)
(htdp "How to Design Programs"
"http://www.htdp.org/"
nil)
(htus "How to Use Scheme"
"http://www.htus.org/"
nil)
(t-y-scheme "Teach Yourself Scheme in Fixnum Days"
"http://www.ccs.neu.edu/home/dorai/t-y-scheme/t-y-scheme.html"
nil)
(tspl "Scheme Programming Language (Dybvig)"
"http://www.scheme.com/tspl/"
nil)
(sicp "Structure and Interpretation of Computer Programs"
"http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-4.html"
nil)
(slib "SLIB"
"http://swissnet.ai.mit.edu/~jaffer/SLIB.html"
nil)
(faq "Scheme Frequently Asked Questions"
"http://www.schemers.org/Documents/FAQ/"
nil))
"*List of specifications of manuals that can be viewed.
Each manual specification is a list of four elements:
(SYMBOL TITLE LOCATION USE-KEYWORDS-P)
where SYMBOL is a short symbol that identifies the manual, TITLE is a string,
LOCATION is either a string with the URL of the manual or the symbol `plt',
and USE-KEYWORDS-P is `t' or `nil'.
If LOCATION is `plt', then Quack treats it as a PLT bundled manual, looking for
the HTML and keyword files in `quack-pltcollect-dirs', and optionally providing
keyword lookup if USE-KEYWORDS-P is `t'. Remote canonical copies of the
manuals will be used if local copies cannot be found.
If LOCATION is a URL, then USE-KEYWORDS-P must be `nil'."
:type '(repeat (list (symbol :tag "Identifying Symbol")
(string :tag "Title String")
(choice :tag "Location"
(string :tag "URL")
(const :tag "PLT Bundled Manual" plt))
(boolean :tag "Use Keywords?")))
:group 'quack)
(defcustom quack-local-keywords-for-remote-manuals-p t
"*If non-nil, Quack will use canonical remote Web URLs when there is a local
keyword file for a PLT manual but no local HTML files. (This feature was
prompted by the Debian 200.2-3 package for MzScheme, which includes keyword
files but not HTML files.) If the symbol `always', then Quack will always use
remote Web manuals for keywords lookup, even if local HTML files exist, as a
workaround for how some versions of Emacs interact with some versions of
Microsoft Windows \(inexplicably discarding the fragment identifier from `file'
scheme URI\)."
:type '(choice (const :tag "Permit" t)
(const :tag "Forbid" nil)
(const :tag "Always" always))
:group 'quack
:set 'quack-custom-set
:initialize 'custom-initialize-default)
(defcustom quack-srfi-master-base-url "http://srfi.schemers.org/"
;; Note: Intentionally not letting user change this through the options menu.
"*The base URL for the master SRFI Web pages.
The SRFI index files should be immediately beneath this."
:type 'string
:group 'quack)
(defcustom quack-pltcollect-dirs
(let ((good '()))
(mapcar (function (lambda (dir)
(and dir
(not (assoc dir good))
(file-directory-p dir)
(setq good (nconc good (list dir))))))
`(,@(let ((v (getenv "PLTCOLLECTS")))
(and v (split-string v ":")))
,(let ((v (getenv "PLTHOME")))
(and v (expand-file-name "collects" v)))
,@(mapcar 'expand-file-name
'("/usr/lib/plt/collects"
"/usr/local/lib/plt/collects"))))
good)
"*PLT collection directories.
Listed in order of priority."
:type '(repeat directory)
:group 'quack
:set 'quack-custom-set
:initialize 'custom-initialize-default)
(defcustom quack-fontify-style 'plt
"*Which font-lock fontification style to use.
If symbol `plt', an approximation of PLT DrScheme 200 Check Syntax
fontification will be used. If symbol `emacs', then fontification in the style
of GNU Emacs' Scheme Mode with extensions will be used. If nil, then Quack
will not override the default Scheme Mode fontification."
:type '(choice (const :tag "PLT Style" plt)
(const :tag "Extended GNU Emacs Style" emacs)
(const :tag "Emacs Default" nil))
:group 'quack
:set 'quack-custom-set
:initialize 'custom-initialize-default)
(defcustom quack-pltish-fontify-definition-names-p t
"*If non-nil, fontify names in definition forms for PLT-style fontification.
This only has effect when `quack-fontify-style' is `plt'."
:type 'boolean
:group 'quack
:set 'quack-custom-set
:initialize 'custom-initialize-default)
(defcustom quack-pltish-fontify-keywords-p t
;; TODO: Rename this from "keywords" to "syntax-keywords", here, and in for
;; face names.
"*If non-nil, fontify keywords in PLT-style fontification.
This only has effect when `quack-fontify-style' is `plt'."
:type 'boolean
:group 'quack
:set 'quack-custom-set
:initialize 'custom-initialize-default)
(defcustom quack-pltish-keywords-to-fontify
;; TODO: These are currently R5RS and some SRFI special syntax plus a bunch
;; of PLT, especially PLT 200 class.ss, and some "define-"* variants from
;; various dialects, plus some Racket 5.0.2... The dumbness of this kind of
;; highlighting without regard to context is not really satisfactory.
'(
"and" "begin" "begin0" "c-declare" "c-lambda" "case" "case-lambda" "class"
"class*" "class*/names" "class100" "class100*" "compound-unit/sig" "cond"
"cond-expand" "define" "define-class" "define-compound-unit"
"define-const-structure"
"define-constant" "define-embedded" "define-entry-point" "define-external"
"define-for-syntax" "define-foreign-record" "define-foreign-type"
"define-foreign-variable" "define-generic" "define-generic-procedure"
"define-inline" "define-location" "define-macro" "define-method"
"define-module" "define-opt" "define-public" "define-reader-ctor"
"define-record" "define-record-printer" "define-record-type"
"define-signature" "define-struct" "define-structure" "define-syntax"
"define-syntax-set" "define-values" "define-values-for-syntax"
"define-values/invoke-unit/infer"
"define-values/invoke-unit/sig" "define/contract" "define/override"
"define/private" "define/public" "define/kw"
"delay" "do" "else" "exit-handler" "field"
"if" "import" "inherit" "inherit-field" "init" "init-field" "init-rest"
"instantiate" "interface" "lambda" "lambda/kw" "let" "let*" "let*-values"
"let+"
"let-syntax" "let-values" "let/ec" "letrec" "letrec-values" "letrec-syntax"
"match-lambda" "match-lambda*" "match-let" "match-let*" "match-letrec"
"match-define" "mixin" "module" "opt-lambda" "or" "override" "override*"
"namespace-variable-bind/invoke-unit/sig" "parameterize" "parameterize*"
"parameterize-break" "private"
"private*" "protect" "provide" "provide-signature-elements"
"provide/contract" "public" "public*" "quasiquote"
"quasisyntax" "quasisyntax/loc" "quote" "receive"
"rename" "require" "require-for-syntax" "send" "send*" "set!" "set!-values"
"signature->symbols" "super-instantiate" "syntax" "syntax/loc"
"syntax-case" "syntax-case*" "syntax-error" "syntax-rules" "unit/sig"
"unless" "unquote" "unquote-splicing" "when" "with-handlers" "with-method"
"with-syntax"
"define-type-alias"
"define-struct:"
"define:"
"let:"
"letrec:"
"let*:"
"lambda:"
"plambda:"
"case-lambda:"
"pcase-lambda:"
"require/typed"
"require/opaque-type"
"require-typed-struct"
"inst"
"ann"
)
"*Scheme keywords to fontify when `quack-fontify-style' is `plt'."
:type '(repeat string)
:group 'quack
:set 'quack-custom-set
:initialize 'custom-initialize-default)
(defcustom quack-emacsish-keywords-to-fontify
'("and" "begin" "begin0" "call-with-current-continuation"
"call-with-input-file" "call-with-output-file" "call/cc" "case"
"case-lambda" "class" "cond" "delay" "do" "else" "exit-handler" "field"
"for-each" "if" "import" "inherit" "init-field" "interface" "lambda" "let"
"let*" "let*-values" "let-values" "let-syntax" "let/ec" "letrec"
"letrec-syntax" "map" "mixin" "opt-lambda" "or" "override" "protect"
"provide" "public" "rename" "require" "require-for-syntax" "syntax"
"syntax-case" "syntax-error" "syntax-rules" "unit/sig" "unless" "when"
"with-syntax")
"*Scheme keywords to fontify when `quack-fontify-style' is `emacs'."
:type '(repeat string)
:group 'quack
:set 'quack-custom-set
:initialize 'custom-initialize-default)
(defcustom quack-fontify-threesemi-p t
"*Whether three-semicolon comments should be fontified differently."
:type 'boolean
:group 'quack
:set 'quack-custom-set
:initialize 'custom-initialize-default)
(defcustom quack-pretty-lambda-p nil
"*Whether Quack should display \"lambda\" as the lambda character.
`quack-fontify-style' must be `plt'. Only supported under GNU Emacs version
21\; not under XEmacs or older GNU Emacs.
Note: Pretty lambda requires that suitable iso8859-7 fonts be available. Under
Debian/GNU Linux, for example, these can be downloaded and installed with the
shell command \"apt-get install 'xfonts-greek-*'\". If iso8859-7 fonts are
unavailable for your system, please notify the Quack author."
:type 'boolean
:group 'quack
:set 'quack-custom-set
:initialize 'custom-initialize-default)
(defcustom quack-programs
'("bigloo" "csi" "csi -hygienic" "gosh" "gracket" "gsi"
"gsi ~~/syntax-case.scm -" "guile" "kawa" "mit-scheme" "racket"
"racket -il typed/racket" "rs" "scheme" "scheme48" "scsh" "sisc" "stklos"
"sxi")
"List of Scheme interpreter programs that can be used with `run-scheme'.
These names will be accessible via completion when `run-scheme' prompts for
which program to run."
:group 'quack
:type '(repeat string)
:set 'quack-custom-set
:initialize 'custom-initialize-default)
(defcustom quack-default-program "mzscheme"
"Default Scheme interpreter program to use with `run-scheme'."
:group 'quack
:type 'string)
(defcustom quack-run-scheme-always-prompts-p t
"`run-scheme' should always prompt for which program to run.
If nil, `run-scheme' will always use `quack-default-program' when invoked
interactively without a prefix argument; this is closest to the behavior of the
`cmuscheme' package."
:group 'quack
:type 'boolean)
(defcustom quack-run-scheme-prompt-defaults-to-last-p t
"If non-nil, `run-scheme' prompt should default to the last program run."
:group 'quack
:type 'boolean)
(defcustom quack-remember-new-programs-p t
"Programs are added to `quack-programs' automatically."
:group 'gigule
:type 'boolean)
(defcustom quack-switch-to-scheme-method 'other-window
"Method to use for choosing a window and frame for the process buffer.
One of three symbols:
`other-window' will split display in a different window in the current frame,
splitting the current window if necessary.
`own-frame' will display the process buffer in its own frame.
`cmuscheme' will use the normal behavior of the `cmuscheme' package."
:group 'quack
:type '(choice (const :tag "Other Window" other-window)
(const :tag "Own Frame" own-frame)
(const :tag "Cmuscheme Behavior" cmuscheme)))
(defcustom quack-warp-pointer-to-frame-p t
"Warp mouse pointer to frame with Scheme process buffer.
When `quack-switch-to-scheme-method' is `own-frame', `switch-to-scheme' will
warp the mouse pointer to the frame displaying the Scheme process buffer."
:group 'quack
:type 'boolean)
(defcustom quack-newline-behavior 'newline-indent
"*Behavior of the RET key in Scheme-Mode buffers. The value is one of three
symbols: `newline' inserts a normal newline, `newline-indent' \(the default\)
inserts a newline and leaves the point properly indented on the new line, and
`indent-newline-indent' indents the current line before inserting a newline and
indenting the new one."
:type '(choice (const 'newline)
(const 'newline-indent)
(const 'indent-newline-indent))
:group 'quack)
(defcustom quack-smart-open-paren-p nil
"The `[' can be used to insert `(' characters.
Actually, this just makes the `(' and '[' keys both insert `(', unless given a
prefix argument. This makes typing parens easier on typical keyboards for
which `(' requires a shift modifier but `[' does not. A later version of Quack
might add actual \"smart\" support for automatic PLT-esque insertion of `['
instead of `(' in some syntactic contexts."
:group 'quack
:type 'boolean)
(defcustom quack-options-persist-p t
"Option menu settings and programs persist using the `custom' facility.
Note that the value of this option itself cannot be set persistently via the
option menu -- you must use the `customize' interface or set it manually in an
Emacs startup file. This is by design, to avoid the risk of users accidentally
disabling their ability to set persistent options via the option menu."
:group 'quack
:type 'boolean)
(defcustom quack-quiet-warnings-p t ; TODO: Options menu.
"Warning messages are quiet and subtle."
:group 'quack
:type 'boolean)
(defconst quack-pltish-comment-face 'quack-pltish-comment-face)
(defface quack-pltish-comment-face
'((((class color) (background light)) (:foreground "cyan4"))
(((class color) (background dark)) (:foreground "cyan1"))
(t (:slant italic)))
"Face used for comments when `quack-fontify-style' is `plt'."
:group 'quack)
(defconst quack-pltish-selfeval-face 'quack-pltish-selfeval-face)
(defface quack-pltish-selfeval-face
'((((class color) (background light)) (:foreground "green4"))
(((class color) (background dark)) (:foreground "green2"))
(t ()))
"Face used for self-evaluating forms when `quack-fontify-style' is `plt'."
:group 'quack)
(defconst quack-pltish-paren-face 'quack-pltish-paren-face)
(defface quack-pltish-paren-face
'((((class color) (background light)) (:foreground "red3"))
(((class color) (background dark)) (:foreground "red1"))
(((class grayscale)) (:foreground "gray"))
(t ()))
"Face used for parentheses when `quack-fontify-style' is `plt'."
:group 'quack)
(defconst quack-pltish-colon-keyword-face 'quack-pltish-colon-keyword-face)
(defface quack-pltish-colon-keyword-face
'((t (:bold t :foreground "gray50")))
"Face used for `#:' keywords when `quack-fontify-style' is `plt'.
Note that this isn't based on anything in PLT."
:group 'quack)
(defconst quack-pltish-paren-face 'quack-pltish-paren-face)
(defface quack-pltish-paren-face
'((((class color) (background light)) (:foreground "red3"))
(((class color) (background dark)) (:foreground "red1"))
(((class grayscale)) (:foreground "gray"))
(t ()))