aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2002-11-12 21:03:37 +0000
committerStefan Monnier2002-11-12 21:03:37 +0000
commit2a4407be87a08186fa8557036b1760f114a3222e (patch)
tree08157a3c9fdbc8fc5943dd6cc522b8af7bea39ee
parent3ceb4629cfc85bb7210786d7bb66b85f6a92acfd (diff)
downloademacs-2a4407be87a08186fa8557036b1760f114a3222e.tar.gz
emacs-2a4407be87a08186fa8557036b1760f114a3222e.zip
(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.
-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 626310a2261..5eaee97e74f 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."
638 (skip-chars-forward " \t\f") 638 (skip-chars-forward " \t\f")
639 (cond ((looking-at "\\(\\w\\|\\s_\\)+:[^:]") 639 (cond ((looking-at "\\(\\w\\|\\s_\\)+:[^:]")
640 (setq indent (max 1 (+ indent perl-label-offset)))) 640 (setq indent (max 1 (+ indent perl-label-offset))))
641 ((= (following-char) ?}) 641 ((= (char-syntax (following-char)) ?\))
642 (setq indent (- indent perl-indent-level))) 642 (setq indent
643 (save-excursion
644 (forward-char 1)
645 (forward-sexp -1)
646 (forward-char 1)
647 (if (perl-hanging-paren-p)
648 (- indent perl-indent-level)
649 (forward-char -1)
650 (current-column)))))
643 ((= (following-char) ?{) 651 ((= (following-char) ?{)
644 (setq indent (+ indent perl-brace-offset)))) 652 (setq indent (+ indent perl-brace-offset))))
645 (- indent (current-column))))) 653 (- indent (current-column)))))
@@ -671,6 +679,12 @@ changed by, or (parse-state) if line starts in a quoted string."
671 ;; Now we get the answer. 679 ;; Now we get the answer.
672 (not (memq (preceding-char) '(?\; ?\} ?\{)))) 680 (not (memq (preceding-char) '(?\; ?\} ?\{))))
673 681
682(defun perl-hanging-paren-p ()
683 "Non-nil if we are right after a hanging parenthesis-like char."
684 (and (looking-at "[ \t]*$")
685 (save-excursion
686 (skip-syntax-backward " (") (not (bolp)))))
687
674(defun perl-calculate-indent (&optional parse-start) 688(defun perl-calculate-indent (&optional parse-start)
675 "Return appropriate indentation for current line as Perl code. 689 "Return appropriate indentation for current line as Perl code.
676In usual case returns an integer: the column to indent to. 690In 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'."
715 ;; line is expression, not statement: 729 ;; line is expression, not statement:
716 ;; indent to just after the surrounding open. 730 ;; indent to just after the surrounding open.
717 (goto-char (1+ containing-sexp)) 731 (goto-char (1+ containing-sexp))
718 (if perl-indent-continued-arguments 732 (if (perl-hanging-paren-p)
719 (+ perl-indent-continued-arguments (current-indentation)) 733 ;; We're indenting an arg of a call like:
720 (skip-chars-forward " \t") 734 ;; $a = foobarlongnamefun (
721 (current-column))) 735 ;; arg1
736 ;; arg2
737 ;; );
738 (progn
739 (skip-syntax-backward "(")
740 (condition-case err
741 (while (save-excursion
742 (skip-syntax-backward " ") (not (bolp)))
743 (forward-sexp -1))
744 (scan-error nil))
745 (+ (current-column) perl-indent-level))
746 (if perl-indent-continued-arguments
747 (+ perl-indent-continued-arguments (current-indentation))
748 (skip-chars-forward " \t")
749 (current-column))))
722 (t 750 (t
723 ;; Statement level. Is it a continuation or a new statement? 751 ;; Statement level. Is it a continuation or a new statement?
724 (if (perl-continuation-line-p containing-sexp) 752 (if (perl-continuation-line-p containing-sexp)
@@ -740,14 +768,9 @@ Optional argument PARSE-START should be the position of `beginning-of-defun'."
740 ;; Position at last unclosed open. 768 ;; Position at last unclosed open.
741 (goto-char containing-sexp) 769 (goto-char containing-sexp)
742 (or 770 (or
743 ;; If open paren is in col 0, close brace is special 771 ;; Is line first statement after an open-brace?
744 (and (bolp) 772 ;; If no, find that first statement and indent like it.
745 (save-excursion (goto-char indent-point) 773 (save-excursion
746 (looking-at "[ \t]*}"))
747 perl-indent-level)
748 ;; Is line first statement after an open-brace?
749 ;; If no, find that first statement and indent like it.
750 (save-excursion
751 (forward-char 1) 774 (forward-char 1)
752 ;; Skip over comments and labels following openbrace. 775 ;; Skip over comments and labels following openbrace.
753 (while (progn 776 (while (progn