aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/progmodes/perl-mode.el
diff options
context:
space:
mode:
authorStefan Monnier <[email protected]>2002-11-12 21:03:37 +0000
committerStefan Monnier <[email protected]>2002-11-12 21:03:37 +0000
commit2a4407be87a08186fa8557036b1760f114a3222e (patch)
tree08157a3c9fdbc8fc5943dd6cc522b8af7bea39ee /lisp/progmodes/perl-mode.el
parent3ceb4629cfc85bb7210786d7bb66b85f6a92acfd (diff)
(perl-hanging-paren-p): New fun.
(perl-indent-line): Look at the open-paren to indent a close-paren. (perl-calculate-indent): Try to better indent args after hanging paren. Remove special code for open-paren-in-column-0.
Diffstat (limited to 'lisp/progmodes/perl-mode.el')
-rw-r--r--lisp/progmodes/perl-mode.el51
1 files changed, 37 insertions, 14 deletions
diff --git a/lisp/progmodes/perl-mode.el b/lisp/progmodes/perl-mode.el
index 626310a226..5eaee97e74 100644
--- a/lisp/progmodes/perl-mode.el
+++ b/lisp/progmodes/perl-mode.el
@@ -638,8 +638,16 @@ changed by, or (parse-state) if line starts in a quoted string."
(skip-chars-forward " \t\f")
(cond ((looking-at "\\(\\w\\|\\s_\\)+:[^:]")
(setq indent (max 1 (+ indent perl-label-offset))))
- ((= (following-char) ?})
- (setq indent (- indent perl-indent-level)))
+ ((= (char-syntax (following-char)) ?\))
+ (setq indent
+ (save-excursion
+ (forward-char 1)
+ (forward-sexp -1)
+ (forward-char 1)
+ (if (perl-hanging-paren-p)
+ (- indent perl-indent-level)
+ (forward-char -1)
+ (current-column)))))
((= (following-char) ?{)
(setq indent (+ indent perl-brace-offset))))
(- indent (current-column)))))
@@ -671,6 +679,12 @@ changed by, or (parse-state) if line starts in a quoted string."
;; Now we get the answer.
(not (memq (preceding-char) '(?\; ?\} ?\{))))
+(defun perl-hanging-paren-p ()
+ "Non-nil if we are right after a hanging parenthesis-like char."
+ (and (looking-at "[ \t]*$")
+ (save-excursion
+ (skip-syntax-backward " (") (not (bolp)))))
+
(defun perl-calculate-indent (&optional parse-start)
"Return appropriate indentation for current line as Perl code.
In usual case returns an integer: the column to indent to.
@@ -715,10 +729,24 @@ Optional argument PARSE-START should be the position of `beginning-of-defun'."
;; line is expression, not statement:
;; indent to just after the surrounding open.
(goto-char (1+ containing-sexp))
- (if perl-indent-continued-arguments
- (+ perl-indent-continued-arguments (current-indentation))
- (skip-chars-forward " \t")
- (current-column)))
+ (if (perl-hanging-paren-p)
+ ;; We're indenting an arg of a call like:
+ ;; $a = foobarlongnamefun (
+ ;; arg1
+ ;; arg2
+ ;; );
+ (progn
+ (skip-syntax-backward "(")
+ (condition-case err
+ (while (save-excursion
+ (skip-syntax-backward " ") (not (bolp)))
+ (forward-sexp -1))
+ (scan-error nil))
+ (+ (current-column) perl-indent-level))
+ (if perl-indent-continued-arguments
+ (+ perl-indent-continued-arguments (current-indentation))
+ (skip-chars-forward " \t")
+ (current-column))))
(t
;; Statement level. Is it a continuation or a new statement?
(if (perl-continuation-line-p containing-sexp)
@@ -740,14 +768,9 @@ Optional argument PARSE-START should be the position of `beginning-of-defun'."
;; Position at last unclosed open.
(goto-char containing-sexp)
(or
- ;; If open paren is in col 0, close brace is special
- (and (bolp)
- (save-excursion (goto-char indent-point)
- (looking-at "[ \t]*}"))
- perl-indent-level)
- ;; Is line first statement after an open-brace?
- ;; If no, find that first statement and indent like it.
- (save-excursion
+ ;; Is line first statement after an open-brace?
+ ;; If no, find that first statement and indent like it.
+ (save-excursion
(forward-char 1)
;; Skip over comments and labels following openbrace.
(while (progn