]> code.delx.au - gnu-emacs/blobdiff - lisp/progmodes/perl-mode.el
* lisp/progmodes/cperl-mode.el (cperl-update-syntaxification):
[gnu-emacs] / lisp / progmodes / perl-mode.el
index 1bc9a397bc75a07fa81065c301a5c76152b01bf7..26c6e5a9f03cc49fb0d64731a170a751dfcb2e73 100644 (file)
@@ -1,7 +1,6 @@
 ;;; perl-mode.el --- Perl code editing commands for GNU Emacs
 
-;; Copyright (C) 1990, 1994, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
-;;   2008, 2009, 2010  Free Software Foundation, Inc.
+;; Copyright (C) 1990, 1994, 2001-2012  Free Software Foundation, Inc.
 
 ;; Author: William F. Mann
 ;; Maintainer: FSF
@@ -167,7 +166,7 @@ The expansion is entirely correct because it uses the C preprocessor."
   '(;; Functions
     (nil "^sub\\s-+\\([-A-Za-z0-9+_:]+\\)" 1)
     ;;Variables
-    ("Variables" "^\\([$@%][-A-Za-z0-9+_:]+\\)\\s-*=" 1)
+    ("Variables" "^\\(?:my\\|our\\)\\s-+\\([$@%][-A-Za-z0-9+_:]+\\)\\s-*=" 1)
     ("Packages" "^package\\s-+\\([-A-Za-z0-9+_:]+\\);" 1)
     ("Doc sections" "^=head[0-9][ \t]+\\(.*\\)" 1))
   "Imenu generic expression for Perl mode.  See `imenu-generic-expression'.")
@@ -305,11 +304,12 @@ The expansion is entirely correct because it uses the C preprocessor."
              (put-text-property (match-beginning 2) (match-end 2)
                                 'syntax-table (string-to-syntax "\""))
              (perl-syntax-propertize-special-constructs end)))))
