Mercurial > emacs
comparison lisp/progmodes/cperl-mode.el @ 104310:2ecd57cadf51
* progmodes/cperl-mode.el: Merge upstream 6.2.
(cperl-mode-syntax-table): Modify syntax entry for ["'`].
(cperl-forward-re): Check cperl-brace-recursing.
(cperl-highlight-charclass): New function.
(cperl-find-pods-heres): Use it.
(cperl-fill-paragraph): Synch to save-excursion placement used
upstream.
(cperl-beautify-regexp-piece): Fix column calculation.
(cperl-make-regexp-x): Handle case where point is between "q" and
"rs".
(cperl-beautify-level): Don't process entire regexp.
(cperl-build-manpage, cperl-perldoc): Bind Man-switches before
calling man.
(cperl-tips-faces, cperl-mode, cperl-electric-backspace): Doc fix.
(cperl-init-faces): Build a list in the normal way.
author | Chong Yidong <cyd@stupidchicken.com> |
---|---|
date | Sun, 16 Aug 2009 23:08:18 +0000 |
parents | f51bb75d96dc |
children | bf7a2419d30f |
comparison
equal
deleted
inserted
replaced
104309:d38c249bcfee | 104310:2ecd57cadf51 |
---|---|
636 '((font-lock-keyword-face nil nil bold shadow) | 636 '((font-lock-keyword-face nil nil bold shadow) |
637 (font-lock-variable-name-face nil nil bold) | 637 (font-lock-variable-name-face nil nil bold) |
638 (font-lock-function-name-face nil nil bold italic box) | 638 (font-lock-function-name-face nil nil bold italic box) |
639 (font-lock-constant-face nil "LightGray" bold) | 639 (font-lock-constant-face nil "LightGray" bold) |
640 (cperl-array-face nil "LightGray" bold underline) | 640 (cperl-array-face nil "LightGray" bold underline) |
641 (cperl-hash-face nil "LightGray" bold italic underline) | 641 (cperl-hash-face nil "LightGray" bold italic underline) |
642 (font-lock-comment-face nil "LightGray" italic) | 642 (font-lock-comment-face nil "LightGray" italic) |
643 (font-lock-string-face nil nil italic underline) | 643 (font-lock-string-face nil nil italic underline) |
644 (cperl-nonoverridable-face nil nil italic underline) | 644 (cperl-nonoverridable-face nil nil italic underline) |
645 (font-lock-type-face nil nil underline) | 645 (font-lock-type-face nil nil underline) |
646 (font-lock-warning-face nil "LightGray" bold italic box) | 646 (font-lock-warning-face nil "LightGray" bold italic box) |
974 and whatever is syntaxically considered | 974 and whatever is syntaxically considered |
975 as string literals | 975 as string literals |
976 `font-lock-type-face' Overridable keywords | 976 `font-lock-type-face' Overridable keywords |
977 `font-lock-variable-name-face' Variable declarations, indirect array and | 977 `font-lock-variable-name-face' Variable declarations, indirect array and |
978 hash names, POD headers/item names | 978 hash names, POD headers/item names |
979 `cperl-invalid' Trailing whitespace | 979 `cperl-invalid-face' Trailing whitespace |
980 | 980 |
981 Note that in several situations the highlighting tries to inform about | 981 Note that in several situations the highlighting tries to inform about |
982 possible confusion, such as different colors for function names in | 982 possible confusion, such as different colors for function names in |
983 declarations depending on what they (do not) override, or special cases | 983 declarations depending on what they (do not) override, or special cases |
984 m// and s/// which do not do what one would expect them to do. | 984 m// and s/// which do not do what one would expect them to do. |
985 | 985 |
986 Help with best setup of these faces for printout requested (for each of | 986 Help with best setup of these faces for printout requested (for each of |
987 the faces: please specify bold, italic, underline, shadow and box.) | 987 the faces: please specify bold, italic, underline, shadow and box.) |
988 | 988 |
989 In regular expressions (except character classes): | 989 In regular expressions (including character classes): |
990 `font-lock-string-face' \"Normal\" stuff and non-0-length constructs | 990 `font-lock-string-face' \"Normal\" stuff and non-0-length constructs |
991 `font-lock-constant-face': Delimiters | 991 `font-lock-constant-face': Delimiters |
992 `font-lock-warning-face' Special-cased m// and s//foo/, | 992 `font-lock-warning-face' Special-cased m// and s//foo/, |
993 Mismatched closing delimiters, parens | 993 Mismatched closing delimiters, parens |
994 we couldn't match, misplaced quantifiers, | 994 we couldn't match, misplaced quantifiers, |
995 unrecognized escape sequences | 995 unrecognized escape sequences |
996 `cperl-nonoverridable-face' Modifiers, as gism in m/REx/gism | 996 `cperl-nonoverridable-face' Modifiers, as gism in m/REx/gism |
997 `font-lock-type-face' POSIX classes inside charclasses, | 997 `font-lock-type-face' escape sequences with arguments (\\x \\23 \\p \\N) |
998 escape sequences with arguments (\x \23 \p \N) | |
999 and others match-a-char escape sequences | 998 and others match-a-char escape sequences |
1000 `font-lock-keyword-face' Capturing parens, and | | 999 `font-lock-keyword-face' Capturing parens, and | |
1001 `font-lock-function-name-face' Special symbols: $ ^ . [ ] [^ ] (?{ }) (??{ }) | 1000 `font-lock-function-name-face' Special symbols: $ ^ . [ ] [^ ] (?{ }) (??{ }) |
1002 `font-lock-builtin-face' \"Remaining\" 0-length constructs, executable | 1001 \"Range -\" in character classes |
1003 parts of a REx, not-capturing parens | 1002 `font-lock-builtin-face' \"Remaining\" 0-length constructs, multipliers |
1004 `font-lock-variable-name-face' Interpolated constructs, embedded code | 1003 ?+*{}, not-capturing parens, leading |
1004 backslashes of escape sequences | |
1005 `font-lock-variable-name-face' Interpolated constructs, embedded code, | |
1006 POSIX classes (inside charclasses) | |
1005 `font-lock-comment-face' Embedded comments | 1007 `font-lock-comment-face' Embedded comments |
1006 | 1008 |
1007 ") | 1009 ") |
1008 | 1010 |
1009 | 1011 |
1059 | 1061 |
1060 (defsubst cperl-put-do-not-fontify (from to &optional post) | 1062 (defsubst cperl-put-do-not-fontify (from to &optional post) |
1061 ;; If POST, do not do it with postponed fontification | 1063 ;; If POST, do not do it with postponed fontification |
1062 (if (and post cperl-syntaxify-by-font-lock) | 1064 (if (and post cperl-syntaxify-by-font-lock) |
1063 nil | 1065 nil |
1064 (put-text-property (max (point-min) (1- from)) | 1066 (put-text-property (max (point-min) (1- from)) |
1065 to cperl-do-not-fontify t))) | 1067 to cperl-do-not-fontify t))) |
1066 | 1068 |
1067 (defcustom cperl-mode-hook nil | 1069 (defcustom cperl-mode-hook nil |
1068 "Hook run by CPerl mode." | 1070 "Hook run by CPerl mode." |
1069 :type 'hook | 1071 :type 'hook |
1493 (modify-syntax-entry ?| "." cperl-mode-syntax-table) | 1495 (modify-syntax-entry ?| "." cperl-mode-syntax-table) |
1494 (setq cperl-string-syntax-table (copy-syntax-table cperl-mode-syntax-table)) | 1496 (setq cperl-string-syntax-table (copy-syntax-table cperl-mode-syntax-table)) |
1495 (modify-syntax-entry ?$ "." cperl-string-syntax-table) | 1497 (modify-syntax-entry ?$ "." cperl-string-syntax-table) |
1496 (modify-syntax-entry ?\{ "." cperl-string-syntax-table) | 1498 (modify-syntax-entry ?\{ "." cperl-string-syntax-table) |
1497 (modify-syntax-entry ?\} "." cperl-string-syntax-table) | 1499 (modify-syntax-entry ?\} "." cperl-string-syntax-table) |
1500 (modify-syntax-entry ?\" "." cperl-string-syntax-table) | |
1501 (modify-syntax-entry ?' "." cperl-string-syntax-table) | |
1502 (modify-syntax-entry ?` "." cperl-string-syntax-table) | |
1498 (modify-syntax-entry ?# "." cperl-string-syntax-table)) ; (?# comment ) | 1503 (modify-syntax-entry ?# "." cperl-string-syntax-table)) ; (?# comment ) |
1499 | 1504 |
1500 | 1505 |
1501 | 1506 |
1502 (defvar cperl-faces-init nil) | 1507 (defvar cperl-faces-init nil) |
1674 \(both available from menu). See examples in `cperl-style-examples'. | 1679 \(both available from menu). See examples in `cperl-style-examples'. |
1675 | 1680 |
1676 Part of the indentation style is how different parts of if/elsif/else | 1681 Part of the indentation style is how different parts of if/elsif/else |
1677 statements are broken into lines; in CPerl, this is reflected on how | 1682 statements are broken into lines; in CPerl, this is reflected on how |
1678 templates for these constructs are created (controlled by | 1683 templates for these constructs are created (controlled by |
1679 `cperl-extra-newline-before-brace'), and how reflow-logic should treat \"continuation\" blocks of else/elsif/continue, controlled by the same variable, | 1684 `cperl-extra-newline-before-brace'), and how reflow-logic should treat |
1680 and by `cperl-extra-newline-before-brace-multiline', | 1685 \"continuation\" blocks of else/elsif/continue, controlled by the same |
1686 variable, and by `cperl-extra-newline-before-brace-multiline', | |
1681 `cperl-merge-trailing-else', `cperl-indent-region-fix-constructs'. | 1687 `cperl-merge-trailing-else', `cperl-indent-region-fix-constructs'. |
1682 | 1688 |
1683 If `cperl-indent-level' is 0, the statement after opening brace in | 1689 If `cperl-indent-level' is 0, the statement after opening brace in |
1684 column 0 is indented on | 1690 column 0 is indented on |
1685 `cperl-brace-offset'+`cperl-continued-statement-offset'. | 1691 `cperl-brace-offset'+`cperl-continued-statement-offset'. |
1805 (cond ((boundp 'compilation-error-regexp-alist-alist);; xemacs 20.x | 1811 (cond ((boundp 'compilation-error-regexp-alist-alist);; xemacs 20.x |
1806 (make-local-variable 'compilation-error-regexp-alist-alist) | 1812 (make-local-variable 'compilation-error-regexp-alist-alist) |
1807 (set 'compilation-error-regexp-alist-alist | 1813 (set 'compilation-error-regexp-alist-alist |
1808 (cons (cons 'cperl (car cperl-compilation-error-regexp-alist)) | 1814 (cons (cons 'cperl (car cperl-compilation-error-regexp-alist)) |
1809 (symbol-value 'compilation-error-regexp-alist-alist))) | 1815 (symbol-value 'compilation-error-regexp-alist-alist))) |
1810 (if (fboundp 'compilation-build-compilation-error-regexp-alist) | 1816 (if (fboundp 'compilation-build-compilation-error-regexp-alist) |
1811 (let ((f 'compilation-build-compilation-error-regexp-alist)) | 1817 (let ((f 'compilation-build-compilation-error-regexp-alist)) |
1812 (funcall f)) | 1818 (funcall f)) |
1813 (make-local-variable 'compilation-error-regexp-alist) | 1819 (make-local-variable 'compilation-error-regexp-alist) |
1814 (push 'cperl compilation-error-regexp-alist))) | 1820 (push 'cperl compilation-error-regexp-alist))) |
1815 ((boundp 'compilation-error-regexp-alist);; xmeacs 19.x | 1821 ((boundp 'compilation-error-regexp-alist);; xmeacs 19.x |
1816 (make-local-variable 'compilation-error-regexp-alist) | 1822 (make-local-variable 'compilation-error-regexp-alist) |
1817 (set 'compilation-error-regexp-alist | 1823 (set 'compilation-error-regexp-alist |
1818 (append cperl-compilation-error-regexp-alist | 1824 (append cperl-compilation-error-regexp-alist |
1819 (symbol-value 'compilation-error-regexp-alist))))) | 1825 (symbol-value 'compilation-error-regexp-alist))))) |
2544 (goto-char insertpos) | 2550 (goto-char insertpos) |
2545 (self-insert-command (prefix-numeric-value arg))) | 2551 (self-insert-command (prefix-numeric-value arg))) |
2546 (self-insert-command (prefix-numeric-value arg))))) | 2552 (self-insert-command (prefix-numeric-value arg))))) |
2547 | 2553 |
2548 (defun cperl-electric-backspace (arg) | 2554 (defun cperl-electric-backspace (arg) |
2549 "Backspace, or remove the whitespace around the point inserted by an electric | 2555 "Backspace, or remove whitespace around the point inserted by an electric key. |
2550 key. Will untabify if `cperl-electric-backspace-untabify' is non-nil." | 2556 Will untabify if `cperl-electric-backspace-untabify' is non-nil." |
2551 (interactive "p") | 2557 (interactive "p") |
2552 (if (and cperl-auto-newline | 2558 (if (and cperl-auto-newline |
2553 (memq last-command '(cperl-electric-semi | 2559 (memq last-command '(cperl-electric-semi |
2554 cperl-electric-terminator | 2560 cperl-electric-terminator |
2555 cperl-electric-lbrace)) | 2561 cperl-electric-lbrace)) |
2724 ;;; (t (or (previous-single-property-change p look-prop lim) | 2730 ;;; (t (or (previous-single-property-change p look-prop lim) |
2725 ;;; (point-min)))) | 2731 ;;; (point-min)))) |
2726 ) | 2732 ) |
2727 | 2733 |
2728 (defun cperl-sniff-for-indent (&optional parse-data) ; was parse-start | 2734 (defun cperl-sniff-for-indent (&optional parse-data) ; was parse-start |
2729 ;; Old workhorse for calculation of indentation; the major problem | 2735 ;; the sniffer logic to understand what the current line MEANS. |
2730 ;; is that it mixes the sniffer logic to understand what the current line | |
2731 ;; MEANS with the logic to actually calculate where to indent it. | |
2732 ;; The latter part should be eventually moved to `cperl-calculate-indent'; | |
2733 ;; actually, this is mostly done now... | |
2734 (cperl-update-syntaxification (point) (point)) | 2736 (cperl-update-syntaxification (point) (point)) |
2735 (let ((res (get-text-property (point) 'syntax-type))) | 2737 (let ((res (get-text-property (point) 'syntax-type))) |
2736 (save-excursion | 2738 (save-excursion |
2737 (cond | 2739 (cond |
2738 ((and (memq res '(pod here-doc here-doc-delim format)) | 2740 ((and (memq res '(pod here-doc here-doc-delim format)) |
3387 (modify-syntax-entry starter (if (eq starter ?\\) "\\" ".") st) | 3389 (modify-syntax-entry starter (if (eq starter ?\\) "\\" ".") st) |
3388 (if ender (modify-syntax-entry ender "." st)) | 3390 (if ender (modify-syntax-entry ender "." st)) |
3389 (setq set-st nil) | 3391 (setq set-st nil) |
3390 (setq ender (cperl-forward-re lim end nil st-l err-l | 3392 (setq ender (cperl-forward-re lim end nil st-l err-l |
3391 argument starter ender) | 3393 argument starter ender) |
3392 ender (nth 2 ender))))) | 3394 ender (nth 2 ender))))) |
3393 (error (goto-char lim) | 3395 (error (goto-char lim) |
3394 (setq set-st nil) | 3396 (setq set-st nil) |
3395 (if reset-st | 3397 (if reset-st |
3396 (set-syntax-table reset-st)) | 3398 (set-syntax-table reset-st)) |
3397 (or end | 3399 (or end |
3400 (and cperl-brace-recursing | |
3401 (or (eq ostart ?\{) | |
3402 (eq starter ?\{))) | |
3398 (message | 3403 (message |
3399 "End of `%s%s%c ... %c' string/RE not found: %s" | 3404 "End of `%s%s%c ... %c' string/RE not found: %s" |
3400 argument | 3405 argument |
3401 (if ostart (format "%c ... %c" ostart (or oend ostart)) "") | 3406 (if ostart (format "%c ... %c" ostart (or oend ostart)) "") |
3402 starter (or ender starter) bb) | 3407 starter (or ender starter) bb) |
3590 (1- e) t)) ; return nil on failure, no moving | 3595 (1- e) t)) ; return nil on failure, no moving |
3591 (if (eq ?\{ (preceding-char)) nil | 3596 (if (eq ?\{ (preceding-char)) nil |
3592 (cperl-postpone-fontification | 3597 (cperl-postpone-fontification |
3593 (1- (point)) (point) | 3598 (1- (point)) (point) |
3594 'face font-lock-warning-face)))) | 3599 'face font-lock-warning-face)))) |
3600 | |
3601 ;; Do some smarter-highlighting | |
3602 ;; XXXX Currently ignores alphanum/dash delims, | |
3603 (defsubst cperl-highlight-charclass (endbracket dashface bsface onec-space) | |
3604 (let ((l '(1 5 7)) ll lle lll | |
3605 ;; 2 groups, the first takes the whole match (include \[trnfabe]) | |
3606 (singleChar (concat "\\(" "[^\\\\]" "\\|" "\\\\[^cdg-mo-qsu-zA-Z0-9_]" "\\|" "\\\\c." "\\|" "\\\\x" "\\([0-9a-fA-F][0-9a-fA-F]?\\|\\={[0-9a-fA-F]+}\\)" "\\|" "\\\\0?[0-7][0-7]?[0-7]?" "\\|" "\\\\N{[^{}]*}" "\\)"))) | |
3607 (while ; look for unescaped - between non-classes | |
3608 (re-search-forward | |
3609 ;; On 19.33, certain simplifications lead | |
3610 ;; to bugs (as in [^a-z] \\| [trnfabe] ) | |
3611 (concat ; 1: SingleChar (include \[trnfabe]) | |
3612 singleChar | |
3613 ;;"\\(" "[^\\\\]" "\\|" "\\\\[^cdg-mo-qsu-zA-Z0-9_]" "\\|" "\\\\c." "\\|" "\\\\x" "\\([0-9a-fA-F][0-9a-fA-F]?\\|\\={[0-9a-fA-F]+}\\)" "\\|" "\\\\0?[0-7][0-7]?[0-7]?" "\\|" "\\\\N{[^{}]*}" "\\)" | |
3614 "\\(" ; 3: DASH SingleChar (match optionally) | |
3615 "\\(-\\)" ; 4: DASH | |
3616 singleChar ; 5: SingleChar | |
3617 ;;"\\(" "[^\\\\]" "\\|" "\\\\[^cdg-mo-qsu-zA-Z0-9_]" "\\|" "\\\\c." "\\|" "\\\\x" "\\([0-9a-fA-F][0-9a-fA-F]?\\|\\={[0-9a-fA-F]+}\\)" "\\|" "\\\\0?[0-7][0-7]?[0-7]?" "\\|" "\\\\N{[^{}]*}" "\\)" | |
3618 "\\)?" | |
3619 "\\|" | |
3620 "\\(" ; 7: other escapes | |
3621 "\\\\[pP]" "\\([^{]\\|{[^{}]*}\\)" | |
3622 "\\|" "\\\\[^pP]" "\\)" | |
3623 ) | |
3624 endbracket 'toend) | |
3625 (if (match-beginning 4) | |
3626 (cperl-postpone-fontification | |
3627 (match-beginning 4) (match-end 4) | |
3628 'face dashface)) | |
3629 ;; save match data (for looking-at) | |
3630 (setq lll (mapcar (function (lambda (elt) (cons (match-beginning elt) | |
3631 (match-end elt)))) l)) | |
3632 (while lll | |
3633 (setq ll (car lll)) | |
3634 (setq lle (cdr ll) | |
3635 ll (car ll)) | |
3636 ;; (message "Got %s of %s" ll l) | |
3637 (if (and ll (eq (char-after ll) ?\\ )) | |
3638 (save-excursion | |
3639 (goto-char ll) | |
3640 (cperl-postpone-fontification ll (1+ ll) | |
3641 'face bsface) | |
3642 (if (looking-at "\\\\[a-zA-Z0-9]") | |
3643 (cperl-postpone-fontification (1+ ll) lle | |
3644 'face onec-space)))) | |
3645 (setq lll (cdr lll)))) | |
3646 (goto-char endbracket) ; just in case something misbehaves??? | |
3647 t)) | |
3595 | 3648 |
3596 ;;; Debugging this may require (setq max-specpdl-size 2000)... | 3649 ;;; Debugging this may require (setq max-specpdl-size 2000)... |
3597 (defun cperl-find-pods-heres (&optional min max non-inter end ignore-max end-of-here-doc) | 3650 (defun cperl-find-pods-heres (&optional min max non-inter end ignore-max end-of-here-doc) |
3598 "Scans the buffer for hard-to-parse Perl constructions. | 3651 "Scans the buffer for hard-to-parse Perl constructions. |
3599 If `cperl-pod-here-fontify' is not-nil after evaluation, will fontify | 3652 If `cperl-pod-here-fontify' is not-nil after evaluation, will fontify |
4473 (cperl-postpone-fontification | 4526 (cperl-postpone-fontification |
4474 (1- REx-subgr-start) (point) | 4527 (1- REx-subgr-start) (point) |
4475 'face my-cperl-REx-length1-face)))) | 4528 'face my-cperl-REx-length1-face)))) |
4476 (setq was-subgr nil)) ; We do stuff here | 4529 (setq was-subgr nil)) ; We do stuff here |
4477 ((match-beginning 3) ; [charclass] | 4530 ((match-beginning 3) ; [charclass] |
4531 ;; Highlight leader, trailer, POSIX classes | |
4478 (forward-char 1) | 4532 (forward-char 1) |
4479 (if (eq (char-after b) ?^ ) | 4533 (if (eq (char-after b) ?^ ) |
4480 (and (eq (following-char) ?\\ ) | 4534 (and (eq (following-char) ?\\ ) |
4481 (eq (char-after (cperl-1+ (point))) | 4535 (eq (char-after (cperl-1+ (point))) |
4482 ?^ ) | 4536 ?^ ) |
4483 (forward-char 2)) | 4537 (forward-char 2)) |
4484 (and (eq (following-char) ?^ ) | 4538 (and (eq (following-char) ?^ ) |
4485 (forward-char 1))) | 4539 (forward-char 1))) |
4486 (setq argument b ; continue? | 4540 (setq argument b ; continue? & end of last POSIX |
4487 tag nil ; list of POSIX classes | 4541 tag nil ; list of POSIX classes |
4488 qtag (point)) | 4542 qtag (point)) ; after leading ^ if present |
4489 (if (eq (char-after b) ?\] ) | 4543 (if (eq (char-after b) ?\] ) |
4490 (and (eq (following-char) ?\\ ) | 4544 (and (eq (following-char) ?\\ ) |
4491 (eq (char-after (cperl-1+ (point))) | 4545 (eq (char-after (cperl-1+ (point))) |
4492 ?\] ) | 4546 ?\] ) |
4493 (setq qtag (1+ qtag)) | 4547 (setq qtag (1+ qtag)) |
4494 (forward-char 2)) | 4548 (forward-char 2)) |
4495 (and (eq (following-char) ?\] ) | 4549 (and (eq (following-char) ?\] ) |
4496 (forward-char 1))) | 4550 (forward-char 1))) |
4551 (setq REx-subgr-end qtag) ;EndOf smart-highlighed | |
4497 ;; Apparently, I can't put \] into a charclass | 4552 ;; Apparently, I can't put \] into a charclass |
4498 ;; in m]]: m][\\\]\]] produces [\\]] | 4553 ;; in m]]: m][\\\]\]] produces [\\]] |
4499 ;;; POSIX? [:word:] [:^word:] only inside [] | 4554 ;;; POSIX? [:word:] [:^word:] only inside [] |
4500 ;;; "\\=\\(\\\\.\\|[^][\\\\]\\|\\[:\\^?\sw+:]\\|\\[[^:]\\)*]") | 4555 ;;; "\\=\\(\\\\.\\|[^][\\\\]\\|\\[:\\^?\sw+:]\\|\\[[^:]\\)*]") |
4501 (while | 4556 (while ; look for unescaped ] |
4502 (and argument | 4557 (and argument |
4503 (re-search-forward | 4558 (re-search-forward |
4504 (if (eq (char-after b) ?\] ) | 4559 (if (eq (char-after b) ?\] ) |
4505 "\\=\\(\\\\[^]]\\|[^]\\\\]\\)*\\\\]" | 4560 "\\=\\(\\\\[^]]\\|[^]\\\\]\\)*\\\\]" |
4506 "\\=\\(\\\\.\\|[^]\\\\]\\)*]") | 4561 "\\=\\(\\\\.\\|[^]\\\\]\\)*]") |
4508 ;; Is this ] an end of POSIX class? | 4563 ;; Is this ] an end of POSIX class? |
4509 (if (save-excursion | 4564 (if (save-excursion |
4510 (and | 4565 (and |
4511 (search-backward "[" argument t) | 4566 (search-backward "[" argument t) |
4512 (< REx-subgr-start (point)) | 4567 (< REx-subgr-start (point)) |
4513 (not | 4568 (setq argument (point)) ; POSIX-start |
4514 (and ; Should work with delim = \ | 4569 (or ; Should work with delim = \ |
4515 (eq (preceding-char) ?\\ ) | 4570 (not (eq (preceding-char) ?\\ )) |
4516 (= (% (skip-chars-backward | 4571 ;; XXXX Double \\ is needed with 19.33 |
4517 "\\\\") 2) 0))) | 4572 (= (% (skip-chars-backward "\\\\") 2) 0)) |
4518 (looking-at | 4573 (looking-at |
4519 (cond | 4574 (cond |
4520 ((eq (char-after b) ?\] ) | 4575 ((eq (char-after b) ?\] ) |
4521 "\\\\*\\[:\\^?\\sw+:\\\\\\]") | 4576 "\\\\*\\[:\\^?\\sw+:\\\\\\]") |
4522 ((eq (char-after b) ?\: ) | 4577 ((eq (char-after b) ?\: ) |
4528 (concat | 4583 (concat |
4529 "\\\\*\\[:\\(\\\\\\^\\)?\\(\\\\" | 4584 "\\\\*\\[:\\(\\\\\\^\\)?\\(\\\\" |
4530 (char-to-string (char-after b)) | 4585 (char-to-string (char-after b)) |
4531 "\\|\\sw\\)+:\]")) | 4586 "\\|\\sw\\)+:\]")) |
4532 (t "\\\\*\\[:\\^?\\sw*:]"))) | 4587 (t "\\\\*\\[:\\^?\\sw*:]"))) |
4533 (setq argument (point)))) | 4588 (goto-char REx-subgr-end) |
4589 (cperl-highlight-charclass | |
4590 argument my-cperl-REx-spec-char-face | |
4591 my-cperl-REx-0length-face my-cperl-REx-length1-face))) | |
4534 (setq tag (cons (cons argument (point)) | 4592 (setq tag (cons (cons argument (point)) |
4535 tag) | 4593 tag) |
4536 argument (point)) ; continue | 4594 argument (point) |
4595 REx-subgr-end argument) ; continue | |
4537 (setq argument nil))) | 4596 (setq argument nil))) |
4538 (and argument | 4597 (and argument |
4539 (message "Couldn't find end of charclass in a REx, pos=%s" | 4598 (message "Couldn't find end of charclass in a REx, pos=%s" |
4540 REx-subgr-start)) | 4599 REx-subgr-start)) |
4600 (setq argument (1- (point))) | |
4601 (goto-char REx-subgr-end) | |
4602 (cperl-highlight-charclass | |
4603 argument my-cperl-REx-spec-char-face | |
4604 my-cperl-REx-0length-face my-cperl-REx-length1-face) | |
4605 (forward-char 1) | |
4606 ;; Highlight starter, trailer, POSIX | |
4541 (if (and cperl-use-syntax-table-text-property | 4607 (if (and cperl-use-syntax-table-text-property |
4542 (> (- (point) 2) REx-subgr-start)) | 4608 (> (- (point) 2) REx-subgr-start)) |
4543 (put-text-property | 4609 (put-text-property |
4544 (1+ REx-subgr-start) (1- (point)) | 4610 (1+ REx-subgr-start) (1- (point)) |
4545 'syntax-table cperl-st-punct)) | 4611 'syntax-table cperl-st-punct)) |
4554 (- (point) 2) (1- (point)) | 4620 (- (point) 2) (1- (point)) |
4555 'face my-cperl-REx-0length-face)) | 4621 'face my-cperl-REx-0length-face)) |
4556 (while tag | 4622 (while tag |
4557 (cperl-postpone-fontification | 4623 (cperl-postpone-fontification |
4558 (car (car tag)) (cdr (car tag)) | 4624 (car (car tag)) (cdr (car tag)) |
4559 'face my-cperl-REx-length1-face) | 4625 'face font-lock-variable-name-face) ;my-cperl-REx-length1-face |
4560 (setq tag (cdr tag))) | 4626 (setq tag (cdr tag))) |
4561 (setq was-subgr nil)) ; did facing already | 4627 (setq was-subgr nil)) ; did facing already |
4562 ;; Now rare stuff: | 4628 ;; Now rare stuff: |
4563 ((and (match-beginning 2) ; #-comment | 4629 ((and (match-beginning 2) ; #-comment |
4564 (/= (match-beginning 2) (match-end 2))) | 4630 (/= (match-beginning 2) (match-end 2))) |
4629 REx-subgr-start REx-subgr-end | 4695 REx-subgr-start REx-subgr-end |
4630 'face font-lock-comment-face)))))) | 4696 'face font-lock-comment-face)))))) |
4631 (if (and is-REx is-x-REx) | 4697 (if (and is-REx is-x-REx) |
4632 (put-text-property (1+ b) (1- e) | 4698 (put-text-property (1+ b) (1- e) |
4633 'syntax-subtype 'x-REx))) | 4699 'syntax-subtype 'x-REx))) |
4634 (if (and i2 e1 b1 (> e1 b1)) | 4700 (if (and i2 e1 (or (not b1) (> e1 b1))) |
4635 (progn ; No errors finding the second part... | 4701 (progn ; No errors finding the second part... |
4636 (cperl-postpone-fontification | 4702 (cperl-postpone-fontification |
4637 (1- e1) e1 'face my-cperl-delimiters-face) | 4703 (1- e1) e1 'face my-cperl-delimiters-face) |
4638 (if (and (not (eobp)) | 4704 (if (and (not (eobp)) |
4639 (assoc (char-after b) cperl-starters)) | 4705 (assoc (char-after b) cperl-starters)) |
5224 (setq empty (looking-at "[ \t]*\n")) | 5290 (setq empty (looking-at "[ \t]*\n")) |
5225 (and (setq comm (looking-at "[ \t]*#")) | 5291 (and (setq comm (looking-at "[ \t]*#")) |
5226 (or (eq (current-indentation) (or old-comm-indent | 5292 (or (eq (current-indentation) (or old-comm-indent |
5227 comment-column)) | 5293 comment-column)) |
5228 (setq old-comm-indent nil)))) | 5294 (setq old-comm-indent nil)))) |
5229 (if (and old-comm-indent | 5295 (if (and old-comm-indent |
5230 (not empty) | 5296 (not empty) |
5231 (= (current-indentation) old-comm-indent) | 5297 (= (current-indentation) old-comm-indent) |
5232 (not (eq (get-text-property (point) 'syntax-type) 'pod)) | 5298 (not (eq (get-text-property (point) 'syntax-type) 'pod)) |
5233 (not (eq (get-text-property (point) 'syntax-table) | 5299 (not (eq (get-text-property (point) 'syntax-table) |
5234 cperl-st-cfence))) | 5300 cperl-st-cfence))) |
5235 (let ((comment-column new-comm-indent)) | 5301 (let ((comment-column new-comm-indent)) |
5236 (indent-for-comment))) | 5302 (indent-for-comment))) |
5237 (progn | 5303 (progn |
5238 (setq i (cperl-indent-line indent-info)) | 5304 (setq i (cperl-indent-line indent-info)) |
5239 (or comm | 5305 (or comm |
5240 (not i) | 5306 (not i) |
5241 (progn | 5307 (progn |
5242 (if cperl-indent-region-fix-constructs | 5308 (if cperl-indent-region-fix-constructs |
5243 (goto-char (cperl-fix-line-spacing end indent-info))) | 5309 (goto-char (cperl-fix-line-spacing end indent-info))) |
5244 (if (setq old-comm-indent | 5310 (if (setq old-comm-indent |
5245 (and (cperl-to-comment-or-eol) | 5311 (and (cperl-to-comment-or-eol) |
5246 (not (memq (get-text-property (point) | 5312 (not (memq (get-text-property (point) |
5247 'syntax-type) | 5313 'syntax-type) |
5248 '(pod here-doc))) | 5314 '(pod here-doc))) |
5249 (not (eq (get-text-property (point) | 5315 (not (eq (get-text-property (point) |
5250 'syntax-table) | 5316 'syntax-table) |
5251 cperl-st-cfence)) | 5317 cperl-st-cfence)) |
5252 (current-column))) | 5318 (current-column))) |
5253 (progn (indent-for-comment) | 5319 (progn (indent-for-comment) |
5254 (skip-chars-backward " \t") | 5320 (skip-chars-backward " \t") |
5255 (skip-chars-backward "#") | 5321 (skip-chars-backward "#") |
5256 (setq new-comm-indent (current-column)))))))) | 5322 (setq new-comm-indent (current-column)))))))) |
5257 (beginning-of-line 2))) | 5323 (beginning-of-line 2))) |
5258 ;; Now run the update hooks | 5324 ;; Now run the update hooks |
5259 (and after-change-functions | 5325 (and after-change-functions |
5260 cperl-update-end | 5326 cperl-update-end |
5261 (save-excursion | 5327 (save-excursion |
5262 (goto-char cperl-update-end) | 5328 (goto-char cperl-update-end) |
5327 (save-excursion | 5393 (save-excursion |
5328 (while (progn (forward-line 1) | 5394 (while (progn (forward-line 1) |
5329 (looking-at "^[ \t]*#+[ \t]*[^ \t\n#]"))) | 5395 (looking-at "^[ \t]*#+[ \t]*[^ \t\n#]"))) |
5330 (point))) | 5396 (point))) |
5331 ;; Remove existing hashes | 5397 ;; Remove existing hashes |
5398 (goto-char (point-min)) | |
5332 (save-excursion | 5399 (save-excursion |
5333 (goto-char (point-min)) | 5400 (while (progn (forward-line 1) (< (point) (point-max))) |
5334 (while (progn (forward-line 1) (< (point) (point-max))) | 5401 (skip-chars-forward " \t") |
5335 (skip-chars-forward " \t") | 5402 (if (looking-at "#+") |
5336 (if (looking-at "#+") | 5403 (progn |
5337 (progn | 5404 (if (and (eq (point) (match-beginning 0)) |
5338 (if (and (eq (point) (match-beginning 0)) | 5405 (not (eq (point) (match-end 0)))) nil |
5339 (not (eq (point) (match-end 0)))) nil | |
5340 (error | 5406 (error |
5341 "Bug in Emacs: `looking-at' in `narrow-to-region': match-data is garbage")) | 5407 "Bug in Emacs: `looking-at' in `narrow-to-region': match-data is garbage")) |
5342 (delete-char (- (match-end 0) (match-beginning 0))))))) | 5408 (delete-char (- (match-end 0) (match-beginning 0))))))) |
5343 | 5409 |
5344 ;; Lines with only hashes on them can be paragraph boundaries. | 5410 ;; Lines with only hashes on them can be paragraph boundaries. |
5623 (if (fboundp 'font-lock-fontify-anchored-keywords) | 5689 (if (fboundp 'font-lock-fontify-anchored-keywords) |
5624 (setq font-lock-anchored t)) | 5690 (setq font-lock-anchored t)) |
5625 (setq | 5691 (setq |
5626 t-font-lock-keywords | 5692 t-font-lock-keywords |
5627 (list | 5693 (list |
5628 `("[ \t]+$" 0 ',cperl-invalid-face t) | 5694 (list "[ \t]+$" 0 cperl-invalid-face t) |
5629 (cons | 5695 (cons |
5630 (concat | 5696 (concat |
5631 "\\(^\\|[^$@%&\\]\\)\\<\\(" | 5697 "\\(^\\|[^$@%&\\]\\)\\<\\(" |
5632 (mapconcat | 5698 (mapconcat |
5633 'identity | 5699 'identity |
7110 (setq cperl-hierarchy (list l1 l2 l3)) | 7176 (setq cperl-hierarchy (list l1 l2 l3)) |
7111 (if (featurep 'xemacs) ; Not checked | 7177 (if (featurep 'xemacs) ; Not checked |
7112 (progn | 7178 (progn |
7113 (or tags-file-name | 7179 (or tags-file-name |
7114 ;; Does this work in XEmacs? | 7180 ;; Does this work in XEmacs? |
7115 (call-interactively 'visit-tags-table)) | 7181 (call-interactively 'visit-tags-table)) |
7116 (message "Updating list of classes...") | 7182 (message "Updating list of classes...") |
7117 (set-buffer (get-file-buffer tags-file-name)) | 7183 (set-buffer (get-file-buffer tags-file-name)) |
7118 (cperl-tags-hier-fill)) | 7184 (cperl-tags-hier-fill)) |
7119 (or tags-table-list | 7185 (or tags-table-list |
7120 (call-interactively 'visit-tags-table)) | 7186 (call-interactively 'visit-tags-table)) |
7121 (mapc | 7187 (mapc |
7122 (function | 7188 (function |
7123 (lambda (tagsfile) | 7189 (lambda (tagsfile) |
7124 (message "Updating list of classes... %s" tagsfile) | 7190 (message "Updating list of classes... %s" tagsfile) |
7125 (set-buffer (get-file-buffer tagsfile)) | 7191 (set-buffer (get-file-buffer tagsfile)) |
7126 (cperl-tags-hier-fill))) | 7192 (cperl-tags-hier-fill))) |
7127 tags-table-list) | 7193 tags-table-list) |
7128 (message "Updating list of classes... postprocessing...")) | 7194 (message "Updating list of classes... postprocessing...")) |
7129 (mapc remover (car cperl-hierarchy)) | 7195 (mapc remover (car cperl-hierarchy)) |
7130 (mapc remover (nth 1 cperl-hierarchy)) | 7196 (mapc remover (nth 1 cperl-hierarchy)) |
7131 (setq to (list nil (cons "Packages: " (nth 1 cperl-hierarchy)) | 7197 (setq to (list nil (cons "Packages: " (nth 1 cperl-hierarchy)) |
7949 ;; EMBED is nil if we process the whole REx. | 8015 ;; EMBED is nil if we process the whole REx. |
7950 ;; The REx is guaranteed to have //x | 8016 ;; The REx is guaranteed to have //x |
7951 ;; LEVEL shows how many levels deep to go | 8017 ;; LEVEL shows how many levels deep to go |
7952 ;; position at enter and at leave is not defined | 8018 ;; position at enter and at leave is not defined |
7953 (let (s c tmp (m (make-marker)) (m1 (make-marker)) c1 spaces inline code pos) | 8019 (let (s c tmp (m (make-marker)) (m1 (make-marker)) c1 spaces inline code pos) |
7954 (if (not embed) | 8020 (if embed |
7955 (goto-char (1+ b)) | 8021 (progn |
7956 (goto-char b) | 8022 (goto-char b) |
7957 (cond ((looking-at "(\\?\\\\#") ; (?#) wrongly commented when //x-ing | 8023 (setq c (if (eq embed t) (current-indentation) (current-column))) |
7958 (forward-char 2) | 8024 (cond ((looking-at "(\\?\\\\#") ; (?#) wrongly commented when //x-ing |
7959 (delete-char 1) | 8025 (forward-char 2) |
7960 (forward-char 1)) | 8026 (delete-char 1) |
7961 ((looking-at "(\\?[^a-zA-Z]") | 8027 (forward-char 1)) |
7962 (forward-char 3)) | 8028 ((looking-at "(\\?[^a-zA-Z]") |
7963 ((looking-at "(\\?") ; (?i) | 8029 (forward-char 3)) |
7964 (forward-char 2)) | 8030 ((looking-at "(\\?") ; (?i) |
7965 (t | 8031 (forward-char 2)) |
7966 (forward-char 1)))) | 8032 (t |
7967 (setq c (if embed (current-indentation) (1- (current-column))) | 8033 (forward-char 1)))) |
7968 c1 (+ c (or cperl-regexp-indent-step cperl-indent-level))) | 8034 (goto-char (1+ b)) |
8035 (setq c (1- (current-column)))) | |
8036 (setq c1 (+ c (or cperl-regexp-indent-step cperl-indent-level))) | |
7969 (or (looking-at "[ \t]*[\n#]") | 8037 (or (looking-at "[ \t]*[\n#]") |
7970 (progn | 8038 (progn |
7971 (insert "\n"))) | 8039 (insert "\n"))) |
7972 (goto-char e) | 8040 (goto-char e) |
7973 (beginning-of-line) | 8041 (beginning-of-line) |
8136 (or cperl-use-syntax-table-text-property | 8204 (or cperl-use-syntax-table-text-property |
8137 (error "I need to have a regexp marked!")) | 8205 (error "I need to have a regexp marked!")) |
8138 ;; Find the start | 8206 ;; Find the start |
8139 (if (looking-at "\\s|") | 8207 (if (looking-at "\\s|") |
8140 nil ; good already | 8208 nil ; good already |
8141 (if (looking-at "\\([smy]\\|qr\\)\\s|") | 8209 (if (or (looking-at "\\([smy]\\|qr\\)\\s|") |
8142 (forward-char 1) | 8210 (and (eq (preceding-char) ?q) |
8211 (looking-at "\\(r\\)\\s|"))) | |
8212 (goto-char (match-end 1)) | |
8143 (re-search-backward "\\s|"))) ; Assume it is scanned already. | 8213 (re-search-backward "\\s|"))) ; Assume it is scanned already. |
8144 ;;(forward-char 1) | 8214 ;;(forward-char 1) |
8145 (let ((b (point)) (e (make-marker)) have-x delim (c (current-column)) | 8215 (let ((b (point)) (e (make-marker)) have-x delim (c (current-column)) |
8146 (sub-p (eq (preceding-char) ?s)) s) | 8216 (sub-p (eq (preceding-char) ?s)) s) |
8147 (forward-sexp 1) | 8217 (forward-sexp 1) |
8240 (save-excursion | 8310 (save-excursion |
8241 (cperl-regext-to-level-start) | 8311 (cperl-regext-to-level-start) |
8242 (let ((b (point)) (e (make-marker))) | 8312 (let ((b (point)) (e (make-marker))) |
8243 (forward-sexp 1) | 8313 (forward-sexp 1) |
8244 (set-marker e (1- (point))) | 8314 (set-marker e (1- (point))) |
8245 (cperl-beautify-regexp-piece b e nil deep)))) | 8315 (cperl-beautify-regexp-piece b e 'level deep)))) |
8246 | 8316 |
8247 (defun cperl-invert-if-unless-modifiers () | 8317 (defun cperl-invert-if-unless-modifiers () |
8248 "Change `B if A;' into `if (A) {B}' etc if possible. | 8318 "Change `B if A;' into `if (A) {B}' etc if possible. |
8249 \(Unfinished.)" | 8319 \(Unfinished.)" |
8250 (interactive) ; | 8320 (interactive) |
8251 (let (A B pre-B post-B pre-if post-if pre-A post-A if-string | 8321 (let (A B pre-B post-B pre-if post-if pre-A post-A if-string |
8252 (w-rex "\\<\\(if\\|unless\\|while\\|until\\|for\\|foreach\\)\\>")) | 8322 (w-rex "\\<\\(if\\|unless\\|while\\|until\\|for\\|foreach\\)\\>")) |
8253 (and (= (char-syntax (preceding-char)) ?w) | 8323 (and (= (char-syntax (preceding-char)) ?w) |
8254 (forward-sexp -1)) | 8324 (forward-sexp -1)) |
8255 (setq pre-if (point)) | 8325 (setq pre-if (point)) |
8455 (string-match "^[a-z]+$" word) | 8525 (string-match "^[a-z]+$" word) |
8456 (string-match (concat "^" word "\\>") | 8526 (string-match (concat "^" word "\\>") |
8457 (documentation-property | 8527 (documentation-property |
8458 'cperl-short-docs | 8528 'cperl-short-docs |
8459 'variable-documentation)))) | 8529 'variable-documentation)))) |
8530 (Man-switches "") | |
8460 (manual-program (if is-func "perldoc -f" "perldoc"))) | 8531 (manual-program (if is-func "perldoc -f" "perldoc"))) |
8461 (cond | 8532 (cond |
8462 ((featurep 'xemacs) | 8533 ((featurep 'xemacs) |
8463 (let ((Manual-program "perldoc") | 8534 (let ((Manual-program "perldoc") |
8464 (Manual-switches (if is-func (list "-f")))) | 8535 (Manual-switches (if is-func (list "-f")))) |
8503 (cond | 8574 (cond |
8504 ((featurep 'xemacs) | 8575 ((featurep 'xemacs) |
8505 (let ((Manual-program "perldoc")) | 8576 (let ((Manual-program "perldoc")) |
8506 (manual-entry buffer-file-name))) | 8577 (manual-entry buffer-file-name))) |
8507 (t | 8578 (t |
8508 (let* ((manual-program "perldoc")) | 8579 (let* ((manual-program "perldoc") |
8580 (Man-switches "")) | |
8509 (Man-getpage-in-background buffer-file-name))))) | 8581 (Man-getpage-in-background buffer-file-name))))) |
8510 | 8582 |
8511 (defun cperl-pod2man-build-command () | 8583 (defun cperl-pod2man-build-command () |
8512 "Builds the entire background manpage and cleaning command." | 8584 "Builds the entire background manpage and cleaning command." |
8513 (let ((command (concat pod2man-program " %s 2>/dev/null")) | 8585 (let ((command (concat pod2man-program " %s 2>/dev/null")) |
8886 (save-excursion | 8958 (save-excursion |
8887 (goto-char from) | 8959 (goto-char from) |
8888 (cperl-fontify-syntaxically to))))) | 8960 (cperl-fontify-syntaxically to))))) |
8889 | 8961 |
8890 (defvar cperl-version | 8962 (defvar cperl-version |
8891 (let ((v "Revision: 5.23")) | 8963 (let ((v "Revision: 6.2")) |
8892 (string-match ":\\s *\\([0-9.]+\\)" v) | 8964 (string-match ":\\s *\\([0-9.]+\\)" v) |
8893 (substring v (match-beginning 1) (match-end 1))) | 8965 (substring v (match-beginning 1) (match-end 1))) |
8894 "Version of IZ-supported CPerl package this file is based on.") | 8966 "Version of IZ-supported CPerl package this file is based on.") |
8895 | 8967 |
8896 (provide 'cperl-mode) | 8968 (provide 'cperl-mode) |