diff options
| author | Karl Heuer | 1997-11-23 02:10:07 +0000 |
|---|---|---|
| committer | Karl Heuer | 1997-11-23 02:10:07 +0000 |
| commit | f83d2997fbf6b7b8287f34a89966f404bd095698 (patch) | |
| tree | 313f5b2abc9c70aa0ed892bd20fbae27690f0bd3 | |
| parent | 950444902e9db2eebe771951f474951e059d8f22 (diff) | |
| download | emacs-f83d2997fbf6b7b8287f34a89966f404bd095698.tar.gz emacs-f83d2997fbf6b7b8287f34a89966f404bd095698.zip | |
Initial revision
| -rw-r--r-- | lisp/play/bruce.el | 139 | ||||
| -rw-r--r-- | lisp/progmodes/cperl-mode.el | 5307 |
2 files changed, 5446 insertions, 0 deletions
diff --git a/lisp/play/bruce.el b/lisp/play/bruce.el new file mode 100644 index 00000000000..46fa59bdec9 --- /dev/null +++ b/lisp/play/bruce.el | |||
| @@ -0,0 +1,139 @@ | |||
| 1 | ;;; bruce.el --- bruce phrase utility for overloading the Communications | ||
| 2 | ;;; Decency Act snoops, if any. | ||
| 3 | |||
| 4 | ;; Copyright (C) 1988, 1993, 1997 Free Software Foundation, Inc. | ||
| 5 | |||
| 6 | ;; Maintainer: FSF | ||
| 7 | ;; Keywords: games | ||
| 8 | ;; Created: Jan 1997 | ||
| 9 | |||
| 10 | ;; This file is part of GNU Emacs. | ||
| 11 | |||
| 12 | ;; GNU Emacs is free software; you can redistribute it and/or modify | ||
| 13 | ;; it under the terms of the GNU General Public License as published by | ||
| 14 | ;; the Free Software Foundation; either version 2, or (at your option) | ||
| 15 | ;; any later version. | ||
| 16 | |||
| 17 | ;; GNU Emacs is distributed in the hope that it will be useful, | ||
| 18 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 19 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 20 | ;; GNU General Public License for more details. | ||
| 21 | |||
| 22 | ;; You should have received a copy of the GNU General Public License | ||
| 23 | ;; along with GNU Emacs; see the file COPYING. If not, write to the | ||
| 24 | ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
| 25 | ;; Boston, MA 02111-1307, USA. | ||
| 26 | |||
| 27 | ;;; Commentary: | ||
| 28 | |||
| 29 | ;; This program was written to protest the miss-named "Communications | ||
| 30 | ;; Decency Act of 1996. This Act bans "indecent speech", whatever that is, | ||
| 31 | ;; from the internet. For more on the CDA, see Richard Stallman's essay on | ||
| 32 | ;; censorship, included in the etc directory of emacs distributions 19.34 | ||
| 33 | ;; and up. See also http://www.eff.org/blueribbon.html. | ||
| 34 | |||
| 35 | ;; For many years, emacs has included a program called Spook. This program | ||
| 36 | ;; adds a series of "keywords" to email just before it goes out. On the | ||
| 37 | ;; theory that the NSA monitors people's email, the keywords would be | ||
| 38 | ;; picked up by the NSA's snoop computers, causing them to waste time | ||
| 39 | ;; reading your meeting schedule notices or other email boring to everyone | ||
| 40 | ;; but you and (you hope) the recipient. See below (I left in the original | ||
| 41 | ;; writeup when I made this conversion), or the emacs documentation at | ||
| 42 | ;; ftp://prep.ai.mit.edu/pub/gnu/emacs-manual*. | ||
| 43 | |||
| 44 | ;; Bruce is a direct copy of spook, with the word "spook" replaced with | ||
| 45 | ;; the word "bruce". Thanks to "esr", whoever he, she or it may be, this | ||
| 46 | ;; conversion was an extremely easy piece of editing, suitable for a first | ||
| 47 | ;; essay at elisp programming. | ||
| 48 | |||
| 49 | ;; You may think of the name as having been derived from a certain Monty | ||
| 50 | ;; Python routine. Or from Lenny Bruce, who opposed censorship in his own | ||
| 51 | ;; inimitable way. Bruce does exactly what Spook does: it throws keywords | ||
| 52 | ;; into your email messages or other documents. | ||
| 53 | |||
| 54 | ;; However, in order to comply with the CDA as interpreted by Richard | ||
| 55 | ;; Stallman (see the essay on censorship), bruce is distributed without a | ||
| 56 | ;; data file from which to select words at random. Sorry about that. I | ||
| 57 | ;; believe the average user will be able to come up with a few words on | ||
| 58 | ;; his or her own. If that is a problem, feel free to ask any American | ||
| 59 | ;; teenager, preferrably one who attends a government school. Failing | ||
| 60 | ;; that, you might write to Mr. Clinton or Ms Reno or their successors and | ||
| 61 | ;; ask them for suggestions. Think of it as a public spirited act: the | ||
| 62 | ;; time they spend answering you is time not spent persecuting someone | ||
| 63 | ;; else. However, do ask them to respond by snail mail, where their | ||
| 64 | ;; suggestions would be legal. | ||
| 65 | |||
| 66 | ;; To build the data file, just start a file called bruce.lines in the etc | ||
| 67 | ;; directory of your emacs distribution. Note that each phrase or word has | ||
| 68 | ;; to be followed by an ascii 0, control-@. See the file spook.lines in | ||
| 69 | ;; the etc directory for an example. In emacs, use c-q c-@ to insert the | ||
| 70 | ;; ascii 0s. | ||
| 71 | |||
| 72 | ;; Once you have edited up a data file, you have to tell emacs how to find | ||
| 73 | ;; the program bruce. Add the follwing two lines to your .emacs file. Be | ||
| 74 | ;; sure to uncomment the second line. | ||
| 75 | |||
| 76 | ;; for bruce mode | ||
| 77 | ;; (autoload 'bruce "bruce" "Use the Bruce program to protest the CDA" t) | ||
| 78 | |||
| 79 | ;; Shut down emacs and fire it up again. Then "M-x bruce" should put some | ||
| 80 | ;; shocking words in the current buffer. | ||
| 81 | |||
| 82 | |||
| 83 | ;; Please note that I am not suggesting that you actually use this program | ||
| 84 | ;; to add "illegal" words to your email, or any other purpose. First, you | ||
| 85 | ;; don't really need a program to do it, and second, it would be illegal | ||
| 86 | ;; for me to suggest or advise that you actually break the law. This | ||
| 87 | ;; program was written as a demonstration only, and as an act of political | ||
| 88 | ;; protest and free expression protected by the First Amendment, or | ||
| 89 | ;; whatever is left of it. | ||
| 90 | |||
| 91 | |||
| 92 | ;; We now return to the original writeup for spook: | ||
| 93 | |||
| 94 | ;; Steve Strassmann <straz@media-lab.media.mit.edu> didn't write the | ||
| 95 | ;; program spook, from which this was adapted, and even if he did, he | ||
| 96 | ;; really didn't mean for you to use it in an anarchistic way. | ||
| 97 | ;; | ||
| 98 | ;; To use this: | ||
| 99 | ;; Just before sending mail, do M-x spook. | ||
| 100 | ;; A number of phrases will be inserted into your buffer, to help | ||
| 101 | ;; give your message that extra bit of attractiveness for automated | ||
| 102 | ;; keyword scanners. Help defeat the NSA trunk trawler! | ||
| 103 | |||
| 104 | ;;; Code: | ||
| 105 | |||
| 106 | (require 'cookie1) | ||
| 107 | |||
| 108 | ; Variables | ||
| 109 | (defvar bruce-phrases-file "~/bruce.lines" | ||
| 110 | "Keep your favorite phrases here.") | ||
| 111 | |||
| 112 | (defvar bruce-phrase-default-count 15 | ||
| 113 | "Default number of phrases to insert") | ||
| 114 | |||
| 115 | ;;;###autoload | ||
| 116 | (defun bruce () | ||
| 117 | "Adds that special touch of class to your outgoing mail." | ||
| 118 | (interactive) | ||
| 119 | (or (file-exists-p bruce-phrases-file) | ||
| 120 | (error "You need to create %s" bruce-phrases-file)) | ||
| 121 | (cookie-insert bruce-phrases-file | ||
| 122 | bruce-phrase-default-count | ||
| 123 | "Checking authorization..." | ||
| 124 | "Checking authorization...Approved")) | ||
| 125 | |||
| 126 | ;;;###autoload | ||
| 127 | (defun snarf-bruces () | ||
| 128 | "Return a vector containing the lines from `bruce-phrases-file'." | ||
| 129 | (or (file-exists-p bruce-phrases-file) | ||
| 130 | (error "You need to create %s" bruce-phrases-file)) | ||
| 131 | (cookie-snarf bruce-phrases-file | ||
| 132 | "Checking authorization..." | ||
| 133 | "Checking authorization...Approved")) | ||
| 134 | |||
| 135 | ;; Note: the implementation that used to take up most of this file has been | ||
| 136 | ;; cleaned up, generalized, gratuitously broken by esr, and now resides in | ||
| 137 | ;; cookie1.el. | ||
| 138 | |||
| 139 | ;;; bruce.el ends here | ||
diff --git a/lisp/progmodes/cperl-mode.el b/lisp/progmodes/cperl-mode.el new file mode 100644 index 00000000000..6285af4b45e --- /dev/null +++ b/lisp/progmodes/cperl-mode.el | |||
| @@ -0,0 +1,5307 @@ | |||
| 1 | ;;; cperl-mode.el --- Perl code editing commands for Emacs | ||
| 2 | |||
| 3 | ;; Copyright (C) 1985, 86, 87, 91, 92, 93, 94, 95, 96, 1997 | ||
| 4 | ;; Free Software Foundation, Inc. | ||
| 5 | |||
| 6 | ;; Author: Ilya Zakharevich and Bob Olson | ||
| 7 | ;; Maintainer: Ilya Zakharevich <ilya@math.ohio-state.edu> | ||
| 8 | ;; Keywords: languages, Perl | ||
| 9 | |||
| 10 | ;; This file is part of GNU Emacs. | ||
| 11 | |||
| 12 | ;; GNU Emacs is free software; you can redistribute it and/or modify | ||
| 13 | ;; it under the terms of the GNU General Public License as published by | ||
| 14 | ;; the Free Software Foundation; either version 2, or (at your option) | ||
| 15 | ;; any later version. | ||
| 16 | |||
| 17 | ;; GNU Emacs is distributed in the hope that it will be useful, | ||
| 18 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 19 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 20 | ;; GNU General Public License for more details. | ||
| 21 | |||
| 22 | ;; You should have received a copy of the GNU General Public License | ||
| 23 | ;; along with GNU Emacs; see the file COPYING. If not, write to the | ||
| 24 | ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
| 25 | ;; Boston, MA 02111-1307, USA. | ||
| 26 | |||
| 27 | ;;; Corrections made by Ilya Zakharevich ilya@math.mps.ohio-state.edu | ||
| 28 | ;;; XEmacs changes by Peter Arius arius@informatik.uni-erlangen.de | ||
| 29 | |||
| 30 | ;;; Commentary: | ||
| 31 | |||
| 32 | ;;; You can either fine-tune the bells and whistles of this mode or | ||
| 33 | ;;; bulk enable them by putting | ||
| 34 | |||
| 35 | ;; (setq cperl-hairy t) | ||
| 36 | |||
| 37 | ;;; in your .emacs file. (Emacs rulers do not consider it politically | ||
| 38 | ;;; correct to make whistles enabled by default.) | ||
| 39 | |||
| 40 | ;;; DO NOT FORGET to read micro-docs (available from `Perl' menu) <<<<<< | ||
| 41 | ;;; or as help on variables `cperl-tips', `cperl-problems', <<<<<< | ||
| 42 | ;;; `cperl-non-problems', `cperl-praise'. <<<<<< | ||
| 43 | |||
| 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 | ||
| 46 | ;;; either lazy-lock-mode or fast-lock-mode. I prefer lazy-lock. | ||
| 47 | |||
| 48 | ;;; Faces used now: three faces for first-class and second-class keywords | ||
| 49 | ;;; and control flow words, one for each: comments, string, labels, | ||
| 50 | ;;; functions definitions and packages, arrays, hashes, and variable | ||
| 51 | ;;; definitions. If you do not see all these faces, your font-lock does | ||
| 52 | ;;; not define them, so you need to define them manually. | ||
| 53 | |||
| 54 | ;;; into your .emacs file. | ||
| 55 | |||
| 56 | ;;;; This mode supports font-lock, imenu and mode-compile. In the | ||
| 57 | ;;;; hairy version font-lock is on, but you should activate imenu | ||
| 58 | ;;;; yourself (note that mode-compile is not standard yet). Well, you | ||
| 59 | ;;;; can use imenu from keyboard anyway (M-x imenu), but it is better | ||
| 60 | ;;;; to bind it like that: | ||
| 61 | |||
| 62 | ;; (define-key global-map [M-S-down-mouse-3] 'imenu) | ||
| 63 | |||
| 64 | ;;; Code: | ||
| 65 | |||
| 66 | (defconst cperl-xemacs-p (string-match "XEmacs\\|Lucid" emacs-version)) | ||
| 67 | |||
| 68 | (defvar cperl-extra-newline-before-brace nil | ||
| 69 | "*Non-nil means that if, elsif, while, until, else, for, foreach | ||
| 70 | and do constructs look like: | ||
| 71 | |||
| 72 | if () | ||
| 73 | { | ||
| 74 | } | ||
| 75 | |||
| 76 | instead of: | ||
| 77 | |||
| 78 | if () { | ||
| 79 | } | ||
| 80 | ") | ||
| 81 | |||
| 82 | (defvar cperl-indent-level 2 | ||
| 83 | "*Indentation of CPerl statements with respect to containing block.") | ||
| 84 | (defvar cperl-lineup-step nil | ||
| 85 | "*`cperl-lineup' will always lineup at multiple of this number. | ||
| 86 | If `nil', the value of `cperl-indent-level' will be used.") | ||
| 87 | (defvar cperl-brace-imaginary-offset 0 | ||
| 88 | "*Imagined indentation of a Perl open brace that actually follows a statement. | ||
| 89 | An open brace following other text is treated as if it were this far | ||
| 90 | to the right of the start of its line.") | ||
| 91 | (defvar cperl-brace-offset 0 | ||
| 92 | "*Extra indentation for braces, compared with other text in same context.") | ||
| 93 | (defvar cperl-label-offset -2 | ||
| 94 | "*Offset of CPerl label lines relative to usual indentation.") | ||
| 95 | (defvar cperl-min-label-indent 1 | ||
| 96 | "*Minimal offset of CPerl label lines.") | ||
| 97 | (defvar cperl-continued-statement-offset 2 | ||
| 98 | "*Extra indent for lines not starting new statements.") | ||
| 99 | (defvar cperl-continued-brace-offset 0 | ||
| 100 | "*Extra indent for substatements that start with open-braces. | ||
| 101 | This is in addition to cperl-continued-statement-offset.") | ||
| 102 | (defvar cperl-close-paren-offset -1 | ||
| 103 | "*Extra indent for substatements that start with close-parenthesis.") | ||
| 104 | |||
| 105 | (defvar cperl-auto-newline nil | ||
| 106 | "*Non-nil means automatically newline before and after braces, | ||
| 107 | and after colons and semicolons, inserted in CPerl code. The following | ||
| 108 | \\[cperl-electric-backspace] will remove the inserted whitespace. | ||
| 109 | Insertion after colons requires both this variable and | ||
| 110 | `cperl-auto-newline-after-colon' set.") | ||
| 111 | |||
| 112 | (defvar cperl-auto-newline-after-colon nil | ||
| 113 | "*Non-nil means automatically newline even after colons. | ||
| 114 | Subject to `cperl-auto-newline' setting.") | ||
| 115 | |||
| 116 | (defvar cperl-tab-always-indent t | ||
| 117 | "*Non-nil means TAB in CPerl mode should always reindent the current line, | ||
| 118 | regardless of where in the line point is when the TAB command is used.") | ||
| 119 | |||
| 120 | (defvar cperl-font-lock nil | ||
| 121 | "*Non-nil (and non-null) means CPerl buffers will use font-lock-mode. | ||
| 122 | Can be overwritten by `cperl-hairy' if nil.") | ||
| 123 | |||
| 124 | (defvar cperl-electric-lbrace-space nil | ||
| 125 | "*Non-nil (and non-null) means { after $ in CPerl buffers should be preceded by ` '. | ||
| 126 | Can be overwritten by `cperl-hairy' if nil.") | ||
| 127 | |||
| 128 | (defvar cperl-electric-parens-string "({[]})<" | ||
| 129 | "*String of parentheses that should be electric in CPerl. | ||
| 130 | Closing ones are electric only if the region is highlighted.") | ||
| 131 | |||
| 132 | (defvar cperl-electric-parens nil | ||
| 133 | "*Non-nil (and non-null) means parentheses should be electric in CPerl. | ||
| 134 | Can be overwritten by `cperl-hairy' if nil.") | ||
| 135 | (defvar cperl-electric-parens-mark | ||
| 136 | (and window-system | ||
| 137 | (or (and (boundp 'transient-mark-mode) ; For Emacs | ||
| 138 | transient-mark-mode) | ||
| 139 | (and (boundp 'zmacs-regions) ; For XEmacs | ||
| 140 | zmacs-regions))) | ||
| 141 | "*Not-nil means that electric parens look for active mark. | ||
| 142 | Default is yes if there is visual feedback on mark.") | ||
| 143 | |||
| 144 | (defvar cperl-electric-linefeed nil | ||
| 145 | "*If true, LFD should be hairy in CPerl, otherwise C-c LFD is hairy. | ||
| 146 | In any case these two mean plain and hairy linefeeds together. | ||
| 147 | Can be overwritten by `cperl-hairy' if nil.") | ||
| 148 | |||
| 149 | (defvar cperl-electric-keywords nil | ||
| 150 | "*Not-nil (and non-null) means keywords are electric in CPerl. | ||
| 151 | Can be overwritten by `cperl-hairy' if nil.") | ||
| 152 | |||
| 153 | (defvar cperl-hairy nil | ||
| 154 | "*Not-nil means all the bells and whistles are enabled in CPerl.") | ||
| 155 | |||
| 156 | (defvar cperl-comment-column 32 | ||
| 157 | "*Column to put comments in CPerl (use \\[cperl-indent]' to lineup with code).") | ||
| 158 | |||
| 159 | (defvar cperl-vc-header-alist '((SCCS "$sccs = '%W\%' ;") | ||
| 160 | (RCS "$rcs = ' $Id\$ ' ;")) | ||
| 161 | "*What to use as `vc-header-alist' in CPerl.") | ||
| 162 | |||
| 163 | (defvar cperl-info-on-command-no-prompt nil | ||
| 164 | "*Not-nil (and non-null) means not to prompt on C-h f. | ||
| 165 | The opposite behaviour is always available if prefixed with C-c. | ||
| 166 | Can be overwritten by `cperl-hairy' if nil.") | ||
| 167 | |||
| 168 | (defvar cperl-lazy-help-time nil | ||
| 169 | "*Not-nil (and non-null) means to show lazy help after given idle time.") | ||
| 170 | |||
| 171 | (defvar cperl-pod-face 'font-lock-comment-face | ||
| 172 | "*The result of evaluation of this expression is used for pod highlighting.") | ||
| 173 | |||
| 174 | (defvar cperl-pod-head-face 'font-lock-variable-name-face | ||
| 175 | "*The result of evaluation of this expression is used for pod highlighting. | ||
| 176 | Font for POD headers.") | ||
| 177 | |||
| 178 | (defvar cperl-here-face 'font-lock-string-face | ||
| 179 | "*The result of evaluation of this expression is used for here-docs highlighting.") | ||
| 180 | |||
| 181 | (defvar cperl-pod-here-fontify '(featurep 'font-lock) | ||
| 182 | "*Not-nil after evaluation means to highlight pod and here-docs sections.") | ||
| 183 | |||
| 184 | (defvar cperl-pod-here-scan t | ||
| 185 | "*Not-nil means look for pod and here-docs sections during startup. | ||
| 186 | You can always make lookup from menu or using \\[cperl-find-pods-heres].") | ||
| 187 | |||
| 188 | (defvar cperl-imenu-addback nil | ||
| 189 | "*Not-nil means add backreferences to generated `imenu's. | ||
| 190 | May require patched `imenu' and `imenu-go'.") | ||
| 191 | |||
| 192 | (defvar cperl-max-help-size 66 | ||
| 193 | "*Non-nil means shrink-wrapping of info-buffer allowed up to these percents.") | ||
| 194 | |||
| 195 | (defvar cperl-shrink-wrap-info-frame t | ||
| 196 | "*Non-nil means shrink-wrapping of info-buffer-frame allowed.") | ||
| 197 | |||
| 198 | (defvar cperl-info-page "perl" | ||
| 199 | "*Name of the info page containing perl docs. | ||
| 200 | Older version of this page was called `perl5', newer `perl'.") | ||
| 201 | |||
| 202 | (defvar cperl-use-syntax-table-text-property | ||
| 203 | (boundp 'parse-sexp-lookup-properties) | ||
| 204 | "*Non-nil means CPerl sets up and uses `syntax-table' text property.") | ||
| 205 | |||
| 206 | (defvar cperl-use-syntax-table-text-property-for-tags | ||
| 207 | cperl-use-syntax-table-text-property | ||
| 208 | "*Non-nil means: set up and use `syntax-table' text property generating TAGS.") | ||
| 209 | |||
| 210 | (defvar cperl-scan-files-regexp "\\.\\([pP][Llm]\\|xs\\)$" | ||
| 211 | "*Regexp to match files to scan when generating TAGS.") | ||
| 212 | |||
| 213 | (defvar cperl-noscan-files-regexp "/\\(\\.\\.?\\|SCCS\\|RCS\\|blib\\)$" | ||
| 214 | "*Regexp to match files/dirs to skip when generating TAGS.") | ||
| 215 | |||
| 216 | (defvar cperl-regexp-indent-step nil | ||
| 217 | "*indentation used when beautifying regexps. | ||
| 218 | If `nil', the value of `cperl-indent-level' will be used.") | ||
| 219 | |||
| 220 | (defvar cperl-indent-left-aligned-comments t | ||
| 221 | "*Non-nil means that the comment starting in leftmost column should indent.") | ||
| 222 | |||
| 223 | (defvar cperl-under-as-char t | ||
| 224 | "*Non-nil means that the _ (underline) should be treated as word char.") | ||
| 225 | |||
| 226 | |||
| 227 | |||
| 228 | |||
| 229 | ;;; Short extra-docs. | ||
| 230 | |||
| 231 | (defvar cperl-tips 'please-ignore-this-line | ||
| 232 | "Get newest version of this package from | ||
| 233 | ftp://ftp.math.ohio-state.edu/pub/users/ilya/emacs | ||
| 234 | and/or | ||
| 235 | ftp://ftp.math.ohio-state.edu/pub/users/ilya/perl | ||
| 236 | |||
| 237 | Get support packages choose-color.el (or font-lock-extra.el before | ||
| 238 | 19.30), imenu-go.el from the same place. \(Look for other files there | ||
| 239 | too... ;-). Get a patch for imenu.el in 19.29. Note that for 19.30 and | ||
| 240 | later you should use choose-color.el *instead* of font-lock-extra.el | ||
| 241 | \(and you will not get smart highlighting in C :-(). | ||
| 242 | |||
| 243 | Note that to enable Compile choices in the menu you need to install | ||
| 244 | mode-compile.el. | ||
| 245 | |||
| 246 | Get perl5-info from | ||
| 247 | $CPAN/doc/manual/info/perl-info.tar.gz | ||
| 248 | older version was on | ||
| 249 | http://www.metronet.com:70/9/perlinfo/perl5/manual/perl5-info.tar.gz | ||
| 250 | |||
| 251 | If you use imenu-go, run imenu on perl5-info buffer (you can do it | ||
| 252 | from CPerl menu). If many files are related, generate TAGS files from | ||
| 253 | Tools/Tags submenu in CPerl menu. | ||
| 254 | |||
| 255 | If some class structure is too complicated, use Tools/Hierarchy-view | ||
| 256 | from CPerl menu, or hierarchic view of imenu. The second one uses the | ||
| 257 | current buffer only, the first one requires generation of TAGS from | ||
| 258 | CPerl/Tools/Tags menu beforehand. | ||
| 259 | |||
| 260 | Run CPerl/Tools/Insert-spaces-if-needed to fix your lazy typing. | ||
| 261 | |||
| 262 | Switch auto-help on/off with CPerl/Tools/Auto-help. | ||
| 263 | |||
| 264 | Before reporting (non-)problems look in the problem section on what I | ||
| 265 | know about them.") | ||
| 266 | |||
| 267 | (defvar cperl-problems 'please-ignore-this-line | ||
| 268 | "Emacs has a _very_ restricted syntax parsing engine. | ||
| 269 | |||
| 270 | It may be corrected on the level of C code, please look in the | ||
| 271 | `non-problems' section if you want to volunteer. | ||
| 272 | |||
| 273 | CPerl mode tries to corrects some Emacs misunderstandings, however, | ||
| 274 | for efficiency reasons the degree of correction is different for | ||
| 275 | different operations. The partially corrected problems are: POD | ||
| 276 | sections, here-documents, regexps. The operations are: highlighting, | ||
| 277 | indentation, electric keywords, electric braces. | ||
| 278 | |||
| 279 | This may be confusing, since the regexp s#//#/#\; may be highlighted | ||
| 280 | as a comment, but it will be recognized as a regexp by the indentation | ||
| 281 | code. Or the opposite case, when a pod section is highlighted, but | ||
| 282 | may break the indentation of the following code (though indentation | ||
| 283 | should work if the balance of delimiters is not broken by POD). | ||
| 284 | |||
| 285 | The main trick (to make $ a \"backslash\") makes constructions like | ||
| 286 | ${aaa} look like unbalanced braces. The only trick I can think of is | ||
| 287 | to insert it as $ {aaa} (legal in perl5, not in perl4). | ||
| 288 | |||
| 289 | Similar problems arise in regexps, when /(\\s|$)/ should be rewritten | ||
| 290 | as /($|\\s)/. Note that such a transposition is not always possible | ||
| 291 | :-(. " ) | ||
| 292 | |||
| 293 | (defvar cperl-non-problems 'please-ignore-this-line | ||
| 294 | "As you know from `problems' section, Perl syntax is too hard for CPerl. | ||
| 295 | |||
| 296 | Most the time, if you write your own code, you may find an equivalent | ||
| 297 | \(and almost as readable) expression. | ||
| 298 | |||
| 299 | Try to help CPerl: add comments with embedded quotes to fix CPerl | ||
| 300 | misunderstandings about the end of quotation: | ||
| 301 | |||
| 302 | $a='500$'; # '; | ||
| 303 | |||
| 304 | You won't need it too often. The reason: $ \"quotes\" the following | ||
| 305 | character (this saves a life a lot of times in CPerl), thus due to | ||
| 306 | Emacs parsing rules it does not consider tick (i.e., ' ) after a | ||
| 307 | dollar as a closing one, but as a usual character. | ||
| 308 | |||
| 309 | Now the indentation code is pretty wise. The only drawback is that it | ||
| 310 | relies on Emacs parsing to find matching parentheses. And Emacs | ||
| 311 | *cannot* match parentheses in Perl 100% correctly. So | ||
| 312 | 1 if s#//#/#; | ||
| 313 | will not break indentation, but | ||
| 314 | 1 if ( s#//#/# ); | ||
| 315 | will. | ||
| 316 | |||
| 317 | By similar reasons | ||
| 318 | s\"abc\"def\"; | ||
| 319 | will confuse CPerl a lot. | ||
| 320 | |||
| 321 | If you still get wrong indentation in situation that you think the | ||
| 322 | code should be able to parse, try: | ||
| 323 | |||
| 324 | a) Check what Emacs thinks about balance of your parentheses. | ||
| 325 | b) Supply the code to me (IZ). | ||
| 326 | |||
| 327 | Pods are treated _very_ rudimentally. Here-documents are not treated | ||
| 328 | at all (except highlighting and inhibiting indentation). (This may | ||
| 329 | change some time. RMS approved making syntax lookup recognize text | ||
| 330 | attributes, but volunteers are needed to change Emacs C code.) | ||
| 331 | |||
| 332 | To speed up coloring the following compromises exist: | ||
| 333 | a) sub in $mypackage::sub may be highlighted. | ||
| 334 | b) -z in [a-z] may be highlighted. | ||
| 335 | c) if your regexp contains a keyword (like \"s\"), it may be highlighted. | ||
| 336 | |||
| 337 | |||
| 338 | Imenu in 19.31 is broken. Set `imenu-use-keymap-menu' to t, and remove | ||
| 339 | `car' before `imenu-choose-buffer-index' in `imenu'. | ||
| 340 | ") | ||
| 341 | |||
| 342 | (defvar cperl-praise 'please-ignore-this-line | ||
| 343 | "RMS asked me to list good things about CPerl. Here they go: | ||
| 344 | |||
| 345 | 0) It uses the newest `syntax-table' property ;-); | ||
| 346 | |||
| 347 | 1) It does 99% of Perl syntax correct (as opposed to 80-90% in Perl | ||
| 348 | mode - but the latter number may have improved too in last years) even | ||
| 349 | without `syntax-table' property; When using this property, it should | ||
| 350 | handle 99.995% of lines correct - or somesuch. | ||
| 351 | |||
| 352 | 2) It is generally belived to be \"the most user-friendly Emacs | ||
| 353 | package\" whatever it may mean (I doubt that the people who say similar | ||
| 354 | things tried _all_ the rest of Emacs ;-), but this was not a lonely | ||
| 355 | voice); | ||
| 356 | |||
| 357 | 3) Everything is customizable, one-by-one or in a big sweep; | ||
| 358 | |||
| 359 | 4) It has many easily-accessable \"tools\": | ||
| 360 | a) Can run program, check syntax, start debugger; | ||
| 361 | b) Can lineup vertically \"middles\" of rows, like `=' in | ||
| 362 | a = b; | ||
| 363 | cc = d; | ||
| 364 | c) Can insert spaces where this impoves readability (in one | ||
| 365 | interactive sweep over the buffer); | ||
| 366 | d) Has support for imenu, including: | ||
| 367 | 1) Separate unordered list of \"interesting places\"; | ||
| 368 | 2) Separate TOC of POD sections; | ||
| 369 | 3) Separate list of packages; | ||
| 370 | 4) Hierarchical view of methods in (sub)packages; | ||
| 371 | 5) and functions (by the full name - with package); | ||
| 372 | e) Has an interface to INFO docs for Perl; The interface is | ||
| 373 | very flexible, including shrink-wrapping of | ||
| 374 | documentation buffer/frame; | ||
| 375 | f) Has a builtin list of one-line explanations for perl constructs. | ||
| 376 | g) Can show these explanations if you stay long enough at the | ||
| 377 | corresponding place (or on demand); | ||
| 378 | h) Has an enhanced fontification (using 3 or 4 additional faces | ||
| 379 | comparing to font-lock - basically, different | ||
| 380 | namespaces in Perl have different colors); | ||
| 381 | i) Can construct TAGS basing on its knowledge of Perl syntax, | ||
| 382 | the standard menu has 6 different way to generate | ||
| 383 | TAGS (if by directory, .xs files - with C-language | ||
| 384 | bindings - are included in the scan); | ||
| 385 | j) Can build a hierarchical view of classes (via imenu) basing | ||
| 386 | on generated TAGS file; | ||
| 387 | k) Has electric parentheses, electric newlines, uses Abbrev | ||
| 388 | for electric logical constructs | ||
| 389 | while () {} | ||
| 390 | with different styles of expansion (context sensitive | ||
| 391 | to be not so bothering). Electric parentheses behave | ||
| 392 | \"as they should\" in a presence of a visible region. | ||
| 393 | l) Changes msb.el \"on the fly\" to insert a group \"Perl files\"; | ||
| 394 | |||
| 395 | 5) The indentation engine was very smart, but most of tricks may be | ||
| 396 | not needed anymore with the support for `syntax-table' property. Has | ||
| 397 | progress indicator for indentation (with `imenu' loaded). | ||
| 398 | |||
| 399 | 6) Indent-region improves inline-comments as well; | ||
| 400 | |||
| 401 | 7) Fill-paragraph correctly handles multi-line comments; | ||
| 402 | ") | ||
| 403 | |||
| 404 | |||
| 405 | |||
| 406 | ;;; Portability stuff: | ||
| 407 | |||
| 408 | (defmacro cperl-define-key (emacs-key definition &optional xemacs-key) | ||
| 409 | (` (define-key cperl-mode-map | ||
| 410 | (, (if xemacs-key | ||
| 411 | (` (if cperl-xemacs-p (, xemacs-key) (, emacs-key))) | ||
| 412 | emacs-key)) | ||
| 413 | (, definition)))) | ||
| 414 | |||
| 415 | (defvar cperl-del-back-ch | ||
| 416 | (car (append (where-is-internal 'delete-backward-char) | ||
| 417 | (where-is-internal 'backward-delete-char-untabify))) | ||
| 418 | "Character generated by key bound to delete-backward-char.") | ||
| 419 | |||
| 420 | (and (vectorp cperl-del-back-ch) (= (length cperl-del-back-ch) 1) | ||
| 421 | (setq cperl-del-back-ch (aref cperl-del-back-ch 0))) | ||
| 422 | |||
| 423 | (if cperl-xemacs-p | ||
| 424 | (progn | ||
| 425 | ;; "Active regions" are on: use region only if active | ||
| 426 | ;; "Active regions" are off: use region unconditionally | ||
| 427 | (defun cperl-use-region-p () | ||
| 428 | (if zmacs-regions (mark) t)) | ||
| 429 | (defun cperl-mark-active () (mark))) | ||
| 430 | (defun cperl-use-region-p () | ||
| 431 | (if transient-mark-mode mark-active t)) | ||
| 432 | (defun cperl-mark-active () mark-active)) | ||
| 433 | |||
| 434 | (defsubst cperl-enable-font-lock () | ||
| 435 | (or cperl-xemacs-p window-system)) | ||
| 436 | |||
| 437 | (if (boundp 'unread-command-events) | ||
| 438 | (if cperl-xemacs-p | ||
| 439 | (defun cperl-putback-char (c) ; XEmacs >= 19.12 | ||
| 440 | (setq unread-command-events (list (character-to-event c)))) | ||
| 441 | (defun cperl-putback-char (c) ; Emacs 19 | ||
| 442 | (setq unread-command-events (list c)))) | ||
| 443 | (defun cperl-putback-char (c) ; XEmacs <= 19.11 | ||
| 444 | (setq unread-command-event (character-to-event c)))) | ||
| 445 | |||
| 446 | (or (fboundp 'uncomment-region) | ||
| 447 | (defun uncomment-region (beg end) | ||
| 448 | (interactive "r") | ||
| 449 | (comment-region beg end -1))) | ||
| 450 | |||
| 451 | (defvar cperl-do-not-fontify | ||
| 452 | (if (string< emacs-version "19.30") | ||
| 453 | 'fontified | ||
| 454 | 'lazy-lock) | ||
| 455 | "Text property which inhibits refontification.") | ||
| 456 | |||
| 457 | (defsubst cperl-put-do-not-fontify (from to) | ||
| 458 | (put-text-property (max (point-min) (1- from)) | ||
| 459 | to cperl-do-not-fontify t)) | ||
| 460 | |||
| 461 | (defvar cperl-mode-hook nil | ||
| 462 | "Hook run by `cperl-mode'.") | ||
| 463 | |||
| 464 | |||
| 465 | ;;; Probably it is too late to set these guys already, but it can help later: | ||
| 466 | |||
| 467 | ;;;(setq auto-mode-alist | ||
| 468 | ;;; (append '(("\\.\\([pP][Llm]\\|al\\)$" . perl-mode)) auto-mode-alist )) | ||
| 469 | ;;;(and (boundp 'interpreter-mode-alist) | ||
| 470 | ;;; (setq interpreter-mode-alist (append interpreter-mode-alist | ||
| 471 | '(("miniperl" . perl-mode))))) | ||
| 472 | (if (fboundp 'eval-when-compile) | ||
| 473 | (eval-when-compile | ||
| 474 | (condition-case nil | ||
| 475 | (require 'imenu) | ||
| 476 | (error nil)) | ||
| 477 | (condition-case nil | ||
| 478 | (require 'easymenu) | ||
| 479 | (error nil)) | ||
| 480 | ;; Calling `cperl-enable-font-lock' below doesn't compile on XEmacs, | ||
| 481 | ;; macros instead of defsubsts don't work on Emacs, so we do the | ||
| 482 | ;; expansion manually. Any other suggestions? | ||
| 483 | (if (or (string-match "XEmacs\\|Lucid" emacs-version) | ||
| 484 | window-system) | ||
| 485 | (require 'font-lock)) | ||
| 486 | (require 'cl) | ||
| 487 | )) | ||
| 488 | |||
| 489 | (defvar cperl-mode-abbrev-table nil | ||
| 490 | "Abbrev table in use in Cperl-mode buffers.") | ||
| 491 | |||
| 492 | (add-hook 'edit-var-mode-alist '(perl-mode (regexp . "^cperl-"))) | ||
| 493 | |||
| 494 | (defvar cperl-mode-map () "Keymap used in CPerl mode.") | ||
| 495 | |||
| 496 | (if cperl-mode-map nil | ||
| 497 | (setq cperl-mode-map (make-sparse-keymap)) | ||
| 498 | (cperl-define-key "{" 'cperl-electric-lbrace) | ||
| 499 | (cperl-define-key "[" 'cperl-electric-paren) | ||
| 500 | (cperl-define-key "(" 'cperl-electric-paren) | ||
| 501 | (cperl-define-key "<" 'cperl-electric-paren) | ||
| 502 | (cperl-define-key "}" 'cperl-electric-brace) | ||
| 503 | (cperl-define-key "]" 'cperl-electric-rparen) | ||
| 504 | (cperl-define-key ")" 'cperl-electric-rparen) | ||
| 505 | (cperl-define-key ";" 'cperl-electric-semi) | ||
| 506 | (cperl-define-key ":" 'cperl-electric-terminator) | ||
| 507 | (cperl-define-key "\C-j" 'newline-and-indent) | ||
| 508 | (cperl-define-key "\C-c\C-j" 'cperl-linefeed) | ||
| 509 | (cperl-define-key "\C-c\C-a" 'cperl-toggle-auto-newline) | ||
| 510 | (cperl-define-key "\C-c\C-k" 'cperl-toggle-abbrev) | ||
| 511 | (cperl-define-key "\C-c\C-e" 'cperl-toggle-electric) | ||
| 512 | (cperl-define-key "\e\C-q" 'cperl-indent-exp) ; Usually not bound | ||
| 513 | (cperl-define-key [?\C-\M-\|] 'cperl-lineup | ||
| 514 | [(control meta |)]) | ||
| 515 | ;;(cperl-define-key "\M-q" 'cperl-fill-paragraph) | ||
| 516 | ;;(cperl-define-key "\e;" 'cperl-indent-for-comment) | ||
| 517 | (cperl-define-key "\177" 'cperl-electric-backspace) | ||
| 518 | (cperl-define-key "\t" 'cperl-indent-command) | ||
| 519 | ;; don't clobber the backspace binding: | ||
| 520 | (cperl-define-key "\C-c\C-hf" 'cperl-info-on-current-command | ||
| 521 | [(control c) (control h) f]) | ||
| 522 | (cperl-define-key "\C-hf" | ||
| 523 | ;;(concat (char-to-string help-char) "f") ; does not work | ||
| 524 | 'cperl-info-on-command | ||
| 525 | [(control h) f]) | ||
| 526 | (cperl-define-key "\C-hv" | ||
| 527 | ;;(concat (char-to-string help-char) "v") ; does not work | ||
| 528 | 'cperl-get-help | ||
| 529 | [(control h) v]) | ||
| 530 | (if (and cperl-xemacs-p | ||
| 531 | (<= emacs-minor-version 11) (<= emacs-major-version 19)) | ||
| 532 | (progn | ||
| 533 | ;; substitute-key-definition is usefulness-deenhanced... | ||
| 534 | (cperl-define-key "\M-q" 'cperl-fill-paragraph) | ||
| 535 | (cperl-define-key "\e;" 'cperl-indent-for-comment) | ||
| 536 | (cperl-define-key "\e\C-\\" 'cperl-indent-region)) | ||
| 537 | (substitute-key-definition | ||
| 538 | 'indent-sexp 'cperl-indent-exp | ||
| 539 | cperl-mode-map global-map) | ||
| 540 | (substitute-key-definition | ||
| 541 | 'fill-paragraph 'cperl-fill-paragraph | ||
| 542 | cperl-mode-map global-map) | ||
| 543 | (substitute-key-definition | ||
| 544 | 'indent-region 'cperl-indent-region | ||
| 545 | cperl-mode-map global-map) | ||
| 546 | (substitute-key-definition | ||
| 547 | 'indent-for-comment 'cperl-indent-for-comment | ||
| 548 | cperl-mode-map global-map))) | ||
| 549 | |||
| 550 | (defvar cperl-menu) | ||
| 551 | (condition-case nil | ||
| 552 | (progn | ||
| 553 | (require 'easymenu) | ||
| 554 | (easy-menu-define cperl-menu cperl-mode-map "Menu for CPerl mode" | ||
| 555 | '("Perl" | ||
| 556 | ["Beginning of function" beginning-of-defun t] | ||
| 557 | ["End of function" end-of-defun t] | ||
| 558 | ["Mark function" mark-defun t] | ||
| 559 | ["Indent expression" cperl-indent-exp t] | ||
| 560 | ["Fill paragraph/comment" cperl-fill-paragraph t] | ||
| 561 | "----" | ||
| 562 | ["Line up a construction" cperl-lineup (cperl-use-region-p)] | ||
| 563 | ["Beautify a regexp" cperl-beautify-regexp | ||
| 564 | cperl-use-syntax-table-text-property] | ||
| 565 | ["Beautify a group in regexp" cperl-beautify-level | ||
| 566 | cperl-use-syntax-table-text-property] | ||
| 567 | ["Contract a group in regexp" cperl-contract-level | ||
| 568 | cperl-use-syntax-table-text-property] | ||
| 569 | ["Refresh \"hard\" constructions" cperl-find-pods-heres t] | ||
| 570 | "----" | ||
| 571 | ["Indent region" cperl-indent-region (cperl-use-region-p)] | ||
| 572 | ["Comment region" cperl-comment-region (cperl-use-region-p)] | ||
| 573 | ["Uncomment region" cperl-uncomment-region (cperl-use-region-p)] | ||
| 574 | "----" | ||
| 575 | ["Run" mode-compile (fboundp 'mode-compile)] | ||
| 576 | ["Kill" mode-compile-kill (and (fboundp 'mode-compile-kill) | ||
| 577 | (get-buffer "*compilation*"))] | ||
| 578 | ["Next error" next-error (get-buffer "*compilation*")] | ||
| 579 | ["Check syntax" cperl-check-syntax (fboundp 'mode-compile)] | ||
| 580 | "----" | ||
| 581 | ["Debugger" cperl-db t] | ||
| 582 | "----" | ||
| 583 | ("Tools" | ||
| 584 | ["Imenu" imenu (fboundp 'imenu)] | ||
| 585 | ["Insert spaces if needed" cperl-find-bad-style t] | ||
| 586 | ["Class Hierarchy from TAGS" cperl-tags-hier-init t] | ||
| 587 | ;;["Update classes" (cperl-tags-hier-init t) tags-table-list] | ||
| 588 | ["Imenu on info" cperl-imenu-on-info (featurep 'imenu)] | ||
| 589 | ("Tags" | ||
| 590 | ;;; ["Create tags for current file" cperl-etags t] | ||
| 591 | ;;; ["Add tags for current file" (cperl-etags t) t] | ||
| 592 | ;;; ["Create tags for Perl files in directory" (cperl-etags nil t) t] | ||
| 593 | ;;; ["Add tags for Perl files in directory" (cperl-etags t t) t] | ||
| 594 | ;;; ["Create tags for Perl files in (sub)directories" | ||
| 595 | ;;; (cperl-etags nil 'recursive) t] | ||
| 596 | ;;; ["Add tags for Perl files in (sub)directories" | ||
| 597 | ;;; (cperl-etags t 'recursive) t]) | ||
| 598 | ;;;; cperl-write-tags (&optional file erase recurse dir inbuffer) | ||
| 599 | ["Create tags for current file" (cperl-write-tags nil t) t] | ||
| 600 | ["Add tags for current file" (cperl-write-tags) t] | ||
| 601 | ["Create tags for Perl files in directory" | ||
| 602 | (cperl-write-tags nil t nil t) t] | ||
| 603 | ["Add tags for Perl files in directory" | ||
| 604 | (cperl-write-tags nil nil nil t) t] | ||
| 605 | ["Create tags for Perl files in (sub)directories" | ||
| 606 | (cperl-write-tags nil t t t) t] | ||
| 607 | ["Add tags for Perl files in (sub)directories" | ||
| 608 | (cperl-write-tags nil nil t t) t]) | ||
| 609 | ["Define word at point" imenu-go-find-at-position | ||
| 610 | (fboundp 'imenu-go-find-at-position)] | ||
| 611 | ["Help on function" cperl-info-on-command t] | ||
| 612 | ["Help on function at point" cperl-info-on-current-command t] | ||
| 613 | ["Help on symbol at point" cperl-get-help t] | ||
| 614 | ["Auto-help on" cperl-lazy-install (fboundp 'run-with-idle-timer)] | ||
| 615 | ["Auto-help off" cperl-lazy-unstall | ||
| 616 | (fboundp 'run-with-idle-timer)]) | ||
| 617 | ("Toggle..." | ||
| 618 | ["Auto newline" cperl-toggle-auto-newline t] | ||
| 619 | ["Electric parens" cperl-toggle-electric t] | ||
| 620 | ["Electric keywords" cperl-toggle-abbrev t] | ||
| 621 | ) | ||
| 622 | ("Indent styles..." | ||
| 623 | ["GNU" (cperl-set-style "GNU") t] | ||
| 624 | ["C++" (cperl-set-style "C++") t] | ||
| 625 | ["FSF" (cperl-set-style "FSF") t] | ||
| 626 | ["BSD" (cperl-set-style "BSD") t] | ||
| 627 | ["Whitesmith" (cperl-set-style "Whitesmith") t]) | ||
| 628 | ("Micro-docs" | ||
| 629 | ["Tips" (describe-variable 'cperl-tips) t] | ||
| 630 | ["Problems" (describe-variable 'cperl-problems) t] | ||
| 631 | ["Non-problems" (describe-variable 'cperl-non-problems) t] | ||
| 632 | ["Praise" (describe-variable 'cperl-praise) t])))) | ||
| 633 | (error nil)) | ||
| 634 | |||
| 635 | (autoload 'c-macro-expand "cmacexp" | ||
| 636 | "Display the result of expanding all C macros occurring in the region. | ||
| 637 | The expansion is entirely correct because it uses the C preprocessor." | ||
| 638 | t) | ||
| 639 | |||
| 640 | (defvar cperl-mode-syntax-table nil | ||
| 641 | "Syntax table in use in Cperl-mode buffers.") | ||
| 642 | |||
| 643 | (defvar cperl-string-syntax-table nil | ||
| 644 | "Syntax table in use in Cperl-mode string-like chunks.") | ||
| 645 | |||
| 646 | (if cperl-mode-syntax-table | ||
| 647 | () | ||
| 648 | (setq cperl-mode-syntax-table (make-syntax-table)) | ||
| 649 | (modify-syntax-entry ?\\ "\\" cperl-mode-syntax-table) | ||
| 650 | (modify-syntax-entry ?/ "." cperl-mode-syntax-table) | ||
| 651 | (modify-syntax-entry ?* "." cperl-mode-syntax-table) | ||
| 652 | (modify-syntax-entry ?+ "." cperl-mode-syntax-table) | ||
| 653 | (modify-syntax-entry ?- "." cperl-mode-syntax-table) | ||
| 654 | (modify-syntax-entry ?= "." cperl-mode-syntax-table) | ||
| 655 | (modify-syntax-entry ?% "." cperl-mode-syntax-table) | ||
| 656 | (modify-syntax-entry ?< "." cperl-mode-syntax-table) | ||
| 657 | (modify-syntax-entry ?> "." cperl-mode-syntax-table) | ||
| 658 | (modify-syntax-entry ?& "." cperl-mode-syntax-table) | ||
| 659 | (modify-syntax-entry ?$ "\\" cperl-mode-syntax-table) | ||
| 660 | (modify-syntax-entry ?\n ">" cperl-mode-syntax-table) | ||
| 661 | (modify-syntax-entry ?# "<" cperl-mode-syntax-table) | ||
| 662 | (modify-syntax-entry ?' "\"" cperl-mode-syntax-table) | ||
| 663 | (modify-syntax-entry ?` "\"" cperl-mode-syntax-table) | ||
| 664 | (if cperl-under-as-char | ||
| 665 | (modify-syntax-entry ?_ "w" cperl-mode-syntax-table)) | ||
| 666 | (modify-syntax-entry ?: "_" cperl-mode-syntax-table) | ||
| 667 | (modify-syntax-entry ?| "." cperl-mode-syntax-table) | ||
| 668 | (setq cperl-string-syntax-table (copy-syntax-table cperl-mode-syntax-table)) | ||
| 669 | (modify-syntax-entry ?$ "." cperl-string-syntax-table) | ||
| 670 | (modify-syntax-entry ?# "." cperl-string-syntax-table) ; (?# comment ) | ||
| 671 | ) | ||
| 672 | |||
| 673 | |||
| 674 | |||
| 675 | ;; Make customization possible "in reverse" | ||
| 676 | ;;(defun cperl-set (symbol to) | ||
| 677 | ;; (or (eq (symbol-value symbol) 'null) (set symbol to))) | ||
| 678 | (defsubst cperl-val (symbol &optional default hairy) | ||
| 679 | (cond | ||
| 680 | ((eq (symbol-value symbol) 'null) default) | ||
| 681 | (cperl-hairy (or hairy t)) | ||
| 682 | (t (symbol-value symbol)))) | ||
| 683 | |||
| 684 | ;; provide an alias for working with emacs 19. the perl-mode that comes | ||
| 685 | ;; with it is really bad, and this lets us seamlessly replace it. | ||
| 686 | ;;;###autoload | ||
| 687 | (fset 'perl-mode 'cperl-mode) | ||
| 688 | (defvar cperl-faces-init) | ||
| 689 | ;; Fix for msb.el | ||
| 690 | (defvar cperl-msb-fixed nil) | ||
| 691 | ;;;###autoload | ||
| 692 | (defun cperl-mode () | ||
| 693 | "Major mode for editing Perl code. | ||
| 694 | Expression and list commands understand all C brackets. | ||
| 695 | Tab indents for Perl code. | ||
| 696 | Paragraphs are separated by blank lines only. | ||
| 697 | Delete converts tabs to spaces as it moves back. | ||
| 698 | |||
| 699 | Various characters in Perl almost always come in pairs: {}, (), [], | ||
| 700 | sometimes <>. When the user types the first, she gets the second as | ||
| 701 | well, with optional special formatting done on {}. (Disabled by | ||
| 702 | default.) You can always quote (with \\[quoted-insert]) the left | ||
| 703 | \"paren\" to avoid the expansion. The processing of < is special, | ||
| 704 | since most the time you mean \"less\". Cperl mode tries to guess | ||
| 705 | whether you want to type pair <>, and inserts is if it | ||
| 706 | appropriate. You can set `cperl-electric-parens-string' to the string that | ||
| 707 | contains the parenths from the above list you want to be electrical. | ||
| 708 | Electricity of parenths is controlled by `cperl-electric-parens'. | ||
| 709 | You may also set `cperl-electric-parens-mark' to have electric parens | ||
| 710 | look for active mark and \"embrace\" a region if possible.' | ||
| 711 | |||
| 712 | CPerl mode provides expansion of the Perl control constructs: | ||
| 713 | if, else, elsif, unless, while, until, for, and foreach. | ||
| 714 | =========(Disabled by default, see `cperl-electric-keywords'.) | ||
| 715 | The user types the keyword immediately followed by a space, which causes | ||
| 716 | the construct to be expanded, and the user is positioned where she is most | ||
| 717 | likely to want to be. | ||
| 718 | eg. when the user types a space following \"if\" the following appears in | ||
| 719 | the buffer: | ||
| 720 | if () { or if () | ||
| 721 | } { | ||
| 722 | } | ||
| 723 | and the cursor is between the parentheses. The user can then type some | ||
| 724 | boolean expression within the parens. Having done that, typing | ||
| 725 | \\[cperl-linefeed] places you, appropriately indented on a new line | ||
| 726 | between the braces. If CPerl decides that you want to insert | ||
| 727 | \"English\" style construct like | ||
| 728 | bite if angry; | ||
| 729 | it will not do any expansion. See also help on variable | ||
| 730 | `cperl-extra-newline-before-brace'. | ||
| 731 | |||
| 732 | \\[cperl-linefeed] is a convenience replacement for typing carriage | ||
| 733 | return. It places you in the next line with proper indentation, or if | ||
| 734 | you type it inside the inline block of control construct, like | ||
| 735 | foreach (@lines) {print; print} | ||
| 736 | and you are on a boundary of a statement inside braces, it will | ||
| 737 | transform the construct into a multiline and will place you into an | ||
| 738 | appropriately indented blank line. If you need a usual | ||
| 739 | `newline-and-indent' behaviour, it is on \\[newline-and-indent], | ||
| 740 | see documentation on `cperl-electric-linefeed'. | ||
| 741 | |||
| 742 | \\{cperl-mode-map} | ||
| 743 | |||
| 744 | Setting the variable `cperl-font-lock' to t switches on | ||
| 745 | font-lock-mode, `cperl-electric-lbrace-space' to t switches on | ||
| 746 | electric space between $ and {, `cperl-electric-parens-string' is the | ||
| 747 | string that contains parentheses that should be electric in CPerl (see | ||
| 748 | also `cperl-electric-parens-mark' and `cperl-electric-parens'), | ||
| 749 | setting `cperl-electric-keywords' enables electric expansion of | ||
| 750 | control structures in CPerl. `cperl-electric-linefeed' governs which | ||
| 751 | one of two linefeed behavior is preferable. You can enable all these | ||
| 752 | options simultaneously (recommended mode of use) by setting | ||
| 753 | `cperl-hairy' to t. In this case you can switch separate options off | ||
| 754 | by setting them to `null'. Note that one may undo the extra whitespace | ||
| 755 | inserted by semis and braces in `auto-newline'-mode by consequent | ||
| 756 | \\[cperl-electric-backspace]. | ||
| 757 | |||
| 758 | If your site has perl5 documentation in info format, you can use commands | ||
| 759 | \\[cperl-info-on-current-command] and \\[cperl-info-on-command] to access it. | ||
| 760 | These keys run commands `cperl-info-on-current-command' and | ||
| 761 | `cperl-info-on-command', which one is which is controlled by variable | ||
| 762 | `cperl-info-on-command-no-prompt' (in turn affected by `cperl-hairy'). | ||
| 763 | |||
| 764 | Even if you have no info-format documentation, short one-liner-style | ||
| 765 | help is available on \\[cperl-get-help]. | ||
| 766 | |||
| 767 | It is possible to show this help automatically after some idle | ||
| 768 | time. This is regulated by variable `cperl-lazy-help-time'. Default | ||
| 769 | with `cperl-hairy' is 5 secs idle time if the value of this variable | ||
| 770 | is nil. It is also possible to switch this on/off from the | ||
| 771 | menu. Requires `run-with-idle-timer'. | ||
| 772 | |||
| 773 | Use \\[cperl-lineup] to vertically lineup some construction - put the | ||
| 774 | beginning of the region at the start of construction, and make region | ||
| 775 | span the needed amount of lines. | ||
| 776 | |||
| 777 | Variables `cperl-pod-here-scan', `cperl-pod-here-fontify', | ||
| 778 | `cperl-pod-face', `cperl-pod-head-face' control processing of pod and | ||
| 779 | here-docs sections. In a future version results of scan may be used | ||
| 780 | for indentation too, currently they are used for highlighting only. | ||
| 781 | |||
| 782 | Variables controlling indentation style: | ||
| 783 | `cperl-tab-always-indent' | ||
| 784 | Non-nil means TAB in CPerl mode should always reindent the current line, | ||
| 785 | regardless of where in the line point is when the TAB command is used. | ||
| 786 | `cperl-auto-newline' | ||
| 787 | Non-nil means automatically newline before and after braces, | ||
| 788 | and after colons and semicolons, inserted in Perl code. The following | ||
| 789 | \\[cperl-electric-backspace] will remove the inserted whitespace. | ||
| 790 | Insertion after colons requires both this variable and | ||
| 791 | `cperl-auto-newline-after-colon' set. | ||
| 792 | `cperl-auto-newline-after-colon' | ||
| 793 | Non-nil means automatically newline even after colons. | ||
| 794 | Subject to `cperl-auto-newline' setting. | ||
| 795 | `cperl-indent-level' | ||
| 796 | Indentation of Perl statements within surrounding block. | ||
| 797 | The surrounding block's indentation is the indentation | ||
| 798 | of the line on which the open-brace appears. | ||
| 799 | `cperl-continued-statement-offset' | ||
| 800 | Extra indentation given to a substatement, such as the | ||
| 801 | then-clause of an if, or body of a while, or just a statement continuation. | ||
| 802 | `cperl-continued-brace-offset' | ||
| 803 | Extra indentation given to a brace that starts a substatement. | ||
| 804 | This is in addition to `cperl-continued-statement-offset'. | ||
| 805 | `cperl-brace-offset' | ||
| 806 | Extra indentation for line if it starts with an open brace. | ||
| 807 | `cperl-brace-imaginary-offset' | ||
| 808 | An open brace following other text is treated as if it the line started | ||
| 809 | this far to the right of the actual line indentation. | ||
| 810 | `cperl-label-offset' | ||
| 811 | Extra indentation for line that is a label. | ||
| 812 | `cperl-min-label-indent' | ||
| 813 | Minimal indentation for line that is a label. | ||
| 814 | |||
| 815 | Settings for K&R and BSD indentation styles are | ||
| 816 | `cperl-indent-level' 5 8 | ||
| 817 | `cperl-continued-statement-offset' 5 8 | ||
| 818 | `cperl-brace-offset' -5 -8 | ||
| 819 | `cperl-label-offset' -5 -8 | ||
| 820 | |||
| 821 | If `cperl-indent-level' is 0, the statement after opening brace in column 0 is indented on `cperl-brace-offset'+`cperl-continued-statement-offset'. | ||
| 822 | |||
| 823 | Turning on CPerl mode calls the hooks in the variable `cperl-mode-hook' | ||
| 824 | with no args." | ||
| 825 | (interactive) | ||
| 826 | (kill-all-local-variables) | ||
| 827 | ;;(if cperl-hairy | ||
| 828 | ;; (progn | ||
| 829 | ;; (cperl-set 'cperl-font-lock cperl-hairy) | ||
| 830 | ;; (cperl-set 'cperl-electric-lbrace-space cperl-hairy) | ||
| 831 | ;; (cperl-set 'cperl-electric-parens "{[(<") | ||
| 832 | ;; (cperl-set 'cperl-electric-keywords cperl-hairy) | ||
| 833 | ;; (cperl-set 'cperl-electric-linefeed cperl-hairy))) | ||
| 834 | (use-local-map cperl-mode-map) | ||
| 835 | (if (cperl-val 'cperl-electric-linefeed) | ||
| 836 | (progn | ||
| 837 | (local-set-key "\C-J" 'cperl-linefeed) | ||
| 838 | (local-set-key "\C-C\C-J" 'newline-and-indent))) | ||
| 839 | (if (cperl-val 'cperl-info-on-command-no-prompt) | ||
| 840 | (progn | ||
| 841 | ;; don't clobber the backspace binding: | ||
| 842 | (cperl-define-key "\C-hf" 'cperl-info-on-current-command [(control h) f]) | ||
| 843 | (cperl-define-key "\C-c\C-hf" 'cperl-info-on-command | ||
| 844 | [(control c) (control h) f]))) | ||
| 845 | (setq major-mode 'perl-mode) | ||
| 846 | (setq mode-name "CPerl") | ||
| 847 | (if (not cperl-mode-abbrev-table) | ||
| 848 | (let ((prev-a-c abbrevs-changed)) | ||
| 849 | (define-abbrev-table 'cperl-mode-abbrev-table '( | ||
| 850 | ("if" "if" cperl-electric-keyword 0) | ||
| 851 | ("elsif" "elsif" cperl-electric-keyword 0) | ||
| 852 | ("while" "while" cperl-electric-keyword 0) | ||
| 853 | ("until" "until" cperl-electric-keyword 0) | ||
| 854 | ("unless" "unless" cperl-electric-keyword 0) | ||
| 855 | ("else" "else" cperl-electric-else 0) | ||
| 856 | ("for" "for" cperl-electric-keyword 0) | ||
| 857 | ("foreach" "foreach" cperl-electric-keyword 0) | ||
| 858 | ("do" "do" cperl-electric-keyword 0))) | ||
| 859 | (setq abbrevs-changed prev-a-c))) | ||
| 860 | (setq local-abbrev-table cperl-mode-abbrev-table) | ||
| 861 | (abbrev-mode (if (cperl-val 'cperl-electric-keywords) 1 0)) | ||
| 862 | (set-syntax-table cperl-mode-syntax-table) | ||
| 863 | (make-local-variable 'paragraph-start) | ||
| 864 | (setq paragraph-start (concat "^$\\|" page-delimiter)) | ||
| 865 | (make-local-variable 'paragraph-separate) | ||
| 866 | (setq paragraph-separate paragraph-start) | ||
| 867 | (make-local-variable 'paragraph-ignore-fill-prefix) | ||
| 868 | (setq paragraph-ignore-fill-prefix t) | ||
| 869 | (make-local-variable 'indent-line-function) | ||
| 870 | (setq indent-line-function 'cperl-indent-line) | ||
| 871 | (make-local-variable 'require-final-newline) | ||
| 872 | (setq require-final-newline t) | ||
| 873 | (make-local-variable 'comment-start) | ||
| 874 | (setq comment-start "# ") | ||
| 875 | (make-local-variable 'comment-end) | ||
| 876 | (setq comment-end "") | ||
| 877 | (make-local-variable 'comment-column) | ||
| 878 | (setq comment-column cperl-comment-column) | ||
| 879 | (make-local-variable 'comment-start-skip) | ||
| 880 | (setq comment-start-skip "#+ *") | ||
| 881 | (make-local-variable 'defun-prompt-regexp) | ||
| 882 | (setq defun-prompt-regexp "^[ \t]*sub[ \t]+\\([^ \t\n{(;]+\\)[ \t]*") | ||
| 883 | (make-local-variable 'comment-indent-function) | ||
| 884 | (setq comment-indent-function 'cperl-comment-indent) | ||
| 885 | (make-local-variable 'parse-sexp-ignore-comments) | ||
| 886 | (setq parse-sexp-ignore-comments t) | ||
| 887 | (make-local-variable 'indent-region-function) | ||
| 888 | (setq indent-region-function 'cperl-indent-region) | ||
| 889 | ;;(setq auto-fill-function 'cperl-do-auto-fill) ; Need to switch on and off! | ||
| 890 | (make-local-variable 'imenu-create-index-function) | ||
| 891 | (setq imenu-create-index-function | ||
| 892 | (function imenu-example--create-perl-index)) | ||
| 893 | (make-local-variable 'imenu-sort-function) | ||
| 894 | (setq imenu-sort-function nil) | ||
| 895 | (make-local-variable 'vc-header-alist) | ||
| 896 | (setq vc-header-alist cperl-vc-header-alist) | ||
| 897 | (make-local-variable 'font-lock-defaults) | ||
| 898 | (setq font-lock-defaults | ||
| 899 | (if (string< emacs-version "19.30") | ||
| 900 | '(perl-font-lock-keywords-2) | ||
| 901 | '((perl-font-lock-keywords | ||
| 902 | perl-font-lock-keywords-1 | ||
| 903 | perl-font-lock-keywords-2)))) | ||
| 904 | (if cperl-use-syntax-table-text-property | ||
| 905 | (progn | ||
| 906 | (make-variable-buffer-local 'parse-sexp-lookup-properties) | ||
| 907 | ;; Do not introduce variable if not needed, we check it! | ||
| 908 | (set 'parse-sexp-lookup-properties t))) | ||
| 909 | (or (fboundp 'cperl-old-auto-fill-mode) | ||
| 910 | (progn | ||
| 911 | (fset 'cperl-old-auto-fill-mode (symbol-function 'auto-fill-mode)) | ||
| 912 | (defun auto-fill-mode (&optional arg) | ||
| 913 | (interactive "P") | ||
| 914 | (cperl-old-auto-fill-mode arg) | ||
| 915 | (and auto-fill-function (eq major-mode 'perl-mode) | ||
| 916 | (setq auto-fill-function 'cperl-do-auto-fill))))) | ||
| 917 | (if (cperl-enable-font-lock) | ||
| 918 | (if (cperl-val 'cperl-font-lock) | ||
| 919 | (progn (or cperl-faces-init (cperl-init-faces)) | ||
| 920 | (font-lock-mode 1)))) | ||
| 921 | (and (boundp 'msb-menu-cond) | ||
| 922 | (not cperl-msb-fixed) | ||
| 923 | (cperl-msb-fix)) | ||
| 924 | (if (featurep 'easymenu) | ||
| 925 | (easy-menu-add cperl-menu)) ; A NOP in Emacs. | ||
| 926 | (run-hooks 'cperl-mode-hook) | ||
| 927 | ;; After hooks since fontification will break this | ||
| 928 | (if cperl-pod-here-scan (cperl-find-pods-heres))) | ||
| 929 | |||
| 930 | ;; Fix for perldb - make default reasonable | ||
| 931 | (defun cperl-db () | ||
| 932 | (interactive) | ||
| 933 | (require 'gud) | ||
| 934 | (perldb (read-from-minibuffer "Run perldb (like this): " | ||
| 935 | (if (consp gud-perldb-history) | ||
| 936 | (car gud-perldb-history) | ||
| 937 | (concat "perl " ;;(file-name-nondirectory | ||
| 938 | ;; I have problems | ||
| 939 | ;; in OS/2 | ||
| 940 | ;; otherwise | ||
| 941 | (buffer-file-name))) | ||
| 942 | nil nil | ||
| 943 | '(gud-perldb-history . 1)))) | ||
| 944 | |||
| 945 | |||
| 946 | (defun cperl-msb-fix () | ||
| 947 | ;; Adds perl files to msb menu, supposes that msb is already loaded | ||
| 948 | (setq cperl-msb-fixed t) | ||
| 949 | (let* ((l (length msb-menu-cond)) | ||
| 950 | (last (nth (1- l) msb-menu-cond)) | ||
| 951 | (precdr (nthcdr (- l 2) msb-menu-cond)) ; cdr of this is last | ||
| 952 | (handle (1- (nth 1 last)))) | ||
| 953 | (setcdr precdr (list | ||
| 954 | (list | ||
| 955 | '(eq major-mode 'perl-mode) | ||
| 956 | handle | ||
| 957 | "Perl Files (%d)") | ||
| 958 | last)))) | ||
| 959 | |||
| 960 | ;; This is used by indent-for-comment | ||
| 961 | ;; to decide how much to indent a comment in CPerl code | ||
| 962 | ;; based on its context. Do fallback if comment is found wrong. | ||
| 963 | |||
| 964 | (defvar cperl-wrong-comment) | ||
| 965 | |||
| 966 | (defun cperl-comment-indent () | ||
| 967 | (let ((p (point)) (c (current-column)) was) | ||
| 968 | (if (looking-at "^#") 0 ; Existing comment at bol stays there. | ||
| 969 | ;; Wrong comment found | ||
| 970 | (save-excursion | ||
| 971 | (setq was (cperl-to-comment-or-eol)) | ||
| 972 | (if (= (point) p) | ||
| 973 | (progn | ||
| 974 | (skip-chars-backward " \t") | ||
| 975 | (max (1+ (current-column)) ; Else indent at comment column | ||
| 976 | comment-column)) | ||
| 977 | (if was nil | ||
| 978 | (insert comment-start) | ||
| 979 | (backward-char (length comment-start))) | ||
| 980 | (setq cperl-wrong-comment t) | ||
| 981 | (indent-to comment-column 1) ; Indent minimum 1 | ||
| 982 | c))))) ; except leave at least one space. | ||
| 983 | |||
| 984 | ;;;(defun cperl-comment-indent-fallback () | ||
| 985 | ;;; "Is called if the standard comment-search procedure fails. | ||
| 986 | ;;;Point is at start of real comment." | ||
| 987 | ;;; (let ((c (current-column)) target cnt prevc) | ||
| 988 | ;;; (if (= c comment-column) nil | ||
| 989 | ;;; (setq cnt (skip-chars-backward "[ \t]")) | ||
| 990 | ;;; (setq target (max (1+ (setq prevc | ||
| 991 | ;;; (current-column))) ; Else indent at comment column | ||
| 992 | ;;; comment-column)) | ||
| 993 | ;;; (if (= c comment-column) nil | ||
| 994 | ;;; (delete-backward-char cnt) | ||
| 995 | ;;; (while (< prevc target) | ||
| 996 | ;;; (insert "\t") | ||
| 997 | ;;; (setq prevc (current-column))) | ||
| 998 | ;;; (if (> prevc target) (progn (delete-char -1) (setq prevc (current-column)))) | ||
| 999 | ;;; (while (< prevc target) | ||
| 1000 | ;;; (insert " ") | ||
| 1001 | ;;; (setq prevc (current-column))))))) | ||
| 1002 | |||
| 1003 | (defun cperl-indent-for-comment () | ||
| 1004 | "Substitute for `indent-for-comment' in CPerl." | ||
| 1005 | (interactive) | ||
| 1006 | (let (cperl-wrong-comment) | ||
| 1007 | (indent-for-comment) | ||
| 1008 | (if cperl-wrong-comment | ||
| 1009 | (progn (cperl-to-comment-or-eol) | ||
| 1010 | (forward-char (length comment-start)))))) | ||
| 1011 | |||
| 1012 | (defun cperl-comment-region (b e arg) | ||
| 1013 | "Comment or uncomment each line in the region in CPerl mode. | ||
| 1014 | See `comment-region'." | ||
| 1015 | (interactive "r\np") | ||
| 1016 | (let ((comment-start "#")) | ||
| 1017 | (comment-region b e arg))) | ||
| 1018 | |||
| 1019 | (defun cperl-uncomment-region (b e arg) | ||
| 1020 | "Uncomment or comment each line in the region in CPerl mode. | ||
| 1021 | See `comment-region'." | ||
| 1022 | (interactive "r\np") | ||
| 1023 | (let ((comment-start "#")) | ||
| 1024 | (comment-region b e (- arg)))) | ||
| 1025 | |||
| 1026 | (defvar cperl-brace-recursing nil) | ||
| 1027 | |||
| 1028 | (defun cperl-electric-brace (arg &optional only-before) | ||
| 1029 | "Insert character and correct line's indentation. | ||
| 1030 | If ONLY-BEFORE and `cperl-auto-newline', will insert newline before the | ||
| 1031 | place (even in empty line), but not after. If after \")\" and the inserted | ||
| 1032 | char is \"{\", insert extra newline before only if | ||
| 1033 | `cperl-extra-newline-before-brace'." | ||
| 1034 | (interactive "P") | ||
| 1035 | (let (insertpos | ||
| 1036 | (other-end (if (and cperl-electric-parens-mark | ||
| 1037 | (cperl-mark-active) | ||
| 1038 | (< (mark) (point))) | ||
| 1039 | (mark) | ||
| 1040 | nil))) | ||
| 1041 | (if (and other-end | ||
| 1042 | (not cperl-brace-recursing) | ||
| 1043 | (cperl-val 'cperl-electric-parens) | ||
| 1044 | (>= (save-excursion (cperl-to-comment-or-eol) (point)) (point))) | ||
| 1045 | ;; Need to insert a matching pair | ||
| 1046 | (progn | ||
| 1047 | (save-excursion | ||
| 1048 | (setq insertpos (point-marker)) | ||
| 1049 | (goto-char other-end) | ||
| 1050 | (setq last-command-char ?\{) | ||
| 1051 | (cperl-electric-lbrace arg insertpos)) | ||
| 1052 | (forward-char 1)) | ||
| 1053 | (if (and (not arg) ; No args, end (of empty line or auto) | ||
| 1054 | (eolp) | ||
| 1055 | (or (and (null only-before) | ||
| 1056 | (save-excursion | ||
| 1057 | (skip-chars-backward " \t") | ||
| 1058 | (bolp))) | ||
| 1059 | (and (eq last-command-char ?\{) ; Do not insert newline | ||
| 1060 | ;; if after ")" and `cperl-extra-newline-before-brace' | ||
| 1061 | ;; is nil, do not insert extra newline. | ||
| 1062 | (not cperl-extra-newline-before-brace) | ||
| 1063 | (save-excursion | ||
| 1064 | (skip-chars-backward " \t") | ||
| 1065 | (eq (preceding-char) ?\)))) | ||
| 1066 | (if cperl-auto-newline | ||
| 1067 | (progn (cperl-indent-line) (newline) t) nil))) | ||
| 1068 | (progn | ||
| 1069 | (self-insert-command (prefix-numeric-value arg)) | ||
| 1070 | (cperl-indent-line) | ||
| 1071 | (if cperl-auto-newline | ||
| 1072 | (setq insertpos (1- (point)))) | ||
| 1073 | (if (and cperl-auto-newline (null only-before)) | ||
| 1074 | (progn | ||
| 1075 | (newline) | ||
| 1076 | (cperl-indent-line))) | ||
| 1077 | (save-excursion | ||
| 1078 | (if insertpos (progn (goto-char insertpos) | ||
| 1079 | (search-forward (make-string | ||
| 1080 | 1 last-command-char)) | ||
| 1081 | (setq insertpos (1- (point))))) | ||
| 1082 | (delete-char -1)))) | ||
| 1083 | (if insertpos | ||
| 1084 | (save-excursion | ||
| 1085 | (goto-char insertpos) | ||
| 1086 | (self-insert-command (prefix-numeric-value arg))) | ||
| 1087 | (self-insert-command (prefix-numeric-value arg)))))) | ||
| 1088 | |||
| 1089 | (defun cperl-electric-lbrace (arg &optional end) | ||
| 1090 | "Insert character, correct line's indentation, correct quoting by space." | ||
| 1091 | (interactive "P") | ||
| 1092 | (let (pos after | ||
| 1093 | (cperl-brace-recursing t) | ||
| 1094 | (cperl-auto-newline cperl-auto-newline) | ||
| 1095 | (other-end (or end | ||
| 1096 | (if (and cperl-electric-parens-mark | ||
| 1097 | (cperl-mark-active) | ||
| 1098 | (> (mark) (point))) | ||
| 1099 | (save-excursion | ||
| 1100 | (goto-char (mark)) | ||
| 1101 | (point-marker)) | ||
| 1102 | nil)))) | ||
| 1103 | (and (cperl-val 'cperl-electric-lbrace-space) | ||
| 1104 | (eq (preceding-char) ?$) | ||
| 1105 | (save-excursion | ||
| 1106 | (skip-chars-backward "$") | ||
| 1107 | (looking-at "\\(\\$\\$\\)*\\$\\([^\\$]\\|$\\)")) | ||
| 1108 | (insert ?\ )) | ||
| 1109 | (if (cperl-after-expr-p nil "{;)") nil (setq cperl-auto-newline nil)) | ||
| 1110 | (cperl-electric-brace arg) | ||
| 1111 | (and (cperl-val 'cperl-electric-parens) | ||
| 1112 | (eq last-command-char ?{) | ||
| 1113 | (memq last-command-char | ||
| 1114 | (append cperl-electric-parens-string nil)) | ||
| 1115 | (or (if other-end (goto-char (marker-position other-end))) | ||
| 1116 | t) | ||
| 1117 | (setq last-command-char ?} pos (point)) | ||
| 1118 | (progn (cperl-electric-brace arg t) | ||
| 1119 | (goto-char pos))))) | ||
| 1120 | |||
| 1121 | (defun cperl-electric-paren (arg) | ||
| 1122 | "Insert a matching pair of parentheses." | ||
| 1123 | (interactive "P") | ||
| 1124 | (let ((beg (save-excursion (beginning-of-line) (point))) | ||
| 1125 | (other-end (if (and cperl-electric-parens-mark | ||
| 1126 | (cperl-mark-active) | ||
| 1127 | (> (mark) (point))) | ||
| 1128 | (save-excursion | ||
| 1129 | (goto-char (mark)) | ||
| 1130 | (point-marker)) | ||
| 1131 | nil))) | ||
| 1132 | (if (and (cperl-val 'cperl-electric-parens) | ||
| 1133 | (memq last-command-char | ||
| 1134 | (append cperl-electric-parens-string nil)) | ||
| 1135 | (>= (save-excursion (cperl-to-comment-or-eol) (point)) (point)) | ||
| 1136 | ;;(not (save-excursion (search-backward "#" beg t))) | ||
| 1137 | (if (eq last-command-char ?<) | ||
| 1138 | (progn | ||
| 1139 | (and abbrev-mode ; later it is too late, may be after `for' | ||
| 1140 | (expand-abbrev)) | ||
| 1141 | (cperl-after-expr-p nil "{;(,:=")) | ||
| 1142 | 1)) | ||
| 1143 | (progn | ||
| 1144 | (self-insert-command (prefix-numeric-value arg)) | ||
| 1145 | (if other-end (goto-char (marker-position other-end))) | ||
| 1146 | (insert (make-string | ||
| 1147 | (prefix-numeric-value arg) | ||
| 1148 | (cdr (assoc last-command-char '((?{ .?}) | ||
| 1149 | (?[ . ?]) | ||
| 1150 | (?( . ?)) | ||
| 1151 | (?< . ?>)))))) | ||
| 1152 | (forward-char (- (prefix-numeric-value arg)))) | ||
| 1153 | (self-insert-command (prefix-numeric-value arg))))) | ||
| 1154 | |||
| 1155 | (defun cperl-electric-rparen (arg) | ||
| 1156 | "Insert a matching pair of parentheses if marking is active. | ||
| 1157 | If not, or if we are not at the end of marking range, would self-insert." | ||
| 1158 | (interactive "P") | ||
| 1159 | (let ((beg (save-excursion (beginning-of-line) (point))) | ||
| 1160 | (other-end (if (and cperl-electric-parens-mark | ||
| 1161 | (cperl-val 'cperl-electric-parens) | ||
| 1162 | (memq last-command-char | ||
| 1163 | (append cperl-electric-parens-string nil)) | ||
| 1164 | (cperl-mark-active) | ||
| 1165 | (< (mark) (point))) | ||
| 1166 | (mark) | ||
| 1167 | nil)) | ||
| 1168 | p) | ||
| 1169 | (if (and other-end | ||
| 1170 | (cperl-val 'cperl-electric-parens) | ||
| 1171 | (memq last-command-char '( ?\) ?\] ?\} ?\> )) | ||
| 1172 | (>= (save-excursion (cperl-to-comment-or-eol) (point)) (point)) | ||
| 1173 | ;;(not (save-excursion (search-backward "#" beg t))) | ||
| 1174 | ) | ||
| 1175 | (progn | ||
| 1176 | (self-insert-command (prefix-numeric-value arg)) | ||
| 1177 | (setq p (point)) | ||
| 1178 | (if other-end (goto-char other-end)) | ||
| 1179 | (insert (make-string | ||
| 1180 | (prefix-numeric-value arg) | ||
| 1181 | (cdr (assoc last-command-char '((?\} . ?\{) | ||
| 1182 | (?\] . ?\[) | ||
| 1183 | (?\) . ?\() | ||
| 1184 | (?\> . ?\<)))))) | ||
| 1185 | (goto-char (1+ p))) | ||
| 1186 | (self-insert-command (prefix-numeric-value arg))))) | ||
| 1187 | |||
| 1188 | (defun cperl-electric-keyword () | ||
| 1189 | "Insert a construction appropriate after a keyword." | ||
| 1190 | (let ((beg (save-excursion (beginning-of-line) (point))) | ||
| 1191 | (dollar (and (eq last-command-char ?$) | ||
| 1192 | (eq this-command 'self-insert-command))) | ||
| 1193 | (delete (and (memq last-command-char '(?\ ?\n ?\t ?\f)) | ||
| 1194 | (memq this-command '(self-insert-command newline))))) | ||
| 1195 | (and (save-excursion | ||
| 1196 | (backward-sexp 1) | ||
| 1197 | (cperl-after-expr-p nil "{;:")) | ||
| 1198 | (save-excursion | ||
| 1199 | (not | ||
| 1200 | (re-search-backward | ||
| 1201 | "[#\"'`]\\|\\<q\\(\\|[wqx]\\)\\>" | ||
| 1202 | beg t))) | ||
| 1203 | (save-excursion (or (not (re-search-backward "^=" nil t)) | ||
| 1204 | (looking-at "=cut"))) | ||
| 1205 | (progn | ||
| 1206 | (and dollar (insert " $")) | ||
| 1207 | (cperl-indent-line) | ||
| 1208 | ;;(insert " () {\n}") | ||
| 1209 | (cond | ||
| 1210 | (cperl-extra-newline-before-brace | ||
| 1211 | (insert " ()\n") | ||
| 1212 | (insert "{") | ||
| 1213 | (cperl-indent-line) | ||
| 1214 | (insert "\n") | ||
| 1215 | (cperl-indent-line) | ||
| 1216 | (insert "\n}")) | ||
| 1217 | (t | ||
| 1218 | (insert " () {\n}")) | ||
| 1219 | ) | ||
| 1220 | (or (looking-at "[ \t]\\|$") (insert " ")) | ||
| 1221 | (cperl-indent-line) | ||
| 1222 | (if dollar (progn (search-backward "$") | ||
| 1223 | (delete-char 1) | ||
| 1224 | (forward-char -1) | ||
| 1225 | (forward-char 1)) | ||
| 1226 | (search-backward ")")) | ||
| 1227 | (if delete | ||
| 1228 | (cperl-putback-char cperl-del-back-ch)))))) | ||
| 1229 | |||
| 1230 | (defun cperl-electric-else () | ||
| 1231 | "Insert a construction appropriate after a keyword." | ||
| 1232 | (let ((beg (save-excursion (beginning-of-line) (point)))) | ||
| 1233 | (and (save-excursion | ||
| 1234 | (backward-sexp 1) | ||
| 1235 | (cperl-after-expr-p nil "{;:")) | ||
| 1236 | (save-excursion | ||
| 1237 | (not | ||
| 1238 | (re-search-backward | ||
| 1239 | "[#\"'`]\\|\\<q\\(\\|[wqx]\\)\\>" | ||
| 1240 | beg t))) | ||
| 1241 | (save-excursion (or (not (re-search-backward "^=" nil t)) | ||
| 1242 | (looking-at "=cut"))) | ||
| 1243 | (progn | ||
| 1244 | (cperl-indent-line) | ||
| 1245 | ;;(insert " {\n\n}") | ||
| 1246 | (cond | ||
| 1247 | (cperl-extra-newline-before-brace | ||
| 1248 | (insert "\n") | ||
| 1249 | (insert "{") | ||
| 1250 | (cperl-indent-line) | ||
| 1251 | (insert "\n\n}")) | ||
| 1252 | (t | ||
| 1253 | (insert " {\n\n}")) | ||
| 1254 | ) | ||
| 1255 | (or (looking-at "[ \t]\\|$") (insert " ")) | ||
| 1256 | (cperl-indent-line) | ||
| 1257 | (forward-line -1) | ||
| 1258 | (cperl-indent-line) | ||
| 1259 | (cperl-putback-char cperl-del-back-ch))))) | ||
| 1260 | |||
| 1261 | (defun cperl-linefeed () | ||
| 1262 | "Go to end of line, open a new line and indent appropriately." | ||
| 1263 | (interactive) | ||
| 1264 | (let ((beg (save-excursion (beginning-of-line) (point))) | ||
| 1265 | (end (save-excursion (end-of-line) (point))) | ||
| 1266 | (pos (point)) start) | ||
| 1267 | (if (and ; Check if we need to split: | ||
| 1268 | ; i.e., on a boundary and inside "{...}" | ||
| 1269 | (save-excursion (cperl-to-comment-or-eol) | ||
| 1270 | (>= (point) pos)) ; Not in a comment | ||
| 1271 | (or (save-excursion | ||
| 1272 | (skip-chars-backward " \t" beg) | ||
| 1273 | (forward-char -1) | ||
| 1274 | (looking-at "[;{]")) ; After { or ; + spaces | ||
| 1275 | (looking-at "[ \t]*}") ; Before } | ||
| 1276 | (re-search-forward "\\=[ \t]*;" end t)) ; Before spaces + ; | ||
| 1277 | (save-excursion | ||
| 1278 | (and | ||
| 1279 | (eq (car (parse-partial-sexp pos end -1)) -1) | ||
| 1280 | ; Leave the level of parens | ||
| 1281 | (looking-at "[,; \t]*\\($\\|#\\)") ; Comma to allow anon subr | ||
| 1282 | ; Are at end | ||
| 1283 | (progn | ||
| 1284 | (backward-sexp 1) | ||
| 1285 | (setq start (point-marker)) | ||
| 1286 | (<= start pos))))) ; RedundantAre after the | ||
| 1287 | ; start of parens group. | ||
| 1288 | (progn | ||
| 1289 | (skip-chars-backward " \t") | ||
| 1290 | (or (memq (preceding-char) (append ";{" nil)) | ||
| 1291 | (insert ";")) | ||
| 1292 | (insert "\n") | ||
| 1293 | (forward-line -1) | ||
| 1294 | (cperl-indent-line) | ||
| 1295 | (goto-char start) | ||
| 1296 | (or (looking-at "{[ \t]*$") ; If there is a statement | ||
| 1297 | ; before, move it to separate line | ||
| 1298 | (progn | ||
| 1299 | (forward-char 1) | ||
| 1300 | (insert "\n") | ||
| 1301 | (cperl-indent-line))) | ||
| 1302 | (forward-line 1) ; We are on the target line | ||
| 1303 | (cperl-indent-line) | ||
| 1304 | (beginning-of-line) | ||
| 1305 | (or (looking-at "[ \t]*}[,; \t]*$") ; If there is a statement | ||
| 1306 | ; after, move it to separate line | ||
| 1307 | (progn | ||
| 1308 | (end-of-line) | ||
| 1309 | (search-backward "}" beg) | ||
| 1310 | (skip-chars-backward " \t") | ||
| 1311 | (or (memq (preceding-char) (append ";{" nil)) | ||
| 1312 | (insert ";")) | ||
| 1313 | (insert "\n") | ||
| 1314 | (cperl-indent-line) | ||
| 1315 | (forward-line -1))) | ||
| 1316 | (forward-line -1) ; We are on the line before target | ||
| 1317 | (end-of-line) | ||
| 1318 | (newline-and-indent)) | ||
| 1319 | (end-of-line) ; else | ||
| 1320 | (cond | ||
| 1321 | ((and (looking-at "\n[ \t]*{$") | ||
| 1322 | (save-excursion | ||
| 1323 | (skip-chars-backward " \t") | ||
| 1324 | (eq (preceding-char) ?\)))) ; Probably if () {} group | ||
| 1325 | ; with an extra newline. | ||
| 1326 | (forward-line 2) | ||
| 1327 | (cperl-indent-line)) | ||
| 1328 | ((looking-at "\n[ \t]*$") ; Next line is empty - use it. | ||
| 1329 | (forward-line 1) | ||
| 1330 | (cperl-indent-line)) | ||
| 1331 | (t | ||
| 1332 | (newline-and-indent)))))) | ||
| 1333 | |||
| 1334 | (defun cperl-electric-semi (arg) | ||
| 1335 | "Insert character and correct line's indentation." | ||
| 1336 | (interactive "P") | ||
| 1337 | (if cperl-auto-newline | ||
| 1338 | (cperl-electric-terminator arg) | ||
| 1339 | (self-insert-command (prefix-numeric-value arg)))) | ||
| 1340 | |||
| 1341 | (defun cperl-electric-terminator (arg) | ||
| 1342 | "Insert character and correct line's indentation." | ||
| 1343 | (interactive "P") | ||
| 1344 | (let (insertpos (end (point)) | ||
| 1345 | (auto (and cperl-auto-newline | ||
| 1346 | (or (not (eq last-command-char ?:)) | ||
| 1347 | cperl-auto-newline-after-colon)))) | ||
| 1348 | (if (and ;;(not arg) | ||
| 1349 | (eolp) | ||
| 1350 | (not (save-excursion | ||
| 1351 | (beginning-of-line) | ||
| 1352 | (skip-chars-forward " \t") | ||
| 1353 | (or | ||
| 1354 | ;; Ignore in comment lines | ||
| 1355 | (= (following-char) ?#) | ||
| 1356 | ;; Colon is special only after a label | ||
| 1357 | ;; So quickly rule out most other uses of colon | ||
| 1358 | ;; and do no indentation for them. | ||
| 1359 | (and (eq last-command-char ?:) | ||
| 1360 | (save-excursion | ||
| 1361 | (forward-word 1) | ||
| 1362 | (skip-chars-forward " \t") | ||
| 1363 | (and (< (point) end) | ||
| 1364 | (progn (goto-char (- end 1)) | ||
| 1365 | (not (looking-at ":")))))) | ||
| 1366 | (progn | ||
| 1367 | (beginning-of-defun) | ||
| 1368 | (let ((pps (parse-partial-sexp (point) end))) | ||
| 1369 | (or (nth 3 pps) (nth 4 pps) (nth 5 pps)))))))) | ||
| 1370 | (progn | ||
| 1371 | (self-insert-command (prefix-numeric-value arg)) | ||
| 1372 | ;;(forward-char -1) | ||
| 1373 | (if auto (setq insertpos (point-marker))) | ||
| 1374 | ;;(forward-char 1) | ||
| 1375 | (cperl-indent-line) | ||
| 1376 | (if auto | ||
| 1377 | (progn | ||
| 1378 | (newline) | ||
| 1379 | (cperl-indent-line))) | ||
| 1380 | ;; (save-excursion | ||
| 1381 | ;; (if insertpos (progn (goto-char (marker-position insertpos)) | ||
| 1382 | ;; (search-forward (make-string | ||
| 1383 | ;; 1 last-command-char)) | ||
| 1384 | ;; (setq insertpos (1- (point))))) | ||
| 1385 | ;; (delete-char -1)))) | ||
| 1386 | (save-excursion | ||
| 1387 | (if insertpos (goto-char (1- (marker-position insertpos))) | ||
| 1388 | (forward-char -1)) | ||
| 1389 | (delete-char 1)))) | ||
| 1390 | (if insertpos | ||
| 1391 | (save-excursion | ||
| 1392 | (goto-char insertpos) | ||
| 1393 | (self-insert-command (prefix-numeric-value arg))) | ||
| 1394 | (self-insert-command (prefix-numeric-value arg))))) | ||
| 1395 | |||
| 1396 | (defun cperl-electric-backspace (arg) | ||
| 1397 | "Backspace-untabify, or remove the whitespace inserted by an electric key." | ||
| 1398 | (interactive "p") | ||
| 1399 | (if (and cperl-auto-newline | ||
| 1400 | (memq last-command '(cperl-electric-semi | ||
| 1401 | cperl-electric-terminator | ||
| 1402 | cperl-electric-lbrace)) | ||
| 1403 | (memq (preceding-char) '(?\ ?\t ?\n))) | ||
| 1404 | (let (p) | ||
| 1405 | (if (eq last-command 'cperl-electric-lbrace) | ||
| 1406 | (skip-chars-forward " \t\n")) | ||
| 1407 | (setq p (point)) | ||
| 1408 | (skip-chars-backward " \t\n") | ||
| 1409 | (delete-region (point) p)) | ||
| 1410 | (backward-delete-char-untabify arg))) | ||
| 1411 | |||
| 1412 | (defun cperl-inside-parens-p () | ||
| 1413 | (condition-case () | ||
| 1414 | (save-excursion | ||
| 1415 | (save-restriction | ||
| 1416 | (narrow-to-region (point) | ||
| 1417 | (progn (beginning-of-defun) (point))) | ||
| 1418 | (goto-char (point-max)) | ||
| 1419 | (= (char-after (or (scan-lists (point) -1 1) (point-min))) ?\())) | ||
| 1420 | (error nil))) | ||
| 1421 | |||
| 1422 | (defun cperl-indent-command (&optional whole-exp) | ||
| 1423 | "Indent current line as Perl code, or in some cases insert a tab character. | ||
| 1424 | If `cperl-tab-always-indent' is non-nil (the default), always indent current line. | ||
| 1425 | Otherwise, indent the current line only if point is at the left margin | ||
| 1426 | or in the line's indentation; otherwise insert a tab. | ||
| 1427 | |||
| 1428 | A numeric argument, regardless of its value, | ||
| 1429 | means indent rigidly all the lines of the expression starting after point | ||
| 1430 | so that this line becomes properly indented. | ||
| 1431 | The relative indentation among the lines of the expression are preserved." | ||
| 1432 | (interactive "P") | ||
| 1433 | (if whole-exp | ||
| 1434 | ;; If arg, always indent this line as Perl | ||
| 1435 | ;; and shift remaining lines of expression the same amount. | ||
| 1436 | (let ((shift-amt (cperl-indent-line)) | ||
| 1437 | beg end) | ||
| 1438 | (save-excursion | ||
| 1439 | (if cperl-tab-always-indent | ||
| 1440 | (beginning-of-line)) | ||
| 1441 | (setq beg (point)) | ||
| 1442 | (forward-sexp 1) | ||
| 1443 | (setq end (point)) | ||
| 1444 | (goto-char beg) | ||
| 1445 | (forward-line 1) | ||
| 1446 | (setq beg (point))) | ||
| 1447 | (if (> end beg) | ||
| 1448 | (indent-code-rigidly beg end shift-amt "#"))) | ||
| 1449 | (if (and (not cperl-tab-always-indent) | ||
| 1450 | (save-excursion | ||
| 1451 | (skip-chars-backward " \t") | ||
| 1452 | (not (bolp)))) | ||
| 1453 | (insert-tab) | ||
| 1454 | (cperl-indent-line)))) | ||
| 1455 | |||
| 1456 | (defun cperl-indent-line (&optional symbol) | ||
| 1457 | "Indent current line as Perl code. | ||
| 1458 | Return the amount the indentation changed by." | ||
| 1459 | (let (indent | ||
| 1460 | beg shift-amt | ||
| 1461 | (case-fold-search nil) | ||
| 1462 | (pos (- (point-max) (point)))) | ||
| 1463 | (setq indent (cperl-calculate-indent nil symbol)) | ||
| 1464 | (beginning-of-line) | ||
| 1465 | (setq beg (point)) | ||
| 1466 | (cond ((or (eq indent nil) (eq indent t)) | ||
| 1467 | (setq indent (current-indentation))) | ||
| 1468 | ;;((eq indent t) ; Never? | ||
| 1469 | ;; (setq indent (cperl-calculate-indent-within-comment))) | ||
| 1470 | ;;((looking-at "[ \t]*#") | ||
| 1471 | ;; (setq indent 0)) | ||
| 1472 | (t | ||
| 1473 | (skip-chars-forward " \t") | ||
| 1474 | (if (listp indent) (setq indent (car indent))) | ||
| 1475 | (cond ((looking-at "[A-Za-z_][A-Za-z_0-9]*:[^:]") | ||
| 1476 | (and (> indent 0) | ||
| 1477 | (setq indent (max cperl-min-label-indent | ||
| 1478 | (+ indent cperl-label-offset))))) | ||
| 1479 | ((= (following-char) ?}) | ||
| 1480 | (setq indent (- indent cperl-indent-level))) | ||
| 1481 | ((memq (following-char) '(?\) ?\])) ; To line up with opening paren. | ||
| 1482 | (setq indent (+ indent cperl-close-paren-offset))) | ||
| 1483 | ((= (following-char) ?{) | ||
| 1484 | (setq indent (+ indent cperl-brace-offset)))))) | ||
| 1485 | (skip-chars-forward " \t") | ||
| 1486 | (setq shift-amt (- indent (current-column))) | ||
| 1487 | (if (zerop shift-amt) | ||
| 1488 | (if (> (- (point-max) pos) (point)) | ||
| 1489 | (goto-char (- (point-max) pos))) | ||
| 1490 | (delete-region beg (point)) | ||
| 1491 | (indent-to indent) | ||
| 1492 | ;; If initial point was within line's indentation, | ||
| 1493 | ;; position after the indentation. Else stay at same point in text. | ||
| 1494 | (if (> (- (point-max) pos) (point)) | ||
| 1495 | (goto-char (- (point-max) pos)))) | ||
| 1496 | shift-amt)) | ||
| 1497 | |||
| 1498 | (defun cperl-after-label () | ||
| 1499 | ;; Returns true if the point is after label. Does not do save-excursion. | ||
| 1500 | (and (eq (preceding-char) ?:) | ||
| 1501 | (memq (char-syntax (char-after (- (point) 2))) | ||
| 1502 | '(?w ?_)) | ||
| 1503 | (progn | ||
| 1504 | (backward-sexp) | ||
| 1505 | (looking-at "[a-zA-Z_][a-zA-Z0-9_]*:[^:]")))) | ||
| 1506 | |||
| 1507 | (defun cperl-get-state (&optional parse-start start-state) | ||
| 1508 | ;; returns list (START STATE DEPTH PRESTART), START is a good place | ||
| 1509 | ;; to start parsing, STATE is what is returned by | ||
| 1510 | ;; `parse-partial-sexp'. DEPTH is true is we are immediately after | ||
| 1511 | ;; end of block which contains START. PRESTART is the position | ||
| 1512 | ;; basing on which START was found. | ||
| 1513 | (save-excursion | ||
| 1514 | (let ((start-point (point)) depth state start prestart) | ||
| 1515 | (if parse-start | ||
| 1516 | (goto-char parse-start) | ||
| 1517 | (beginning-of-defun)) | ||
| 1518 | (setq prestart (point)) | ||
| 1519 | (if start-state nil | ||
| 1520 | ;; Try to go out, if sub is not on the outermost level | ||
| 1521 | (while (< (point) start-point) | ||
| 1522 | (setq start (point) parse-start start depth nil | ||
| 1523 | state (parse-partial-sexp start start-point -1)) | ||
| 1524 | (if (> (car state) -1) nil | ||
| 1525 | ;; The current line could start like }}}, so the indentation | ||
| 1526 | ;; corresponds to a different level than what we reached | ||
| 1527 | (setq depth t) | ||
| 1528 | (beginning-of-line 2))) ; Go to the next line. | ||
| 1529 | (if start (goto-char start))) ; Not at the start of file | ||
| 1530 | (setq start (point)) | ||
| 1531 | (if (< start start-point) (setq parse-start start)) | ||
| 1532 | (or state (setq state (parse-partial-sexp start start-point -1 nil start-state))) | ||
| 1533 | (list start state depth prestart)))) | ||
| 1534 | |||
| 1535 | (defun cperl-block-p () ; Do not C-M-q ! One string contains ";" ! | ||
| 1536 | ;; Positions is before ?\{. Checks whether it starts a block. | ||
| 1537 | ;; No save-excursion! | ||
| 1538 | (cperl-backward-to-noncomment (point-min)) | ||
| 1539 | ;;(skip-chars-backward " \t\n\f") | ||
| 1540 | (or (memq (preceding-char) (append ";){}$@&%\C-@" nil)) ; Or label! \C-@ at bobp | ||
| 1541 | ; Label may be mixed up with `$blah :' | ||
| 1542 | (save-excursion (cperl-after-label)) | ||
| 1543 | (and (memq (char-syntax (preceding-char)) '(?w ?_)) | ||
| 1544 | (progn | ||
| 1545 | (backward-sexp) | ||
| 1546 | ;; Need take into account `bless', `return', `tr',... | ||
| 1547 | (or (and (looking-at "[a-zA-Z0-9_:]+[ \t\n\f]*[{#]") ; Method call syntax | ||
| 1548 | (not (looking-at "\\(bless\\|return\\|qw\\|tr\\|[smy]\\)\\>"))) | ||
| 1549 | (progn | ||
| 1550 | (skip-chars-backward " \t\n\f") | ||
| 1551 | (and (memq (char-syntax (preceding-char)) '(?w ?_)) | ||
| 1552 | (progn | ||
| 1553 | (backward-sexp) | ||
| 1554 | (looking-at | ||
| 1555 | "sub[ \t]+[a-zA-Z0-9_:]+[ \t\n\f]*\\(([^()]*)[ \t\n\f]*\\)?[#{]"))))))))) | ||
| 1556 | |||
| 1557 | (defvar cperl-look-for-prop '((pod in-pod) (here-doc-delim here-doc-group))) | ||
| 1558 | |||
| 1559 | (defun cperl-calculate-indent (&optional parse-start symbol) | ||
| 1560 | "Return appropriate indentation for current line as Perl code. | ||
| 1561 | In usual case returns an integer: the column to indent to. | ||
| 1562 | Returns nil if line starts inside a string, t if in a comment." | ||
| 1563 | (save-excursion | ||
| 1564 | (if (or | ||
| 1565 | (memq (get-text-property (point) 'syntax-type) | ||
| 1566 | '(pod here-doc here-doc-delim format)) | ||
| 1567 | ;; before start of POD - whitespace found since do not have 'pod! | ||
| 1568 | (and (looking-at "[ \t]*\n=") | ||
| 1569 | (error "Spaces before pod section!")) | ||
| 1570 | (and (not cperl-indent-left-aligned-comments) | ||
| 1571 | (looking-at "^#"))) | ||
| 1572 | nil | ||
| 1573 | (beginning-of-line) | ||
| 1574 | (let ((indent-point (point)) | ||
| 1575 | (char-after (save-excursion | ||
| 1576 | (skip-chars-forward " \t") | ||
| 1577 | (following-char))) | ||
| 1578 | (in-pod (get-text-property (point) 'in-pod)) | ||
| 1579 | (pre-indent-point (point)) | ||
| 1580 | p prop look-prop) | ||
| 1581 | (cond | ||
| 1582 | (in-pod | ||
| 1583 | ;; In the verbatim part, probably code example. What to do??? | ||
| 1584 | ) | ||
| 1585 | (t | ||
| 1586 | (save-excursion | ||
| 1587 | ;; Not in pod | ||
| 1588 | (cperl-backward-to-noncomment nil) | ||
| 1589 | (setq p (max (point-min) (1- (point))) | ||
| 1590 | prop (get-text-property p 'syntax-type) | ||
| 1591 | look-prop (or (nth 1 (assoc prop cperl-look-for-prop)) | ||
| 1592 | 'syntax-type)) | ||
| 1593 | (if (memq prop '(pod here-doc format here-doc-delim)) | ||
| 1594 | (progn | ||
| 1595 | (goto-char (or (previous-single-property-change p look-prop) | ||
| 1596 | (point-min))) | ||
| 1597 | (beginning-of-line) | ||
| 1598 | (setq pre-indent-point (point))))))) | ||
| 1599 | (goto-char pre-indent-point) | ||
| 1600 | (let* ((case-fold-search nil) | ||
| 1601 | (s-s (cperl-get-state)) | ||
| 1602 | (start (nth 0 s-s)) | ||
| 1603 | (state (nth 1 s-s)) | ||
| 1604 | (containing-sexp (car (cdr state))) | ||
| 1605 | (start-indent (save-excursion | ||
| 1606 | (goto-char start) | ||
| 1607 | (- (current-indentation) | ||
| 1608 | (if (nth 2 s-s) cperl-indent-level 0)))) | ||
| 1609 | old-indent) | ||
| 1610 | ;; (or parse-start (null symbol) | ||
| 1611 | ;; (setq parse-start (symbol-value symbol) | ||
| 1612 | ;; start-indent (nth 2 parse-start) | ||
| 1613 | ;; parse-start (car parse-start))) | ||
| 1614 | ;; (if parse-start | ||
| 1615 | ;; (goto-char parse-start) | ||
| 1616 | ;; (beginning-of-defun)) | ||
| 1617 | ;; ;; Try to go out | ||
| 1618 | ;; (while (< (point) indent-point) | ||
| 1619 | ;; (setq start (point) parse-start start moved nil | ||
| 1620 | ;; state (parse-partial-sexp start indent-point -1)) | ||
| 1621 | ;; (if (> (car state) -1) nil | ||
| 1622 | ;; ;; The current line could start like }}}, so the indentation | ||
| 1623 | ;; ;; corresponds to a different level than what we reached | ||
| 1624 | ;; (setq moved t) | ||
| 1625 | ;; (beginning-of-line 2))) ; Go to the next line. | ||
| 1626 | ;; (if start ; Not at the start of file | ||
| 1627 | ;; (progn | ||
| 1628 | ;; (goto-char start) | ||
| 1629 | ;; (setq start-indent (current-indentation)) | ||
| 1630 | ;; (if moved ; Should correct... | ||
| 1631 | ;; (setq start-indent (- start-indent cperl-indent-level)))) | ||
| 1632 | ;; (setq start-indent 0)) | ||
| 1633 | ;; (if (< (point) indent-point) (setq parse-start (point))) | ||
| 1634 | ;; (or state (setq state (parse-partial-sexp | ||
| 1635 | ;; (point) indent-point -1 nil start-state))) | ||
| 1636 | ;; (setq containing-sexp | ||
| 1637 | ;; (or (car (cdr state)) | ||
| 1638 | ;; (and (>= (nth 6 state) 0) old-containing-sexp)) | ||
| 1639 | ;; old-containing-sexp nil start-state nil) | ||
| 1640 | ;;;; (while (< (point) indent-point) | ||
| 1641 | ;;;; (setq parse-start (point)) | ||
| 1642 | ;;;; (setq state (parse-partial-sexp (point) indent-point -1 nil start-state)) | ||
| 1643 | ;;;; (setq containing-sexp | ||
| 1644 | ;;;; (or (car (cdr state)) | ||
| 1645 | ;;;; (and (>= (nth 6 state) 0) old-containing-sexp)) | ||
| 1646 | ;;;; old-containing-sexp nil start-state nil)) | ||
| 1647 | ;; (if symbol (set symbol (list indent-point state start-indent))) | ||
| 1648 | ;; (goto-char indent-point) | ||
| 1649 | (cond ((or (nth 3 state) (nth 4 state)) | ||
| 1650 | ;; return nil or t if should not change this line | ||
| 1651 | (nth 4 state)) | ||
| 1652 | ((null containing-sexp) | ||
| 1653 | ;; Line is at top level. May be data or function definition, | ||
| 1654 | ;; or may be function argument declaration. | ||
| 1655 | ;; Indent like the previous top level line | ||
| 1656 | ;; unless that ends in a closeparen without semicolon, | ||
| 1657 | ;; in which case this line is the first argument decl. | ||
| 1658 | (skip-chars-forward " \t") | ||
| 1659 | (+ start-indent | ||
| 1660 | (if (= (following-char) ?{) cperl-continued-brace-offset 0) | ||
| 1661 | (progn | ||
| 1662 | (cperl-backward-to-noncomment (or parse-start (point-min))) | ||
| 1663 | ;;(skip-chars-backward " \t\f\n") | ||
| 1664 | ;; Look at previous line that's at column 0 | ||
| 1665 | ;; to determine whether we are in top-level decls | ||
| 1666 | ;; or function's arg decls. Set basic-indent accordingly. | ||
| 1667 | ;; Now add a little if this is a continuation line. | ||
| 1668 | (if (or (bobp) | ||
| 1669 | (memq (preceding-char) (append " ;}" nil)) ; Was ?\) | ||
| 1670 | (memq char-after (append ")]}" nil)) | ||
| 1671 | (and (eq (preceding-char) ?\:) ; label | ||
| 1672 | (progn | ||
| 1673 | (forward-sexp -1) | ||
| 1674 | (skip-chars-backward " \t") | ||
| 1675 | (looking-at "[ \t]*[a-zA-Z_][a-zA-Z_0-9]*[ \t]*:")))) | ||
| 1676 | 0 | ||
| 1677 | cperl-continued-statement-offset)))) | ||
| 1678 | ((/= (char-after containing-sexp) ?{) | ||
| 1679 | ;; line is expression, not statement: | ||
| 1680 | ;; indent to just after the surrounding open, | ||
| 1681 | ;; skip blanks if we do not close the expression. | ||
| 1682 | (goto-char (1+ containing-sexp)) | ||
| 1683 | (or (memq char-after (append ")]}" nil)) | ||
| 1684 | (looking-at "[ \t]*\\(#\\|$\\)") | ||
| 1685 | (skip-chars-forward " \t")) | ||
| 1686 | (current-column)) | ||
| 1687 | ((progn | ||
| 1688 | ;; Containing-expr starts with \{. Check whether it is a hash. | ||
| 1689 | (goto-char containing-sexp) | ||
| 1690 | (not (cperl-block-p))) | ||
| 1691 | (goto-char (1+ containing-sexp)) | ||
| 1692 | (or (eq char-after ?\}) | ||
| 1693 | (looking-at "[ \t]*\\(#\\|$\\)") | ||
| 1694 | (skip-chars-forward " \t")) | ||
| 1695 | (+ (current-column) ; Correct indentation of trailing ?\} | ||
| 1696 | (if (eq char-after ?\}) (+ cperl-indent-level | ||
| 1697 | cperl-close-paren-offset) | ||
| 1698 | 0))) | ||
| 1699 | (t | ||
| 1700 | ;; Statement level. Is it a continuation or a new statement? | ||
| 1701 | ;; Find previous non-comment character. | ||
| 1702 | (goto-char pre-indent-point) | ||
| 1703 | (cperl-backward-to-noncomment containing-sexp) | ||
| 1704 | ;; Back up over label lines, since they don't | ||
| 1705 | ;; affect whether our line is a continuation. | ||
| 1706 | (while (or (eq (preceding-char) ?\,) | ||
| 1707 | (and (eq (preceding-char) ?:) | ||
| 1708 | (or;;(eq (char-after (- (point) 2)) ?\') ; ???? | ||
| 1709 | (memq (char-syntax (char-after (- (point) 2))) | ||
| 1710 | '(?w ?_))))) | ||
| 1711 | (if (eq (preceding-char) ?\,) | ||
| 1712 | ;; Will go to beginning of line, essentially. | ||
| 1713 | ;; Will ignore embedded sexpr XXXX. | ||
| 1714 | (cperl-backward-to-start-of-continued-exp containing-sexp)) | ||
| 1715 | (beginning-of-line) | ||
| 1716 | (cperl-backward-to-noncomment containing-sexp)) | ||
| 1717 | ;; Now we get the answer. | ||
| 1718 | (if (not (memq (preceding-char) (append ", ;}{" '(nil)))) ; Was ?\, | ||
| 1719 | ;; This line is continuation of preceding line's statement; | ||
| 1720 | ;; indent `cperl-continued-statement-offset' more than the | ||
| 1721 | ;; previous line of the statement. | ||
| 1722 | (progn | ||
| 1723 | (cperl-backward-to-start-of-continued-exp containing-sexp) | ||
| 1724 | (+ (if (memq char-after (append "}])" nil)) | ||
| 1725 | 0 ; Closing parenth | ||
| 1726 | cperl-continued-statement-offset) | ||
| 1727 | (current-column) | ||
| 1728 | (if (eq char-after ?\{) | ||
| 1729 | cperl-continued-brace-offset 0))) | ||
| 1730 | ;; This line starts a new statement. | ||
| 1731 | ;; Position following last unclosed open. | ||
| 1732 | (goto-char containing-sexp) | ||
| 1733 | ;; Is line first statement after an open-brace? | ||
| 1734 | (or | ||
| 1735 | ;; If no, find that first statement and indent like | ||
| 1736 | ;; it. If the first statement begins with label, do | ||
| 1737 | ;; not believe when the indentation of the label is too | ||
| 1738 | ;; small. | ||
| 1739 | (save-excursion | ||
| 1740 | (forward-char 1) | ||
| 1741 | (setq old-indent (current-indentation)) | ||
| 1742 | (let ((colon-line-end 0)) | ||
| 1743 | (while (progn (skip-chars-forward " \t\n") | ||
| 1744 | (looking-at "#\\|[a-zA-Z0-9_$]*:[^:]")) | ||
| 1745 | ;; Skip over comments and labels following openbrace. | ||
| 1746 | (cond ((= (following-char) ?\#) | ||
| 1747 | (forward-line 1)) | ||
| 1748 | ;; label: | ||
| 1749 | (t | ||
| 1750 | (save-excursion (end-of-line) | ||
| 1751 | (setq colon-line-end (point))) | ||
| 1752 | (search-forward ":")))) | ||
| 1753 | ;; The first following code counts | ||
| 1754 | ;; if it is before the line we want to indent. | ||
| 1755 | (and (< (point) indent-point) | ||
| 1756 | (if (> colon-line-end (point)) ; After label | ||
| 1757 | (if (> (current-indentation) | ||
| 1758 | cperl-min-label-indent) | ||
| 1759 | (- (current-indentation) cperl-label-offset) | ||
| 1760 | ;; Do not believe: `max' is involved | ||
| 1761 | (+ old-indent cperl-indent-level)) | ||
| 1762 | (current-column))))) | ||
| 1763 | ;; If no previous statement, | ||
| 1764 | ;; indent it relative to line brace is on. | ||
| 1765 | ;; For open brace in column zero, don't let statement | ||
| 1766 | ;; start there too. If cperl-indent-level is zero, | ||
| 1767 | ;; use cperl-brace-offset + cperl-continued-statement-offset instead. | ||
| 1768 | ;; For open-braces not the first thing in a line, | ||
| 1769 | ;; add in cperl-brace-imaginary-offset. | ||
| 1770 | |||
| 1771 | ;; If first thing on a line: ????? | ||
| 1772 | (+ (if (and (bolp) (zerop cperl-indent-level)) | ||
| 1773 | (+ cperl-brace-offset cperl-continued-statement-offset) | ||
| 1774 | cperl-indent-level) | ||
| 1775 | ;; Move back over whitespace before the openbrace. | ||
| 1776 | ;; If openbrace is not first nonwhite thing on the line, | ||
| 1777 | ;; add the cperl-brace-imaginary-offset. | ||
| 1778 | (progn (skip-chars-backward " \t") | ||
| 1779 | (if (bolp) 0 cperl-brace-imaginary-offset)) | ||
| 1780 | ;; If the openbrace is preceded by a parenthesized exp, | ||
| 1781 | ;; move to the beginning of that; | ||
| 1782 | ;; possibly a different line | ||
| 1783 | (progn | ||
| 1784 | (if (eq (preceding-char) ?\)) | ||
| 1785 | (forward-sexp -1)) | ||
| 1786 | ;; In the case it starts a subroutine, indent with | ||
| 1787 | ;; respect to `sub', not with respect to the the | ||
| 1788 | ;; first thing on the line, say in the case of | ||
| 1789 | ;; anonymous sub in a hash. | ||
| 1790 | ;; | ||
| 1791 | (skip-chars-backward " \t") | ||
| 1792 | (if (and (eq (preceding-char) ?b) | ||
| 1793 | (progn | ||
| 1794 | (forward-sexp -1) | ||
| 1795 | (looking-at "sub\\>")) | ||
| 1796 | (setq old-indent | ||
| 1797 | (nth 1 | ||
| 1798 | (parse-partial-sexp | ||
| 1799 | (save-excursion (beginning-of-line) (point)) | ||
| 1800 | (point))))) | ||
| 1801 | (progn (goto-char (1+ old-indent)) | ||
| 1802 | (skip-chars-forward " \t") | ||
| 1803 | (current-column)) | ||
| 1804 | ;; Get initial indentation of the line we are on. | ||
| 1805 | ;; If line starts with label, calculate label indentation | ||
| 1806 | (if (save-excursion | ||
| 1807 | (beginning-of-line) | ||
| 1808 | (looking-at "[ \t]*[a-zA-Z_][a-zA-Z_0-9]*:[^:]")) | ||
| 1809 | (if (> (current-indentation) cperl-min-label-indent) | ||
| 1810 | (- (current-indentation) cperl-label-offset) | ||
| 1811 | (cperl-calculate-indent | ||
| 1812 | (if (and parse-start (<= parse-start (point))) | ||
| 1813 | parse-start))) | ||
| 1814 | (current-indentation)))))))))))))) | ||
| 1815 | |||
| 1816 | (defvar cperl-indent-alist | ||
| 1817 | '((string nil) | ||
| 1818 | (comment nil) | ||
| 1819 | (toplevel 0) | ||
| 1820 | (toplevel-after-parenth 2) | ||
| 1821 | (toplevel-continued 2) | ||
| 1822 | (expression 1)) | ||
| 1823 | "Alist of indentation rules for CPerl mode. | ||
| 1824 | The values mean: | ||
| 1825 | nil: do not indent; | ||
| 1826 | number: add this amount of indentation.") | ||
| 1827 | |||
| 1828 | (defun cperl-where-am-i (&optional parse-start start-state) | ||
| 1829 | ;; Unfinished | ||
| 1830 | "Return a list of lists ((TYPE POS)...) of good points before the point. | ||
| 1831 | POS may be nil if it is hard to find, say, when TYPE is `string' or `comment'." | ||
| 1832 | (save-excursion | ||
| 1833 | (let* ((start-point (point)) | ||
| 1834 | (s-s (cperl-get-state)) | ||
| 1835 | (start (nth 0 s-s)) | ||
| 1836 | (state (nth 1 s-s)) | ||
| 1837 | (prestart (nth 3 s-s)) | ||
| 1838 | (containing-sexp (car (cdr state))) | ||
| 1839 | (case-fold-search nil) | ||
| 1840 | (res (list (list 'parse-start start) (list 'parse-prestart prestart)))) | ||
| 1841 | (cond ((nth 3 state) ; In string | ||
| 1842 | (setq res (cons (list 'string nil (nth 3 state)) res))) ; What started string | ||
| 1843 | ((nth 4 state) ; In comment | ||
| 1844 | (setq res (cons '(comment) res))) | ||
| 1845 | ((null containing-sexp) | ||
| 1846 | ;; Line is at top level. | ||
| 1847 | ;; Indent like the previous top level line | ||
| 1848 | ;; unless that ends in a closeparen without semicolon, | ||
| 1849 | ;; in which case this line is the first argument decl. | ||
| 1850 | (cperl-backward-to-noncomment (or parse-start (point-min))) | ||
| 1851 | ;;(skip-chars-backward " \t\f\n") | ||
| 1852 | (cond | ||
| 1853 | ((or (bobp) | ||
| 1854 | (memq (preceding-char) (append ";}" nil))) | ||
| 1855 | (setq res (cons (list 'toplevel start) res))) | ||
| 1856 | ((eq (preceding-char) ?\) ) | ||
| 1857 | (setq res (cons (list 'toplevel-after-parenth start) res))) | ||
| 1858 | (t | ||
| 1859 | (setq res (cons (list 'toplevel-continued start) res))))) | ||
| 1860 | ((/= (char-after containing-sexp) ?{) | ||
| 1861 | ;; line is expression, not statement: | ||
| 1862 | ;; indent to just after the surrounding open. | ||
| 1863 | ;; skip blanks if we do not close the expression. | ||
| 1864 | (setq res (cons (list 'expression-blanks | ||
| 1865 | (progn | ||
| 1866 | (goto-char (1+ containing-sexp)) | ||
| 1867 | (or (looking-at "[ \t]*\\(#\\|$\\)") | ||
| 1868 | (skip-chars-forward " \t")) | ||
| 1869 | (point))) | ||
| 1870 | (cons (list 'expression containing-sexp) res)))) | ||
| 1871 | ((progn | ||
| 1872 | ;; Containing-expr starts with \{. Check whether it is a hash. | ||
| 1873 | (goto-char containing-sexp) | ||
| 1874 | (not (cperl-block-p))) | ||
| 1875 | (setq res (cons (list 'expression-blanks | ||
| 1876 | (progn | ||
| 1877 | (goto-char (1+ containing-sexp)) | ||
| 1878 | (or (looking-at "[ \t]*\\(#\\|$\\)") | ||
| 1879 | (skip-chars-forward " \t")) | ||
| 1880 | (point))) | ||
| 1881 | (cons (list 'expression containing-sexp) res)))) | ||
| 1882 | (t | ||
| 1883 | ;; Statement level. | ||
| 1884 | (setq res (cons (list 'in-block containing-sexp) res)) | ||
| 1885 | ;; Is it a continuation or a new statement? | ||
| 1886 | ;; Find previous non-comment character. | ||
| 1887 | (cperl-backward-to-noncomment containing-sexp) | ||
| 1888 | ;; Back up over label lines, since they don't | ||
| 1889 | ;; affect whether our line is a continuation. | ||
| 1890 | ;; Back up comma-delimited lines too ????? | ||
| 1891 | (while (or (eq (preceding-char) ?\,) | ||
| 1892 | (save-excursion (cperl-after-label))) | ||
| 1893 | (if (eq (preceding-char) ?\,) | ||
| 1894 | ;; Will go to beginning of line, essentially | ||
| 1895 | ;; Will ignore embedded sexpr XXXX. | ||
| 1896 | (cperl-backward-to-start-of-continued-exp containing-sexp)) | ||
| 1897 | (beginning-of-line) | ||
| 1898 | (cperl-backward-to-noncomment containing-sexp)) | ||
| 1899 | ;; Now we get the answer. | ||
| 1900 | (if (not (memq (preceding-char) (append ";}{" '(nil)))) ; Was ?\, | ||
| 1901 | ;; This line is continuation of preceding line's statement. | ||
| 1902 | (list (list 'statement-continued containing-sexp)) | ||
| 1903 | ;; This line starts a new statement. | ||
| 1904 | ;; Position following last unclosed open. | ||
| 1905 | (goto-char containing-sexp) | ||
| 1906 | ;; Is line first statement after an open-brace? | ||
| 1907 | (or | ||
| 1908 | ;; If no, find that first statement and indent like | ||
| 1909 | ;; it. If the first statement begins with label, do | ||
| 1910 | ;; not believe when the indentation of the label is too | ||
| 1911 | ;; small. | ||
| 1912 | (save-excursion | ||
| 1913 | (forward-char 1) | ||
| 1914 | (let ((colon-line-end 0)) | ||
| 1915 | (while (progn (skip-chars-forward " \t\n" start-point) | ||
| 1916 | (and (< (point) start-point) | ||
| 1917 | (looking-at | ||
| 1918 | "#\\|[a-zA-Z_][a-zA-Z0-9_]*:[^:]"))) | ||
| 1919 | ;; Skip over comments and labels following openbrace. | ||
| 1920 | (cond ((= (following-char) ?\#) | ||
| 1921 | ;;(forward-line 1) | ||
| 1922 | (end-of-line)) | ||
| 1923 | ;; label: | ||
| 1924 | (t | ||
| 1925 | (save-excursion (end-of-line) | ||
| 1926 | (setq colon-line-end (point))) | ||
| 1927 | (search-forward ":")))) | ||
| 1928 | ;; Now at the point, after label, or at start | ||
| 1929 | ;; of first statement in the block. | ||
| 1930 | (and (< (point) start-point) | ||
| 1931 | (if (> colon-line-end (point)) | ||
| 1932 | ;; Before statement after label | ||
| 1933 | (if (> (current-indentation) | ||
| 1934 | cperl-min-label-indent) | ||
| 1935 | (list (list 'label-in-block (point))) | ||
| 1936 | ;; Do not believe: `max' is involved | ||
| 1937 | (list | ||
| 1938 | (list 'label-in-block-min-indent (point)))) | ||
| 1939 | ;; Before statement | ||
| 1940 | (list 'statement-in-block (point)))))) | ||
| 1941 | ;; If no previous statement, | ||
| 1942 | ;; indent it relative to line brace is on. | ||
| 1943 | ;; For open brace in column zero, don't let statement | ||
| 1944 | ;; start there too. If cperl-indent-level is zero, | ||
| 1945 | ;; use cperl-brace-offset + cperl-continued-statement-offset instead. | ||
| 1946 | ;; For open-braces not the first thing in a line, | ||
| 1947 | ;; add in cperl-brace-imaginary-offset. | ||
| 1948 | |||
| 1949 | ;; If first thing on a line: ????? | ||
| 1950 | (+ (if (and (bolp) (zerop cperl-indent-level)) | ||
| 1951 | (+ cperl-brace-offset cperl-continued-statement-offset) | ||
| 1952 | cperl-indent-level) | ||
| 1953 | ;; Move back over whitespace before the openbrace. | ||
| 1954 | ;; If openbrace is not first nonwhite thing on the line, | ||
| 1955 | ;; add the cperl-brace-imaginary-offset. | ||
| 1956 | (progn (skip-chars-backward " \t") | ||
| 1957 | (if (bolp) 0 cperl-brace-imaginary-offset)) | ||
| 1958 | ;; If the openbrace is preceded by a parenthesized exp, | ||
| 1959 | ;; move to the beginning of that; | ||
| 1960 | ;; possibly a different line | ||
| 1961 | (progn | ||
| 1962 | (if (eq (preceding-char) ?\)) | ||
| 1963 | (forward-sexp -1)) | ||
| 1964 | ;; Get initial indentation of the line we are on. | ||
| 1965 | ;; If line starts with label, calculate label indentation | ||
| 1966 | (if (save-excursion | ||
| 1967 | (beginning-of-line) | ||
| 1968 | (looking-at "[ \t]*[a-zA-Z_][a-zA-Z_0-9]*:[^:]")) | ||
| 1969 | (if (> (current-indentation) cperl-min-label-indent) | ||
| 1970 | (- (current-indentation) cperl-label-offset) | ||
| 1971 | (cperl-calculate-indent | ||
| 1972 | (if (and parse-start (<= parse-start (point))) | ||
| 1973 | parse-start))) | ||
| 1974 | (current-indentation)))))))) | ||
| 1975 | res))) | ||
| 1976 | |||
| 1977 | (defun cperl-calculate-indent-within-comment () | ||
| 1978 | "Return the indentation amount for line, assuming that | ||
| 1979 | the current line is to be regarded as part of a block comment." | ||
| 1980 | (let (end star-start) | ||
| 1981 | (save-excursion | ||
| 1982 | (beginning-of-line) | ||
| 1983 | (skip-chars-forward " \t") | ||
| 1984 | (setq end (point)) | ||
| 1985 | (and (= (following-char) ?#) | ||
| 1986 | (forward-line -1) | ||
| 1987 | (cperl-to-comment-or-eol) | ||
| 1988 | (setq end (point))) | ||
| 1989 | (goto-char end) | ||
| 1990 | (current-column)))) | ||
| 1991 | |||
| 1992 | |||
| 1993 | (defun cperl-to-comment-or-eol () | ||
| 1994 | "Goes to position before comment on the current line, or to end of line. | ||
| 1995 | Returns true if comment is found." | ||
| 1996 | (let (state stop-in cpoint (lim (progn (end-of-line) (point)))) | ||
| 1997 | (beginning-of-line) | ||
| 1998 | (if (or | ||
| 1999 | (eq (get-text-property (point) 'syntax-type) 'pod) | ||
| 2000 | (re-search-forward "\\=[ \t]*\\(#\\|$\\)" lim t)) | ||
| 2001 | (if (eq (preceding-char) ?\#) (progn (backward-char 1) t)) | ||
| 2002 | ;; Else | ||
| 2003 | (while (not stop-in) | ||
| 2004 | (setq state (parse-partial-sexp (point) lim nil nil nil t)) | ||
| 2005 | ; stop at comment | ||
| 2006 | ;; If fails (beginning-of-line inside sexp), then contains not-comment | ||
| 2007 | ;; Do simplified processing | ||
| 2008 | ;;(if (re-search-forward "[^$]#" lim 1) | ||
| 2009 | ;; (progn | ||
| 2010 | ;; (forward-char -1) | ||
| 2011 | ;; (skip-chars-backward " \t\n\f" lim)) | ||
| 2012 | ;; (goto-char lim)) ; No `#' at all | ||
| 2013 | ;;) | ||
| 2014 | (if (nth 4 state) ; After `#'; | ||
| 2015 | ; (nth 2 state) can be | ||
| 2016 | ; beginning of m,s,qq and so | ||
| 2017 | ; on | ||
| 2018 | (if (nth 2 state) | ||
| 2019 | (progn | ||
| 2020 | (setq cpoint (point)) | ||
| 2021 | (goto-char (nth 2 state)) | ||
| 2022 | (cond | ||
| 2023 | ((looking-at "\\(s\\|tr\\)\\>") | ||
| 2024 | (or (re-search-forward | ||
| 2025 | "\\=\\w+[ \t]*#\\([^\n\\\\#]\\|\\\\[\\\\#]\\)*#\\([^\n\\\\#]\\|\\\\[\\\\#]\\)*" | ||
| 2026 | lim 'move) | ||
| 2027 | (setq stop-in t))) | ||
| 2028 | ((looking-at "\\(m\\|q\\([qxw]\\)?\\)\\>") | ||
| 2029 | (or (re-search-forward | ||
| 2030 | "\\=\\w+[ \t]*#\\([^\n\\\\#]\\|\\\\[\\\\#]\\)*#" | ||
| 2031 | lim 'move) | ||
| 2032 | (setq stop-in t))) | ||
| 2033 | (t ; It was fair comment | ||
| 2034 | (setq stop-in t) ; Finish | ||
| 2035 | (goto-char (1- cpoint))))) | ||
| 2036 | (setq stop-in t) ; Finish | ||
| 2037 | (forward-char -1)) | ||
| 2038 | (setq stop-in t)) ; Finish | ||
| 2039 | ) | ||
| 2040 | (nth 4 state)))) | ||
| 2041 | |||
| 2042 | (defsubst cperl-1- (p) | ||
| 2043 | (max (point-min) (1- p))) | ||
| 2044 | |||
| 2045 | (defsubst cperl-1+ (p) | ||
| 2046 | (min (point-max) (1+ p))) | ||
| 2047 | |||
| 2048 | (defvar cperl-st-cfence '(14)) ; Comment-fence | ||
| 2049 | (defvar cperl-st-sfence '(15)) ; String-fence | ||
| 2050 | (defvar cperl-st-punct '(1)) | ||
| 2051 | (defvar cperl-st-word '(2)) | ||
| 2052 | (defvar cperl-st-bra '(4 . ?\>)) | ||
| 2053 | (defvar cperl-st-ket '(5 . ?\<)) | ||
| 2054 | |||
| 2055 | (defsubst cperl-modify-syntax-type (at how) | ||
| 2056 | (if (< at (point-max)) | ||
| 2057 | (progn | ||
| 2058 | (put-text-property at (1+ at) 'syntax-table how) | ||
| 2059 | (put-text-property at (1+ at) 'rear-nonsticky t)))) | ||
| 2060 | |||
| 2061 | (defun cperl-protect-defun-start (s e) | ||
| 2062 | ;; C code looks for "^\\s(" to skip comment backward in "hard" situations | ||
| 2063 | (save-excursion | ||
| 2064 | (goto-char s) | ||
| 2065 | (while (re-search-forward "^\\s(" e 'to-end) | ||
| 2066 | (put-text-property (1- (point)) (point) 'syntax-table cperl-st-punct)))) | ||
| 2067 | |||
| 2068 | (defun cperl-commentify (bb e string) | ||
| 2069 | (if cperl-use-syntax-table-text-property | ||
| 2070 | (progn | ||
| 2071 | ;; We suppose that e is _after_ the end of construction, as after eol. | ||
| 2072 | (setq string (if string cperl-st-sfence cperl-st-cfence)) | ||
| 2073 | (cperl-modify-syntax-type bb string) | ||
| 2074 | (cperl-modify-syntax-type (1- e) string) | ||
| 2075 | (if (and (eq string cperl-st-sfence) (> (- e 2) bb)) | ||
| 2076 | (put-text-property (1+ bb) (1- e) | ||
| 2077 | 'syntax-table cperl-string-syntax-table)) | ||
| 2078 | (cperl-protect-defun-start bb e)))) | ||
| 2079 | |||
| 2080 | (defun cperl-forward-re (lim end is-2arg set-st st-l err-l argument | ||
| 2081 | &optional ostart oend) | ||
| 2082 | ;; Works *before* syntax recognition is done | ||
| 2083 | ;; May modify syntax-type text property if the situation is too hard | ||
| 2084 | (let (b starter ender st i i2 go-forward) | ||
| 2085 | (skip-chars-forward " \t") | ||
| 2086 | ;; ender means matching-char matcher. | ||
| 2087 | (setq b (point) | ||
| 2088 | starter (char-after b) | ||
| 2089 | ;; ender: | ||
| 2090 | ender (cdr (assoc starter '(( ?\( . ?\) ) | ||
| 2091 | ( ?\[ . ?\] ) | ||
| 2092 | ( ?\{ . ?\} ) | ||
| 2093 | ( ?\< . ?\> ) | ||
| 2094 | )))) | ||
| 2095 | ;; What if starter == ?\\ ???? | ||
| 2096 | (if set-st | ||
| 2097 | (if (car st-l) | ||
| 2098 | (setq st (car st-l)) | ||
| 2099 | (setcar st-l (make-syntax-table)) | ||
| 2100 | (setq i 0 st (car st-l)) | ||
| 2101 | (while (< i 256) | ||
| 2102 | (modify-syntax-entry i "." st) | ||
| 2103 | (setq i (1+ i))) | ||
| 2104 | (modify-syntax-entry ?\\ "\\" st))) | ||
| 2105 | (setq set-st t) | ||
| 2106 | ;; Whether we have an intermediate point | ||
| 2107 | (setq i nil) | ||
| 2108 | ;; Prepare the syntax table: | ||
| 2109 | (and set-st | ||
| 2110 | (if (not ender) ; m/blah/, s/x//, s/x/y/ | ||
| 2111 | (modify-syntax-entry starter "$" st) | ||
| 2112 | (modify-syntax-entry starter (concat "(" (list ender)) st) | ||
| 2113 | (modify-syntax-entry ender (concat ")" (list starter)) st))) | ||
| 2114 | (condition-case bb | ||
| 2115 | (progn | ||
| 2116 | (if (and (eq starter (char-after (cperl-1+ b))) | ||
| 2117 | (not ender)) | ||
| 2118 | ;; $ has TeXish matching rules, so $$ equiv $... | ||
| 2119 | (forward-char 2) | ||
| 2120 | (set-syntax-table st) | ||
| 2121 | (forward-sexp 1) | ||
| 2122 | (set-syntax-table cperl-mode-syntax-table) | ||
| 2123 | ;; Now the problem is with m;blah;; | ||
| 2124 | (and (not ender) | ||
| 2125 | (eq (preceding-char) | ||
| 2126 | (char-after (- (point) 2))) | ||
| 2127 | (save-excursion | ||
| 2128 | (forward-char -2) | ||
| 2129 | (= 0 (% (skip-chars-backward "\\\\") 2))) | ||
| 2130 | (forward-char -1))) | ||
| 2131 | (and is-2arg ; Have trailing part | ||
| 2132 | (not ender) | ||
| 2133 | (eq (following-char) starter) ; Empty trailing part | ||
| 2134 | (progn | ||
| 2135 | (or (eq (char-syntax (following-char)) ?.) | ||
| 2136 | ;; Make trailing letter into punctuation | ||
| 2137 | (cperl-modify-syntax-type (point) cperl-st-punct)) | ||
| 2138 | (setq is-2arg nil go-forward t))) ; Ignore the tail | ||
| 2139 | (if is-2arg ; Not number => have second part | ||
| 2140 | (progn | ||
| 2141 | (setq i (point) i2 i) | ||
| 2142 | (if ender | ||
| 2143 | (if (memq (following-char) '(?\ ?\t ?\n ?\f)) | ||
| 2144 | (progn | ||
| 2145 | (if (looking-at "[ \t\n\f]+\\(#[^\n]*\n[ \t\n\f]*\\)+") | ||
| 2146 | (goto-char (match-end 0)) | ||
| 2147 | (skip-chars-forward " \t\n\f")) | ||
| 2148 | (setq i2 (point)))) | ||
| 2149 | (forward-char -1)) | ||
| 2150 | (modify-syntax-entry starter (if (eq starter ?\\) "\\" ".") st) | ||
| 2151 | (if ender (modify-syntax-entry ender "." st)) | ||
| 2152 | (setq set-st nil) | ||
| 2153 | (setq | ||
| 2154 | ender | ||
| 2155 | (cperl-forward-re lim end nil t st-l err-l argument starter ender) | ||
| 2156 | ender (nth 2 ender))))) | ||
| 2157 | (error (goto-char lim) | ||
| 2158 | (setq set-st nil) | ||
| 2159 | (or end | ||
| 2160 | (message | ||
| 2161 | "End of `%s%s%c ... %c' string not found: %s" | ||
| 2162 | argument | ||
| 2163 | (if ostart (format "%c ... %c" ostart (or oend ostart)) "") | ||
| 2164 | starter (or ender starter) bb) | ||
| 2165 | (or (car err-l) (setcar err-l b))))) | ||
| 2166 | (if set-st | ||
| 2167 | (progn | ||
| 2168 | (modify-syntax-entry starter (if (eq starter ?\\) "\\" ".") st) | ||
| 2169 | (if ender (modify-syntax-entry ender "." st)))) | ||
| 2170 | (list i i2 ender starter go-forward))) | ||
| 2171 | |||
| 2172 | (defun cperl-find-pods-heres (&optional min max non-inter end) | ||
| 2173 | "Scans the buffer for hard-to-parse Perl constructions. | ||
| 2174 | If `cperl-pod-here-fontify' is not-nil after evaluation, will fontify | ||
| 2175 | the sections using `cperl-pod-head-face', `cperl-pod-face', | ||
| 2176 | `cperl-here-face'." | ||
| 2177 | (interactive) | ||
| 2178 | (or min (setq min (point-min))) | ||
| 2179 | (or max (setq max (point-max))) | ||
| 2180 | (let (face head-face here-face b e bb tag qtag b1 e1 argument i c tail state | ||
| 2181 | (cperl-pod-here-fontify (eval cperl-pod-here-fontify)) go | ||
| 2182 | (case-fold-search nil) (inhibit-read-only t) (buffer-undo-list t) | ||
| 2183 | (modified (buffer-modified-p)) | ||
| 2184 | (after-change-functions nil) | ||
| 2185 | (state-point (point-min)) | ||
| 2186 | (st-l '(nil)) (err-l '(nil)) i2 | ||
| 2187 | ;; Somehow font-lock may be not loaded yet... | ||
| 2188 | (font-lock-string-face (if (boundp 'font-lock-string-face) | ||
| 2189 | font-lock-string-face | ||
| 2190 | 'font-lock-string-face)) | ||
| 2191 | (search | ||
| 2192 | (concat | ||
| 2193 | "\\(\\`\n?\\|\n\n\\)=" | ||
| 2194 | "\\|" | ||
| 2195 | ;; One extra () before this: | ||
| 2196 | "<<" | ||
| 2197 | "\\(" | ||
| 2198 | ;; First variant "BLAH" or just ``. | ||
| 2199 | "\\([\"'`]\\)" | ||
| 2200 | "\\([^\"'`\n]*\\)" | ||
| 2201 | "\\3" | ||
| 2202 | "\\|" | ||
| 2203 | ;; Second variant: Identifier or empty | ||
| 2204 | "\\(\\([a-zA-Z_][a-zA-Z_0-9]*\\)?\\)" | ||
| 2205 | ;; Check that we do not have <<= or << 30 or << $blah. | ||
| 2206 | "\\([^= \t$@%&]\\|[ \t]+[^ \t\n0-9$@%&]\\)" | ||
| 2207 | "\\)" | ||
| 2208 | "\\|" | ||
| 2209 | ;; 1+6 extra () before this: | ||
| 2210 | "^[ \t]*\\(format\\)[ \t]*\\([a-zA-Z0-9_]+\\)?[ \t]*=[ \t]*$" | ||
| 2211 | (if cperl-use-syntax-table-text-property | ||
| 2212 | (concat | ||
| 2213 | "\\|" | ||
| 2214 | ;; 1+6+2=9 extra () before this: | ||
| 2215 | "\\<\\(q[wxq]?\\|[msy]\\|tr\\)\\>" | ||
| 2216 | "\\|" | ||
| 2217 | ;; 1+6+2+1=10 extra () before this: | ||
| 2218 | "\\([?/]\\)" ; /blah/ or ?blah? | ||
| 2219 | "\\|" | ||
| 2220 | ;; 1+6+2+1+1=11 extra () before this: | ||
| 2221 | "\\<sub\\>[ \t]*\\([a-zA-Z_:'0-9]+[ \t]*\\)?\\(([^()]*)\\)" | ||
| 2222 | "\\|" | ||
| 2223 | ;; 1+6+2+1+1+2=13 extra () before this: | ||
| 2224 | "\\$\\(['{]\\)" | ||
| 2225 | "\\|" | ||
| 2226 | ;; 1+6+2+1+1+2+1=14 extra () before this: | ||
| 2227 | "\\(\\<sub[ \t\n\f]+\\|[&*$@%]\\)[a-zA-Z0-9_]*'" | ||
| 2228 | ;; 1+6+2+1+1+2+1+1=15 extra () before this: | ||
| 2229 | "\\|" | ||
| 2230 | "__\\(END\\|DATA\\)__" ; Commented - does not help with indent... | ||
| 2231 | ) | ||
| 2232 | "")))) | ||
| 2233 | (unwind-protect | ||
| 2234 | (progn | ||
| 2235 | (save-excursion | ||
| 2236 | (or non-inter | ||
| 2237 | (message "Scanning for \"hard\" Perl constructions...")) | ||
| 2238 | (if cperl-pod-here-fontify | ||
| 2239 | ;; We had evals here, do not know why... | ||
| 2240 | (setq face cperl-pod-face | ||
| 2241 | head-face cperl-pod-head-face | ||
| 2242 | here-face cperl-here-face)) | ||
| 2243 | (remove-text-properties min max | ||
| 2244 | '(syntax-type t in-pod t syntax-table t)) | ||
| 2245 | ;; Need to remove face as well... | ||
| 2246 | (goto-char min) | ||
| 2247 | (if (and (eq system-type 'emx) | ||
| 2248 | (looking-at "extproc[ \t]")) ; Analogue of #! | ||
| 2249 | (cperl-commentify min | ||
| 2250 | (save-excursion (end-of-line) (point)) | ||
| 2251 | nil)) | ||
| 2252 | (while (re-search-forward search max t) | ||
| 2253 | (cond | ||
| 2254 | ((match-beginning 1) ; POD section | ||
| 2255 | ;; "\\(\\`\n?\\|\n\n\\)=" | ||
| 2256 | (if (looking-at "\n*cut\\>") | ||
| 2257 | (progn | ||
| 2258 | (message "=cut is not preceded by a POD section") | ||
| 2259 | (or (car err-l) (setcar err-l (point)))) | ||
| 2260 | (beginning-of-line) | ||
| 2261 | |||
| 2262 | (setq b (point) bb b) | ||
| 2263 | (or (re-search-forward "\n\n=cut\\>" max 'toend) | ||
| 2264 | (progn | ||
| 2265 | (message "End of a POD section not marked by =cut") | ||
| 2266 | (or (car err-l) (setcar err-l b)))) | ||
| 2267 | (beginning-of-line 2) ; An empty line after =cut is not POD! | ||
| 2268 | (setq e (point)) | ||
| 2269 | (put-text-property b e 'in-pod t) | ||
| 2270 | (goto-char b) | ||
| 2271 | (while (re-search-forward "\n\n[ \t]" e t) | ||
| 2272 | ;; We start 'pod 1 char earlier to include the preceding line | ||
| 2273 | (beginning-of-line) | ||
| 2274 | (put-text-property (cperl-1- b) (point) 'syntax-type 'pod) | ||
| 2275 | (cperl-put-do-not-fontify b (point)) | ||
| 2276 | ;;(put-text-property (max (point-min) (1- b)) | ||
| 2277 | ;; (point) cperl-do-not-fontify t) | ||
| 2278 | (if cperl-pod-here-fontify (put-text-property b (point) 'face face)) | ||
| 2279 | (re-search-forward "\n\n[^ \t\f\n]" e 'toend) | ||
| 2280 | (beginning-of-line) | ||
| 2281 | (setq b (point))) | ||
| 2282 | (put-text-property (cperl-1- (point)) e 'syntax-type 'pod) | ||
| 2283 | (cperl-put-do-not-fontify (point) e) | ||
| 2284 | ;;(put-text-property (max (point-min) (1- (point))) | ||
| 2285 | ;; e cperl-do-not-fontify t) | ||
| 2286 | (if cperl-pod-here-fontify | ||
| 2287 | (progn (put-text-property (point) e 'face face) | ||
| 2288 | (goto-char bb) | ||
| 2289 | (if (looking-at | ||
| 2290 | "=[a-zA-Z0-9_]+\\>[ \t]*\\(\\(\n?[^\n]\\)+\\)$") | ||
| 2291 | (put-text-property | ||
| 2292 | (match-beginning 1) (match-end 1) | ||
| 2293 | 'face head-face)) | ||
| 2294 | (while (re-search-forward | ||
| 2295 | ;; One paragraph | ||
| 2296 | "\n\n=[a-zA-Z0-9_]+\\>[ \t]*\\(\\(\n?[^\n]\\)+\\)$" | ||
| 2297 | e 'toend) | ||
| 2298 | (put-text-property | ||
| 2299 | (match-beginning 1) (match-end 1) | ||
| 2300 | 'face head-face)))) | ||
| 2301 | (cperl-commentify bb e nil) | ||
| 2302 | (goto-char e) | ||
| 2303 | (or (eq e (point-max)) | ||
| 2304 | (forward-char -1)))) ; Prepare for immediate pod start. | ||
| 2305 | ;; Here document | ||
| 2306 | ;; We do only one here-per-line | ||
| 2307 | ;; 1 () ahead | ||
| 2308 | ;; "<<\\(\\([\"'`]\\)\\([^\"'`\n]*\\)\\3\\|\\(\\([a-zA-Z_][a-zA-Z_0-9]*\\)?\\)\\)" | ||
| 2309 | ((match-beginning 2) ; 1 + 1 | ||
| 2310 | ;; Abort in comment: | ||
| 2311 | (setq b (point)) | ||
| 2312 | (setq state (parse-partial-sexp state-point b nil nil state) | ||
| 2313 | state-point b) | ||
| 2314 | (if ;;(save-excursion | ||
| 2315 | ;; (beginning-of-line) | ||
| 2316 | ;; (search-forward "#" b t)) | ||
| 2317 | (or (nth 3 state) (nth 4 state)) | ||
| 2318 | (goto-char (match-end 2)) | ||
| 2319 | (if (match-beginning 5) ;4 + 1 | ||
| 2320 | (setq b1 (match-beginning 5) ; 4 + 1 | ||
| 2321 | e1 (match-end 5)) ; 4 + 1 | ||
| 2322 | (setq b1 (match-beginning 4) ; 3 + 1 | ||
| 2323 | e1 (match-end 4))) ; 3 + 1 | ||
| 2324 | (setq tag (buffer-substring b1 e1) | ||
| 2325 | qtag (regexp-quote tag)) | ||
| 2326 | (cond (cperl-pod-here-fontify | ||
| 2327 | (put-text-property b1 e1 'face font-lock-reference-face) | ||
| 2328 | (cperl-put-do-not-fontify b1 e1))) | ||
| 2329 | (forward-line) | ||
| 2330 | (setq b (point)) | ||
| 2331 | (cond ((re-search-forward (concat "^" qtag "$") max 'toend) | ||
| 2332 | (if cperl-pod-here-fontify | ||
| 2333 | (progn | ||
| 2334 | (put-text-property (match-beginning 0) (match-end 0) | ||
| 2335 | 'face font-lock-reference-face) | ||
| 2336 | (cperl-put-do-not-fontify b (match-end 0)) | ||
| 2337 | ;;(put-text-property (max (point-min) (1- b)) | ||
| 2338 | ;; (min (point-max) | ||
| 2339 | ;; (1+ (match-end 0))) | ||
| 2340 | ;; cperl-do-not-fontify t) | ||
| 2341 | (put-text-property b (match-beginning 0) | ||
| 2342 | 'face here-face))) | ||
| 2343 | (setq e1 (cperl-1+ (match-end 0))) | ||
| 2344 | (put-text-property b (match-beginning 0) | ||
| 2345 | 'syntax-type 'here-doc) | ||
| 2346 | (put-text-property (match-beginning 0) e1 | ||
| 2347 | 'syntax-type 'here-doc-delim) | ||
| 2348 | (put-text-property b e1 | ||
| 2349 | 'here-doc-group t) | ||
| 2350 | (cperl-commentify b e1 nil) | ||
| 2351 | (cperl-put-do-not-fontify b (match-end 0))) | ||
| 2352 | (t (message "End of here-document `%s' not found." tag) | ||
| 2353 | (or (car err-l) (setcar err-l b)))))) | ||
| 2354 | ;; format | ||
| 2355 | ((match-beginning 8) | ||
| 2356 | ;; 1+6=7 extra () before this: | ||
| 2357 | ;;"^[ \t]*\\(format\\)[ \t]*\\([a-zA-Z0-9_]+\\)?[ \t]*=[ \t]*$" | ||
| 2358 | (setq b (point) | ||
| 2359 | name (if (match-beginning 8) ; 7 + 1 | ||
| 2360 | (buffer-substring (match-beginning 8) ; 7 + 1 | ||
| 2361 | (match-end 8)) ; 7 + 1 | ||
| 2362 | "")) | ||
| 2363 | (setq argument nil) | ||
| 2364 | (if cperl-pod-here-fontify | ||
| 2365 | (while (and (eq (forward-line) 0) | ||
| 2366 | (not (looking-at "^[.;]$"))) | ||
| 2367 | (cond | ||
| 2368 | ((looking-at "^#")) ; Skip comments | ||
| 2369 | ((and argument ; Skip argument multi-lines | ||
| 2370 | (looking-at "^[ \t]*{")) | ||
| 2371 | (forward-sexp 1) | ||
| 2372 | (setq argument nil)) | ||
| 2373 | (argument ; Skip argument lines | ||
| 2374 | (setq argument nil)) | ||
| 2375 | (t ; Format line | ||
| 2376 | (setq b1 (point)) | ||
| 2377 | (setq argument (looking-at "^[^\n]*[@^]")) | ||
| 2378 | (end-of-line) | ||
| 2379 | (put-text-property b1 (point) | ||
| 2380 | 'face font-lock-string-face) | ||
| 2381 | (cperl-commentify b1 (point) nil) | ||
| 2382 | (cperl-put-do-not-fontify b1 (point))))) | ||
| 2383 | (re-search-forward (concat "^[.;]$") max 'toend)) | ||
| 2384 | (beginning-of-line) | ||
| 2385 | (if (looking-at "^[.;]$") | ||
| 2386 | (progn | ||
| 2387 | (put-text-property (point) (+ (point) 2) | ||
| 2388 | 'face font-lock-string-face) | ||
| 2389 | (cperl-commentify (point) (+ (point) 2) nil) | ||
| 2390 | (cperl-put-do-not-fontify (point) (+ (point) 2))) | ||
| 2391 | (message "End of format `%s' not found." name) | ||
| 2392 | (or (car err-l) (setcar err-l b))) | ||
| 2393 | (forward-line) | ||
| 2394 | (put-text-property b (point) 'syntax-type 'format) | ||
| 2395 | ;;; (cond ((re-search-forward (concat "^[.;]$") max 'toend) | ||
| 2396 | ;;; (if cperl-pod-here-fontify | ||
| 2397 | ;;; (progn | ||
| 2398 | ;;; (put-text-property b (match-end 0) | ||
| 2399 | ;;; 'face font-lock-string-face) | ||
| 2400 | ;;; (cperl-put-do-not-fontify b (match-end 0)))) | ||
| 2401 | ;;; (put-text-property b (match-end 0) | ||
| 2402 | ;;; 'syntax-type 'format) | ||
| 2403 | ;;; (cperl-put-do-not-fontify b (match-beginning 0))) | ||
| 2404 | ;;; (t (message "End of format `%s' not found." name))) | ||
| 2405 | ) | ||
| 2406 | ;; Regexp: | ||
| 2407 | ((or (match-beginning 10) (match-beginning 11)) | ||
| 2408 | ;; 1+6+2=9 extra () before this: | ||
| 2409 | ;; "\\<\\(q[wxq]?\\|[msy]\\|tr\\)\\>" | ||
| 2410 | ;; "\\|" | ||
| 2411 | ;; "\\([?/]\\)" ; /blah/ or ?blah? | ||
| 2412 | (setq b1 (if (match-beginning 10) 10 11) | ||
| 2413 | argument (buffer-substring | ||
| 2414 | (match-beginning b1) (match-end b1)) | ||
| 2415 | b (point) | ||
| 2416 | i b | ||
| 2417 | c (char-after (match-beginning b1)) | ||
| 2418 | bb (char-after (1- (match-beginning b1))) ; tmp holder | ||
| 2419 | bb (and ; user variables/whatever | ||
| 2420 | (match-beginning 10) | ||
| 2421 | (or | ||
| 2422 | (memq bb '(?\$ ?\@ ?\% ?\* ?\#)) ; $#y | ||
| 2423 | (and (eq bb ?-) (eq c ?s)) ; -s file test | ||
| 2424 | (and (eq bb ?\&) ; &&m/blah/ | ||
| 2425 | (not (eq (char-after | ||
| 2426 | (- (match-beginning b1) 2)) | ||
| 2427 | ?\&)))))) | ||
| 2428 | (or bb | ||
| 2429 | (if (eq b1 11) ; bare /blah/ or ?blah? | ||
| 2430 | (setq argument "" | ||
| 2431 | bb ; Not a regexp? | ||
| 2432 | (progn | ||
| 2433 | (goto-char (match-beginning b1)) | ||
| 2434 | (cperl-backward-to-noncomment (point-min)) | ||
| 2435 | (not | ||
| 2436 | ;; What is below: regexp-p? | ||
| 2437 | (and | ||
| 2438 | (or (memq (preceding-char) | ||
| 2439 | (append (if (eq c ?\?) | ||
| 2440 | ;; $a++ ? 1 : 2 | ||
| 2441 | "~{(=|&*!,;" | ||
| 2442 | "~{(=|&+-*!,;") nil)) | ||
| 2443 | (and (eq (preceding-char) ?\}) | ||
| 2444 | (cperl-after-block-p (point-min))) | ||
| 2445 | (and (eq (char-syntax (preceding-char)) ?w) | ||
| 2446 | (progn | ||
| 2447 | (forward-sexp -1) | ||
| 2448 | (looking-at | ||
| 2449 | "\\(while\\|if\\|unless\\|until\\|and\\|or\\|not\\|xor\\|split\\|grep\\|map\\|print\\)\\>"))) | ||
| 2450 | (and (eq (preceding-char) ?.) | ||
| 2451 | (eq (char-after (- (point) 2)) ?.)) | ||
| 2452 | (bobp)) | ||
| 2453 | ;; m|blah| ? foo : bar; | ||
| 2454 | (not | ||
| 2455 | (and (eq c ?\?) | ||
| 2456 | cperl-use-syntax-table-text-property | ||
| 2457 | (not (bobp)) | ||
| 2458 | (progn | ||
| 2459 | (forward-char -1) | ||
| 2460 | (looking-at "\\s|"))))))) | ||
| 2461 | b (1- b)))) | ||
| 2462 | (or bb (setq state (parse-partial-sexp | ||
| 2463 | state-point b nil nil state) | ||
| 2464 | state-point b)) | ||
| 2465 | (goto-char b) | ||
| 2466 | (if (or bb (nth 3 state) (nth 4 state)) | ||
| 2467 | (goto-char i) | ||
| 2468 | (if (looking-at "[ \t\n\f]+\\(#[^\n]*\n[ \t\n\f]*\\)+") | ||
| 2469 | (goto-char (match-end 0)) | ||
| 2470 | (skip-chars-forward " \t\n\f")) | ||
| 2471 | ;; qtag means two-arg matcher, may be reset to | ||
| 2472 | ;; 2 or 3 later if some special quoting is needed. | ||
| 2473 | ;; e1 means matching-char matcher. | ||
| 2474 | (setq b (point) | ||
| 2475 | i (cperl-forward-re max end | ||
| 2476 | (string-match "^\\([sy]\\|tr\\)$" argument) | ||
| 2477 | t st-l err-l argument) | ||
| 2478 | i2 (nth 1 i) ; start of the second part | ||
| 2479 | e1 (nth 2 i) ; ender, true if matching second part | ||
| 2480 | go (nth 4 i) ; There is a 1-char part after the end | ||
| 2481 | i (car i) ; intermediate point | ||
| 2482 | tail (if (and i (not e1)) (1- (point))) | ||
| 2483 | e nil) ; need to preserve backslashitis | ||
| 2484 | ;; Commenting \\ is dangerous, what about ( ? | ||
| 2485 | (and i tail | ||
| 2486 | (eq (char-after i) ?\\) | ||
| 2487 | (setq e t)) | ||
| 2488 | (if (null i) | ||
| 2489 | (progn | ||
| 2490 | (cperl-commentify b (point) t) | ||
| 2491 | (if go (forward-char 1))) | ||
| 2492 | (cperl-commentify b i t) | ||
| 2493 | (if (looking-at "\\sw*e") ; s///e | ||
| 2494 | (progn | ||
| 2495 | (and | ||
| 2496 | ;; silent: | ||
| 2497 | (cperl-find-pods-heres i2 (1- (point)) t end) | ||
| 2498 | ;; Error | ||
| 2499 | (goto-char (1+ max))) | ||
| 2500 | (if (and e1 (eq (preceding-char) ?\>)) | ||
| 2501 | (progn | ||
| 2502 | (cperl-modify-syntax-type (1- (point)) cperl-st-ket) | ||
| 2503 | (cperl-modify-syntax-type i cperl-st-bra)))) | ||
| 2504 | (cperl-commentify i2 (point) t) | ||
| 2505 | (if e | ||
| 2506 | (cperl-modify-syntax-type (1+ i) cperl-st-punct)) | ||
| 2507 | (setq tail nil))) | ||
| 2508 | (if (eq (char-syntax (following-char)) ?w) | ||
| 2509 | (progn | ||
| 2510 | (forward-word 1) ; skip modifiers s///s | ||
| 2511 | (if tail (cperl-commentify tail (point) t)))))) | ||
| 2512 | ((match-beginning 13) ; sub with prototypes | ||
| 2513 | (setq b (match-beginning 0)) | ||
| 2514 | (if (memq (char-after (1- b)) | ||
| 2515 | '(?\$ ?\@ ?\% ?\& ?\*)) | ||
| 2516 | nil | ||
| 2517 | (setq state (parse-partial-sexp | ||
| 2518 | state-point (1- b) nil nil state) | ||
| 2519 | state-point (1- b)) | ||
| 2520 | (if (or (nth 3 state) (nth 4 state)) | ||
| 2521 | nil | ||
| 2522 | ;; Mark as string | ||
| 2523 | (cperl-commentify (match-beginning 13) (match-end 13) t)) | ||
| 2524 | (goto-char (match-end 0)))) | ||
| 2525 | ;; 1+6+2+1+1+2=13 extra () before this: | ||
| 2526 | ;; "\\$\\(['{]\\)" | ||
| 2527 | ((and (match-beginning 14) | ||
| 2528 | (eq (preceding-char) ?\')) ; $' | ||
| 2529 | (setq b (1- (point)) | ||
| 2530 | state (parse-partial-sexp | ||
| 2531 | state-point (1- b) nil nil state) | ||
| 2532 | state-point (1- b)) | ||
| 2533 | (if (nth 3 state) ; in string | ||
| 2534 | (cperl-modify-syntax-type (1- b) cperl-st-punct)) | ||
| 2535 | (goto-char (1+ b))) | ||
| 2536 | ;; 1+6+2+1+1+2=13 extra () before this: | ||
| 2537 | ;; "\\$\\(['{]\\)" | ||
| 2538 | ((match-beginning 14) ; ${ | ||
| 2539 | (setq bb (match-beginning 0)) | ||
| 2540 | (cperl-modify-syntax-type bb cperl-st-punct)) | ||
| 2541 | ;; 1+6+2+1+1+2+1=14 extra () before this: | ||
| 2542 | ;; "\\(\\<sub[ \t\n\f]+\\|[&*$@%]\\)[a-zA-Z0-9_]*'") | ||
| 2543 | ((match-beginning 15) ; old $abc'efg syntax | ||
| 2544 | (setq bb (match-end 0) | ||
| 2545 | b (match-beginning 0) | ||
| 2546 | state (parse-partial-sexp | ||
| 2547 | state-point b nil nil state) | ||
| 2548 | state-point b) | ||
| 2549 | (if (nth 3 state) ; in string | ||
| 2550 | nil | ||
| 2551 | (put-text-property (1- bb) bb 'syntax-table cperl-st-word)) | ||
| 2552 | (goto-char bb)) | ||
| 2553 | ;; 1+6+2+1+1+2+1+1=15 extra () before this: | ||
| 2554 | ;; "__\\(END\\|DATA\\)__" | ||
| 2555 | (t ; __END__, __DATA__ | ||
| 2556 | (setq bb (match-end 0) | ||
| 2557 | b (match-beginning 0) | ||
| 2558 | state (parse-partial-sexp | ||
| 2559 | state-point b nil nil state) | ||
| 2560 | state-point b) | ||
| 2561 | (if (or (nth 3 state) (nth 4 state)) | ||
| 2562 | nil | ||
| 2563 | ;; (put-text-property b (1+ bb) 'syntax-type 'pod) ; Cheat | ||
| 2564 | (cperl-commentify b bb nil) | ||
| 2565 | (setq end t)) | ||
| 2566 | (goto-char bb))) | ||
| 2567 | (if (> (point) max) | ||
| 2568 | (progn | ||
| 2569 | (if end | ||
| 2570 | (message "Garbage after __END__/__DATA__ ignored") | ||
| 2571 | (message "Unbalanced syntax found while scanning") | ||
| 2572 | (or (car err-l) (setcar err-l b))) | ||
| 2573 | (goto-char max)))) | ||
| 2574 | ;;; (while (re-search-forward "\\(\\`\n?\\|\n\n\\)=" max t) | ||
| 2575 | ;;; (if (looking-at "\n*cut\\>") | ||
| 2576 | ;;; (progn | ||
| 2577 | ;;; (message "=cut is not preceded by a pod section") | ||
| 2578 | ;;; (setq err (point))) | ||
| 2579 | ;;; (beginning-of-line) | ||
| 2580 | |||
| 2581 | ;;; (setq b (point) bb b) | ||
| 2582 | ;;; (or (re-search-forward "\n\n=cut\\>" max 'toend) | ||
| 2583 | ;;; (message "Cannot find the end of a pod section")) | ||
| 2584 | ;;; (beginning-of-line 3) | ||
| 2585 | ;;; (setq e (point)) | ||
| 2586 | ;;; (put-text-property b e 'in-pod t) | ||
| 2587 | ;;; (goto-char b) | ||
| 2588 | ;;; (while (re-search-forward "\n\n[ \t]" e t) | ||
| 2589 | ;;; (beginning-of-line) | ||
| 2590 | ;;; (put-text-property b (point) 'syntax-type 'pod) | ||
| 2591 | ;;; (cperl-put-do-not-fontify b (point)) | ||
| 2592 | ;;; ;;(put-text-property (max (point-min) (1- b)) | ||
| 2593 | ;;; ;; (point) cperl-do-not-fontify t) | ||
| 2594 | ;;; (if cperl-pod-here-fontify (put-text-property b (point) 'face face)) | ||
| 2595 | ;;; (re-search-forward "\n\n[^ \t\f\n]" e 'toend) | ||
| 2596 | ;;; (beginning-of-line) | ||
| 2597 | ;;; (setq b (point))) | ||
| 2598 | ;;; (put-text-property (point) e 'syntax-type 'pod) | ||
| 2599 | ;;; (cperl-put-do-not-fontify (point) e) | ||
| 2600 | ;;; ;;(put-text-property (max (point-min) (1- (point))) | ||
| 2601 | ;;; ;; e cperl-do-not-fontify t) | ||
| 2602 | ;;; (if cperl-pod-here-fontify | ||
| 2603 | ;;; (progn (put-text-property (point) e 'face face) | ||
| 2604 | ;;; (goto-char bb) | ||
| 2605 | ;;; (if (looking-at | ||
| 2606 | ;;; "=[a-zA-Z0-9]+\\>[ \t]*\\(\\(\n?[^\n]\\)+\\)$") | ||
| 2607 | ;;; (put-text-property | ||
| 2608 | ;;; (match-beginning 1) (match-end 1) | ||
| 2609 | ;;; 'face head-face)) | ||
| 2610 | ;;; (while (re-search-forward | ||
| 2611 | ;;; ;; One paragraph | ||
| 2612 | ;;; "\n\n=[a-zA-Z0-9]+\\>[ \t]*\\(\\(\n?[^\n]\\)+\\)$" | ||
| 2613 | ;;; e 'toend) | ||
| 2614 | ;;; (put-text-property | ||
| 2615 | ;;; (match-beginning 1) (match-end 1) | ||
| 2616 | ;;; 'face head-face)))) | ||
| 2617 | ;;; (goto-char e))) | ||
| 2618 | ;;; (goto-char min) | ||
| 2619 | ;;; (while (re-search-forward | ||
| 2620 | ;;; ;; We exclude \n to avoid misrecognition inside quotes. | ||
| 2621 | ;;; "<<\\(\\([\"'`]\\)\\([^\"'`\n]*\\)\\2\\|\\(\\([a-zA-Z_][a-zA-Z_0-9]*\\)?\\)\\)" | ||
| 2622 | ;;; max t) | ||
| 2623 | ;;; (if (match-beginning 4) | ||
| 2624 | ;;; (setq b1 (match-beginning 4) | ||
| 2625 | ;;; e1 (match-end 4)) | ||
| 2626 | ;;; (setq b1 (match-beginning 3) | ||
| 2627 | ;;; e1 (match-end 3))) | ||
| 2628 | ;;; (setq tag (buffer-substring b1 e1) | ||
| 2629 | ;;; qtag (regexp-quote tag)) | ||
| 2630 | ;;; (cond (cperl-pod-here-fontify | ||
| 2631 | ;;; (put-text-property b1 e1 'face font-lock-reference-face) | ||
| 2632 | ;;; (cperl-put-do-not-fontify b1 e1))) | ||
| 2633 | ;;; (forward-line) | ||
| 2634 | ;;; (setq b (point)) | ||
| 2635 | ;;; (cond ((re-search-forward (concat "^" qtag "$") max 'toend) | ||
| 2636 | ;;; (if cperl-pod-here-fontify | ||
| 2637 | ;;; (progn | ||
| 2638 | ;;; (put-text-property (match-beginning 0) (match-end 0) | ||
| 2639 | ;;; 'face font-lock-reference-face) | ||
| 2640 | ;;; (cperl-put-do-not-fontify b (match-end 0)) | ||
| 2641 | ;;; ;;(put-text-property (max (point-min) (1- b)) | ||
| 2642 | ;;; ;; (min (point-max) | ||
| 2643 | ;;; ;; (1+ (match-end 0))) | ||
| 2644 | ;;; ;; cperl-do-not-fontify t) | ||
| 2645 | ;;; (put-text-property b (match-beginning 0) | ||
| 2646 | ;;; 'face here-face))) | ||
| 2647 | ;;; (put-text-property b (match-beginning 0) | ||
| 2648 | ;;; 'syntax-type 'here-doc) | ||
| 2649 | ;;; (cperl-put-do-not-fontify b (match-beginning 0))) | ||
| 2650 | ;;; (t (message "End of here-document `%s' not found." tag)))) | ||
| 2651 | ;;; (goto-char min) | ||
| 2652 | ;;; (while (re-search-forward | ||
| 2653 | ;;; "^[ \t]*format[ \t]*\\(\\([a-zA-Z0-9_]+[ \t]*\\)?\\)=[ \t]*$" | ||
| 2654 | ;;; max t) | ||
| 2655 | ;;; (setq b (point) | ||
| 2656 | ;;; name (buffer-substring (match-beginning 1) | ||
| 2657 | ;;; (match-end 1))) | ||
| 2658 | ;;; (cond ((re-search-forward (concat "^[.;]$") max 'toend) | ||
| 2659 | ;;; (if cperl-pod-here-fontify | ||
| 2660 | ;;; (progn | ||
| 2661 | ;;; (put-text-property b (match-end 0) | ||
| 2662 | ;;; 'face font-lock-string-face) | ||
| 2663 | ;;; (cperl-put-do-not-fontify b (match-end 0)))) | ||
| 2664 | ;;; (put-text-property b (match-end 0) | ||
| 2665 | ;;; 'syntax-type 'format) | ||
| 2666 | ;;; (cperl-put-do-not-fontify b (match-beginning 0))) | ||
| 2667 | ;;; (t (message "End of format `%s' not found." name)))) | ||
| 2668 | ) | ||
| 2669 | (if (car err-l) (goto-char (car err-l)) | ||
| 2670 | (or noninteractive | ||
| 2671 | (message "Scan for \"hard\" Perl constructions completed.")))) | ||
| 2672 | (and (buffer-modified-p) | ||
| 2673 | (not modified) | ||
| 2674 | (set-buffer-modified-p nil)) | ||
| 2675 | (set-syntax-table cperl-mode-syntax-table)) | ||
| 2676 | (car err-l))) | ||
| 2677 | |||
| 2678 | (defun cperl-backward-to-noncomment (lim) | ||
| 2679 | ;; Stops at lim or after non-whitespace that is not in comment | ||
| 2680 | (let (stop p) | ||
| 2681 | (while (and (not stop) (> (point) (or lim 1))) | ||
| 2682 | (skip-chars-backward " \t\n\f" lim) | ||
| 2683 | (setq p (point)) | ||
| 2684 | (beginning-of-line) | ||
| 2685 | (if (or (looking-at "^[ \t]*\\(#\\|$\\)") | ||
| 2686 | (progn (cperl-to-comment-or-eol) (bolp))) | ||
| 2687 | nil ; Only comment, skip | ||
| 2688 | ;; Else | ||
| 2689 | (skip-chars-backward " \t") | ||
| 2690 | (if (< p (point)) (goto-char p)) | ||
| 2691 | (setq stop t))))) | ||
| 2692 | |||
| 2693 | (defun cperl-after-block-p (lim) | ||
| 2694 | ;; We suppose that the preceding char is }. | ||
| 2695 | (save-excursion | ||
| 2696 | (condition-case nil | ||
| 2697 | (progn | ||
| 2698 | (forward-sexp -1) | ||
| 2699 | (cperl-backward-to-noncomment lim) | ||
| 2700 | (or (eq (preceding-char) ?\) ) ; if () {} | ||
| 2701 | (and (eq (char-syntax (preceding-char)) ?w) ; else {} | ||
| 2702 | (progn | ||
| 2703 | (forward-sexp -1) | ||
| 2704 | (looking-at "\\(else\\|grep\\|map\\)\\>"))) | ||
| 2705 | (cperl-after-expr-p lim))) | ||
| 2706 | (error nil)))) | ||
| 2707 | |||
| 2708 | (defun cperl-after-expr-p (&optional lim chars test) | ||
| 2709 | "Returns true if the position is good for start of expression. | ||
| 2710 | TEST is the expression to evaluate at the found position. If absent, | ||
| 2711 | CHARS is a string that contains good characters to have before us (however, | ||
| 2712 | `}' is treated \"smartly\" if it is not in the list)." | ||
| 2713 | (let (stop p | ||
| 2714 | (lim (or lim (point-min)))) | ||
| 2715 | (save-excursion | ||
| 2716 | (while (and (not stop) (> (point) lim)) | ||
| 2717 | (skip-chars-backward " \t\n\f" lim) | ||
| 2718 | (setq p (point)) | ||
| 2719 | (beginning-of-line) | ||
| 2720 | (if (looking-at "^[ \t]*\\(#\\|$\\)") nil ; Only comment, skip | ||
| 2721 | ;; Else: last iteration (What to do with labels?) | ||
| 2722 | (cperl-to-comment-or-eol) | ||
| 2723 | (skip-chars-backward " \t") | ||
| 2724 | (if (< p (point)) (goto-char p)) | ||
| 2725 | (setq stop t))) | ||
| 2726 | (or (bobp) | ||
| 2727 | (progn | ||
| 2728 | (if test (eval test) | ||
| 2729 | (or (memq (preceding-char) (append (or chars "{;") nil)) | ||
| 2730 | (and (eq (preceding-char) ?\}) | ||
| 2731 | (cperl-after-block-p lim))))))))) | ||
| 2732 | |||
| 2733 | (defun cperl-backward-to-start-of-continued-exp (lim) | ||
| 2734 | (if (memq (preceding-char) (append ")]}\"'`" nil)) | ||
| 2735 | (forward-sexp -1)) | ||
| 2736 | (beginning-of-line) | ||
| 2737 | (if (<= (point) lim) | ||
| 2738 | (goto-char (1+ lim))) | ||
| 2739 | (skip-chars-forward " \t")) | ||
| 2740 | |||
| 2741 | |||
| 2742 | (defvar innerloop-done nil) | ||
| 2743 | (defvar last-depth nil) | ||
| 2744 | |||
| 2745 | (defun cperl-indent-exp () | ||
| 2746 | "Simple variant of indentation of continued-sexp. | ||
| 2747 | Should be slow. Will not indent comment if it starts at `comment-indent' | ||
| 2748 | or looks like continuation of the comment on the previous line." | ||
| 2749 | (interactive) | ||
| 2750 | (save-excursion | ||
| 2751 | (let ((tmp-end (progn (end-of-line) (point))) top done) | ||
| 2752 | (save-excursion | ||
| 2753 | (beginning-of-line) | ||
| 2754 | (while (null done) | ||
| 2755 | (setq top (point)) | ||
| 2756 | (while (= (nth 0 (parse-partial-sexp (point) tmp-end | ||
| 2757 | -1)) -1) | ||
| 2758 | (setq top (point))) ; Get the outermost parenths in line | ||
| 2759 | (goto-char top) | ||
| 2760 | (while (< (point) tmp-end) | ||
| 2761 | (parse-partial-sexp (point) tmp-end nil t) ; To start-sexp or eol | ||
| 2762 | (or (eolp) (forward-sexp 1))) | ||
| 2763 | (if (> (point) tmp-end) (progn (end-of-line) (setq tmp-end (point))) | ||
| 2764 | (setq done t))) | ||
| 2765 | (goto-char tmp-end) | ||
| 2766 | (setq tmp-end (point-marker))) | ||
| 2767 | (cperl-indent-region (point) tmp-end)))) | ||
| 2768 | |||
| 2769 | (defun cperl-indent-region (start end) | ||
| 2770 | "Simple variant of indentation of region in CPerl mode. | ||
| 2771 | Should be slow. Will not indent comment if it starts at `comment-indent' | ||
| 2772 | or looks like continuation of the comment on the previous line. | ||
| 2773 | Indents all the lines whose first character is between START and END | ||
| 2774 | inclusive." | ||
| 2775 | (interactive "r") | ||
| 2776 | (save-excursion | ||
| 2777 | (let (st comm indent-info old-comm-indent new-comm-indent | ||
| 2778 | (pm 0) (imenu-scanning-message "Indenting... (%3d%%)")) | ||
| 2779 | (goto-char start) | ||
| 2780 | (setq old-comm-indent (and (cperl-to-comment-or-eol) | ||
| 2781 | (current-column)) | ||
| 2782 | new-comm-indent old-comm-indent) | ||
| 2783 | (goto-char start) | ||
| 2784 | (or (bolp) (beginning-of-line 2)) | ||
| 2785 | (or (fboundp 'imenu-progress-message) | ||
| 2786 | (message "Indenting... For feedback load `imenu'...")) | ||
| 2787 | (while (and (<= (point) end) (not (eobp))) ; bol to check start | ||
| 2788 | (and (fboundp 'imenu-progress-message) | ||
| 2789 | (imenu-progress-message | ||
| 2790 | pm (/ (* 100 (- (point) start)) (- end start -1)))) | ||
| 2791 | (setq st (point) | ||
| 2792 | indent-info nil | ||
| 2793 | ) ; Believe indentation of the current | ||
| 2794 | (if (and (setq comm (looking-at "[ \t]*#")) | ||
| 2795 | (or (eq (current-indentation) (or old-comm-indent | ||
| 2796 | comment-column)) | ||
| 2797 | (setq old-comm-indent nil))) | ||
| 2798 | (if (and old-comm-indent | ||
| 2799 | (= (current-indentation) old-comm-indent) | ||
| 2800 | (not (eq (get-text-property (point) 'syntax-type) 'pod))) | ||
| 2801 | (let ((comment-column new-comm-indent)) | ||
| 2802 | (indent-for-comment))) | ||
| 2803 | (progn | ||
| 2804 | (cperl-indent-line 'indent-info) | ||
| 2805 | (or comm | ||
| 2806 | (progn | ||
| 2807 | (if (setq old-comm-indent | ||
| 2808 | (and (cperl-to-comment-or-eol) | ||
| 2809 | (not (memq (get-text-property (point) | ||
| 2810 | 'syntax-type) | ||
| 2811 | '(pod here-doc))) | ||
| 2812 | (current-column))) | ||
| 2813 | (progn (indent-for-comment) | ||
| 2814 | (skip-chars-backward " \t") | ||
| 2815 | (skip-chars-backward "#") | ||
| 2816 | (setq new-comm-indent (current-column)))))))) | ||
| 2817 | (beginning-of-line 2)) | ||
| 2818 | (if (fboundp 'imenu-progress-message) | ||
| 2819 | (imenu-progress-message pm 100) | ||
| 2820 | (message nil))))) | ||
| 2821 | |||
| 2822 | ;;(defun cperl-slash-is-regexp (&optional pos) | ||
| 2823 | ;; (save-excursion | ||
| 2824 | ;; (goto-char (if pos pos (1- (point)))) | ||
| 2825 | ;; (and | ||
| 2826 | ;; (not (memq (get-text-property (point) 'face) | ||
| 2827 | ;; '(font-lock-string-face font-lock-comment-face))) | ||
| 2828 | ;; (cperl-after-expr-p nil nil ' | ||
| 2829 | ;; (or (looking-at "[^]a-zA-Z0-9_)}]") | ||
| 2830 | ;; (eq (get-text-property (point) 'face) | ||
| 2831 | ;; 'font-lock-keyword-face)))))) | ||
| 2832 | |||
| 2833 | ;; Stolen from lisp-mode with a lot of improvements | ||
| 2834 | |||
| 2835 | (defun cperl-fill-paragraph (&optional justify iteration) | ||
| 2836 | "Like \\[fill-paragraph], but handle CPerl comments. | ||
| 2837 | If any of the current line is a comment, fill the comment or the | ||
| 2838 | block of it that point is in, preserving the comment's initial | ||
| 2839 | indentation and initial hashes. Behaves usually outside of comment." | ||
| 2840 | (interactive "P") | ||
| 2841 | (let ( | ||
| 2842 | ;; Non-nil if the current line contains a comment. | ||
| 2843 | has-comment | ||
| 2844 | |||
| 2845 | ;; If has-comment, the appropriate fill-prefix for the comment. | ||
| 2846 | comment-fill-prefix | ||
| 2847 | ;; Line that contains code and comment (or nil) | ||
| 2848 | start | ||
| 2849 | c spaces len dc (comment-column comment-column)) | ||
| 2850 | ;; Figure out what kind of comment we are looking at. | ||
| 2851 | (save-excursion | ||
| 2852 | (beginning-of-line) | ||
| 2853 | (cond | ||
| 2854 | |||
| 2855 | ;; A line with nothing but a comment on it? | ||
| 2856 | ((looking-at "[ \t]*#[# \t]*") | ||
| 2857 | (setq has-comment t | ||
| 2858 | comment-fill-prefix (buffer-substring (match-beginning 0) | ||
| 2859 | (match-end 0)))) | ||
| 2860 | |||
| 2861 | ;; A line with some code, followed by a comment? Remember that the | ||
| 2862 | ;; semi which starts the comment shouldn't be part of a string or | ||
| 2863 | ;; character. | ||
| 2864 | ((cperl-to-comment-or-eol) | ||
| 2865 | (setq has-comment t) | ||
| 2866 | (looking-at "#+[ \t]*") | ||
| 2867 | (setq start (point) c (current-column) | ||
| 2868 | comment-fill-prefix | ||
| 2869 | (concat (make-string (current-column) ?\ ) | ||
| 2870 | (buffer-substring (match-beginning 0) (match-end 0))) | ||
| 2871 | spaces (progn (skip-chars-backward " \t") | ||
| 2872 | (buffer-substring (point) start)) | ||
| 2873 | dc (- c (current-column)) len (- start (point)) | ||
| 2874 | start (point-marker)) | ||
| 2875 | (delete-char len) | ||
| 2876 | (insert (make-string dc ?-))))) | ||
| 2877 | (if (not has-comment) | ||
| 2878 | (fill-paragraph justify) ; Do the usual thing outside of comment | ||
| 2879 | ;; Narrow to include only the comment, and then fill the region. | ||
| 2880 | (save-restriction | ||
| 2881 | (narrow-to-region | ||
| 2882 | ;; Find the first line we should include in the region to fill. | ||
| 2883 | (if start (progn (beginning-of-line) (point)) | ||
| 2884 | (save-excursion | ||
| 2885 | (while (and (zerop (forward-line -1)) | ||
| 2886 | (looking-at "^[ \t]*#+[ \t]*[^ \t\n#]"))) | ||
| 2887 | ;; We may have gone to far. Go forward again. | ||
| 2888 | (or (looking-at "^[ \t]*#+[ \t]*[^ \t\n#]") | ||
| 2889 | (forward-line 1)) | ||
| 2890 | (point))) | ||
| 2891 | ;; Find the beginning of the first line past the region to fill. | ||
| 2892 | (save-excursion | ||
| 2893 | (while (progn (forward-line 1) | ||
| 2894 | (looking-at "^[ \t]*#+[ \t]*[^ \t\n#]"))) | ||
| 2895 | (point))) | ||
| 2896 | ;; Remove existing hashes | ||
| 2897 | (goto-char (point-min)) | ||
| 2898 | (while (progn (forward-line 1) (< (point) (point-max))) | ||
| 2899 | (skip-chars-forward " \t") | ||
| 2900 | (and (looking-at "#+") | ||
| 2901 | (delete-char (- (match-end 0) (match-beginning 0))))) | ||
| 2902 | |||
| 2903 | ;; Lines with only hashes on them can be paragraph boundaries. | ||
| 2904 | (let ((paragraph-start (concat paragraph-start "\\|^[ \t#]*$")) | ||
| 2905 | (paragraph-separate (concat paragraph-start "\\|^[ \t#]*$")) | ||
| 2906 | (fill-prefix comment-fill-prefix)) | ||
| 2907 | (fill-paragraph justify))) | ||
| 2908 | (if (and start) | ||
| 2909 | (progn | ||
| 2910 | (goto-char start) | ||
| 2911 | (if (> dc 0) | ||
| 2912 | (progn (delete-char dc) (insert spaces))) | ||
| 2913 | (if (or (= (current-column) c) iteration) nil | ||
| 2914 | (setq comment-column c) | ||
| 2915 | (indent-for-comment) | ||
| 2916 | ;; Repeat once more, flagging as iteration | ||
| 2917 | (cperl-fill-paragraph justify t))))))) | ||
| 2918 | |||
| 2919 | (defun cperl-do-auto-fill () | ||
| 2920 | ;; Break out if the line is short enough | ||
| 2921 | (if (> (save-excursion | ||
| 2922 | (end-of-line) | ||
| 2923 | (current-column)) | ||
| 2924 | fill-column) | ||
| 2925 | (let ((c (save-excursion (beginning-of-line) | ||
| 2926 | (cperl-to-comment-or-eol) (point))) | ||
| 2927 | (s (memq (following-char) '(?\ ?\t))) marker) | ||
| 2928 | (if (>= c (point)) nil | ||
| 2929 | (setq marker (point-marker)) | ||
| 2930 | (cperl-fill-paragraph) | ||
| 2931 | (goto-char marker) | ||
| 2932 | ;; Is not enough, sometimes marker is a start of line | ||
| 2933 | (if (bolp) (progn (re-search-forward "#+[ \t]*") | ||
| 2934 | (goto-char (match-end 0)))) | ||
| 2935 | ;; Following space could have gone: | ||
| 2936 | (if (or (not s) (memq (following-char) '(?\ ?\t))) nil | ||
| 2937 | (insert " ") | ||
| 2938 | (backward-char 1)) | ||
| 2939 | ;; Previous space could have gone: | ||
| 2940 | (or (memq (preceding-char) '(?\ ?\t)) (insert " ")))))) | ||
| 2941 | |||
| 2942 | (defvar imenu-example--function-name-regexp-perl | ||
| 2943 | (concat | ||
| 2944 | "^\\(" | ||
| 2945 | "[ \t]*\\(sub\\|package\\)[ \t\n]+\\([a-zA-Z_0-9:']+\\)[ \t]*\\(([^()]*)[ \t]*\\)?" | ||
| 2946 | "\\|" | ||
| 2947 | "=head\\([12]\\)[ \t]+\\([^\n]+\\)$" | ||
| 2948 | "\\)")) | ||
| 2949 | |||
| 2950 | (defun cperl-imenu-addback (lst &optional isback name) | ||
| 2951 | ;; We suppose that the lst is a DAG, unless the first element only | ||
| 2952 | ;; loops back, and ISBACK is set. Thus this function cannot be | ||
| 2953 | ;; applied twice without ISBACK set. | ||
| 2954 | (cond ((not cperl-imenu-addback) lst) | ||
| 2955 | (t | ||
| 2956 | (or name | ||
| 2957 | (setq name "+++BACK+++")) | ||
| 2958 | (mapcar (function (lambda (elt) | ||
| 2959 | (if (and (listp elt) (listp (cdr elt))) | ||
| 2960 | (progn | ||
| 2961 | ;; In the other order it goes up | ||
| 2962 | ;; one level only ;-( | ||
| 2963 | (setcdr elt (cons (cons name lst) | ||
| 2964 | (cdr elt))) | ||
| 2965 | (cperl-imenu-addback (cdr elt) t name) | ||
| 2966 | )))) | ||
| 2967 | (if isback (cdr lst) lst)) | ||
| 2968 | lst))) | ||
| 2969 | |||
| 2970 | (defun imenu-example--create-perl-index (&optional regexp) | ||
| 2971 | (require 'cl) | ||
| 2972 | (require 'imenu) ; May be called from TAGS creator | ||
| 2973 | (let ((index-alist '()) (index-pack-alist '()) (index-pod-alist '()) | ||
| 2974 | (index-unsorted-alist '()) (i-s-f (default-value 'imenu-sort-function)) | ||
| 2975 | (index-meth-alist '()) meth | ||
| 2976 | packages ends-ranges p | ||
| 2977 | (prev-pos 0) char fchar index index1 name (end-range 0) package) | ||
| 2978 | (goto-char (point-min)) | ||
| 2979 | (if noninteractive | ||
| 2980 | (message "Scanning Perl for index") | ||
| 2981 | (imenu-progress-message prev-pos 0)) | ||
| 2982 | ;; Search for the function | ||
| 2983 | (progn ;;save-match-data | ||
| 2984 | (while (re-search-forward | ||
| 2985 | (or regexp imenu-example--function-name-regexp-perl) | ||
| 2986 | nil t) | ||
| 2987 | (or noninteractive | ||
| 2988 | (imenu-progress-message prev-pos)) | ||
| 2989 | ;;(backward-up-list 1) | ||
| 2990 | (cond | ||
| 2991 | ((and ; Skip some noise if building tags | ||
| 2992 | (match-beginning 2) ; package or sub | ||
| 2993 | (eq (char-after (match-beginning 2)) ?p) ; package | ||
| 2994 | (not (save-match-data | ||
| 2995 | (looking-at "[ \t\n]*;")))) ; Plain text word 'package' | ||
| 2996 | nil) | ||
| 2997 | ((and | ||
| 2998 | (match-beginning 2) ; package or sub | ||
| 2999 | ;; Skip if quoted (will not skip multi-line ''-comments :-(): | ||
| 3000 | (null (get-text-property (match-beginning 1) 'syntax-table)) | ||
| 3001 | (null (get-text-property (match-beginning 1) 'syntax-type)) | ||
| 3002 | (null (get-text-property (match-beginning 1) 'in-pod))) | ||
| 3003 | (save-excursion | ||
| 3004 | (goto-char (match-beginning 2)) | ||
| 3005 | (setq fchar (following-char)) | ||
| 3006 | ) | ||
| 3007 | ;; (if (looking-at "([^()]*)[ \t\n\f]*") | ||
| 3008 | ;; (goto-char (match-end 0))) ; Messes what follows | ||
| 3009 | (setq char (following-char) | ||
| 3010 | meth nil | ||
| 3011 | p (point)) | ||
| 3012 | (while (and ends-ranges (>= p (car ends-ranges))) | ||
| 3013 | ;; delete obsolete entries | ||
| 3014 | (setq ends-ranges (cdr ends-ranges) packages (cdr packages))) | ||
| 3015 | (setq package (or (car packages) "") | ||
| 3016 | end-range (or (car ends-ranges) 0)) | ||
| 3017 | (if (eq fchar ?p) | ||
| 3018 | (setq name (buffer-substring (match-beginning 3) (match-end 3)) | ||
| 3019 | name (progn | ||
| 3020 | (set-text-properties 0 (length name) nil name) | ||
| 3021 | name) | ||
| 3022 | package (concat name "::") | ||
| 3023 | name (concat "package " name) | ||
| 3024 | end-range | ||
| 3025 | (save-excursion | ||
| 3026 | (parse-partial-sexp (point) (point-max) -1) (point)) | ||
| 3027 | ends-ranges (cons end-range ends-ranges) | ||
| 3028 | packages (cons package packages))) | ||
| 3029 | ;; ) | ||
| 3030 | ;; Skip this function name if it is a prototype declaration. | ||
| 3031 | (if (and (eq fchar ?s) (eq char ?\;)) nil | ||
| 3032 | (setq index (imenu-example--name-and-position)) | ||
| 3033 | (if (eq fchar ?p) nil | ||
| 3034 | (setq name (buffer-substring (match-beginning 3) (match-end 3))) | ||
| 3035 | (set-text-properties 0 (length name) nil name) | ||
| 3036 | (cond ((string-match "[:']" name) | ||
| 3037 | (setq meth t)) | ||
| 3038 | ((> p end-range) nil) | ||
| 3039 | (t | ||
| 3040 | (setq name (concat package name) meth t)))) | ||
| 3041 | (setcar index name) | ||
| 3042 | (if (eq fchar ?p) | ||
| 3043 | (push index index-pack-alist) | ||
| 3044 | (push index index-alist)) | ||
| 3045 | (if meth (push index index-meth-alist)) | ||
| 3046 | (push index index-unsorted-alist))) | ||
| 3047 | ((match-beginning 5) ; Pod section | ||
| 3048 | ;; (beginning-of-line) | ||
| 3049 | (setq index (imenu-example--name-and-position) | ||
| 3050 | name (buffer-substring (match-beginning 6) (match-end 6))) | ||
| 3051 | (set-text-properties 0 (length name) nil name) | ||
| 3052 | (if (eq (char-after (match-beginning 5)) ?2) | ||
| 3053 | (setq name (concat " " name))) | ||
| 3054 | (setcar index name) | ||
| 3055 | (setq index1 (cons (concat "=" name) (cdr index))) | ||
| 3056 | (push index index-pod-alist) | ||
| 3057 | (push index1 index-unsorted-alist))))) | ||
| 3058 | (or noninteractive | ||
| 3059 | (imenu-progress-message prev-pos 100)) | ||
| 3060 | (setq index-alist | ||
| 3061 | (if (default-value 'imenu-sort-function) | ||
| 3062 | (sort index-alist (default-value 'imenu-sort-function)) | ||
| 3063 | (nreverse index-alist))) | ||
| 3064 | (and index-pod-alist | ||
| 3065 | (push (cons "+POD headers+..." | ||
| 3066 | (nreverse index-pod-alist)) | ||
| 3067 | index-alist)) | ||
| 3068 | (and (or index-pack-alist index-meth-alist) | ||
| 3069 | (let ((lst index-pack-alist) hier-list pack elt group name) | ||
| 3070 | ;; Remove "package ", reverse and uniquify. | ||
| 3071 | (while lst | ||
| 3072 | (setq elt (car lst) lst (cdr lst) name (substring (car elt) 8)) | ||
| 3073 | (if (assoc name hier-list) nil | ||
| 3074 | (setq hier-list (cons (cons name (cdr elt)) hier-list)))) | ||
| 3075 | (setq lst index-meth-alist) | ||
| 3076 | (while lst | ||
| 3077 | (setq elt (car lst) lst (cdr lst)) | ||
| 3078 | (cond ((string-match "\\(::\\|'\\)[_a-zA-Z0-9]+$" (car elt)) | ||
| 3079 | (setq pack (substring (car elt) 0 (match-beginning 0))) | ||
| 3080 | (if (setq group (assoc pack hier-list)) | ||
| 3081 | (if (listp (cdr group)) | ||
| 3082 | ;; Have some functions already | ||
| 3083 | (setcdr group | ||
| 3084 | (cons (cons (substring | ||
| 3085 | (car elt) | ||
| 3086 | (+ 2 (match-beginning 0))) | ||
| 3087 | (cdr elt)) | ||
| 3088 | (cdr group))) | ||
| 3089 | (setcdr group (list (cons (substring | ||
| 3090 | (car elt) | ||
| 3091 | (+ 2 (match-beginning 0))) | ||
| 3092 | (cdr elt))))) | ||
| 3093 | (setq hier-list | ||
| 3094 | (cons (cons pack | ||
| 3095 | (list (cons (substring | ||
| 3096 | (car elt) | ||
| 3097 | (+ 2 (match-beginning 0))) | ||
| 3098 | (cdr elt)))) | ||
| 3099 | hier-list)))))) | ||
| 3100 | (push (cons "+Hierarchy+..." | ||
| 3101 | hier-list) | ||
| 3102 | index-alist))) | ||
| 3103 | (and index-pack-alist | ||
| 3104 | (push (cons "+Packages+..." | ||
| 3105 | (nreverse index-pack-alist)) | ||
| 3106 | index-alist)) | ||
| 3107 | (and (or index-pack-alist index-pod-alist | ||
| 3108 | (default-value 'imenu-sort-function)) | ||
| 3109 | index-unsorted-alist | ||
| 3110 | (push (cons "+Unsorted List+..." | ||
| 3111 | (nreverse index-unsorted-alist)) | ||
| 3112 | index-alist)) | ||
| 3113 | (cperl-imenu-addback index-alist))) | ||
| 3114 | |||
| 3115 | (defvar cperl-compilation-error-regexp-alist | ||
| 3116 | ;; This look like a paranoiac regexp: could anybody find a better one? (which WORK). | ||
| 3117 | '(("^[^\n]* \\(file\\|at\\) \\([^ \t\n]+\\) [^\n]*line \\([0-9]+\\)[\\., \n]" | ||
| 3118 | 2 3)) | ||
| 3119 | "Alist that specifies how to match errors in perl output.") | ||
| 3120 | |||
| 3121 | (if (fboundp 'eval-after-load) | ||
| 3122 | (eval-after-load | ||
| 3123 | "mode-compile" | ||
| 3124 | '(setq perl-compilation-error-regexp-alist | ||
| 3125 | cperl-compilation-error-regexp-alist))) | ||
| 3126 | |||
| 3127 | |||
| 3128 | (defvar cperl-faces-init nil) | ||
| 3129 | |||
| 3130 | (defun cperl-windowed-init () | ||
| 3131 | "Initialization under windowed version." | ||
| 3132 | (add-hook 'font-lock-mode-hook | ||
| 3133 | (function | ||
| 3134 | (lambda () | ||
| 3135 | (if (or | ||
| 3136 | (eq major-mode 'perl-mode) | ||
| 3137 | (eq major-mode 'cperl-mode)) | ||
| 3138 | (progn | ||
| 3139 | (or cperl-faces-init (cperl-init-faces)))))))) | ||
| 3140 | |||
| 3141 | (defvar perl-font-lock-keywords-1 nil | ||
| 3142 | "Additional expressions to highlight in Perl mode. Minimal set.") | ||
| 3143 | (defvar perl-font-lock-keywords nil | ||
| 3144 | "Additional expressions to highlight in Perl mode. Default set.") | ||
| 3145 | (defvar perl-font-lock-keywords-2 nil | ||
| 3146 | "Additional expressions to highlight in Perl mode. Maximal set") | ||
| 3147 | |||
| 3148 | (defun cperl-init-faces () | ||
| 3149 | (condition-case nil | ||
| 3150 | (progn | ||
| 3151 | (require 'font-lock) | ||
| 3152 | (and (fboundp 'font-lock-fontify-anchored-keywords) | ||
| 3153 | (featurep 'font-lock-extra) | ||
| 3154 | (message "You have an obsolete package `font-lock-extra'. Install `choose-color'.")) | ||
| 3155 | (let (t-font-lock-keywords t-font-lock-keywords-1 font-lock-anchored) | ||
| 3156 | ;;(defvar cperl-font-lock-enhanced nil | ||
| 3157 | ;; "Set to be non-nil if font-lock allows active highlights.") | ||
| 3158 | (if (fboundp 'font-lock-fontify-anchored-keywords) | ||
| 3159 | (setq font-lock-anchored t)) | ||
| 3160 | (setq | ||
| 3161 | t-font-lock-keywords | ||
| 3162 | (list | ||
| 3163 | (cons | ||
| 3164 | (concat | ||
| 3165 | "\\(^\\|[^$@%&\\]\\)\\<\\(" | ||
| 3166 | (mapconcat | ||
| 3167 | 'identity | ||
| 3168 | '("if" "until" "while" "elsif" "else" "unless" "for" | ||
| 3169 | "foreach" "continue" "exit" "die" "last" "goto" "next" | ||
| 3170 | "redo" "return" "local" "exec" "sub" "do" "dump" "use" | ||
| 3171 | "require" "package" "eval" "my" "BEGIN" "END") | ||
| 3172 | "\\|") ; Flow control | ||
| 3173 | "\\)\\>") 2) ; was "\\)[ \n\t;():,\|&]" | ||
| 3174 | ; In what follows we use `type' style | ||
| 3175 | ; for overwritable builtins | ||
| 3176 | (list | ||
| 3177 | (concat | ||
| 3178 | "\\(^\\|[^$@%&\\]\\)\\<\\(" | ||
| 3179 | ;; "CORE" "__FILE__" "__LINE__" "abs" "accept" "alarm" | ||
| 3180 | ;; "and" "atan2" "bind" "binmode" "bless" "caller" | ||
| 3181 | ;; "chdir" "chmod" "chown" "chr" "chroot" "close" | ||
| 3182 | ;; "closedir" "cmp" "connect" "continue" "cos" "crypt" | ||
| 3183 | ;; "dbmclose" "dbmopen" "die" "dump" "endgrent" | ||
| 3184 | ;; "endhostent" "endnetent" "endprotoent" "endpwent" | ||
| 3185 | ;; "endservent" "eof" "eq" "exec" "exit" "exp" "fcntl" | ||
| 3186 | ;; "fileno" "flock" "fork" "formline" "ge" "getc" | ||
| 3187 | ;; "getgrent" "getgrgid" "getgrnam" "gethostbyaddr" | ||
| 3188 | ;; "gethostbyname" "gethostent" "getlogin" | ||
| 3189 | ;; "getnetbyaddr" "getnetbyname" "getnetent" | ||
| 3190 | ;; "getpeername" "getpgrp" "getppid" "getpriority" | ||
| 3191 | ;; "getprotobyname" "getprotobynumber" "getprotoent" | ||
| 3192 | ;; "getpwent" "getpwnam" "getpwuid" "getservbyname" | ||
| 3193 | ;; "getservbyport" "getservent" "getsockname" | ||
| 3194 | ;; "getsockopt" "glob" "gmtime" "gt" "hex" "index" "int" | ||
| 3195 | ;; "ioctl" "join" "kill" "lc" "lcfirst" "le" "length" | ||
| 3196 | ;; "link" "listen" "localtime" "log" "lstat" "lt" | ||
| 3197 | ;; "mkdir" "msgctl" "msgget" "msgrcv" "msgsnd" "ne" | ||
| 3198 | ;; "not" "oct" "open" "opendir" "or" "ord" "pack" "pipe" | ||
| 3199 | ;; "quotemeta" "rand" "read" "readdir" "readline" | ||
| 3200 | ;; "readlink" "readpipe" "recv" "ref" "rename" "require" | ||
| 3201 | ;; "reset" "reverse" "rewinddir" "rindex" "rmdir" "seek" | ||
| 3202 | ;; "seekdir" "select" "semctl" "semget" "semop" "send" | ||
| 3203 | ;; "setgrent" "sethostent" "setnetent" "setpgrp" | ||
| 3204 | ;; "setpriority" "setprotoent" "setpwent" "setservent" | ||
| 3205 | ;; "setsockopt" "shmctl" "shmget" "shmread" "shmwrite" | ||
| 3206 | ;; "shutdown" "sin" "sleep" "socket" "socketpair" | ||
| 3207 | ;; "sprintf" "sqrt" "srand" "stat" "substr" "symlink" | ||
| 3208 | ;; "syscall" "sysread" "system" "syswrite" "tell" | ||
| 3209 | ;; "telldir" "time" "times" "truncate" "uc" "ucfirst" | ||
| 3210 | ;; "umask" "unlink" "unpack" "utime" "values" "vec" | ||
| 3211 | ;; "wait" "waitpid" "wantarray" "warn" "write" "x" "xor" | ||
| 3212 | "a\\(bs\\|ccept\\|tan2\\|larm\\|nd\\)\\|" | ||
| 3213 | "b\\(in\\(d\\|mode\\)\\|less\\)\\|" | ||
| 3214 | "c\\(h\\(r\\(\\|oot\\)\\|dir\\|mod\\|own\\)\\|aller\\|rypt\\|" | ||
| 3215 | "lose\\(\\|dir\\)\\|mp\\|o\\(s\\|n\\(tinue\\|nect\\)\\)\\)\\|" | ||
| 3216 | "CORE\\|d\\(ie\\|bm\\(close\\|open\\)\\|ump\\)\\|" | ||
| 3217 | "e\\(x\\(p\\|it\\|ec\\)\\|q\\|nd\\(p\\(rotoent\\|went\\)\\|" | ||
| 3218 | "hostent\\|servent\\|netent\\|grent\\)\\|of\\)\\|" | ||
| 3219 | "f\\(ileno\\|cntl\\|lock\\|or\\(k\\|mline\\)\\)\\|" | ||
| 3220 | "g\\(t\\|lob\\|mtime\\|e\\(\\|t\\(p\\(pid\\|r\\(iority\\|" | ||
| 3221 | "oto\\(byn\\(ame\\|umber\\)\\|ent\\)\\)\\|eername\\|w" | ||
| 3222 | "\\(uid\\|ent\\|nam\\)\\|grp\\)\\|host\\(by\\(addr\\|name\\)\\|" | ||
| 3223 | "ent\\)\\|s\\(erv\\(by\\(port\\|name\\)\\|ent\\)\\|" | ||
| 3224 | "ock\\(name\\|opt\\)\\)\\|c\\|login\\|net\\(by\\(addr\\|name\\)\\|" | ||
| 3225 | "ent\\)\\|gr\\(ent\\|nam\\|gid\\)\\)\\)\\)\\|" | ||
| 3226 | "hex\\|i\\(n\\(t\\|dex\\)\\|octl\\)\\|join\\|kill\\|" | ||
| 3227 | "l\\(i\\(sten\\|nk\\)\\|stat\\|c\\(\\|first\\)\\|t\\|e" | ||
| 3228 | "\\(\\|ngth\\)\\|o\\(caltime\\|g\\)\\)\\|m\\(sg\\(rcv\\|snd\\|" | ||
| 3229 | "ctl\\|get\\)\\|kdir\\)\\|n\\(e\\|ot\\)\\|o\\(pen\\(\\|dir\\)\\|" | ||
| 3230 | "r\\(\\|d\\)\\|ct\\)\\|p\\(ipe\\|ack\\)\\|quotemeta\\|" | ||
| 3231 | "r\\(index\\|and\\|mdir\\|e\\(quire\\|ad\\(pipe\\|\\|lin" | ||
| 3232 | "\\(k\\|e\\)\\|dir\\)\\|set\\|cv\\|verse\\|f\\|winddir\\|name" | ||
| 3233 | "\\)\\)\\|s\\(printf\\|qrt\\|rand\\|tat\\|ubstr\\|e\\(t\\(p\\(r" | ||
| 3234 | "\\(iority\\|otoent\\)\\|went\\|grp\\)\\|hostent\\|s\\(ervent\\|" | ||
| 3235 | "ockopt\\)\\|netent\\|grent\\)\\|ek\\(\\|dir\\)\\|lect\\|" | ||
| 3236 | "m\\(ctl\\|op\\|get\\)\\|nd\\)\\|h\\(utdown\\|m\\(read\\|ctl\\|" | ||
| 3237 | "write\\|get\\)\\)\\|y\\(s\\(read\\|call\\|tem\\|write\\)\\|" | ||
| 3238 | "mlink\\)\\|in\\|leep\\|ocket\\(pair\\|\\)\\)\\|t\\(runcate\\|" | ||
| 3239 | "ell\\(\\|dir\\)\\|ime\\(\\|s\\)\\)\\|u\\(c\\(\\|first\\)\\|" | ||
| 3240 | "time\\|mask\\|n\\(pack\\|link\\)\\)\\|v\\(alues\\|ec\\)\\|" | ||
| 3241 | "w\\(a\\(rn\\|it\\(pid\\|\\)\\|ntarray\\)\\|rite\\)\\|" | ||
| 3242 | "x\\(\\|or\\)\\|__\\(FILE__\\|LINE__\\|PACKAGE__\\)" | ||
| 3243 | "\\)\\>") 2 'font-lock-type-face) | ||
| 3244 | ;; In what follows we use `other' style | ||
| 3245 | ;; for nonoverwritable builtins | ||
| 3246 | ;; Somehow 's', 'm' are not auto-generated??? | ||
| 3247 | (list | ||
| 3248 | (concat | ||
| 3249 | "\\(^\\|[^$@%&\\]\\)\\<\\(" | ||
| 3250 | ;; "AUTOLOAD" "BEGIN" "DESTROY" "END" "__END__" "chomp" | ||
| 3251 | ;; "chop" "defined" "delete" "do" "each" "else" "elsif" | ||
| 3252 | ;; "eval" "exists" "for" "foreach" "format" "goto" | ||
| 3253 | ;; "grep" "if" "keys" "last" "local" "map" "my" "next" | ||
| 3254 | ;; "no" "package" "pop" "pos" "print" "printf" "push" | ||
| 3255 | ;; "q" "qq" "qw" "qx" "redo" "return" "scalar" "shift" | ||
| 3256 | ;; "sort" "splice" "split" "study" "sub" "tie" "tr" | ||
| 3257 | ;; "undef" "unless" "unshift" "untie" "until" "use" | ||
| 3258 | ;; "while" "y" | ||
| 3259 | "AUTOLOAD\\|BEGIN\\|cho\\(p\\|mp\\)\\|d\\(e\\(fined\\|lete\\)\\|" | ||
| 3260 | "o\\)\\|DESTROY\\|e\\(ach\\|val\\|xists\\|ls\\(e\\|if\\)\\)\\|" | ||
| 3261 | "END\\|for\\(\\|each\\|mat\\)\\|g\\(rep\\|oto\\)\\|if\\|keys\\|" | ||
| 3262 | "l\\(ast\\|ocal\\)\\|m\\(ap\\|y\\)\\|n\\(ext\\|o\\)\\|" | ||
| 3263 | "p\\(ackage\\|rint\\(\\|f\\)\\|ush\\|o\\(p\\|s\\)\\)\\|" | ||
| 3264 | "q\\(\\|q\\|w\\|x\\)\\|re\\(turn\\|do\\)\\|s\\(pli\\(ce\\|t\\)\\|" | ||
| 3265 | "calar\\|tudy\\|ub\\|hift\\|ort\\)\\|t\\(r\\|ie\\)\\|" | ||
| 3266 | "u\\(se\\|n\\(shift\\|ti\\(l\\|e\\)\\|def\\|less\\)\\)\\|" | ||
| 3267 | "while\\|y\\|__\\(END\\|DATA\\)__" ;__DATA__ added manually | ||
| 3268 | "\\|[sm]" ; Added manually | ||
| 3269 | "\\)\\>") 2 'font-lock-other-type-face) | ||
| 3270 | ;; (mapconcat 'identity | ||
| 3271 | ;; '("#endif" "#else" "#ifdef" "#ifndef" "#if" | ||
| 3272 | ;; "#include" "#define" "#undef") | ||
| 3273 | ;; "\\|") | ||
| 3274 | '("-[rwxoRWXOezsfdlpSbctugkTBMAC]\\>\\([ \t]+_\\>\\)?" 0 | ||
| 3275 | font-lock-function-name-face keep) ; Not very good, triggers at "[a-z]" | ||
| 3276 | '("\\<sub[ \t]+\\([^ \t{;]+\\)[ \t]*\\(([^()]*)[ \t]*\\)?[#{\n]" 1 | ||
| 3277 | font-lock-function-name-face) | ||
| 3278 | '("\\<\\(package\\|require\\|use\\|import\\|no\\|bootstrap\\)[ \t]+\\([a-zA-z_][a-zA-z_0-9:]*\\)[ \t;]" ; require A if B; | ||
| 3279 | 2 font-lock-function-name-face) | ||
| 3280 | '("^[ \t]*format[ \t]+\\([a-zA-z_][a-zA-z_0-9:]*\\)[ \t]*=[ \t]*$" | ||
| 3281 | 1 font-lock-function-name-face) | ||
| 3282 | (cond ((featurep 'font-lock-extra) | ||
| 3283 | '("\\([]}\\\\%@>*&]\\|\\$[a-zA-Z0-9_:]*\\)[ \t]*{[ \t]*\\(-?[a-zA-Z0-9_:]+\\)[ \t]*}" | ||
| 3284 | (2 font-lock-string-face t) | ||
| 3285 | (0 '(restart 2 t)))) ; To highlight $a{bc}{ef} | ||
| 3286 | (font-lock-anchored | ||
| 3287 | '("\\([]}\\\\%@>*&]\\|\\$[a-zA-Z0-9_:]*\\)[ \t]*{[ \t]*\\(-?[a-zA-Z0-9_:]+\\)[ \t]*}" | ||
| 3288 | (2 font-lock-string-face t) | ||
| 3289 | ("\\=[ \t]*{[ \t]*\\(-?[a-zA-Z0-9_:]+\\)[ \t]*}" | ||
| 3290 | nil nil | ||
| 3291 | (1 font-lock-string-face t)))) | ||
| 3292 | (t '("\\([]}\\\\%@>*&]\\|\\$[a-zA-Z0-9_:]*\\)[ \t]*{[ \t]*\\(-?[a-zA-Z0-9_:]+\\)[ \t]*}" | ||
| 3293 | 2 font-lock-string-face t))) | ||
| 3294 | '("[ \t{,(]\\(-?[a-zA-Z0-9_:]+\\)[ \t]*=>" 1 | ||
| 3295 | font-lock-string-face t) | ||
| 3296 | '("^[ \t]*\\([a-zA-Z0-9_]+[ \t]*:\\)[ \t]*\\($\\|{\\|\\<\\(until\\|while\\|for\\(each\\)?\\|do\\)\\>\\)" 1 | ||
| 3297 | font-lock-reference-face) ; labels | ||
| 3298 | '("\\<\\(continue\\|next\\|last\\|redo\\|goto\\)\\>[ \t]+\\([a-zA-Z0-9_:]+\\)" ; labels as targets | ||
| 3299 | 2 font-lock-reference-face) | ||
| 3300 | (cond ((featurep 'font-lock-extra) | ||
| 3301 | '("^[ \t]*\\(my\\|local\\)[ \t]*\\(([ \t]*\\)?\\([$@%*][a-zA-Z0-9_:]+\\)\\([ \t]*,\\)?" | ||
| 3302 | (3 font-lock-variable-name-face) | ||
| 3303 | (4 '(another 4 nil | ||
| 3304 | ("\\=[ \t]*,[ \t]*\\([$@%*][a-zA-Z0-9_:]+\\)\\([ \t]*,\\)?" | ||
| 3305 | (1 font-lock-variable-name-face) | ||
| 3306 | (2 '(restart 2 nil) nil t))) | ||
| 3307 | nil t))) ; local variables, multiple | ||
| 3308 | (font-lock-anchored | ||
| 3309 | '("^[ \t{}]*\\(my\\|local\\)[ \t]*\\(([ \t]*\\)?\\([$@%*][a-zA-Z0-9_:]+\\)" | ||
| 3310 | (3 font-lock-variable-name-face) | ||
| 3311 | ("\\=[ \t]*,[ \t]*\\([$@%*][a-zA-Z0-9_:]+\\)" | ||
| 3312 | nil nil | ||
| 3313 | (1 font-lock-variable-name-face)))) | ||
| 3314 | (t '("^[ \t{}]*\\(my\\|local\\)[ \t]*\\(([ \t]*\\)?\\([$@%*][a-zA-Z0-9_:]+\\)" | ||
| 3315 | 3 font-lock-variable-name-face))) | ||
| 3316 | '("\\<for\\(each\\)?[ \t]*\\(\\$[a-zA-Z_][a-zA-Z_0-9]*\\)[ \t]*(" | ||
| 3317 | 2 font-lock-variable-name-face))) | ||
| 3318 | (setq | ||
| 3319 | t-font-lock-keywords-1 | ||
| 3320 | (and (fboundp 'turn-on-font-lock) ; Check for newer font-lock | ||
| 3321 | (not cperl-xemacs-p) ; not yet as of XEmacs 19.12 | ||
| 3322 | '( | ||
| 3323 | ("\\(\\([@%]\\|\$#\\)[a-zA-Z_:][a-zA-Z0-9_:]*\\)" 1 | ||
| 3324 | (if (eq (char-after (match-beginning 2)) ?%) | ||
| 3325 | font-lock-other-emphasized-face | ||
| 3326 | font-lock-emphasized-face) | ||
| 3327 | t) ; arrays and hashes | ||
| 3328 | ("\\(\\([$@]+\\)[a-zA-Z_:][a-zA-Z0-9_:]*\\)[ \t]*\\([[{]\\)" | ||
| 3329 | 1 | ||
| 3330 | (if (= (- (match-end 2) (match-beginning 2)) 1) | ||
| 3331 | (if (eq (char-after (match-beginning 3)) ?{) | ||
| 3332 | font-lock-other-emphasized-face | ||
| 3333 | font-lock-emphasized-face) ; arrays and hashes | ||
| 3334 | font-lock-variable-name-face) ; Just to put something | ||
| 3335 | t) | ||
| 3336 | ;;("\\([smy]\\|tr\\)\\([^a-z_A-Z0-9]\\)\\(\\([^\n\\]*||\\)\\)\\2") | ||
| 3337 | ;;; Too much noise from \s* @s[ and friends | ||
| 3338 | ;;("\\(\\<\\([msy]\\|tr\\)[ \t]*\\([^ \t\na-zA-Z0-9_]\\)\\|\\(/\\)\\)" | ||
| 3339 | ;;(3 font-lock-function-name-face t t) | ||
| 3340 | ;;(4 | ||
| 3341 | ;; (if (cperl-slash-is-regexp) | ||
| 3342 | ;; font-lock-function-name-face 'default) nil t)) | ||
| 3343 | ))) | ||
| 3344 | (setq perl-font-lock-keywords-1 t-font-lock-keywords | ||
| 3345 | perl-font-lock-keywords perl-font-lock-keywords-1 | ||
| 3346 | perl-font-lock-keywords-2 (append | ||
| 3347 | t-font-lock-keywords | ||
| 3348 | t-font-lock-keywords-1))) | ||
| 3349 | (if (fboundp 'ps-print-buffer) (cperl-ps-print-init)) | ||
| 3350 | (if (or (featurep 'choose-color) (featurep 'font-lock-extra)) | ||
| 3351 | (font-lock-require-faces | ||
| 3352 | (list | ||
| 3353 | ;; Color-light Color-dark Gray-light Gray-dark Mono | ||
| 3354 | (list 'font-lock-comment-face | ||
| 3355 | ["Firebrick" "OrangeRed" "DimGray" "Gray80"] | ||
| 3356 | nil | ||
| 3357 | [nil nil t t t] | ||
| 3358 | [nil nil t t t] | ||
| 3359 | nil) | ||
| 3360 | (list 'font-lock-string-face | ||
| 3361 | ["RosyBrown" "LightSalmon" "Gray50" "LightGray"] | ||
| 3362 | nil | ||
| 3363 | nil | ||
| 3364 | [nil nil t t t] | ||
| 3365 | nil) | ||
| 3366 | (list 'font-lock-keyword-face | ||
| 3367 | ["Purple" "LightSteelBlue" "DimGray" "Gray90"] | ||
| 3368 | nil | ||
| 3369 | [nil nil t t t] | ||
| 3370 | nil | ||
| 3371 | nil) | ||
| 3372 | (list 'font-lock-function-name-face | ||
| 3373 | (vector | ||
| 3374 | "Blue" "LightSkyBlue" "Gray50" "LightGray" | ||
| 3375 | (cdr (assq 'background-color ; if mono | ||
| 3376 | (frame-parameters)))) | ||
| 3377 | (vector | ||
| 3378 | nil nil nil nil | ||
| 3379 | (cdr (assq 'foreground-color ; if mono | ||
| 3380 | (frame-parameters)))) | ||
| 3381 | [nil nil t t t] | ||
| 3382 | nil | ||
| 3383 | nil) | ||
| 3384 | (list 'font-lock-variable-name-face | ||
| 3385 | ["DarkGoldenrod" "LightGoldenrod" "DimGray" "Gray90"] | ||
| 3386 | nil | ||
| 3387 | [nil nil t t t] | ||
| 3388 | [nil nil t t t] | ||
| 3389 | nil) | ||
| 3390 | (list 'font-lock-type-face | ||
| 3391 | ["DarkOliveGreen" "PaleGreen" "DimGray" "Gray80"] | ||
| 3392 | nil | ||
| 3393 | [nil nil t t t] | ||
| 3394 | nil | ||
| 3395 | [nil nil t t t] | ||
| 3396 | ) | ||
| 3397 | (list 'font-lock-reference-face | ||
| 3398 | ["CadetBlue" "Aquamarine" "Gray50" "LightGray"] | ||
| 3399 | nil | ||
| 3400 | [nil nil t t t] | ||
| 3401 | nil | ||
| 3402 | [nil nil t t t] | ||
| 3403 | ) | ||
| 3404 | (list 'font-lock-other-type-face | ||
| 3405 | ["chartreuse3" ("orchid1" "orange") | ||
| 3406 | nil "Gray80"] | ||
| 3407 | [nil nil "gray90"] | ||
| 3408 | [nil nil nil t t] | ||
| 3409 | [nil nil t t] | ||
| 3410 | [nil nil t t t] | ||
| 3411 | ) | ||
| 3412 | (list 'font-lock-emphasized-face | ||
| 3413 | ["blue" "yellow" nil "Gray80"] | ||
| 3414 | ["lightyellow2" ("navy" "os2blue" "darkgreen") | ||
| 3415 | "gray90"] | ||
| 3416 | t | ||
| 3417 | nil | ||
| 3418 | nil) | ||
| 3419 | (list 'font-lock-other-emphasized-face | ||
| 3420 | ["red" "red" nil "Gray80"] | ||
| 3421 | ["lightyellow2" ("navy" "os2blue" "darkgreen") | ||
| 3422 | "gray90"] | ||
| 3423 | t | ||
| 3424 | t | ||
| 3425 | nil))) | ||
| 3426 | (defvar cperl-guessed-background nil | ||
| 3427 | "Display characteristics as guessed by cperl.") | ||
| 3428 | (or (fboundp 'x-color-defined-p) | ||
| 3429 | (defalias 'x-color-defined-p | ||
| 3430 | (cond ((fboundp 'color-defined-p) 'color-defined-p) | ||
| 3431 | ;; XEmacs >= 19.12 | ||
| 3432 | ((fboundp 'valid-color-name-p) 'valid-color-name-p) | ||
| 3433 | ;; XEmacs 19.11 | ||
| 3434 | (t 'x-valid-color-name-p)))) | ||
| 3435 | (defvar font-lock-reference-face 'font-lock-reference-face) | ||
| 3436 | (defvar font-lock-variable-name-face 'font-lock-variable-name-face) | ||
| 3437 | (or (boundp 'font-lock-type-face) | ||
| 3438 | (defconst font-lock-type-face | ||
| 3439 | 'font-lock-type-face | ||
| 3440 | "Face to use for data types.") | ||
| 3441 | ) | ||
| 3442 | (or (boundp 'font-lock-other-type-face) | ||
| 3443 | (defconst font-lock-other-type-face | ||
| 3444 | 'font-lock-other-type-face | ||
| 3445 | "Face to use for data types from another group.") | ||
| 3446 | ) | ||
| 3447 | (if (not cperl-xemacs-p) nil | ||
| 3448 | (or (boundp 'font-lock-comment-face) | ||
| 3449 | (defconst font-lock-comment-face | ||
| 3450 | 'font-lock-comment-face | ||
| 3451 | "Face to use for comments.") | ||
| 3452 | ) | ||
| 3453 | (or (boundp 'font-lock-keyword-face) | ||
| 3454 | (defconst font-lock-keyword-face | ||
| 3455 | 'font-lock-keyword-face | ||
| 3456 | "Face to use for keywords.") | ||
| 3457 | ) | ||
| 3458 | (or (boundp 'font-lock-function-name-face) | ||
| 3459 | (defconst font-lock-function-name-face | ||
| 3460 | 'font-lock-function-name-face | ||
| 3461 | "Face to use for function names.") | ||
| 3462 | ) | ||
| 3463 | ) | ||
| 3464 | ;;(if (featurep 'font-lock) | ||
| 3465 | (if (face-equal font-lock-type-face font-lock-comment-face) | ||
| 3466 | (defconst font-lock-type-face | ||
| 3467 | 'font-lock-type-face | ||
| 3468 | "Face to use for basic data types.") | ||
| 3469 | ) | ||
| 3470 | ;;; (if (fboundp 'eval-after-load) | ||
| 3471 | ;;; (eval-after-load "font-lock" | ||
| 3472 | ;;; '(if (face-equal font-lock-type-face | ||
| 3473 | ;;; font-lock-comment-face) | ||
| 3474 | ;;; (defconst font-lock-type-face | ||
| 3475 | ;;; 'font-lock-type-face | ||
| 3476 | ;;; "Face to use for basic data types.") | ||
| 3477 | ;;; ))) ; This does not work :-( Why?! | ||
| 3478 | ;;; ; Workaround: added to font-lock-m-h | ||
| 3479 | ;;; ) | ||
| 3480 | (or (boundp 'font-lock-other-emphasized-face) | ||
| 3481 | (defconst font-lock-other-emphasized-face | ||
| 3482 | 'font-lock-other-emphasized-face | ||
| 3483 | "Face to use for another type of emphasizing.") | ||
| 3484 | ) | ||
| 3485 | (or (boundp 'font-lock-emphasized-face) | ||
| 3486 | (defconst font-lock-emphasized-face | ||
| 3487 | 'font-lock-emphasized-face | ||
| 3488 | "Face to use for emphasizing.") | ||
| 3489 | ) | ||
| 3490 | ;; Here we try to guess background | ||
| 3491 | (let ((background | ||
| 3492 | (if (boundp 'font-lock-background-mode) | ||
| 3493 | font-lock-background-mode | ||
| 3494 | 'light)) | ||
| 3495 | (face-list (and (fboundp 'face-list) (face-list))) | ||
| 3496 | is-face) | ||
| 3497 | (fset 'is-face | ||
| 3498 | (cond ((fboundp 'find-face) | ||
| 3499 | (symbol-function 'find-face)) | ||
| 3500 | (face-list | ||
| 3501 | (function (lambda (face) (member face face-list)))) | ||
| 3502 | (t | ||
| 3503 | (function (lambda (face) (boundp face)))))) | ||
| 3504 | (defvar cperl-guessed-background | ||
| 3505 | (if (and (boundp 'font-lock-display-type) | ||
| 3506 | (eq font-lock-display-type 'grayscale)) | ||
| 3507 | 'gray | ||
| 3508 | background) | ||
| 3509 | "Background as guessed by CPerl mode") | ||
| 3510 | (if (is-face 'font-lock-type-face) nil | ||
| 3511 | (copy-face 'default 'font-lock-type-face) | ||
| 3512 | (cond | ||
| 3513 | ((eq background 'light) | ||
| 3514 | (set-face-foreground 'font-lock-type-face | ||
| 3515 | (if (x-color-defined-p "seagreen") | ||
| 3516 | "seagreen" | ||
| 3517 | "sea green"))) | ||
| 3518 | ((eq background 'dark) | ||
| 3519 | (set-face-foreground 'font-lock-type-face | ||
| 3520 | (if (x-color-defined-p "os2pink") | ||
| 3521 | "os2pink" | ||
| 3522 | "pink"))) | ||
| 3523 | (t | ||
| 3524 | (set-face-background 'font-lock-type-face "gray90")))) | ||
| 3525 | (if (is-face 'font-lock-other-type-face) | ||
| 3526 | nil | ||
| 3527 | (copy-face 'font-lock-type-face 'font-lock-other-type-face) | ||
| 3528 | (cond | ||
| 3529 | ((eq background 'light) | ||
| 3530 | (set-face-foreground 'font-lock-other-type-face | ||
| 3531 | (if (x-color-defined-p "chartreuse3") | ||
| 3532 | "chartreuse3" | ||
| 3533 | "chartreuse"))) | ||
| 3534 | ((eq background 'dark) | ||
| 3535 | (set-face-foreground 'font-lock-other-type-face | ||
| 3536 | (if (x-color-defined-p "orchid1") | ||
| 3537 | "orchid1" | ||
| 3538 | "orange"))))) | ||
| 3539 | (if (is-face 'font-lock-other-emphasized-face) nil | ||
| 3540 | (copy-face 'bold-italic 'font-lock-other-emphasized-face) | ||
| 3541 | (cond | ||
| 3542 | ((eq background 'light) | ||
| 3543 | (set-face-background 'font-lock-other-emphasized-face | ||
| 3544 | (if (x-color-defined-p "lightyellow2") | ||
| 3545 | "lightyellow2" | ||
| 3546 | (if (x-color-defined-p "lightyellow") | ||
| 3547 | "lightyellow" | ||
| 3548 | "light yellow")))) | ||
| 3549 | ((eq background 'dark) | ||
| 3550 | (set-face-background 'font-lock-other-emphasized-face | ||
| 3551 | (if (x-color-defined-p "navy") | ||
| 3552 | "navy" | ||
| 3553 | (if (x-color-defined-p "darkgreen") | ||
| 3554 | "darkgreen" | ||
| 3555 | "dark green")))) | ||
| 3556 | (t (set-face-background 'font-lock-other-emphasized-face "gray90")))) | ||
| 3557 | (if (is-face 'font-lock-emphasized-face) nil | ||
| 3558 | (copy-face 'bold 'font-lock-emphasized-face) | ||
| 3559 | (cond | ||
| 3560 | ((eq background 'light) | ||
| 3561 | (set-face-background 'font-lock-emphasized-face | ||
| 3562 | (if (x-color-defined-p "lightyellow2") | ||
| 3563 | "lightyellow2" | ||
| 3564 | "lightyellow"))) | ||
| 3565 | ((eq background 'dark) | ||
| 3566 | (set-face-background 'font-lock-emphasized-face | ||
| 3567 | (if (x-color-defined-p "navy") | ||
| 3568 | "navy" | ||
| 3569 | (if (x-color-defined-p "darkgreen") | ||
| 3570 | "darkgreen" | ||
| 3571 | "dark green")))) | ||
| 3572 | (t (set-face-background 'font-lock-emphasized-face "gray90")))) | ||
| 3573 | (if (is-face 'font-lock-variable-name-face) nil | ||
| 3574 | (copy-face 'italic 'font-lock-variable-name-face)) | ||
| 3575 | (if (is-face 'font-lock-reference-face) nil | ||
| 3576 | (copy-face 'italic 'font-lock-reference-face)))) | ||
| 3577 | (setq cperl-faces-init t)) | ||
| 3578 | (error nil))) | ||
| 3579 | |||
| 3580 | |||
| 3581 | (defun cperl-ps-print-init () | ||
| 3582 | "Initialization of `ps-print' components for faces used in CPerl." | ||
| 3583 | ;; Guard against old versions | ||
| 3584 | (defvar ps-underlined-faces nil) | ||
| 3585 | (defvar ps-bold-faces nil) | ||
| 3586 | (defvar ps-italic-faces nil) | ||
| 3587 | (setq ps-bold-faces | ||
| 3588 | (append '(font-lock-emphasized-face | ||
| 3589 | font-lock-keyword-face | ||
| 3590 | font-lock-variable-name-face | ||
| 3591 | font-lock-reference-face | ||
| 3592 | font-lock-other-emphasized-face) | ||
| 3593 | ps-bold-faces)) | ||
| 3594 | (setq ps-italic-faces | ||
| 3595 | (append '(font-lock-other-type-face | ||
| 3596 | font-lock-reference-face | ||
| 3597 | font-lock-other-emphasized-face) | ||
| 3598 | ps-italic-faces)) | ||
| 3599 | (setq ps-underlined-faces | ||
| 3600 | (append '(font-lock-emphasized-face | ||
| 3601 | font-lock-other-emphasized-face | ||
| 3602 | font-lock-other-type-face font-lock-type-face) | ||
| 3603 | ps-underlined-faces)) | ||
| 3604 | (cons 'font-lock-type-face ps-underlined-faces)) | ||
| 3605 | |||
| 3606 | |||
| 3607 | (if (cperl-enable-font-lock) (cperl-windowed-init)) | ||
| 3608 | |||
| 3609 | (defun cperl-set-style (style) | ||
| 3610 | "Set CPerl-mode variables to use one of several different indentation styles. | ||
| 3611 | The arguments are a string representing the desired style. | ||
| 3612 | Available styles are GNU, K&R, BSD and Whitesmith." | ||
| 3613 | (interactive | ||
| 3614 | (let ((list (mapcar (function (lambda (elt) (list (car elt)))) | ||
| 3615 | c-style-alist))) | ||
| 3616 | (list (completing-read "Enter style: " list nil 'insist)))) | ||
| 3617 | (let ((style (cdr (assoc style c-style-alist))) setting str sym) | ||
| 3618 | (while style | ||
| 3619 | (setq setting (car style) style (cdr style)) | ||
| 3620 | (setq str (symbol-name (car setting))) | ||
| 3621 | (and (string-match "^c-" str) | ||
| 3622 | (setq str (concat "cperl-" (substring str 2))) | ||
| 3623 | (setq sym (intern-soft str)) | ||
| 3624 | (boundp sym) | ||
| 3625 | (set sym (cdr setting)))))) | ||
| 3626 | |||
| 3627 | (defun cperl-check-syntax () | ||
| 3628 | (interactive) | ||
| 3629 | (require 'mode-compile) | ||
| 3630 | (let ((perl-dbg-flags "-wc")) | ||
| 3631 | (mode-compile))) | ||
| 3632 | |||
| 3633 | (defun cperl-info-buffer (type) | ||
| 3634 | ;; Returns buffer with documentation. Creates if missing. | ||
| 3635 | ;; If TYPE, this vars buffer. | ||
| 3636 | ;; Special care is taken to not stomp over an existing info buffer | ||
| 3637 | (let* ((bname (if type "*info-perl-var*" "*info-perl*")) | ||
| 3638 | (info (get-buffer bname)) | ||
| 3639 | (oldbuf (get-buffer "*info*"))) | ||
| 3640 | (if info info | ||
| 3641 | (save-window-excursion | ||
| 3642 | ;; Get Info running | ||
| 3643 | (require 'info) | ||
| 3644 | (cond (oldbuf | ||
| 3645 | (set-buffer oldbuf) | ||
| 3646 | (rename-buffer "*info-perl-tmp*"))) | ||
| 3647 | (save-window-excursion | ||
| 3648 | (info)) | ||
| 3649 | (Info-find-node cperl-info-page (if type "perlvar" "perlfunc")) | ||
| 3650 | (set-buffer "*info*") | ||
| 3651 | (rename-buffer bname) | ||
| 3652 | (cond (oldbuf | ||
| 3653 | (set-buffer "*info-perl-tmp*") | ||
| 3654 | (rename-buffer "*info*") | ||
| 3655 | (set-buffer bname))) | ||
| 3656 | (make-variable-buffer-local 'window-min-height) | ||
| 3657 | (setq window-min-height 2) | ||
| 3658 | (current-buffer))))) | ||
| 3659 | |||
| 3660 | (defun cperl-word-at-point (&optional p) | ||
| 3661 | ;; Returns the word at point or at P. | ||
| 3662 | (save-excursion | ||
| 3663 | (if p (goto-char p)) | ||
| 3664 | (or (cperl-word-at-point-hard) | ||
| 3665 | (progn | ||
| 3666 | (require 'etags) | ||
| 3667 | (funcall (or (and (boundp 'find-tag-default-function) | ||
| 3668 | find-tag-default-function) | ||
| 3669 | (get major-mode 'find-tag-default-function) | ||
| 3670 | ;; XEmacs 19.12 has `find-tag-default-hook'; it is | ||
| 3671 | ;; automatically used within `find-tag-default': | ||
| 3672 | 'find-tag-default)))))) | ||
| 3673 | |||
| 3674 | (defun cperl-info-on-command (command) | ||
| 3675 | "Shows documentation for Perl command in other window. | ||
| 3676 | If perl-info buffer is shown in some frame, uses this frame. | ||
| 3677 | Customized by setting variables `cperl-shrink-wrap-info-frame', | ||
| 3678 | `cperl-max-help-size'." | ||
| 3679 | (interactive | ||
| 3680 | (let* ((default (cperl-word-at-point)) | ||
| 3681 | (read (read-string | ||
| 3682 | (format "Find doc for Perl function (default %s): " | ||
| 3683 | default)))) | ||
| 3684 | (list (if (equal read "") | ||
| 3685 | default | ||
| 3686 | read)))) | ||
| 3687 | |||
| 3688 | (let ((buffer (current-buffer)) | ||
| 3689 | (cmd-desc (concat "^" (regexp-quote command) "[^a-zA-Z_0-9]")) ; "tr///" | ||
| 3690 | pos isvar height iniheight frheight buf win fr1 fr2 iniwin not-loner | ||
| 3691 | max-height char-height buf-list) | ||
| 3692 | (if (string-match "^-[a-zA-Z]$" command) | ||
| 3693 | (setq cmd-desc "^-X[ \t\n]")) | ||
| 3694 | (setq isvar (string-match "^[$@%]" command) | ||
| 3695 | buf (cperl-info-buffer isvar) | ||
| 3696 | iniwin (selected-window) | ||
| 3697 | fr1 (window-frame iniwin)) | ||
| 3698 | (set-buffer buf) | ||
| 3699 | (beginning-of-buffer) | ||
| 3700 | (or isvar | ||
| 3701 | (progn (re-search-forward "^-X[ \t\n]") | ||
| 3702 | (forward-line -1))) | ||
| 3703 | (if (re-search-forward cmd-desc nil t) | ||
| 3704 | (progn | ||
| 3705 | ;; Go back to beginning of the group (ex, for qq) | ||
| 3706 | (if (re-search-backward "^[ \t\n\f]") | ||
| 3707 | (forward-line 1)) | ||
| 3708 | (beginning-of-line) | ||
| 3709 | ;; Get some of | ||
| 3710 | (setq pos (point) | ||
| 3711 | buf-list (list buf "*info-perl-var*" "*info-perl*")) | ||
| 3712 | (while (and (not win) buf-list) | ||
| 3713 | (setq win (get-buffer-window (car buf-list) t)) | ||
| 3714 | (setq buf-list (cdr buf-list))) | ||
| 3715 | (or (not win) | ||
| 3716 | (eq (window-buffer win) buf) | ||
| 3717 | (set-window-buffer win buf)) | ||
| 3718 | (and win (setq fr2 (window-frame win))) | ||
| 3719 | (if (or (not fr2) (eq fr1 fr2)) | ||
| 3720 | (pop-to-buffer buf) | ||
| 3721 | (special-display-popup-frame buf) ; Make it visible | ||
| 3722 | (select-window win)) | ||
| 3723 | (goto-char pos) ; Needed (?!). | ||
| 3724 | ;; Resize | ||
| 3725 | (setq iniheight (window-height) | ||
| 3726 | frheight (frame-height) | ||
| 3727 | not-loner (< iniheight (1- frheight))) ; Are not alone | ||
| 3728 | (cond ((if not-loner cperl-max-help-size | ||
| 3729 | cperl-shrink-wrap-info-frame) | ||
| 3730 | (setq height | ||
| 3731 | (+ 2 | ||
| 3732 | (count-lines | ||
| 3733 | pos | ||
| 3734 | (save-excursion | ||
| 3735 | (if (re-search-forward | ||
| 3736 | "^[ \t][^\n]*\n+\\([^ \t\n\f]\\|\\'\\)" nil t) | ||
| 3737 | (match-beginning 0) (point-max))))) | ||
| 3738 | max-height | ||
| 3739 | (if not-loner | ||
| 3740 | (/ (* (- frheight 3) cperl-max-help-size) 100) | ||
| 3741 | (setq char-height (frame-char-height)) | ||
| 3742 | ;; Non-functioning under OS/2: | ||
| 3743 | (if (eq char-height 1) (setq char-height 18)) | ||
| 3744 | ;; Title, menubar, + 2 for slack | ||
| 3745 | (- (/ (x-display-pixel-height) char-height) 4) | ||
| 3746 | )) | ||
| 3747 | (if (> height max-height) (setq height max-height)) | ||
| 3748 | ;;(message "was %s doing %s" iniheight height) | ||
| 3749 | (if not-loner | ||
| 3750 | (enlarge-window (- height iniheight)) | ||
| 3751 | (set-frame-height (window-frame win) (1+ height))))) | ||
| 3752 | (set-window-start (selected-window) pos)) | ||
| 3753 | (message "No entry for %s found." command)) | ||
| 3754 | ;;(pop-to-buffer buffer) | ||
| 3755 | (select-window iniwin))) | ||
| 3756 | |||
| 3757 | (defun cperl-info-on-current-command () | ||
| 3758 | "Shows documentation for Perl command at point in other window." | ||
| 3759 | (interactive) | ||
| 3760 | (cperl-info-on-command (cperl-word-at-point))) | ||
| 3761 | |||
| 3762 | (defun cperl-imenu-info-imenu-search () | ||
| 3763 | (if (looking-at "^-X[ \t\n]") nil | ||
| 3764 | (re-search-backward | ||
| 3765 | "^\n\\([-a-zA-Z_]+\\)[ \t\n]") | ||
| 3766 | (forward-line 1))) | ||
| 3767 | |||
| 3768 | (defun cperl-imenu-info-imenu-name () | ||
| 3769 | (buffer-substring | ||
| 3770 | (match-beginning 1) (match-end 1))) | ||
| 3771 | |||
| 3772 | (defun cperl-imenu-on-info () | ||
| 3773 | (interactive) | ||
| 3774 | (let* ((buffer (current-buffer)) | ||
| 3775 | imenu-create-index-function | ||
| 3776 | imenu-prev-index-position-function | ||
| 3777 | imenu-extract-index-name-function | ||
| 3778 | (index-item (save-restriction | ||
| 3779 | (save-window-excursion | ||
| 3780 | (set-buffer (cperl-info-buffer nil)) | ||
| 3781 | (setq imenu-create-index-function | ||
| 3782 | 'imenu-default-create-index-function | ||
| 3783 | imenu-prev-index-position-function | ||
| 3784 | 'cperl-imenu-info-imenu-search | ||
| 3785 | imenu-extract-index-name-function | ||
| 3786 | 'cperl-imenu-info-imenu-name) | ||
| 3787 | (imenu-choose-buffer-index))))) | ||
| 3788 | (and index-item | ||
| 3789 | (progn | ||
| 3790 | (push-mark) | ||
| 3791 | (pop-to-buffer "*info-perl*") | ||
| 3792 | (cond | ||
| 3793 | ((markerp (cdr index-item)) | ||
| 3794 | (goto-char (marker-position (cdr index-item)))) | ||
| 3795 | (t | ||
| 3796 | (goto-char (cdr index-item)))) | ||
| 3797 | (set-window-start (selected-window) (point)) | ||
| 3798 | (pop-to-buffer buffer))))) | ||
| 3799 | |||
| 3800 | (defun cperl-lineup (beg end &optional step minshift) | ||
| 3801 | "Lineup construction in a region. | ||
| 3802 | Beginning of region should be at the start of a construction. | ||
| 3803 | All first occurrences of this construction in the lines that are | ||
| 3804 | partially contained in the region are lined up at the same column. | ||
| 3805 | |||
| 3806 | MINSHIFT is the minimal amount of space to insert before the construction. | ||
| 3807 | STEP is the tabwidth to position constructions. | ||
| 3808 | If STEP is `nil', `cperl-lineup-step' will be used | ||
| 3809 | \(or `cperl-indent-level', if `cperl-lineup-step' is `nil'). | ||
| 3810 | Will not move the position at the start to the left." | ||
| 3811 | (interactive "r") | ||
| 3812 | (let (search col tcol seen b e) | ||
| 3813 | (save-excursion | ||
| 3814 | (goto-char end) | ||
| 3815 | (end-of-line) | ||
| 3816 | (setq end (point-marker)) | ||
| 3817 | (goto-char beg) | ||
| 3818 | (skip-chars-forward " \t\f") | ||
| 3819 | (setq beg (point-marker)) | ||
| 3820 | (indent-region beg end nil) | ||
| 3821 | (goto-char beg) | ||
| 3822 | (setq col (current-column)) | ||
| 3823 | (if (looking-at "[a-zA-Z0-9_]") | ||
| 3824 | (if (looking-at "\\<[a-zA-Z0-9_]+\\>") | ||
| 3825 | (setq search | ||
| 3826 | (concat "\\<" | ||
| 3827 | (regexp-quote | ||
| 3828 | (buffer-substring (match-beginning 0) | ||
| 3829 | (match-end 0))) "\\>")) | ||
| 3830 | (error "Cannot line up in a middle of the word")) | ||
| 3831 | (if (looking-at "$") | ||
| 3832 | (error "Cannot line up end of line")) | ||
| 3833 | (setq search (regexp-quote (char-to-string (following-char))))) | ||
| 3834 | (setq step (or step cperl-lineup-step cperl-indent-level)) | ||
| 3835 | (or minshift (setq minshift 1)) | ||
| 3836 | (while (progn | ||
| 3837 | (beginning-of-line 2) | ||
| 3838 | (and (< (point) end) | ||
| 3839 | (re-search-forward search end t) | ||
| 3840 | (goto-char (match-beginning 0)))) | ||
| 3841 | (setq tcol (current-column) seen t) | ||
| 3842 | (if (> tcol col) (setq col tcol))) | ||
| 3843 | (or seen | ||
| 3844 | (error "The construction to line up occurred only once")) | ||
| 3845 | (goto-char beg) | ||
| 3846 | (setq col (+ col minshift)) | ||
| 3847 | (if (/= (% col step) 0) (setq step (* step (1+ (/ col step))))) | ||
| 3848 | (while | ||
| 3849 | (progn | ||
| 3850 | (setq e (point)) | ||
| 3851 | (skip-chars-backward " \t") | ||
| 3852 | (delete-region (point) e) | ||
| 3853 | (indent-to-column col); (make-string (- col (current-column)) ?\ )) | ||
| 3854 | (beginning-of-line 2) | ||
| 3855 | (and (< (point) end) | ||
| 3856 | (re-search-forward search end t) | ||
| 3857 | (goto-char (match-beginning 0)))))))) ; No body | ||
| 3858 | |||
| 3859 | (defun cperl-etags (&optional add all files) | ||
| 3860 | "Run etags with appropriate options for Perl files. | ||
| 3861 | If optional argument ALL is `recursive', will process Perl files | ||
| 3862 | in subdirectories too." | ||
| 3863 | (interactive) | ||
| 3864 | (let ((cmd "etags") | ||
| 3865 | (args '("-l" "none" "-r" "/\\<\\(package\\|sub\\)[ \\t]+\\(\\([a-zA-Z0-9:_]*::\\)?\\([a-zA-Z0-9_]+\\)[ \\t]*\\(([^()]*)[ \t]*\\)?\\([{#]\\|$\\)\\)/\\4/")) | ||
| 3866 | res) | ||
| 3867 | (if add (setq args (cons "-a" args))) | ||
| 3868 | (or files (setq files (list buffer-file-name))) | ||
| 3869 | (cond | ||
| 3870 | ((eq all 'recursive) | ||
| 3871 | ;;(error "Not implemented: recursive") | ||
| 3872 | (setq args (append (list "-e" | ||
| 3873 | "sub wanted {push @ARGV, $File::Find::name if /\\.[pP][Llm]$/} | ||
| 3874 | use File::Find; | ||
| 3875 | find(\\&wanted, '.'); | ||
| 3876 | exec @ARGV;" | ||
| 3877 | cmd) args) | ||
| 3878 | cmd "perl")) | ||
| 3879 | (all | ||
| 3880 | ;;(error "Not implemented: all") | ||
| 3881 | (setq args (append (list "-e" | ||
| 3882 | "push @ARGV, <*.PL *.pl *.pm>; | ||
| 3883 | exec @ARGV;" | ||
| 3884 | cmd) args) | ||
| 3885 | cmd "perl")) | ||
| 3886 | (t | ||
| 3887 | (setq args (append args files)))) | ||
| 3888 | (setq res (apply 'call-process cmd nil nil nil args)) | ||
| 3889 | (or (eq res 0) | ||
| 3890 | (message "etags returned \"%s\"" res)))) | ||
| 3891 | |||
| 3892 | (defun cperl-toggle-auto-newline () | ||
| 3893 | "Toggle the state of `cperl-auto-newline'." | ||
| 3894 | (interactive) | ||
| 3895 | (setq cperl-auto-newline (not cperl-auto-newline)) | ||
| 3896 | (message "Newlines will %sbe auto-inserted now." | ||
| 3897 | (if cperl-auto-newline "" "not "))) | ||
| 3898 | |||
| 3899 | (defun cperl-toggle-abbrev () | ||
| 3900 | "Toggle the state of automatic keyword expansion in CPerl mode." | ||
| 3901 | (interactive) | ||
| 3902 | (abbrev-mode (if abbrev-mode 0 1)) | ||
| 3903 | (message "Perl control structure will %sbe auto-inserted now." | ||
| 3904 | (if abbrev-mode "" "not "))) | ||
| 3905 | |||
| 3906 | |||
| 3907 | (defun cperl-toggle-electric () | ||
| 3908 | "Toggle the state of parentheses doubling in CPerl mode." | ||
| 3909 | (interactive) | ||
| 3910 | (setq cperl-electric-parens (if (cperl-val 'cperl-electric-parens) 'null t)) | ||
| 3911 | (message "Parentheses will %sbe auto-doubled now." | ||
| 3912 | (if (cperl-val 'cperl-electric-parens) "" "not "))) | ||
| 3913 | |||
| 3914 | ;;;; Tags file creation. | ||
| 3915 | |||
| 3916 | (defvar cperl-tmp-buffer " *cperl-tmp*") | ||
| 3917 | |||
| 3918 | (defun cperl-setup-tmp-buf () | ||
| 3919 | (set-buffer (get-buffer-create cperl-tmp-buffer)) | ||
| 3920 | (set-syntax-table cperl-mode-syntax-table) | ||
| 3921 | (buffer-disable-undo) | ||
| 3922 | (auto-fill-mode 0) | ||
| 3923 | (if cperl-use-syntax-table-text-property-for-tags | ||
| 3924 | (progn | ||
| 3925 | (make-variable-buffer-local 'parse-sexp-lookup-properties) | ||
| 3926 | ;; Do not introduce variable if not needed, we check it! | ||
| 3927 | (set 'parse-sexp-lookup-properties t)))) | ||
| 3928 | |||
| 3929 | (defun cperl-xsub-scan () | ||
| 3930 | (require 'cl) | ||
| 3931 | (require 'imenu) | ||
| 3932 | (let ((index-alist '()) | ||
| 3933 | (prev-pos 0) index index1 name package prefix) | ||
| 3934 | (goto-char (point-min)) | ||
| 3935 | (if noninteractive | ||
| 3936 | (message "Scanning XSUB for index") | ||
| 3937 | (imenu-progress-message prev-pos 0)) | ||
| 3938 | ;; Search for the function | ||
| 3939 | (progn ;;save-match-data | ||
| 3940 | (while (re-search-forward | ||
| 3941 | "^\\([ \t]*MODULE\\>[^\n]*\\<PACKAGE[ \t]*=[ \t]*\\([a-zA-Z_][a-zA-Z_0-9:]*\\)\\>\\|\\([a-zA-Z_][a-zA-Z_0-9]*\\)(\\|[ \t]*BOOT:\\)" | ||
| 3942 | nil t) | ||
| 3943 | (or noninteractive | ||
| 3944 | (imenu-progress-message prev-pos)) | ||
| 3945 | (cond | ||
| 3946 | ((match-beginning 2) ; SECTION | ||
| 3947 | (setq package (buffer-substring (match-beginning 2) (match-end 2))) | ||
| 3948 | (goto-char (match-beginning 0)) | ||
| 3949 | (skip-chars-forward " \t") | ||
| 3950 | (forward-char 1) | ||
| 3951 | (if (looking-at "[^\n]*\\<PREFIX[ \t]*=[ \t]*\\([a-zA-Z_][a-zA-Z_0-9]*\\)\\>") | ||
| 3952 | (setq prefix (buffer-substring (match-beginning 1) (match-end 1))) | ||
| 3953 | (setq prefix nil))) | ||
| 3954 | ((not package) nil) ; C language section | ||
| 3955 | ((match-beginning 3) ; XSUB | ||
| 3956 | (goto-char (1+ (match-beginning 3))) | ||
| 3957 | (setq index (imenu-example--name-and-position)) | ||
| 3958 | (setq name (buffer-substring (match-beginning 3) (match-end 3))) | ||
| 3959 | (if (and prefix (string-match (concat "^" prefix) name)) | ||
| 3960 | (setq name (substring name (length prefix)))) | ||
| 3961 | (cond ((string-match "::" name) nil) | ||
| 3962 | (t | ||
| 3963 | (setq index1 (cons (concat package "::" name) (cdr index))) | ||
| 3964 | (push index1 index-alist))) | ||
| 3965 | (setcar index name) | ||
| 3966 | (push index index-alist)) | ||
| 3967 | (t ; BOOT: section | ||
| 3968 | ;; (beginning-of-line) | ||
| 3969 | (setq index (imenu-example--name-and-position)) | ||
| 3970 | (setcar index (concat package "::BOOT:")) | ||
| 3971 | (push index index-alist))))) | ||
| 3972 | (or noninteractive | ||
| 3973 | (imenu-progress-message prev-pos 100)) | ||
| 3974 | ;;(setq index-alist | ||
| 3975 | ;; (if (default-value 'imenu-sort-function) | ||
| 3976 | ;; (sort index-alist (default-value 'imenu-sort-function)) | ||
| 3977 | ;; (nreverse index-alist))) | ||
| 3978 | index-alist)) | ||
| 3979 | |||
| 3980 | (defun cperl-find-tags (file xs topdir) | ||
| 3981 | (let (ind (b (get-buffer cperl-tmp-buffer)) lst elt pos ret rel | ||
| 3982 | (cperl-pod-here-fontify nil)) | ||
| 3983 | (save-excursion | ||
| 3984 | (if b (set-buffer b) | ||
| 3985 | (cperl-setup-tmp-buf)) | ||
| 3986 | (erase-buffer) | ||
| 3987 | (setq file (car (insert-file-contents file))) | ||
| 3988 | (message "Scanning file %s ..." file) | ||
| 3989 | (if (and cperl-use-syntax-table-text-property-for-tags | ||
| 3990 | (not xs)) | ||
| 3991 | (condition-case err ; after __END__ may have garbage | ||
| 3992 | (cperl-find-pods-heres) | ||
| 3993 | (error (message "While scanning for syntax: %s" err)))) | ||
| 3994 | (if xs | ||
| 3995 | (setq lst (cperl-xsub-scan)) | ||
| 3996 | (setq ind (imenu-example--create-perl-index)) | ||
| 3997 | (setq lst (cdr (assoc "+Unsorted List+..." ind)))) | ||
| 3998 | (setq lst | ||
| 3999 | (mapcar | ||
| 4000 | (function | ||
| 4001 | (lambda (elt) | ||
| 4002 | (cond ((string-match "^[_a-zA-Z]" (car elt)) | ||
| 4003 | (goto-char (cdr elt)) | ||
| 4004 | (list (car elt) | ||
| 4005 | (point) (count-lines 1 (point)) | ||
| 4006 | (buffer-substring (progn | ||
| 4007 | (skip-chars-forward | ||
| 4008 | ":_a-zA-Z0-9") | ||
| 4009 | (or (eolp) (forward-char 1)) | ||
| 4010 | (point)) | ||
| 4011 | (progn | ||
| 4012 | (beginning-of-line) | ||
| 4013 | (point)))))))) | ||
| 4014 | lst)) | ||
| 4015 | (erase-buffer) | ||
| 4016 | (while lst | ||
| 4017 | (setq elt (car lst) lst (cdr lst)) | ||
| 4018 | (if elt | ||
| 4019 | (progn | ||
| 4020 | (insert (elt elt 3) | ||
| 4021 | 127 | ||
| 4022 | (if (string-match "^package " (car elt)) | ||
| 4023 | (substring (car elt) 8) | ||
| 4024 | (car elt) ) | ||
| 4025 | 1 | ||
| 4026 | (number-to-string (elt elt 1)) | ||
| 4027 | "," | ||
| 4028 | (number-to-string (elt elt 2)) | ||
| 4029 | "\n") | ||
| 4030 | (if (and (string-match "^[_a-zA-Z]+::" (car elt)) | ||
| 4031 | (string-match "^sub[ \t]+\\([_a-zA-Z]+\\)[^:_a-zA-Z]" | ||
| 4032 | (elt elt 3))) | ||
| 4033 | ;; Need to insert the name without package as well | ||
| 4034 | (setq lst (cons (cons (substring (elt elt 3) | ||
| 4035 | (match-beginning 1) | ||
| 4036 | (match-end 1)) | ||
| 4037 | (cdr elt)) | ||
| 4038 | lst)))))) | ||
| 4039 | (setq pos (point)) | ||
| 4040 | (goto-char 1) | ||
| 4041 | (setq rel file) | ||
| 4042 | ;; On case-preserving filesystems (EMX on OS/2) case might be encoded in properties | ||
| 4043 | (set-text-properties 0 (length rel) nil rel) | ||
| 4044 | (and (equal topdir (substring rel 0 (length topdir))) | ||
| 4045 | (setq rel (substring file (length topdir)))) | ||
| 4046 | (insert "\f\n" rel "," (number-to-string (1- pos)) "\n") | ||
| 4047 | (setq ret (buffer-substring 1 (point-max))) | ||
| 4048 | (erase-buffer) | ||
| 4049 | (or noninteractive | ||
| 4050 | (message "Scanning file %s finished" file)) | ||
| 4051 | ret))) | ||
| 4052 | |||
| 4053 | (defun cperl-add-tags-recurse-noxs () | ||
| 4054 | "Add to TAGS data for Perl and XSUB files in the current directory and kids. | ||
| 4055 | Use as | ||
| 4056 | emacs -batch -q -no-site-file -l emacs/cperl-mode.el \ | ||
| 4057 | -f cperl-add-tags-recurse | ||
| 4058 | " | ||
| 4059 | (cperl-write-tags nil nil t t nil t)) | ||
| 4060 | |||
| 4061 | (defun cperl-add-tags-recurse () | ||
| 4062 | "Add to TAGS file data for Perl files in the current directory and kids. | ||
| 4063 | Use as | ||
| 4064 | emacs -batch -q -no-site-file -l emacs/cperl-mode.el \ | ||
| 4065 | -f cperl-add-tags-recurse | ||
| 4066 | " | ||
| 4067 | (cperl-write-tags nil nil t t)) | ||
| 4068 | |||
| 4069 | (defun cperl-write-tags (&optional file erase recurse dir inbuffer noxs topdir) | ||
| 4070 | ;; If INBUFFER, do not select buffer, and do not save | ||
| 4071 | ;; If ERASE is `ignore', do not erase, and do not try to delete old info. | ||
| 4072 | (require 'etags) | ||
| 4073 | (if file nil | ||
| 4074 | (setq file (if dir default-directory (buffer-file-name))) | ||
| 4075 | (if (and (not dir) (buffer-modified-p)) (error "Save buffer first!"))) | ||
| 4076 | (or topdir | ||
| 4077 | (setq topdir default-directory)) | ||
| 4078 | (let ((tags-file-name "TAGS") | ||
| 4079 | (case-fold-search (eq system-type 'emx)) | ||
| 4080 | xs) | ||
| 4081 | (save-excursion | ||
| 4082 | (cond (inbuffer nil) ; Already there | ||
| 4083 | ((file-exists-p tags-file-name) | ||
| 4084 | (visit-tags-table-buffer tags-file-name)) | ||
| 4085 | (t (set-buffer (find-file-noselect tags-file-name)))) | ||
| 4086 | (cond | ||
| 4087 | (dir | ||
| 4088 | (cond ((eq erase 'ignore)) | ||
| 4089 | (erase | ||
| 4090 | (erase-buffer) | ||
| 4091 | (setq erase 'ignore))) | ||
| 4092 | (let ((files | ||
| 4093 | (directory-files file t | ||
| 4094 | (if recurse nil cperl-scan-files-regexp) | ||
| 4095 | t))) | ||
| 4096 | (mapcar (function (lambda (file) | ||
| 4097 | (cond | ||
| 4098 | ((string-match cperl-noscan-files-regexp file) | ||
| 4099 | nil) | ||
| 4100 | ((not (file-directory-p file)) | ||
| 4101 | (if (string-match cperl-scan-files-regexp file) | ||
| 4102 | (cperl-write-tags file erase recurse nil t noxs topdir))) | ||
| 4103 | ((not recurse) nil) | ||
| 4104 | (t (cperl-write-tags file erase recurse t t noxs topdir))))) | ||
| 4105 | files)) | ||
| 4106 | ) | ||
| 4107 | (t | ||
| 4108 | (setq xs (string-match "\\.xs$" file)) | ||
| 4109 | (if (not (and xs noxs)) | ||
| 4110 | (progn | ||
| 4111 | (cond ((eq erase 'ignore) (goto-char (point-max))) | ||
| 4112 | (erase (erase-buffer)) | ||
| 4113 | (t | ||
| 4114 | (goto-char 1) | ||
| 4115 | (if (search-forward (concat "\f\n" file ",") nil t) | ||
| 4116 | (progn | ||
| 4117 | (search-backward "\f\n") | ||
| 4118 | (delete-region (point) | ||
| 4119 | (save-excursion | ||
| 4120 | (forward-char 1) | ||
| 4121 | (if (search-forward "\f\n" | ||
| 4122 | nil 'toend) | ||
| 4123 | (- (point) 2) | ||
| 4124 | (point-max))))) | ||
| 4125 | (goto-char (point-max))))) | ||
| 4126 | (insert (cperl-find-tags file xs topdir)))))) | ||
| 4127 | (if inbuffer nil ; Delegate to the caller | ||
| 4128 | (save-buffer 0) ; No backup | ||
| 4129 | (if (fboundp 'initialize-new-tags-table) ; Do we need something special in XEmacs? | ||
| 4130 | (initialize-new-tags-table)))))) | ||
| 4131 | |||
| 4132 | (defvar cperl-tags-hier-regexp-list | ||
| 4133 | (concat | ||
| 4134 | "^\\(" | ||
| 4135 | "\\(package\\)\\>" | ||
| 4136 | "\\|" | ||
| 4137 | "sub\\>[^\n]+::" | ||
| 4138 | "\\|" | ||
| 4139 | "[a-zA-Z_][a-zA-Z_0-9:]*(\C-?[^\n]+::" ; XSUB? | ||
| 4140 | "\\|" | ||
| 4141 | "[ \t]*BOOT:\C-?[^\n]+::" ; BOOT section | ||
| 4142 | "\\)")) | ||
| 4143 | |||
| 4144 | (defvar cperl-hierarchy '(() ()) | ||
| 4145 | "Global hierarchy of classes") | ||
| 4146 | |||
| 4147 | (defun cperl-tags-hier-fill () | ||
| 4148 | ;; Suppose we are in a tag table cooked by cperl. | ||
| 4149 | (goto-char 1) | ||
| 4150 | (let (type pack name pos line chunk ord cons1 file str info fileind) | ||
| 4151 | (while (re-search-forward cperl-tags-hier-regexp-list nil t) | ||
| 4152 | (setq pos (match-beginning 0) | ||
| 4153 | pack (match-beginning 2)) | ||
| 4154 | (beginning-of-line) | ||
| 4155 | (if (looking-at (concat | ||
| 4156 | "\\([^\n]+\\)" | ||
| 4157 | "\C-?" | ||
| 4158 | "\\([^\n]+\\)" | ||
| 4159 | "\C-a" | ||
| 4160 | "\\([0-9]+\\)" | ||
| 4161 | "," | ||
| 4162 | "\\([0-9]+\\)")) | ||
| 4163 | (progn | ||
| 4164 | (setq ;;str (buffer-substring (match-beginning 1) (match-end 1)) | ||
| 4165 | name (buffer-substring (match-beginning 2) (match-end 2)) | ||
| 4166 | ;;pos (buffer-substring (match-beginning 3) (match-end 3)) | ||
| 4167 | line (buffer-substring (match-beginning 4) (match-end 4)) | ||
| 4168 | ord (if pack 1 0) | ||
| 4169 | info (etags-snarf-tag) ; Moves to beginning of the next line | ||
| 4170 | file (file-of-tag) | ||
| 4171 | fileind (format "%s:%s" file line)) | ||
| 4172 | ;; Move back | ||
| 4173 | (forward-char -1) | ||
| 4174 | ;; Make new member of hierarchy name ==> file ==> pos if needed | ||
| 4175 | (if (setq cons1 (assoc name (nth ord cperl-hierarchy))) | ||
| 4176 | ;; Name known | ||
| 4177 | (setcdr cons1 (cons (cons fileind (vector file info)) | ||
| 4178 | (cdr cons1))) | ||
| 4179 | ;; First occurrence of the name, start alist | ||
| 4180 | (setq cons1 (cons name (list (cons fileind (vector file info))))) | ||
| 4181 | (if pack | ||
| 4182 | (setcar (cdr cperl-hierarchy) | ||
| 4183 | (cons cons1 (nth 1 cperl-hierarchy))) | ||
| 4184 | (setcar cperl-hierarchy | ||
| 4185 | (cons cons1 (car cperl-hierarchy))))))) | ||
| 4186 | (end-of-line)))) | ||
| 4187 | |||
| 4188 | (defun cperl-tags-hier-init (&optional update) | ||
| 4189 | "Show hierarchical menu of classes and methods. | ||
| 4190 | Finds info about classes by a scan of loaded TAGS files. | ||
| 4191 | Supposes that the TAGS files contain fully qualified function names. | ||
| 4192 | One may build such TAGS files from CPerl mode menu." | ||
| 4193 | (interactive) | ||
| 4194 | (require 'etags) | ||
| 4195 | (require 'imenu) | ||
| 4196 | (if (or update (null (nth 2 cperl-hierarchy))) | ||
| 4197 | (let (pack name cons1 to l1 l2 l3 l4 | ||
| 4198 | (remover (function (lambda (elt) ; (name (file1...) (file2..)) | ||
| 4199 | (or (nthcdr 2 elt) | ||
| 4200 | ;; Only in one file | ||
| 4201 | (setcdr elt (cdr (nth 1 elt)))))))) | ||
| 4202 | ;; (setq cperl-hierarchy '(() () ())) ; Would write into '() later! | ||
| 4203 | (setq cperl-hierarchy (list l1 l2 l3)) | ||
| 4204 | (or tags-table-list | ||
| 4205 | (call-interactively 'visit-tags-table)) | ||
| 4206 | (message "Updating list of classes...") | ||
| 4207 | (mapcar | ||
| 4208 | (function | ||
| 4209 | (lambda (tagsfile) | ||
| 4210 | (set-buffer (get-file-buffer tagsfile)) | ||
| 4211 | (cperl-tags-hier-fill))) | ||
| 4212 | tags-table-list) | ||
| 4213 | (mapcar remover (car cperl-hierarchy)) | ||
| 4214 | (mapcar remover (nth 1 cperl-hierarchy)) | ||
| 4215 | (setq to (list nil (cons "Packages: " (nth 1 cperl-hierarchy)) | ||
| 4216 | (cons "Methods: " (car cperl-hierarchy)))) | ||
| 4217 | (cperl-tags-treeify to 1) | ||
| 4218 | (setcar (nthcdr 2 cperl-hierarchy) | ||
| 4219 | (cperl-menu-to-keymap (cons '("+++UPDATE+++" . -999) (cdr to)))) | ||
| 4220 | (message "Updating list of classes: done, requesting display...") | ||
| 4221 | ;;(cperl-imenu-addback (nth 2 cperl-hierarchy)) | ||
| 4222 | )) | ||
| 4223 | (or (nth 2 cperl-hierarchy) | ||
| 4224 | (error "No items found")) | ||
| 4225 | (setq update | ||
| 4226 | ;;; (imenu-choose-buffer-index "Packages: " (nth 2 cperl-hierarchy)) | ||
| 4227 | (if window-system | ||
| 4228 | (x-popup-menu t (nth 2 cperl-hierarchy)) | ||
| 4229 | (require 'tmm) | ||
| 4230 | (tmm-prompt (nth 2 cperl-hierarchy)))) | ||
| 4231 | (if (and update (listp update)) | ||
| 4232 | (progn (while (cdr update) (setq update (cdr update))) | ||
| 4233 | (setq update (car update)))) ; Get the last from the list | ||
| 4234 | (if (vectorp update) | ||
| 4235 | (progn | ||
| 4236 | (find-file (elt update 0)) | ||
| 4237 | (etags-goto-tag-location (elt update 1)))) | ||
| 4238 | (if (eq update -999) (cperl-tags-hier-init t))) | ||
| 4239 | |||
| 4240 | (defun cperl-tags-treeify (to level) | ||
| 4241 | ;; cadr of `to' is read-write. On start it is a cons | ||
| 4242 | (let* ((regexp (concat "^\\(" (mapconcat | ||
| 4243 | 'identity | ||
| 4244 | (make-list level "[_a-zA-Z0-9]+") | ||
| 4245 | "::") | ||
| 4246 | "\\)\\(::\\)?")) | ||
| 4247 | (packages (cdr (nth 1 to))) | ||
| 4248 | (methods (cdr (nth 2 to))) | ||
| 4249 | l1 head tail cons1 cons2 ord writeto packs recurse | ||
| 4250 | root-packages root-functions ms many_ms same_name ps | ||
| 4251 | (move-deeper | ||
| 4252 | (function | ||
| 4253 | (lambda (elt) | ||
| 4254 | (cond ((and (string-match regexp (car elt)) | ||
| 4255 | (or (eq ord 1) (match-end 2))) | ||
| 4256 | (setq head (substring (car elt) 0 (match-end 1)) | ||
| 4257 | tail (if (match-end 2) (substring (car elt) | ||
| 4258 | (match-end 2))) | ||
| 4259 | recurse t) | ||
| 4260 | (if (setq cons1 (assoc head writeto)) nil | ||
| 4261 | ;; Need to init new head | ||
| 4262 | (setcdr writeto (cons (list head (list "Packages: ") | ||
| 4263 | (list "Methods: ")) | ||
| 4264 | (cdr writeto))) | ||
| 4265 | (setq cons1 (nth 1 writeto))) | ||
| 4266 | (setq cons2 (nth ord cons1)) ; Either packs or meths | ||
| 4267 | (setcdr cons2 (cons elt (cdr cons2)))) | ||
| 4268 | ((eq ord 2) | ||
| 4269 | (setq root-functions (cons elt root-functions))) | ||
| 4270 | (t | ||
| 4271 | (setq root-packages (cons elt root-packages)))))))) | ||
| 4272 | (setcdr to l1) ; Init to dynamic space | ||
| 4273 | (setq writeto to) | ||
| 4274 | (setq ord 1) | ||
| 4275 | (mapcar move-deeper packages) | ||
| 4276 | (setq ord 2) | ||
| 4277 | (mapcar move-deeper methods) | ||
| 4278 | (if recurse | ||
| 4279 | (mapcar (function (lambda (elt) | ||
| 4280 | (cperl-tags-treeify elt (1+ level)))) | ||
| 4281 | (cdr to))) | ||
| 4282 | ;;Now clean up leaders with one child only | ||
| 4283 | (mapcar (function (lambda (elt) | ||
| 4284 | (if (not (and (listp (cdr elt)) | ||
| 4285 | (eq (length elt) 2))) nil | ||
| 4286 | (setcar elt (car (nth 1 elt))) | ||
| 4287 | (setcdr elt (cdr (nth 1 elt)))))) | ||
| 4288 | (cdr to)) | ||
| 4289 | ;; Sort the roots of subtrees | ||
| 4290 | (if (default-value 'imenu-sort-function) | ||
| 4291 | (setcdr to | ||
| 4292 | (sort (cdr to) (default-value 'imenu-sort-function)))) | ||
| 4293 | ;; Now add back functions removed from display | ||
| 4294 | (mapcar (function (lambda (elt) | ||
| 4295 | (setcdr to (cons elt (cdr to))))) | ||
| 4296 | (if (default-value 'imenu-sort-function) | ||
| 4297 | (nreverse | ||
| 4298 | (sort root-functions (default-value 'imenu-sort-function))) | ||
| 4299 | root-functions)) | ||
| 4300 | ;; Now add back packages removed from display | ||
| 4301 | (mapcar (function (lambda (elt) | ||
| 4302 | (setcdr to (cons (cons (concat "package " (car elt)) | ||
| 4303 | (cdr elt)) | ||
| 4304 | (cdr to))))) | ||
| 4305 | (if (default-value 'imenu-sort-function) | ||
| 4306 | (nreverse | ||
| 4307 | (sort root-packages (default-value 'imenu-sort-function))) | ||
| 4308 | root-packages)) | ||
| 4309 | )) | ||
| 4310 | |||
| 4311 | ;;;(x-popup-menu t | ||
| 4312 | ;;; '(keymap "Name1" | ||
| 4313 | ;;; ("Ret1" "aa") | ||
| 4314 | ;;; ("Head1" "ab" | ||
| 4315 | ;;; keymap "Name2" | ||
| 4316 | ;;; ("Tail1" "x") ("Tail2" "y")))) | ||
| 4317 | |||
| 4318 | (defun cperl-list-fold (list name limit) | ||
| 4319 | (let (list1 list2 elt1 (num 0)) | ||
| 4320 | (if (<= (length list) limit) list | ||
| 4321 | (setq list1 nil list2 nil) | ||
| 4322 | (while list | ||
| 4323 | (setq num (1+ num) | ||
| 4324 | elt1 (car list) | ||
| 4325 | list (cdr list)) | ||
| 4326 | (if (<= num imenu-max-items) | ||
| 4327 | (setq list2 (cons elt1 list2)) | ||
| 4328 | (setq list1 (cons (cons name | ||
| 4329 | (nreverse list2)) | ||
| 4330 | list1) | ||
| 4331 | list2 (list elt1) | ||
| 4332 | num 1))) | ||
| 4333 | (nreverse (cons (cons name | ||
| 4334 | (nreverse list2)) | ||
| 4335 | list1))))) | ||
| 4336 | |||
| 4337 | (defun cperl-menu-to-keymap (menu &optional name) | ||
| 4338 | (let (list) | ||
| 4339 | (cons 'keymap | ||
| 4340 | (mapcar | ||
| 4341 | (function | ||
| 4342 | (lambda (elt) | ||
| 4343 | (cond ((listp (cdr elt)) | ||
| 4344 | (setq list (cperl-list-fold | ||
| 4345 | (cdr elt) (car elt) imenu-max-items)) | ||
| 4346 | (cons nil | ||
| 4347 | (cons (car elt) | ||
| 4348 | (cperl-menu-to-keymap list)))) | ||
| 4349 | (t | ||
| 4350 | (list (cdr elt) (car elt) t))))) ; t is needed in 19.34 | ||
| 4351 | (cperl-list-fold menu "Root" imenu-max-items))))) | ||
| 4352 | |||
| 4353 | |||
| 4354 | (defvar cperl-bad-style-regexp | ||
| 4355 | (mapconcat 'identity | ||
| 4356 | '("[^-\n\t <>=+!.&|(*/'`\"#^][-=+<>!|&^]" ; char sign | ||
| 4357 | "[-<>=+^&|]+[^- \t\n=+<>~]" ; sign+ char | ||
| 4358 | ) | ||
| 4359 | "\\|") | ||
| 4360 | "Finds places such that insertion of a whitespace may help a lot.") | ||
| 4361 | |||
| 4362 | (defvar cperl-not-bad-style-regexp | ||
| 4363 | (mapconcat 'identity | ||
| 4364 | '("[^-\t <>=+]\\(--\\|\\+\\+\\)" ; var-- var++ | ||
| 4365 | "[a-zA-Z0-9_][|&][a-zA-Z0-9_$]" ; abc|def abc&def are often used. | ||
| 4366 | "&[(a-zA-Z0-9_$]" ; &subroutine &(var->field) | ||
| 4367 | "<\\$?\\sw+\\(\\.\\sw+\\)?>" ; <IN> <stdin.h> | ||
| 4368 | "-[a-zA-Z][ \t]+[_$\"'`]" ; -f file | ||
| 4369 | "-[0-9]" ; -5 | ||
| 4370 | "\\+\\+" ; ++var | ||
| 4371 | "--" ; --var | ||
| 4372 | ".->" ; a->b | ||
| 4373 | "->" ; a SPACE ->b | ||
| 4374 | "\\[-" ; a[-1] | ||
| 4375 | "^=" ; =head | ||
| 4376 | "||" | ||
| 4377 | "&&" | ||
| 4378 | "[CBIXSLFZ]<\\(\\sw\\|\\s \\|\\s_\\|[\n]\\)*>" ; C<code like text> | ||
| 4379 | "-[a-zA-Z_0-9]+[ \t]*=>" ; -option => value | ||
| 4380 | ;; Unaddressed trouble spots: = -abc, f(56, -abc) --- specialcased below | ||
| 4381 | ;;"[*/+-|&<.]+=" | ||
| 4382 | ) | ||
| 4383 | "\\|") | ||
| 4384 | "If matches at the start of match found by `my-bad-c-style-regexp', | ||
| 4385 | insertion of a whitespace will not help.") | ||
| 4386 | |||
| 4387 | (defvar found-bad) | ||
| 4388 | |||
| 4389 | (defun cperl-find-bad-style () | ||
| 4390 | "Find places in the buffer where insertion of a whitespace may help. | ||
| 4391 | Prompts user for insertion of spaces. | ||
| 4392 | Currently it is tuned to C and Perl syntax." | ||
| 4393 | (interactive) | ||
| 4394 | (let (found-bad (p (point))) | ||
| 4395 | (setq last-nonmenu-event 13) ; To disable popup | ||
| 4396 | (beginning-of-buffer) | ||
| 4397 | (map-y-or-n-p "Insert space here? " | ||
| 4398 | (function (lambda (arg) (insert " "))) | ||
| 4399 | 'cperl-next-bad-style | ||
| 4400 | '("location" "locations" "insert a space into") | ||
| 4401 | '((?\C-r (lambda (arg) | ||
| 4402 | (let ((buffer-quit-function | ||
| 4403 | 'exit-recursive-edit)) | ||
| 4404 | (message "Exit with Esc Esc") | ||
| 4405 | (recursive-edit) | ||
| 4406 | t)) ; Consider acted upon | ||
| 4407 | "edit, exit with Esc Esc") | ||
| 4408 | (?e (lambda (arg) | ||
| 4409 | (let ((buffer-quit-function | ||
| 4410 | 'exit-recursive-edit)) | ||
| 4411 | (message "Exit with Esc Esc") | ||
| 4412 | (recursive-edit) | ||
| 4413 | t)) ; Consider acted upon | ||
| 4414 | "edit, exit with Esc Esc")) | ||
| 4415 | t) | ||
| 4416 | (if found-bad (goto-char found-bad) | ||
| 4417 | (goto-char p) | ||
| 4418 | (message "No appropriate place found")))) | ||
| 4419 | |||
| 4420 | (defun cperl-next-bad-style () | ||
| 4421 | (let (p (not-found t) (point (point)) found) | ||
| 4422 | (while (and not-found | ||
| 4423 | (re-search-forward cperl-bad-style-regexp nil 'to-end)) | ||
| 4424 | (setq p (point)) | ||
| 4425 | (goto-char (match-beginning 0)) | ||
| 4426 | (if (or | ||
| 4427 | (looking-at cperl-not-bad-style-regexp) | ||
| 4428 | ;; Check for a < -b and friends | ||
| 4429 | (and (eq (following-char) ?\-) | ||
| 4430 | (save-excursion | ||
| 4431 | (skip-chars-backward " \t\n") | ||
| 4432 | (memq (preceding-char) '(?\= ?\> ?\< ?\, ?\(, ?\[, ?\{)))) | ||
| 4433 | ;; Now check for syntax type | ||
| 4434 | (save-match-data | ||
| 4435 | (setq found (point)) | ||
| 4436 | (beginning-of-defun) | ||
| 4437 | (let ((pps (parse-partial-sexp (point) found))) | ||
| 4438 | (or (nth 3 pps) (nth 4 pps) (nth 5 pps))))) | ||
| 4439 | (goto-char (match-end 0)) | ||
| 4440 | (goto-char (1- p)) | ||
| 4441 | (setq not-found nil | ||
| 4442 | found-bad found))) | ||
| 4443 | (not not-found))) | ||
| 4444 | |||
| 4445 | =06 | ||
| 4446 | ;;; Getting help | ||
| 4447 | (defvar cperl-have-help-regexp | ||
| 4448 | ;;(concat "\\(" | ||
| 4449 | (mapconcat | ||
| 4450 | 'identity | ||
| 4451 | '("[$@%*&][0-9a-zA-Z_:]+\\([ \t]*[[{]\\)?" ; Usual variable | ||
| 4452 | "[$@]\\^[a-zA-Z]" ; Special variable | ||
| 4453 | "[$@][^ \n\t]" ; Special variable | ||
| 4454 | "-[a-zA-Z]" ; File test | ||
| 4455 | "\\\\[a-zA-Z0]" ; Special chars | ||
| 4456 | "^=[a-z][a-zA-Z0-9_]*" ; Pod sections | ||
| 4457 | "[-!&*+,-./<=>?\\\\^|~]+" ; Operator | ||
| 4458 | "[a-zA-Z_0-9:]+" ; symbol or number | ||
| 4459 | "x=" | ||
| 4460 | "#!" | ||
| 4461 | ) | ||
| 4462 | ;;"\\)\\|\\(" | ||
| 4463 | "\\|" | ||
| 4464 | ) | ||
| 4465 | ;;"\\)" | ||
| 4466 | ;;) | ||
| 4467 | "Matches places in the buffer we can find help for.") | ||
| 4468 | |||
| 4469 | (defvar cperl-message-on-help-error t) | ||
| 4470 | (defvar cperl-help-from-timer nil) | ||
| 4471 | |||
| 4472 | (defun cperl-word-at-point-hard () | ||
| 4473 | ;; Does not save-excursion | ||
| 4474 | ;; Get to the something meaningful | ||
| 4475 | (or (eobp) (eolp) (forward-char 1)) | ||
| 4476 | (re-search-backward "[-a-zA-Z0-9_:!&*+,-./<=>?\\\\^|~$%@]" | ||
| 4477 | (save-excursion (beginning-of-line) (point)) | ||
| 4478 | 'to-beg) | ||
| 4479 | ;; (cond | ||
| 4480 | ;; ((or (eobp) (looking-at "[][ \t\n{}();,]")) ; Not at a symbol | ||
| 4481 | ;; (skip-chars-backward " \n\t\r({[]});,") | ||
| 4482 | ;; (or (bobp) (backward-char 1)))) | ||
| 4483 | ;; Try to backtrace | ||
| 4484 | (cond | ||
| 4485 | ((looking-at "[a-zA-Z0-9_:]") ; symbol | ||
| 4486 | (skip-chars-backward "a-zA-Z0-9_:") | ||
| 4487 | (cond | ||
| 4488 | ((and (eq (preceding-char) ?^) ; $^I | ||
| 4489 | (eq (char-after (- (point) 2)) ?\$)) | ||
| 4490 | (forward-char -2)) | ||
| 4491 | ((memq (preceding-char) (append "*$@%&\\" nil)) ; *glob | ||
| 4492 | (forward-char -1)) | ||
| 4493 | ((and (eq (preceding-char) ?\=) | ||
| 4494 | (eq (current-column) 1)) | ||
| 4495 | (forward-char -1))) ; =head1 | ||
| 4496 | (if (and (eq (preceding-char) ?\<) | ||
| 4497 | (looking-at "\\$?[a-zA-Z0-9_:]+>")) ; <FH> | ||
| 4498 | (forward-char -1))) | ||
| 4499 | ((and (looking-at "=") (eq (preceding-char) ?x)) ; x= | ||
| 4500 | (forward-char -1)) | ||
| 4501 | ((and (looking-at "\\^") (eq (preceding-char) ?\$)) ; $^I | ||
| 4502 | (forward-char -1)) | ||
| 4503 | ((looking-at "[-!&*+,-./<=>?\\\\^|~]") | ||
| 4504 | (skip-chars-backward "-!&*+,-./<=>?\\\\^|~") | ||
| 4505 | (cond | ||
| 4506 | ((and (eq (preceding-char) ?\$) | ||
| 4507 | (not (eq (char-after (- (point) 2)) ?\$))) ; $- | ||
| 4508 | (forward-char -1)) | ||
| 4509 | ((and (eq (following-char) ?\>) | ||
| 4510 | (string-match "[a-zA-Z0-9_]" (char-to-string (preceding-char))) | ||
| 4511 | (save-excursion | ||
| 4512 | (forward-sexp -1) | ||
| 4513 | (and (eq (preceding-char) ?\<) | ||
| 4514 | (looking-at "\\$?[a-zA-Z0-9_:]+>")))) ; <FH> | ||
| 4515 | (search-backward "<")))) | ||
| 4516 | ((and (eq (following-char) ?\$) | ||
| 4517 | (eq (preceding-char) ?\<) | ||
| 4518 | (looking-at "\\$?[a-zA-Z0-9_:]+>")) ; <$fh> | ||
| 4519 | (forward-char -1))) | ||
| 4520 | (if (looking-at cperl-have-help-regexp) | ||
| 4521 | (buffer-substring (match-beginning 0) (match-end 0)))) | ||
| 4522 | |||
| 4523 | (defun cperl-get-help () | ||
| 4524 | "Get one-line docs on the symbol at the point. | ||
| 4525 | The data for these docs is a little bit obsolete and may be in fact longer | ||
| 4526 | than a line. Your contribution to update/shorten it is appreciated." | ||
| 4527 | (interactive) | ||
| 4528 | (save-match-data ; May be called "inside" query-replace | ||
| 4529 | (save-excursion | ||
| 4530 | (let ((word (cperl-word-at-point-hard))) | ||
| 4531 | (if word | ||
| 4532 | (if (and cperl-help-from-timer ; Bail out if not in mainland | ||
| 4533 | (not (string-match "^#!\\|\\\\\\|^=" word)) ; Show help even in comments/strings. | ||
| 4534 | (or (memq (get-text-property (point) 'face) | ||
| 4535 | '(font-lock-comment-face font-lock-string-face)) | ||
| 4536 | (memq (get-text-property (point) 'syntax-type) | ||
| 4537 | '(pod here-doc format)))) | ||
| 4538 | nil | ||
| 4539 | (cperl-describe-perl-symbol word)) | ||
| 4540 | (if cperl-message-on-help-error | ||
| 4541 | (message "Nothing found for %s..." | ||
| 4542 | (buffer-substring (point) (min (+ 5 (point)) (point-max)))))))))) | ||
| 4543 | |||
| 4544 | ;;; Stolen from perl-descr.el by Johan Vromans: | ||
| 4545 | |||
| 4546 | (defvar cperl-doc-buffer " *perl-doc*" | ||
| 4547 | "Where the documentation can be found.") | ||
| 4548 | |||
| 4549 | (defun cperl-describe-perl-symbol (val) | ||
| 4550 | "Display the documentation of symbol at point, a Perl operator." | ||
| 4551 | (let ((enable-recursive-minibuffers t) | ||
| 4552 | args-file regexp) | ||
| 4553 | (cond | ||
| 4554 | ((string-match "^[&*][a-zA-Z_]" val) | ||
| 4555 | (setq val (concat (substring val 0 1) "NAME"))) | ||
| 4556 | ((string-match "^[$@]\\([a-zA-Z_:0-9]+\\)[ \t]*\\[" val) | ||
| 4557 | (setq val (concat "@" (substring val 1 (match-end 1))))) | ||
| 4558 | ((string-match "^[$@]\\([a-zA-Z_:0-9]+\\)[ \t]*{" val) | ||
| 4559 | (setq val (concat "%" (substring val 1 (match-end 1))))) | ||
| 4560 | ((and (string= val "x") (string-match "^x=" val)) | ||
| 4561 | (setq val "x=")) | ||
| 4562 | ((string-match "^\\$[\C-a-\C-z]" val) | ||
| 4563 | (setq val (concat "$^" (char-to-string (+ ?A -1 (aref val 1)))))) | ||
| 4564 | ((string-match "^CORE::" val) | ||
| 4565 | (setq val "CORE::")) | ||
| 4566 | ((string-match "^SUPER::" val) | ||
| 4567 | (setq val "SUPER::")) | ||
| 4568 | ((and (string= "<" val) (string-match "^<\\$?[a-zA-Z0-9_:]+>" val)) | ||
| 4569 | (setq val "<NAME>"))) | ||
| 4570 | (setq regexp (concat "^" | ||
| 4571 | "\\([^a-zA-Z0-9_:]+[ \t]+\\)?" | ||
| 4572 | (regexp-quote val) | ||
| 4573 | "\\([ \t([/]\\|$\\)")) | ||
| 4574 | |||
| 4575 | ;; get the buffer with the documentation text | ||
| 4576 | (cperl-switch-to-doc-buffer) | ||
| 4577 | |||
| 4578 | ;; lookup in the doc | ||
| 4579 | (goto-char (point-min)) | ||
| 4580 | (let ((case-fold-search nil)) | ||
| 4581 | (list | ||
| 4582 | (if (re-search-forward regexp (point-max) t) | ||
| 4583 | (save-excursion | ||
| 4584 | (beginning-of-line 1) | ||
| 4585 | (let ((lnstart (point))) | ||
| 4586 | (end-of-line) | ||
| 4587 | (message "%s" (buffer-substring lnstart (point))))) | ||
| 4588 | (if cperl-message-on-help-error | ||
| 4589 | (message "No definition for %s" val))))))) | ||
| 4590 | |||
| 4591 | (defvar cperl-short-docs "Ignore my value" | ||
| 4592 | ;; Perl4 version was written by Johan Vromans (jvromans@squirrel.nl) | ||
| 4593 | "# based on '@(#)@ perl-descr.el 1.9 - describe-perl-symbol' [Perl 5] | ||
| 4594 | ! ... Logical negation. | ||
| 4595 | ... != ... Numeric inequality. | ||
| 4596 | ... !~ ... Search pattern, substitution, or translation (negated). | ||
| 4597 | $! In numeric context: errno. In a string context: error string. | ||
| 4598 | $\" The separator which joins elements of arrays interpolated in strings. | ||
| 4599 | $# The output format for printed numbers. Initial value is %.15g or close. | ||
| 4600 | $$ Process number of this script. Changes in the fork()ed child process. | ||
| 4601 | $% The current page number of the currently selected output channel. | ||
| 4602 | |||
| 4603 | The following variables are always local to the current block: | ||
| 4604 | |||
| 4605 | $1 Match of the 1st set of parentheses in the last match (auto-local). | ||
| 4606 | $2 Match of the 2nd set of parentheses in the last match (auto-local). | ||
| 4607 | $3 Match of the 3rd set of parentheses in the last match (auto-local). | ||
| 4608 | $4 Match of the 4th set of parentheses in the last match (auto-local). | ||
| 4609 | $5 Match of the 5th set of parentheses in the last match (auto-local). | ||
| 4610 | $6 Match of the 6th set of parentheses in the last match (auto-local). | ||
| 4611 | $7 Match of the 7th set of parentheses in the last match (auto-local). | ||
| 4612 | $8 Match of the 8th set of parentheses in the last match (auto-local). | ||
| 4613 | $9 Match of the 9th set of parentheses in the last match (auto-local). | ||
| 4614 | $& The string matched by the last pattern match (auto-local). | ||
| 4615 | $' The string after what was matched by the last match (auto-local). | ||
| 4616 | $` The string before what was matched by the last match (auto-local). | ||
| 4617 | |||
| 4618 | $( The real gid of this process. | ||
| 4619 | $) The effective gid of this process. | ||
| 4620 | $* Deprecated: Set to 1 to do multiline matching within a string. | ||
| 4621 | $+ The last bracket matched by the last search pattern. | ||
| 4622 | $, The output field separator for the print operator. | ||
| 4623 | $- The number of lines left on the page. | ||
| 4624 | $. The current input line number of the last filehandle that was read. | ||
| 4625 | $/ The input record separator, newline by default. | ||
| 4626 | $0 Name of the file containing the perl script being executed. May be set. | ||
| 4627 | $: String may be broken after these characters to fill ^-lines in a format. | ||
| 4628 | $; Subscript separator for multi-dim array emulation. Default \"\\034\". | ||
| 4629 | $< The real uid of this process. | ||
| 4630 | $= The page length of the current output channel. Default is 60 lines. | ||
| 4631 | $> The effective uid of this process. | ||
| 4632 | $? The status returned by the last ``, pipe close or `system'. | ||
| 4633 | $@ The perl error message from the last eval or do @var{EXPR} command. | ||
| 4634 | $ARGV The name of the current file used with <> . | ||
| 4635 | $[ Deprecated: The index of the first element/char in an array/string. | ||
| 4636 | $\\ The output record separator for the print operator. | ||
| 4637 | $] The perl version string as displayed with perl -v. | ||
| 4638 | $^ The name of the current top-of-page format. | ||
| 4639 | $^A The current value of the write() accumulator for format() lines. | ||
| 4640 | $^D The value of the perl debug (-D) flags. | ||
| 4641 | $^E Information about the last system error other than that provided by $!. | ||
| 4642 | $^F The highest system file descriptor, ordinarily 2. | ||
| 4643 | $^H The current set of syntax checks enabled by `use strict'. | ||
| 4644 | $^I The value of the in-place edit extension (perl -i option). | ||
| 4645 | $^L What formats output to perform a formfeed. Default is \f. | ||
| 4646 | $^O The operating system name under which this copy of Perl was built. | ||
| 4647 | $^P Internal debugging flag. | ||
| 4648 | $^T The time the script was started. Used by -A/-M/-C file tests. | ||
| 4649 | $^W True if warnings are requested (perl -w flag). | ||
| 4650 | $^X The name under which perl was invoked (argv[0] in C-speech). | ||
| 4651 | $_ The default input and pattern-searching space. | ||
| 4652 | $| Auto-flush after write/print on current output channel? Default 0. | ||
| 4653 | $~ The name of the current report format. | ||
| 4654 | ... % ... Modulo division. | ||
| 4655 | ... %= ... Modulo division assignment. | ||
| 4656 | %ENV Contains the current environment. | ||
| 4657 | %INC List of files that have been require-d or do-ne. | ||
| 4658 | %SIG Used to set signal handlers for various signals. | ||
| 4659 | ... & ... Bitwise and. | ||
| 4660 | ... && ... Logical and. | ||
| 4661 | ... &&= ... Logical and assignment. | ||
| 4662 | ... &= ... Bitwise and assignment. | ||
| 4663 | ... * ... Multiplication. | ||
| 4664 | ... ** ... Exponentiation. | ||
| 4665 | *NAME Glob: all objects refered by NAME. *NAM1 = *NAM2 aliases NAM1 to NAM2. | ||
| 4666 | &NAME(arg0, ...) Subroutine call. Arguments go to @_. | ||
| 4667 | ... + ... Addition. +EXPR Makes EXPR into scalar context. | ||
| 4668 | ++ Auto-increment (magical on strings). ++EXPR EXPR++ | ||
| 4669 | ... += ... Addition assignment. | ||
| 4670 | , Comma operator. | ||
| 4671 | ... - ... Subtraction. | ||
| 4672 | -- Auto-decrement (NOT magical on strings). --EXPR EXPR-- | ||
| 4673 | ... -= ... Subtraction assignment. | ||
| 4674 | -A Access time in days since script started. | ||
| 4675 | -B File is a non-text (binary) file. | ||
| 4676 | -C Inode change time in days since script started. | ||
| 4677 | -M Age in days since script started. | ||
| 4678 | -O File is owned by real uid. | ||
| 4679 | -R File is readable by real uid. | ||
| 4680 | -S File is a socket . | ||
| 4681 | -T File is a text file. | ||
| 4682 | -W File is writable by real uid. | ||
| 4683 | -X File is executable by real uid. | ||
| 4684 | -b File is a block special file. | ||
| 4685 | -c File is a character special file. | ||
| 4686 | -d File is a directory. | ||
| 4687 | -e File exists . | ||
| 4688 | -f File is a plain file. | ||
| 4689 | -g File has setgid bit set. | ||
| 4690 | -k File has sticky bit set. | ||
| 4691 | -l File is a symbolic link. | ||
| 4692 | -o File is owned by effective uid. | ||
| 4693 | -p File is a named pipe (FIFO). | ||
| 4694 | -r File is readable by effective uid. | ||
| 4695 | -s File has non-zero size. | ||
| 4696 | -t Tests if filehandle (STDIN by default) is opened to a tty. | ||
| 4697 | -u File has setuid bit set. | ||
| 4698 | -w File is writable by effective uid. | ||
| 4699 | -x File is executable by effective uid. | ||
| 4700 | -z File has zero size. | ||
| 4701 | . Concatenate strings. | ||
| 4702 | .. Alternation, also range operator. | ||
| 4703 | .= Concatenate assignment strings | ||
| 4704 | ... / ... Division. /PATTERN/ioxsmg Pattern match | ||
| 4705 | ... /= ... Division assignment. | ||
| 4706 | /PATTERN/ioxsmg Pattern match. | ||
| 4707 | ... < ... Numeric less than. <pattern> Glob. See <NAME>, <> as well. | ||
| 4708 | <NAME> Reads line from filehandle NAME (a bareword or dollar-bareword). | ||
| 4709 | <pattern> Glob (Unless pattern is bareword/dollar-bareword - see <NAME>). | ||
| 4710 | <> Reads line from union of files in @ARGV (= command line) and STDIN. | ||
| 4711 | ... << ... Bitwise shift left. << start of HERE-DOCUMENT. | ||
| 4712 | ... <= ... Numeric less than or equal to. | ||
| 4713 | ... <=> ... Numeric compare. | ||
| 4714 | ... = ... Assignment. | ||
| 4715 | ... == ... Numeric equality. | ||
| 4716 | ... =~ ... Search pattern, substitution, or translation | ||
| 4717 | ... > ... Numeric greater than. | ||
| 4718 | ... >= ... Numeric greater than or equal to. | ||
| 4719 | ... >> ... Bitwise shift right. | ||
| 4720 | ... >>= ... Bitwise shift right assignment. | ||
| 4721 | ... ? ... : ... Condition=if-then-else operator. ?PAT? One-time pattern match. | ||
| 4722 | ?PATTERN? One-time pattern match. | ||
| 4723 | @ARGV Command line arguments (not including the command name - see $0). | ||
| 4724 | @INC List of places to look for perl scripts during do/include/use. | ||
| 4725 | @_ Parameter array for subroutines. Also used by split unless in array context. | ||
| 4726 | \\ Creates reference to what follows, like \$var, or quotes non-\w in strings. | ||
| 4727 | \\0 Octal char, e.g. \\033. | ||
| 4728 | \\E Case modification terminator. See \\Q, \\L, and \\U. | ||
| 4729 | \\L Lowercase until \\E . See also \l, lc. | ||
| 4730 | \\U Upcase until \\E . See also \u, uc. | ||
| 4731 | \\Q Quote metacharacters until \\E . See also quotemeta. | ||
| 4732 | \\a Alarm character (octal 007). | ||
| 4733 | \\b Backspace character (octal 010). | ||
| 4734 | \\c Control character, e.g. \\c[ . | ||
| 4735 | \\e Escape character (octal 033). | ||
| 4736 | \\f Formfeed character (octal 014). | ||
| 4737 | \\l Lowercase the next character. See also \\L and \\u, lcfirst. | ||
| 4738 | \\n Newline character (octal 012 on most systems). | ||
| 4739 | \\r Return character (octal 015 on most systems). | ||
| 4740 | \\t Tab character (octal 011). | ||
| 4741 | \\u Upcase the next character. See also \\U and \\l, ucfirst. | ||
| 4742 | \\x Hex character, e.g. \\x1b. | ||
| 4743 | ... ^ ... Bitwise exclusive or. | ||
| 4744 | __END__ Ends program source. | ||
| 4745 | __DATA__ Ends program source. | ||
| 4746 | __FILE__ Current (source) filename. | ||
| 4747 | __LINE__ Current line in current source. | ||
| 4748 | __PACKAGE__ Current package. | ||
| 4749 | ARGV Default multi-file input filehandle. <ARGV> is a synonym for <>. | ||
| 4750 | ARGVOUT Output filehandle with -i flag. | ||
| 4751 | BEGIN { ... } Immediately executed (during compilation) piece of code. | ||
| 4752 | END { ... } Pseudo-subroutine executed after the script finishes. | ||
| 4753 | DATA Input filehandle for what follows after __END__ or __DATA__. | ||
| 4754 | accept(NEWSOCKET,GENERICSOCKET) | ||
| 4755 | alarm(SECONDS) | ||
| 4756 | atan2(X,Y) | ||
| 4757 | bind(SOCKET,NAME) | ||
| 4758 | binmode(FILEHANDLE) | ||
| 4759 | caller[(LEVEL)] | ||
| 4760 | chdir(EXPR) | ||
| 4761 | chmod(LIST) | ||
| 4762 | chop[(LIST|VAR)] | ||
| 4763 | chown(LIST) | ||
| 4764 | chroot(FILENAME) | ||
| 4765 | close(FILEHANDLE) | ||
| 4766 | closedir(DIRHANDLE) | ||
| 4767 | ... cmp ... String compare. | ||
| 4768 | connect(SOCKET,NAME) | ||
| 4769 | continue of { block } continue { block }. Is executed after `next' or at end. | ||
| 4770 | cos(EXPR) | ||
| 4771 | crypt(PLAINTEXT,SALT) | ||
| 4772 | dbmclose(%HASH) | ||
| 4773 | dbmopen(%HASH,DBNAME,MODE) | ||
| 4774 | defined(EXPR) | ||
| 4775 | delete($HASH{KEY}) | ||
| 4776 | die(LIST) | ||
| 4777 | do { ... }|SUBR while|until EXPR executes at least once | ||
| 4778 | do(EXPR|SUBR([LIST])) (with while|until executes at least once) | ||
| 4779 | dump LABEL | ||
| 4780 | each(%HASH) | ||
| 4781 | endgrent | ||
| 4782 | endhostent | ||
| 4783 | endnetent | ||
| 4784 | endprotoent | ||
| 4785 | endpwent | ||
| 4786 | endservent | ||
| 4787 | eof[([FILEHANDLE])] | ||
| 4788 | ... eq ... String equality. | ||
| 4789 | eval(EXPR) or eval { BLOCK } | ||
| 4790 | exec(LIST) | ||
| 4791 | exit(EXPR) | ||
| 4792 | exp(EXPR) | ||
| 4793 | fcntl(FILEHANDLE,FUNCTION,SCALAR) | ||
| 4794 | fileno(FILEHANDLE) | ||
| 4795 | flock(FILEHANDLE,OPERATION) | ||
| 4796 | for (EXPR;EXPR;EXPR) { ... } | ||
| 4797 | foreach [VAR] (@ARRAY) { ... } | ||
| 4798 | fork | ||
| 4799 | ... ge ... String greater than or equal. | ||
| 4800 | getc[(FILEHANDLE)] | ||
| 4801 | getgrent | ||
| 4802 | getgrgid(GID) | ||
| 4803 | getgrnam(NAME) | ||
| 4804 | gethostbyaddr(ADDR,ADDRTYPE) | ||
| 4805 | gethostbyname(NAME) | ||
| 4806 | gethostent | ||
| 4807 | getlogin | ||
| 4808 | getnetbyaddr(ADDR,ADDRTYPE) | ||
| 4809 | getnetbyname(NAME) | ||
| 4810 | getnetent | ||
| 4811 | getpeername(SOCKET) | ||
| 4812 | getpgrp(PID) | ||
| 4813 | getppid | ||
| 4814 | getpriority(WHICH,WHO) | ||
| 4815 | getprotobyname(NAME) | ||
| 4816 | getprotobynumber(NUMBER) | ||
| 4817 | getprotoent | ||
| 4818 | getpwent | ||
| 4819 | getpwnam(NAME) | ||
| 4820 | getpwuid(UID) | ||
| 4821 | getservbyname(NAME,PROTO) | ||
| 4822 | getservbyport(PORT,PROTO) | ||
| 4823 | getservent | ||
| 4824 | getsockname(SOCKET) | ||
| 4825 | getsockopt(SOCKET,LEVEL,OPTNAME) | ||
| 4826 | gmtime(EXPR) | ||
| 4827 | goto LABEL | ||
| 4828 | grep(EXPR,LIST) | ||
| 4829 | ... gt ... String greater than. | ||
| 4830 | hex(EXPR) | ||
| 4831 | if (EXPR) { ... } [ elsif (EXPR) { ... } ... ] [ else { ... } ] or EXPR if EXPR | ||
| 4832 | index(STR,SUBSTR[,OFFSET]) | ||
| 4833 | int(EXPR) | ||
| 4834 | ioctl(FILEHANDLE,FUNCTION,SCALAR) | ||
| 4835 | join(EXPR,LIST) | ||
| 4836 | keys(%HASH) | ||
| 4837 | kill(LIST) | ||
| 4838 | last [LABEL] | ||
| 4839 | ... le ... String less than or equal. | ||
| 4840 | length(EXPR) | ||
| 4841 | link(OLDFILE,NEWFILE) | ||
| 4842 | listen(SOCKET,QUEUESIZE) | ||
| 4843 | local(LIST) | ||
| 4844 | localtime(EXPR) | ||
| 4845 | log(EXPR) | ||
| 4846 | lstat(EXPR|FILEHANDLE|VAR) | ||
| 4847 | ... lt ... String less than. | ||
| 4848 | m/PATTERN/iogsmx | ||
| 4849 | mkdir(FILENAME,MODE) | ||
| 4850 | msgctl(ID,CMD,ARG) | ||
| 4851 | msgget(KEY,FLAGS) | ||
| 4852 | msgrcv(ID,VAR,SIZE,TYPE.FLAGS) | ||
| 4853 | msgsnd(ID,MSG,FLAGS) | ||
| 4854 | my VAR or my (VAR1,...) Introduces a lexical variable ($VAR, @ARR, or %HASH). | ||
| 4855 | ... ne ... String inequality. | ||
| 4856 | next [LABEL] | ||
| 4857 | oct(EXPR) | ||
| 4858 | open(FILEHANDLE[,EXPR]) | ||
| 4859 | opendir(DIRHANDLE,EXPR) | ||
| 4860 | ord(EXPR) ASCII value of the first char of the string. | ||
| 4861 | pack(TEMPLATE,LIST) | ||
| 4862 | package NAME Introduces package context. | ||
| 4863 | pipe(READHANDLE,WRITEHANDLE) Create a pair of filehandles on ends of a pipe. | ||
| 4864 | pop(ARRAY) | ||
| 4865 | print [FILEHANDLE] [(LIST)] | ||
| 4866 | printf [FILEHANDLE] (FORMAT,LIST) | ||
| 4867 | push(ARRAY,LIST) | ||
| 4868 | q/STRING/ Synonym for 'STRING' | ||
| 4869 | qq/STRING/ Synonym for \"STRING\" | ||
| 4870 | qx/STRING/ Synonym for `STRING` | ||
| 4871 | rand[(EXPR)] | ||
| 4872 | read(FILEHANDLE,SCALAR,LENGTH[,OFFSET]) | ||
| 4873 | readdir(DIRHANDLE) | ||
| 4874 | readlink(EXPR) | ||
| 4875 | recv(SOCKET,SCALAR,LEN,FLAGS) | ||
| 4876 | redo [LABEL] | ||
| 4877 | rename(OLDNAME,NEWNAME) | ||
| 4878 | require [FILENAME | PERL_VERSION] | ||
| 4879 | reset[(EXPR)] | ||
| 4880 | return(LIST) | ||
| 4881 | reverse(LIST) | ||
| 4882 | rewinddir(DIRHANDLE) | ||
| 4883 | rindex(STR,SUBSTR[,OFFSET]) | ||
| 4884 | rmdir(FILENAME) | ||
| 4885 | s/PATTERN/REPLACEMENT/gieoxsm | ||
| 4886 | scalar(EXPR) | ||
| 4887 | seek(FILEHANDLE,POSITION,WHENCE) | ||
| 4888 | seekdir(DIRHANDLE,POS) | ||
| 4889 | select(FILEHANDLE | RBITS,WBITS,EBITS,TIMEOUT) | ||
| 4890 | semctl(ID,SEMNUM,CMD,ARG) | ||
| 4891 | semget(KEY,NSEMS,SIZE,FLAGS) | ||
| 4892 | semop(KEY,...) | ||
| 4893 | send(SOCKET,MSG,FLAGS[,TO]) | ||
| 4894 | setgrent | ||
| 4895 | sethostent(STAYOPEN) | ||
| 4896 | setnetent(STAYOPEN) | ||
| 4897 | setpgrp(PID,PGRP) | ||
| 4898 | setpriority(WHICH,WHO,PRIORITY) | ||
| 4899 | setprotoent(STAYOPEN) | ||
| 4900 | setpwent | ||
| 4901 | setservent(STAYOPEN) | ||
| 4902 | setsockopt(SOCKET,LEVEL,OPTNAME,OPTVAL) | ||
| 4903 | shift[(ARRAY)] | ||
| 4904 | shmctl(ID,CMD,ARG) | ||
| 4905 | shmget(KEY,SIZE,FLAGS) | ||
| 4906 | shmread(ID,VAR,POS,SIZE) | ||
| 4907 | shmwrite(ID,STRING,POS,SIZE) | ||
| 4908 | shutdown(SOCKET,HOW) | ||
| 4909 | sin(EXPR) | ||
| 4910 | sleep[(EXPR)] | ||
| 4911 | socket(SOCKET,DOMAIN,TYPE,PROTOCOL) | ||
| 4912 | socketpair(SOCKET1,SOCKET2,DOMAIN,TYPE,PROTOCOL) | ||
| 4913 | sort [SUBROUTINE] (LIST) | ||
| 4914 | splice(ARRAY,OFFSET[,LENGTH[,LIST]]) | ||
| 4915 | split[(/PATTERN/[,EXPR[,LIMIT]])] | ||
| 4916 | sprintf(FORMAT,LIST) | ||
| 4917 | sqrt(EXPR) | ||
| 4918 | srand(EXPR) | ||
| 4919 | stat(EXPR|FILEHANDLE|VAR) | ||
| 4920 | study[(SCALAR)] | ||
| 4921 | sub [NAME [(format)]] { BODY } sub NAME [(format)]; sub [(format)] {...} | ||
| 4922 | substr(EXPR,OFFSET[,LEN]) | ||
| 4923 | symlink(OLDFILE,NEWFILE) | ||
| 4924 | syscall(LIST) | ||
| 4925 | sysread(FILEHANDLE,SCALAR,LENGTH[,OFFSET]) | ||
| 4926 | system(LIST) | ||
| 4927 | syswrite(FILEHANDLE,SCALAR,LENGTH[,OFFSET]) | ||
| 4928 | tell[(FILEHANDLE)] | ||
| 4929 | telldir(DIRHANDLE) | ||
| 4930 | time | ||
| 4931 | times | ||
| 4932 | tr/SEARCHLIST/REPLACEMENTLIST/cds | ||
| 4933 | truncate(FILE|EXPR,LENGTH) | ||
| 4934 | umask[(EXPR)] | ||
| 4935 | undef[(EXPR)] | ||
| 4936 | unless (EXPR) { ... } [ else { ... } ] or EXPR unless EXPR | ||
| 4937 | unlink(LIST) | ||
| 4938 | unpack(TEMPLATE,EXPR) | ||
| 4939 | unshift(ARRAY,LIST) | ||
| 4940 | until (EXPR) { ... } EXPR until EXPR | ||
| 4941 | utime(LIST) | ||
| 4942 | values(%HASH) | ||
| 4943 | vec(EXPR,OFFSET,BITS) | ||
| 4944 | wait | ||
| 4945 | waitpid(PID,FLAGS) | ||
| 4946 | wantarray Returns true if the sub/eval is called in list context. | ||
| 4947 | warn(LIST) | ||
| 4948 | while (EXPR) { ... } EXPR while EXPR | ||
| 4949 | write[(EXPR|FILEHANDLE)] | ||
| 4950 | ... x ... Repeat string or array. | ||
| 4951 | x= ... Repetition assignment. | ||
| 4952 | y/SEARCHLIST/REPLACEMENTLIST/ | ||
| 4953 | ... | ... Bitwise or. | ||
| 4954 | ... || ... Logical or. | ||
| 4955 | ~ ... Unary bitwise complement. | ||
| 4956 | #! OS interpreter indicator. If has `perl', used for options, and -x. | ||
| 4957 | AUTOLOAD {...} Shorthand for `sub AUTOLOAD {...}'. | ||
| 4958 | CORE:: Prefix to access builtin function if imported sub obscures it. | ||
| 4959 | SUPER:: Prefix to lookup for a method in @ISA classes. | ||
| 4960 | DESTROY Shorthand for `sub DESTROY {...}'. | ||
| 4961 | ... EQ ... Obsolete synonym of `eq'. | ||
| 4962 | ... GE ... Obsolete synonym of `ge'. | ||
| 4963 | ... GT ... Obsolete synonym of `gt'. | ||
| 4964 | ... LE ... Obsolete synonym of `le'. | ||
| 4965 | ... LT ... Obsolete synonym of `lt'. | ||
| 4966 | ... NE ... Obsolete synonym of `ne'. | ||
| 4967 | abs [ EXPR ] absolute value | ||
| 4968 | ... and ... Low-precedence synonym for &&. | ||
| 4969 | bless REFERENCE [, PACKAGE] Makes reference into an object of a package. | ||
| 4970 | chomp [LIST] Strips $/ off LIST/$_. Returns count. Special if $/ eq ''! | ||
| 4971 | chr Converts a number to char with the same ordinal. | ||
| 4972 | else Part of if/unless {BLOCK} elsif {BLOCK} else {BLOCK}. | ||
| 4973 | elsif Part of if/unless {BLOCK} elsif {BLOCK} else {BLOCK}. | ||
| 4974 | exists $HASH{KEY} True if the key exists. | ||
| 4975 | format [NAME] = Start of output format. Ended by a single dot (.) on a line. | ||
| 4976 | formline PICTURE, LIST Backdoor into \"format\" processing. | ||
| 4977 | glob EXPR Synonym of <EXPR>. | ||
| 4978 | lc [ EXPR ] Returns lowercased EXPR. | ||
| 4979 | lcfirst [ EXPR ] Returns EXPR with lower-cased first letter. | ||
| 4980 | map EXPR, LIST or map {BLOCK} LIST Applies EXPR/BLOCK to elts of LIST. | ||
| 4981 | no PACKAGE [SYMBOL1, ...] Partial reverse for `use'. Runs `unimport' method. | ||
| 4982 | not ... Low-precedence synonym for ! - negation. | ||
| 4983 | ... or ... Low-precedence synonym for ||. | ||
| 4984 | pos STRING Set/Get end-position of the last match over this string, see \\G. | ||
| 4985 | quotemeta [ EXPR ] Quote regexp metacharacters. | ||
| 4986 | qw/WORD1 .../ Synonym of split('', 'WORD1 ...') | ||
| 4987 | readline FH Synonym of <FH>. | ||
| 4988 | readpipe CMD Synonym of `CMD`. | ||
| 4989 | ref [ EXPR ] Type of EXPR when dereferenced. | ||
| 4990 | sysopen FH, FILENAME, MODE [, PERM] (MODE is numeric, see Fcntl.) | ||
| 4991 | tie VAR, PACKAGE, LIST Hide an object behind a simple Perl variable. | ||
| 4992 | tied Returns internal object for a tied data. | ||
| 4993 | uc [ EXPR ] Returns upcased EXPR. | ||
| 4994 | ucfirst [ EXPR ] Returns EXPR with upcased first letter. | ||
| 4995 | untie VAR Unlink an object from a simple Perl variable. | ||
| 4996 | use PACKAGE [SYMBOL1, ...] Compile-time `require' with consequent `import'. | ||
| 4997 | ... xor ... Low-precedence synonym for exclusive or. | ||
| 4998 | prototype \&SUB Returns prototype of the function given a reference. | ||
| 4999 | =head1 Top-level heading. | ||
| 5000 | =head2 Second-level heading. | ||
| 5001 | =head3 Third-level heading (is there such?). | ||
| 5002 | =over [ NUMBER ] Start list. | ||
| 5003 | =item [ TITLE ] Start new item in the list. | ||
| 5004 | =back End list. | ||
| 5005 | =cut Switch from POD to Perl. | ||
| 5006 | =pod Switch from Perl to POD. | ||
| 5007 | ") | ||
| 5008 | |||
| 5009 | (defun cperl-switch-to-doc-buffer () | ||
| 5010 | "Go to the perl documentation buffer and insert the documentation." | ||
| 5011 | (interactive) | ||
| 5012 | (let ((buf (get-buffer-create cperl-doc-buffer))) | ||
| 5013 | (if (interactive-p) | ||
| 5014 | (switch-to-buffer-other-window buf) | ||
| 5015 | (set-buffer buf)) | ||
| 5016 | (if (= (buffer-size) 0) | ||
| 5017 | (progn | ||
| 5018 | (insert (documentation-property 'cperl-short-docs | ||
| 5019 | 'variable-documentation)) | ||
| 5020 | (setq buffer-read-only t))))) | ||
| 5021 | |||
| 5022 | (defun cperl-beautify-regexp-piece (b e embed) | ||
| 5023 | ;; b is before the starting delimiter, e before the ending | ||
| 5024 | ;; e should be a marker, may be changed, but remains "correct". | ||
| 5025 | (let (s c tmp (m (make-marker)) (m1 (make-marker)) c1 spaces inline code) | ||
| 5026 | (if (not embed) | ||
| 5027 | (goto-char (1+ b)) | ||
| 5028 | (goto-char b) | ||
| 5029 | (cond ((looking-at "(\\?\\\\#") ; badly commented (?#) | ||
| 5030 | (forward-char 2) | ||
| 5031 | (delete-char 1) | ||
| 5032 | (forward-char 1)) | ||
| 5033 | ((looking-at "(\\?[^a-zA-Z]") | ||
| 5034 | (forward-char 3)) | ||
| 5035 | ((looking-at "(\\?") ; (?i) | ||
| 5036 | (forward-char 2)) | ||
| 5037 | (t | ||
| 5038 | (forward-char 1)))) | ||
| 5039 | (setq c (if embed (current-indentation) (1- (current-column))) | ||
| 5040 | c1 (+ c (or cperl-regexp-indent-step cperl-indent-level))) | ||
| 5041 | (or (looking-at "[ \t]*[\n#]") | ||
| 5042 | (progn | ||
| 5043 | (insert "\n"))) | ||
| 5044 | (goto-char e) | ||
| 5045 | (beginning-of-line) | ||
| 5046 | (if (re-search-forward "[^ \t]" e t) | ||
| 5047 | (progn | ||
| 5048 | (goto-char e) | ||
| 5049 | (insert "\n") | ||
| 5050 | (indent-to-column c) | ||
| 5051 | (set-marker e (point)))) | ||
| 5052 | (goto-char b) | ||
| 5053 | (end-of-line 2) | ||
| 5054 | (while (< (point) (marker-position e)) | ||
| 5055 | (beginning-of-line) | ||
| 5056 | (setq s (point) | ||
| 5057 | inline t) | ||
| 5058 | (skip-chars-forward " \t") | ||
| 5059 | (delete-region s (point)) | ||
| 5060 | (indent-to-column c1) | ||
| 5061 | (while (and | ||
| 5062 | inline | ||
| 5063 | (looking-at | ||
| 5064 | (concat "\\([a-zA-Z0-9]+[^*+{?]\\)" ; 1 word | ||
| 5065 | "\\|" ; Embedded variable | ||
| 5066 | "\\$\\([a-zA-Z0-9_]+\\([[{]\\)?\\|[^\n \t)|]\\)" ; 2 3 | ||
| 5067 | "\\|" ; $ ^ | ||
| 5068 | "[$^]" | ||
| 5069 | "\\|" ; simple-code simple-code*? | ||
| 5070 | "\\(\\\\.\\|[^][()#|*+?\n]\\)\\([*+{?]\\??\\)?" ; 4 5 | ||
| 5071 | "\\|" ; Class | ||
| 5072 | "\\(\\[\\)" ; 6 | ||
| 5073 | "\\|" ; Grouping | ||
| 5074 | "\\((\\(\\?\\)?\\)" ; 7 8 | ||
| 5075 | "\\|" ; | | ||
| 5076 | "\\(|\\)" ; 9 | ||
| 5077 | ))) | ||
| 5078 | (goto-char (match-end 0)) | ||
| 5079 | (setq spaces t) | ||
| 5080 | (cond ((match-beginning 1) ; Alphanum word + junk | ||
| 5081 | (forward-char -1)) | ||
| 5082 | ((or (match-beginning 3) ; $ab[12] | ||
| 5083 | (and (match-beginning 5) ; X* X+ X{2,3} | ||
| 5084 | (eq (preceding-char) ?\{))) | ||
| 5085 | (forward-char -1) | ||
| 5086 | (forward-sexp 1)) | ||
| 5087 | ((match-beginning 6) ; [] | ||
| 5088 | (setq tmp (point)) | ||
| 5089 | (if (looking-at "\\^?\\]") | ||
| 5090 | (goto-char (match-end 0))) | ||
| 5091 | (or (re-search-forward "\\]\\([*+{?]\\)?" e t) | ||
| 5092 | (progn | ||
| 5093 | (goto-char (1- tmp)) | ||
| 5094 | (error "[]-group not terminated"))) | ||
| 5095 | (if (not (eq (preceding-char) ?\{)) nil | ||
| 5096 | (forward-char -1) | ||
| 5097 | (forward-sexp 1))) | ||
| 5098 | ((match-beginning 7) ; () | ||
| 5099 | (goto-char (match-beginning 0)) | ||
| 5100 | (or (eq (current-column) c1) | ||
| 5101 | (progn | ||
| 5102 | (insert "\n") | ||
| 5103 | (indent-to-column c1))) | ||
| 5104 | (setq tmp (point)) | ||
| 5105 | (forward-sexp 1) | ||
| 5106 | ;; (or (forward-sexp 1) | ||
| 5107 | ;; (progn | ||
| 5108 | ;; (goto-char tmp) | ||
| 5109 | ;; (error "()-group not terminated"))) | ||
| 5110 | (set-marker m (1- (point))) | ||
| 5111 | (set-marker m1 (point)) | ||
| 5112 | (cond | ||
| 5113 | ((not (match-beginning 8)) | ||
| 5114 | (cperl-beautify-regexp-piece tmp m t)) | ||
| 5115 | ((eq (char-after (+ 2 tmp)) ?\{) ; Code | ||
| 5116 | t) | ||
| 5117 | ((eq (char-after (+ 2 tmp)) ?\() ; Conditional | ||
| 5118 | (goto-char (+ 2 tmp)) | ||
| 5119 | (forward-sexp 1) | ||
| 5120 | (cperl-beautify-regexp-piece (point) m t)) | ||
| 5121 | (t | ||
| 5122 | (cperl-beautify-regexp-piece tmp m t))) | ||
| 5123 | (goto-char m1) | ||
| 5124 | (cond ((looking-at "[*+?]\\??") | ||
| 5125 | (goto-char (match-end 0))) | ||
| 5126 | ((eq (following-char) ?\{) | ||
| 5127 | (forward-sexp 1) | ||
| 5128 | (if (eq (following-char) ?\?) | ||
| 5129 | (forward-char)))) | ||
| 5130 | (skip-chars-forward " \t") | ||
| 5131 | (setq spaces nil) | ||
| 5132 | (if (looking-at "[#\n]") | ||
| 5133 | (progn | ||
| 5134 | (or (eolp) (indent-for-comment)) | ||
| 5135 | (beginning-of-line 2)) | ||
| 5136 | (insert "\n")) | ||
| 5137 | (end-of-line) | ||
| 5138 | (setq inline nil)) | ||
| 5139 | ((match-beginning 9) ; | | ||
| 5140 | (forward-char -1) | ||
| 5141 | (setq tmp (point)) | ||
| 5142 | (beginning-of-line) | ||
| 5143 | (if (re-search-forward "[^ \t]" tmp t) | ||
| 5144 | (progn | ||
| 5145 | (goto-char tmp) | ||
| 5146 | (insert "\n")) | ||
| 5147 | ;; first at line | ||
| 5148 | (delete-region (point) tmp)) | ||
| 5149 | (indent-to-column c) | ||
| 5150 | (forward-char 1) | ||
| 5151 | (skip-chars-forward " \t") | ||
| 5152 | (setq spaces nil) | ||
| 5153 | (if (looking-at "[#\n]") | ||
| 5154 | (beginning-of-line 2) | ||
| 5155 | (insert "\n")) | ||
| 5156 | (end-of-line) | ||
| 5157 | (setq inline nil))) | ||
| 5158 | (or (looking-at "[ \t\n]") | ||
| 5159 | (not spaces) | ||
| 5160 | (insert " ")) | ||
| 5161 | (skip-chars-forward " \t")) | ||
| 5162 | (or (looking-at "[#\n]") | ||
| 5163 | (error "unknown code \"%s\" in a regexp" (buffer-substring (point) | ||
| 5164 | (1+ (point))))) | ||
| 5165 | (and inline (end-of-line 2))) | ||
| 5166 | ;; Special-case the last line of group | ||
| 5167 | (if (and (>= (point) (marker-position e)) | ||
| 5168 | (/= (current-indentation) c)) | ||
| 5169 | (progn | ||
| 5170 | (beginning-of-line) | ||
| 5171 | (setq s (point)) | ||
| 5172 | (skip-chars-forward " \t") | ||
| 5173 | (delete-region s (point)) | ||
| 5174 | (indent-to-column c))) | ||
| 5175 | )) | ||
| 5176 | |||
| 5177 | (defun cperl-make-regexp-x () | ||
| 5178 | (save-excursion | ||
| 5179 | (or cperl-use-syntax-table-text-property | ||
| 5180 | (error "I need to have regex marked!")) | ||
| 5181 | ;; Find the start | ||
| 5182 | (re-search-backward "\\s|") ; Assume it is scanned already. | ||
| 5183 | ;;(forward-char 1) | ||
| 5184 | (let ((b (point)) (e (make-marker)) have-x delim (c (current-column)) | ||
| 5185 | (sub-p (eq (preceding-char) ?s)) s) | ||
| 5186 | (forward-sexp 1) | ||
| 5187 | (set-marker e (1- (point))) | ||
| 5188 | (setq delim (preceding-char)) | ||
| 5189 | (if (and sub-p (eq delim (char-after (- (point) 2)))) | ||
| 5190 | (error "Possible s/blah// - do not know how to deal with")) | ||
| 5191 | (if sub-p (forward-sexp 1)) | ||
| 5192 | (if (looking-at "\\sw*x") | ||
| 5193 | (setq have-x t) | ||
| 5194 | (insert "x")) | ||
| 5195 | ;; Protect fragile " ", "#" | ||
| 5196 | (if have-x nil | ||
| 5197 | (goto-char (1+ b)) | ||
| 5198 | (while (re-search-forward "\\(\\=\\|[^\\\\]\\)\\(\\\\\\\\\\)*[ \t\n#]" e t) ; Need to include (?#) too? | ||
| 5199 | (forward-char -1) | ||
| 5200 | (insert "\\") | ||
| 5201 | (forward-char 1))) | ||
| 5202 | b))) | ||
| 5203 | |||
| 5204 | (defun cperl-beautify-regexp () | ||
| 5205 | "do it. (Experimental, may change semantics, recheck the result.) | ||
| 5206 | We suppose that the regexp is scanned already." | ||
| 5207 | (interactive) | ||
| 5208 | (cperl-make-regexp-x) | ||
| 5209 | (re-search-backward "\\s|") ; Assume it is scanned already. | ||
| 5210 | ;;(forward-char 1) | ||
| 5211 | (let ((b (point)) (e (make-marker))) | ||
| 5212 | (forward-sexp 1) | ||
| 5213 | (set-marker e (1- (point))) | ||
| 5214 | (cperl-beautify-regexp-piece b e nil))) | ||
| 5215 | |||
| 5216 | (defun cperl-contract-level () | ||
| 5217 | "Find an enclosing group in regexp and contract it. Unfinished. | ||
| 5218 | \(Experimental, may change semantics, recheck the result.) | ||
| 5219 | We suppose that the regexp is scanned already." | ||
| 5220 | (interactive) | ||
| 5221 | (let ((bb (cperl-make-regexp-x)) done) | ||
| 5222 | (while (not done) | ||
| 5223 | (or (eq (following-char) ?\() | ||
| 5224 | (search-backward "(" (1+ bb) t) | ||
| 5225 | (error "Cannot find `(' which starts a group")) | ||
| 5226 | (setq done | ||
| 5227 | (save-excursion | ||
| 5228 | (skip-chars-backward "\\") | ||
| 5229 | (looking-at "\\(\\\\\\\\\\)*("))) | ||
| 5230 | (or done (forward-char -1))) | ||
| 5231 | (let ((b (point)) (e (make-marker)) s c) | ||
| 5232 | (forward-sexp 1) | ||
| 5233 | (set-marker e (1- (point))) | ||
| 5234 | (goto-char b) | ||
| 5235 | (while (re-search-forward "\\(#\\)\\|\n" e t) | ||
| 5236 | (cond | ||
| 5237 | ((match-beginning 1) ; #-comment | ||
| 5238 | (or c (setq c (current-indentation))) | ||
| 5239 | (beginning-of-line 2) ; Skip | ||
| 5240 | (setq s (point)) | ||
| 5241 | (skip-chars-forward " \t") | ||
| 5242 | (delete-region s (point)) | ||
| 5243 | (indent-to-column c)) | ||
| 5244 | (t | ||
| 5245 | (delete-char -1) | ||
| 5246 | (just-one-space))))))) | ||
| 5247 | |||
| 5248 | (defun cperl-beautify-level () | ||
| 5249 | "Find an enclosing group in regexp and beautify it. | ||
| 5250 | \(Experimental, may change semantics, recheck the result.) | ||
| 5251 | We suppose that the regexp is scanned already." | ||
| 5252 | (interactive) | ||
| 5253 | (let ((bb (cperl-make-regexp-x)) done) | ||
| 5254 | (while (not done) | ||
| 5255 | (or (eq (following-char) ?\() | ||
| 5256 | (search-backward "(" (1+ bb) t) | ||
| 5257 | (error "Cannot find `(' which starts a group")) | ||
| 5258 | (setq done | ||
| 5259 | (save-excursion | ||
| 5260 | (skip-chars-backward "\\") | ||
| 5261 | (looking-at "\\(\\\\\\\\\\)*("))) | ||
| 5262 | (or done (forward-char -1))) | ||
| 5263 | (let ((b (point)) (e (make-marker))) | ||
| 5264 | (forward-sexp 1) | ||
| 5265 | (set-marker e (1- (point))) | ||
| 5266 | (cperl-beautify-regexp-piece b e nil)))) | ||
| 5267 | |||
| 5268 | (if (fboundp 'run-with-idle-timer) | ||
| 5269 | (progn | ||
| 5270 | (defvar cperl-help-shown nil | ||
| 5271 | "Non-nil means that the help was already shown now.") | ||
| 5272 | |||
| 5273 | (defvar cperl-lazy-installed nil | ||
| 5274 | "Non-nil means that the lazy-help handlers are installed now.") | ||
| 5275 | |||
| 5276 | (defun cperl-lazy-install () | ||
| 5277 | (interactive) | ||
| 5278 | (make-variable-buffer-local 'cperl-help-shown) | ||
| 5279 | (if (and (cperl-val 'cperl-lazy-help-time) | ||
| 5280 | (not cperl-lazy-installed)) | ||
| 5281 | (progn | ||
| 5282 | (add-hook 'post-command-hook 'cperl-lazy-hook) | ||
| 5283 | (run-with-idle-timer | ||
| 5284 | (cperl-val 'cperl-lazy-help-time 1000000 5) | ||
| 5285 | t | ||
| 5286 | 'cperl-get-help-defer) | ||
| 5287 | (setq cperl-lazy-installed t)))) | ||
| 5288 | |||
| 5289 | (defun cperl-lazy-unstall () | ||
| 5290 | (interactive) | ||
| 5291 | (remove-hook 'post-command-hook 'cperl-lazy-hook) | ||
| 5292 | (cancel-function-timers 'cperl-get-help-defer) | ||
| 5293 | (setq cperl-lazy-installed nil)) | ||
| 5294 | |||
| 5295 | (defun cperl-lazy-hook () | ||
| 5296 | (setq cperl-help-shown nil)) | ||
| 5297 | |||
| 5298 | (defun cperl-get-help-defer () | ||
| 5299 | (if (not (eq major-mode 'perl-mode)) nil | ||
| 5300 | (let ((cperl-message-on-help-error nil) (cperl-help-from-timer t)) | ||
| 5301 | (cperl-get-help) | ||
| 5302 | (setq cperl-help-shown t)))) | ||
| 5303 | (cperl-lazy-install))) | ||
| 5304 | |||
| 5305 | (provide 'cperl-mode) | ||
| 5306 | |||
| 5307 | ;;; cperl-mode.el ends here | ||