-      ("\\(^\\|[?:.,;=!~({[ \t]\\)\\([msy]\\|q[qxrw]?\\|tr\\)\\>\\s-*\\([^])}> \n\t]\\)"
+      ("\\(^\\|[?:.,;=!~({[ \t]\\)\\([msy]\\|q[qxrw]?\\|tr\\)\\>\\s-*\\(?:\\([^])}>= \n\t]\\)\\|\\(?3:=\\)[^>]\\)"
        ;; Nasty cases:
        ;; /foo/m  $a->m  $#m $m @m %m
        ;; \s (appears often in regexps).
        ;; -s file
+       ;; y => 3
        ;; sub tr {...}
        (3 (ignore
            (if (save-excursion (goto-char (match-beginning 0))
@@ -360,7 +360,8 @@ The expansion is entirely correct because it uses the C preprocessor."
      (t
       ;; This is regexp like quote thingy.
       (setq char (char-after (nth 8 state)))
-      (let ((twoargs (save-excursion
+      (let ((startpos (point))
+            (twoargs (save-excursion
                        (goto-char (nth 8 state))
                        (skip-syntax-backward " ")
                        (skip-syntax-backward "w")
@@ -377,16 +378,21 @@ The expansion is entirely correct because it uses the C preprocessor."
                    ;; we are: we have to go back to the beginning of this
                    ;; "string" and count from there.
                    (condition-case nil
-                        (progn
+                       (progn
                          ;; Start after the first char since it doesn't have
                          ;; paren-syntax (an alternative would be to let-bind
                          ;; parse-sexp-lookup-properties).
                          (goto-char (1+ (nth 8 state)))
                          (up-list 1)
                          t)
-                     (scan-error nil))
+                      ;; In case of error, make sure we don't move backward.
+                     (scan-error (goto-char startpos) nil))
                  (not (or (nth 8 (parse-partial-sexp
-                                  (point) limit nil nil state 'syntax-table))
+                                  ;; Since we don't know if point is within
+                                  ;; the first or the scond arg, we have to
+                                  ;; start from the beginning.
+                                  (if twoargs (1+ (nth 8 state)) (point))
+                                  limit nil nil state 'syntax-table))
                           ;; If we have a self-paired opener and a twoargs
                           ;; command, the form is s/../../ so we have to skip
                           ;; a second time.
@@ -409,17 +415,17 @@ The expansion is entirely correct because it uses the C preprocessor."
          ;; s{...}{...}) we're right after the first arg, so we still have to
          ;; handle the second part.
          (when (and twoargs close)
-            ;; Skip whitespace and make sure that font-lock will
-            ;; refontify the second part in the proper context.
-            (put-text-property
-             (point) (progn (forward-comment (point-max)) (point))
+           ;; Skip whitespace and make sure that font-lock will
+           ;; refontify the second part in the proper context.
+           (put-text-property
+            (point) (progn (forward-comment (point-max)) (point))
             'syntax-multiline t)
-            ;;
+           ;;
            (when (< (point) limit)
-              (put-text-property (point) (1+ (point))
-                                 'syntax-table
-                                 (if (assoc (char-after)
-                                            perl-quote-like-pairs)
+             (put-text-property (point) (1+ (point))
+                                'syntax-table
+                                (if (assoc (char-after)
+                                           perl-quote-like-pairs)
                                      ;; Put an `e' in the cdr to mark this
                                      ;; char as "second arg starter".
                                     (string-to-syntax "|e")
@@ -545,7 +551,7 @@ create a new comment."
   "Normal hook to run when entering Perl mode.")
 
 ;;;###autoload
-(defun perl-mode ()
+(define-derived-mode perl-mode prog-mode "Perl"
   "Major mode for editing Perl code.
 Expression and list commands understand all Perl brackets.
 Tab indents for Perl code.
@@ -592,33 +598,16 @@ Various indentation styles:       K&R  BSD  BLK  GNU  LW
   perl-label-offset               -5   -8   -2   -2   -2
 
 Turning on Perl mode runs the normal hook `perl-mode-hook'."
-  (interactive)
-  (kill-all-local-variables)
-  (use-local-map perl-mode-map)
-  (setq major-mode 'perl-mode)
-  (setq mode-name "Perl")
-  (setq local-abbrev-table perl-mode-abbrev-table)
-  (set-syntax-table perl-mode-syntax-table)
-  (make-local-variable 'paragraph-start)
-  (setq paragraph-start (concat "$\\|" page-delimiter))
-  (make-local-variable 'paragraph-separate)
-  (setq paragraph-separate paragraph-start)
-  (make-local-variable 'paragraph-ignore-fill-prefix)
-  (setq paragraph-ignore-fill-prefix t)
-  (make-local-variable 'indent-line-function)
-  (setq indent-line-function 'perl-indent-line)
-  (make-local-variable 'require-final-newline)
-  (setq require-final-newline mode-require-final-newline)
-  (make-local-variable 'comment-start)
-  (setq comment-start "# ")
-  (make-local-variable 'comment-end)
-  (setq comment-end "")
-  (make-local-variable 'comment-start-skip)
-  (setq comment-start-skip "\\(^\\|\\s-\\);?#+ *")
-  (make-local-variable 'comment-indent-function)
-  (setq comment-indent-function 'perl-comment-indent)
-  (make-local-variable 'parse-sexp-ignore-comments)
-  (setq parse-sexp-ignore-comments t)
+  :abbrev-table perl-mode-abbrev-table
+  (set (make-local-variable 'paragraph-start) (concat "$\\|" page-delimiter))
+  (set (make-local-variable 'paragraph-separate) paragraph-start)
+  (set (make-local-variable 'paragraph-ignore-fill-prefix) t)
+  (set (make-local-variable 'indent-line-function) #'perl-indent-line)
+  (set (make-local-variable 'comment-start) "# ")
+  (set (make-local-variable 'comment-end) "")
+  (set (make-local-variable 'comment-start-skip) "\\(^\\|\\s-\\);?#+ *")
+  (set (make-local-variable 'comment-indent-function) #'perl-comment-indent)
+  (set (make-local-variable 'parse-sexp-ignore-comments) t)
   ;; Tell font-lock.el how to handle Perl.
   (setq font-lock-defaults '((perl-font-lock-keywords
                              perl-font-lock-keywords-1
@@ -636,8 +625,7 @@ Turning on Perl mode runs the normal hook `perl-mode-hook'."
   (setq imenu-case-fold-search nil)
   ;; Setup outline-minor-mode.
   (set (make-local-variable 'outline-regexp) perl-outline-regexp)
-  (set (make-local-variable 'outline-level) 'perl-outline-level)
-  (run-mode-hooks 'perl-mode-hook))
+  (set (make-local-variable 'outline-level) 'perl-outline-level))
 \f
 ;; This is used by indent-for-comment
 ;; to decide how much to indent a comment in Perl code
@@ -649,8 +637,8 @@ Turning on Perl mode runs the normal hook `perl-mode-hook'."
 
 (defalias 'electric-perl-terminator 'perl-electric-terminator)
 (defun perl-electric-terminator (arg)
-  "Insert character and adjust indentation.
-If at end-of-line, and not in a comment or a quote, correct the's indentation."
+  "Insert character and maybe adjust indentation.
+If at end-of-line, and not in a comment or a quote, correct the indentation."
   (interactive "P")
   (let ((insertpos (point)))
     (and (not arg)                     ; decide whether to indent
@@ -768,6 +756,7 @@ changed by, or (parse-state) if line starts in a quoted string."
     (setq shift-amt
          (cond ((eq (char-after bof) ?=) 0)
                ((listp (setq indent (perl-calculate-indent bof))) indent)
+                ((eq 'noindent indent) indent)
                ((looking-at (or nochange perl-nochange)) 0)
                (t
                 (skip-chars-forward " \t\f")
@@ -848,7 +837,11 @@ Optional argument PARSE-START should be the position of `beginning-of-defun'."
                  (save-excursion
                    (beginning-of-line)
                    (looking-at "\\s-+sub\\>"))
-                 (> indent-point (save-excursion (forward-sexp 1) (point))))
+                 (> indent-point (save-excursion
+                                   (condition-case nil
+                                       (forward-sexp 1)
+                                     (scan-error nil))
+                                   (point))))
        (perl-beginning-of-function))
       (while (< (point) indent-point)  ;repeat until right sexp
        (setq state (parse-partial-sexp (point) indent-point 0))
@@ -857,7 +850,7 @@ Optional argument PARSE-START should be the position of `beginning-of-defun'."
        ;;          following_quotep minimum_paren-depth_this_scan)
        ;; Parsing stops if depth in parentheses becomes equal to third arg.
        (setq containing-sexp (nth 1 state)))
-      (cond ((nth 3 state) state)      ; In a quoted string?
+      (cond ((nth 3 state) 'noindent)  ; In a quoted string?
            ((null containing-sexp)     ; Line is at top level.
             (skip-chars-forward " \t\f")
             (if (= (following-char) ?{)
@@ -879,7 +872,7 @@ Optional argument PARSE-START should be the position of `beginning-of-defun'."
                 ;;         );
                 (progn
                   (skip-syntax-backward "(")
-                  (condition-case err
+                  (condition-case nil
                       (while (save-excursion
                                (skip-syntax-backward " ") (not (bolp)))
                         (forward-sexp -1))
@@ -920,9 +913,7 @@ Optional argument PARSE-START should be the position of `beginning-of-defun'."
                           (cond ((looking-at ";?#")
                                  (forward-line 1) t)
                                 ((looking-at "\\(\\w\\|\\s_\\)+:[^:]")
-                                 (save-excursion
-                                   (end-of-line)
-                                   (setq colon-line-end (point)))
+                                 (setq colon-line-end (line-end-position))
                                  (search-forward ":")))))
                  ;; The first following code counts
                  ;; if it is before the line we want to indent.
@@ -982,7 +973,7 @@ Optional argument PARSE-START should be the position of `beginning-of-defun'."
     (if (= (char-after (marker-position bof-mark)) ?=)
        (message "Can't indent a format statement")
       (message "Indenting Perl expression...")
-      (save-excursion (end-of-line) (setq eol (point)))
+      (setq eol (line-end-position))
       (save-excursion                  ; locate matching close paren
        (while (and (not (eobp)) (<= (point) eol))
          (parse-partial-sexp (point) (point-max) 0))
@@ -1080,5 +1071,4 @@ With argument, repeat that many times; negative args move backward."
 
 (provide 'perl-mode)
 
-;; arch-tag: 8c7ff68d-15f3-46a2-ade2-b7c41f176826
 ;;; perl-mode.el ends here