forked from jrockway/cperl-mode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cperl-mode.el
8947 lines (8459 loc) · 321 KB
/
cperl-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
;;; cperl-mode.el --- Perl code editing commands for Emacs
;; Copyright (C) 1985, 1986, 1987, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
;; 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
;; Free Software Foundation, Inc.
;; Author: Ilya Zakharevich
;; Bob Olson
;; Maintainer: Jonathan Rockway <jon@jrock.us>
;; Keywords: languages, Perl
;; This particular file is not actually part of GNU Emacs.
;; It is from http://github.com/jrockway/cperl-mode
;; GNU Emacs 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 3 of the License, or
;; (at your option) any later version.
;; GNU Emacs 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.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
;;; Corrections made by Ilya Zakharevich ilyaz@cpan.org
;;; Commentary:
;; This version of the file contains support for the syntax added by
;; the MooseX::Declare CPAN module, as well as Perl 5.10 keyword
;; support.
;; The latest version is available from
;; http://github.com/jrockway/cperl-mode
;;
;; (perhaps in the moosex-declare branch)
;; You can either fine-tune the bells and whistles of this mode or
;; bulk enable them by putting
;; (setq cperl-hairy t)
;; in your .emacs file. (Emacs rulers do not consider it politically
;; correct to make whistles enabled by default.)
;; DO NOT FORGET to read micro-docs (available from `Perl' menu) <<<<<<
;; or as help on variables `cperl-tips', `cperl-problems', <<<<<<
;; `cperl-praise', `cperl-speed'. <<<<<<
;; The mode information (on C-h m) provides some customization help.
;; If you use font-lock feature of this mode, it is advisable to use
;; either lazy-lock-mode or fast-lock-mode. I prefer lazy-lock.
;; Faces used now: three faces for first-class and second-class keywords
;; and control flow words, one for each: comments, string, labels,
;; functions definitions and packages, arrays, hashes, and variable
;; definitions. If you do not see all these faces, your font-lock does
;; not define them, so you need to define them manually.
;; This mode supports font-lock, imenu and mode-compile. In the
;; hairy version font-lock is on, but you should activate imenu
;; yourself (note that mode-compile is not standard yet). Well, you
;; can use imenu from keyboard anyway (M-x imenu), but it is better
;; to bind it like that:
;; (define-key global-map [M-S-down-mouse-3] 'imenu)
;;; Font lock bugs as of v4.32:
;; The following kinds of Perl code erroneously start strings:
;; \$` \$' \$"
;; $opt::s $opt_s $opt{s} (s => ...) /\s+.../
;; likewise with m, tr, y, q, qX instead of s
;;; Code:
(defvar vc-rcs-header)
(defvar vc-sccs-header)
(eval-when-compile
(condition-case nil
(require 'custom)
(error nil))
(condition-case nil
(require 'man)
(error nil))
(defvar cperl-can-font-lock
(or (featurep 'xemacs)
(and (boundp 'emacs-major-version)
(or window-system
(> emacs-major-version 20)))))
(if cperl-can-font-lock
(require 'font-lock))
(defvar msb-menu-cond)
(defvar gud-perldb-history)
(defvar font-lock-background-mode) ; not in Emacs
(defvar font-lock-display-type) ; ditto
(defvar paren-backwards-message) ; Not in newer XEmacs?
(or (fboundp 'defgroup)
(defmacro defgroup (name val doc &rest arr)
nil))
(or (fboundp 'custom-declare-variable)
(defmacro defcustom (name val doc &rest arr)
`(defvar ,name ,val ,doc)))
(or (and (fboundp 'custom-declare-variable)
(string< "19.31" emacs-version)) ; Checked with 19.30: defface does not work
(defmacro defface (&rest arr)
nil))
;; Avoid warning (tmp definitions)
(or (fboundp 'x-color-defined-p)
(defmacro x-color-defined-p (col)
(cond ((fboundp 'color-defined-p) `(color-defined-p ,col))
;; XEmacs >= 19.12
((fboundp 'valid-color-name-p) `(valid-color-name-p ,col))
;; XEmacs 19.11
((fboundp 'x-valid-color-name-p) `(x-valid-color-name-p ,col))
(t '(error "Cannot implement color-defined-p")))))
(defmacro cperl-is-face (arg) ; Takes quoted arg
(cond ((fboundp 'find-face)
`(find-face ,arg))
(;;(and (fboundp 'face-list)
;; (face-list))
(fboundp 'face-list)
`(member ,arg (and (fboundp 'face-list)
(face-list))))
(t
`(boundp ,arg))))
(defmacro cperl-make-face (arg descr) ; Takes unquoted arg
(cond ((fboundp 'make-face)
`(make-face (quote ,arg)))
(t
`(defvar ,arg (quote ,arg) ,descr))))
(defmacro cperl-force-face (arg descr) ; Takes unquoted arg
`(progn
(or (cperl-is-face (quote ,arg))
(cperl-make-face ,arg ,descr))
(or (boundp (quote ,arg)) ; We use unquoted variants too
(defvar ,arg (quote ,arg) ,descr))))
(if (featurep 'xemacs)
(defmacro cperl-etags-snarf-tag (file line)
`(progn
(beginning-of-line 2)
(list ,file ,line)))
(defmacro cperl-etags-snarf-tag (file line)
`(etags-snarf-tag)))
(if (featurep 'xemacs)
(defmacro cperl-etags-goto-tag-location (elt)
;;(progn
;; (switch-to-buffer (get-file-buffer (elt ,elt 0)))
;; (set-buffer (get-file-buffer (elt ,elt 0)))
;; Probably will not work due to some save-excursion???
;; Or save-file-position?
;; (message "Did I get to line %s?" (elt ,elt 1))
`(goto-line (string-to-int (elt ,elt 1))))
;;)
(defmacro cperl-etags-goto-tag-location (elt)
`(etags-goto-tag-location ,elt))))
(defvar cperl-can-font-lock
(or (featurep 'xemacs)
(and (boundp 'emacs-major-version)
(or window-system
(> emacs-major-version 20)))))
(defun cperl-choose-color (&rest list)
(let (answer)
(while list
(or answer
(if (or (x-color-defined-p (car list))
(null (cdr list)))
(setq answer (car list))))
(setq list (cdr list)))
answer))
(defgroup cperl nil
"Major mode for editing Perl code."
:prefix "cperl-"
:group 'languages
:version "20.3")
(defgroup cperl-indentation-details nil
"Indentation."
:prefix "cperl-"
:group 'cperl)
(defgroup cperl-affected-by-hairy nil
"Variables affected by `cperl-hairy'."
:prefix "cperl-"
:group 'cperl)
(defgroup cperl-autoinsert-details nil
"Auto-insert tuneup."
:prefix "cperl-"
:group 'cperl)
(defgroup cperl-faces nil
"Fontification colors."
:link '(custom-group-link :tag "Font Lock Faces group" font-lock-faces)
:prefix "cperl-"
:group 'cperl)
(defgroup cperl-speed nil
"Speed vs. validity tuneup."
:prefix "cperl-"
:group 'cperl)
(defgroup cperl-help-system nil
"Help system tuneup."
:prefix "cperl-"
:group 'cperl)
(defcustom cperl-extra-newline-before-brace nil
"*Non-nil means that if, elsif, while, until, else, for, foreach
and do constructs look like:
if ()
{
}
instead of:
if () {
}"
:type 'boolean
:group 'cperl-autoinsert-details)
(defcustom cperl-extra-newline-before-brace-multiline
cperl-extra-newline-before-brace
"*Non-nil means the same as `cperl-extra-newline-before-brace', but
for constructs with multiline if/unless/while/until/for/foreach condition."
:type 'boolean
:group 'cperl-autoinsert-details)
(defcustom cperl-indent-level 2
"*Indentation of CPerl statements with respect to containing block."
:type 'integer
:group 'cperl-indentation-details)
;; Is is not unusual to put both things like perl-indent-level and
;; cperl-indent-level in the local variable section of a file. If only
;; one of perl-mode and cperl-mode is in use, a warning will be issued
;; about the variable. Autoload these here, so that no warning is
;; issued when using either perl-mode or cperl-mode.
;;;###autoload(put 'cperl-indent-level 'safe-local-variable 'integerp)
;;;###autoload(put 'cperl-brace-offset 'safe-local-variable 'integerp)
;;;###autoload(put 'cperl-continued-brace-offset 'safe-local-variable 'integerp)
;;;###autoload(put 'cperl-label-offset 'safe-local-variable 'integerp)
;;;###autoload(put 'cperl-continued-statement-offset 'safe-local-variable 'integerp)
;;;###autoload(put 'cperl-extra-newline-before-brace 'safe-local-variable 'booleanp)
;;;###autoload(put 'cperl-merge-trailing-else 'safe-local-variable 'booleanp)
(defcustom cperl-lineup-step nil
"*`cperl-lineup' will always lineup at multiple of this number.
If nil, the value of `cperl-indent-level' will be used."
:type '(choice (const nil) integer)
:group 'cperl-indentation-details)
(defcustom cperl-brace-imaginary-offset 0
"*Imagined indentation of a Perl open brace that actually follows a statement.
An open brace following other text is treated as if it were this far
to the right of the start of its line."
:type 'integer
:group 'cperl-indentation-details)
(defcustom cperl-brace-offset 0
"*Extra indentation for braces, compared with other text in same context."
:type 'integer
:group 'cperl-indentation-details)
(defcustom cperl-label-offset -2
"*Offset of CPerl label lines relative to usual indentation."
:type 'integer
:group 'cperl-indentation-details)
(defcustom cperl-min-label-indent 1
"*Minimal offset of CPerl label lines."
:type 'integer
:group 'cperl-indentation-details)
(defcustom cperl-continued-statement-offset 2
"*Extra indent for lines not starting new statements."
:type 'integer
:group 'cperl-indentation-details)
(defcustom cperl-continued-brace-offset 0
"*Extra indent for substatements that start with open-braces.
This is in addition to cperl-continued-statement-offset."
:type 'integer
:group 'cperl-indentation-details)
(defcustom cperl-close-paren-offset -1
"*Extra indent for substatements that start with close-parenthesis."
:type 'integer
:group 'cperl-indentation-details)
(defcustom cperl-indent-wrt-brace t
"*Non-nil means indent statements in if/etc block relative brace, not if/etc.
Versions 5.2 ... 5.20 behaved as if this were `nil'."
:type 'boolean
:group 'cperl-indentation-details)
(defcustom cperl-indent-subs-specially t
"*Non-nil means indent subs that are inside other blocks (hash values, for example) relative to the beginning of the \"sub\" keyword, rather than relative to the statement that contains the declaration."
:type 'boolean
:group 'cperl-indentation-details)
(defcustom cperl-auto-newline nil
"*Non-nil means automatically newline before and after braces,
and after colons and semicolons, inserted in CPerl code. The following
\\[cperl-electric-backspace] will remove the inserted whitespace.
Insertion after colons requires both this variable and
`cperl-auto-newline-after-colon' set."
:type 'boolean
:group 'cperl-autoinsert-details)
(defcustom cperl-autoindent-on-semi nil
"*Non-nil means automatically indent after insertion of (semi)colon.
Active if `cperl-auto-newline' is false."
:type 'boolean
:group 'cperl-autoinsert-details)
(defcustom cperl-auto-newline-after-colon nil
"*Non-nil means automatically newline even after colons.
Subject to `cperl-auto-newline' setting."
:type 'boolean
:group 'cperl-autoinsert-details)
(defcustom cperl-tab-always-indent t
"*Non-nil means TAB in CPerl mode should always reindent the current line,
regardless of where in the line point is when the TAB command is used."
:type 'boolean
:group 'cperl-indentation-details)
(defcustom cperl-font-lock nil
"*Non-nil (and non-null) means CPerl buffers will use `font-lock-mode'.
Can be overwritten by `cperl-hairy' if nil."
:type '(choice (const null) boolean)
:group 'cperl-affected-by-hairy)
(defcustom cperl-electric-lbrace-space nil
"*Non-nil (and non-null) means { after $ should be preceded by ` '.
Can be overwritten by `cperl-hairy' if nil."
:type '(choice (const null) boolean)
:group 'cperl-affected-by-hairy)
(defcustom cperl-electric-parens-string "({[]})<"
"*String of parentheses that should be electric in CPerl.
Closing ones are electric only if the region is highlighted."
:type 'string
:group 'cperl-affected-by-hairy)
(defcustom cperl-electric-parens nil
"*Non-nil (and non-null) means parentheses should be electric in CPerl.
Can be overwritten by `cperl-hairy' if nil."
:type '(choice (const null) boolean)
:group 'cperl-affected-by-hairy)
(defvar zmacs-regions) ; Avoid warning
(defcustom cperl-electric-parens-mark
(and window-system
(or (and (boundp 'transient-mark-mode) ; For Emacs
transient-mark-mode)
(and (boundp 'zmacs-regions) ; For XEmacs
zmacs-regions)))
"*Not-nil means that electric parens look for active mark.
Default is yes if there is visual feedback on mark."
:type 'boolean
:group 'cperl-autoinsert-details)
(defcustom cperl-electric-linefeed nil
"*If true, LFD should be hairy in CPerl, otherwise C-c LFD is hairy.
In any case these two mean plain and hairy linefeeds together.
Can be overwritten by `cperl-hairy' if nil."
:type '(choice (const null) boolean)
:group 'cperl-affected-by-hairy)
(defcustom cperl-electric-keywords nil
"*Not-nil (and non-null) means keywords are electric in CPerl.
Can be overwritten by `cperl-hairy' if nil.
Uses `abbrev-mode' to do the expansion. If you want to use your
own abbrevs in cperl-mode, but do not want keywords to be
electric, you must redefine `cperl-mode-abbrev-table': do
\\[edit-abbrevs], search for `cperl-mode-abbrev-table', and, in
that paragraph, delete the words that appear at the ends of lines and
that begin with \"cperl-electric\".
"
:type '(choice (const null) boolean)
:group 'cperl-affected-by-hairy)
(defcustom cperl-electric-backspace-untabify t
"*Not-nil means electric-backspace will untabify in CPerl."
:type 'boolean
:group 'cperl-autoinsert-details)
(defcustom cperl-hairy nil
"*Not-nil means most of the bells and whistles are enabled in CPerl.
Affects: `cperl-font-lock', `cperl-electric-lbrace-space',
`cperl-electric-parens', `cperl-electric-linefeed', `cperl-electric-keywords',
`cperl-info-on-command-no-prompt', `cperl-clobber-lisp-bindings',
`cperl-lazy-help-time'."
:type 'boolean
:group 'cperl-affected-by-hairy)
(defcustom cperl-comment-column 32
"*Column to put comments in CPerl (use \\[cperl-indent] to lineup with code)."
:type 'integer
:group 'cperl-indentation-details)
(defcustom cperl-indent-comment-at-column-0 nil
"*Non-nil means that comment started at column 0 should be indentable."
:type 'boolean
:group 'cperl-indentation-details)
(defcustom cperl-vc-sccs-header '("($sccs) = ('%W\%' =~ /(\\d+(\\.\\d+)+)/) ;")
"*Special version of `vc-sccs-header' that is used in CPerl mode buffers."
:type '(repeat string)
:group 'cperl)
(defcustom cperl-vc-rcs-header '("($rcs) = (' $Id\$ ' =~ /(\\d+(\\.\\d+)+)/);")
"*Special version of `vc-rcs-header' that is used in CPerl mode buffers."
:type '(repeat string)
:group 'cperl)
;; This became obsolete...
(defvar cperl-vc-header-alist nil)
(make-obsolete-variable
'cperl-vc-header-alist
"use cperl-vc-rcs-header or cperl-vc-sccs-header instead.")
(defcustom cperl-clobber-mode-lists
(not
(and
(boundp 'interpreter-mode-alist)
(assoc "miniperl" interpreter-mode-alist)
(assoc "\\.\\([pP][Llm]\\|al\\)$" auto-mode-alist)))
"*Whether to install us into `interpreter-' and `extension' mode lists."
:type 'boolean
:group 'cperl)
(defcustom cperl-info-on-command-no-prompt nil
"*Not-nil (and non-null) means not to prompt on C-h f.
The opposite behavior is always available if prefixed with C-c.
Can be overwritten by `cperl-hairy' if nil."
:type '(choice (const null) boolean)
:group 'cperl-affected-by-hairy)
(defcustom cperl-clobber-lisp-bindings nil
"*Not-nil (and non-null) means not overwrite C-h f.
The function is available on \\[cperl-info-on-command], \\[cperl-get-help].
Can be overwritten by `cperl-hairy' if nil."
:type '(choice (const null) boolean)
:group 'cperl-affected-by-hairy)
(defcustom cperl-lazy-help-time nil
"*Not-nil (and non-null) means to show lazy help after given idle time.
Can be overwritten by `cperl-hairy' to be 5 sec if nil."
:type '(choice (const null) (const nil) integer)
:group 'cperl-affected-by-hairy)
(defcustom cperl-pod-face 'font-lock-comment-face
"*Face for POD highlighting."
:type 'face
:group 'cperl-faces)
(defcustom cperl-pod-head-face 'font-lock-variable-name-face
"*Face for POD highlighting.
Font for POD headers."
:type 'face
:group 'cperl-faces)
(defcustom cperl-here-face 'font-lock-string-face
"*Face for here-docs highlighting."
:type 'face
:group 'cperl-faces)
;;; Some double-evaluation happened with font-locks... Needed with 21.2...
(defvar cperl-singly-quote-face (featurep 'xemacs))
(defcustom cperl-invalid-face 'underline
"*Face for highlighting trailing whitespace."
:type 'face
:version "21.1"
:group 'cperl-faces)
(defcustom cperl-pod-here-fontify '(featurep 'font-lock)
"*Not-nil after evaluation means to highlight POD and here-docs sections."
:type 'boolean
:group 'cperl-faces)
(defcustom cperl-fontify-m-as-s t
"*Not-nil means highlight 1arg regular expressions operators same as 2arg."
:type 'boolean
:group 'cperl-faces)
(defcustom cperl-highlight-variables-indiscriminately nil
"*Non-nil means perform additional highlighting on variables.
Currently only changes how scalar variables are highlighted.
Note that that variable is only read at initialization time for
the variable `cperl-font-lock-keywords-2', so changing it after you've
entered CPerl mode the first time will have no effect."
:type 'boolean
:group 'cperl)
(defcustom cperl-pod-here-scan t
"*Not-nil means look for POD and here-docs sections during startup.
You can always make lookup from menu or using \\[cperl-find-pods-heres]."
:type 'boolean
:group 'cperl-speed)
(defcustom cperl-regexp-scan t
"*Not-nil means make marking of regular expression more thorough.
Effective only with `cperl-pod-here-scan'."
:type 'boolean
:group 'cperl-speed)
(defcustom cperl-hook-after-change t
"*Not-nil means install hook to know which regions of buffer are changed.
May significantly speed up delayed fontification. Changes take effect
after reload."
:type 'boolean
:group 'cperl-speed)
(defcustom cperl-imenu-addback nil
"*Not-nil means add backreferences to generated `imenu's.
May require patched `imenu' and `imenu-go'. Obsolete."
:type 'boolean
:group 'cperl-help-system)
(defcustom cperl-max-help-size 66
"*Non-nil means shrink-wrapping of info-buffer allowed up to these percents."
:type '(choice integer (const nil))
:group 'cperl-help-system)
(defcustom cperl-shrink-wrap-info-frame t
"*Non-nil means shrink-wrapping of info-buffer-frame allowed."
:type 'boolean
:group 'cperl-help-system)
(defcustom cperl-info-page "perl"
"*Name of the info page containing perl docs.
Older version of this page was called `perl5', newer `perl'."
:type 'string
:group 'cperl-help-system)
(defcustom cperl-use-syntax-table-text-property
(boundp 'parse-sexp-lookup-properties)
"*Non-nil means CPerl sets up and uses `syntax-table' text property."
:type 'boolean
:group 'cperl-speed)
(defcustom cperl-use-syntax-table-text-property-for-tags
cperl-use-syntax-table-text-property
"*Non-nil means: set up and use `syntax-table' text property generating TAGS."
:type 'boolean
:group 'cperl-speed)
(defcustom cperl-scan-files-regexp "\\.\\([pP][Llm]\\|xs\\)$"
"*Regexp to match files to scan when generating TAGS."
:type 'regexp
:group 'cperl)
(defcustom cperl-noscan-files-regexp
"/\\(\\.\\.?\\|SCCS\\|RCS\\|CVS\\|blib\\)$"
"*Regexp to match files/dirs to skip when generating TAGS."
:type 'regexp
:group 'cperl)
(defcustom cperl-regexp-indent-step nil
"*Indentation used when beautifying regexps.
If nil, the value of `cperl-indent-level' will be used."
:type '(choice integer (const nil))
:group 'cperl-indentation-details)
(defcustom cperl-indent-left-aligned-comments t
"*Non-nil means that the comment starting in leftmost column should indent."
:type 'boolean
:group 'cperl-indentation-details)
(defcustom cperl-under-as-char nil
"*Non-nil means that the _ (underline) should be treated as word char."
:type 'boolean
:group 'cperl)
(defcustom cperl-extra-perl-args ""
"*Extra arguments to use when starting Perl.
Currently used with `cperl-check-syntax' only."
:type 'string
:group 'cperl)
(defcustom cperl-message-electric-keyword t
"*Non-nil means that the `cperl-electric-keyword' prints a help message."
:type 'boolean
:group 'cperl-help-system)
(defcustom cperl-indent-region-fix-constructs 1
"*Amount of space to insert between `}' and `else' or `elsif'
in `cperl-indent-region'. Set to nil to leave as is. Values other
than 1 and nil will probably not work."
:type '(choice (const nil) (const 1))
:group 'cperl-indentation-details)
(defcustom cperl-break-one-line-blocks-when-indent t
"*Non-nil means that one-line if/unless/while/until/for/foreach BLOCKs
need to be reformatted into multiline ones when indenting a region."
:type 'boolean
:group 'cperl-indentation-details)
(defcustom cperl-fix-hanging-brace-when-indent t
"*Non-nil means that BLOCK-end `}' may be put on a separate line
when indenting a region.
Braces followed by else/elsif/while/until are excepted."
:type 'boolean
:group 'cperl-indentation-details)
(defcustom cperl-merge-trailing-else t
"*Non-nil means that BLOCK-end `}' followed by else/elsif/continue
may be merged to be on the same line when indenting a region."
:type 'boolean
:group 'cperl-indentation-details)
(defcustom cperl-indent-parens-as-block nil
"*Non-nil means that non-block ()-, {}- and []-groups are indented as blocks,
but for trailing \",\" inside the group, which won't increase indentation.
One should tune up `cperl-close-paren-offset' as well."
:type 'boolean
:group 'cperl-indentation-details)
(defcustom cperl-syntaxify-by-font-lock
(and cperl-can-font-lock
(boundp 'parse-sexp-lookup-properties))
"*Non-nil means that CPerl uses `font-lock's routines for syntaxification."
:type '(choice (const message) boolean)
:group 'cperl-speed)
(defcustom cperl-syntaxify-unwind
t
"*Non-nil means that CPerl unwinds to a start of a long construction
when syntaxifying a chunk of buffer."
:type 'boolean
:group 'cperl-speed)
(defcustom cperl-syntaxify-for-menu
t
"*Non-nil means that CPerl syntaxifies up to the point before showing menu.
This way enabling/disabling of menu items is more correct."
:type 'boolean
:group 'cperl-speed)
(defcustom cperl-ps-print-face-properties
'((font-lock-keyword-face nil nil bold shadow)
(font-lock-variable-name-face nil nil bold)
(font-lock-function-name-face nil nil bold italic box)
(font-lock-constant-face nil "LightGray" bold)
(cperl-array-face nil "LightGray" bold underline)
(cperl-hash-face nil "LightGray" bold italic underline)
(font-lock-comment-face nil "LightGray" italic)
(font-lock-string-face nil nil italic underline)
(cperl-nonoverridable-face nil nil italic underline)
(font-lock-type-face nil nil underline)
(font-lock-warning-face nil "LightGray" bold italic box)
(underline nil "LightGray" strikeout))
"List given as an argument to `ps-extend-face-list' in `cperl-ps-print'."
:type '(repeat (cons symbol
(cons (choice (const nil) string)
(cons (choice (const nil) string)
(repeat symbol)))))
:group 'cperl-faces)
(defvar cperl-dark-background
(cperl-choose-color "navy" "os2blue" "darkgreen"))
(defvar cperl-dark-foreground
(cperl-choose-color "orchid1" "orange"))
(defface cperl-nonoverridable-face
`((((class grayscale) (background light))
(:background "Gray90" :slant italic :underline t))
(((class grayscale) (background dark))
(:foreground "Gray80" :slant italic :underline t :weight bold))
(((class color) (background light))
(:foreground "chartreuse3"))
(((class color) (background dark))
(:foreground ,cperl-dark-foreground))
(t (:weight bold :underline t)))
"Font Lock mode face used non-overridable keywords and modifiers of regexps."
:group 'cperl-faces)
(defface cperl-array-face
`((((class grayscale) (background light))
(:background "Gray90" :weight bold))
(((class grayscale) (background dark))
(:foreground "Gray80" :weight bold))
(((class color) (background light))
(:foreground "Blue" :background "lightyellow2" :weight bold))
(((class color) (background dark))
(:foreground "yellow" :background ,cperl-dark-background :weight bold))
(t (:weight bold)))
"Font Lock mode face used to highlight array names."
:group 'cperl-faces)
(defface cperl-hash-face
`((((class grayscale) (background light))
(:background "Gray90" :weight bold :slant italic))
(((class grayscale) (background dark))
(:foreground "Gray80" :weight bold :slant italic))
(((class color) (background light))
(:foreground "Red" :background "lightyellow2" :weight bold :slant italic))
(((class color) (background dark))
(:foreground "Red" :background ,cperl-dark-background :weight bold :slant italic))
(t (:weight bold :slant italic)))
"Font Lock mode face used to highlight hash names."
:group 'cperl-faces)
;;; Short extra-docs.
(defvar cperl-tips 'please-ignore-this-line
"Get maybe newer version of this package from
http://ilyaz.org/software/emacs
Subdirectory `cperl-mode' may contain yet newer development releases and/or
patches to related files.
For best results apply to an older Emacs the patches from
ftp://ftp.math.ohio-state.edu/pub/users/ilya/cperl-mode/patches
\(this upgrades syntax-parsing abilities of Emacsen v19.34 and
v20.2 up to the level of Emacs v20.3 - a must for a good Perl
mode.) As of beginning of 2003, XEmacs may provide a similar ability.
Get support packages choose-color.el (or font-lock-extra.el before
19.30), imenu-go.el from the same place. \(Look for other files there
too... ;-). Get a patch for imenu.el in 19.29. Note that for 19.30 and
later you should use choose-color.el *instead* of font-lock-extra.el
\(and you will not get smart highlighting in C :-().
Note that to enable Compile choices in the menu you need to install
mode-compile.el.
If your Emacs does not default to `cperl-mode' on Perl files, and you
want it to: put the following into your .emacs file:
(defalias 'perl-mode 'cperl-mode)
Get perl5-info from
$CPAN/doc/manual/info/perl5-old/perl5-info.tar.gz
Also, one can generate a newer documentation running `pod2texi' converter
$CPAN/doc/manual/info/perl5/pod2texi-0.1.tar.gz
If you use imenu-go, run imenu on perl5-info buffer (you can do it
from Perl menu). If many files are related, generate TAGS files from
Tools/Tags submenu in Perl menu.
If some class structure is too complicated, use Tools/Hierarchy-view
from Perl menu, or hierarchic view of imenu. The second one uses the
current buffer only, the first one requires generation of TAGS from
Perl/Tools/Tags menu beforehand.
Run Perl/Tools/Insert-spaces-if-needed to fix your lazy typing.
Switch auto-help on/off with Perl/Tools/Auto-help.
Though with contemporary Emaxen CPerl mode should maintain the correct
parsing of Perl even when editing, sometimes it may be lost. Fix this by
\\[normal-mode]
In cases of more severe confusion sometimes it is helpful to do
\\[load-library] cperl-mode RET
\\[normal-mode]
Before reporting (non-)problems look in the problem section of online
micro-docs on what I know about CPerl problems.")
(defvar cperl-problems 'please-ignore-this-line
"Description of problems in CPerl mode.
Some faces will not be shown on some versions of Emacs unless you
install choose-color.el, available from
http://ilyaz.org/software/emacs
`fill-paragraph' on a comment may leave the point behind the
paragraph. It also triggers a bug in some versions of Emacs (CPerl tries
to detect it and bulk out).
See documentation of a variable `cperl-problems-old-emaxen' for the
problems which disappear if you upgrade Emacs to a reasonably new
version (20.3 for Emacs, and those of 2004 for XEmacs).")
(defvar cperl-problems-old-emaxen 'please-ignore-this-line
"Description of problems in CPerl mode specific for older Emacs versions.
Emacs had a _very_ restricted syntax parsing engine until version
20.1. Most problems below are corrected starting from this version of
Emacs, and all of them should be fixed in version 20.3. (Or apply
patches to Emacs 19.33/34 - see tips.) XEmacs was very backward in
this respect (until 2003).
Note that even with newer Emacsen in some very rare cases the details
of interaction of `font-lock' and syntaxification may be not cleaned
up yet. You may get slightly different colors basing on the order of
fontification and syntaxification. Say, the initial faces is correct,
but editing the buffer breaks this.
Even with older Emacsen CPerl mode tries to corrects some Emacs
misunderstandings, however, for efficiency reasons the degree of
correction is different for different operations. The partially
corrected problems are: POD sections, here-documents, regexps. The
operations are: highlighting, indentation, electric keywords, electric
braces.
This may be confusing, since the regexp s#//#/#\; may be highlighted
as a comment, but it will be recognized as a regexp by the indentation
code. Or the opposite case, when a POD section is highlighted, but
may break the indentation of the following code (though indentation
should work if the balance of delimiters is not broken by POD).
The main trick (to make $ a \"backslash\") makes constructions like
${aaa} look like unbalanced braces. The only trick I can think of is
to insert it as $ {aaa} (valid in perl5, not in perl4).
Similar problems arise in regexps, when /(\\s|$)/ should be rewritten
as /($|\\s)/. Note that such a transposition is not always possible.
The solution is to upgrade your Emacs or patch an older one. Note
that Emacs 20.2 has some bugs related to `syntax-table' text
properties. Patches are available on the main CPerl download site,
and on CPAN.
If these bugs cannot be fixed on your machine (say, you have an inferior
environment and cannot recompile), you may still disable all the fancy stuff
via `cperl-use-syntax-table-text-property'.")
(defvar cperl-praise 'please-ignore-this-line
"Advantages of CPerl mode.
0) It uses the newest `syntax-table' property ;-);
1) It does 99% of Perl syntax correct (as opposed to 80-90% in Perl
mode - but the latter number may have improved too in last years) even
with old Emaxen which do not support `syntax-table' property.
When using `syntax-table' property for syntax assist hints, it should
handle 99.995% of lines correct - or somesuch. It automatically
updates syntax assist hints when you edit your script.
2) It is generally believed to be \"the most user-friendly Emacs
package\" whatever it may mean (I doubt that the people who say similar
things tried _all_ the rest of Emacs ;-), but this was not a lonely
voice);
3) Everything is customizable, one-by-one or in a big sweep;
4) It has many easily-accessible \"tools\":
a) Can run program, check syntax, start debugger;
b) Can lineup vertically \"middles\" of rows, like `=' in
a = b;
cc = d;
c) Can insert spaces where this impoves readability (in one
interactive sweep over the buffer);
d) Has support for imenu, including:
1) Separate unordered list of \"interesting places\";
2) Separate TOC of POD sections;
3) Separate list of packages;
4) Hierarchical view of methods in (sub)packages;
5) and functions (by the full name - with package);
e) Has an interface to INFO docs for Perl; The interface is
very flexible, including shrink-wrapping of
documentation buffer/frame;
f) Has a builtin list of one-line explanations for perl constructs.
g) Can show these explanations if you stay long enough at the
corresponding place (or on demand);
h) Has an enhanced fontification (using 3 or 4 additional faces
comparing to font-lock - basically, different
namespaces in Perl have different colors);
i) Can construct TAGS basing on its knowledge of Perl syntax,
the standard menu has 6 different way to generate
TAGS (if \"by directory\", .xs files - with C-language
bindings - are included in the scan);
j) Can build a hierarchical view of classes (via imenu) basing
on generated TAGS file;
k) Has electric parentheses, electric newlines, uses Abbrev
for electric logical constructs
while () {}
with different styles of expansion (context sensitive
to be not so bothering). Electric parentheses behave
\"as they should\" in a presence of a visible region.
l) Changes msb.el \"on the fly\" to insert a group \"Perl files\";
m) Can convert from
if (A) { B }
to
B if A;
n) Highlights (by user-choice) either 3-delimiters constructs
(such as tr/a/b/), or regular expressions and `y/tr';
o) Highlights trailing whitespace;
p) Is able to manipulate Perl Regular Expressions to ease
conversion to a more readable form.
q) Can ispell POD sections and HERE-DOCs.
r) Understands comments and character classes inside regular
expressions; can find matching () and [] in a regular expression.
s) Allows indentation of //x-style regular expressions;
t) Highlights different symbols in regular expressions according
to their function; much less problems with backslashitis;
u) Allows to find regular expressions which contain interpolated parts.
5) The indentation engine was very smart, but most of tricks may be
not needed anymore with the support for `syntax-table' property. Has
progress indicator for indentation (with `imenu' loaded).
6) Indent-region improves inline-comments as well; also corrects
whitespace *inside* the conditional/loop constructs.
7) Fill-paragraph correctly handles multi-line comments;
8) Can switch to different indentation styles by one command, and restore
the settings present before the switch.
9) When doing indentation of control constructs, may correct
line-breaks/spacing between elements of the construct.
10) Uses a linear-time algorith for indentation of regions (on Emaxen with
capable syntax engines).
11) Syntax-highlight, indentation, sexp-recognition inside regular expressions.
")
(defvar cperl-speed 'please-ignore-this-line
"This is an incomplete compendium of what is available in other parts
of CPerl documentation. (Please inform me if I skept anything.)
There is a perception that CPerl is slower than alternatives. This part
of documentation is designed to overcome this misconception.
*By default* CPerl tries to enable the most comfortable settings.
From most points of view, correctly working package is infinitely more
comfortable than a non-correctly working one, thus by default CPerl
prefers correctness over speed. Below is the guide how to change
settings if your preferences are different.
A) Speed of loading the file. When loading file, CPerl may perform a
scan which indicates places which cannot be parsed by primitive Emacs
syntax-parsing routines, and marks them up so that either
A1) CPerl may work around these deficiencies (for big chunks, mostly
PODs and HERE-documents), or
A2) On capable Emaxen CPerl will use improved syntax-handlings
which reads mark-up hints directly.
The scan in case A2 is much more comprehensive, thus may be slower.
User can disable syntax-engine-helping scan of A2 by setting
`cperl-use-syntax-table-text-property'
variable to nil (if it is set to t).
One can disable the scan altogether (both A1 and A2) by setting
`cperl-pod-here-scan'
to nil.
B) Speed of editing operations.
One can add a (minor) speedup to editing operations by setting
`cperl-use-syntax-table-text-property'
variable to nil (if it is set to t). This will disable
syntax-engine-helping scan, thus will make many more Perl
constructs be wrongly recognized by CPerl, thus may lead to
wrongly matched parentheses, wrong indentation, etc.
One can unset `cperl-syntaxify-unwind'. This might speed up editing
of, say, long POD sections.")
(defvar cperl-tips-faces 'please-ignore-this-line
"CPerl mode uses following faces for highlighting:
`cperl-array-face' Array names
`cperl-hash-face' Hash names
`font-lock-comment-face' Comments, PODs and whatever is considered
syntaxically to be not code
`font-lock-constant-face' HERE-doc delimiters, labels, delimiters of
2-arg operators s/y/tr/ or of RExen,
`font-lock-warning-face' Special-cased m// and s//foo/,
`font-lock-function-name-face' _ as a target of a file tests, file tests,
subroutine names at the moment of definition
(except those conflicting with Perl operators),
package names (when recognized), format names
`font-lock-keyword-face' Control flow switch constructs, declarators
`cperl-nonoverridable-face' Non-overridable keywords, modifiers of RExen
`font-lock-string-face' Strings, qw() constructs, RExen, POD sections,
literal parts and the terminator of formats
and whatever is syntaxically considered
as string literals
`font-lock-type-face' Overridable keywords
`font-lock-variable-name-face' Variable declarations, indirect array and
hash names, POD headers/item names
`cperl-invalid' Trailing whitespace
Note that in several situations the highlighting tries to inform about
possible confusion, such as different colors for function names in
declarations depending on what they (do not) override, or special cases
m// and s/// which do not do what one would expect them to do.