Mercurial > emacs
changeset 48268:3177076ca9a1
(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.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Tue, 12 Nov 2002 21:03:37 +0000 |
parents | 0f40d654e6c3 |
children | b4a43403c371 |
files | lisp/progmodes/perl-mode.el |
diffstat | 1 files changed, 37 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/lisp/progmodes/perl-mode.el Tue Nov 12 20:41:14 2002 +0000 +++ b/lisp/progmodes/perl-mode.el Tue Nov 12 21:03:37 2002 +0000 @@ -638,8 +638,16 @@ (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 @@ ;; 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 @@ ;; 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 @@ ;; 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