diff options
| author | Richard M. Stallman | 1998-05-30 15:43:16 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1998-05-30 15:43:16 +0000 |
| commit | db133cb6032095e0efe127e3bd09f6aa595a16cd (patch) | |
| tree | 4f1ea262ae427797a35e61e0f2600e5d9bb110d8 | |
| parent | 68dabb618a82aa10945a05644b2c39babda38269 (diff) | |
| download | emacs-db133cb6032095e0efe127e3bd09f6aa595a16cd.tar.gz emacs-db133cb6032095e0efe127e3bd09f6aa595a16cd.zip | |
(cperl-style-alist): New variable, since `c-mode'
is no longer loaded.
- (Somebody who uses the styles should check that they work OK!)
- (a lot of work is needed, especially with new
`cperl-fix-line-spacing').
Old value of style is memorized when choosing a new style, may be
restored from the same menu.
(cperl-perldoc, cperl-pod-to-manpage): New commands; thanks to
Anthony Foiani <afoiani@uswest.com> and Nick Roberts
<Nick.Roberts@src.bae.co.uk>.
(`Perl doc', `Regexp'): New submenus (latter to allow short displays).
(cperl-clobber-lisp-bindings): New cfg variable.
(cperl-find-pods-heres): $a->y() is not y///.
(cperl-after-block-p): Add save-excursion.
(cperl-init-faces): Was failing.
Init faces when loading `ps-print'.
(cperl-toggle-autohelp): New command.
(cperl-electric-paren): `while SPACE LESS' was buggy.
(cperl-init-faces): `-text' in `[-text => 1]' was not highlighted.
(cperl-after-block-p): was FALSE after `sub f {}'.
(cperl-electric-keyword): `foreachmy', `formy' expanded too,
Expands `=pod-directive'.
(cperl-linefeed): behaves reasonable in POD-directive lines.
(cperl-message-electric-keyword): new cfg variable.
(cperl-electric-keyword): print a message, governed by
`cperl-message-electric-keyword'.
(cperl-electric-paren): Typing `}' was not checking for being
block or not.
(cperl-beautify-regexp-piece): Did not know about lookbehind;
finding *which* level to work with was not intuitive.
(cperl-beautify-levels): New command.
(cperl-electric-keyword): Allow here-docs contain `=head1'
and friends for keyword expansion.
Fix for broken `font-lock-unfontify-region-function'. Should
preserve `syntax-table' properties even with `lazy-lock'.
(cperl-indent-region-fix-else): New command.
(cperl-fix-line-spacing): New command.
(cperl-invert-if-unless): New command (C-c C-t and in Menu).
(cperl-hints): mention 20.2's goods/bads.
(cperl-extra-newline-before-brace-multiline): Started to use it.
(cperl-break-one-line-blocks-when-indent): New cfg variable.
(cperl-fix-hanging-brace-when-indent): New cfg variable.
(cperl-merge-trailing-else): New cfg variable.
Workaround for another `font-lock's `syntax-table' text-property bug.
`zerop' could be applied to nil.
At last, may work with `font-lock' without setting `cperl-font-lock'.
(cperl-indent-region-fix-constructs): Renamed from
`cperl-indent-region-fix-constructs'.
(cperl-fix-line-spacing): could be triggered inside strings, would not
know what to do with BLOCKs of map/printf/etc.
(cperl-merge-trailing-else): Handle `continue' too.
(cperl-fix-line-spacing): Likewise.
(cperl-calculate-indent): Knows about map/printf/etc before {BLOCK};
treat after-comma lines as continuation lines.
(cperl-mode): `continue' made electric.
(cperl-electric-keyword): Electric `do' inserts `do/while'.
(cperl-fontify-syntaxically): New function.
(cperl-syntaxify-by-font-lock): New cfg variable.
Make syntaxification to be autoredone via `font-lock',
switched on by `cperl-syntaxify-by-font-lock', off by default so far.
Remove some commented out chunks.
(cperl-set-style-back): Old value of style is memorized when
choosing a new style, may be restored from the same menu.
Mode-documentation added to micro-docs.
(cperl-praise): updated.
(cperl-toggle-construct-fix): New command. Added on C-c C-w and menu.
(auto-fill-mode): added on C-c C-f and menu.
(cperl-style-alist): `PerlStyle' style added.
(cperl-find-pods-heres): Message for termination of scan corrected.
(cperl-speed): New variable with hints.
(cperl-electric-else): Make backspace electric after
expansion of `else/continue' too.
Fixed customization to honor cperl-hairy.
Created customization groups.
All the compile-time warnings fixed.
(cperl-syntaxify-by-font-lock): Interaction with `font-lock-hot-pass'
fixed.
(cperl-after-block-and-statement-beg): It is BLOCK if we reach lim
when backup sexp.
(cperl-after-block-p, cperl-after-expr-p): Likewise.
(cperl-indent-region): Make a marker for END - text added/removed.
(cperl-style-alist): Include `cperl-merge-trailing-else'
where the value is clear.
(cperl-styles-entries): Likewise.
(cperl-tips, cperl-problems): Improvements to docs.
| -rw-r--r-- | lisp/progmodes/cperl-mode.el | 2088 |
1 files changed, 1478 insertions, 610 deletions
diff --git a/lisp/progmodes/cperl-mode.el b/lisp/progmodes/cperl-mode.el index 784a0166a7f..88ca899869c 100644 --- a/lisp/progmodes/cperl-mode.el +++ b/lisp/progmodes/cperl-mode.el | |||
| @@ -39,7 +39,7 @@ | |||
| 39 | 39 | ||
| 40 | ;;; DO NOT FORGET to read micro-docs (available from `Perl' menu) <<<<<< | 40 | ;;; DO NOT FORGET to read micro-docs (available from `Perl' menu) <<<<<< |
| 41 | ;;; or as help on variables `cperl-tips', `cperl-problems', <<<<<< | 41 | ;;; or as help on variables `cperl-tips', `cperl-problems', <<<<<< |
| 42 | ;;; `cperl-non-problems', `cperl-praise'. <<<<<< | 42 | ;;; `cperl-non-problems', `cperl-praise', `cperl-speed'. <<<<<< |
| 43 | 43 | ||
| 44 | ;;; The mode information (on C-h m) provides some customization help. | 44 | ;;; The mode information (on C-h m) provides some customization help. |
| 45 | ;;; If you use font-lock feature of this mode, it is advisable to use | 45 | ;;; If you use font-lock feature of this mode, it is advisable to use |
| @@ -66,9 +66,39 @@ | |||
| 66 | (defgroup cperl nil | 66 | (defgroup cperl nil |
| 67 | "Major mode for editing Perl code." | 67 | "Major mode for editing Perl code." |
| 68 | :prefix "cperl-" | 68 | :prefix "cperl-" |
| 69 | :group 'languages) | 69 | :group 'languages |
| 70 | :version "20.3") | ||
| 71 | |||
| 72 | (defgroup cperl-indentation-details nil | ||
| 73 | "Indentation." | ||
| 74 | :prefix "cperl-" | ||
| 75 | :group 'cperl) | ||
| 76 | |||
| 77 | (defgroup cperl-affected-by-hairy nil | ||
| 78 | "Variables affected by `cperl-hairy'." | ||
| 79 | :prefix "cperl-" | ||
| 80 | :group 'cperl) | ||
| 81 | |||
| 82 | (defgroup cperl-autoinsert-details nil | ||
| 83 | "Auto-insert tuneup." | ||
| 84 | :prefix "cperl-" | ||
| 85 | :group 'cperl) | ||
| 86 | |||
| 87 | (defgroup cperl-faces nil | ||
| 88 | "Fontification colors." | ||
| 89 | :prefix "cperl-" | ||
| 90 | :group 'cperl) | ||
| 91 | |||
| 92 | (defgroup cperl-speed nil | ||
| 93 | "Speed vs. validity tuneup." | ||
| 94 | :prefix "cperl-" | ||
| 95 | :group 'cperl) | ||
| 96 | |||
| 97 | (defgroup cperl-help-system nil | ||
| 98 | "Help system tuneup." | ||
| 99 | :prefix "cperl-" | ||
| 100 | :group 'cperl) | ||
| 70 | 101 | ||
| 71 | (defconst cperl-xemacs-p (string-match "XEmacs\\|Lucid" emacs-version)) | ||
| 72 | 102 | ||
| 73 | (defcustom cperl-extra-newline-before-brace nil | 103 | (defcustom cperl-extra-newline-before-brace nil |
| 74 | "*Non-nil means that if, elsif, while, until, else, for, foreach | 104 | "*Non-nil means that if, elsif, while, until, else, for, foreach |
| @@ -84,50 +114,58 @@ instead of: | |||
| 84 | } | 114 | } |
| 85 | " | 115 | " |
| 86 | :type 'boolean | 116 | :type 'boolean |
| 87 | :group 'cperl) | 117 | :group 'cperl-autoinsert-details) |
| 118 | |||
| 119 | (defcustom cperl-extra-newline-before-brace-multiline | ||
| 120 | cperl-extra-newline-before-brace | ||
| 121 | "*Non-nil means the same as `cperl-extra-newline-before-brace', but | ||
| 122 | for constructs with multiline if/unless/while/until/for/foreach condition." | ||
| 123 | :type 'boolean | ||
| 124 | :group 'cperl-autoinsert-details) | ||
| 88 | 125 | ||
| 89 | (defcustom cperl-indent-level 2 | 126 | (defcustom cperl-indent-level 2 |
| 90 | "*Indentation of CPerl statements with respect to containing block." | 127 | "*Indentation of CPerl statements with respect to containing block." |
| 91 | :type 'integer | 128 | :type 'integer |
| 92 | :group 'cperl) | 129 | :group 'cperl-indentation-details) |
| 93 | 130 | ||
| 94 | (defcustom cperl-lineup-step nil | 131 | (defcustom cperl-lineup-step nil |
| 95 | "*`cperl-lineup' will always lineup at multiple of this number. | 132 | "*`cperl-lineup' will always lineup at multiple of this number. |
| 96 | If `nil', the value of `cperl-indent-level' will be used." | 133 | If `nil', the value of `cperl-indent-level' will be used." |
| 97 | :type '(choice (const nil) integer) | 134 | :type '(choice (const nil) integer) |
| 98 | :group 'cperl) | 135 | :group 'cperl-indentation-details) |
| 136 | |||
| 99 | (defcustom cperl-brace-imaginary-offset 0 | 137 | (defcustom cperl-brace-imaginary-offset 0 |
| 100 | "*Imagined indentation of a Perl open brace that actually follows a statement. | 138 | "*Imagined indentation of a Perl open brace that actually follows a statement. |
| 101 | An open brace following other text is treated as if it were this far | 139 | An open brace following other text is treated as if it were this far |
| 102 | to the right of the start of its line." | 140 | to the right of the start of its line." |
| 103 | :type 'integer | 141 | :type 'integer |
| 104 | :group 'cperl) | 142 | :group 'cperl-indentation-details) |
| 105 | 143 | ||
| 106 | (defcustom cperl-brace-offset 0 | 144 | (defcustom cperl-brace-offset 0 |
| 107 | "*Extra indentation for braces, compared with other text in same context." | 145 | "*Extra indentation for braces, compared with other text in same context." |
| 108 | :type 'integer | 146 | :type 'integer |
| 109 | :group 'cperl) | 147 | :group 'cperl-indentation-details) |
| 110 | (defcustom cperl-label-offset -2 | 148 | (defcustom cperl-label-offset -2 |
| 111 | "*Offset of CPerl label lines relative to usual indentation." | 149 | "*Offset of CPerl label lines relative to usual indentation." |
| 112 | :type 'integer | 150 | :type 'integer |
| 113 | :group 'cperl) | 151 | :group 'cperl-indentation-details) |
| 114 | (defcustom cperl-min-label-indent 1 | 152 | (defcustom cperl-min-label-indent 1 |
| 115 | "*Minimal offset of CPerl label lines." | 153 | "*Minimal offset of CPerl label lines." |
| 116 | :type 'integer | 154 | :type 'integer |
| 117 | :group 'cperl) | 155 | :group 'cperl-indentation-details) |
| 118 | (defcustom cperl-continued-statement-offset 2 | 156 | (defcustom cperl-continued-statement-offset 2 |
| 119 | "*Extra indent for lines not starting new statements." | 157 | "*Extra indent for lines not starting new statements." |
| 120 | :type 'integer | 158 | :type 'integer |
| 121 | :group 'cperl) | 159 | :group 'cperl-indentation-details) |
| 122 | (defcustom cperl-continued-brace-offset 0 | 160 | (defcustom cperl-continued-brace-offset 0 |
| 123 | "*Extra indent for substatements that start with open-braces. | 161 | "*Extra indent for substatements that start with open-braces. |
| 124 | This is in addition to cperl-continued-statement-offset." | 162 | This is in addition to cperl-continued-statement-offset." |
| 125 | :type 'integer | 163 | :type 'integer |
| 126 | :group 'cperl) | 164 | :group 'cperl-indentation-details) |
| 127 | (defcustom cperl-close-paren-offset -1 | 165 | (defcustom cperl-close-paren-offset -1 |
| 128 | "*Extra indent for substatements that start with close-parenthesis." | 166 | "*Extra indent for substatements that start with close-parenthesis." |
| 129 | :type 'integer | 167 | :type 'integer |
| 130 | :group 'cperl) | 168 | :group 'cperl-indentation-details) |
| 131 | 169 | ||
| 132 | (defcustom cperl-auto-newline nil | 170 | (defcustom cperl-auto-newline nil |
| 133 | "*Non-nil means automatically newline before and after braces, | 171 | "*Non-nil means automatically newline before and after braces, |
| @@ -136,43 +174,46 @@ and after colons and semicolons, inserted in CPerl code. The following | |||
| 136 | Insertion after colons requires both this variable and | 174 | Insertion after colons requires both this variable and |
| 137 | `cperl-auto-newline-after-colon' set." | 175 | `cperl-auto-newline-after-colon' set." |
| 138 | :type 'boolean | 176 | :type 'boolean |
| 139 | :group 'cperl) | 177 | :group 'cperl-autoinsert-details) |
| 140 | 178 | ||
| 141 | (defcustom cperl-auto-newline-after-colon nil | 179 | (defcustom cperl-auto-newline-after-colon nil |
| 142 | "*Non-nil means automatically newline even after colons. | 180 | "*Non-nil means automatically newline even after colons. |
| 143 | Subject to `cperl-auto-newline' setting." | 181 | Subject to `cperl-auto-newline' setting." |
| 144 | :type 'boolean | 182 | :type 'boolean |
| 145 | :group 'cperl) | 183 | :group 'cperl-autoinsert-details) |
| 146 | 184 | ||
| 147 | (defcustom cperl-tab-always-indent t | 185 | (defcustom cperl-tab-always-indent t |
| 148 | "*Non-nil means TAB in CPerl mode should always reindent the current line, | 186 | "*Non-nil means TAB in CPerl mode should always reindent the current line, |
| 149 | regardless of where in the line point is when the TAB command is used." | 187 | regardless of where in the line point is when the TAB command is used." |
| 150 | :type 'boolean | 188 | :type 'boolean |
| 151 | :group 'cperl) | 189 | :group 'cperl-indentation-details) |
| 152 | 190 | ||
| 153 | (defcustom cperl-font-lock nil | 191 | (defcustom cperl-font-lock nil |
| 154 | "*Non-nil (and non-null) means CPerl buffers will use font-lock-mode. | 192 | "*Non-nil (and non-null) means CPerl buffers will use font-lock-mode. |
| 155 | Can be overwritten by `cperl-hairy' if nil." | 193 | Can be overwritten by `cperl-hairy' if nil." |
| 156 | :type 'boolean | 194 | :type '(choice (const null) boolean) |
| 157 | :group 'cperl) | 195 | :group 'cperl-affected-by-hairy) |
| 158 | 196 | ||
| 159 | (defcustom cperl-electric-lbrace-space nil | 197 | (defcustom cperl-electric-lbrace-space nil |
| 160 | "*Non-nil (and non-null) means { after $ in CPerl buffers should be preceded by ` '. | 198 | "*Non-nil (and non-null) means { after $ in CPerl buffers should be preceded by ` '. |
| 161 | Can be overwritten by `cperl-hairy' if nil." | 199 | Can be overwritten by `cperl-hairy' if nil." |
| 162 | :type 'boolean | 200 | :type '(choice (const null) boolean) |
| 163 | :group 'cperl) | 201 | :group 'cperl-affected-by-hairy) |
| 164 | 202 | ||
| 165 | (defcustom cperl-electric-parens-string "({[]})<" | 203 | (defcustom cperl-electric-parens-string "({[]})<" |
| 166 | "*String of parentheses that should be electric in CPerl. | 204 | "*String of parentheses that should be electric in CPerl. |
| 167 | Closing ones are electric only if the region is highlighted." | 205 | Closing ones are electric only if the region is highlighted." |
| 168 | :type 'string | 206 | :type 'string |
| 169 | :group 'cperl) | 207 | :group 'cperl-affected-by-hairy) |
| 170 | 208 | ||
| 171 | (defcustom cperl-electric-parens nil | 209 | (defcustom cperl-electric-parens nil |
| 172 | "*Non-nil (and non-null) means parentheses should be electric in CPerl. | 210 | "*Non-nil (and non-null) means parentheses should be electric in CPerl. |
| 173 | Can be overwritten by `cperl-hairy' if nil." | 211 | Can be overwritten by `cperl-hairy' if nil." |
| 174 | :type 'boolean | 212 | :type '(choice (const null) boolean) |
| 175 | :group 'cperl) | 213 | :group 'cperl-affected-by-hairy) |
| 214 | |||
| 215 | (defvar zmacs-regions) ; Avoid warning | ||
| 216 | |||
| 176 | (defcustom cperl-electric-parens-mark | 217 | (defcustom cperl-electric-parens-mark |
| 177 | (and window-system | 218 | (and window-system |
| 178 | (or (and (boundp 'transient-mark-mode) ; For Emacs | 219 | (or (and (boundp 'transient-mark-mode) ; For Emacs |
| @@ -182,30 +223,34 @@ Can be overwritten by `cperl-hairy' if nil." | |||
| 182 | "*Not-nil means that electric parens look for active mark. | 223 | "*Not-nil means that electric parens look for active mark. |
| 183 | Default is yes if there is visual feedback on mark." | 224 | Default is yes if there is visual feedback on mark." |
| 184 | :type 'boolean | 225 | :type 'boolean |
| 185 | :group 'cperl) | 226 | :group 'cperl-autoinsert-details) |
| 186 | 227 | ||
| 187 | (defcustom cperl-electric-linefeed nil | 228 | (defcustom cperl-electric-linefeed nil |
| 188 | "*If true, LFD should be hairy in CPerl, otherwise C-c LFD is hairy. | 229 | "*If true, LFD should be hairy in CPerl, otherwise C-c LFD is hairy. |
| 189 | In any case these two mean plain and hairy linefeeds together. | 230 | In any case these two mean plain and hairy linefeeds together. |
| 190 | Can be overwritten by `cperl-hairy' if nil." | 231 | Can be overwritten by `cperl-hairy' if nil." |
| 191 | :type 'boolean | 232 | :type '(choice (const null) boolean) |
| 192 | :group 'cperl) | 233 | :group 'cperl-affected-by-hairy) |
| 193 | 234 | ||
| 194 | (defcustom cperl-electric-keywords nil | 235 | (defcustom cperl-electric-keywords nil |
| 195 | "*Not-nil (and non-null) means keywords are electric in CPerl. | 236 | "*Not-nil (and non-null) means keywords are electric in CPerl. |
| 196 | Can be overwritten by `cperl-hairy' if nil." | 237 | Can be overwritten by `cperl-hairy' if nil." |
| 197 | :type 'boolean | 238 | :type '(choice (const null) boolean) |
| 198 | :group 'cperl) | 239 | :group 'cperl-affected-by-hairy) |
| 199 | 240 | ||
| 200 | (defcustom cperl-hairy nil | 241 | (defcustom cperl-hairy nil |
| 201 | "*Not-nil means all the bells and whistles are enabled in CPerl." | 242 | "*Not-nil means most of the bells and whistles are enabled in CPerl. |
| 243 | Affects: `cperl-font-lock', `cperl-electric-lbrace-space', | ||
| 244 | `cperl-electric-parens', `cperl-electric-linefeed', `cperl-electric-keywords', | ||
| 245 | `cperl-info-on-command-no-prompt', `cperl-clobber-lisp-bindings', | ||
| 246 | `cperl-lazy-help-time'." | ||
| 202 | :type 'boolean | 247 | :type 'boolean |
| 203 | :group 'cperl) | 248 | :group 'cperl-affected-by-hairy) |
| 204 | 249 | ||
| 205 | (defcustom cperl-comment-column 32 | 250 | (defcustom cperl-comment-column 32 |
| 206 | "*Column to put comments in CPerl (use \\[cperl-indent] to lineup with code)." | 251 | "*Column to put comments in CPerl (use \\[cperl-indent] to lineup with code)." |
| 207 | :type 'integer | 252 | :type 'integer |
| 208 | :group 'cperl) | 253 | :group 'cperl-indentation-details) |
| 209 | 254 | ||
| 210 | (defcustom cperl-vc-header-alist '((SCCS "$sccs = '%W\%' ;") | 255 | (defcustom cperl-vc-header-alist '((SCCS "$sccs = '%W\%' ;") |
| 211 | (RCS "$rcs = ' $Id\$ ' ;")) | 256 | (RCS "$rcs = ' $Id\$ ' ;")) |
| @@ -217,74 +262,82 @@ Can be overwritten by `cperl-hairy' if nil." | |||
| 217 | "*Not-nil (and non-null) means not to prompt on C-h f. | 262 | "*Not-nil (and non-null) means not to prompt on C-h f. |
| 218 | The opposite behaviour is always available if prefixed with C-c. | 263 | The opposite behaviour is always available if prefixed with C-c. |
| 219 | Can be overwritten by `cperl-hairy' if nil." | 264 | Can be overwritten by `cperl-hairy' if nil." |
| 220 | :type 'boolean | 265 | :type '(choice (const null) boolean) |
| 221 | :group 'cperl) | 266 | :group 'cperl-affected-by-hairy) |
| 267 | |||
| 268 | (defcustom cperl-clobber-lisp-bindings nil | ||
| 269 | "*Not-nil (and non-null) means not overwrite C-h f. | ||
| 270 | The function is available on \\[cperl-info-on-command], \\[cperl-get-help]. | ||
| 271 | Can be overwritten by `cperl-hairy' if nil." | ||
| 272 | :type '(choice (const null) boolean) | ||
| 273 | :group 'cperl-affected-by-hairy) | ||
| 222 | 274 | ||
| 223 | (defcustom cperl-lazy-help-time nil | 275 | (defcustom cperl-lazy-help-time nil |
| 224 | "*Not-nil (and non-null) means to show lazy help after given idle time." | 276 | "*Not-nil (and non-null) means to show lazy help after given idle time. |
| 225 | :type 'boolean | 277 | Can be overwritten by `cperl-hairy' to be 5 sec if nil." |
| 226 | :group 'cperl) | 278 | :type '(choice (const null) integer) |
| 279 | :group 'cperl-affected-by-hairy) | ||
| 227 | 280 | ||
| 228 | (defcustom cperl-pod-face 'font-lock-comment-face | 281 | (defcustom cperl-pod-face 'font-lock-comment-face |
| 229 | "*The result of evaluation of this expression is used for pod highlighting." | 282 | "*The result of evaluation of this expression is used for pod highlighting." |
| 230 | :type 'face | 283 | :type 'face |
| 231 | :group 'cperl) | 284 | :group 'cperl-faces) |
| 232 | 285 | ||
| 233 | (defcustom cperl-pod-head-face 'font-lock-variable-name-face | 286 | (defcustom cperl-pod-head-face 'font-lock-variable-name-face |
| 234 | "*The result of evaluation of this expression is used for pod highlighting. | 287 | "*The result of evaluation of this expression is used for pod highlighting. |
| 235 | Font for POD headers." | 288 | Font for POD headers." |
| 236 | :type 'face | 289 | :type 'face |
| 237 | :group 'cperl) | 290 | :group 'cperl-faces) |
| 238 | 291 | ||
| 239 | (defcustom cperl-here-face 'font-lock-string-face | 292 | (defcustom cperl-here-face 'font-lock-string-face |
| 240 | "*The result of evaluation of this expression is used for here-docs highlighting." | 293 | "*The result of evaluation of this expression is used for here-docs highlighting." |
| 241 | :type 'face | 294 | :type 'face |
| 242 | :group 'cperl) | 295 | :group 'cperl-faces) |
| 243 | 296 | ||
| 244 | (defcustom cperl-pod-here-fontify '(featurep 'font-lock) | 297 | (defcustom cperl-pod-here-fontify '(featurep 'font-lock) |
| 245 | "*Not-nil after evaluation means to highlight pod and here-docs sections." | 298 | "*Not-nil after evaluation means to highlight pod and here-docs sections." |
| 246 | :type 'boolean | 299 | :type 'boolean |
| 247 | :group 'cperl) | 300 | :group 'cperl-faces) |
| 248 | 301 | ||
| 249 | (defcustom cperl-pod-here-scan t | 302 | (defcustom cperl-pod-here-scan t |
| 250 | "*Not-nil means look for pod and here-docs sections during startup. | 303 | "*Not-nil means look for pod and here-docs sections during startup. |
| 251 | You can always make lookup from menu or using \\[cperl-find-pods-heres]." | 304 | You can always make lookup from menu or using \\[cperl-find-pods-heres]." |
| 252 | :type 'boolean | 305 | :type 'boolean |
| 253 | :group 'cperl) | 306 | :group 'cperl-speed) |
| 254 | 307 | ||
| 255 | (defcustom cperl-imenu-addback nil | 308 | (defcustom cperl-imenu-addback nil |
| 256 | "*Not-nil means add backreferences to generated `imenu's. | 309 | "*Not-nil means add backreferences to generated `imenu's. |
| 257 | May require patched `imenu' and `imenu-go'." | 310 | May require patched `imenu' and `imenu-go'. Obsolete." |
| 258 | :type 'boolean | 311 | :type 'boolean |
| 259 | :group 'cperl) | 312 | :group 'cperl-help-system) |
| 260 | 313 | ||
| 261 | (defcustom cperl-max-help-size 66 | 314 | (defcustom cperl-max-help-size 66 |
| 262 | "*Non-nil means shrink-wrapping of info-buffer allowed up to these percents." | 315 | "*Non-nil means shrink-wrapping of info-buffer allowed up to these percents." |
| 263 | :type '(choice integer (const nil)) | 316 | :type '(choice integer (const nil)) |
| 264 | :group 'cperl) | 317 | :group 'cperl-help-system) |
| 265 | 318 | ||
| 266 | (defcustom cperl-shrink-wrap-info-frame t | 319 | (defcustom cperl-shrink-wrap-info-frame t |
| 267 | "*Non-nil means shrink-wrapping of info-buffer-frame allowed." | 320 | "*Non-nil means shrink-wrapping of info-buffer-frame allowed." |
| 268 | :type 'boolean | 321 | :type 'boolean |
| 269 | :group 'cperl) | 322 | :group 'cperl-help-system) |
| 270 | 323 | ||
| 271 | (defcustom cperl-info-page "perl" | 324 | (defcustom cperl-info-page "perl" |
| 272 | "*Name of the info page containing perl docs. | 325 | "*Name of the info page containing perl docs. |
| 273 | Older version of this page was called `perl5', newer `perl'." | 326 | Older version of this page was called `perl5', newer `perl'." |
| 274 | :type 'string | 327 | :type 'string |
| 275 | :group 'cperl) | 328 | :group 'cperl-help-system) |
| 276 | 329 | ||
| 277 | (defcustom cperl-use-syntax-table-text-property | 330 | (defcustom cperl-use-syntax-table-text-property |
| 278 | (boundp 'parse-sexp-lookup-properties) | 331 | (boundp 'parse-sexp-lookup-properties) |
| 279 | "*Non-nil means CPerl sets up and uses `syntax-table' text property." | 332 | "*Non-nil means CPerl sets up and uses `syntax-table' text property." |
| 280 | :type 'boolean | 333 | :type 'boolean |
| 281 | :group 'cperl) | 334 | :group 'cperl-speed) |
| 282 | 335 | ||
| 283 | (defcustom cperl-use-syntax-table-text-property-for-tags | 336 | (defcustom cperl-use-syntax-table-text-property-for-tags |
| 284 | cperl-use-syntax-table-text-property | 337 | cperl-use-syntax-table-text-property |
| 285 | "*Non-nil means: set up and use `syntax-table' text property generating TAGS." | 338 | "*Non-nil means: set up and use `syntax-table' text property generating TAGS." |
| 286 | :type 'boolean | 339 | :type 'boolean |
| 287 | :group 'cperl) | 340 | :group 'cperl-speed) |
| 288 | 341 | ||
| 289 | (defcustom cperl-scan-files-regexp "\\.\\([pP][Llm]\\|xs\\)$" | 342 | (defcustom cperl-scan-files-regexp "\\.\\([pP][Llm]\\|xs\\)$" |
| 290 | "*Regexp to match files to scan when generating TAGS." | 343 | "*Regexp to match files to scan when generating TAGS." |
| @@ -300,18 +353,61 @@ Older version of this page was called `perl5', newer `perl'." | |||
| 300 | "*Indentation used when beautifying regexps. | 353 | "*Indentation used when beautifying regexps. |
| 301 | If `nil', the value of `cperl-indent-level' will be used." | 354 | If `nil', the value of `cperl-indent-level' will be used." |
| 302 | :type '(choice integer (const nil)) | 355 | :type '(choice integer (const nil)) |
| 303 | :group 'cperl) | 356 | :group 'cperl-indentation-details) |
| 304 | 357 | ||
| 305 | (defcustom cperl-indent-left-aligned-comments t | 358 | (defcustom cperl-indent-left-aligned-comments t |
| 306 | "*Non-nil means that the comment starting in leftmost column should indent." | 359 | "*Non-nil means that the comment starting in leftmost column should indent." |
| 307 | :type 'boolean | 360 | :type 'boolean |
| 308 | :group 'cperl) | 361 | :group 'cperl-indentation-details) |
| 309 | 362 | ||
| 310 | (defcustom cperl-under-as-char t | 363 | (defcustom cperl-under-as-char t |
| 311 | "*Non-nil means that the _ (underline) should be treated as word char." | 364 | "*Non-nil means that the _ (underline) should be treated as word char." |
| 312 | :type 'boolean | 365 | :type 'boolean |
| 313 | :group 'cperl) | 366 | :group 'cperl) |
| 314 | 367 | ||
| 368 | (defcustom cperl-extra-perl-args "" | ||
| 369 | "*Extra arguments to use when starting Perl. | ||
| 370 | Currently used with `cperl-check-syntax' only." | ||
| 371 | :type 'string | ||
| 372 | :group 'cperl) | ||
| 373 | |||
| 374 | (defcustom cperl-message-electric-keyword t | ||
| 375 | "*Non-nil means that the `cperl-electric-keyword' prints a help message." | ||
| 376 | :type 'boolean | ||
| 377 | :group 'cperl-help-system) | ||
| 378 | |||
| 379 | (defcustom cperl-indent-region-fix-constructs 1 | ||
| 380 | "*Amount of space to insert between `}' and `else' or `elsif' | ||
| 381 | in `cperl-indent-region'. Set to nil to leave as is. Values other | ||
| 382 | than 1 and nil will probably not work." | ||
| 383 | :type '(choice (const nil) (const 1)) | ||
| 384 | :group 'cperl-indentation-details) | ||
| 385 | |||
| 386 | (defcustom cperl-break-one-line-blocks-when-indent t | ||
| 387 | "*Non-nil means that one-line if/unless/while/until/for/foreach BLOCKs | ||
| 388 | need to be reformated into multiline ones when indenting a region." | ||
| 389 | :type 'boolean | ||
| 390 | :group 'cperl-indentation-details) | ||
| 391 | |||
| 392 | (defcustom cperl-fix-hanging-brace-when-indent t | ||
| 393 | "*Non-nil means that BLOCK-end `}' may be put on a separate line | ||
| 394 | when indenting a region. | ||
| 395 | Braces followed by else/elsif/while/until are excepted." | ||
| 396 | :type 'boolean | ||
| 397 | :group 'cperl-indentation-details) | ||
| 398 | |||
| 399 | (defcustom cperl-merge-trailing-else t | ||
| 400 | "*Non-nil means that BLOCK-end `}' followed by else/elsif/continue | ||
| 401 | may be merged to be on the same line when indenting a region." | ||
| 402 | :type 'boolean | ||
| 403 | :group 'cperl-indentation-details) | ||
| 404 | |||
| 405 | (defcustom cperl-syntaxify-by-font-lock nil | ||
| 406 | "*Non-nil means that CPerl uses `font-lock's routines for syntaxification. | ||
| 407 | Not debugged yet." | ||
| 408 | :type 'boolean | ||
| 409 | :group 'cperl-speed) | ||
| 410 | |||
| 315 | 411 | ||
| 316 | 412 | ||
| 317 | ;;; Short extra-docs. | 413 | ;;; Short extra-docs. |
| @@ -321,6 +417,8 @@ If `nil', the value of `cperl-indent-level' will be used." | |||
| 321 | ftp://ftp.math.ohio-state.edu/pub/users/ilya/emacs | 417 | ftp://ftp.math.ohio-state.edu/pub/users/ilya/emacs |
| 322 | and/or | 418 | and/or |
| 323 | ftp://ftp.math.ohio-state.edu/pub/users/ilya/perl | 419 | ftp://ftp.math.ohio-state.edu/pub/users/ilya/perl |
| 420 | Subdirectory `cperl-mode' may contain yet newer development releases and/or | ||
| 421 | patches to related files. | ||
| 324 | 422 | ||
| 325 | Get support packages choose-color.el (or font-lock-extra.el before | 423 | Get support packages choose-color.el (or font-lock-extra.el before |
| 326 | 19.30), imenu-go.el from the same place. \(Look for other files there | 424 | 19.30), imenu-go.el from the same place. \(Look for other files there |
| @@ -353,16 +451,15 @@ Before reporting (non-)problems look in the problem section on what I | |||
| 353 | know about them.") | 451 | know about them.") |
| 354 | 452 | ||
| 355 | (defvar cperl-problems 'please-ignore-this-line | 453 | (defvar cperl-problems 'please-ignore-this-line |
| 356 | "Emacs has a _very_ restricted syntax parsing engine. | 454 | "Emacs had a _very_ restricted syntax parsing engine (until RMS's Emacs |
| 455 | 20.1). | ||
| 357 | 456 | ||
| 358 | It may be corrected on the level of C code, please look in the | 457 | Even with older Emacsen CPerl mode tries to corrects some Emacs |
| 359 | `non-problems' section if you want to volunteer. | 458 | misunderstandings, however, for efficiency reasons the degree of |
| 360 | 459 | correction is different for different operations. The partially | |
| 361 | CPerl mode tries to corrects some Emacs misunderstandings, however, | 460 | corrected problems are: POD sections, here-documents, regexps. The |
| 362 | for efficiency reasons the degree of correction is different for | 461 | operations are: highlighting, indentation, electric keywords, electric |
| 363 | different operations. The partially corrected problems are: POD | 462 | braces. |
| 364 | sections, here-documents, regexps. The operations are: highlighting, | ||
| 365 | indentation, electric keywords, electric braces. | ||
| 366 | 463 | ||
| 367 | This may be confusing, since the regexp s#//#/#\; may be highlighted | 464 | This may be confusing, since the regexp s#//#/#\; may be highlighted |
| 368 | as a comment, but it will be recognized as a regexp by the indentation | 465 | as a comment, but it will be recognized as a regexp by the indentation |
| @@ -375,14 +472,23 @@ ${aaa} look like unbalanced braces. The only trick I can think of is | |||
| 375 | to insert it as $ {aaa} (legal in perl5, not in perl4). | 472 | to insert it as $ {aaa} (legal in perl5, not in perl4). |
| 376 | 473 | ||
| 377 | Similar problems arise in regexps, when /(\\s|$)/ should be rewritten | 474 | Similar problems arise in regexps, when /(\\s|$)/ should be rewritten |
| 378 | as /($|\\s)/. Note that such a transposition is not always possible | 475 | as /($|\\s)/. Note that such a transposition is not always possible. |
| 379 | :-(. " ) | 476 | |
| 477 | The solution is to upgrade your Emacs. Note that RMS's 20.2 has some | ||
| 478 | bugs related to `syntax-table' text properties. Patches are available | ||
| 479 | on the main CPerl download site, and on CPAN. | ||
| 480 | |||
| 481 | If these bugs cannot be fixed on your machine (say, you have an inferior | ||
| 482 | environment and cannot recompile), you may still disable all the fancy stuff | ||
| 483 | via `cperl-use-syntax-table-text-property'." ) | ||
| 380 | 484 | ||
| 381 | (defvar cperl-non-problems 'please-ignore-this-line | 485 | (defvar cperl-non-problems 'please-ignore-this-line |
| 382 | "As you know from `problems' section, Perl syntax is too hard for CPerl. | 486 | "As you know from `problems' section, Perl syntax is too hard for CPerl on |
| 487 | older Emacsen. | ||
| 383 | 488 | ||
| 384 | Most the time, if you write your own code, you may find an equivalent | 489 | Most of the time, if you write your own code, you may find an equivalent |
| 385 | \(and almost as readable) expression. | 490 | \(and almost as readable) expression (what is discussed below is usually |
| 491 | not relevant on newer Emacsen, since they can do it automatically). | ||
| 386 | 492 | ||
| 387 | Try to help CPerl: add comments with embedded quotes to fix CPerl | 493 | Try to help CPerl: add comments with embedded quotes to fix CPerl |
| 388 | misunderstandings about the end of quotation: | 494 | misunderstandings about the end of quotation: |
| @@ -392,19 +498,21 @@ $a='500$'; # '; | |||
| 392 | You won't need it too often. The reason: $ \"quotes\" the following | 498 | You won't need it too often. The reason: $ \"quotes\" the following |
| 393 | character (this saves a life a lot of times in CPerl), thus due to | 499 | character (this saves a life a lot of times in CPerl), thus due to |
| 394 | Emacs parsing rules it does not consider tick (i.e., ' ) after a | 500 | Emacs parsing rules it does not consider tick (i.e., ' ) after a |
| 395 | dollar as a closing one, but as a usual character. | 501 | dollar as a closing one, but as a usual character. This is usually |
| 502 | correct, but not in the above context. | ||
| 396 | 503 | ||
| 397 | Now the indentation code is pretty wise. The only drawback is that it | 504 | Even with older Emacsen the indentation code is pretty wise. The only |
| 398 | relies on Emacs parsing to find matching parentheses. And Emacs | 505 | drawback is that it relied on Emacs parsing to find matching |
| 399 | *cannot* match parentheses in Perl 100% correctly. So | 506 | parentheses. And Emacs *could not* match parentheses in Perl 100% |
| 507 | correctly. So | ||
| 400 | 1 if s#//#/#; | 508 | 1 if s#//#/#; |
| 401 | will not break indentation, but | 509 | would not break indentation, but |
| 402 | 1 if ( s#//#/# ); | 510 | 1 if ( s#//#/# ); |
| 403 | will. | 511 | would. Upgrade. |
| 404 | 512 | ||
| 405 | By similar reasons | 513 | By similar reasons |
| 406 | s\"abc\"def\"; | 514 | s\"abc\"def\"; |
| 407 | will confuse CPerl a lot. | 515 | would confuse CPerl a lot. |
| 408 | 516 | ||
| 409 | If you still get wrong indentation in situation that you think the | 517 | If you still get wrong indentation in situation that you think the |
| 410 | code should be able to parse, try: | 518 | code should be able to parse, try: |
| @@ -412,10 +520,8 @@ code should be able to parse, try: | |||
| 412 | a) Check what Emacs thinks about balance of your parentheses. | 520 | a) Check what Emacs thinks about balance of your parentheses. |
| 413 | b) Supply the code to me (IZ). | 521 | b) Supply the code to me (IZ). |
| 414 | 522 | ||
| 415 | Pods are treated _very_ rudimentally. Here-documents are not treated | 523 | Pods were treated _very_ rudimentally. Here-documents were not |
| 416 | at all (except highlighting and inhibiting indentation). (This may | 524 | treated at all (except highlighting and inhibiting indentation). Upgrade. |
| 417 | change some time. RMS approved making syntax lookup recognize text | ||
| 418 | attributes, but volunteers are needed to change Emacs C code.) | ||
| 419 | 525 | ||
| 420 | To speed up coloring the following compromises exist: | 526 | To speed up coloring the following compromises exist: |
| 421 | a) sub in $mypackage::sub may be highlighted. | 527 | a) sub in $mypackage::sub may be highlighted. |
| @@ -425,7 +531,10 @@ To speed up coloring the following compromises exist: | |||
| 425 | 531 | ||
| 426 | Imenu in 19.31 is broken. Set `imenu-use-keymap-menu' to t, and remove | 532 | Imenu in 19.31 is broken. Set `imenu-use-keymap-menu' to t, and remove |
| 427 | `car' before `imenu-choose-buffer-index' in `imenu'. | 533 | `car' before `imenu-choose-buffer-index' in `imenu'. |
| 428 | ") | 534 | `imenu-add-to-menubar' in 20.2 is broken. |
| 535 | Most things on XEmacs are broken too, judging by bug reports I recieve. | ||
| 536 | Note that some releases of XEmacs are better than the others as far as bugs | ||
| 537 | reports I see are concerned.") | ||
| 429 | 538 | ||
| 430 | (defvar cperl-praise 'please-ignore-this-line | 539 | (defvar cperl-praise 'please-ignore-this-line |
| 431 | "RMS asked me to list good things about CPerl. Here they go: | 540 | "RMS asked me to list good things about CPerl. Here they go: |
| @@ -468,7 +577,7 @@ voice); | |||
| 468 | namespaces in Perl have different colors); | 577 | namespaces in Perl have different colors); |
| 469 | i) Can construct TAGS basing on its knowledge of Perl syntax, | 578 | i) Can construct TAGS basing on its knowledge of Perl syntax, |
| 470 | the standard menu has 6 different way to generate | 579 | the standard menu has 6 different way to generate |
| 471 | TAGS (if by directory, .xs files - with C-language | 580 | TAGS (if \"by directory\", .xs files - with C-language |
| 472 | bindings - are included in the scan); | 581 | bindings - are included in the scan); |
| 473 | j) Can build a hierarchical view of classes (via imenu) basing | 582 | j) Can build a hierarchical view of classes (via imenu) basing |
| 474 | on generated TAGS file; | 583 | on generated TAGS file; |
| @@ -479,20 +588,75 @@ voice); | |||
| 479 | to be not so bothering). Electric parentheses behave | 588 | to be not so bothering). Electric parentheses behave |
| 480 | \"as they should\" in a presence of a visible region. | 589 | \"as they should\" in a presence of a visible region. |
| 481 | l) Changes msb.el \"on the fly\" to insert a group \"Perl files\"; | 590 | l) Changes msb.el \"on the fly\" to insert a group \"Perl files\"; |
| 591 | m) Can convert from | ||
| 592 | if (A) { B } | ||
| 593 | to | ||
| 594 | B if A; | ||
| 482 | 595 | ||
| 483 | 5) The indentation engine was very smart, but most of tricks may be | 596 | 5) The indentation engine was very smart, but most of tricks may be |
| 484 | not needed anymore with the support for `syntax-table' property. Has | 597 | not needed anymore with the support for `syntax-table' property. Has |
| 485 | progress indicator for indentation (with `imenu' loaded). | 598 | progress indicator for indentation (with `imenu' loaded). |
| 486 | 599 | ||
| 487 | 6) Indent-region improves inline-comments as well; | 600 | 6) Indent-region improves inline-comments as well; also corrects |
| 601 | whitespace *inside* the conditional/loop constructs. | ||
| 488 | 602 | ||
| 489 | 7) Fill-paragraph correctly handles multi-line comments; | 603 | 7) Fill-paragraph correctly handles multi-line comments; |
| 604 | |||
| 605 | 8) Can switch to different indentation styles by one command, and restore | ||
| 606 | the settings present before the switch. | ||
| 607 | |||
| 608 | 9) When doing indentation of control constructs, may correct | ||
| 609 | line-breaks/spacing between elements of the construct. | ||
| 610 | ") | ||
| 611 | |||
| 612 | (defvar cperl-speed 'please-ignore-this-line | ||
| 613 | "This is an incomplete compendium of what is available in other parts | ||
| 614 | of CPerl documentation. (Please inform me if I skept anything.) | ||
| 615 | |||
| 616 | There is a perception that CPerl is slower than alternatives. This part | ||
| 617 | of documentation is designed to overcome this misconception. | ||
| 618 | |||
| 619 | *By default* CPerl tries to enable the most comfortable settings. | ||
| 620 | From most points of view, correctly working package is infinitely more | ||
| 621 | comfortable than a non-correctly working one, thus by default CPerl | ||
| 622 | prefers correctness over speed. Below is the guide how to change | ||
| 623 | settings if your preferences are different. | ||
| 624 | |||
| 625 | A) Speed of loading the file. When loading file, CPerl may perform a | ||
| 626 | scan which indicates places which cannot be parsed by primitive Emacs | ||
| 627 | syntax-parsing routines, and marks them up so that either | ||
| 628 | |||
| 629 | A1) CPerl may work around these deficiencies (for big chunks, mostly | ||
| 630 | PODs and HERE-documents), or | ||
| 631 | A2) On capable Emaxen CPerl will use improved syntax-handlings | ||
| 632 | which reads mark-up hints directly. | ||
| 633 | |||
| 634 | The scan in case A2 is much more comprehensive, thus may be slower. | ||
| 635 | |||
| 636 | User can disable syntax-engine-helping scan of A2 by setting | ||
| 637 | `cperl-use-syntax-table-text-property' | ||
| 638 | variable to nil (if it is set to t). | ||
| 639 | |||
| 640 | One can disable the scan altogether (both A1 and A2) by setting | ||
| 641 | `cperl-pod-here-scan' | ||
| 642 | to nil. | ||
| 643 | |||
| 644 | B) Speed of editing operations. | ||
| 645 | |||
| 646 | One can add a (minor) speedup to editing operations by setting | ||
| 647 | `cperl-use-syntax-table-text-property' | ||
| 648 | variable to nil (if it is set to t). This will disable | ||
| 649 | syntax-engine-helping scan, thus will make many more Perl | ||
| 650 | constructs be wrongly recognized by CPerl, thus may lead to | ||
| 651 | wrongly matched parentheses, wrong indentation, etc. | ||
| 490 | ") | 652 | ") |
| 491 | 653 | ||
| 492 | 654 | ||
| 493 | 655 | ||
| 494 | ;;; Portability stuff: | 656 | ;;; Portability stuff: |
| 495 | 657 | ||
| 658 | (defconst cperl-xemacs-p (string-match "XEmacs\\|Lucid" emacs-version)) | ||
| 659 | |||
| 496 | (defmacro cperl-define-key (emacs-key definition &optional xemacs-key) | 660 | (defmacro cperl-define-key (emacs-key definition &optional xemacs-key) |
| 497 | (` (define-key cperl-mode-map | 661 | (` (define-key cperl-mode-map |
| 498 | (, (if xemacs-key | 662 | (, (if xemacs-key |
| @@ -508,13 +672,13 @@ progress indicator for indentation (with `imenu' loaded). | |||
| 508 | (and (vectorp cperl-del-back-ch) (= (length cperl-del-back-ch) 1) | 672 | (and (vectorp cperl-del-back-ch) (= (length cperl-del-back-ch) 1) |
| 509 | (setq cperl-del-back-ch (aref cperl-del-back-ch 0))) | 673 | (setq cperl-del-back-ch (aref cperl-del-back-ch 0))) |
| 510 | 674 | ||
| 675 | (defun cperl-mark-active () (mark)) ; Avoid undefined warning | ||
| 511 | (if cperl-xemacs-p | 676 | (if cperl-xemacs-p |
| 512 | (progn | 677 | (progn |
| 513 | ;; "Active regions" are on: use region only if active | 678 | ;; "Active regions" are on: use region only if active |
| 514 | ;; "Active regions" are off: use region unconditionally | 679 | ;; "Active regions" are off: use region unconditionally |
| 515 | (defun cperl-use-region-p () | 680 | (defun cperl-use-region-p () |
| 516 | (if zmacs-regions (mark) t)) | 681 | (if zmacs-regions (mark) t))) |
| 517 | (defun cperl-mark-active () (mark))) | ||
| 518 | (defun cperl-use-region-p () | 682 | (defun cperl-use-region-p () |
| 519 | (if transient-mark-mode mark-active t)) | 683 | (if transient-mark-mode mark-active t)) |
| 520 | (defun cperl-mark-active () mark-active)) | 684 | (defun cperl-mark-active () mark-active)) |
| @@ -522,14 +686,15 @@ progress indicator for indentation (with `imenu' loaded). | |||
| 522 | (defsubst cperl-enable-font-lock () | 686 | (defsubst cperl-enable-font-lock () |
| 523 | (or cperl-xemacs-p window-system)) | 687 | (or cperl-xemacs-p window-system)) |
| 524 | 688 | ||
| 689 | (defun cperl-putback-char (c) ; Emacs 19 | ||
| 690 | (set 'unread-command-events (list c))) ; Avoid undefined warning | ||
| 691 | |||
| 525 | (if (boundp 'unread-command-events) | 692 | (if (boundp 'unread-command-events) |
| 526 | (if cperl-xemacs-p | 693 | (if cperl-xemacs-p |
| 527 | (defun cperl-putback-char (c) ; XEmacs >= 19.12 | 694 | (defun cperl-putback-char (c) ; XEmacs >= 19.12 |
| 528 | (setq unread-command-events (list (character-to-event c)))) | 695 | (setq unread-command-events (list (eval '(character-to-event c)))))) |
| 529 | (defun cperl-putback-char (c) ; Emacs 19 | ||
| 530 | (setq unread-command-events (list c)))) | ||
| 531 | (defun cperl-putback-char (c) ; XEmacs <= 19.11 | 696 | (defun cperl-putback-char (c) ; XEmacs <= 19.11 |
| 532 | (setq unread-command-event (character-to-event c)))) | 697 | (set 'unread-command-event (eval '(character-to-event c))))) ; Avoid warnings |
| 533 | 698 | ||
| 534 | (or (fboundp 'uncomment-region) | 699 | (or (fboundp 'uncomment-region) |
| 535 | (defun uncomment-region (beg end) | 700 | (defun uncomment-region (beg end) |
| @@ -551,6 +716,15 @@ progress indicator for indentation (with `imenu' loaded). | |||
| 551 | :type 'hook | 716 | :type 'hook |
| 552 | :group 'cperl) | 717 | :group 'cperl) |
| 553 | 718 | ||
| 719 | (defvar cperl-syntax-state nil) | ||
| 720 | (defvar cperl-syntax-done-to nil) | ||
| 721 | |||
| 722 | ;; Make customization possible "in reverse" | ||
| 723 | (defsubst cperl-val (symbol &optional default hairy) | ||
| 724 | (cond | ||
| 725 | ((eq (symbol-value symbol) 'null) default) | ||
| 726 | (cperl-hairy (or hairy t)) | ||
| 727 | (t (symbol-value symbol)))) | ||
| 554 | 728 | ||
| 555 | ;;; Probably it is too late to set these guys already, but it can help later: | 729 | ;;; Probably it is too late to set these guys already, but it can help later: |
| 556 | 730 | ||
| @@ -567,6 +741,18 @@ progress indicator for indentation (with `imenu' loaded). | |||
| 567 | (condition-case nil | 741 | (condition-case nil |
| 568 | (require 'easymenu) | 742 | (require 'easymenu) |
| 569 | (error nil)) | 743 | (error nil)) |
| 744 | (condition-case nil | ||
| 745 | (require 'etags) | ||
| 746 | (error nil)) | ||
| 747 | (condition-case nil | ||
| 748 | (require 'timer) | ||
| 749 | (error nil)) | ||
| 750 | (condition-case nil | ||
| 751 | (require 'man) | ||
| 752 | (error nil)) | ||
| 753 | (condition-case nil | ||
| 754 | (require 'info) | ||
| 755 | (error nil)) | ||
| 570 | ;; Calling `cperl-enable-font-lock' below doesn't compile on XEmacs, | 756 | ;; Calling `cperl-enable-font-lock' below doesn't compile on XEmacs, |
| 571 | ;; macros instead of defsubsts don't work on Emacs, so we do the | 757 | ;; macros instead of defsubsts don't work on Emacs, so we do the |
| 572 | ;; expansion manually. Any other suggestions? | 758 | ;; expansion manually. Any other suggestions? |
| @@ -574,7 +760,24 @@ progress indicator for indentation (with `imenu' loaded). | |||
| 574 | window-system) | 760 | window-system) |
| 575 | (require 'font-lock)) | 761 | (require 'font-lock)) |
| 576 | (require 'cl) | 762 | (require 'cl) |
| 577 | )) | 763 | ;; Avoid warning (tmp definitions) |
| 764 | (or (fboundp 'x-color-defined-p) | ||
| 765 | (defalias 'x-color-defined-p | ||
| 766 | (cond ((fboundp 'color-defined-p) 'color-defined-p) | ||
| 767 | ;; XEmacs >= 19.12 | ||
| 768 | ((fboundp 'valid-color-name-p) 'valid-color-name-p) | ||
| 769 | ;; XEmacs 19.11 | ||
| 770 | (t 'x-valid-color-name-p)))) | ||
| 771 | (fset 'cperl-is-face | ||
| 772 | (cond ((fboundp 'find-face) | ||
| 773 | (symbol-function 'find-face)) | ||
| 774 | ((and (fboundp 'face-list) | ||
| 775 | (face-list)) | ||
| 776 | (function (lambda (face) | ||
| 777 | (member face (and (fboundp 'face-list) | ||
| 778 | (face-list)))))) | ||
| 779 | (t | ||
| 780 | (function (lambda (face) (boundp face)))))))) | ||
| 578 | 781 | ||
| 579 | (defvar cperl-mode-abbrev-table nil | 782 | (defvar cperl-mode-abbrev-table nil |
| 580 | "Abbrev table in use in Cperl-mode buffers.") | 783 | "Abbrev table in use in Cperl-mode buffers.") |
| @@ -596,9 +799,13 @@ progress indicator for indentation (with `imenu' loaded). | |||
| 596 | (cperl-define-key ":" 'cperl-electric-terminator) | 799 | (cperl-define-key ":" 'cperl-electric-terminator) |
| 597 | (cperl-define-key "\C-j" 'newline-and-indent) | 800 | (cperl-define-key "\C-j" 'newline-and-indent) |
| 598 | (cperl-define-key "\C-c\C-j" 'cperl-linefeed) | 801 | (cperl-define-key "\C-c\C-j" 'cperl-linefeed) |
| 802 | (cperl-define-key "\C-c\C-t" 'cperl-invert-if-unless) | ||
| 599 | (cperl-define-key "\C-c\C-a" 'cperl-toggle-auto-newline) | 803 | (cperl-define-key "\C-c\C-a" 'cperl-toggle-auto-newline) |
| 600 | (cperl-define-key "\C-c\C-k" 'cperl-toggle-abbrev) | 804 | (cperl-define-key "\C-c\C-k" 'cperl-toggle-abbrev) |
| 805 | (cperl-define-key "\C-c\C-w" 'cperl-toggle-construct-fix) | ||
| 806 | (cperl-define-key "\C-c\C-f" 'auto-fill-mode) | ||
| 601 | (cperl-define-key "\C-c\C-e" 'cperl-toggle-electric) | 807 | (cperl-define-key "\C-c\C-e" 'cperl-toggle-electric) |
| 808 | (cperl-define-key "\C-c\C-ha" 'cperl-toggle-autohelp) | ||
| 602 | (cperl-define-key "\e\C-q" 'cperl-indent-exp) ; Usually not bound | 809 | (cperl-define-key "\e\C-q" 'cperl-indent-exp) ; Usually not bound |
| 603 | (cperl-define-key [?\C-\M-\|] 'cperl-lineup | 810 | (cperl-define-key [?\C-\M-\|] 'cperl-lineup |
| 604 | [(control meta |)]) | 811 | [(control meta |)]) |
| @@ -609,14 +816,22 @@ progress indicator for indentation (with `imenu' loaded). | |||
| 609 | ;; don't clobber the backspace binding: | 816 | ;; don't clobber the backspace binding: |
| 610 | (cperl-define-key "\C-c\C-hf" 'cperl-info-on-current-command | 817 | (cperl-define-key "\C-c\C-hf" 'cperl-info-on-current-command |
| 611 | [(control c) (control h) f]) | 818 | [(control c) (control h) f]) |
| 612 | (cperl-define-key "\C-hf" | 819 | (cperl-define-key "\C-c\C-hF" 'cperl-info-on-command |
| 613 | ;;(concat (char-to-string help-char) "f") ; does not work | 820 | [(control c) (control h) F]) |
| 614 | 'cperl-info-on-command | 821 | (cperl-define-key "\C-c\C-hv" |
| 615 | [(control h) f]) | ||
| 616 | (cperl-define-key "\C-hv" | ||
| 617 | ;;(concat (char-to-string help-char) "v") ; does not work | 822 | ;;(concat (char-to-string help-char) "v") ; does not work |
| 618 | 'cperl-get-help | 823 | 'cperl-get-help |
| 619 | [(control h) v]) | 824 | [(control c) (control h) v]) |
| 825 | (if (cperl-val 'cperl-clobber-lisp-bindings) | ||
| 826 | (progn | ||
| 827 | (cperl-define-key "\C-hf" | ||
| 828 | ;;(concat (char-to-string help-char) "f") ; does not work | ||
| 829 | 'cperl-info-on-command | ||
| 830 | [(control h) f]) | ||
| 831 | (cperl-define-key "\C-hv" | ||
| 832 | ;;(concat (char-to-string help-char) "v") ; does not work | ||
| 833 | 'cperl-get-help | ||
| 834 | [(control h) v]))) | ||
| 620 | (if (and cperl-xemacs-p | 835 | (if (and cperl-xemacs-p |
| 621 | (<= emacs-minor-version 11) (<= emacs-major-version 19)) | 836 | (<= emacs-minor-version 11) (<= emacs-major-version 19)) |
| 622 | (progn | 837 | (progn |
| @@ -638,6 +853,8 @@ progress indicator for indentation (with `imenu' loaded). | |||
| 638 | cperl-mode-map global-map))) | 853 | cperl-mode-map global-map))) |
| 639 | 854 | ||
| 640 | (defvar cperl-menu) | 855 | (defvar cperl-menu) |
| 856 | (defvar cperl-lazy-installed) | ||
| 857 | (defvar cperl-old-style nil) | ||
| 641 | (condition-case nil | 858 | (condition-case nil |
| 642 | (progn | 859 | (progn |
| 643 | (require 'easymenu) | 860 | (require 'easymenu) |
| @@ -650,12 +867,16 @@ progress indicator for indentation (with `imenu' loaded). | |||
| 650 | ["Fill paragraph/comment" cperl-fill-paragraph t] | 867 | ["Fill paragraph/comment" cperl-fill-paragraph t] |
| 651 | "----" | 868 | "----" |
| 652 | ["Line up a construction" cperl-lineup (cperl-use-region-p)] | 869 | ["Line up a construction" cperl-lineup (cperl-use-region-p)] |
| 653 | ["Beautify a regexp" cperl-beautify-regexp | 870 | ["Invert if/unless/while/until" cperl-invert-if-unless t] |
| 654 | cperl-use-syntax-table-text-property] | 871 | ("Regexp" |
| 655 | ["Beautify a group in regexp" cperl-beautify-level | 872 | ["Beautify" cperl-beautify-regexp |
| 656 | cperl-use-syntax-table-text-property] | 873 | cperl-use-syntax-table-text-property] |
| 657 | ["Contract a group in regexp" cperl-contract-level | 874 | ["Beautify a group" cperl-beautify-level |
| 658 | cperl-use-syntax-table-text-property] | 875 | cperl-use-syntax-table-text-property] |
| 876 | ["Contract a group" cperl-contract-level | ||
| 877 | cperl-use-syntax-table-text-property] | ||
| 878 | ["Contract groups" cperl-contract-levels | ||
| 879 | cperl-use-syntax-table-text-property]) | ||
| 659 | ["Refresh \"hard\" constructions" cperl-find-pods-heres t] | 880 | ["Refresh \"hard\" constructions" cperl-find-pods-heres t] |
| 660 | "----" | 881 | "----" |
| 661 | ["Indent region" cperl-indent-region (cperl-use-region-p)] | 882 | ["Indent region" cperl-indent-region (cperl-use-region-p)] |
| @@ -695,31 +916,45 @@ progress indicator for indentation (with `imenu' loaded). | |||
| 695 | ["Create tags for Perl files in (sub)directories" | 916 | ["Create tags for Perl files in (sub)directories" |
| 696 | (cperl-write-tags nil t t t) t] | 917 | (cperl-write-tags nil t t t) t] |
| 697 | ["Add tags for Perl files in (sub)directories" | 918 | ["Add tags for Perl files in (sub)directories" |
| 698 | (cperl-write-tags nil nil t t) t]) | 919 | (cperl-write-tags nil nil t t) t])) |
| 920 | ("Perl docs" | ||
| 699 | ["Define word at point" imenu-go-find-at-position | 921 | ["Define word at point" imenu-go-find-at-position |
| 700 | (fboundp 'imenu-go-find-at-position)] | 922 | (fboundp 'imenu-go-find-at-position)] |
| 701 | ["Help on function" cperl-info-on-command t] | 923 | ["Help on function" cperl-info-on-command t] |
| 702 | ["Help on function at point" cperl-info-on-current-command t] | 924 | ["Help on function at point" cperl-info-on-current-command t] |
| 703 | ["Help on symbol at point" cperl-get-help t] | 925 | ["Help on symbol at point" cperl-get-help t] |
| 704 | ["Auto-help on" cperl-lazy-install (fboundp 'run-with-idle-timer)] | 926 | ["Perldoc" cperl-perldoc t] |
| 705 | ["Auto-help off" cperl-lazy-unstall | 927 | ["Perldoc on word at point" cperl-perldoc-at-point t] |
| 706 | (fboundp 'run-with-idle-timer)]) | 928 | ["View manpage of POD in this file" cperl-pod-to-manpage t] |
| 929 | ["Auto-help on" cperl-lazy-install | ||
| 930 | (and (fboundp 'run-with-idle-timer) | ||
| 931 | (not cperl-lazy-installed))] | ||
| 932 | ["Auto-help off" (eval '(cperl-lazy-unstall)) | ||
| 933 | (and (fboundp 'run-with-idle-timer) | ||
| 934 | cperl-lazy-installed)]) | ||
| 707 | ("Toggle..." | 935 | ("Toggle..." |
| 708 | ["Auto newline" cperl-toggle-auto-newline t] | 936 | ["Auto newline" cperl-toggle-auto-newline t] |
| 709 | ["Electric parens" cperl-toggle-electric t] | 937 | ["Electric parens" cperl-toggle-electric t] |
| 710 | ["Electric keywords" cperl-toggle-abbrev t] | 938 | ["Electric keywords" cperl-toggle-abbrev t] |
| 711 | ) | 939 | ["Fix whitespace on indent" cperl-toggle-construct-fix t] |
| 940 | ["Auto fill" auto-fill-mode t]) | ||
| 712 | ("Indent styles..." | 941 | ("Indent styles..." |
| 942 | ["CPerl" (cperl-set-style "CPerl") t] | ||
| 943 | ["PerlStyle" (cperl-set-style "PerlStyle") t] | ||
| 713 | ["GNU" (cperl-set-style "GNU") t] | 944 | ["GNU" (cperl-set-style "GNU") t] |
| 714 | ["C++" (cperl-set-style "C++") t] | 945 | ["C++" (cperl-set-style "C++") t] |
| 715 | ["FSF" (cperl-set-style "FSF") t] | 946 | ["FSF" (cperl-set-style "FSF") t] |
| 716 | ["BSD" (cperl-set-style "BSD") t] | 947 | ["BSD" (cperl-set-style "BSD") t] |
| 717 | ["Whitesmith" (cperl-set-style "Whitesmith") t]) | 948 | ["Whitesmith" (cperl-set-style "Whitesmith") t] |
| 949 | ["Current" (cperl-set-style "Current") t] | ||
| 950 | ["Memorized" (cperl-set-style-back) cperl-old-style]) | ||
| 718 | ("Micro-docs" | 951 | ("Micro-docs" |
| 719 | ["Tips" (describe-variable 'cperl-tips) t] | 952 | ["Tips" (describe-variable 'cperl-tips) t] |
| 720 | ["Problems" (describe-variable 'cperl-problems) t] | 953 | ["Problems" (describe-variable 'cperl-problems) t] |
| 721 | ["Non-problems" (describe-variable 'cperl-non-problems) t] | 954 | ["Non-problems" (describe-variable 'cperl-non-problems) t] |
| 722 | ["Praise" (describe-variable 'cperl-praise) t])))) | 955 | ["Speed" (describe-variable 'cperl-speed) t] |
| 956 | ["Praise" (describe-variable 'cperl-praise) t] | ||
| 957 | ["CPerl mode" (describe-function 'cperl-mode) t])))) | ||
| 723 | (error nil)) | 958 | (error nil)) |
| 724 | 959 | ||
| 725 | (autoload 'c-macro-expand "cmacexp" | 960 | (autoload 'c-macro-expand "cmacexp" |
| @@ -762,22 +997,13 @@ The expansion is entirely correct because it uses the C preprocessor." | |||
| 762 | 997 | ||
| 763 | 998 | ||
| 764 | 999 | ||
| 765 | ;; Make customization possible "in reverse" | 1000 | (defvar cperl-faces-init nil) |
| 766 | ;;(defun cperl-set (symbol to) | ||
| 767 | ;; (or (eq (symbol-value symbol) 'null) (set symbol to))) | ||
| 768 | (defsubst cperl-val (symbol &optional default hairy) | ||
| 769 | (cond | ||
| 770 | ((eq (symbol-value symbol) 'null) default) | ||
| 771 | (cperl-hairy (or hairy t)) | ||
| 772 | (t (symbol-value symbol)))) | ||
| 773 | |||
| 774 | ;; provide an alias for working with emacs 19. the perl-mode that comes | ||
| 775 | ;; with it is really bad, and this lets us seamlessly replace it. | ||
| 776 | ;;;###autoload | ||
| 777 | (fset 'perl-mode 'cperl-mode) | ||
| 778 | (defvar cperl-faces-init) | ||
| 779 | ;; Fix for msb.el | 1001 | ;; Fix for msb.el |
| 780 | (defvar cperl-msb-fixed nil) | 1002 | (defvar cperl-msb-fixed nil) |
| 1003 | (defvar font-lock-syntactic-keywords) | ||
| 1004 | (defvar perl-font-lock-keywords) | ||
| 1005 | (defvar perl-font-lock-keywords-1) | ||
| 1006 | (defvar perl-font-lock-keywords-2) | ||
| 781 | ;;;###autoload | 1007 | ;;;###autoload |
| 782 | (defun cperl-mode () | 1008 | (defun cperl-mode () |
| 783 | "Major mode for editing Perl code. | 1009 | "Major mode for editing Perl code. |
| @@ -800,65 +1026,83 @@ You may also set `cperl-electric-parens-mark' to have electric parens | |||
| 800 | look for active mark and \"embrace\" a region if possible.' | 1026 | look for active mark and \"embrace\" a region if possible.' |
| 801 | 1027 | ||
| 802 | CPerl mode provides expansion of the Perl control constructs: | 1028 | CPerl mode provides expansion of the Perl control constructs: |
| 803 | if, else, elsif, unless, while, until, for, and foreach. | 1029 | |
| 804 | =========(Disabled by default, see `cperl-electric-keywords'.) | 1030 | if, else, elsif, unless, while, until, continue, do, |
| 805 | The user types the keyword immediately followed by a space, which causes | 1031 | for, foreach, formy and foreachmy. |
| 806 | the construct to be expanded, and the user is positioned where she is most | 1032 | |
| 807 | likely to want to be. | 1033 | and POD directives (Disabled by default, see `cperl-electric-keywords'.) |
| 808 | eg. when the user types a space following \"if\" the following appears in | 1034 | |
| 809 | the buffer: | 1035 | The user types the keyword immediately followed by a space, which |
| 810 | if () { or if () | 1036 | causes the construct to be expanded, and the point is positioned where |
| 811 | } { | 1037 | she is most likely to want to be. eg. when the user types a space |
| 812 | } | 1038 | following \"if\" the following appears in the buffer: if () { or if () |
| 813 | and the cursor is between the parentheses. The user can then type some | 1039 | } { } and the cursor is between the parentheses. The user can then |
| 814 | boolean expression within the parens. Having done that, typing | 1040 | type some boolean expression within the parens. Having done that, |
| 815 | \\[cperl-linefeed] places you, appropriately indented on a new line | 1041 | typing \\[cperl-linefeed] places you - appropriately indented - on a |
| 816 | between the braces. If CPerl decides that you want to insert | 1042 | new line between the braces (if you typed \\[cperl-linefeed] in a POD |
| 817 | \"English\" style construct like | 1043 | directive line, then appropriate number of new lines is inserted). |
| 1044 | |||
| 1045 | If CPerl decides that you want to insert \"English\" style construct like | ||
| 1046 | |||
| 818 | bite if angry; | 1047 | bite if angry; |
| 819 | it will not do any expansion. See also help on variable | 1048 | |
| 820 | `cperl-extra-newline-before-brace'. | 1049 | it will not do any expansion. See also help on variable |
| 1050 | `cperl-extra-newline-before-brace'. (Note that one can switch the | ||
| 1051 | help message on expansion by setting `cperl-message-electric-keyword' | ||
| 1052 | to nil.) | ||
| 821 | 1053 | ||
| 822 | \\[cperl-linefeed] is a convenience replacement for typing carriage | 1054 | \\[cperl-linefeed] is a convenience replacement for typing carriage |
| 823 | return. It places you in the next line with proper indentation, or if | 1055 | return. It places you in the next line with proper indentation, or if |
| 824 | you type it inside the inline block of control construct, like | 1056 | you type it inside the inline block of control construct, like |
| 1057 | |||
| 825 | foreach (@lines) {print; print} | 1058 | foreach (@lines) {print; print} |
| 1059 | |||
| 826 | and you are on a boundary of a statement inside braces, it will | 1060 | and you are on a boundary of a statement inside braces, it will |
| 827 | transform the construct into a multiline and will place you into an | 1061 | transform the construct into a multiline and will place you into an |
| 828 | appropriately indented blank line. If you need a usual | 1062 | appropriately indented blank line. If you need a usual |
| 829 | `newline-and-indent' behaviour, it is on \\[newline-and-indent], | 1063 | `newline-and-indent' behaviour, it is on \\[newline-and-indent], |
| 830 | see documentation on `cperl-electric-linefeed'. | 1064 | see documentation on `cperl-electric-linefeed'. |
| 831 | 1065 | ||
| 1066 | Use \\[cperl-invert-if-unless] to change a construction of the form | ||
| 1067 | |||
| 1068 | if (A) { B } | ||
| 1069 | |||
| 1070 | into | ||
| 1071 | |||
| 1072 | B if A; | ||
| 1073 | |||
| 832 | \\{cperl-mode-map} | 1074 | \\{cperl-mode-map} |
| 833 | 1075 | ||
| 834 | Setting the variable `cperl-font-lock' to t switches on | 1076 | Setting the variable `cperl-font-lock' to t switches on font-lock-mode |
| 835 | font-lock-mode, `cperl-electric-lbrace-space' to t switches on | 1077 | \(even with older Emacsen), `cperl-electric-lbrace-space' to t switches |
| 836 | electric space between $ and {, `cperl-electric-parens-string' is the | 1078 | on electric space between $ and {, `cperl-electric-parens-string' is |
| 837 | string that contains parentheses that should be electric in CPerl (see | 1079 | the string that contains parentheses that should be electric in CPerl |
| 838 | also `cperl-electric-parens-mark' and `cperl-electric-parens'), | 1080 | \(see also `cperl-electric-parens-mark' and `cperl-electric-parens'), |
| 839 | setting `cperl-electric-keywords' enables electric expansion of | 1081 | setting `cperl-electric-keywords' enables electric expansion of |
| 840 | control structures in CPerl. `cperl-electric-linefeed' governs which | 1082 | control structures in CPerl. `cperl-electric-linefeed' governs which |
| 841 | one of two linefeed behavior is preferable. You can enable all these | 1083 | one of two linefeed behavior is preferable. You can enable all these |
| 842 | options simultaneously (recommended mode of use) by setting | 1084 | options simultaneously (recommended mode of use) by setting |
| 843 | `cperl-hairy' to t. In this case you can switch separate options off | 1085 | `cperl-hairy' to t. In this case you can switch separate options off |
| 844 | by setting them to `null'. Note that one may undo the extra whitespace | 1086 | by setting them to `null'. Note that one may undo the extra |
| 845 | inserted by semis and braces in `auto-newline'-mode by consequent | 1087 | whitespace inserted by semis and braces in `auto-newline'-mode by |
| 846 | \\[cperl-electric-backspace]. | 1088 | consequent \\[cperl-electric-backspace]. |
| 847 | 1089 | ||
| 848 | If your site has perl5 documentation in info format, you can use commands | 1090 | If your site has perl5 documentation in info format, you can use commands |
| 849 | \\[cperl-info-on-current-command] and \\[cperl-info-on-command] to access it. | 1091 | \\[cperl-info-on-current-command] and \\[cperl-info-on-command] to access it. |
| 850 | These keys run commands `cperl-info-on-current-command' and | 1092 | These keys run commands `cperl-info-on-current-command' and |
| 851 | `cperl-info-on-command', which one is which is controlled by variable | 1093 | `cperl-info-on-command', which one is which is controlled by variable |
| 852 | `cperl-info-on-command-no-prompt' (in turn affected by `cperl-hairy'). | 1094 | `cperl-info-on-command-no-prompt' and `cperl-clobber-lisp-bindings' |
| 1095 | \(in turn affected by `cperl-hairy'). | ||
| 853 | 1096 | ||
| 854 | Even if you have no info-format documentation, short one-liner-style | 1097 | Even if you have no info-format documentation, short one-liner-style |
| 855 | help is available on \\[cperl-get-help]. | 1098 | help is available on \\[cperl-get-help], and one can run perldoc or |
| 1099 | man via menu. | ||
| 856 | 1100 | ||
| 857 | It is possible to show this help automatically after some idle | 1101 | It is possible to show this help automatically after some idle time. |
| 858 | time. This is regulated by variable `cperl-lazy-help-time'. Default | 1102 | This is regulated by variable `cperl-lazy-help-time'. Default with |
| 859 | with `cperl-hairy' is 5 secs idle time if the value of this variable | 1103 | `cperl-hairy' (if the value of `cperl-lazy-help-time' is nil) is 5 |
| 860 | is nil. It is also possible to switch this on/off from the | 1104 | secs idle time . It is also possible to switch this on/off from the |
| 861 | menu. Requires `run-with-idle-timer'. | 1105 | menu, or via \\[cperl-toggle-autohelp]. Requires `run-with-idle-timer'. |
| 862 | 1106 | ||
| 863 | Use \\[cperl-lineup] to vertically lineup some construction - put the | 1107 | Use \\[cperl-lineup] to vertically lineup some construction - put the |
| 864 | beginning of the region at the start of construction, and make region | 1108 | beginning of the region at the start of construction, and make region |
| @@ -866,13 +1110,15 @@ span the needed amount of lines. | |||
| 866 | 1110 | ||
| 867 | Variables `cperl-pod-here-scan', `cperl-pod-here-fontify', | 1111 | Variables `cperl-pod-here-scan', `cperl-pod-here-fontify', |
| 868 | `cperl-pod-face', `cperl-pod-head-face' control processing of pod and | 1112 | `cperl-pod-face', `cperl-pod-head-face' control processing of pod and |
| 869 | here-docs sections. In a future version results of scan may be used | 1113 | here-docs sections. With capable Emaxen results of scan are used |
| 870 | for indentation too, currently they are used for highlighting only. | 1114 | for indentation too, otherwise they are used for highlighting only. |
| 871 | 1115 | ||
| 872 | Variables controlling indentation style: | 1116 | Variables controlling indentation style: |
| 873 | `cperl-tab-always-indent' | 1117 | `cperl-tab-always-indent' |
| 874 | Non-nil means TAB in CPerl mode should always reindent the current line, | 1118 | Non-nil means TAB in CPerl mode should always reindent the current line, |
| 875 | regardless of where in the line point is when the TAB command is used. | 1119 | regardless of where in the line point is when the TAB command is used. |
| 1120 | `cperl-indent-left-aligned-comments' | ||
| 1121 | Non-nil means that the comment starting in leftmost column should indent. | ||
| 876 | `cperl-auto-newline' | 1122 | `cperl-auto-newline' |
| 877 | Non-nil means automatically newline before and after braces, | 1123 | Non-nil means automatically newline before and after braces, |
| 878 | and after colons and semicolons, inserted in Perl code. The following | 1124 | and after colons and semicolons, inserted in Perl code. The following |
| @@ -908,25 +1154,31 @@ Settings for K&R and BSD indentation styles are | |||
| 908 | `cperl-brace-offset' -5 -8 | 1154 | `cperl-brace-offset' -5 -8 |
| 909 | `cperl-label-offset' -5 -8 | 1155 | `cperl-label-offset' -5 -8 |
| 910 | 1156 | ||
| 911 | If `cperl-indent-level' is 0, the statement after opening brace in column 0 is indented on `cperl-brace-offset'+`cperl-continued-statement-offset'. | 1157 | CPerl knows several indentation styles, and may bulk set the |
| 1158 | corresponding variables. Use \\[cperl-set-style] to do this. Use | ||
| 1159 | \\[cperl-set-style-back] to restore the memorized preexisting values | ||
| 1160 | \(both available from menu). | ||
| 1161 | |||
| 1162 | If `cperl-indent-level' is 0, the statement after opening brace in | ||
| 1163 | column 0 is indented on | ||
| 1164 | `cperl-brace-offset'+`cperl-continued-statement-offset'. | ||
| 912 | 1165 | ||
| 913 | Turning on CPerl mode calls the hooks in the variable `cperl-mode-hook' | 1166 | Turning on CPerl mode calls the hooks in the variable `cperl-mode-hook' |
| 914 | with no args." | 1167 | with no args. |
| 1168 | |||
| 1169 | DO NOT FORGET to read micro-docs (available from `Perl' menu) | ||
| 1170 | or as help on variables `cperl-tips', `cperl-problems', | ||
| 1171 | `cperl-non-problems', `cperl-praise', `cperl-speed'." | ||
| 915 | (interactive) | 1172 | (interactive) |
| 916 | (kill-all-local-variables) | 1173 | (kill-all-local-variables) |
| 917 | ;;(if cperl-hairy | ||
| 918 | ;; (progn | ||
| 919 | ;; (cperl-set 'cperl-font-lock cperl-hairy) | ||
| 920 | ;; (cperl-set 'cperl-electric-lbrace-space cperl-hairy) | ||
| 921 | ;; (cperl-set 'cperl-electric-parens "{[(<") | ||
| 922 | ;; (cperl-set 'cperl-electric-keywords cperl-hairy) | ||
| 923 | ;; (cperl-set 'cperl-electric-linefeed cperl-hairy))) | ||
| 924 | (use-local-map cperl-mode-map) | 1174 | (use-local-map cperl-mode-map) |
| 925 | (if (cperl-val 'cperl-electric-linefeed) | 1175 | (if (cperl-val 'cperl-electric-linefeed) |
| 926 | (progn | 1176 | (progn |
| 927 | (local-set-key "\C-J" 'cperl-linefeed) | 1177 | (local-set-key "\C-J" 'cperl-linefeed) |
| 928 | (local-set-key "\C-C\C-J" 'newline-and-indent))) | 1178 | (local-set-key "\C-C\C-J" 'newline-and-indent))) |
| 929 | (if (cperl-val 'cperl-info-on-command-no-prompt) | 1179 | (if (and |
| 1180 | (cperl-val 'cperl-clobber-lisp-bindings) | ||
| 1181 | (cperl-val 'cperl-info-on-command-no-prompt)) | ||
| 930 | (progn | 1182 | (progn |
| 931 | ;; don't clobber the backspace binding: | 1183 | ;; don't clobber the backspace binding: |
| 932 | (cperl-define-key "\C-hf" 'cperl-info-on-current-command [(control h) f]) | 1184 | (cperl-define-key "\C-hf" 'cperl-info-on-current-command [(control h) f]) |
| @@ -943,9 +1195,16 @@ with no args." | |||
| 943 | ("until" "until" cperl-electric-keyword 0) | 1195 | ("until" "until" cperl-electric-keyword 0) |
| 944 | ("unless" "unless" cperl-electric-keyword 0) | 1196 | ("unless" "unless" cperl-electric-keyword 0) |
| 945 | ("else" "else" cperl-electric-else 0) | 1197 | ("else" "else" cperl-electric-else 0) |
| 1198 | ("continue" "continue" cperl-electric-else 0) | ||
| 946 | ("for" "for" cperl-electric-keyword 0) | 1199 | ("for" "for" cperl-electric-keyword 0) |
| 947 | ("foreach" "foreach" cperl-electric-keyword 0) | 1200 | ("foreach" "foreach" cperl-electric-keyword 0) |
| 948 | ("do" "do" cperl-electric-keyword 0))) | 1201 | ("formy" "formy" cperl-electric-keyword 0) |
| 1202 | ("foreachmy" "foreachmy" cperl-electric-keyword 0) | ||
| 1203 | ("do" "do" cperl-electric-keyword 0) | ||
| 1204 | ("pod" "pod" cperl-electric-pod 0) | ||
| 1205 | ("over" "over" cperl-electric-pod 0) | ||
| 1206 | ("head1" "head1" cperl-electric-pod 0) | ||
| 1207 | ("head2" "head2" cperl-electric-pod 0))) | ||
| 949 | (setq abbrevs-changed prev-a-c))) | 1208 | (setq abbrevs-changed prev-a-c))) |
| 950 | (setq local-abbrev-table cperl-mode-abbrev-table) | 1209 | (setq local-abbrev-table cperl-mode-abbrev-table) |
| 951 | (abbrev-mode (if (cperl-val 'cperl-electric-keywords) 1 0)) | 1210 | (abbrev-mode (if (cperl-val 'cperl-electric-keywords) 1 0)) |
| @@ -983,25 +1242,50 @@ with no args." | |||
| 983 | (make-local-variable 'imenu-sort-function) | 1242 | (make-local-variable 'imenu-sort-function) |
| 984 | (setq imenu-sort-function nil) | 1243 | (setq imenu-sort-function nil) |
| 985 | (make-local-variable 'vc-header-alist) | 1244 | (make-local-variable 'vc-header-alist) |
| 986 | (setq vc-header-alist cperl-vc-header-alist) | 1245 | (set 'vc-header-alist cperl-vc-header-alist) ; Avoid warning |
| 987 | (make-local-variable 'font-lock-defaults) | 1246 | (make-local-variable 'font-lock-defaults) |
| 988 | (setq font-lock-defaults | 1247 | (setq font-lock-defaults |
| 989 | (if (string< emacs-version "19.30") | 1248 | (cond |
| 990 | '(perl-font-lock-keywords-2) | 1249 | ((string< emacs-version "19.30") |
| 1250 | '(perl-font-lock-keywords-2)) | ||
| 1251 | ((string< emacs-version "19.33") ; Which one to use? | ||
| 991 | '((perl-font-lock-keywords | 1252 | '((perl-font-lock-keywords |
| 992 | perl-font-lock-keywords-1 | 1253 | perl-font-lock-keywords-1 |
| 993 | perl-font-lock-keywords-2)))) | 1254 | perl-font-lock-keywords-2))) |
| 1255 | (t | ||
| 1256 | '((cperl-load-font-lock-keywords | ||
| 1257 | cperl-load-font-lock-keywords-1 | ||
| 1258 | cperl-load-font-lock-keywords-2))))) | ||
| 1259 | (make-local-variable 'cperl-syntax-state) | ||
| 994 | (if cperl-use-syntax-table-text-property | 1260 | (if cperl-use-syntax-table-text-property |
| 995 | (progn | 1261 | (progn |
| 996 | (make-variable-buffer-local 'parse-sexp-lookup-properties) | 1262 | (make-variable-buffer-local 'parse-sexp-lookup-properties) |
| 997 | ;; Do not introduce variable if not needed, we check it! | 1263 | ;; Do not introduce variable if not needed, we check it! |
| 998 | (set 'parse-sexp-lookup-properties t))) | 1264 | (set 'parse-sexp-lookup-properties t) |
| 1265 | ;; Fix broken font-lock: | ||
| 1266 | (or (boundp 'font-lock-unfontify-region-function) | ||
| 1267 | (set 'font-lock-unfontify-region-function | ||
| 1268 | 'font-lock-default-unfontify-buffer)) | ||
| 1269 | (make-variable-buffer-local 'font-lock-unfontify-region-function) | ||
| 1270 | (set 'font-lock-unfontify-region-function | ||
| 1271 | 'cperl-font-lock-unfontify-region-function) | ||
| 1272 | (make-variable-buffer-local 'cperl-syntax-done-to) | ||
| 1273 | ;; Another bug: unless font-lock-syntactic-keywords, font-lock | ||
| 1274 | ;; ignores syntax-table text-property. (t) is a hack | ||
| 1275 | ;; to make font-lock think that font-lock-syntactic-keywords | ||
| 1276 | ;; are defined | ||
| 1277 | (make-variable-buffer-local 'font-lock-syntactic-keywords) | ||
| 1278 | (setq font-lock-syntactic-keywords | ||
| 1279 | (if cperl-syntaxify-by-font-lock | ||
| 1280 | '(t (cperl-fontify-syntaxically)) | ||
| 1281 | '(t))))) | ||
| 1282 | (make-local-variable 'cperl-old-style) | ||
| 999 | (or (fboundp 'cperl-old-auto-fill-mode) | 1283 | (or (fboundp 'cperl-old-auto-fill-mode) |
| 1000 | (progn | 1284 | (progn |
| 1001 | (fset 'cperl-old-auto-fill-mode (symbol-function 'auto-fill-mode)) | 1285 | (fset 'cperl-old-auto-fill-mode (symbol-function 'auto-fill-mode)) |
| 1002 | (defun auto-fill-mode (&optional arg) | 1286 | (defun auto-fill-mode (&optional arg) |
| 1003 | (interactive "P") | 1287 | (interactive "P") |
| 1004 | (cperl-old-auto-fill-mode arg) | 1288 | (eval '(cperl-old-auto-fill-mode arg)) ; Avoid a warning |
| 1005 | (and auto-fill-function (eq major-mode 'perl-mode) | 1289 | (and auto-fill-function (eq major-mode 'perl-mode) |
| 1006 | (setq auto-fill-function 'cperl-do-auto-fill))))) | 1290 | (setq auto-fill-function 'cperl-do-auto-fill))))) |
| 1007 | (if (cperl-enable-font-lock) | 1291 | (if (cperl-enable-font-lock) |
| @@ -1012,12 +1296,17 @@ with no args." | |||
| 1012 | (not cperl-msb-fixed) | 1296 | (not cperl-msb-fixed) |
| 1013 | (cperl-msb-fix)) | 1297 | (cperl-msb-fix)) |
| 1014 | (if (featurep 'easymenu) | 1298 | (if (featurep 'easymenu) |
| 1015 | (easy-menu-add cperl-menu)) ; A NOP in Emacs. | 1299 | (easy-menu-add cperl-menu)) ; A NOP in RMS Emacs. |
| 1016 | (run-hooks 'cperl-mode-hook) | 1300 | (run-hooks 'cperl-mode-hook) |
| 1017 | ;; After hooks since fontification will break this | 1301 | ;; After hooks since fontification will break this |
| 1018 | (if cperl-pod-here-scan (cperl-find-pods-heres))) | 1302 | (if cperl-pod-here-scan |
| 1303 | (or (and (boundp 'font-lock-mode) | ||
| 1304 | (eval 'font-lock-mode) ; Avoid warning | ||
| 1305 | (boundp 'font-lock-hot-pass)) ; Newer font-lock | ||
| 1306 | (cperl-find-pods-heres)))) | ||
| 1019 | 1307 | ||
| 1020 | ;; Fix for perldb - make default reasonable | 1308 | ;; Fix for perldb - make default reasonable |
| 1309 | (defvar gud-perldb-history) | ||
| 1021 | (defun cperl-db () | 1310 | (defun cperl-db () |
| 1022 | (interactive) | 1311 | (interactive) |
| 1023 | (require 'gud) | 1312 | (require 'gud) |
| @@ -1032,7 +1321,7 @@ with no args." | |||
| 1032 | nil nil | 1321 | nil nil |
| 1033 | '(gud-perldb-history . 1)))) | 1322 | '(gud-perldb-history . 1)))) |
| 1034 | 1323 | ||
| 1035 | 1324 | (defvar msb-menu-cond) | |
| 1036 | (defun cperl-msb-fix () | 1325 | (defun cperl-msb-fix () |
| 1037 | ;; Adds perl files to msb menu, supposes that msb is already loaded | 1326 | ;; Adds perl files to msb menu, supposes that msb is already loaded |
| 1038 | (setq cperl-msb-fixed t) | 1327 | (setq cperl-msb-fixed t) |
| @@ -1140,41 +1429,52 @@ char is \"{\", insert extra newline before only if | |||
| 1140 | (setq last-command-char ?\{) | 1429 | (setq last-command-char ?\{) |
| 1141 | (cperl-electric-lbrace arg insertpos)) | 1430 | (cperl-electric-lbrace arg insertpos)) |
| 1142 | (forward-char 1)) | 1431 | (forward-char 1)) |
| 1143 | (if (and (not arg) ; No args, end (of empty line or auto) | 1432 | ;: Check whether we close something "usual" with `}' |
| 1144 | (eolp) | 1433 | (if (and (eq last-command-char ?\}) |
| 1145 | (or (and (null only-before) | 1434 | (not |
| 1146 | (save-excursion | 1435 | (condition-case nil |
| 1147 | (skip-chars-backward " \t") | 1436 | (save-excursion |
| 1148 | (bolp))) | 1437 | (up-list (- (prefix-numeric-value arg))) |
| 1149 | (and (eq last-command-char ?\{) ; Do not insert newline | 1438 | ;;(cperl-after-block-p (point-min)) |
| 1150 | ;; if after ")" and `cperl-extra-newline-before-brace' | 1439 | (cperl-after-expr-p nil "{;)")) |
| 1151 | ;; is nil, do not insert extra newline. | 1440 | (error nil)))) |
| 1152 | (not cperl-extra-newline-before-brace) | 1441 | ;; Just insert the guy |
| 1153 | (save-excursion | 1442 | (self-insert-command (prefix-numeric-value arg)) |
| 1154 | (skip-chars-backward " \t") | 1443 | (if (and (not arg) ; No args, end (of empty line or auto) |
| 1155 | (eq (preceding-char) ?\)))) | 1444 | (eolp) |
| 1156 | (if cperl-auto-newline | 1445 | (or (and (null only-before) |
| 1157 | (progn (cperl-indent-line) (newline) t) nil))) | 1446 | (save-excursion |
| 1158 | (progn | 1447 | (skip-chars-backward " \t") |
| 1159 | (self-insert-command (prefix-numeric-value arg)) | 1448 | (bolp))) |
| 1160 | (cperl-indent-line) | 1449 | (and (eq last-command-char ?\{) ; Do not insert newline |
| 1161 | (if cperl-auto-newline | 1450 | ;; if after ")" and `cperl-extra-newline-before-brace' |
| 1162 | (setq insertpos (1- (point)))) | 1451 | ;; is nil, do not insert extra newline. |
| 1163 | (if (and cperl-auto-newline (null only-before)) | 1452 | (not cperl-extra-newline-before-brace) |
| 1164 | (progn | 1453 | (save-excursion |
| 1165 | (newline) | 1454 | (skip-chars-backward " \t") |
| 1166 | (cperl-indent-line))) | 1455 | (eq (preceding-char) ?\)))) |
| 1456 | (if cperl-auto-newline | ||
| 1457 | (progn (cperl-indent-line) (newline) t) nil))) | ||
| 1458 | (progn | ||
| 1459 | (self-insert-command (prefix-numeric-value arg)) | ||
| 1460 | (cperl-indent-line) | ||
| 1461 | (if cperl-auto-newline | ||
| 1462 | (setq insertpos (1- (point)))) | ||
| 1463 | (if (and cperl-auto-newline (null only-before)) | ||
| 1464 | (progn | ||
| 1465 | (newline) | ||
| 1466 | (cperl-indent-line))) | ||
| 1467 | (save-excursion | ||
| 1468 | (if insertpos (progn (goto-char insertpos) | ||
| 1469 | (search-forward (make-string | ||
| 1470 | 1 last-command-char)) | ||
| 1471 | (setq insertpos (1- (point))))) | ||
| 1472 | (delete-char -1)))) | ||
| 1473 | (if insertpos | ||
| 1167 | (save-excursion | 1474 | (save-excursion |
| 1168 | (if insertpos (progn (goto-char insertpos) | 1475 | (goto-char insertpos) |
| 1169 | (search-forward (make-string | 1476 | (self-insert-command (prefix-numeric-value arg))) |
| 1170 | 1 last-command-char)) | 1477 | (self-insert-command (prefix-numeric-value arg))))))) |
| 1171 | (setq insertpos (1- (point))))) | ||
| 1172 | (delete-char -1)))) | ||
| 1173 | (if insertpos | ||
| 1174 | (save-excursion | ||
| 1175 | (goto-char insertpos) | ||
| 1176 | (self-insert-command (prefix-numeric-value arg))) | ||
| 1177 | (self-insert-command (prefix-numeric-value arg)))))) | ||
| 1178 | 1478 | ||
| 1179 | (defun cperl-electric-lbrace (arg &optional end) | 1479 | (defun cperl-electric-lbrace (arg &optional end) |
| 1180 | "Insert character, correct line's indentation, correct quoting by space." | 1480 | "Insert character, correct line's indentation, correct quoting by space." |
| @@ -1276,14 +1576,21 @@ If not, or if we are not at the end of marking range, would self-insert." | |||
| 1276 | (self-insert-command (prefix-numeric-value arg))))) | 1576 | (self-insert-command (prefix-numeric-value arg))))) |
| 1277 | 1577 | ||
| 1278 | (defun cperl-electric-keyword () | 1578 | (defun cperl-electric-keyword () |
| 1279 | "Insert a construction appropriate after a keyword." | 1579 | "Insert a construction appropriate after a keyword. |
| 1580 | Help message may be switched off by setting `cperl-message-electric-keyword' | ||
| 1581 | to nil." | ||
| 1280 | (let ((beg (save-excursion (beginning-of-line) (point))) | 1582 | (let ((beg (save-excursion (beginning-of-line) (point))) |
| 1281 | (dollar (and (eq last-command-char ?$) | 1583 | (dollar (and (eq last-command-char ?$) |
| 1282 | (eq this-command 'self-insert-command))) | 1584 | (eq this-command 'self-insert-command))) |
| 1283 | (delete (and (memq last-command-char '(?\ ?\n ?\t ?\f)) | 1585 | (delete (and (memq last-command-char '(?\ ?\n ?\t ?\f)) |
| 1284 | (memq this-command '(self-insert-command newline))))) | 1586 | (memq this-command '(self-insert-command newline)))) |
| 1587 | my do) | ||
| 1285 | (and (save-excursion | 1588 | (and (save-excursion |
| 1286 | (backward-sexp 1) | 1589 | (condition-case nil |
| 1590 | (progn | ||
| 1591 | (backward-sexp 1) | ||
| 1592 | (setq do (looking-at "do\\>"))) | ||
| 1593 | (error nil)) | ||
| 1287 | (cperl-after-expr-p nil "{;:")) | 1594 | (cperl-after-expr-p nil "{;:")) |
| 1288 | (save-excursion | 1595 | (save-excursion |
| 1289 | (not | 1596 | (not |
| @@ -1291,34 +1598,128 @@ If not, or if we are not at the end of marking range, would self-insert." | |||
| 1291 | "[#\"'`]\\|\\<q\\(\\|[wqx]\\)\\>" | 1598 | "[#\"'`]\\|\\<q\\(\\|[wqx]\\)\\>" |
| 1292 | beg t))) | 1599 | beg t))) |
| 1293 | (save-excursion (or (not (re-search-backward "^=" nil t)) | 1600 | (save-excursion (or (not (re-search-backward "^=" nil t)) |
| 1294 | (looking-at "=cut"))) | 1601 | (or |
| 1602 | (looking-at "=cut") | ||
| 1603 | (and cperl-use-syntax-table-text-property | ||
| 1604 | (not (eq (get-text-property (point) | ||
| 1605 | 'syntax-type) | ||
| 1606 | 'pod)))))) | ||
| 1295 | (progn | 1607 | (progn |
| 1608 | (and (eq (preceding-char) ?y) | ||
| 1609 | (progn ; "foreachmy" | ||
| 1610 | (forward-char -2) | ||
| 1611 | (insert " ") | ||
| 1612 | (forward-char 2) | ||
| 1613 | (setq my t dollar t | ||
| 1614 | delete | ||
| 1615 | (memq this-command '(self-insert-command newline))))) | ||
| 1296 | (and dollar (insert " $")) | 1616 | (and dollar (insert " $")) |
| 1297 | (cperl-indent-line) | 1617 | (cperl-indent-line) |
| 1298 | ;;(insert " () {\n}") | 1618 | ;;(insert " () {\n}") |
| 1299 | (cond | 1619 | (cond |
| 1300 | (cperl-extra-newline-before-brace | 1620 | (cperl-extra-newline-before-brace |
| 1301 | (insert " ()\n") | 1621 | (insert (if do "\n" " ()\n")) |
| 1302 | (insert "{") | 1622 | (insert "{") |
| 1303 | (cperl-indent-line) | 1623 | (cperl-indent-line) |
| 1304 | (insert "\n") | 1624 | (insert "\n") |
| 1305 | (cperl-indent-line) | 1625 | (cperl-indent-line) |
| 1306 | (insert "\n}")) | 1626 | (insert "\n}") |
| 1627 | (and do (insert " while ();"))) | ||
| 1307 | (t | 1628 | (t |
| 1308 | (insert " () {\n}")) | 1629 | (insert (if do " {\n} while ();" " () {\n}"))) |
| 1309 | ) | 1630 | ) |
| 1310 | (or (looking-at "[ \t]\\|$") (insert " ")) | 1631 | (or (looking-at "[ \t]\\|$") (insert " ")) |
| 1311 | (cperl-indent-line) | 1632 | (cperl-indent-line) |
| 1312 | (if dollar (progn (search-backward "$") | 1633 | (if dollar (progn (search-backward "$") |
| 1313 | (delete-char 1) | 1634 | (if my |
| 1314 | (forward-char -1) | 1635 | (forward-char 1) |
| 1315 | (forward-char 1)) | 1636 | (delete-char 1))) |
| 1316 | (search-backward ")")) | 1637 | (search-backward ")")) |
| 1317 | (if delete | 1638 | (if delete |
| 1639 | (cperl-putback-char cperl-del-back-ch)) | ||
| 1640 | (if cperl-message-electric-keyword | ||
| 1641 | (message "Precede char by C-q to avoid expansion")))))) | ||
| 1642 | |||
| 1643 | (defun cperl-ensure-newlines (n &optional pos) | ||
| 1644 | "Make sure there are N newlines after the point." | ||
| 1645 | (or pos (setq pos (point))) | ||
| 1646 | (if (looking-at "\n") | ||
| 1647 | (forward-char 1) | ||
| 1648 | (insert "\n")) | ||
| 1649 | (if (> n 1) | ||
| 1650 | (cperl-ensure-newlines (1- n) pos) | ||
| 1651 | (goto-char pos))) | ||
| 1652 | |||
| 1653 | (defun cperl-electric-pod () | ||
| 1654 | "Insert a POD chunk appropriate after a =POD directive." | ||
| 1655 | (let ((delete (and (memq last-command-char '(?\ ?\n ?\t ?\f)) | ||
| 1656 | (memq this-command '(self-insert-command newline)))) | ||
| 1657 | head1 notlast name p really-delete over) | ||
| 1658 | (and (save-excursion | ||
| 1659 | (condition-case nil | ||
| 1660 | (backward-sexp 1) | ||
| 1661 | (error nil)) | ||
| 1662 | (and | ||
| 1663 | (eq (preceding-char) ?=) | ||
| 1664 | (progn | ||
| 1665 | (setq head1 (looking-at "head1\\>")) | ||
| 1666 | (setq over (looking-at "over\\>")) | ||
| 1667 | (forward-char -1) | ||
| 1668 | (bolp)) | ||
| 1669 | (or | ||
| 1670 | (cperl-after-expr-p nil "{;:") | ||
| 1671 | (and (re-search-backward | ||
| 1672 | "\\(\\`\n?\\|\n\n\\)=\\sw+" (point-min) t) | ||
| 1673 | (not (or | ||
| 1674 | (looking-at "=cut") | ||
| 1675 | (and cperl-use-syntax-table-text-property | ||
| 1676 | (not (eq (get-text-property (point) 'syntax-type) | ||
| 1677 | 'pod))))))))) | ||
| 1678 | (progn | ||
| 1679 | (save-excursion | ||
| 1680 | (setq notlast (search-forward "\n\n=" nil t))) | ||
| 1681 | (or notlast | ||
| 1682 | (progn | ||
| 1683 | (insert "\n\n=cut") | ||
| 1684 | (cperl-ensure-newlines 2) | ||
| 1685 | (forward-sexp -2) | ||
| 1686 | (if (and head1 | ||
| 1687 | (not | ||
| 1688 | (save-excursion | ||
| 1689 | (forward-char -1) | ||
| 1690 | (re-search-backward "\\(\\`\n?\\|\n\n\\)=head1\\>" | ||
| 1691 | nil t)))) ; Only one | ||
| 1692 | (progn | ||
| 1693 | (forward-sexp 1) | ||
| 1694 | (setq name (file-name-sans-extension | ||
| 1695 | (file-name-nondirectory (buffer-file-name))) | ||
| 1696 | p (point)) | ||
| 1697 | (insert " NAME\n\n" name | ||
| 1698 | " - \n\n=head1 SYNOPSYS\n\n\n\n" | ||
| 1699 | "=head1 DESCRIPTION") | ||
| 1700 | (cperl-ensure-newlines 4) | ||
| 1701 | (goto-char p) | ||
| 1702 | (forward-sexp 2) | ||
| 1703 | (end-of-line) | ||
| 1704 | (setq really-delete t)) | ||
| 1705 | (forward-sexp 1)))) | ||
| 1706 | (if over | ||
| 1707 | (progn | ||
| 1708 | (setq p (point)) | ||
| 1709 | (insert "\n\n=item \n\n\n\n" | ||
| 1710 | "=back") | ||
| 1711 | (cperl-ensure-newlines 2) | ||
| 1712 | (goto-char p) | ||
| 1713 | (forward-sexp 1) | ||
| 1714 | (end-of-line) | ||
| 1715 | (setq really-delete t))) | ||
| 1716 | (if (and delete really-delete) | ||
| 1318 | (cperl-putback-char cperl-del-back-ch)))))) | 1717 | (cperl-putback-char cperl-del-back-ch)))))) |
| 1319 | 1718 | ||
| 1320 | (defun cperl-electric-else () | 1719 | (defun cperl-electric-else () |
| 1321 | "Insert a construction appropriate after a keyword." | 1720 | "Insert a construction appropriate after a keyword. |
| 1721 | Help message may be switched off by setting `cperl-message-electric-keyword' | ||
| 1722 | to nil." | ||
| 1322 | (let ((beg (save-excursion (beginning-of-line) (point)))) | 1723 | (let ((beg (save-excursion (beginning-of-line) (point)))) |
| 1323 | (and (save-excursion | 1724 | (and (save-excursion |
| 1324 | (backward-sexp 1) | 1725 | (backward-sexp 1) |
| @@ -1329,7 +1730,11 @@ If not, or if we are not at the end of marking range, would self-insert." | |||
| 1329 | "[#\"'`]\\|\\<q\\(\\|[wqx]\\)\\>" | 1730 | "[#\"'`]\\|\\<q\\(\\|[wqx]\\)\\>" |
| 1330 | beg t))) | 1731 | beg t))) |
| 1331 | (save-excursion (or (not (re-search-backward "^=" nil t)) | 1732 | (save-excursion (or (not (re-search-backward "^=" nil t)) |
| 1332 | (looking-at "=cut"))) | 1733 | (looking-at "=cut") |
| 1734 | (and cperl-use-syntax-table-text-property | ||
| 1735 | (not (eq (get-text-property (point) | ||
| 1736 | 'syntax-type) | ||
| 1737 | 'pod))))) | ||
| 1333 | (progn | 1738 | (progn |
| 1334 | (cperl-indent-line) | 1739 | (cperl-indent-line) |
| 1335 | ;;(insert " {\n\n}") | 1740 | ;;(insert " {\n\n}") |
| @@ -1346,14 +1751,18 @@ If not, or if we are not at the end of marking range, would self-insert." | |||
| 1346 | (cperl-indent-line) | 1751 | (cperl-indent-line) |
| 1347 | (forward-line -1) | 1752 | (forward-line -1) |
| 1348 | (cperl-indent-line) | 1753 | (cperl-indent-line) |
| 1349 | (cperl-putback-char cperl-del-back-ch))))) | 1754 | (cperl-putback-char cperl-del-back-ch) |
| 1755 | (setq this-command 'cperl-electric-else) | ||
| 1756 | (if cperl-message-electric-keyword | ||
| 1757 | (message "Precede char by C-q to avoid expansion")))))) | ||
| 1350 | 1758 | ||
| 1351 | (defun cperl-linefeed () | 1759 | (defun cperl-linefeed () |
| 1352 | "Go to end of line, open a new line and indent appropriately." | 1760 | "Go to end of line, open a new line and indent appropriately. |
| 1761 | If in POD, insert appropriate lines." | ||
| 1353 | (interactive) | 1762 | (interactive) |
| 1354 | (let ((beg (save-excursion (beginning-of-line) (point))) | 1763 | (let ((beg (save-excursion (beginning-of-line) (point))) |
| 1355 | (end (save-excursion (end-of-line) (point))) | 1764 | (end (save-excursion (end-of-line) (point))) |
| 1356 | (pos (point)) start) | 1765 | (pos (point)) start over cut res) |
| 1357 | (if (and ; Check if we need to split: | 1766 | (if (and ; Check if we need to split: |
| 1358 | ; i.e., on a boundary and inside "{...}" | 1767 | ; i.e., on a boundary and inside "{...}" |
| 1359 | (save-excursion (cperl-to-comment-or-eol) | 1768 | (save-excursion (cperl-to-comment-or-eol) |
| @@ -1373,7 +1782,7 @@ If not, or if we are not at the end of marking range, would self-insert." | |||
| 1373 | (progn | 1782 | (progn |
| 1374 | (backward-sexp 1) | 1783 | (backward-sexp 1) |
| 1375 | (setq start (point-marker)) | 1784 | (setq start (point-marker)) |
| 1376 | (<= start pos))))) ; RedundantAre after the | 1785 | (<= start pos))))) ; Redundant? Are after the |
| 1377 | ; start of parens group. | 1786 | ; start of parens group. |
| 1378 | (progn | 1787 | (progn |
| 1379 | (skip-chars-backward " \t") | 1788 | (skip-chars-backward " \t") |
| @@ -1406,7 +1815,7 @@ If not, or if we are not at the end of marking range, would self-insert." | |||
| 1406 | (forward-line -1) ; We are on the line before target | 1815 | (forward-line -1) ; We are on the line before target |
| 1407 | (end-of-line) | 1816 | (end-of-line) |
| 1408 | (newline-and-indent)) | 1817 | (newline-and-indent)) |
| 1409 | (end-of-line) ; else | 1818 | (end-of-line) ; else - no splitting |
| 1410 | (cond | 1819 | (cond |
| 1411 | ((and (looking-at "\n[ \t]*{$") | 1820 | ((and (looking-at "\n[ \t]*{$") |
| 1412 | (save-excursion | 1821 | (save-excursion |
| @@ -1415,6 +1824,37 @@ If not, or if we are not at the end of marking range, would self-insert." | |||
| 1415 | ; with an extra newline. | 1824 | ; with an extra newline. |
| 1416 | (forward-line 2) | 1825 | (forward-line 2) |
| 1417 | (cperl-indent-line)) | 1826 | (cperl-indent-line)) |
| 1827 | ((save-excursion ; In POD header | ||
| 1828 | (forward-paragraph -1) | ||
| 1829 | ;; (re-search-backward "\\(\\`\n?\\|\n\n\\)=head1\\b") | ||
| 1830 | ;; We are after \n now, so look for the rest | ||
| 1831 | (if (looking-at "\\(\\`\n?\\|\n\\)=\\sw+") | ||
| 1832 | (progn | ||
| 1833 | (setq cut (looking-at "\\(\\`\n?\\|\n\\)=cut\\>")) | ||
| 1834 | (setq over (looking-at "\\(\\`\n?\\|\n\\)=over\\>")) | ||
| 1835 | t))) | ||
| 1836 | (if (and over | ||
| 1837 | (progn | ||
| 1838 | (forward-paragraph -1) | ||
| 1839 | (forward-word 1) | ||
| 1840 | (setq pos (point)) | ||
| 1841 | (setq cut (buffer-substring (point) | ||
| 1842 | (save-excursion | ||
| 1843 | (end-of-line) | ||
| 1844 | (point)))) | ||
| 1845 | (delete-char (- (save-excursion (end-of-line) (point)) | ||
| 1846 | (point))) | ||
| 1847 | (setq res (expand-abbrev)) | ||
| 1848 | (save-excursion | ||
| 1849 | (goto-char pos) | ||
| 1850 | (insert cut)) | ||
| 1851 | res)) | ||
| 1852 | nil | ||
| 1853 | (cperl-ensure-newlines (if cut 2 4)) | ||
| 1854 | (forward-line 2))) | ||
| 1855 | ((get-text-property (point) 'in-pod) ; In POD section | ||
| 1856 | (cperl-ensure-newlines 4) | ||
| 1857 | (forward-line 2)) | ||
| 1418 | ((looking-at "\n[ \t]*$") ; Next line is empty - use it. | 1858 | ((looking-at "\n[ \t]*$") ; Next line is empty - use it. |
| 1419 | (forward-line 1) | 1859 | (forward-line 1) |
| 1420 | (cperl-indent-line)) | 1860 | (cperl-indent-line)) |
| @@ -1467,12 +1907,6 @@ If not, or if we are not at the end of marking range, would self-insert." | |||
| 1467 | (progn | 1907 | (progn |
| 1468 | (newline) | 1908 | (newline) |
| 1469 | (cperl-indent-line))) | 1909 | (cperl-indent-line))) |
| 1470 | ;; (save-excursion | ||
| 1471 | ;; (if insertpos (progn (goto-char (marker-position insertpos)) | ||
| 1472 | ;; (search-forward (make-string | ||
| 1473 | ;; 1 last-command-char)) | ||
| 1474 | ;; (setq insertpos (1- (point))))) | ||
| 1475 | ;; (delete-char -1)))) | ||
| 1476 | (save-excursion | 1910 | (save-excursion |
| 1477 | (if insertpos (goto-char (1- (marker-position insertpos))) | 1911 | (if insertpos (goto-char (1- (marker-position insertpos))) |
| 1478 | (forward-char -1)) | 1912 | (forward-char -1)) |
| @@ -1484,7 +1918,8 @@ If not, or if we are not at the end of marking range, would self-insert." | |||
| 1484 | (self-insert-command (prefix-numeric-value arg))))) | 1918 | (self-insert-command (prefix-numeric-value arg))))) |
| 1485 | 1919 | ||
| 1486 | (defun cperl-electric-backspace (arg) | 1920 | (defun cperl-electric-backspace (arg) |
| 1487 | "Backspace-untabify, or remove the whitespace inserted by an electric key." | 1921 | "Backspace-untabify, or remove the whitespace around the point inserted |
| 1922 | by an electric key." | ||
| 1488 | (interactive "p") | 1923 | (interactive "p") |
| 1489 | (if (and cperl-auto-newline | 1924 | (if (and cperl-auto-newline |
| 1490 | (memq last-command '(cperl-electric-semi | 1925 | (memq last-command '(cperl-electric-semi |
| @@ -1497,7 +1932,18 @@ If not, or if we are not at the end of marking range, would self-insert." | |||
| 1497 | (setq p (point)) | 1932 | (setq p (point)) |
| 1498 | (skip-chars-backward " \t\n") | 1933 | (skip-chars-backward " \t\n") |
| 1499 | (delete-region (point) p)) | 1934 | (delete-region (point) p)) |
| 1500 | (backward-delete-char-untabify arg))) | 1935 | (and (eq last-command 'cperl-electric-else) |
| 1936 | ;; We are removing the whitespace *inside* cperl-electric-else | ||
| 1937 | (setq this-command 'cperl-electric-else-really)) | ||
| 1938 | (if (and cperl-auto-newline | ||
| 1939 | (eq last-command 'cperl-electric-else-really) | ||
| 1940 | (memq (preceding-char) '(?\ ?\t ?\n))) | ||
| 1941 | (let (p) | ||
| 1942 | (skip-chars-forward " \t\n") | ||
| 1943 | (setq p (point)) | ||
| 1944 | (skip-chars-backward " \t\n") | ||
| 1945 | (delete-region (point) p)) | ||
| 1946 | (backward-delete-char-untabify arg)))) | ||
| 1501 | 1947 | ||
| 1502 | (defun cperl-inside-parens-p () | 1948 | (defun cperl-inside-parens-p () |
| 1503 | (condition-case () | 1949 | (condition-case () |
| @@ -1511,8 +1957,8 @@ If not, or if we are not at the end of marking range, would self-insert." | |||
| 1511 | 1957 | ||
| 1512 | (defun cperl-indent-command (&optional whole-exp) | 1958 | (defun cperl-indent-command (&optional whole-exp) |
| 1513 | "Indent current line as Perl code, or in some cases insert a tab character. | 1959 | "Indent current line as Perl code, or in some cases insert a tab character. |
| 1514 | If `cperl-tab-always-indent' is non-nil (the default), always indent current line. | 1960 | If `cperl-tab-always-indent' is non-nil (the default), always indent current |
| 1515 | Otherwise, indent the current line only if point is at the left margin | 1961 | line. Otherwise, indent the current line only if point is at the left margin |
| 1516 | or in the line's indentation; otherwise insert a tab. | 1962 | or in the line's indentation; otherwise insert a tab. |
| 1517 | 1963 | ||
| 1518 | A numeric argument, regardless of its value, | 1964 | A numeric argument, regardless of its value, |
| @@ -1534,7 +1980,7 @@ The relative indentation among the lines of the expression are preserved." | |||
| 1534 | (goto-char beg) | 1980 | (goto-char beg) |
| 1535 | (forward-line 1) | 1981 | (forward-line 1) |
| 1536 | (setq beg (point))) | 1982 | (setq beg (point))) |
| 1537 | (if (> end beg) | 1983 | (if (and shift-amt (> end beg)) |
| 1538 | (indent-code-rigidly beg end shift-amt "#"))) | 1984 | (indent-code-rigidly beg end shift-amt "#"))) |
| 1539 | (if (and (not cperl-tab-always-indent) | 1985 | (if (and (not cperl-tab-always-indent) |
| 1540 | (save-excursion | 1986 | (save-excursion |
| @@ -1546,15 +1992,15 @@ The relative indentation among the lines of the expression are preserved." | |||
| 1546 | (defun cperl-indent-line (&optional symbol) | 1992 | (defun cperl-indent-line (&optional symbol) |
| 1547 | "Indent current line as Perl code. | 1993 | "Indent current line as Perl code. |
| 1548 | Return the amount the indentation changed by." | 1994 | Return the amount the indentation changed by." |
| 1549 | (let (indent | 1995 | (let (indent i beg shift-amt |
| 1550 | beg shift-amt | ||
| 1551 | (case-fold-search nil) | 1996 | (case-fold-search nil) |
| 1552 | (pos (- (point-max) (point)))) | 1997 | (pos (- (point-max) (point)))) |
| 1553 | (setq indent (cperl-calculate-indent nil symbol)) | 1998 | (setq indent (cperl-calculate-indent nil symbol) |
| 1999 | i indent) | ||
| 1554 | (beginning-of-line) | 2000 | (beginning-of-line) |
| 1555 | (setq beg (point)) | 2001 | (setq beg (point)) |
| 1556 | (cond ((or (eq indent nil) (eq indent t)) | 2002 | (cond ((or (eq indent nil) (eq indent t)) |
| 1557 | (setq indent (current-indentation))) | 2003 | (setq indent (current-indentation) i nil)) |
| 1558 | ;;((eq indent t) ; Never? | 2004 | ;;((eq indent t) ; Never? |
| 1559 | ;; (setq indent (cperl-calculate-indent-within-comment))) | 2005 | ;; (setq indent (cperl-calculate-indent-within-comment))) |
| 1560 | ;;((looking-at "[ \t]*#") | 2006 | ;;((looking-at "[ \t]*#") |
| @@ -1573,8 +2019,9 @@ Return the amount the indentation changed by." | |||
| 1573 | ((= (following-char) ?{) | 2019 | ((= (following-char) ?{) |
| 1574 | (setq indent (+ indent cperl-brace-offset)))))) | 2020 | (setq indent (+ indent cperl-brace-offset)))))) |
| 1575 | (skip-chars-forward " \t") | 2021 | (skip-chars-forward " \t") |
| 1576 | (setq shift-amt (- indent (current-column))) | 2022 | (setq shift-amt (and i (- indent (current-column)))) |
| 1577 | (if (zerop shift-amt) | 2023 | (if (or (not shift-amt) |
| 2024 | (zerop shift-amt)) | ||
| 1578 | (if (> (- (point-max) pos) (point)) | 2025 | (if (> (- (point-max) pos) (point)) |
| 1579 | (goto-char (- (point-max) pos))) | 2026 | (goto-char (- (point-max) pos))) |
| 1580 | (delete-region beg (point)) | 2027 | (delete-region beg (point)) |
| @@ -1626,7 +2073,6 @@ Return the amount the indentation changed by." | |||
| 1626 | ;; Positions is before ?\{. Checks whether it starts a block. | 2073 | ;; Positions is before ?\{. Checks whether it starts a block. |
| 1627 | ;; No save-excursion! | 2074 | ;; No save-excursion! |
| 1628 | (cperl-backward-to-noncomment (point-min)) | 2075 | (cperl-backward-to-noncomment (point-min)) |
| 1629 | ;;(skip-chars-backward " \t\n\f") | ||
| 1630 | (or (memq (preceding-char) (append ";){}$@&%\C-@" nil)) ; Or label! \C-@ at bobp | 2076 | (or (memq (preceding-char) (append ";){}$@&%\C-@" nil)) ; Or label! \C-@ at bobp |
| 1631 | ; Label may be mixed up with `$blah :' | 2077 | ; Label may be mixed up with `$blah :' |
| 1632 | (save-excursion (cperl-after-label)) | 2078 | (save-excursion (cperl-after-label)) |
| @@ -1750,13 +2196,15 @@ Returns nil if line starts inside a string, t if in a comment." | |||
| 1750 | (if (= (following-char) ?{) cperl-continued-brace-offset 0) | 2196 | (if (= (following-char) ?{) cperl-continued-brace-offset 0) |
| 1751 | (progn | 2197 | (progn |
| 1752 | (cperl-backward-to-noncomment (or parse-start (point-min))) | 2198 | (cperl-backward-to-noncomment (or parse-start (point-min))) |
| 1753 | ;;(skip-chars-backward " \t\f\n") | ||
| 1754 | ;; Look at previous line that's at column 0 | 2199 | ;; Look at previous line that's at column 0 |
| 1755 | ;; to determine whether we are in top-level decls | 2200 | ;; to determine whether we are in top-level decls |
| 1756 | ;; or function's arg decls. Set basic-indent accordingly. | 2201 | ;; or function's arg decls. Set basic-indent accordingly. |
| 1757 | ;; Now add a little if this is a continuation line. | 2202 | ;; Now add a little if this is a continuation line. |
| 1758 | (if (or (bobp) | 2203 | (if (or (bobp) |
| 1759 | (memq (preceding-char) (append " ;}" nil)) ; Was ?\) | 2204 | (eq (preceding-char) ?\;) |
| 2205 | ;; Had ?\) too | ||
| 2206 | (and (eq (preceding-char) ?\}) | ||
| 2207 | (cperl-after-block-and-statement-beg start)) | ||
| 1760 | (memq char-after (append ")]}" nil)) | 2208 | (memq char-after (append ")]}" nil)) |
| 1761 | (and (eq (preceding-char) ?\:) ; label | 2209 | (and (eq (preceding-char) ?\:) ; label |
| 1762 | (progn | 2210 | (progn |
| @@ -1805,7 +2253,11 @@ Returns nil if line starts inside a string, t if in a comment." | |||
| 1805 | (beginning-of-line) | 2253 | (beginning-of-line) |
| 1806 | (cperl-backward-to-noncomment containing-sexp)) | 2254 | (cperl-backward-to-noncomment containing-sexp)) |
| 1807 | ;; Now we get the answer. | 2255 | ;; Now we get the answer. |
| 1808 | (if (not (memq (preceding-char) (append ", ;}{" '(nil)))) ; Was ?\, | 2256 | ;; Had \?, too: |
| 2257 | (if (not (or (memq (preceding-char) (append " ;{" '(nil))) | ||
| 2258 | (and (eq (preceding-char) ?\}) | ||
| 2259 | (cperl-after-block-and-statement-beg | ||
| 2260 | containing-sexp)))) ; Was ?\, | ||
| 1809 | ;; This line is continuation of preceding line's statement; | 2261 | ;; This line is continuation of preceding line's statement; |
| 1810 | ;; indent `cperl-continued-statement-offset' more than the | 2262 | ;; indent `cperl-continued-statement-offset' more than the |
| 1811 | ;; previous line of the statement. | 2263 | ;; previous line of the statement. |
| @@ -1913,12 +2365,16 @@ Returns nil if line starts inside a string, t if in a comment." | |||
| 1913 | "Alist of indentation rules for CPerl mode. | 2365 | "Alist of indentation rules for CPerl mode. |
| 1914 | The values mean: | 2366 | The values mean: |
| 1915 | nil: do not indent; | 2367 | nil: do not indent; |
| 1916 | number: add this amount of indentation.") | 2368 | number: add this amount of indentation. |
| 2369 | |||
| 2370 | Not finished, not used.") | ||
| 1917 | 2371 | ||
| 1918 | (defun cperl-where-am-i (&optional parse-start start-state) | 2372 | (defun cperl-where-am-i (&optional parse-start start-state) |
| 1919 | ;; Unfinished | 2373 | ;; Unfinished |
| 1920 | "Return a list of lists ((TYPE POS)...) of good points before the point. | 2374 | "Return a list of lists ((TYPE POS)...) of good points before the point. |
| 1921 | POS may be nil if it is hard to find, say, when TYPE is `string' or `comment'." | 2375 | POS may be nil if it is hard to find, say, when TYPE is `string' or `comment'. |
| 2376 | |||
| 2377 | Not finished, not used." | ||
| 1922 | (save-excursion | 2378 | (save-excursion |
| 1923 | (let* ((start-point (point)) | 2379 | (let* ((start-point (point)) |
| 1924 | (s-s (cperl-get-state)) | 2380 | (s-s (cperl-get-state)) |
| @@ -2094,13 +2550,6 @@ Returns true if comment is found." | |||
| 2094 | (setq state (parse-partial-sexp (point) lim nil nil nil t)) | 2550 | (setq state (parse-partial-sexp (point) lim nil nil nil t)) |
| 2095 | ; stop at comment | 2551 | ; stop at comment |
| 2096 | ;; If fails (beginning-of-line inside sexp), then contains not-comment | 2552 | ;; If fails (beginning-of-line inside sexp), then contains not-comment |
| 2097 | ;; Do simplified processing | ||
| 2098 | ;;(if (re-search-forward "[^$]#" lim 1) | ||
| 2099 | ;; (progn | ||
| 2100 | ;; (forward-char -1) | ||
| 2101 | ;; (skip-chars-backward " \t\n\f" lim)) | ||
| 2102 | ;; (goto-char lim)) ; No `#' at all | ||
| 2103 | ;;) | ||
| 2104 | (if (nth 4 state) ; After `#'; | 2553 | (if (nth 4 state) ; After `#'; |
| 2105 | ; (nth 2 state) can be | 2554 | ; (nth 2 state) can be |
| 2106 | ; beginning of m,s,qq and so | 2555 | ; beginning of m,s,qq and so |
| @@ -2259,73 +2708,87 @@ Returns true if comment is found." | |||
| 2259 | (if ender (modify-syntax-entry ender "." st)))) | 2708 | (if ender (modify-syntax-entry ender "." st)))) |
| 2260 | (list i i2 ender starter go-forward))) | 2709 | (list i i2 ender starter go-forward))) |
| 2261 | 2710 | ||
| 2262 | (defun cperl-find-pods-heres (&optional min max non-inter end) | 2711 | (defvar font-lock-string-face) |
| 2712 | (defvar font-lock-reference-face) | ||
| 2713 | (defvar font-lock-constant-face) | ||
| 2714 | (defun cperl-find-pods-heres (&optional min max non-inter end ignore-max) | ||
| 2263 | "Scans the buffer for hard-to-parse Perl constructions. | 2715 | "Scans the buffer for hard-to-parse Perl constructions. |
| 2264 | If `cperl-pod-here-fontify' is not-nil after evaluation, will fontify | 2716 | If `cperl-pod-here-fontify' is not-nil after evaluation, will fontify |
| 2265 | the sections using `cperl-pod-head-face', `cperl-pod-face', | 2717 | the sections using `cperl-pod-head-face', `cperl-pod-face', |
| 2266 | `cperl-here-face'." | 2718 | `cperl-here-face'." |
| 2267 | (interactive) | 2719 | (interactive) |
| 2268 | (or min (setq min (point-min))) | 2720 | (or min (setq min (point-min) |
| 2721 | cperl-syntax-state nil | ||
| 2722 | cperl-syntax-done-to min)) | ||
| 2269 | (or max (setq max (point-max))) | 2723 | (or max (setq max (point-max))) |
| 2270 | (let (face head-face here-face b e bb tag qtag b1 e1 argument i c tail state | 2724 | (let* (face head-face here-face b e bb tag qtag b1 e1 argument i c tail |
| 2271 | (cperl-pod-here-fontify (eval cperl-pod-here-fontify)) go | 2725 | (cperl-pod-here-fontify (eval cperl-pod-here-fontify)) go |
| 2272 | (case-fold-search nil) (inhibit-read-only t) (buffer-undo-list t) | 2726 | (case-fold-search nil) (inhibit-read-only t) (buffer-undo-list t) |
| 2273 | (modified (buffer-modified-p)) | 2727 | (modified (buffer-modified-p)) |
| 2274 | (after-change-functions nil) | 2728 | (after-change-functions nil) |
| 2275 | (state-point (point-min)) | 2729 | (use-syntax-state (and cperl-syntax-state |
| 2276 | (st-l '(nil)) (err-l '(nil)) i2 | 2730 | (>= min (car cperl-syntax-state)))) |
| 2277 | ;; Somehow font-lock may be not loaded yet... | 2731 | (state-point (if use-syntax-state |
| 2278 | (font-lock-string-face (if (boundp 'font-lock-string-face) | 2732 | (car cperl-syntax-state) |
| 2279 | font-lock-string-face | 2733 | (point-min))) |
| 2280 | 'font-lock-string-face)) | 2734 | (state (if use-syntax-state |
| 2281 | (search | 2735 | (cdr cperl-syntax-state))) |
| 2282 | (concat | 2736 | (st-l '(nil)) (err-l '(nil)) i2 |
| 2283 | "\\(\\`\n?\\|\n\n\\)=" | 2737 | ;; Somehow font-lock may be not loaded yet... |
| 2284 | "\\|" | 2738 | (font-lock-string-face (if (boundp 'font-lock-string-face) |
| 2285 | ;; One extra () before this: | 2739 | font-lock-string-face |
| 2286 | "<<" | 2740 | 'font-lock-string-face)) |
| 2287 | "\\(" | 2741 | (stop-point (if ignore-max |
| 2288 | ;; First variant "BLAH" or just ``. | 2742 | (point-max) |
| 2289 | "\\([\"'`]\\)" | 2743 | max)) |
| 2290 | "\\([^\"'`\n]*\\)" | 2744 | (search |
| 2291 | "\\3" | 2745 | (concat |
| 2292 | "\\|" | 2746 | "\\(\\`\n?\\|\n\n\\)=" |
| 2293 | ;; Second variant: Identifier or empty | 2747 | "\\|" |
| 2294 | "\\(\\([a-zA-Z_][a-zA-Z_0-9]*\\)?\\)" | 2748 | ;; One extra () before this: |
| 2295 | ;; Check that we do not have <<= or << 30 or << $blah. | 2749 | "<<" |
| 2296 | "\\([^= \t$@%&]\\|[ \t]+[^ \t\n0-9$@%&]\\)" | 2750 | "\\(" |
| 2297 | "\\)" | 2751 | ;; First variant "BLAH" or just ``. |
| 2298 | "\\|" | 2752 | "\\([\"'`]\\)" |
| 2299 | ;; 1+6 extra () before this: | 2753 | "\\([^\"'`\n]*\\)" |
| 2300 | "^[ \t]*\\(format\\)[ \t]*\\([a-zA-Z0-9_]+\\)?[ \t]*=[ \t]*$" | 2754 | "\\3" |
| 2301 | (if cperl-use-syntax-table-text-property | 2755 | "\\|" |
| 2302 | (concat | 2756 | ;; Second variant: Identifier or empty |
| 2303 | "\\|" | 2757 | "\\(\\([a-zA-Z_][a-zA-Z_0-9]*\\)?\\)" |
| 2304 | ;; 1+6+2=9 extra () before this: | 2758 | ;; Check that we do not have <<= or << 30 or << $blah. |
| 2305 | "\\<\\(q[wxq]?\\|[msy]\\|tr\\)\\>" | 2759 | "\\([^= \t$@%&]\\|[ \t]+[^ \t\n0-9$@%&]\\)" |
| 2306 | "\\|" | 2760 | "\\)" |
| 2307 | ;; 1+6+2+1=10 extra () before this: | 2761 | "\\|" |
| 2308 | "\\([?/]\\)" ; /blah/ or ?blah? | 2762 | ;; 1+6 extra () before this: |
| 2309 | "\\|" | 2763 | "^[ \t]*\\(format\\)[ \t]*\\([a-zA-Z0-9_]+\\)?[ \t]*=[ \t]*$" |
| 2310 | ;; 1+6+2+1+1=11 extra () before this: | 2764 | (if cperl-use-syntax-table-text-property |
| 2311 | "\\<sub\\>[ \t]*\\([a-zA-Z_:'0-9]+[ \t]*\\)?\\(([^()]*)\\)" | 2765 | (concat |
| 2312 | "\\|" | 2766 | "\\|" |
| 2313 | ;; 1+6+2+1+1+2=13 extra () before this: | 2767 | ;; 1+6+2=9 extra () before this: |
| 2314 | "\\$\\(['{]\\)" | 2768 | "\\<\\(q[wxq]?\\|[msy]\\|tr\\)\\>" |
| 2315 | "\\|" | 2769 | "\\|" |
| 2316 | ;; 1+6+2+1+1+2+1=14 extra () before this: | 2770 | ;; 1+6+2+1=10 extra () before this: |
| 2317 | "\\(\\<sub[ \t\n\f]+\\|[&*$@%]\\)[a-zA-Z0-9_]*'" | 2771 | "\\([?/]\\)" ; /blah/ or ?blah? |
| 2318 | ;; 1+6+2+1+1+2+1+1=15 extra () before this: | 2772 | "\\|" |
| 2319 | "\\|" | 2773 | ;; 1+6+2+1+1=11 extra () before this: |
| 2320 | "__\\(END\\|DATA\\)__" ; Commented - does not help with indent... | 2774 | "\\<sub\\>[ \t]*\\([a-zA-Z_:'0-9]+[ \t]*\\)?\\(([^()]*)\\)" |
| 2321 | ) | 2775 | "\\|" |
| 2322 | "")))) | 2776 | ;; 1+6+2+1+1+2=13 extra () before this: |
| 2777 | "\\$\\(['{]\\)" | ||
| 2778 | "\\|" | ||
| 2779 | ;; 1+6+2+1+1+2+1=14 extra () before this: | ||
| 2780 | "\\(\\<sub[ \t\n\f]+\\|[&*$@%]\\)[a-zA-Z0-9_]*'" | ||
| 2781 | ;; 1+6+2+1+1+2+1+1=15 extra () before this: | ||
| 2782 | "\\|" | ||
| 2783 | "__\\(END\\|DATA\\)__" ; Commented - does not help with indent... | ||
| 2784 | ) | ||
| 2785 | "")))) | ||
| 2323 | (unwind-protect | 2786 | (unwind-protect |
| 2324 | (progn | 2787 | (progn |
| 2325 | (save-excursion | 2788 | (save-excursion |
| 2326 | (or non-inter | 2789 | (or non-inter |
| 2327 | (message "Scanning for \"hard\" Perl constructions...")) | 2790 | (message "Scanning for \"hard\" Perl constructions...")) |
| 2328 | (if cperl-pod-here-fontify | 2791 | (and cperl-pod-here-fontify |
| 2329 | ;; We had evals here, do not know why... | 2792 | ;; We had evals here, do not know why... |
| 2330 | (setq face cperl-pod-face | 2793 | (setq face cperl-pod-face |
| 2331 | head-face cperl-pod-head-face | 2794 | head-face cperl-pod-head-face |
| @@ -2334,12 +2797,14 @@ the sections using `cperl-pod-head-face', `cperl-pod-face', | |||
| 2334 | '(syntax-type t in-pod t syntax-table t)) | 2797 | '(syntax-type t in-pod t syntax-table t)) |
| 2335 | ;; Need to remove face as well... | 2798 | ;; Need to remove face as well... |
| 2336 | (goto-char min) | 2799 | (goto-char min) |
| 2337 | (if (and (eq system-type 'emx) | 2800 | (and (eq system-type 'emx) |
| 2338 | (looking-at "extproc[ \t]")) ; Analogue of #! | 2801 | (looking-at "extproc[ \t]") ; Analogue of #! |
| 2339 | (cperl-commentify min | 2802 | (cperl-commentify min |
| 2340 | (save-excursion (end-of-line) (point)) | 2803 | (save-excursion (end-of-line) (point)) |
| 2341 | nil)) | 2804 | nil)) |
| 2342 | (while (re-search-forward search max t) | 2805 | (while (and |
| 2806 | (< (point) max) | ||
| 2807 | (re-search-forward search max t)) | ||
| 2343 | (cond | 2808 | (cond |
| 2344 | ((match-beginning 1) ; POD section | 2809 | ((match-beginning 1) ; POD section |
| 2345 | ;; "\\(\\`\n?\\|\n\n\\)=" | 2810 | ;; "\\(\\`\n?\\|\n\n\\)=" |
| @@ -2350,12 +2815,17 @@ the sections using `cperl-pod-head-face', `cperl-pod-face', | |||
| 2350 | (beginning-of-line) | 2815 | (beginning-of-line) |
| 2351 | 2816 | ||
| 2352 | (setq b (point) bb b) | 2817 | (setq b (point) bb b) |
| 2353 | (or (re-search-forward "\n\n=cut\\>" max 'toend) | 2818 | ;; We do not search to max, since we may be called from |
| 2819 | ;; some hook of fontification, and max is random | ||
| 2820 | (or (re-search-forward "\n\n=cut\\>" stop-point 'toend) | ||
| 2354 | (progn | 2821 | (progn |
| 2355 | (message "End of a POD section not marked by =cut") | 2822 | (message "End of a POD section not marked by =cut") |
| 2356 | (or (car err-l) (setcar err-l b)))) | 2823 | (or (car err-l) (setcar err-l b)))) |
| 2357 | (beginning-of-line 2) ; An empty line after =cut is not POD! | 2824 | (beginning-of-line 2) ; An empty line after =cut is not POD! |
| 2358 | (setq e (point)) | 2825 | (setq e (point)) |
| 2826 | (and (> e max) | ||
| 2827 | (remove-text-properties max e | ||
| 2828 | '(syntax-type t in-pod t syntax-table t))) | ||
| 2359 | (put-text-property b e 'in-pod t) | 2829 | (put-text-property b e 'in-pod t) |
| 2360 | (goto-char b) | 2830 | (goto-char b) |
| 2361 | (while (re-search-forward "\n\n[ \t]" e t) | 2831 | (while (re-search-forward "\n\n[ \t]" e t) |
| @@ -2363,16 +2833,12 @@ the sections using `cperl-pod-head-face', `cperl-pod-face', | |||
| 2363 | (beginning-of-line) | 2833 | (beginning-of-line) |
| 2364 | (put-text-property (cperl-1- b) (point) 'syntax-type 'pod) | 2834 | (put-text-property (cperl-1- b) (point) 'syntax-type 'pod) |
| 2365 | (cperl-put-do-not-fontify b (point)) | 2835 | (cperl-put-do-not-fontify b (point)) |
| 2366 | ;;(put-text-property (max (point-min) (1- b)) | ||
| 2367 | ;; (point) cperl-do-not-fontify t) | ||
| 2368 | (if cperl-pod-here-fontify (put-text-property b (point) 'face face)) | 2836 | (if cperl-pod-here-fontify (put-text-property b (point) 'face face)) |
| 2369 | (re-search-forward "\n\n[^ \t\f\n]" e 'toend) | 2837 | (re-search-forward "\n\n[^ \t\f\n]" e 'toend) |
| 2370 | (beginning-of-line) | 2838 | (beginning-of-line) |
| 2371 | (setq b (point))) | 2839 | (setq b (point))) |
| 2372 | (put-text-property (cperl-1- (point)) e 'syntax-type 'pod) | 2840 | (put-text-property (cperl-1- (point)) e 'syntax-type 'pod) |
| 2373 | (cperl-put-do-not-fontify (point) e) | 2841 | (cperl-put-do-not-fontify (point) e) |
| 2374 | ;;(put-text-property (max (point-min) (1- (point))) | ||
| 2375 | ;; e cperl-do-not-fontify t) | ||
| 2376 | (if cperl-pod-here-fontify | 2842 | (if cperl-pod-here-fontify |
| 2377 | (progn (put-text-property (point) e 'face face) | 2843 | (progn (put-text-property (point) e 'face face) |
| 2378 | (goto-char bb) | 2844 | (goto-char bb) |
| @@ -2401,10 +2867,7 @@ the sections using `cperl-pod-head-face', `cperl-pod-face', | |||
| 2401 | (setq b (point)) | 2867 | (setq b (point)) |
| 2402 | (setq state (parse-partial-sexp state-point b nil nil state) | 2868 | (setq state (parse-partial-sexp state-point b nil nil state) |
| 2403 | state-point b) | 2869 | state-point b) |
| 2404 | (if ;;(save-excursion | 2870 | (if (or (nth 3 state) (nth 4 state)) |
| 2405 | ;; (beginning-of-line) | ||
| 2406 | ;; (search-forward "#" b t)) | ||
| 2407 | (or (nth 3 state) (nth 4 state)) | ||
| 2408 | (goto-char (match-end 2)) | 2871 | (goto-char (match-end 2)) |
| 2409 | (if (match-beginning 5) ;4 + 1 | 2872 | (if (match-beginning 5) ;4 + 1 |
| 2410 | (setq b1 (match-beginning 5) ; 4 + 1 | 2873 | (setq b1 (match-beginning 5) ; 4 + 1 |
| @@ -2418,16 +2881,15 @@ the sections using `cperl-pod-head-face', `cperl-pod-face', | |||
| 2418 | (cperl-put-do-not-fontify b1 e1))) | 2881 | (cperl-put-do-not-fontify b1 e1))) |
| 2419 | (forward-line) | 2882 | (forward-line) |
| 2420 | (setq b (point)) | 2883 | (setq b (point)) |
| 2421 | (cond ((re-search-forward (concat "^" qtag "$") max 'toend) | 2884 | ;; We do not search to max, since we may be called from |
| 2885 | ;; some hook of fontification, and max is random | ||
| 2886 | (cond ((re-search-forward (concat "^" qtag "$") | ||
| 2887 | stop-point 'toend) | ||
| 2422 | (if cperl-pod-here-fontify | 2888 | (if cperl-pod-here-fontify |
| 2423 | (progn | 2889 | (progn |
| 2424 | (put-text-property (match-beginning 0) (match-end 0) | 2890 | (put-text-property (match-beginning 0) (match-end 0) |
| 2425 | 'face font-lock-constant-face) | 2891 | 'face font-lock-constant-face) |
| 2426 | (cperl-put-do-not-fontify b (match-end 0)) | 2892 | (cperl-put-do-not-fontify b (match-end 0)) |
| 2427 | ;;(put-text-property (max (point-min) (1- b)) | ||
| 2428 | ;; (min (point-max) | ||
| 2429 | ;; (1+ (match-end 0))) | ||
| 2430 | ;; cperl-do-not-fontify t) | ||
| 2431 | (put-text-property b (match-beginning 0) | 2893 | (put-text-property b (match-beginning 0) |
| 2432 | 'face here-face))) | 2894 | 'face here-face))) |
| 2433 | (setq e1 (cperl-1+ (match-end 0))) | 2895 | (setq e1 (cperl-1+ (match-end 0))) |
| @@ -2470,7 +2932,9 @@ the sections using `cperl-pod-head-face', `cperl-pod-face', | |||
| 2470 | 'face font-lock-string-face) | 2932 | 'face font-lock-string-face) |
| 2471 | (cperl-commentify b1 (point) nil) | 2933 | (cperl-commentify b1 (point) nil) |
| 2472 | (cperl-put-do-not-fontify b1 (point))))) | 2934 | (cperl-put-do-not-fontify b1 (point))))) |
| 2473 | (re-search-forward (concat "^[.;]$") max 'toend)) | 2935 | ;; We do not search to max, since we may be called from |
| 2936 | ;; some hook of fontification, and max is random | ||
| 2937 | (re-search-forward "^[.;]$" stop-point 'toend)) | ||
| 2474 | (beginning-of-line) | 2938 | (beginning-of-line) |
| 2475 | (if (looking-at "^[.;]$") | 2939 | (if (looking-at "^[.;]$") |
| 2476 | (progn | 2940 | (progn |
| @@ -2481,18 +2945,7 @@ the sections using `cperl-pod-head-face', `cperl-pod-face', | |||
| 2481 | (message "End of format `%s' not found." name) | 2945 | (message "End of format `%s' not found." name) |
| 2482 | (or (car err-l) (setcar err-l b))) | 2946 | (or (car err-l) (setcar err-l b))) |
| 2483 | (forward-line) | 2947 | (forward-line) |
| 2484 | (put-text-property b (point) 'syntax-type 'format) | 2948 | (put-text-property b (point) 'syntax-type 'format)) |
| 2485 | ;;; (cond ((re-search-forward (concat "^[.;]$") max 'toend) | ||
| 2486 | ;;; (if cperl-pod-here-fontify | ||
| 2487 | ;;; (progn | ||
| 2488 | ;;; (put-text-property b (match-end 0) | ||
| 2489 | ;;; 'face font-lock-string-face) | ||
| 2490 | ;;; (cperl-put-do-not-fontify b (match-end 0)))) | ||
| 2491 | ;;; (put-text-property b (match-end 0) | ||
| 2492 | ;;; 'syntax-type 'format) | ||
| 2493 | ;;; (cperl-put-do-not-fontify b (match-beginning 0))) | ||
| 2494 | ;;; (t (message "End of format `%s' not found." name))) | ||
| 2495 | ) | ||
| 2496 | ;; Regexp: | 2949 | ;; Regexp: |
| 2497 | ((or (match-beginning 10) (match-beginning 11)) | 2950 | ((or (match-beginning 10) (match-beginning 11)) |
| 2498 | ;; 1+6+2=9 extra () before this: | 2951 | ;; 1+6+2=9 extra () before this: |
| @@ -2515,40 +2968,48 @@ the sections using `cperl-pod-head-face', `cperl-pod-face', | |||
| 2515 | (not (eq (char-after | 2968 | (not (eq (char-after |
| 2516 | (- (match-beginning b1) 2)) | 2969 | (- (match-beginning b1) 2)) |
| 2517 | ?\&)))))) | 2970 | ?\&)))))) |
| 2971 | (goto-char (match-beginning b1)) | ||
| 2972 | (cperl-backward-to-noncomment (point-min)) | ||
| 2518 | (or bb | 2973 | (or bb |
| 2519 | (if (eq b1 11) ; bare /blah/ or ?blah? | 2974 | (if (eq b1 11) ; bare /blah/ or ?blah? |
| 2520 | (setq argument "" | 2975 | (setq argument "" |
| 2521 | bb ; Not a regexp? | 2976 | bb ; Not a regexp? |
| 2522 | (progn | 2977 | (progn |
| 2523 | (goto-char (match-beginning b1)) | 2978 | (not |
| 2524 | (cperl-backward-to-noncomment (point-min)) | 2979 | ;; What is below: regexp-p? |
| 2525 | (not | 2980 | (and |
| 2526 | ;; What is below: regexp-p? | 2981 | (or (memq (preceding-char) |
| 2527 | (and | 2982 | (append (if (eq c ?\?) |
| 2528 | (or (memq (preceding-char) | 2983 | ;; $a++ ? 1 : 2 |
| 2529 | (append (if (eq c ?\?) | 2984 | "~{(=|&*!,;" |
| 2530 | ;; $a++ ? 1 : 2 | 2985 | "~{(=|&+-*!,;") nil)) |
| 2531 | "~{(=|&*!,;" | 2986 | (and (eq (preceding-char) ?\}) |
| 2532 | "~{(=|&+-*!,;") nil)) | 2987 | (cperl-after-block-p (point-min))) |
| 2533 | (and (eq (preceding-char) ?\}) | 2988 | (and (eq (char-syntax (preceding-char)) ?w) |
| 2534 | (cperl-after-block-p (point-min))) | 2989 | (progn |
| 2535 | (and (eq (char-syntax (preceding-char)) ?w) | 2990 | (forward-sexp -1) |
| 2536 | (progn | 2991 | ;;; After these keywords `/' starts a RE. One should add all the |
| 2537 | (forward-sexp -1) | 2992 | ;;; functions/builtins which expect an argument, but ... |
| 2538 | (looking-at | 2993 | (looking-at |
| 2539 | "\\(while\\|if\\|unless\\|until\\|and\\|or\\|not\\|xor\\|split\\|grep\\|map\\|print\\)\\>"))) | 2994 | "\\(while\\|if\\|unless\\|until\\|and\\|or\\|not\\|xor\\|split\\|grep\\|map\\|print\\)\\>"))) |
| 2540 | (and (eq (preceding-char) ?.) | 2995 | (and (eq (preceding-char) ?.) |
| 2541 | (eq (char-after (- (point) 2)) ?.)) | 2996 | (eq (char-after (- (point) 2)) ?.)) |
| 2542 | (bobp)) | 2997 | (bobp)) |
| 2543 | ;; m|blah| ? foo : bar; | 2998 | ;; m|blah| ? foo : bar; |
| 2544 | (not | 2999 | (not |
| 2545 | (and (eq c ?\?) | 3000 | (and (eq c ?\?) |
| 2546 | cperl-use-syntax-table-text-property | 3001 | cperl-use-syntax-table-text-property |
| 2547 | (not (bobp)) | 3002 | (not (bobp)) |
| 2548 | (progn | 3003 | (progn |
| 2549 | (forward-char -1) | 3004 | (forward-char -1) |
| 2550 | (looking-at "\\s|"))))))) | 3005 | (looking-at "\\s|"))))))) |
| 2551 | b (1- b)))) | 3006 | b (1- b)) |
| 3007 | ;; s y tr m | ||
| 3008 | ;; Check for $a->y | ||
| 3009 | (if (and (eq (preceding-char) ?>) | ||
| 3010 | (eq (char-after (- (point) 2)) ?-)) | ||
| 3011 | ;; Not a regexp | ||
| 3012 | (setq bb t)))) | ||
| 2552 | (or bb (setq state (parse-partial-sexp | 3013 | (or bb (setq state (parse-partial-sexp |
| 2553 | state-point b nil nil state) | 3014 | state-point b nil nil state) |
| 2554 | state-point b)) | 3015 | state-point b)) |
| @@ -2562,9 +3023,11 @@ the sections using `cperl-pod-head-face', `cperl-pod-face', | |||
| 2562 | ;; 2 or 3 later if some special quoting is needed. | 3023 | ;; 2 or 3 later if some special quoting is needed. |
| 2563 | ;; e1 means matching-char matcher. | 3024 | ;; e1 means matching-char matcher. |
| 2564 | (setq b (point) | 3025 | (setq b (point) |
| 2565 | i (cperl-forward-re max end | 3026 | ;; We do not search to max, since we may be called from |
| 2566 | (string-match "^\\([sy]\\|tr\\)$" argument) | 3027 | ;; some hook of fontification, and max is random |
| 2567 | t st-l err-l argument) | 3028 | i (cperl-forward-re stop-point end |
| 3029 | (string-match "^\\([sy]\\|tr\\)$" argument) | ||
| 3030 | t st-l err-l argument) | ||
| 2568 | i2 (nth 1 i) ; start of the second part | 3031 | i2 (nth 1 i) ; start of the second part |
| 2569 | e1 (nth 2 i) ; ender, true if matching second part | 3032 | e1 (nth 2 i) ; ender, true if matching second part |
| 2570 | go (nth 4 i) ; There is a 1-char part after the end | 3033 | go (nth 4 i) ; There is a 1-char part after the end |
| @@ -2593,7 +3056,7 @@ the sections using `cperl-pod-head-face', `cperl-pod-face', | |||
| 2593 | (cperl-modify-syntax-type i cperl-st-bra)))) | 3056 | (cperl-modify-syntax-type i cperl-st-bra)))) |
| 2594 | (cperl-commentify i2 (point) t) | 3057 | (cperl-commentify i2 (point) t) |
| 2595 | (if e | 3058 | (if e |
| 2596 | (cperl-modify-syntax-type (1+ i) cperl-st-punct)) | 3059 | (cperl-modify-syntax-type (1+ i) cperl-st-punct)) |
| 2597 | (setq tail nil))) | 3060 | (setq tail nil))) |
| 2598 | (if (eq (char-syntax (following-char)) ?w) | 3061 | (if (eq (char-syntax (following-char)) ?w) |
| 2599 | (progn | 3062 | (progn |
| @@ -2615,7 +3078,7 @@ the sections using `cperl-pod-head-face', `cperl-pod-face', | |||
| 2615 | ;; 1+6+2+1+1+2=13 extra () before this: | 3078 | ;; 1+6+2+1+1+2=13 extra () before this: |
| 2616 | ;; "\\$\\(['{]\\)" | 3079 | ;; "\\$\\(['{]\\)" |
| 2617 | ((and (match-beginning 14) | 3080 | ((and (match-beginning 14) |
| 2618 | (eq (preceding-char) ?\')) ; $' | 3081 | (eq (preceding-char) ?\')) ; $' |
| 2619 | (setq b (1- (point)) | 3082 | (setq b (1- (point)) |
| 2620 | state (parse-partial-sexp | 3083 | state (parse-partial-sexp |
| 2621 | state-point (1- b) nil nil state) | 3084 | state-point (1- b) nil nil state) |
| @@ -2654,111 +3117,18 @@ the sections using `cperl-pod-head-face', `cperl-pod-face', | |||
| 2654 | (cperl-commentify b bb nil) | 3117 | (cperl-commentify b bb nil) |
| 2655 | (setq end t)) | 3118 | (setq end t)) |
| 2656 | (goto-char bb))) | 3119 | (goto-char bb))) |
| 2657 | (if (> (point) max) | 3120 | (if (> (point) stop-point) |
| 2658 | (progn | 3121 | (progn |
| 2659 | (if end | 3122 | (if end |
| 2660 | (message "Garbage after __END__/__DATA__ ignored") | 3123 | (message "Garbage after __END__/__DATA__ ignored") |
| 2661 | (message "Unbalanced syntax found while scanning") | 3124 | (message "Unbalanced syntax found while scanning") |
| 2662 | (or (car err-l) (setcar err-l b))) | 3125 | (or (car err-l) (setcar err-l b))) |
| 2663 | (goto-char max)))) | 3126 | (goto-char stop-point)))) |
| 2664 | ;;; (while (re-search-forward "\\(\\`\n?\\|\n\n\\)=" max t) | 3127 | (setq cperl-syntax-state (cons state-point state) |
| 2665 | ;;; (if (looking-at "\n*cut\\>") | 3128 | cperl-syntax-done-to (max (point) max))) |
| 2666 | ;;; (progn | ||
| 2667 | ;;; (message "=cut is not preceded by a pod section") | ||
| 2668 | ;;; (setq err (point))) | ||
| 2669 | ;;; (beginning-of-line) | ||
| 2670 | |||
| 2671 | ;;; (setq b (point) bb b) | ||
| 2672 | ;;; (or (re-search-forward "\n\n=cut\\>" max 'toend) | ||
| 2673 | ;;; (message "Cannot find the end of a pod section")) | ||
| 2674 | ;;; (beginning-of-line 3) | ||
| 2675 | ;;; (setq e (point)) | ||
| 2676 | ;;; (put-text-property b e 'in-pod t) | ||
| 2677 | ;;; (goto-char b) | ||
| 2678 | ;;; (while (re-search-forward "\n\n[ \t]" e t) | ||
| 2679 | ;;; (beginning-of-line) | ||
| 2680 | ;;; (put-text-property b (point) 'syntax-type 'pod) | ||
| 2681 | ;;; (cperl-put-do-not-fontify b (point)) | ||
| 2682 | ;;; ;;(put-text-property (max (point-min) (1- b)) | ||
| 2683 | ;;; ;; (point) cperl-do-not-fontify t) | ||
| 2684 | ;;; (if cperl-pod-here-fontify (put-text-property b (point) 'face face)) | ||
| 2685 | ;;; (re-search-forward "\n\n[^ \t\f\n]" e 'toend) | ||
| 2686 | ;;; (beginning-of-line) | ||
| 2687 | ;;; (setq b (point))) | ||
| 2688 | ;;; (put-text-property (point) e 'syntax-type 'pod) | ||
| 2689 | ;;; (cperl-put-do-not-fontify (point) e) | ||
| 2690 | ;;; ;;(put-text-property (max (point-min) (1- (point))) | ||
| 2691 | ;;; ;; e cperl-do-not-fontify t) | ||
| 2692 | ;;; (if cperl-pod-here-fontify | ||
| 2693 | ;;; (progn (put-text-property (point) e 'face face) | ||
| 2694 | ;;; (goto-char bb) | ||
| 2695 | ;;; (if (looking-at | ||
| 2696 | ;;; "=[a-zA-Z0-9]+\\>[ \t]*\\(\\(\n?[^\n]\\)+\\)$") | ||
| 2697 | ;;; (put-text-property | ||
| 2698 | ;;; (match-beginning 1) (match-end 1) | ||
| 2699 | ;;; 'face head-face)) | ||
| 2700 | ;;; (while (re-search-forward | ||
| 2701 | ;;; ;; One paragraph | ||
| 2702 | ;;; "\n\n=[a-zA-Z0-9]+\\>[ \t]*\\(\\(\n?[^\n]\\)+\\)$" | ||
| 2703 | ;;; e 'toend) | ||
| 2704 | ;;; (put-text-property | ||
| 2705 | ;;; (match-beginning 1) (match-end 1) | ||
| 2706 | ;;; 'face head-face)))) | ||
| 2707 | ;;; (goto-char e))) | ||
| 2708 | ;;; (goto-char min) | ||
| 2709 | ;;; (while (re-search-forward | ||
| 2710 | ;;; ;; We exclude \n to avoid misrecognition inside quotes. | ||
| 2711 | ;;; "<<\\(\\([\"'`]\\)\\([^\"'`\n]*\\)\\2\\|\\(\\([a-zA-Z_][a-zA-Z_0-9]*\\)?\\)\\)" | ||
| 2712 | ;;; max t) | ||
| 2713 | ;;; (if (match-beginning 4) | ||
| 2714 | ;;; (setq b1 (match-beginning 4) | ||
| 2715 | ;;; e1 (match-end 4)) | ||
| 2716 | ;;; (setq b1 (match-beginning 3) | ||
| 2717 | ;;; e1 (match-end 3))) | ||
| 2718 | ;;; (setq tag (buffer-substring b1 e1) | ||
| 2719 | ;;; qtag (regexp-quote tag)) | ||
| 2720 | ;;; (cond (cperl-pod-here-fontify | ||
| 2721 | ;;; (put-text-property b1 e1 'face font-lock-constant-face) | ||
| 2722 | ;;; (cperl-put-do-not-fontify b1 e1))) | ||
| 2723 | ;;; (forward-line) | ||
| 2724 | ;;; (setq b (point)) | ||
| 2725 | ;;; (cond ((re-search-forward (concat "^" qtag "$") max 'toend) | ||
| 2726 | ;;; (if cperl-pod-here-fontify | ||
| 2727 | ;;; (progn | ||
| 2728 | ;;; (put-text-property (match-beginning 0) (match-end 0) | ||
| 2729 | ;;; 'face font-lock-constant-face) | ||
| 2730 | ;;; (cperl-put-do-not-fontify b (match-end 0)) | ||
| 2731 | ;;; ;;(put-text-property (max (point-min) (1- b)) | ||
| 2732 | ;;; ;; (min (point-max) | ||
| 2733 | ;;; ;; (1+ (match-end 0))) | ||
| 2734 | ;;; ;; cperl-do-not-fontify t) | ||
| 2735 | ;;; (put-text-property b (match-beginning 0) | ||
| 2736 | ;;; 'face here-face))) | ||
| 2737 | ;;; (put-text-property b (match-beginning 0) | ||
| 2738 | ;;; 'syntax-type 'here-doc) | ||
| 2739 | ;;; (cperl-put-do-not-fontify b (match-beginning 0))) | ||
| 2740 | ;;; (t (message "End of here-document `%s' not found." tag)))) | ||
| 2741 | ;;; (goto-char min) | ||
| 2742 | ;;; (while (re-search-forward | ||
| 2743 | ;;; "^[ \t]*format[ \t]*\\(\\([a-zA-Z0-9_]+[ \t]*\\)?\\)=[ \t]*$" | ||
| 2744 | ;;; max t) | ||
| 2745 | ;;; (setq b (point) | ||
| 2746 | ;;; name (buffer-substring (match-beginning 1) | ||
| 2747 | ;;; (match-end 1))) | ||
| 2748 | ;;; (cond ((re-search-forward (concat "^[.;]$") max 'toend) | ||
| 2749 | ;;; (if cperl-pod-here-fontify | ||
| 2750 | ;;; (progn | ||
| 2751 | ;;; (put-text-property b (match-end 0) | ||
| 2752 | ;;; 'face font-lock-string-face) | ||
| 2753 | ;;; (cperl-put-do-not-fontify b (match-end 0)))) | ||
| 2754 | ;;; (put-text-property b (match-end 0) | ||
| 2755 | ;;; 'syntax-type 'format) | ||
| 2756 | ;;; (cperl-put-do-not-fontify b (match-beginning 0))) | ||
| 2757 | ;;; (t (message "End of format `%s' not found." name)))) | ||
| 2758 | ) | ||
| 2759 | (if (car err-l) (goto-char (car err-l)) | 3129 | (if (car err-l) (goto-char (car err-l)) |
| 2760 | (or noninteractive | 3130 | (or non-inter |
| 2761 | (message "Scan for \"hard\" Perl constructions completed.")))) | 3131 | (message "Scanning for \"hard\" Perl constructions... done")))) |
| 2762 | (and (buffer-modified-p) | 3132 | (and (buffer-modified-p) |
| 2763 | (not modified) | 3133 | (not modified) |
| 2764 | (set-buffer-modified-p nil)) | 3134 | (set-buffer-modified-p nil)) |
| @@ -2787,12 +3157,19 @@ the sections using `cperl-pod-head-face', `cperl-pod-face', | |||
| 2787 | (progn | 3157 | (progn |
| 2788 | (forward-sexp -1) | 3158 | (forward-sexp -1) |
| 2789 | (cperl-backward-to-noncomment lim) | 3159 | (cperl-backward-to-noncomment lim) |
| 2790 | (or (eq (preceding-char) ?\) ) ; if () {} | 3160 | (or (eq (preceding-char) ?\) ) ; if () {} sub f () {} |
| 2791 | (and (eq (char-syntax (preceding-char)) ?w) ; else {} | 3161 | (if (eq (char-syntax (preceding-char)) ?w) ; else {} |
| 2792 | (progn | 3162 | (save-excursion |
| 2793 | (forward-sexp -1) | 3163 | (forward-sexp -1) |
| 2794 | (looking-at "\\(else\\|grep\\|map\\)\\>"))) | 3164 | (or (looking-at "\\(else\\|grep\\|map\\)\\>") |
| 2795 | (cperl-after-expr-p lim))) | 3165 | ;; sub f {} |
| 3166 | (progn | ||
| 3167 | (cperl-backward-to-noncomment lim) | ||
| 3168 | (and (eq (char-syntax (preceding-char)) ?w) | ||
| 3169 | (progn | ||
| 3170 | (forward-sexp -1) | ||
| 3171 | (looking-at "sub\\>")))))) | ||
| 3172 | (cperl-after-expr-p lim)))) | ||
| 2796 | (error nil)))) | 3173 | (error nil)))) |
| 2797 | 3174 | ||
| 2798 | (defun cperl-after-expr-p (&optional lim chars test) | 3175 | (defun cperl-after-expr-p (&optional lim chars test) |
| @@ -2828,6 +3205,21 @@ CHARS is a string that contains good characters to have before us (however, | |||
| 2828 | (goto-char (1+ lim))) | 3205 | (goto-char (1+ lim))) |
| 2829 | (skip-chars-forward " \t")) | 3206 | (skip-chars-forward " \t")) |
| 2830 | 3207 | ||
| 3208 | (defun cperl-after-block-and-statement-beg (lim) | ||
| 3209 | ;; We assume that we are after ?\} | ||
| 3210 | (and | ||
| 3211 | (cperl-after-block-p lim) | ||
| 3212 | (save-excursion | ||
| 3213 | (forward-sexp -1) | ||
| 3214 | (cperl-backward-to-noncomment (point-min)) | ||
| 3215 | (or (bobp) | ||
| 3216 | (not (= (char-syntax (preceding-char)) ?w)) | ||
| 3217 | (progn | ||
| 3218 | (forward-sexp -1) | ||
| 3219 | (not | ||
| 3220 | (looking-at | ||
| 3221 | "\\(map\\|grep\\|printf?\\|system\\|exec\\|tr\\|s\\)\\>"))))))) | ||
| 3222 | |||
| 2831 | 3223 | ||
| 2832 | (defvar innerloop-done nil) | 3224 | (defvar innerloop-done nil) |
| 2833 | (defvar last-depth nil) | 3225 | (defvar last-depth nil) |
| @@ -2835,7 +3227,10 @@ CHARS is a string that contains good characters to have before us (however, | |||
| 2835 | (defun cperl-indent-exp () | 3227 | (defun cperl-indent-exp () |
| 2836 | "Simple variant of indentation of continued-sexp. | 3228 | "Simple variant of indentation of continued-sexp. |
| 2837 | Should be slow. Will not indent comment if it starts at `comment-indent' | 3229 | Should be slow. Will not indent comment if it starts at `comment-indent' |
| 2838 | or looks like continuation of the comment on the previous line." | 3230 | or looks like continuation of the comment on the previous line. |
| 3231 | |||
| 3232 | If `cperl-indent-region-fix-constructs', will improve spacing on | ||
| 3233 | conditional/loop constructs." | ||
| 2839 | (interactive) | 3234 | (interactive) |
| 2840 | (save-excursion | 3235 | (save-excursion |
| 2841 | (let ((tmp-end (progn (end-of-line) (point))) top done) | 3236 | (let ((tmp-end (progn (end-of-line) (point))) top done) |
| @@ -2854,17 +3249,186 @@ or looks like continuation of the comment on the previous line." | |||
| 2854 | (setq done t))) | 3249 | (setq done t))) |
| 2855 | (goto-char tmp-end) | 3250 | (goto-char tmp-end) |
| 2856 | (setq tmp-end (point-marker))) | 3251 | (setq tmp-end (point-marker))) |
| 3252 | (if cperl-indent-region-fix-constructs | ||
| 3253 | (cperl-fix-line-spacing tmp-end)) | ||
| 2857 | (cperl-indent-region (point) tmp-end)))) | 3254 | (cperl-indent-region (point) tmp-end)))) |
| 2858 | 3255 | ||
| 3256 | (defun cperl-fix-line-spacing (&optional end) | ||
| 3257 | "Improve whitespace in a conditional/loop construct." | ||
| 3258 | (interactive) | ||
| 3259 | (or end | ||
| 3260 | (setq end (point-max))) | ||
| 3261 | (let (p pp ml | ||
| 3262 | (cperl-indent-region-fix-constructs | ||
| 3263 | (or cperl-indent-region-fix-constructs 1))) | ||
| 3264 | (save-excursion | ||
| 3265 | (beginning-of-line) | ||
| 3266 | ;; Looking at: | ||
| 3267 | ;; } | ||
| 3268 | ;; else | ||
| 3269 | (if (and cperl-merge-trailing-else | ||
| 3270 | (looking-at | ||
| 3271 | "[ \t]*}[ \t]*\n[ \t\n]*\\(els\\(e\\|if\\)\\|continue\\)\\>")) | ||
| 3272 | (progn | ||
| 3273 | (search-forward "}") | ||
| 3274 | (setq p (point)) | ||
| 3275 | (skip-chars-forward " \t\n") | ||
| 3276 | (delete-region p (point)) | ||
| 3277 | (insert (make-string cperl-indent-region-fix-constructs ?\ )) | ||
| 3278 | (beginning-of-line))) | ||
| 3279 | ;; Looking at: | ||
| 3280 | ;; } else | ||
| 3281 | (if (looking-at "[ \t]*}\\(\t*\\|[ \t][ \t]+\\)\\<\\(els\\(e\\|if\\)\\|continue\\)\\>") | ||
| 3282 | (progn | ||
| 3283 | (search-forward "}") | ||
| 3284 | (delete-horizontal-space) | ||
| 3285 | (insert (make-string cperl-indent-region-fix-constructs ?\ )) | ||
| 3286 | (beginning-of-line))) | ||
| 3287 | ;; Looking at: | ||
| 3288 | ;; else { | ||
| 3289 | (if (looking-at | ||
| 3290 | "[ \t]*}?[ \t]*\\<\\(\\els\\(e\\|if\\)\\|continue\\|if\\|while\\|for\\(each\\)?\\|until\\)\\>\\(\t*\\|[ \t][ \t]+\\)[^ \t\n#]") | ||
| 3291 | (progn | ||
| 3292 | (forward-word 1) | ||
| 3293 | (delete-horizontal-space) | ||
| 3294 | (insert (make-string cperl-indent-region-fix-constructs ?\ )) | ||
| 3295 | (beginning-of-line))) | ||
| 3296 | ;; Looking at: | ||
| 3297 | ;; foreach my $var | ||
| 3298 | (if (looking-at | ||
| 3299 | "[ \t]*\\<for\\(each\\)?[ \t]+\\(my\\|local\\)\\(\t*\\|[ \t][ \t]+\\)[^ \t\n]") | ||
| 3300 | (progn | ||
| 3301 | (forward-word 2) | ||
| 3302 | (delete-horizontal-space) | ||
| 3303 | (insert (make-string cperl-indent-region-fix-constructs ?\ )) | ||
| 3304 | (beginning-of-line))) | ||
| 3305 | ;; Looking at: | ||
| 3306 | ;; foreach my $var ( | ||
| 3307 | (if (looking-at | ||
| 3308 | "[ \t]*\\<for\\(each\\)?[ \t]+\\(my\\|local\\)[ \t]*\\$[_a-zA-Z0-9]+\\(\t*\\|[ \t][ \t]+\\)[^ \t\n#]") | ||
| 3309 | (progn | ||
| 3310 | (forward-word 3) | ||
| 3311 | (delete-horizontal-space) | ||
| 3312 | (insert | ||
| 3313 | (make-string cperl-indent-region-fix-constructs ?\ )) | ||
| 3314 | (beginning-of-line))) | ||
| 3315 | ;; Looking at: | ||
| 3316 | ;; } foreach my $var () { | ||
| 3317 | (if (looking-at | ||
| 3318 | "[ \t]*\\(}[ \t]*\\)?\\<\\(\\els\\(e\\|if\\)\\|continue\\|if\\|while\\|for\\(each\\)?\\(\\([ t]+\\(my\\|local\\)\\)?[ \t]*\\$[_a-zA-Z0-9]+\\)?\\|until\\)\\>\\([ \t]*(\\|[ \t\n]*{\\)\\|[ \t]*{") | ||
| 3319 | (progn | ||
| 3320 | (setq ml (match-beginning 8)) | ||
| 3321 | (re-search-forward "[({]") | ||
| 3322 | (forward-char -1) | ||
| 3323 | (setq p (point)) | ||
| 3324 | (if (eq (following-char) ?\( ) | ||
| 3325 | (progn | ||
| 3326 | (forward-sexp 1) | ||
| 3327 | (setq pp (point))) | ||
| 3328 | ;; after `else' or nothing | ||
| 3329 | (if ml ; after `else' | ||
| 3330 | (skip-chars-backward " \t\n") | ||
| 3331 | (beginning-of-line)) | ||
| 3332 | (setq pp nil)) | ||
| 3333 | ;; Now after the sexp before the brace | ||
| 3334 | ;; Multiline expr should be special | ||
| 3335 | (setq ml (and pp (save-excursion (goto-char p) | ||
| 3336 | (search-forward "\n" pp t)))) | ||
| 3337 | (if (and (or (not pp) (< pp end)) | ||
| 3338 | (looking-at "[ \t\n]*{")) | ||
| 3339 | (progn | ||
| 3340 | (cond | ||
| 3341 | ((bolp) ; Were before `{', no if/else/etc | ||
| 3342 | nil) | ||
| 3343 | ((looking-at "\\(\t*\\| [ \t]+\\){") | ||
| 3344 | (delete-horizontal-space) | ||
| 3345 | (if (if ml | ||
| 3346 | cperl-extra-newline-before-brace-multiline | ||
| 3347 | cperl-extra-newline-before-brace) | ||
| 3348 | (progn | ||
| 3349 | (delete-horizontal-space) | ||
| 3350 | (insert "\n") | ||
| 3351 | (if (cperl-indent-line) | ||
| 3352 | (cperl-fix-line-spacing end))) | ||
| 3353 | (insert | ||
| 3354 | (make-string cperl-indent-region-fix-constructs ?\ )))) | ||
| 3355 | ((and (looking-at "[ \t]*\n") | ||
| 3356 | (not (if ml | ||
| 3357 | cperl-extra-newline-before-brace-multiline | ||
| 3358 | cperl-extra-newline-before-brace))) | ||
| 3359 | (setq pp (point)) | ||
| 3360 | (skip-chars-forward " \t\n") | ||
| 3361 | (delete-region pp (point)) | ||
| 3362 | (insert | ||
| 3363 | (make-string cperl-indent-region-fix-constructs ?\ )))) | ||
| 3364 | ;; Now we are before `{' | ||
| 3365 | (if (looking-at "[ \t\n]*{[ \t]*[^ \t\n#]") | ||
| 3366 | (progn | ||
| 3367 | (skip-chars-forward " \t\n") | ||
| 3368 | (setq pp (point)) | ||
| 3369 | (forward-sexp 1) | ||
| 3370 | (setq p (point)) | ||
| 3371 | (goto-char pp) | ||
| 3372 | (setq ml (search-forward "\n" p t)) | ||
| 3373 | (if (or cperl-break-one-line-blocks-when-indent ml) | ||
| 3374 | ;; not good: multi-line BLOCK | ||
| 3375 | (progn | ||
| 3376 | (goto-char (1+ pp)) | ||
| 3377 | (delete-horizontal-space) | ||
| 3378 | (insert "\n") | ||
| 3379 | (if (cperl-indent-line) | ||
| 3380 | (cperl-fix-line-spacing end)))))))))) | ||
| 3381 | (beginning-of-line) | ||
| 3382 | (setq p (point) pp (save-excursion (end-of-line) (point))) | ||
| 3383 | ;; Now check whether there is a hanging `}' | ||
| 3384 | ;; Looking at: | ||
| 3385 | ;; } blah | ||
| 3386 | (if (and | ||
| 3387 | cperl-fix-hanging-brace-when-indent | ||
| 3388 | (not (looking-at "[ \t]*}[ \t]*\\(\\<\\(els\\(if\\|e\\)\\|continue\\|while\\|until\\)\\>\\|$\\|#\\)")) | ||
| 3389 | (condition-case nil | ||
| 3390 | (progn | ||
| 3391 | (up-list 1) | ||
| 3392 | (if (and (<= (point) pp) | ||
| 3393 | (eq (preceding-char) ?\} ) | ||
| 3394 | (cperl-after-block-and-statement-beg (point-min))) | ||
| 3395 | t | ||
| 3396 | (goto-char p) | ||
| 3397 | nil)) | ||
| 3398 | (error nil))) | ||
| 3399 | (progn | ||
| 3400 | (forward-char -1) | ||
| 3401 | (skip-chars-backward " \t") | ||
| 3402 | (if (bolp) | ||
| 3403 | ;; `}' was the first thing on the line, insert NL *after* it. | ||
| 3404 | (progn | ||
| 3405 | (cperl-indent-line) | ||
| 3406 | (search-forward "}") | ||
| 3407 | (delete-horizontal-space) | ||
| 3408 | (insert "\n")) | ||
| 3409 | (delete-horizontal-space) | ||
| 3410 | (or (eq (preceding-char) ?\;) | ||
| 3411 | (bolp) | ||
| 3412 | (and (eq (preceding-char) ?\} ) | ||
| 3413 | (cperl-after-block-p (point-min))) | ||
| 3414 | (insert ";")) | ||
| 3415 | (insert "\n")) | ||
| 3416 | (if (cperl-indent-line) | ||
| 3417 | (cperl-fix-line-spacing end)) | ||
| 3418 | (beginning-of-line)))))) | ||
| 3419 | |||
| 2859 | (defun cperl-indent-region (start end) | 3420 | (defun cperl-indent-region (start end) |
| 2860 | "Simple variant of indentation of region in CPerl mode. | 3421 | "Simple variant of indentation of region in CPerl mode. |
| 2861 | Should be slow. Will not indent comment if it starts at `comment-indent' | 3422 | Should be slow. Will not indent comment if it starts at `comment-indent' |
| 2862 | or looks like continuation of the comment on the previous line. | 3423 | or looks like continuation of the comment on the previous line. |
| 2863 | Indents all the lines whose first character is between START and END | 3424 | Indents all the lines whose first character is between START and END |
| 2864 | inclusive." | 3425 | inclusive. |
| 3426 | |||
| 3427 | If `cperl-indent-region-fix-constructs', will improve spacing on | ||
| 3428 | conditional/loop constructs." | ||
| 2865 | (interactive "r") | 3429 | (interactive "r") |
| 2866 | (save-excursion | 3430 | (save-excursion |
| 2867 | (let (st comm indent-info old-comm-indent new-comm-indent | 3431 | (let (st comm indent-info old-comm-indent new-comm-indent p pp i |
| 2868 | (pm 0) (imenu-scanning-message "Indenting... (%3d%%)")) | 3432 | (pm 0) (imenu-scanning-message "Indenting... (%3d%%)")) |
| 2869 | (goto-char start) | 3433 | (goto-char start) |
| 2870 | (setq old-comm-indent (and (cperl-to-comment-or-eol) | 3434 | (setq old-comm-indent (and (cperl-to-comment-or-eol) |
| @@ -2891,9 +3455,12 @@ inclusive." | |||
| 2891 | (let ((comment-column new-comm-indent)) | 3455 | (let ((comment-column new-comm-indent)) |
| 2892 | (indent-for-comment))) | 3456 | (indent-for-comment))) |
| 2893 | (progn | 3457 | (progn |
| 2894 | (cperl-indent-line 'indent-info) | 3458 | (setq i (cperl-indent-line 'indent-info)) |
| 2895 | (or comm | 3459 | (or comm |
| 3460 | (not i) | ||
| 2896 | (progn | 3461 | (progn |
| 3462 | (if cperl-indent-region-fix-constructs | ||
| 3463 | (cperl-fix-line-spacing end)) | ||
| 2897 | (if (setq old-comm-indent | 3464 | (if (setq old-comm-indent |
| 2898 | (and (cperl-to-comment-or-eol) | 3465 | (and (cperl-to-comment-or-eol) |
| 2899 | (not (memq (get-text-property (point) | 3466 | (not (memq (get-text-property (point) |
| @@ -2909,17 +3476,6 @@ inclusive." | |||
| 2909 | (imenu-progress-message pm 100) | 3476 | (imenu-progress-message pm 100) |
| 2910 | (message nil))))) | 3477 | (message nil))))) |
| 2911 | 3478 | ||
| 2912 | ;;(defun cperl-slash-is-regexp (&optional pos) | ||
| 2913 | ;; (save-excursion | ||
| 2914 | ;; (goto-char (if pos pos (1- (point)))) | ||
| 2915 | ;; (and | ||
| 2916 | ;; (not (memq (get-text-property (point) 'face) | ||
| 2917 | ;; '(font-lock-string-face font-lock-comment-face))) | ||
| 2918 | ;; (cperl-after-expr-p nil nil ' | ||
| 2919 | ;; (or (looking-at "[^]a-zA-Z0-9_)}]") | ||
| 2920 | ;; (eq (get-text-property (point) 'face) | ||
| 2921 | ;; 'font-lock-keyword-face)))))) | ||
| 2922 | |||
| 2923 | ;; Stolen from lisp-mode with a lot of improvements | 3479 | ;; Stolen from lisp-mode with a lot of improvements |
| 2924 | 3480 | ||
| 2925 | (defun cperl-fill-paragraph (&optional justify iteration) | 3481 | (defun cperl-fill-paragraph (&optional justify iteration) |
| @@ -3076,7 +3632,6 @@ indentation and initial hashes. Behaves usually outside of comment." | |||
| 3076 | nil t) | 3632 | nil t) |
| 3077 | (or noninteractive | 3633 | (or noninteractive |
| 3078 | (imenu-progress-message prev-pos)) | 3634 | (imenu-progress-message prev-pos)) |
| 3079 | ;;(backward-up-list 1) | ||
| 3080 | (cond | 3635 | (cond |
| 3081 | ((and ; Skip some noise if building tags | 3636 | ((and ; Skip some noise if building tags |
| 3082 | (match-beginning 2) ; package or sub | 3637 | (match-beginning 2) ; package or sub |
| @@ -3215,18 +3770,35 @@ indentation and initial hashes. Behaves usually outside of comment." | |||
| 3215 | cperl-compilation-error-regexp-alist))) | 3770 | cperl-compilation-error-regexp-alist))) |
| 3216 | 3771 | ||
| 3217 | 3772 | ||
| 3218 | (defvar cperl-faces-init nil) | ||
| 3219 | |||
| 3220 | (defun cperl-windowed-init () | 3773 | (defun cperl-windowed-init () |
| 3221 | "Initialization under windowed version." | 3774 | "Initialization under windowed version." |
| 3222 | (add-hook 'font-lock-mode-hook | 3775 | (if (or (featurep 'ps-print) cperl-faces-init) |
| 3223 | (function | 3776 | ;; Need to init anyway: |
| 3224 | (lambda () | 3777 | (or cperl-faces-init (cperl-init-faces)) |
| 3225 | (if (or | 3778 | (add-hook 'font-lock-mode-hook |
| 3226 | (eq major-mode 'perl-mode) | 3779 | (function |
| 3227 | (eq major-mode 'cperl-mode)) | 3780 | (lambda () |
| 3228 | (progn | 3781 | (if (or |
| 3229 | (or cperl-faces-init (cperl-init-faces)))))))) | 3782 | (eq major-mode 'perl-mode) |
| 3783 | (eq major-mode 'cperl-mode)) | ||
| 3784 | (progn | ||
| 3785 | (or cperl-faces-init (cperl-init-faces))))))) | ||
| 3786 | (if (fboundp 'eval-after-load) | ||
| 3787 | (eval-after-load | ||
| 3788 | "ps-print" | ||
| 3789 | '(or cperl-faces-init (cperl-init-faces)))))) | ||
| 3790 | |||
| 3791 | (defun cperl-load-font-lock-keywords () | ||
| 3792 | (or cperl-faces-init (cperl-init-faces)) | ||
| 3793 | perl-font-lock-keywords) | ||
| 3794 | |||
| 3795 | (defun cperl-load-font-lock-keywords-1 () | ||
| 3796 | (or cperl-faces-init (cperl-init-faces)) | ||
| 3797 | perl-font-lock-keywords-1) | ||
| 3798 | |||
| 3799 | (defun cperl-load-font-lock-keywords-2 () | ||
| 3800 | (or cperl-faces-init (cperl-init-faces)) | ||
| 3801 | perl-font-lock-keywords-2) | ||
| 3230 | 3802 | ||
| 3231 | (defvar perl-font-lock-keywords-1 nil | 3803 | (defvar perl-font-lock-keywords-1 nil |
| 3232 | "Additional expressions to highlight in Perl mode. Minimal set.") | 3804 | "Additional expressions to highlight in Perl mode. Minimal set.") |
| @@ -3235,6 +3807,8 @@ indentation and initial hashes. Behaves usually outside of comment." | |||
| 3235 | (defvar perl-font-lock-keywords-2 nil | 3807 | (defvar perl-font-lock-keywords-2 nil |
| 3236 | "Additional expressions to highlight in Perl mode. Maximal set") | 3808 | "Additional expressions to highlight in Perl mode. Maximal set") |
| 3237 | 3809 | ||
| 3810 | (defvar font-lock-background-mode) | ||
| 3811 | (defvar font-lock-display-type) | ||
| 3238 | (defun cperl-init-faces () | 3812 | (defun cperl-init-faces () |
| 3239 | (condition-case nil | 3813 | (condition-case nil |
| 3240 | (progn | 3814 | (progn |
| @@ -3243,8 +3817,6 @@ indentation and initial hashes. Behaves usually outside of comment." | |||
| 3243 | (featurep 'font-lock-extra) | 3817 | (featurep 'font-lock-extra) |
| 3244 | (message "You have an obsolete package `font-lock-extra'. Install `choose-color'.")) | 3818 | (message "You have an obsolete package `font-lock-extra'. Install `choose-color'.")) |
| 3245 | (let (t-font-lock-keywords t-font-lock-keywords-1 font-lock-anchored) | 3819 | (let (t-font-lock-keywords t-font-lock-keywords-1 font-lock-anchored) |
| 3246 | ;;(defvar cperl-font-lock-enhanced nil | ||
| 3247 | ;; "Set to be non-nil if font-lock allows active highlights.") | ||
| 3248 | (if (fboundp 'font-lock-fontify-anchored-keywords) | 3820 | (if (fboundp 'font-lock-fontify-anchored-keywords) |
| 3249 | (setq font-lock-anchored t)) | 3821 | (setq font-lock-anchored t)) |
| 3250 | (setq | 3822 | (setq |
| @@ -3381,7 +3953,7 @@ indentation and initial hashes. Behaves usually outside of comment." | |||
| 3381 | (1 font-lock-string-face t)))) | 3953 | (1 font-lock-string-face t)))) |
| 3382 | (t '("\\([]}\\\\%@>*&]\\|\\$[a-zA-Z0-9_:]*\\)[ \t]*{[ \t]*\\(-?[a-zA-Z0-9_:]+\\)[ \t]*}" | 3954 | (t '("\\([]}\\\\%@>*&]\\|\\$[a-zA-Z0-9_:]*\\)[ \t]*{[ \t]*\\(-?[a-zA-Z0-9_:]+\\)[ \t]*}" |
| 3383 | 2 font-lock-string-face t))) | 3955 | 2 font-lock-string-face t))) |
| 3384 | '("[ \t{,(]\\(-?[a-zA-Z0-9_:]+\\)[ \t]*=>" 1 | 3956 | '("[\[ \t{,(]\\(-?[a-zA-Z0-9_:]+\\)[ \t]*=>" 1 |
| 3385 | font-lock-string-face t) | 3957 | font-lock-string-face t) |
| 3386 | '("^[ \t]*\\([a-zA-Z0-9_]+[ \t]*:\\)[ \t]*\\($\\|{\\|\\<\\(until\\|while\\|for\\(each\\)?\\|do\\)\\>\\)" 1 | 3958 | '("^[ \t]*\\([a-zA-Z0-9_]+[ \t]*:\\)[ \t]*\\($\\|{\\|\\<\\(until\\|while\\|for\\(each\\)?\\|do\\)\\>\\)" 1 |
| 3387 | font-lock-constant-face) ; labels | 3959 | font-lock-constant-face) ; labels |
| @@ -3438,7 +4010,8 @@ indentation and initial hashes. Behaves usually outside of comment." | |||
| 3438 | t-font-lock-keywords-1))) | 4010 | t-font-lock-keywords-1))) |
| 3439 | (if (fboundp 'ps-print-buffer) (cperl-ps-print-init)) | 4011 | (if (fboundp 'ps-print-buffer) (cperl-ps-print-init)) |
| 3440 | (if (or (featurep 'choose-color) (featurep 'font-lock-extra)) | 4012 | (if (or (featurep 'choose-color) (featurep 'font-lock-extra)) |
| 3441 | (font-lock-require-faces | 4013 | (eval ; Avoid a warning |
| 4014 | '(font-lock-require-faces | ||
| 3442 | (list | 4015 | (list |
| 3443 | ;; Color-light Color-dark Gray-light Gray-dark Mono | 4016 | ;; Color-light Color-dark Gray-light Gray-dark Mono |
| 3444 | (list 'font-lock-comment-face | 4017 | (list 'font-lock-comment-face |
| @@ -3512,7 +4085,7 @@ indentation and initial hashes. Behaves usually outside of comment." | |||
| 3512 | "gray90"] | 4085 | "gray90"] |
| 3513 | t | 4086 | t |
| 3514 | t | 4087 | t |
| 3515 | nil))) | 4088 | nil)))) |
| 3516 | (defvar cperl-guessed-background nil | 4089 | (defvar cperl-guessed-background nil |
| 3517 | "Display characteristics as guessed by cperl.") | 4090 | "Display characteristics as guessed by cperl.") |
| 3518 | (or (fboundp 'x-color-defined-p) | 4091 | (or (fboundp 'x-color-defined-p) |
| @@ -3527,64 +4100,40 @@ indentation and initial hashes. Behaves usually outside of comment." | |||
| 3527 | (or (boundp 'font-lock-type-face) | 4100 | (or (boundp 'font-lock-type-face) |
| 3528 | (defconst font-lock-type-face | 4101 | (defconst font-lock-type-face |
| 3529 | 'font-lock-type-face | 4102 | 'font-lock-type-face |
| 3530 | "Face to use for data types.") | 4103 | "Face to use for data types.")) |
| 3531 | ) | ||
| 3532 | (or (boundp 'font-lock-other-type-face) | 4104 | (or (boundp 'font-lock-other-type-face) |
| 3533 | (defconst font-lock-other-type-face | 4105 | (defconst font-lock-other-type-face |
| 3534 | 'font-lock-other-type-face | 4106 | 'font-lock-other-type-face |
| 3535 | "Face to use for data types from another group.") | 4107 | "Face to use for data types from another group.")) |
| 3536 | ) | ||
| 3537 | (if (not cperl-xemacs-p) nil | 4108 | (if (not cperl-xemacs-p) nil |
| 3538 | (or (boundp 'font-lock-comment-face) | 4109 | (or (boundp 'font-lock-comment-face) |
| 3539 | (defconst font-lock-comment-face | 4110 | (defconst font-lock-comment-face |
| 3540 | 'font-lock-comment-face | 4111 | 'font-lock-comment-face |
| 3541 | "Face to use for comments.") | 4112 | "Face to use for comments.")) |
| 3542 | ) | ||
| 3543 | (or (boundp 'font-lock-keyword-face) | 4113 | (or (boundp 'font-lock-keyword-face) |
| 3544 | (defconst font-lock-keyword-face | 4114 | (defconst font-lock-keyword-face |
| 3545 | 'font-lock-keyword-face | 4115 | 'font-lock-keyword-face |
| 3546 | "Face to use for keywords.") | 4116 | "Face to use for keywords.")) |
| 3547 | ) | ||
| 3548 | (or (boundp 'font-lock-function-name-face) | 4117 | (or (boundp 'font-lock-function-name-face) |
| 3549 | (defconst font-lock-function-name-face | 4118 | (defconst font-lock-function-name-face |
| 3550 | 'font-lock-function-name-face | 4119 | 'font-lock-function-name-face |
| 3551 | "Face to use for function names.") | 4120 | "Face to use for function names."))) |
| 3552 | ) | ||
| 3553 | ) | ||
| 3554 | ;;(if (featurep 'font-lock) | ||
| 3555 | (if (face-equal font-lock-type-face font-lock-comment-face) | ||
| 3556 | (defconst font-lock-type-face | ||
| 3557 | 'font-lock-type-face | ||
| 3558 | "Face to use for basic data types.") | ||
| 3559 | ) | ||
| 3560 | ;;; (if (fboundp 'eval-after-load) | ||
| 3561 | ;;; (eval-after-load "font-lock" | ||
| 3562 | ;;; '(if (face-equal font-lock-type-face | ||
| 3563 | ;;; font-lock-comment-face) | ||
| 3564 | ;;; (defconst font-lock-type-face | ||
| 3565 | ;;; 'font-lock-type-face | ||
| 3566 | ;;; "Face to use for basic data types.") | ||
| 3567 | ;;; ))) ; This does not work :-( Why?! | ||
| 3568 | ;;; ; Workaround: added to font-lock-m-h | ||
| 3569 | ;;; ) | ||
| 3570 | (or (boundp 'font-lock-other-emphasized-face) | 4121 | (or (boundp 'font-lock-other-emphasized-face) |
| 3571 | (defconst font-lock-other-emphasized-face | 4122 | (defconst font-lock-other-emphasized-face |
| 3572 | 'font-lock-other-emphasized-face | 4123 | 'font-lock-other-emphasized-face |
| 3573 | "Face to use for another type of emphasizing.") | 4124 | "Face to use for another type of emphasizing.")) |
| 3574 | ) | ||
| 3575 | (or (boundp 'font-lock-emphasized-face) | 4125 | (or (boundp 'font-lock-emphasized-face) |
| 3576 | (defconst font-lock-emphasized-face | 4126 | (defconst font-lock-emphasized-face |
| 3577 | 'font-lock-emphasized-face | 4127 | 'font-lock-emphasized-face |
| 3578 | "Face to use for emphasizing.") | 4128 | "Face to use for emphasizing.")) |
| 3579 | ) | ||
| 3580 | ;; Here we try to guess background | 4129 | ;; Here we try to guess background |
| 3581 | (let ((background | 4130 | (let ((background |
| 3582 | (if (boundp 'font-lock-background-mode) | 4131 | (if (boundp 'font-lock-background-mode) |
| 3583 | font-lock-background-mode | 4132 | font-lock-background-mode |
| 3584 | 'light)) | 4133 | 'light)) |
| 3585 | (face-list (and (fboundp 'face-list) (face-list))) | 4134 | (face-list (and (fboundp 'face-list) (face-list))) |
| 3586 | is-face) | 4135 | cperl-is-face) |
| 3587 | (fset 'is-face | 4136 | (fset 'cperl-is-face |
| 3588 | (cond ((fboundp 'find-face) | 4137 | (cond ((fboundp 'find-face) |
| 3589 | (symbol-function 'find-face)) | 4138 | (symbol-function 'find-face)) |
| 3590 | (face-list | 4139 | (face-list |
| @@ -3597,7 +4146,12 @@ indentation and initial hashes. Behaves usually outside of comment." | |||
| 3597 | 'gray | 4146 | 'gray |
| 3598 | background) | 4147 | background) |
| 3599 | "Background as guessed by CPerl mode") | 4148 | "Background as guessed by CPerl mode") |
| 3600 | (if (is-face 'font-lock-type-face) nil | 4149 | (if (and |
| 4150 | (not (cperl-is-face 'font-lock-constant-face)) | ||
| 4151 | (cperl-is-face 'font-lock-reference-face)) | ||
| 4152 | nil | ||
| 4153 | (copy-face 'font-lock-reference-face 'font-lock-constant-face)) | ||
| 4154 | (if (cperl-is-face 'font-lock-type-face) nil | ||
| 3601 | (copy-face 'default 'font-lock-type-face) | 4155 | (copy-face 'default 'font-lock-type-face) |
| 3602 | (cond | 4156 | (cond |
| 3603 | ((eq background 'light) | 4157 | ((eq background 'light) |
| @@ -3612,7 +4166,7 @@ indentation and initial hashes. Behaves usually outside of comment." | |||
| 3612 | "pink"))) | 4166 | "pink"))) |
| 3613 | (t | 4167 | (t |
| 3614 | (set-face-background 'font-lock-type-face "gray90")))) | 4168 | (set-face-background 'font-lock-type-face "gray90")))) |
| 3615 | (if (is-face 'font-lock-other-type-face) | 4169 | (if (cperl-is-face 'font-lock-other-type-face) |
| 3616 | nil | 4170 | nil |
| 3617 | (copy-face 'font-lock-type-face 'font-lock-other-type-face) | 4171 | (copy-face 'font-lock-type-face 'font-lock-other-type-face) |
| 3618 | (cond | 4172 | (cond |
| @@ -3626,7 +4180,7 @@ indentation and initial hashes. Behaves usually outside of comment." | |||
| 3626 | (if (x-color-defined-p "orchid1") | 4180 | (if (x-color-defined-p "orchid1") |
| 3627 | "orchid1" | 4181 | "orchid1" |
| 3628 | "orange"))))) | 4182 | "orange"))))) |
| 3629 | (if (is-face 'font-lock-other-emphasized-face) nil | 4183 | (if (cperl-is-face 'font-lock-other-emphasized-face) nil |
| 3630 | (copy-face 'bold-italic 'font-lock-other-emphasized-face) | 4184 | (copy-face 'bold-italic 'font-lock-other-emphasized-face) |
| 3631 | (cond | 4185 | (cond |
| 3632 | ((eq background 'light) | 4186 | ((eq background 'light) |
| @@ -3644,7 +4198,7 @@ indentation and initial hashes. Behaves usually outside of comment." | |||
| 3644 | "darkgreen" | 4198 | "darkgreen" |
| 3645 | "dark green")))) | 4199 | "dark green")))) |
| 3646 | (t (set-face-background 'font-lock-other-emphasized-face "gray90")))) | 4200 | (t (set-face-background 'font-lock-other-emphasized-face "gray90")))) |
| 3647 | (if (is-face 'font-lock-emphasized-face) nil | 4201 | (if (cperl-is-face 'font-lock-emphasized-face) nil |
| 3648 | (copy-face 'bold 'font-lock-emphasized-face) | 4202 | (copy-face 'bold 'font-lock-emphasized-face) |
| 3649 | (cond | 4203 | (cond |
| 3650 | ((eq background 'light) | 4204 | ((eq background 'light) |
| @@ -3660,9 +4214,9 @@ indentation and initial hashes. Behaves usually outside of comment." | |||
| 3660 | "darkgreen" | 4214 | "darkgreen" |
| 3661 | "dark green")))) | 4215 | "dark green")))) |
| 3662 | (t (set-face-background 'font-lock-emphasized-face "gray90")))) | 4216 | (t (set-face-background 'font-lock-emphasized-face "gray90")))) |
| 3663 | (if (is-face 'font-lock-variable-name-face) nil | 4217 | (if (cperl-is-face 'font-lock-variable-name-face) nil |
| 3664 | (copy-face 'italic 'font-lock-variable-name-face)) | 4218 | (copy-face 'italic 'font-lock-variable-name-face)) |
| 3665 | (if (is-face 'font-lock-constant-face) nil | 4219 | (if (cperl-is-face 'font-lock-constant-face) nil |
| 3666 | (copy-face 'italic 'font-lock-constant-face)))) | 4220 | (copy-face 'italic 'font-lock-constant-face)))) |
| 3667 | (setq cperl-faces-init t)) | 4221 | (setq cperl-faces-init t)) |
| 3668 | (error nil))) | 4222 | (error nil))) |
| @@ -3678,11 +4232,13 @@ indentation and initial hashes. Behaves usually outside of comment." | |||
| 3678 | (append '(font-lock-emphasized-face | 4232 | (append '(font-lock-emphasized-face |
| 3679 | font-lock-keyword-face | 4233 | font-lock-keyword-face |
| 3680 | font-lock-variable-name-face | 4234 | font-lock-variable-name-face |
| 4235 | font-lock-constant-face | ||
| 3681 | font-lock-reference-face | 4236 | font-lock-reference-face |
| 3682 | font-lock-other-emphasized-face) | 4237 | font-lock-other-emphasized-face) |
| 3683 | ps-bold-faces)) | 4238 | ps-bold-faces)) |
| 3684 | (setq ps-italic-faces | 4239 | (setq ps-italic-faces |
| 3685 | (append '(font-lock-other-type-face | 4240 | (append '(font-lock-other-type-face |
| 4241 | font-lock-constant-face | ||
| 3686 | font-lock-reference-face | 4242 | font-lock-reference-face |
| 3687 | font-lock-other-emphasized-face) | 4243 | font-lock-other-emphasized-face) |
| 3688 | ps-italic-faces)) | 4244 | ps-italic-faces)) |
| @@ -3696,29 +4252,106 @@ indentation and initial hashes. Behaves usually outside of comment." | |||
| 3696 | 4252 | ||
| 3697 | (if (cperl-enable-font-lock) (cperl-windowed-init)) | 4253 | (if (cperl-enable-font-lock) (cperl-windowed-init)) |
| 3698 | 4254 | ||
| 4255 | (defconst cperl-styles-entries | ||
| 4256 | '(cperl-indent-level cperl-brace-offset cperl-continued-brace-offset | ||
| 4257 | cperl-label-offset cperl-extra-newline-before-brace | ||
| 4258 | cperl-continued-statement-offset)) | ||
| 4259 | |||
| 4260 | (defconst cperl-style-alist | ||
| 4261 | '(("CPerl" ; =GNU without extra-newline-before-brace | ||
| 4262 | (cperl-indent-level . 2) | ||
| 4263 | (cperl-brace-offset . 0) | ||
| 4264 | (cperl-continued-brace-offset . 0) | ||
| 4265 | (cperl-label-offset . -2) | ||
| 4266 | (cperl-extra-newline-before-brace . nil) | ||
| 4267 | (cperl-continued-statement-offset . 2)) | ||
| 4268 | ("PerlStyle" ; CPerl with 4 as indent | ||
| 4269 | (cperl-indent-level . 4) | ||
| 4270 | (cperl-brace-offset . 0) | ||
| 4271 | (cperl-continued-brace-offset . 0) | ||
| 4272 | (cperl-label-offset . -4) | ||
| 4273 | (cperl-extra-newline-before-brace . nil) | ||
| 4274 | (cperl-continued-statement-offset . 4)) | ||
| 4275 | ("GNU" | ||
| 4276 | (cperl-indent-level . 2) | ||
| 4277 | (cperl-brace-offset . 0) | ||
| 4278 | (cperl-continued-brace-offset . 0) | ||
| 4279 | (cperl-label-offset . -2) | ||
| 4280 | (cperl-extra-newline-before-brace . t) | ||
| 4281 | (cperl-continued-statement-offset . 2)) | ||
| 4282 | ("K&R" | ||
| 4283 | (cperl-indent-level . 5) | ||
| 4284 | (cperl-brace-offset . 0) | ||
| 4285 | (cperl-continued-brace-offset . -5) | ||
| 4286 | (cperl-label-offset . -5) | ||
| 4287 | ;;(cperl-extra-newline-before-brace . nil) ; ??? | ||
| 4288 | (cperl-continued-statement-offset . 5)) | ||
| 4289 | ("BSD" | ||
| 4290 | (cperl-indent-level . 4) | ||
| 4291 | (cperl-brace-offset . 0) | ||
| 4292 | (cperl-continued-brace-offset . -4) | ||
| 4293 | (cperl-label-offset . -4) | ||
| 4294 | ;;(cperl-extra-newline-before-brace . nil) ; ??? | ||
| 4295 | (cperl-continued-statement-offset . 4)) | ||
| 4296 | ("C++" | ||
| 4297 | (cperl-indent-level . 4) | ||
| 4298 | (cperl-brace-offset . 0) | ||
| 4299 | (cperl-continued-brace-offset . -4) | ||
| 4300 | (cperl-label-offset . -4) | ||
| 4301 | (cperl-continued-statement-offset . 4) | ||
| 4302 | (cperl-extra-newline-before-brace . t)) | ||
| 4303 | ("Current") | ||
| 4304 | ("Whitesmith" | ||
| 4305 | (cperl-indent-level . 4) | ||
| 4306 | (cperl-brace-offset . 0) | ||
| 4307 | (cperl-continued-brace-offset . 0) | ||
| 4308 | (cperl-label-offset . -4) | ||
| 4309 | ;;(cperl-extra-newline-before-brace . nil) ; ??? | ||
| 4310 | (cperl-continued-statement-offset . 4))) | ||
| 4311 | "(Experimental) list of variables to set to get a particular indentation style. | ||
| 4312 | Should be used via `cperl-set-style' or via CPerl menu.") | ||
| 4313 | |||
| 3699 | (defun cperl-set-style (style) | 4314 | (defun cperl-set-style (style) |
| 3700 | "Set CPerl-mode variables to use one of several different indentation styles. | 4315 | "Set CPerl-mode variables to use one of several different indentation styles. |
| 3701 | The arguments are a string representing the desired style. | 4316 | The arguments are a string representing the desired style. |
| 3702 | Available styles are GNU, K&R, BSD and Whitesmith." | 4317 | The list of styles is in `cperl-style-alist', available styles |
| 4318 | are GNU, K&R, BSD, C++ and Whitesmith. | ||
| 4319 | |||
| 4320 | The current value of style is memorized (unless there is a memorized | ||
| 4321 | data already), may be restored by `cperl-set-style-back'. | ||
| 4322 | |||
| 4323 | Chosing \"Current\" style will not change style, so this may be used for | ||
| 4324 | side-effect of memorizing only." | ||
| 3703 | (interactive | 4325 | (interactive |
| 3704 | (let ((list (mapcar (function (lambda (elt) (list (car elt)))) | 4326 | (let ((list (mapcar (function (lambda (elt) (list (car elt)))) |
| 3705 | c-style-alist))) | 4327 | cperl-style-alist))) |
| 3706 | (list (completing-read "Enter style: " list nil 'insist)))) | 4328 | (list (completing-read "Enter style: " list nil 'insist)))) |
| 3707 | (let ((style (cdr (assoc style c-style-alist))) setting str sym) | 4329 | (or cperl-old-style |
| 4330 | (setq cperl-old-style | ||
| 4331 | (mapcar (function | ||
| 4332 | (lambda (name) | ||
| 4333 | (cons name (eval name)))) | ||
| 4334 | cperl-styles-entries))) | ||
| 4335 | (let ((style (cdr (assoc style cperl-style-alist))) setting str sym) | ||
| 3708 | (while style | 4336 | (while style |
| 3709 | (setq setting (car style) style (cdr style)) | 4337 | (setq setting (car style) style (cdr style)) |
| 3710 | (setq str (symbol-name (car setting))) | 4338 | (set (car setting) (cdr setting))))) |
| 3711 | (and (string-match "^c-" str) | 4339 | |
| 3712 | (setq str (concat "cperl-" (substring str 2))) | 4340 | (defun cperl-set-style-back () |
| 3713 | (setq sym (intern-soft str)) | 4341 | "Restore a style memorised by `cperl-set-style'." |
| 3714 | (boundp sym) | 4342 | (interactive) |
| 3715 | (set sym (cdr setting)))))) | 4343 | (or cperl-old-style (error "The style was not changed")) |
| 4344 | (let (setting) | ||
| 4345 | (while cperl-old-style | ||
| 4346 | (setq setting (car cperl-old-style) | ||
| 4347 | cperl-old-style (cdr cperl-old-style)) | ||
| 4348 | (set (car setting) (cdr setting))))) | ||
| 3716 | 4349 | ||
| 3717 | (defun cperl-check-syntax () | 4350 | (defun cperl-check-syntax () |
| 3718 | (interactive) | 4351 | (interactive) |
| 3719 | (require 'mode-compile) | 4352 | (require 'mode-compile) |
| 3720 | (let ((perl-dbg-flags "-wc")) | 4353 | (let ((perl-dbg-flags (concat cperl-extra-perl-args " -wc"))) |
| 3721 | (mode-compile))) | 4354 | (eval '(mode-compile)))) ; Avoid a warning |
| 3722 | 4355 | ||
| 3723 | (defun cperl-info-buffer (type) | 4356 | (defun cperl-info-buffer (type) |
| 3724 | ;; Returns buffer with documentation. Creates if missing. | 4357 | ;; Returns buffer with documentation. Creates if missing. |
| @@ -4001,6 +4634,27 @@ in subdirectories too." | |||
| 4001 | (message "Parentheses will %sbe auto-doubled now." | 4634 | (message "Parentheses will %sbe auto-doubled now." |
| 4002 | (if (cperl-val 'cperl-electric-parens) "" "not "))) | 4635 | (if (cperl-val 'cperl-electric-parens) "" "not "))) |
| 4003 | 4636 | ||
| 4637 | (defun cperl-toggle-autohelp () | ||
| 4638 | "Toggle the state of automatic help message in CPerl mode. | ||
| 4639 | See `cperl-lazy-help-time' too." | ||
| 4640 | (interactive) | ||
| 4641 | (if (fboundp 'run-with-idle-timer) | ||
| 4642 | (progn | ||
| 4643 | (if cperl-lazy-installed | ||
| 4644 | (eval '(cperl-lazy-unstall)) | ||
| 4645 | (cperl-lazy-install)) | ||
| 4646 | (message "Perl help messages will %sbe automatically shown now." | ||
| 4647 | (if cperl-lazy-installed "" "not "))) | ||
| 4648 | (message "Cannot automatically show Perl help messages - run-with-idle-timer missing."))) | ||
| 4649 | |||
| 4650 | (defun cperl-toggle-construct-fix () | ||
| 4651 | "Toggle whether `indent-region'/`indent-sexp' fix whitespace too." | ||
| 4652 | (interactive) | ||
| 4653 | (setq cperl-indent-region-fix-constructs | ||
| 4654 | (not cperl-indent-region-fix-constructs)) | ||
| 4655 | (message "indent-region/indent-sexp will %sbe automatically fix whitespace." | ||
| 4656 | (if cperl-indent-region-fix-constructs "" "not "))) | ||
| 4657 | |||
| 4004 | ;;;; Tags file creation. | 4658 | ;;;; Tags file creation. |
| 4005 | 4659 | ||
| 4006 | (defvar cperl-tmp-buffer " *cperl-tmp*") | 4660 | (defvar cperl-tmp-buffer " *cperl-tmp*") |
| @@ -4061,10 +4715,6 @@ in subdirectories too." | |||
| 4061 | (push index index-alist))))) | 4715 | (push index index-alist))))) |
| 4062 | (or noninteractive | 4716 | (or noninteractive |
| 4063 | (imenu-progress-message prev-pos 100)) | 4717 | (imenu-progress-message prev-pos 100)) |
| 4064 | ;;(setq index-alist | ||
| 4065 | ;; (if (default-value 'imenu-sort-function) | ||
| 4066 | ;; (sort index-alist (default-value 'imenu-sort-function)) | ||
| 4067 | ;; (nreverse index-alist))) | ||
| 4068 | index-alist)) | 4718 | index-alist)) |
| 4069 | 4719 | ||
| 4070 | (defun cperl-find-tags (file xs topdir) | 4720 | (defun cperl-find-tags (file xs topdir) |
| @@ -4532,6 +5182,7 @@ Currently it is tuned to C and Perl syntax." | |||
| 4532 | found-bad found))) | 5182 | found-bad found))) |
| 4533 | (not not-found))) | 5183 | (not not-found))) |
| 4534 | 5184 | ||
| 5185 | |||
| 4535 | ;;; Getting help | 5186 | ;;; Getting help |
| 4536 | (defvar cperl-have-help-regexp | 5187 | (defvar cperl-have-help-regexp |
| 4537 | ;;(concat "\\(" | 5188 | ;;(concat "\\(" |
| @@ -4914,7 +5565,6 @@ getsockname(SOCKET) | |||
| 4914 | getsockopt(SOCKET,LEVEL,OPTNAME) | 5565 | getsockopt(SOCKET,LEVEL,OPTNAME) |
| 4915 | gmtime(EXPR) | 5566 | gmtime(EXPR) |
| 4916 | goto LABEL | 5567 | goto LABEL |
| 4917 | grep(EXPR,LIST) | ||
| 4918 | ... gt ... String greater than. | 5568 | ... gt ... String greater than. |
| 4919 | hex(EXPR) | 5569 | hex(EXPR) |
| 4920 | if (EXPR) { ... } [ elsif (EXPR) { ... } ... ] [ else { ... } ] or EXPR if EXPR | 5570 | if (EXPR) { ... } [ elsif (EXPR) { ... } ... ] [ else { ... } ] or EXPR if EXPR |
| @@ -5042,7 +5692,7 @@ y/SEARCHLIST/REPLACEMENTLIST/ | |||
| 5042 | ... | ... Bitwise or. | 5692 | ... | ... Bitwise or. |
| 5043 | ... || ... Logical or. | 5693 | ... || ... Logical or. |
| 5044 | ~ ... Unary bitwise complement. | 5694 | ~ ... Unary bitwise complement. |
| 5045 | #! OS interpreter indicator. If has `perl', used for options, and -x. | 5695 | #! OS interpreter indicator. If contains `perl', used for options, and -x. |
| 5046 | AUTOLOAD {...} Shorthand for `sub AUTOLOAD {...}'. | 5696 | AUTOLOAD {...} Shorthand for `sub AUTOLOAD {...}'. |
| 5047 | CORE:: Prefix to access builtin function if imported sub obscures it. | 5697 | CORE:: Prefix to access builtin function if imported sub obscures it. |
| 5048 | SUPER:: Prefix to lookup for a method in @ISA classes. | 5698 | SUPER:: Prefix to lookup for a method in @ISA classes. |
| @@ -5066,6 +5716,7 @@ formline PICTURE, LIST Backdoor into \"format\" processing. | |||
| 5066 | glob EXPR Synonym of <EXPR>. | 5716 | glob EXPR Synonym of <EXPR>. |
| 5067 | lc [ EXPR ] Returns lowercased EXPR. | 5717 | lc [ EXPR ] Returns lowercased EXPR. |
| 5068 | lcfirst [ EXPR ] Returns EXPR with lower-cased first letter. | 5718 | lcfirst [ EXPR ] Returns EXPR with lower-cased first letter. |
| 5719 | grep EXPR,LIST or grep {BLOCK} LIST Filters LIST via EXPR/BLOCK. | ||
| 5069 | map EXPR, LIST or map {BLOCK} LIST Applies EXPR/BLOCK to elts of LIST. | 5720 | map EXPR, LIST or map {BLOCK} LIST Applies EXPR/BLOCK to elts of LIST. |
| 5070 | no PACKAGE [SYMBOL1, ...] Partial reverse for `use'. Runs `unimport' method. | 5721 | no PACKAGE [SYMBOL1, ...] Partial reverse for `use'. Runs `unimport' method. |
| 5071 | not ... Low-precedence synonym for ! - negation. | 5722 | not ... Low-precedence synonym for ! - negation. |
| @@ -5207,6 +5858,9 @@ prototype \&SUB Returns prototype of the function given a reference. | |||
| 5207 | (goto-char (+ 2 tmp)) | 5858 | (goto-char (+ 2 tmp)) |
| 5208 | (forward-sexp 1) | 5859 | (forward-sexp 1) |
| 5209 | (cperl-beautify-regexp-piece (point) m t)) | 5860 | (cperl-beautify-regexp-piece (point) m t)) |
| 5861 | ((eq (char-after (+ 2 tmp)) ?<) ; Lookbehind | ||
| 5862 | (goto-char (+ 3 tmp)) | ||
| 5863 | (cperl-beautify-regexp-piece (point) m t)) | ||
| 5210 | (t | 5864 | (t |
| 5211 | (cperl-beautify-regexp-piece tmp m t))) | 5865 | (cperl-beautify-regexp-piece tmp m t))) |
| 5212 | (goto-char m1) | 5866 | (goto-char m1) |
| @@ -5264,11 +5918,16 @@ prototype \&SUB Returns prototype of the function given a reference. | |||
| 5264 | )) | 5918 | )) |
| 5265 | 5919 | ||
| 5266 | (defun cperl-make-regexp-x () | 5920 | (defun cperl-make-regexp-x () |
| 5921 | ;; Returns position of the start | ||
| 5267 | (save-excursion | 5922 | (save-excursion |
| 5268 | (or cperl-use-syntax-table-text-property | 5923 | (or cperl-use-syntax-table-text-property |
| 5269 | (error "I need to have regex marked!")) | 5924 | (error "I need to have regex marked!")) |
| 5270 | ;; Find the start | 5925 | ;; Find the start |
| 5271 | (re-search-backward "\\s|") ; Assume it is scanned already. | 5926 | (if (looking-at "\\s|") |
| 5927 | nil ; good already | ||
| 5928 | (if (looking-at "[smy]\\s|") | ||
| 5929 | (forward-char 1) | ||
| 5930 | (re-search-backward "\\s|"))) ; Assume it is scanned already. | ||
| 5272 | ;;(forward-char 1) | 5931 | ;;(forward-char 1) |
| 5273 | (let ((b (point)) (e (make-marker)) have-x delim (c (current-column)) | 5932 | (let ((b (point)) (e (make-marker)) have-x delim (c (current-column)) |
| 5274 | (sub-p (eq (preceding-char) ?s)) s) | 5933 | (sub-p (eq (preceding-char) ?s)) s) |
| @@ -5294,65 +5953,237 @@ prototype \&SUB Returns prototype of the function given a reference. | |||
| 5294 | "do it. (Experimental, may change semantics, recheck the result.) | 5953 | "do it. (Experimental, may change semantics, recheck the result.) |
| 5295 | We suppose that the regexp is scanned already." | 5954 | We suppose that the regexp is scanned already." |
| 5296 | (interactive) | 5955 | (interactive) |
| 5297 | (cperl-make-regexp-x) | 5956 | (goto-char (cperl-make-regexp-x)) |
| 5298 | (re-search-backward "\\s|") ; Assume it is scanned already. | ||
| 5299 | ;;(forward-char 1) | ||
| 5300 | (let ((b (point)) (e (make-marker))) | 5957 | (let ((b (point)) (e (make-marker))) |
| 5301 | (forward-sexp 1) | 5958 | (forward-sexp 1) |
| 5302 | (set-marker e (1- (point))) | 5959 | (set-marker e (1- (point))) |
| 5303 | (cperl-beautify-regexp-piece b e nil))) | 5960 | (cperl-beautify-regexp-piece b e nil))) |
| 5304 | 5961 | ||
| 5305 | (defun cperl-contract-level () | 5962 | (defun cperl-regext-to-level-start () |
| 5306 | "Find an enclosing group in regexp and contract it. Unfinished. | 5963 | "Goto start of an enclosing group in regexp. |
| 5307 | \(Experimental, may change semantics, recheck the result.) | ||
| 5308 | We suppose that the regexp is scanned already." | 5964 | We suppose that the regexp is scanned already." |
| 5309 | (interactive) | 5965 | (interactive) |
| 5310 | (let ((bb (cperl-make-regexp-x)) done) | 5966 | (let ((limit (cperl-make-regexp-x)) done) |
| 5311 | (while (not done) | 5967 | (while (not done) |
| 5312 | (or (eq (following-char) ?\() | 5968 | (or (eq (following-char) ?\() |
| 5313 | (search-backward "(" (1+ bb) t) | 5969 | (search-backward "(" (1+ limit) t) |
| 5314 | (error "Cannot find `(' which starts a group")) | 5970 | (error "Cannot find `(' which starts a group")) |
| 5315 | (setq done | 5971 | (setq done |
| 5316 | (save-excursion | 5972 | (save-excursion |
| 5317 | (skip-chars-backward "\\") | 5973 | (skip-chars-backward "\\") |
| 5318 | (looking-at "\\(\\\\\\\\\\)*("))) | 5974 | (looking-at "\\(\\\\\\\\\\)*("))) |
| 5319 | (or done (forward-char -1))) | 5975 | (or done (forward-char -1))))) |
| 5320 | (let ((b (point)) (e (make-marker)) s c) | 5976 | |
| 5321 | (forward-sexp 1) | 5977 | (defun cperl-contract-level () |
| 5322 | (set-marker e (1- (point))) | 5978 | "Find an enclosing group in regexp and contract it. Unfinished. |
| 5323 | (goto-char b) | 5979 | \(Experimental, may change semantics, recheck the result.) |
| 5324 | (while (re-search-forward "\\(#\\)\\|\n" e t) | 5980 | We suppose that the regexp is scanned already." |
| 5325 | (cond | 5981 | (interactive) |
| 5326 | ((match-beginning 1) ; #-comment | 5982 | (cperl-regext-to-level-start) |
| 5327 | (or c (setq c (current-indentation))) | 5983 | (let ((b (point)) (e (make-marker)) s c) |
| 5328 | (beginning-of-line 2) ; Skip | 5984 | (forward-sexp 1) |
| 5329 | (setq s (point)) | 5985 | (set-marker e (1- (point))) |
| 5330 | (skip-chars-forward " \t") | 5986 | (goto-char b) |
| 5331 | (delete-region s (point)) | 5987 | (while (re-search-forward "\\(#\\)\\|\n" e t) |
| 5332 | (indent-to-column c)) | 5988 | (cond |
| 5333 | (t | 5989 | ((match-beginning 1) ; #-comment |
| 5334 | (delete-char -1) | 5990 | (or c (setq c (current-indentation))) |
| 5335 | (just-one-space))))))) | 5991 | (beginning-of-line 2) ; Skip |
| 5992 | (setq s (point)) | ||
| 5993 | (skip-chars-forward " \t") | ||
| 5994 | (delete-region s (point)) | ||
| 5995 | (indent-to-column c)) | ||
| 5996 | (t | ||
| 5997 | (delete-char -1) | ||
| 5998 | (just-one-space)))))) | ||
| 5999 | |||
| 6000 | (defun cperl-contract-levels () | ||
| 6001 | "Find an enclosing group in regexp and contract all the kids. Unfinished. | ||
| 6002 | \(Experimental, may change semantics, recheck the result.) | ||
| 6003 | We suppose that the regexp is scanned already." | ||
| 6004 | (interactive) | ||
| 6005 | (condition-case nil | ||
| 6006 | (cperl-regext-to-level-start) | ||
| 6007 | (error ; We are outside outermost group | ||
| 6008 | (goto-char (cperl-make-regexp-x)))) | ||
| 6009 | (let ((b (point)) (e (make-marker)) s c) | ||
| 6010 | (forward-sexp 1) | ||
| 6011 | (set-marker e (1- (point))) | ||
| 6012 | (goto-char (1+ b)) | ||
| 6013 | (while (re-search-forward "\\(\\\\\\\\\\)\\|(" e t) | ||
| 6014 | (cond | ||
| 6015 | ((match-beginning 1) ; Skip | ||
| 6016 | nil) | ||
| 6017 | (t ; Group | ||
| 6018 | (cperl-contract-level)))))) | ||
| 5336 | 6019 | ||
| 5337 | (defun cperl-beautify-level () | 6020 | (defun cperl-beautify-level () |
| 5338 | "Find an enclosing group in regexp and beautify it. | 6021 | "Find an enclosing group in regexp and beautify it. |
| 5339 | \(Experimental, may change semantics, recheck the result.) | 6022 | \(Experimental, may change semantics, recheck the result.) |
| 5340 | We suppose that the regexp is scanned already." | 6023 | We suppose that the regexp is scanned already." |
| 5341 | (interactive) | 6024 | (interactive) |
| 5342 | (let ((bb (cperl-make-regexp-x)) done) | 6025 | (cperl-regext-to-level-start) |
| 5343 | (while (not done) | 6026 | (let ((b (point)) (e (make-marker))) |
| 5344 | (or (eq (following-char) ?\() | 6027 | (forward-sexp 1) |
| 5345 | (search-backward "(" (1+ bb) t) | 6028 | (set-marker e (1- (point))) |
| 5346 | (error "Cannot find `(' which starts a group")) | 6029 | (cperl-beautify-regexp-piece b e nil))) |
| 5347 | (setq done | 6030 | |
| 5348 | (save-excursion | 6031 | (defun cperl-invert-if-unless () |
| 5349 | (skip-chars-backward "\\") | 6032 | "Changes `if (A) {B}' into `B if A;' if possible." |
| 5350 | (looking-at "\\(\\\\\\\\\\)*("))) | 6033 | (interactive) |
| 5351 | (or done (forward-char -1))) | 6034 | (or (looking-at "\\<") |
| 5352 | (let ((b (point)) (e (make-marker))) | 6035 | (forward-sexp -1)) |
| 5353 | (forward-sexp 1) | 6036 | (if (looking-at "\\<\\(if\\|unless\\|while\\|until\\)\\>") |
| 5354 | (set-marker e (1- (point))) | 6037 | (let ((pos1 (point)) |
| 5355 | (cperl-beautify-regexp-piece b e nil)))) | 6038 | pos2 pos3 pos4 pos5 s1 s2 state p pos45 |
| 6039 | (s0 (buffer-substring (match-beginning 0) (match-end 0)))) | ||
| 6040 | (forward-sexp 2) | ||
| 6041 | (setq pos3 (point)) | ||
| 6042 | (forward-sexp -1) | ||
| 6043 | (setq pos2 (point)) | ||
| 6044 | (if (eq (following-char) ?\( ) | ||
| 6045 | (progn | ||
| 6046 | (goto-char pos3) | ||
| 6047 | (forward-sexp 1) | ||
| 6048 | (setq pos5 (point)) | ||
| 6049 | (forward-sexp -1) | ||
| 6050 | (setq pos4 (point)) | ||
| 6051 | ;; XXXX In fact may be `A if (B); {C}' ... | ||
| 6052 | (if (and (eq (following-char) ?\{ ) | ||
| 6053 | (progn | ||
| 6054 | (cperl-backward-to-noncomment pos3) | ||
| 6055 | (eq (preceding-char) ?\) ))) | ||
| 6056 | (if (condition-case nil | ||
| 6057 | (progn | ||
| 6058 | (goto-char pos5) | ||
| 6059 | (forward-sexp 1) | ||
| 6060 | (forward-sexp -1) | ||
| 6061 | (looking-at "\\<els\\(e\\|if\\)\\>")) | ||
| 6062 | (error nil)) | ||
| 6063 | (error | ||
| 6064 | "`%s' (EXPR) {BLOCK} with `else'/`elsif'" s0) | ||
| 6065 | (goto-char (1- pos5)) | ||
| 6066 | (cperl-backward-to-noncomment pos4) | ||
| 6067 | (if (eq (preceding-char) ?\;) | ||
| 6068 | (forward-char -1)) | ||
| 6069 | (setq pos45 (point)) | ||
| 6070 | (goto-char pos4) | ||
| 6071 | (while (re-search-forward "\\<\\(for\\|foreach\\|if\\|unless\\|while\\|until\\)\\>\\|;" pos45 t) | ||
| 6072 | (setq p (match-beginning 0) | ||
| 6073 | s1 (buffer-substring p (match-end 0)) | ||
| 6074 | state (parse-partial-sexp pos4 p)) | ||
| 6075 | (or (nth 3 state) | ||
| 6076 | (nth 4 state) | ||
| 6077 | (nth 5 state) | ||
| 6078 | (error "`%s' inside `%s' BLOCK" s1 s0)) | ||
| 6079 | (goto-char (match-end 0))) | ||
| 6080 | ;; Finally got it | ||
| 6081 | (goto-char (1+ pos4)) | ||
| 6082 | (skip-chars-forward " \t\n") | ||
| 6083 | (setq s2 (buffer-substring (point) pos45)) | ||
| 6084 | (goto-char pos45) | ||
| 6085 | (or (looking-at ";?[ \t\n]*}") | ||
| 6086 | (progn | ||
| 6087 | (skip-chars-forward "; \t\n") | ||
| 6088 | (setq s2 (concat s2 "\n" (buffer-substring (point) (1- pos5)))))) | ||
| 6089 | (and (equal s2 "") | ||
| 6090 | (setq s2 "1")) | ||
| 6091 | (goto-char (1- pos3)) | ||
| 6092 | (cperl-backward-to-noncomment pos2) | ||
| 6093 | (or (looking-at "[ \t\n]*)") | ||
| 6094 | (goto-char (1- pos3))) | ||
| 6095 | (setq p (point)) | ||
| 6096 | (goto-char (1+ pos2)) | ||
| 6097 | (skip-chars-forward " \t\n") | ||
| 6098 | (setq s1 (buffer-substring (point) p)) | ||
| 6099 | (delete-region pos4 pos5) | ||
| 6100 | (delete-region pos2 pos3) | ||
| 6101 | (goto-char pos1) | ||
| 6102 | (insert s2 " ") | ||
| 6103 | (just-one-space) | ||
| 6104 | (forward-word 1) | ||
| 6105 | (setq pos1 (point)) | ||
| 6106 | (insert " " s1 ";") | ||
| 6107 | (forward-char -1) | ||
| 6108 | (delete-horizontal-space) | ||
| 6109 | (goto-char pos1) | ||
| 6110 | (just-one-space) | ||
| 6111 | (cperl-indent-line)) | ||
| 6112 | (error "`%s' (EXPR) not with an {BLOCK}" s0))) | ||
| 6113 | (error "`%s' not with an (EXPR)" s0))) | ||
| 6114 | (error "Not at `if', `unless', `while', or `unless'"))) | ||
| 6115 | |||
| 6116 | ;;; By Anthony Foiani <afoiani@uswest.com> | ||
| 6117 | ;;; Getting help on modules in C-h f ? | ||
| 6118 | ;;; Need to teach it how to lookup functions | ||
| 6119 | (defvar Man-filter-list) | ||
| 6120 | (defun cperl-perldoc (word) | ||
| 6121 | "Run a 'perldoc' on WORD." | ||
| 6122 | (interactive | ||
| 6123 | (list (let* ((default-entry (cperl-word-at-point)) | ||
| 6124 | (input (read-string | ||
| 6125 | (format "perldoc entry%s: " | ||
| 6126 | (if (string= default-entry "") | ||
| 6127 | "" | ||
| 6128 | (format " (default %s)" default-entry)))))) | ||
| 6129 | (if (string= input "") | ||
| 6130 | (if (string= default-entry "") | ||
| 6131 | (error "No perldoc args given") | ||
| 6132 | default-entry) | ||
| 6133 | input)))) | ||
| 6134 | (let* ((is-func (and | ||
| 6135 | (string-match "^[a-z]+$" word) | ||
| 6136 | (string-match (concat "^" word "\\>") | ||
| 6137 | (documentation-property | ||
| 6138 | 'cperl-short-docs | ||
| 6139 | 'variable-documentation)))) | ||
| 6140 | (manual-program (if is-func "perldoc -f" "perldoc"))) | ||
| 6141 | (require 'man) | ||
| 6142 | (Man-getpage-in-background word))) | ||
| 6143 | |||
| 6144 | (defun cperl-perldoc-at-point () | ||
| 6145 | "Run a 'perldoc' on WORD." | ||
| 6146 | (interactive) | ||
| 6147 | (cperl-perldoc (cperl-word-at-point))) | ||
| 6148 | |||
| 6149 | ;;; By Nick Roberts <Nick.Roberts@src.bae.co.uk> (with changes) | ||
| 6150 | (defvar pod2man-program "pod2man") | ||
| 6151 | |||
| 6152 | (defun cperl-pod-to-manpage () | ||
| 6153 | "Create a virtual manpage in emacs from the Perl Online Documentation" | ||
| 6154 | (interactive) | ||
| 6155 | (require 'man) | ||
| 6156 | (let* ((pod2man-args (concat buffer-file-name " | nroff -man ")) | ||
| 6157 | (bufname (concat "Man " buffer-file-name)) | ||
| 6158 | (buffer (generate-new-buffer bufname))) | ||
| 6159 | (save-excursion | ||
| 6160 | (set-buffer buffer) | ||
| 6161 | (let ((process-environment (copy-sequence process-environment))) | ||
| 6162 | ;; Prevent any attempt to use display terminal fanciness. | ||
| 6163 | (setenv "TERM" "dumb") | ||
| 6164 | (set-process-sentinel | ||
| 6165 | (start-process pod2man-program buffer "sh" "-c" | ||
| 6166 | (format (cperl-pod2man-build-command) pod2man-args)) | ||
| 6167 | 'Man-bgproc-sentinel))))) | ||
| 6168 | |||
| 6169 | (defun cperl-pod2man-build-command () | ||
| 6170 | "Builds the entire background manpage and cleaning command." | ||
| 6171 | (let ((command (concat pod2man-program " %s 2>/dev/null")) | ||
| 6172 | (flist Man-filter-list)) | ||
| 6173 | (while (and flist (car flist)) | ||
| 6174 | (let ((pcom (car (car flist))) | ||
| 6175 | (pargs (cdr (car flist)))) | ||
| 6176 | (setq command | ||
| 6177 | (concat command " | " pcom " " | ||
| 6178 | (mapconcat '(lambda (phrase) | ||
| 6179 | (if (not (stringp phrase)) | ||
| 6180 | (error "Malformed Man-filter-list")) | ||
| 6181 | phrase) | ||
| 6182 | pargs " "))) | ||
| 6183 | (setq flist (cdr flist)))) | ||
| 6184 | command)) | ||
| 6185 | |||
| 6186 | (defun cperl-lazy-install ()) ; Avoid a warning | ||
| 5356 | 6187 | ||
| 5357 | (if (fboundp 'run-with-idle-timer) | 6188 | (if (fboundp 'run-with-idle-timer) |
| 5358 | (progn | 6189 | (progn |
| @@ -5391,6 +6222,43 @@ We suppose that the regexp is scanned already." | |||
| 5391 | (setq cperl-help-shown t)))) | 6222 | (setq cperl-help-shown t)))) |
| 5392 | (cperl-lazy-install))) | 6223 | (cperl-lazy-install))) |
| 5393 | 6224 | ||
| 6225 | |||
| 6226 | ;;; Plug for wrong font-lock: | ||
| 6227 | |||
| 6228 | (defun cperl-font-lock-unfontify-region-function (beg end) | ||
| 6229 | (let* ((modified (buffer-modified-p)) (buffer-undo-list t) | ||
| 6230 | (inhibit-read-only t) (inhibit-point-motion-hooks t) | ||
| 6231 | before-change-functions after-change-functions | ||
| 6232 | deactivate-mark buffer-file-name buffer-file-truename) | ||
| 6233 | (remove-text-properties beg end '(face nil)) | ||
| 6234 | (when (and (not modified) (buffer-modified-p)) | ||
| 6235 | (set-buffer-modified-p nil)))) | ||
| 6236 | |||
| 6237 | (defvar cperl-d-l nil) | ||
| 6238 | (defun cperl-fontify-syntaxically (end) | ||
| 6239 | (let ((start (point)) (dbg (point))) | ||
| 6240 | (or cperl-syntax-done-to | ||
| 6241 | (setq cperl-syntax-done-to (point-min))) | ||
| 6242 | (if (or (not (boundp 'font-lock-hot-pass)) | ||
| 6243 | (eval 'font-lock-hot-pass)) | ||
| 6244 | ;; Need to forget what is after `start' | ||
| 6245 | (setq start (min cperl-syntax-done-to start)) | ||
| 6246 | ;; Fontification without a change | ||
| 6247 | (setq start (max cperl-syntax-done-to start))) | ||
| 6248 | (and (> end start) | ||
| 6249 | (setq cperl-syntax-done-to start) ; In case what follows fails | ||
| 6250 | (cperl-find-pods-heres start end t nil t)) | ||
| 6251 | ;;(setq cperl-d-l (cons (format "Syntaxifying %s..%s from %s to %s\n" | ||
| 6252 | ;; dbg end start cperl-syntax-done-to) | ||
| 6253 | ;; cperl-d-l)) | ||
| 6254 | ;;(let ((standard-output (get-buffer "*Messages*"))) | ||
| 6255 | ;;(princ (format "Syntaxifying %s..%s from %s to %s\n" | ||
| 6256 | ;; dbg end start cperl-syntax-done-to))) | ||
| 6257 | (if (eq cperl-syntaxify-by-font-lock 1) | ||
| 6258 | (message "Syntaxifying %s..%s from %s to %s" | ||
| 6259 | dbg end start cperl-syntax-done-to)) ; For debugging | ||
| 6260 | nil)) ; Do not iterate | ||
| 6261 | |||
| 5394 | (provide 'cperl-mode) | 6262 | (provide 'cperl-mode) |
| 5395 | 6263 | ||
| 5396 | ;;; cperl-mode.el ends here | 6264 | ;;; cperl-mode.el ends here |