aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabián Ezequiel Gallina2015-01-28 01:08:18 -0300
committerFabián Ezequiel Gallina2015-01-28 01:08:18 -0300
commit95a2cb24b0697558e6629460d8bc693b394f0138 (patch)
treecf6cc03950fc6b0982497f00ff6c92eec1912b45
parentf5ebe84d75bb75156db9e2e0a7ab356941b4ea75 (diff)
parent9664defd262252faf037c5fe1ea095f1cc4b308b (diff)
downloademacs-95a2cb24b0697558e6629460d8bc693b394f0138.tar.gz
emacs-95a2cb24b0697558e6629460d8bc693b394f0138.zip
Merge from origin/emacs-24
9664def Signal a file-error from directory-files on MS-Windows (Bug#19701) fd4e65e Added missing test for previous commit 5485e3e5 python.el: New non-global state dependent indentation engine. 3b23e6a Fix the description of --insert command-line option (Bug#19694) 7a7e594 Add a cross-reference in ELisp manual. (Bug#19668) b4f4075 Fixes: debbugs:19660 83b3c31 * test/automated/regexp-tests.el: Require regexp-opt Conflicts: lisp/progmodes/python.el
-rw-r--r--doc/emacs/ChangeLog5
-rw-r--r--doc/emacs/cmdargs.texi9
-rw-r--r--doc/lispref/ChangeLog5
-rw-r--r--doc/lispref/searching.texi9
-rw-r--r--lisp/ChangeLog20
-rw-r--r--lisp/progmodes/python.el702
-rw-r--r--src/ChangeLog13
-rw-r--r--src/dired.c13
-rw-r--r--src/nsterm.m2
-rw-r--r--src/w32.c17
-rw-r--r--test/ChangeLog27
-rw-r--r--test/automated/python-tests.el582
-rw-r--r--test/automated/regexp-tests.el2
13 files changed, 917 insertions, 489 deletions
diff --git a/doc/emacs/ChangeLog b/doc/emacs/ChangeLog
index 329da9418f8..718657a360b 100644
--- a/doc/emacs/ChangeLog
+++ b/doc/emacs/ChangeLog
@@ -1,3 +1,8 @@
12015-01-26 Eli Zaretskii <eliz@gnu.org>
2
3 * cmdargs.texi (Action Arguments): Clarify into which buffer
4 '--insert' inserts. (Bug#19694)
5
12015-01-21 Eli Zaretskii <eliz@gnu.org> 62015-01-21 Eli Zaretskii <eliz@gnu.org>
2 7
3 * programs.texi (Custom C Indent): Fix a typo. (Bug#19647) 8 * programs.texi (Custom C Indent): Fix a typo. (Bug#19647)
diff --git a/doc/emacs/cmdargs.texi b/doc/emacs/cmdargs.texi
index f724f77e230..42c8e33d5c7 100644
--- a/doc/emacs/cmdargs.texi
+++ b/doc/emacs/cmdargs.texi
@@ -165,9 +165,12 @@ Evaluate Lisp expression @var{expression}.
165@item --insert=@var{file} 165@item --insert=@var{file}
166@opindex --insert 166@opindex --insert
167@cindex insert file contents, command-line argument 167@cindex insert file contents, command-line argument
168Insert the contents of @var{file} into the @file{*scratch*} buffer 168Insert the contents of @var{file} into the buffer that is current when
169(@pxref{Lisp Interaction}). This is like what @kbd{M-x insert-file} 169this command-line argument is processed. Usually, this is the
170does (@pxref{Misc File Ops}). 170@file{*scratch*} buffer (@pxref{Lisp Interaction}), but if arguments
171earlier on the command line visit files or switch buffers, that might
172be a different buffer. The effect of this command-line argument is
173like what @kbd{M-x insert-file} does (@pxref{Misc File Ops}).
171 174
172@item --kill 175@item --kill
173@opindex --kill 176@opindex --kill
diff --git a/doc/lispref/ChangeLog b/doc/lispref/ChangeLog
index ef1d79af003..3a1eeb2acb9 100644
--- a/doc/lispref/ChangeLog
+++ b/doc/lispref/ChangeLog
@@ -1,3 +1,8 @@
12015-01-24 Eli Zaretskii <eliz@gnu.org>
2
3 * searching.texi (Regexp Search): Add a cross-reference to "Syntax
4 of Regexps". (Bug#19668)
5
12015-01-21 Daniel Koning <dk@danielkoning.com> (tiny change) 62015-01-21 Daniel Koning <dk@danielkoning.com> (tiny change)
2 7
3 * commands.texi (Drag Events, Motion Events, Event Examples) 8 * commands.texi (Drag Events, Motion Events, Event Examples)
diff --git a/doc/lispref/searching.texi b/doc/lispref/searching.texi
index 2032b151d07..61fac78e4a8 100644
--- a/doc/lispref/searching.texi
+++ b/doc/lispref/searching.texi
@@ -988,10 +988,11 @@ list of characters @var{chars}.
988@cindex searching for regexp 988@cindex searching for regexp
989 989
990 In GNU Emacs, you can search for the next match for a regular 990 In GNU Emacs, you can search for the next match for a regular
991expression either incrementally or not. For incremental search 991expression (@pxref{Syntax of Regexps}) either incrementally or not.
992commands, see @ref{Regexp Search, , Regular Expression Search, emacs, 992For incremental search commands, see @ref{Regexp Search, , Regular
993The GNU Emacs Manual}. Here we describe only the search functions 993Expression Search, emacs, The GNU Emacs Manual}. Here we describe
994useful in programs. The principal one is @code{re-search-forward}. 994only the search functions useful in programs. The principal one is
995@code{re-search-forward}.
995 996
996 These search functions convert the regular expression to multibyte if 997 These search functions convert the regular expression to multibyte if
997the buffer is multibyte; they convert the regular expression to unibyte 998the buffer is multibyte; they convert the regular expression to unibyte
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index a693cc0bdc6..2e5a67ce228 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,23 @@
12015-01-26 Fabián Ezequiel Gallina <fgallina@gnu.org>
2
3 python.el: New non-global state dependent indentation engine.
4 (Bug#18319, Bug#19595)
5
6 * progmodes/python.el (python-syntax-comment-or-string-p): Accept
7 PPSS as argument.
8 (python-syntax-closing-paren-p): New function.
9 (python-indent-current-level)
10 (python-indent-levels): Mark obsolete.
11 (python-indent-context): Return more context cases.
12 (python-indent--calculate-indentation)
13 (python-indent--calculate-levels): New functions.
14 (python-indent-calculate-levels): Use them.
15 (python-indent-calculate-indentation, python-indent-line):
16 (python-indent-line-function): Rewritten to use new API.
17 (python-indent-dedent-line): Simplify logic.
18 (python-indent-dedent-line-backspace): Use `unless`.
19 (python-indent-toggle-levels): Delete function.
20
12015-01-21 Daniel Koning <dk@danielkoning.com> (tiny change) 212015-01-21 Daniel Koning <dk@danielkoning.com> (tiny change)
2 22
3 * subr.el (posnp): Correct docstring of `posnp'. 23 * subr.el (posnp): Correct docstring of `posnp'.
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 13ff439bef2..d340550a017 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -463,9 +463,14 @@ The type returned can be `comment', `string' or `paren'."
463 ((nth 8 ppss) (if (nth 4 ppss) 'comment 'string)) 463 ((nth 8 ppss) (if (nth 4 ppss) 'comment 'string))
464 ((nth 1 ppss) 'paren)))) 464 ((nth 1 ppss) 'paren))))
465 465
466(defsubst python-syntax-comment-or-string-p () 466(defsubst python-syntax-comment-or-string-p (&optional ppss)
467 "Return non-nil if point is inside 'comment or 'string." 467 "Return non-nil if PPSS is inside 'comment or 'string."
468 (nth 8 (syntax-ppss))) 468 (nth 8 (or ppss (syntax-ppss))))
469
470(defsubst python-syntax-closing-paren-p ()
471 "Return non-nil if char after point is a closing paren."
472 (= (syntax-class (syntax-after (point)))
473 (syntax-class (string-to-syntax ")"))))
469 474
470(define-obsolete-function-alias 475(define-obsolete-function-alias
471 'python-info-ppss-context #'python-syntax-context "24.3") 476 'python-info-ppss-context #'python-syntax-context "24.3")
@@ -704,11 +709,28 @@ It makes underscores and dots word constituent chars.")
704 'python-guess-indent 'python-indent-guess-indent-offset "24.3") 709 'python-guess-indent 'python-indent-guess-indent-offset "24.3")
705 710
706(defvar python-indent-current-level 0 711(defvar python-indent-current-level 0
707 "Current indentation level `python-indent-line-function' is using.") 712 "Deprecated var available for compatibility.")
708 713
709(defvar python-indent-levels '(0) 714(defvar python-indent-levels '(0)
710 "Levels of indentation available for `python-indent-line-function'. 715 "Deprecated var available for compatibility.")
711Can also be `noindent' if automatic indentation can't be used.") 716
717(make-obsolete-variable
718 'python-indent-current-level
719 "The indentation API changed to avoid global state.
720The function `python-indent-calculate-levels' does not use it
721anymore. If you were defadvising it and or depended on this
722variable for indentation customizations, refactor your code to
723work on `python-indent-calculate-indentation' instead."
724 "24.5")
725
726(make-obsolete-variable
727 'python-indent-levels
728 "The indentation API changed to avoid global state.
729The function `python-indent-calculate-levels' does not use it
730anymore. If you were defadvising it and or depended on this
731variable for indentation customizations, refactor your code to
732work on `python-indent-calculate-indentation' instead."
733 "24.5")
712 734
713(defun python-indent-guess-indent-offset () 735(defun python-indent-guess-indent-offset ()
714 "Guess and set `python-indent-offset' for the current buffer." 736 "Guess and set `python-indent-offset' for the current buffer."
@@ -748,362 +770,358 @@ Can also be `noindent' if automatic indentation can't be used.")
748 python-indent-offset))))))) 770 python-indent-offset)))))))
749 771
750(defun python-indent-context () 772(defun python-indent-context ()
751 "Get information on indentation context. 773 "Get information about the current indentation context.
752Context information is returned with a cons with the form: 774Context is returned in a cons with the form (STATUS . START).
753 (STATUS . START) 775
754 776STATUS can be one of the following:
755Where status can be any of the following symbols: 777
756 778keyword
757 * after-comment: When current line might continue a comment block 779-------
758 * inside-paren: If point in between (), {} or [] 780
759 * inside-string: If point is inside a string 781:after-comment
760 * after-backslash: Previous line ends in a backslash 782 - Point is after a comment line.
761 * after-beginning-of-block: Point is after beginning of block 783 - START is the position of the \"#\" character.
762 * after-line: Point is after normal line 784:inside-string
763 * dedenter-statement: Point is on a dedenter statement. 785 - Point is inside string.
764 * no-indent: Point is at beginning of buffer or other special case 786 - START is the position of the first quote that starts it.
765START is the buffer position where the sexp starts." 787:no-indent
788 - No possible indentation case matches.
789 - START is always zero.
790
791:inside-paren
792 - Fallback case when point is inside paren.
793 - START is the first non space char position *after* the open paren.
794:inside-paren-at-closing-nested-paren
795 - Point is on a line that contains a nested paren closer.
796 - START is the position of the open paren it closes.
797:inside-paren-at-closing-paren
798 - Point is on a line that contains a paren closer.
799 - START is the position of the open paren.
800:inside-paren-newline-start
801 - Point is inside a paren with items starting in their own line.
802 - START is the position of the open paren.
803:inside-paren-newline-start-from-block
804 - Point is inside a paren with items starting in their own line
805 from a block start.
806 - START is the position of the open paren.
807
808:after-backslash
809 - Fallback case when point is after backslash.
810 - START is the char after the position of the backslash.
811:after-backslash-assignment-continuation
812 - Point is after a backslashed assignment.
813 - START is the char after the position of the backslash.
814:after-backslash-block-continuation
815 - Point is after a backslashed block continuation.
816 - START is the char after the position of the backslash.
817:after-backslash-dotted-continuation
818 - Point is after a backslashed dotted continuation. Previous
819 line must contain a dot to align with.
820 - START is the char after the position of the backslash.
821:after-backslash-first-line
822 - First line following a backslashed continuation.
823 - START is the char after the position of the backslash.
824
825:after-block-end
826 - Point is after a line containing a block ender.
827 - START is the position where the ender starts.
828:after-block-start
829 - Point is after a line starting a block.
830 - START is the position where the block starts.
831:after-line
832 - Point is after a simple line.
833 - START is the position where the previous line starts.
834:at-dedenter-block-start
835 - Point is on a line starting a dedenter block.
836 - START is the position where the dedenter block starts."
766 (save-restriction 837 (save-restriction
767 (widen) 838 (widen)
768 (let ((ppss (save-excursion (beginning-of-line) (syntax-ppss))) 839 (let ((ppss (save-excursion
769 (start)) 840 (beginning-of-line)
770 (cons 841 (syntax-ppss))))
771 (cond 842 (cond
772 ;; Beginning of buffer 843 ;; Beginning of buffer.
773 ((save-excursion 844 ((= (line-number-at-pos) 1)
774 (goto-char (line-beginning-position)) 845 (cons :no-indent 0))
775 (bobp)) 846 ;; Comment continuation (maybe).
776 'no-indent) 847 ((save-excursion
777 ;; Comment continuation 848 (when (and
778 ((save-excursion 849 (or
779 (when (and 850 (python-info-current-line-comment-p)
780 (or 851 (python-info-current-line-empty-p))
781 (python-info-current-line-comment-p) 852 (forward-comment -1)
782 (python-info-current-line-empty-p)) 853 (python-info-current-line-comment-p))
783 (progn 854 (cons :after-comment (point)))))
784 (forward-comment -1) 855 ;; Inside a string.
785 (python-info-current-line-comment-p))) 856 ((let ((start (python-syntax-context 'string ppss)))
786 (setq start (point)) 857 (when start
787 'after-comment))) 858 (cons :inside-string start))))
788 ;; Inside string 859 ;; Inside a paren.
789 ((setq start (python-syntax-context 'string ppss)) 860 ((let* ((start (python-syntax-context 'paren ppss))
790 'inside-string) 861 (starts-in-newline
791 ;; Inside a paren 862 (when start
792 ((setq start (python-syntax-context 'paren ppss)) 863 (save-excursion
793 'inside-paren) 864 (goto-char start)
794 ;; After backslash 865 (forward-char)
795 ((setq start (when (not (or (python-syntax-context 'string ppss) 866 (not
796 (python-syntax-context 'comment ppss))) 867 (= (line-number-at-pos)
797 (let ((line-beg-pos (line-number-at-pos))) 868 (progn
798 (python-info-line-ends-backslash-p 869 (python-util-forward-comment)
799 (1- line-beg-pos))))) 870 (line-number-at-pos))))))))
800 'after-backslash) 871 (when start
801 ;; After beginning of block 872 (cond
802 ((setq start (save-excursion 873 ;; Current line only holds the closing paren.
803 (when (progn 874 ((save-excursion
804 (back-to-indentation) 875 (skip-syntax-forward " ")
805 (python-util-forward-comment -1) 876 (when (and (python-syntax-closing-paren-p)
806 (equal (char-before) ?:)) 877 (progn
807 ;; Move to the first block start that's not in within 878 (forward-char 1)
808 ;; a string, comment or paren and that's not a 879 (not (python-syntax-context 'paren))))
809 ;; continuation line. 880 (cons :inside-paren-at-closing-paren start))))
810 (while (and (re-search-backward 881 ;; Current line only holds a closing paren for nested.
811 (python-rx block-start) nil t) 882 ((save-excursion
812 (or 883 (back-to-indentation)
813 (python-syntax-context-type) 884 (python-syntax-closing-paren-p))
814 (python-info-continuation-line-p)))) 885 (cons :inside-paren-at-closing-nested-paren start))
815 (when (looking-at (python-rx block-start)) 886 ;; This line starts from a opening block in its own line.
816 (point-marker))))) 887 ((save-excursion
817 'after-beginning-of-block) 888 (goto-char start)
818 ((when (setq start (python-info-dedenter-statement-p)) 889 (when (and
819 'dedenter-statement)) 890 starts-in-newline
820 ;; After normal line 891 (save-excursion
821 ((setq start (save-excursion 892 (back-to-indentation)
893 (looking-at (python-rx block-start))))
894 (cons
895 :inside-paren-newline-start-from-block start))))
896 (starts-in-newline
897 (cons :inside-paren-newline-start start))
898 ;; General case.
899 (t (cons :inside-paren
900 (save-excursion
901 (goto-char (1+ start))
902 (skip-syntax-forward "(" 1)
903 (skip-syntax-forward " ")
904 (point))))))))
905 ;; After backslash.
906 ((let ((start (when (not (python-syntax-comment-or-string-p ppss))
907 (python-info-line-ends-backslash-p
908 (1- (line-number-at-pos))))))
909 (when start
910 (cond
911 ;; Continuation of dotted expression.
912 ((save-excursion
913 (back-to-indentation)
914 (when (eq (char-after) ?\.)
915 ;; Move point back until it's not inside a paren.
916 (while (prog2
917 (forward-line -1)
918 (and (not (bobp))
919 (python-syntax-context 'paren))))
920 (goto-char (line-end-position))
921 (while (and (search-backward
922 "." (line-beginning-position) t)
923 (python-syntax-context-type)))
924 ;; Ensure previous statement has dot to align with.
925 (when (and (eq (char-after) ?\.)
926 (not (python-syntax-context-type)))
927 (cons :after-backslash-dotted-continuation (point))))))
928 ;; Continuation of block definition.
929 ((let ((block-continuation-start
930 (python-info-block-continuation-line-p)))
931 (when block-continuation-start
932 (save-excursion
933 (goto-char block-continuation-start)
934 (re-search-forward
935 (python-rx block-start (* space))
936 (line-end-position) t)
937 (cons :after-backslash-block-continuation (point))))))
938 ;; Continuation of assignment.
939 ((let ((assignment-continuation-start
940 (python-info-assignment-continuation-line-p)))
941 (when assignment-continuation-start
942 (save-excursion
943 (goto-char assignment-continuation-start)
944 (cons :after-backslash-assignment-continuation (point))))))
945 ;; First line after backslash continuation start.
946 ((save-excursion
947 (goto-char start)
948 (when (or (= (line-number-at-pos) 1)
949 (not (python-info-beginning-of-backslash
950 (1- (line-number-at-pos)))))
951 (cons :after-backslash-first-line start))))
952 ;; General case.
953 (t (cons :after-backslash start))))))
954 ;; After beginning of block.
955 ((let ((start (save-excursion
956 (back-to-indentation)
957 (python-util-forward-comment -1)
958 (when (equal (char-before) ?:)
959 (python-nav-beginning-of-block)))))
960 (when start
961 (cons :after-block-start start))))
962 ;; At dedenter statement.
963 ((let ((start (python-info-dedenter-statement-p)))
964 (when start
965 (cons :at-dedenter-block-start start))))
966 ;; After normal line.
967 ((let ((start (save-excursion
822 (back-to-indentation) 968 (back-to-indentation)
823 (skip-chars-backward (rx (or whitespace ?\n))) 969 (skip-chars-backward " \t\n")
824 (python-nav-beginning-of-statement) 970 (python-nav-beginning-of-statement)
825 (point-marker))) 971 (point))))
826 'after-line) 972 (when start
827 ;; Do not indent 973 (if (save-excursion
828 (t 'no-indent)) 974 (python-util-forward-comment -1)
829 start)))) 975 (python-nav-beginning-of-statement)
830 976 (looking-at (python-rx block-ender)))
831(defun python-indent-calculate-indentation () 977 (cons :after-block-end start)
832 "Calculate correct indentation offset for the current line. 978 (cons :after-line start)))))
833Returns `noindent' if the indentation does not depend on Python syntax, 979 ;; Default case: do not indent.
834such as in strings." 980 (t (cons :no-indent 0))))))
835 (let* ((indentation-context (python-indent-context)) 981
836 (context-status (car indentation-context)) 982(defun python-indent--calculate-indentation ()
837 (context-start (cdr indentation-context))) 983 "Internal implementation of `python-indent-calculate-indentation'.
838 (save-restriction 984May return an integer for the maximum possible indentation at
839 (widen) 985current context or a list of integers. The latter case is only
840 (save-excursion 986happening for :at-dedenter-block-start context since the
841 (pcase context-status 987possibilities can be narrowed to especific indentation points."
842 (`no-indent 0) 988 (save-restriction
843 (`after-comment 989 (widen)
844 (goto-char context-start) 990 (save-excursion
845 (current-indentation)) 991 (pcase (python-indent-context)
846 ;; When point is after beginning of block just add one level 992 (`(:no-indent . ,_) 0)
847 ;; of indentation relative to the context-start 993 (`(,(or :after-line
848 (`after-beginning-of-block 994 :after-comment
849 (goto-char context-start) 995 :inside-string
850 (+ (current-indentation) python-indent-offset)) 996 :after-backslash
851 ;; When after a simple line just use previous line 997 :inside-paren-at-closing-paren
852 ;; indentation. 998 :inside-paren-at-closing-nested-paren) . ,start)
853 (`after-line 999 ;; Copy previous indentation.
854 (let* ((pair (save-excursion 1000 (goto-char start)
855 (goto-char context-start) 1001 (current-indentation))
856 (cons 1002 (`(,(or :after-block-start
857 (current-indentation) 1003 :after-backslash-first-line
858 (python-info-beginning-of-block-p)))) 1004 :inside-paren-newline-start) . ,start)
859 (context-indentation (car pair)) 1005 ;; Add one indentation level.
860 ;; TODO: Separate block enders into its own case. 1006 (goto-char start)
861 (adjustment 1007 (+ (current-indentation) python-indent-offset))
862 (if (save-excursion 1008 (`(,(or :inside-paren
863 (python-util-forward-comment -1) 1009 :after-backslash-block-continuation
864 (python-nav-beginning-of-statement) 1010 :after-backslash-assignment-continuation
865 (looking-at (python-rx block-ender))) 1011 :after-backslash-dotted-continuation) . ,start)
866 python-indent-offset 1012 ;; Use the column given by the context.
867 0))) 1013 (goto-char start)
868 (- context-indentation adjustment))) 1014 (current-column))
869 ;; When point is on a dedenter statement, search for the 1015 (`(:after-block-end . ,start)
870 ;; opening block that corresponds to it and use its 1016 ;; Subtract one indentation level.
871 ;; indentation. If no opening block is found just remove 1017 (goto-char start)
872 ;; indentation as this is an invalid python file. 1018 (- (current-indentation) python-indent-offset))
873 (`dedenter-statement 1019 (`(:at-dedenter-block-start . ,_)
874 (let ((block-start-point 1020 ;; List all possible indentation levels from opening blocks.
875 (python-info-dedenter-opening-block-position))) 1021 (let ((opening-block-start-points
876 (save-excursion 1022 (python-info-dedenter-opening-block-positions)))
877 (if (not block-start-point) 1023 (if (not opening-block-start-points)
878 0 1024 0 ; if not found default to first column
879 (goto-char block-start-point) 1025 (mapcar (lambda (pos)
880 (current-indentation))))) 1026 (save-excursion
881 ;; When inside of a string, do nothing. just use the current 1027 (goto-char pos)
882 ;; indentation. XXX: perhaps it would be a good idea to 1028 (current-indentation)))
883 ;; invoke standard text indentation here 1029 opening-block-start-points))))
884 (`inside-string 'noindent) 1030 (`(,(or :inside-paren-newline-start-from-block) . ,start)
885 ;; After backslash we have several possibilities. 1031 ;; Add two indentation levels to make the suite stand out.
886 (`after-backslash 1032 (goto-char start)
887 (cond 1033 (+ (current-indentation) (* python-indent-offset 2)))))))
888 ;; Check if current line is a dot continuation. For this 1034
889 ;; the current line must start with a dot and previous 1035(defun python-indent--calculate-levels (indentation)
890 ;; line must contain a dot too. 1036 "Calculate levels list given INDENTATION.
891 ((save-excursion 1037Argument INDENTATION can either be an integer or a list of
892 (back-to-indentation) 1038integers. Levels are returned in ascending order, and in the
893 (when (looking-at "\\.") 1039case INDENTATION is a list, this order is enforced."
894 ;; If after moving one line back point is inside a paren it 1040 (if (listp indentation)
895 ;; needs to move back until it's not anymore 1041 (sort (copy-sequence indentation) #'<)
896 (while (prog2 1042 (let* ((remainder (% indentation python-indent-offset))
897 (forward-line -1) 1043 (steps (/ (- indentation remainder) python-indent-offset))
898 (and (not (bobp)) 1044 (levels (mapcar (lambda (step)
899 (python-syntax-context 'paren)))) 1045 (* python-indent-offset step))
900 (goto-char (line-end-position)) 1046 (number-sequence steps 0 -1))))
901 (while (and (re-search-backward 1047 (reverse
902 "\\." (line-beginning-position) t) 1048 (if (not (zerop remainder))
903 (python-syntax-context-type))) 1049 (cons indentation levels)
904 (if (and (looking-at "\\.") 1050 levels)))))
905 (not (python-syntax-context-type))) 1051
906 ;; The indentation is the same column of the 1052(defun python-indent--previous-level (levels indentation)
907 ;; first matching dot that's not inside a 1053 "Return previous level from LEVELS relative to INDENTATION."
908 ;; comment, a string or a paren 1054 (let* ((levels (sort (copy-sequence levels) #'>))
909 (current-column) 1055 (default (car levels)))
910 ;; No dot found on previous line, just add another 1056 (catch 'return
911 ;; indentation level. 1057 (dolist (level levels)
912 (+ (current-indentation) python-indent-offset))))) 1058 (when (funcall #'< level indentation)
913 ;; Check if prev line is a block continuation 1059 (throw 'return level)))
914 ((let ((block-continuation-start 1060 default)))
915 (python-info-block-continuation-line-p))) 1061
916 (when block-continuation-start 1062(defun python-indent-calculate-indentation (&optional previous)
917 ;; If block-continuation-start is set jump to that 1063 "Calculate indentation.
918 ;; marker and use first column after the block start 1064Get indentation of PREVIOUS level when argument is non-nil.
919 ;; as indentation value. 1065Return the max level of the cycle when indentation reaches the
920 (goto-char block-continuation-start) 1066minimum."
921 (re-search-forward 1067 (let* ((indentation (python-indent--calculate-indentation))
922 (python-rx block-start (* space)) 1068 (levels (python-indent--calculate-levels indentation)))
923 (line-end-position) t) 1069 (if previous
924 (current-column)))) 1070 (python-indent--previous-level levels (current-indentation))
925 ;; Check if current line is an assignment continuation 1071 (apply #'max levels))))
926 ((let ((assignment-continuation-start 1072
927 (python-info-assignment-continuation-line-p))) 1073(defun python-indent-line (&optional previous)
928 (when assignment-continuation-start
929 ;; If assignment-continuation is set jump to that
930 ;; marker and use first column after the assignment
931 ;; operator as indentation value.
932 (goto-char assignment-continuation-start)
933 (current-column))))
934 (t
935 (forward-line -1)
936 (goto-char (python-info-beginning-of-backslash))
937 (if (save-excursion
938 (and
939 (forward-line -1)
940 (goto-char
941 (or (python-info-beginning-of-backslash) (point)))
942 (python-info-line-ends-backslash-p)))
943 ;; The two previous lines ended in a backslash so we must
944 ;; respect previous line indentation.
945 (current-indentation)
946 ;; What happens here is that we are dealing with the second
947 ;; line of a backslash continuation, in that case we just going
948 ;; to add one indentation level.
949 (+ (current-indentation) python-indent-offset)))))
950 ;; When inside a paren there's a need to handle nesting
951 ;; correctly
952 (`inside-paren
953 (cond
954 ;; If current line closes the outermost open paren use the
955 ;; current indentation of the context-start line.
956 ((save-excursion
957 (skip-syntax-forward "\s" (line-end-position))
958 (when (and (looking-at (regexp-opt '(")" "]" "}")))
959 (progn
960 (forward-char 1)
961 (not (python-syntax-context 'paren))))
962 (goto-char context-start)
963 (current-indentation))))
964 ;; If open paren is contained on a line by itself add another
965 ;; indentation level, else look for the first word after the
966 ;; opening paren and use it's column position as indentation
967 ;; level.
968 ((let* ((content-starts-in-newline)
969 (indent
970 (save-excursion
971 (if (setq content-starts-in-newline
972 (progn
973 (goto-char context-start)
974 (forward-char)
975 (save-restriction
976 (narrow-to-region
977 (line-beginning-position)
978 (line-end-position))
979 (python-util-forward-comment))
980 (looking-at "$")))
981 (+ (current-indentation) python-indent-offset)
982 (current-column)))))
983 ;; Adjustments
984 (cond
985 ;; If current line closes a nested open paren de-indent one
986 ;; level.
987 ((progn
988 (back-to-indentation)
989 (looking-at (regexp-opt '(")" "]" "}"))))
990 (- indent python-indent-offset))
991 ;; If the line of the opening paren that wraps the current
992 ;; line starts a block add another level of indentation to
993 ;; follow new pep8 recommendation. See: http://ur1.ca/5rojx
994 ((save-excursion
995 (when (and content-starts-in-newline
996 (progn
997 (goto-char context-start)
998 (back-to-indentation)
999 (looking-at (python-rx block-start))))
1000 (+ indent python-indent-offset))))
1001 (t indent)))))))))))
1002
1003(defun python-indent-calculate-levels ()
1004 "Calculate `python-indent-levels' and reset `python-indent-current-level'."
1005 (if (or (python-info-continuation-line-p)
1006 (not (python-info-dedenter-statement-p)))
1007 ;; XXX: This asks for a refactor. Even if point is on a
1008 ;; dedenter statement, it could be multiline and in that case
1009 ;; the continuation lines should be indented with normal rules.
1010 (let* ((indentation (python-indent-calculate-indentation)))
1011 (if (not (numberp indentation))
1012 (setq python-indent-levels indentation)
1013 (let* ((remainder (% indentation python-indent-offset))
1014 (steps (/ (- indentation remainder) python-indent-offset)))
1015 (setq python-indent-levels (list 0))
1016 (dotimes (step steps)
1017 (push (* python-indent-offset (1+ step)) python-indent-levels))
1018 (when (not (eq 0 remainder))
1019 (push (+ (* python-indent-offset steps) remainder)
1020 python-indent-levels)))))
1021 (setq python-indent-levels
1022 (or
1023 (mapcar (lambda (pos)
1024 (save-excursion
1025 (goto-char pos)
1026 (current-indentation)))
1027 (python-info-dedenter-opening-block-positions))
1028 (list 0))))
1029 (when (listp python-indent-levels)
1030 (setq python-indent-current-level (1- (length python-indent-levels))
1031 python-indent-levels (nreverse python-indent-levels))))
1032
1033(defun python-indent-toggle-levels ()
1034 "Toggle `python-indent-current-level' over `python-indent-levels'."
1035 (setq python-indent-current-level (1- python-indent-current-level))
1036 (when (< python-indent-current-level 0)
1037 (setq python-indent-current-level (1- (length python-indent-levels)))))
1038
1039(defun python-indent-line (&optional force-toggle)
1040 "Internal implementation of `python-indent-line-function'. 1074 "Internal implementation of `python-indent-line-function'.
1041Uses the offset calculated in 1075Use the PREVIOUS level when argument is non-nil, otherwise indent
1042`python-indent-calculate-indentation' and available levels 1076to the maxium available level. When indentation is the minimum
1043indicated by the variable `python-indent-levels' to set the 1077possible and PREVIOUS is non-nil, cycle back to the maximum
1044current indentation. 1078level."
1079 (let ((follow-indentation-p
1080 ;; Check if point is within indentation.
1081 (and (<= (line-beginning-position) (point))
1082 (>= (+ (line-beginning-position)
1083 (current-indentation))
1084 (point)))))
1085 (save-excursion
1086 (indent-line-to
1087 (python-indent-calculate-indentation previous))
1088 (python-info-dedenter-opening-block-message))
1089 (when follow-indentation-p
1090 (back-to-indentation))))
1045 1091
1046When the variable `last-command' is equal to one of the symbols 1092(defun python-indent-calculate-levels ()
1047inside `python-indent-trigger-commands' or FORCE-TOGGLE is 1093 "Return possible indentation levels."
1048non-nil it cycles levels indicated in the variable 1094 (python-indent--calculate-levels
1049`python-indent-levels' by setting the current level in the 1095 (python-indent--calculate-indentation)))
1050variable `python-indent-current-level'.
1051
1052When the variable `last-command' is not equal to one of the
1053symbols inside `python-indent-trigger-commands' and FORCE-TOGGLE
1054is nil it calculates possible indentation levels and saves them
1055in the variable `python-indent-levels'. Afterwards it sets the
1056variable `python-indent-current-level' correctly so offset is
1057equal to
1058 (nth python-indent-current-level python-indent-levels)"
1059 (if (and (or (and (memq this-command python-indent-trigger-commands)
1060 (eq last-command this-command))
1061 force-toggle)
1062 (not (equal python-indent-levels '(0))))
1063 (if (listp python-indent-levels)
1064 (python-indent-toggle-levels))
1065 (python-indent-calculate-levels))
1066 (if (eq python-indent-levels 'noindent)
1067 python-indent-levels
1068 (let* ((starting-pos (point-marker))
1069 (indent-ending-position
1070 (+ (line-beginning-position) (current-indentation)))
1071 (follow-indentation-p
1072 (or (bolp)
1073 (and (<= (line-beginning-position) starting-pos)
1074 (>= indent-ending-position starting-pos))))
1075 (next-indent (nth python-indent-current-level python-indent-levels)))
1076 (unless (= next-indent (current-indentation))
1077 (beginning-of-line)
1078 (delete-horizontal-space)
1079 (indent-to next-indent)
1080 (goto-char starting-pos))
1081 (and follow-indentation-p (back-to-indentation)))
1082 (python-info-dedenter-opening-block-message)))
1083 1096
1084(defun python-indent-line-function () 1097(defun python-indent-line-function ()
1085 "`indent-line-function' for Python mode. 1098 "`indent-line-function' for Python mode.
1086See `python-indent-line' for details." 1099When the variable `last-command' is equal to one of the symbols
1087 (python-indent-line)) 1100inside `python-indent-trigger-commands' it cycles possible
1101indentation levels from right to left."
1102 (python-indent-line
1103 (and (memq this-command python-indent-trigger-commands)
1104 (eq last-command this-command))))
1088 1105
1089(defun python-indent-dedent-line () 1106(defun python-indent-dedent-line ()
1090 "De-indent current line." 1107 "De-indent current line."
1091 (interactive "*") 1108 (interactive "*")
1092 (when (and (not (python-syntax-comment-or-string-p)) 1109 (when (and (not (bolp))
1093 (<= (point) (save-excursion 1110 (not (python-syntax-comment-or-string-p))
1094 (back-to-indentation) 1111 (= (+ (line-beginning-position)
1095 (point))) 1112 (current-indentation))
1096 (> (current-column) 0)) 1113 (point)))
1097 (python-indent-line t) 1114 (python-indent-line t)
1098 t)) 1115 t))
1099 1116
1100(defun python-indent-dedent-line-backspace (arg) 1117(defun python-indent-dedent-line-backspace (arg)
1101 "De-indent current line. 1118 "De-indent current line.
1102Argument ARG is passed to `backward-delete-char-untabify' when 1119Argument ARG is passed to `backward-delete-char-untabify' when
1103point is not in between the indentation." 1120point is not in between the indentation."
1104 (interactive "*p") 1121 (interactive "*p")
1105 (when (not (python-indent-dedent-line)) 1122 (unless (python-indent-dedent-line)
1106 (backward-delete-char-untabify arg))) 1123 (backward-delete-char-untabify arg)))
1124
1107(put 'python-indent-dedent-line-backspace 'delete-selection 'supersede) 1125(put 'python-indent-dedent-line-backspace 'delete-selection 'supersede)
1108 1126
1109(defun python-indent-region (start end) 1127(defun python-indent-region (start end)
diff --git a/src/ChangeLog b/src/ChangeLog
index d46e34c8525..8efc90727e1 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,16 @@
12015-01-27 Eli Zaretskii <eliz@gnu.org>
2
3 * dired.c (directory_files_internal) [WINDOWSNT]: If readdir
4 returns NULL and errno is ENOTDIR, behave as if opendir failed to
5 open the directory. (Bug#19701)
6
7 * w32.c (sys_readdir): If FindFirstFile fails because the
8 directory doesn't exist, set errno to ENOTDIR.
9
102015-01-24 Jan Djärv <jan.h.d@swipnet.se>
11
12 * nsterm.m (drawRect:): Add block/unblock_input (Bug#19660).
13
12015-01-21 Paul Eggert <eggert@cs.ucla.edu> 142015-01-21 Paul Eggert <eggert@cs.ucla.edu>
2 15
3 Fix coding.c subscript error 16 Fix coding.c subscript error
diff --git a/src/dired.c b/src/dired.c
index e31fdf87ac2..757eb6d30cd 100644
--- a/src/dired.c
+++ b/src/dired.c
@@ -238,6 +238,19 @@ directory_files_internal (Lisp_Object directory, Lisp_Object full,
238 QUIT; 238 QUIT;
239 continue; 239 continue;
240 } 240 }
241#ifdef WINDOWSNT
242 /* The MS-Windows implementation of 'opendir' doesn't
243 actually open a directory until the first call to
244 'readdir'. If 'readdir' fails to open the directory, it
245 sets errno to ENOTDIR; we convert it here to ENOENT so
246 that the error message is similar to what happens on
247 Posix hosts in such cases. */
248 if (errno == ENOTDIR)
249 {
250 errno = ENOENT;
251 report_file_error ("Opening directory", directory);
252 }
253#endif
241 break; 254 break;
242 } 255 }
243 256
diff --git a/src/nsterm.m b/src/nsterm.m
index ee1268ef850..e90c3d70db3 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -6773,7 +6773,9 @@ if (cols > 0 && rows > 0)
6773 return; 6773 return;
6774 6774
6775 ns_clear_frame_area (emacsframe, x, y, width, height); 6775 ns_clear_frame_area (emacsframe, x, y, width, height);
6776 block_input ();
6776 expose_frame (emacsframe, x, y, width, height); 6777 expose_frame (emacsframe, x, y, width, height);
6778 unblock_input ();
6777 6779
6778 /* 6780 /*
6779 drawRect: may be called (at least in OS X 10.5) for invisible 6781 drawRect: may be called (at least in OS X 10.5) for invisible
diff --git a/src/w32.c b/src/w32.c
index 31b13289b57..acd06ba2601 100644
--- a/src/w32.c
+++ b/src/w32.c
@@ -3433,7 +3433,22 @@ sys_readdir (DIR *dirp)
3433 } 3433 }
3434 3434
3435 if (dir_find_handle == INVALID_HANDLE_VALUE) 3435 if (dir_find_handle == INVALID_HANDLE_VALUE)
3436 return NULL; 3436 {
3437 switch (GetLastError ())
3438 {
3439 case ERROR_PATH_NOT_FOUND:
3440 case ERROR_ACCESS_DENIED:
3441 case ERROR_INVALID_DRIVE:
3442 case ERROR_BAD_NETPATH:
3443 /* This special value will be noticed by
3444 directory_files_internal, which see. */
3445 errno = ENOTDIR;
3446 break;
3447 default:
3448 break;
3449 }
3450 return NULL;
3451 }
3437 } 3452 }
3438 else if (w32_unicode_filenames) 3453 else if (w32_unicode_filenames)
3439 { 3454 {
diff --git a/test/ChangeLog b/test/ChangeLog
index 61ab8b6595a..66535ac42a3 100644
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -1,3 +1,30 @@
12015-01-26 Fabián Ezequiel Gallina <fgallina@gnu.org>
2
3 * automated/python-tests.el (python-indent-pep8-1)
4 (python-indent-pep8-2, python-indent-pep8-3)
5 (python-indent-after-comment-1, python-indent-after-comment-2)
6 (python-indent-inside-paren-1, python-indent-inside-paren-2)
7 (python-indent-after-block-1, python-indent-after-block-2)
8 (python-indent-after-backslash-1, python-indent-after-backslash-2)
9 (python-indent-after-backslash-3, python-indent-block-enders-1)
10 (python-indent-block-enders-2, python-indent-block-enders-3)
11 (python-indent-block-enders-4, python-indent-block-enders-5)
12 (python-indent-dedenters-1, python-indent-dedenters-2)
13 (python-indent-dedenters-3, python-indent-dedenters-4)
14 (python-indent-dedenters-5, python-indent-dedenters-6)
15 (python-indent-dedenters-7, python-indent-dedenters-8): Fix tests.
16 (python-indent-base-case, python-indent-after-block-3)
17 (python-indent-after-backslash-5, python-indent-inside-paren-3)
18 (python-indent-inside-paren-4, python-indent-inside-paren-5)
19 (python-indent-inside-paren-6, python-indent-inside-string-1)
20 (python-indent-inside-string-2, python-indent-inside-string-3)
21 (python-indent-dedent-line-backspace-1): New Tests.
22
232015-01-24 Glenn Morris <rgm@gnu.org>
24
25 * automated/regexp-tests.el: Require regexp-opt, which is
26 not preloaded --without-x.
27
12015-01-26 Stefan Monnier <monnier@iro.umontreal.ca> 282015-01-26 Stefan Monnier <monnier@iro.umontreal.ca>
2 29
3 * automated/cl-generic-tests.el: Try and make sure cl-lib is not 30 * automated/cl-generic-tests.el: Try and make sure cl-lib is not
diff --git a/test/automated/python-tests.el b/test/automated/python-tests.el
index e989ccb6792..672b05c39de 100644
--- a/test/automated/python-tests.el
+++ b/test/automated/python-tests.el
@@ -174,13 +174,13 @@ aliqua."
174foo = long_function_name(var_one, var_two, 174foo = long_function_name(var_one, var_two,
175 var_three, var_four) 175 var_three, var_four)
176" 176"
177 (should (eq (car (python-indent-context)) 'no-indent)) 177 (should (eq (car (python-indent-context)) :no-indent))
178 (should (= (python-indent-calculate-indentation) 0)) 178 (should (= (python-indent-calculate-indentation) 0))
179 (python-tests-look-at "foo = long_function_name(var_one, var_two,") 179 (python-tests-look-at "foo = long_function_name(var_one, var_two,")
180 (should (eq (car (python-indent-context)) 'after-line)) 180 (should (eq (car (python-indent-context)) :after-line))
181 (should (= (python-indent-calculate-indentation) 0)) 181 (should (= (python-indent-calculate-indentation) 0))
182 (python-tests-look-at "var_three, var_four)") 182 (python-tests-look-at "var_three, var_four)")
183 (should (eq (car (python-indent-context)) 'inside-paren)) 183 (should (eq (car (python-indent-context)) :inside-paren))
184 (should (= (python-indent-calculate-indentation) 25)))) 184 (should (= (python-indent-calculate-indentation) 25))))
185 185
186(ert-deftest python-indent-pep8-2 () 186(ert-deftest python-indent-pep8-2 ()
@@ -192,19 +192,22 @@ def long_function_name(
192 var_four): 192 var_four):
193 print (var_one) 193 print (var_one)
194" 194"
195 (should (eq (car (python-indent-context)) 'no-indent)) 195 (should (eq (car (python-indent-context)) :no-indent))
196 (should (= (python-indent-calculate-indentation) 0)) 196 (should (= (python-indent-calculate-indentation) 0))
197 (python-tests-look-at "def long_function_name(") 197 (python-tests-look-at "def long_function_name(")
198 (should (eq (car (python-indent-context)) 'after-line)) 198 (should (eq (car (python-indent-context)) :after-line))
199 (should (= (python-indent-calculate-indentation) 0)) 199 (should (= (python-indent-calculate-indentation) 0))
200 (python-tests-look-at "var_one, var_two, var_three,") 200 (python-tests-look-at "var_one, var_two, var_three,")
201 (should (eq (car (python-indent-context)) 'inside-paren)) 201 (should (eq (car (python-indent-context))
202 :inside-paren-newline-start-from-block))
202 (should (= (python-indent-calculate-indentation) 8)) 203 (should (= (python-indent-calculate-indentation) 8))
203 (python-tests-look-at "var_four):") 204 (python-tests-look-at "var_four):")
204 (should (eq (car (python-indent-context)) 'inside-paren)) 205 (should (eq (car (python-indent-context))
206 :inside-paren-newline-start-from-block))
205 (should (= (python-indent-calculate-indentation) 8)) 207 (should (= (python-indent-calculate-indentation) 8))
206 (python-tests-look-at "print (var_one)") 208 (python-tests-look-at "print (var_one)")
207 (should (eq (car (python-indent-context)) 'after-beginning-of-block)) 209 (should (eq (car (python-indent-context))
210 :after-block-start))
208 (should (= (python-indent-calculate-indentation) 4)))) 211 (should (= (python-indent-calculate-indentation) 4))))
209 212
210(ert-deftest python-indent-pep8-3 () 213(ert-deftest python-indent-pep8-3 ()
@@ -215,18 +218,34 @@ foo = long_function_name(
215 var_one, var_two, 218 var_one, var_two,
216 var_three, var_four) 219 var_three, var_four)
217" 220"
218 (should (eq (car (python-indent-context)) 'no-indent)) 221 (should (eq (car (python-indent-context)) :no-indent))
219 (should (= (python-indent-calculate-indentation) 0)) 222 (should (= (python-indent-calculate-indentation) 0))
220 (python-tests-look-at "foo = long_function_name(") 223 (python-tests-look-at "foo = long_function_name(")
221 (should (eq (car (python-indent-context)) 'after-line)) 224 (should (eq (car (python-indent-context)) :after-line))
222 (should (= (python-indent-calculate-indentation) 0)) 225 (should (= (python-indent-calculate-indentation) 0))
223 (python-tests-look-at "var_one, var_two,") 226 (python-tests-look-at "var_one, var_two,")
224 (should (eq (car (python-indent-context)) 'inside-paren)) 227 (should (eq (car (python-indent-context)) :inside-paren-newline-start))
225 (should (= (python-indent-calculate-indentation) 4)) 228 (should (= (python-indent-calculate-indentation) 4))
226 (python-tests-look-at "var_three, var_four)") 229 (python-tests-look-at "var_three, var_four)")
227 (should (eq (car (python-indent-context)) 'inside-paren)) 230 (should (eq (car (python-indent-context)) :inside-paren-newline-start))
228 (should (= (python-indent-calculate-indentation) 4)))) 231 (should (= (python-indent-calculate-indentation) 4))))
229 232
233(ert-deftest python-indent-base-case ()
234 "Check base case does not trigger errors."
235 (python-tests-with-temp-buffer
236 "
237
238"
239 (goto-char (point-min))
240 (should (eq (car (python-indent-context)) :no-indent))
241 (should (= (python-indent-calculate-indentation) 0))
242 (forward-line 1)
243 (should (eq (car (python-indent-context)) :after-line))
244 (should (= (python-indent-calculate-indentation) 0))
245 (forward-line 1)
246 (should (eq (car (python-indent-context)) :after-line))
247 (should (= (python-indent-calculate-indentation) 0))))
248
230(ert-deftest python-indent-after-comment-1 () 249(ert-deftest python-indent-after-comment-1 ()
231 "The most simple after-comment case that shouldn't fail." 250 "The most simple after-comment case that shouldn't fail."
232 (python-tests-with-temp-buffer 251 (python-tests-with-temp-buffer
@@ -240,23 +259,23 @@ class Blag(object):
240# with the exception with which the first child failed. 259# with the exception with which the first child failed.
241" 260"
242 (python-tests-look-at "# We only complete") 261 (python-tests-look-at "# We only complete")
243 (should (eq (car (python-indent-context)) 'after-line)) 262 (should (eq (car (python-indent-context)) :after-block-end))
244 (should (= (python-indent-calculate-indentation) 8)) 263 (should (= (python-indent-calculate-indentation) 8))
245 (python-tests-look-at "# terminal state") 264 (python-tests-look-at "# terminal state")
246 (should (eq (car (python-indent-context)) 'after-comment)) 265 (should (eq (car (python-indent-context)) :after-comment))
247 (should (= (python-indent-calculate-indentation) 8)) 266 (should (= (python-indent-calculate-indentation) 8))
248 (python-tests-look-at "# with the exception") 267 (python-tests-look-at "# with the exception")
249 (should (eq (car (python-indent-context)) 'after-comment)) 268 (should (eq (car (python-indent-context)) :after-comment))
250 ;; This one indents relative to previous block, even given the fact 269 ;; This one indents relative to previous block, even given the fact
251 ;; that it was under-indented. 270 ;; that it was under-indented.
252 (should (= (python-indent-calculate-indentation) 4)) 271 (should (= (python-indent-calculate-indentation) 4))
253 (python-tests-look-at "# terminal state" -1) 272 (python-tests-look-at "# terminal state" -1)
254 ;; It doesn't hurt to check again. 273 ;; It doesn't hurt to check again.
255 (should (eq (car (python-indent-context)) 'after-comment)) 274 (should (eq (car (python-indent-context)) :after-comment))
256 (python-indent-line) 275 (python-indent-line)
257 (should (= (current-indentation) 8)) 276 (should (= (current-indentation) 8))
258 (python-tests-look-at "# with the exception") 277 (python-tests-look-at "# with the exception")
259 (should (eq (car (python-indent-context)) 'after-comment)) 278 (should (eq (car (python-indent-context)) :after-comment))
260 ;; Now everything should be lined up. 279 ;; Now everything should be lined up.
261 (should (= (python-indent-calculate-indentation) 8)))) 280 (should (= (python-indent-calculate-indentation) 8))))
262 281
@@ -275,33 +294,33 @@ now_we_do_mess_cause_this_is_not_a_comment = 1
275# yeah, that. 294# yeah, that.
276" 295"
277 (python-tests-look-at "# I don't do much") 296 (python-tests-look-at "# I don't do much")
278 (should (eq (car (python-indent-context)) 'after-beginning-of-block)) 297 (should (eq (car (python-indent-context)) :after-block-start))
279 (should (= (python-indent-calculate-indentation) 4)) 298 (should (= (python-indent-calculate-indentation) 4))
280 (python-tests-look-at "return arg") 299 (python-tests-look-at "return arg")
281 ;; Comment here just gets ignored, this line is not a comment so 300 ;; Comment here just gets ignored, this line is not a comment so
282 ;; the rules won't apply here. 301 ;; the rules won't apply here.
283 (should (eq (car (python-indent-context)) 'after-beginning-of-block)) 302 (should (eq (car (python-indent-context)) :after-block-start))
284 (should (= (python-indent-calculate-indentation) 4)) 303 (should (= (python-indent-calculate-indentation) 4))
285 (python-tests-look-at "# This comment is badly") 304 (python-tests-look-at "# This comment is badly")
286 (should (eq (car (python-indent-context)) 'after-line)) 305 (should (eq (car (python-indent-context)) :after-block-end))
287 ;; The return keyword moves indentation backwards 4 spaces, but 306 ;; The return keyword moves indentation backwards 4 spaces, but
288 ;; let's assume this comment was placed there because the user 307 ;; let's assume this comment was placed there because the user
289 ;; wanted to (manually adding spaces or whatever). 308 ;; wanted to (manually adding spaces or whatever).
290 (should (= (python-indent-calculate-indentation) 0)) 309 (should (= (python-indent-calculate-indentation) 0))
291 (python-tests-look-at "# but we won't mess") 310 (python-tests-look-at "# but we won't mess")
292 (should (eq (car (python-indent-context)) 'after-comment)) 311 (should (eq (car (python-indent-context)) :after-comment))
293 (should (= (python-indent-calculate-indentation) 4)) 312 (should (= (python-indent-calculate-indentation) 4))
294 ;; Behave the same for blank lines: potentially a comment. 313 ;; Behave the same for blank lines: potentially a comment.
295 (forward-line 1) 314 (forward-line 1)
296 (should (eq (car (python-indent-context)) 'after-comment)) 315 (should (eq (car (python-indent-context)) :after-comment))
297 (should (= (python-indent-calculate-indentation) 4)) 316 (should (= (python-indent-calculate-indentation) 4))
298 (python-tests-look-at "now_we_do_mess") 317 (python-tests-look-at "now_we_do_mess")
299 ;; Here is where comment indentation starts to get ignored and 318 ;; Here is where comment indentation starts to get ignored and
300 ;; where the user can't freely indent anymore. 319 ;; where the user can't freely indent anymore.
301 (should (eq (car (python-indent-context)) 'after-line)) 320 (should (eq (car (python-indent-context)) :after-block-end))
302 (should (= (python-indent-calculate-indentation) 0)) 321 (should (= (python-indent-calculate-indentation) 0))
303 (python-tests-look-at "# yeah, that.") 322 (python-tests-look-at "# yeah, that.")
304 (should (eq (car (python-indent-context)) 'after-line)) 323 (should (eq (car (python-indent-context)) :after-line))
305 (should (= (python-indent-calculate-indentation) 0)))) 324 (should (= (python-indent-calculate-indentation) 0))))
306 325
307(ert-deftest python-indent-inside-paren-1 () 326(ert-deftest python-indent-inside-paren-1 ()
@@ -325,49 +344,53 @@ data = {
325} 344}
326" 345"
327 (python-tests-look-at "data = {") 346 (python-tests-look-at "data = {")
328 (should (eq (car (python-indent-context)) 'after-line)) 347 (should (eq (car (python-indent-context)) :after-line))
329 (should (= (python-indent-calculate-indentation) 0)) 348 (should (= (python-indent-calculate-indentation) 0))
330 (python-tests-look-at "'key':") 349 (python-tests-look-at "'key':")
331 (should (eq (car (python-indent-context)) 'inside-paren)) 350 (should (eq (car (python-indent-context)) :inside-paren-newline-start))
332 (should (= (python-indent-calculate-indentation) 4)) 351 (should (= (python-indent-calculate-indentation) 4))
333 (python-tests-look-at "{") 352 (python-tests-look-at "{")
334 (should (eq (car (python-indent-context)) 'inside-paren)) 353 (should (eq (car (python-indent-context)) :inside-paren-newline-start))
335 (should (= (python-indent-calculate-indentation) 4)) 354 (should (= (python-indent-calculate-indentation) 4))
336 (python-tests-look-at "'objlist': [") 355 (python-tests-look-at "'objlist': [")
337 (should (eq (car (python-indent-context)) 'inside-paren)) 356 (should (eq (car (python-indent-context)) :inside-paren-newline-start))
338 (should (= (python-indent-calculate-indentation) 8)) 357 (should (= (python-indent-calculate-indentation) 8))
339 (python-tests-look-at "{") 358 (python-tests-look-at "{")
340 (should (eq (car (python-indent-context)) 'inside-paren)) 359 (should (eq (car (python-indent-context)) :inside-paren-newline-start))
341 (should (= (python-indent-calculate-indentation) 12)) 360 (should (= (python-indent-calculate-indentation) 12))
342 (python-tests-look-at "'pk': 1,") 361 (python-tests-look-at "'pk': 1,")
343 (should (eq (car (python-indent-context)) 'inside-paren)) 362 (should (eq (car (python-indent-context)) :inside-paren-newline-start))
344 (should (= (python-indent-calculate-indentation) 16)) 363 (should (= (python-indent-calculate-indentation) 16))
345 (python-tests-look-at "'name': 'first',") 364 (python-tests-look-at "'name': 'first',")
346 (should (eq (car (python-indent-context)) 'inside-paren)) 365 (should (eq (car (python-indent-context)) :inside-paren-newline-start))
347 (should (= (python-indent-calculate-indentation) 16)) 366 (should (= (python-indent-calculate-indentation) 16))
348 (python-tests-look-at "},") 367 (python-tests-look-at "},")
349 (should (eq (car (python-indent-context)) 'inside-paren)) 368 (should (eq (car (python-indent-context))
369 :inside-paren-at-closing-nested-paren))
350 (should (= (python-indent-calculate-indentation) 12)) 370 (should (= (python-indent-calculate-indentation) 12))
351 (python-tests-look-at "{") 371 (python-tests-look-at "{")
352 (should (eq (car (python-indent-context)) 'inside-paren)) 372 (should (eq (car (python-indent-context)) :inside-paren-newline-start))
353 (should (= (python-indent-calculate-indentation) 12)) 373 (should (= (python-indent-calculate-indentation) 12))
354 (python-tests-look-at "'pk': 2,") 374 (python-tests-look-at "'pk': 2,")
355 (should (eq (car (python-indent-context)) 'inside-paren)) 375 (should (eq (car (python-indent-context)) :inside-paren-newline-start))
356 (should (= (python-indent-calculate-indentation) 16)) 376 (should (= (python-indent-calculate-indentation) 16))
357 (python-tests-look-at "'name': 'second',") 377 (python-tests-look-at "'name': 'second',")
358 (should (eq (car (python-indent-context)) 'inside-paren)) 378 (should (eq (car (python-indent-context)) :inside-paren-newline-start))
359 (should (= (python-indent-calculate-indentation) 16)) 379 (should (= (python-indent-calculate-indentation) 16))
360 (python-tests-look-at "}") 380 (python-tests-look-at "}")
361 (should (eq (car (python-indent-context)) 'inside-paren)) 381 (should (eq (car (python-indent-context))
382 :inside-paren-at-closing-nested-paren))
362 (should (= (python-indent-calculate-indentation) 12)) 383 (should (= (python-indent-calculate-indentation) 12))
363 (python-tests-look-at "]") 384 (python-tests-look-at "]")
364 (should (eq (car (python-indent-context)) 'inside-paren)) 385 (should (eq (car (python-indent-context))
386 :inside-paren-at-closing-nested-paren))
365 (should (= (python-indent-calculate-indentation) 8)) 387 (should (= (python-indent-calculate-indentation) 8))
366 (python-tests-look-at "}") 388 (python-tests-look-at "}")
367 (should (eq (car (python-indent-context)) 'inside-paren)) 389 (should (eq (car (python-indent-context))
390 :inside-paren-at-closing-nested-paren))
368 (should (= (python-indent-calculate-indentation) 4)) 391 (should (= (python-indent-calculate-indentation) 4))
369 (python-tests-look-at "}") 392 (python-tests-look-at "}")
370 (should (eq (car (python-indent-context)) 'inside-paren)) 393 (should (eq (car (python-indent-context)) :inside-paren-at-closing-paren))
371 (should (= (python-indent-calculate-indentation) 0)))) 394 (should (= (python-indent-calculate-indentation) 0))))
372 395
373(ert-deftest python-indent-inside-paren-2 () 396(ert-deftest python-indent-inside-paren-2 ()
@@ -384,43 +407,121 @@ data = {'key': {
384}} 407}}
385" 408"
386 (python-tests-look-at "data = {") 409 (python-tests-look-at "data = {")
387 (should (eq (car (python-indent-context)) 'after-line)) 410 (should (eq (car (python-indent-context)) :after-line))
388 (should (= (python-indent-calculate-indentation) 0)) 411 (should (= (python-indent-calculate-indentation) 0))
389 (python-tests-look-at "'objlist': [") 412 (python-tests-look-at "'objlist': [")
390 (should (eq (car (python-indent-context)) 'inside-paren)) 413 (should (eq (car (python-indent-context)) :inside-paren-newline-start))
391 (should (= (python-indent-calculate-indentation) 4)) 414 (should (= (python-indent-calculate-indentation) 4))
392 (python-tests-look-at "{'pk': 1,") 415 (python-tests-look-at "{'pk': 1,")
393 (should (eq (car (python-indent-context)) 'inside-paren)) 416 (should (eq (car (python-indent-context)) :inside-paren-newline-start))
394 (should (= (python-indent-calculate-indentation) 8)) 417 (should (= (python-indent-calculate-indentation) 8))
395 (python-tests-look-at "'name': 'first'},") 418 (python-tests-look-at "'name': 'first'},")
396 (should (eq (car (python-indent-context)) 'inside-paren)) 419 (should (eq (car (python-indent-context)) :inside-paren))
397 (should (= (python-indent-calculate-indentation) 9)) 420 (should (= (python-indent-calculate-indentation) 9))
398 (python-tests-look-at "{'pk': 2,") 421 (python-tests-look-at "{'pk': 2,")
399 (should (eq (car (python-indent-context)) 'inside-paren)) 422 (should (eq (car (python-indent-context)) :inside-paren-newline-start))
400 (should (= (python-indent-calculate-indentation) 8)) 423 (should (= (python-indent-calculate-indentation) 8))
401 (python-tests-look-at "'name': 'second'}") 424 (python-tests-look-at "'name': 'second'}")
402 (should (eq (car (python-indent-context)) 'inside-paren)) 425 (should (eq (car (python-indent-context)) :inside-paren))
403 (should (= (python-indent-calculate-indentation) 9)) 426 (should (= (python-indent-calculate-indentation) 9))
404 (python-tests-look-at "]") 427 (python-tests-look-at "]")
405 (should (eq (car (python-indent-context)) 'inside-paren)) 428 (should (eq (car (python-indent-context))
429 :inside-paren-at-closing-nested-paren))
406 (should (= (python-indent-calculate-indentation) 4)) 430 (should (= (python-indent-calculate-indentation) 4))
407 (python-tests-look-at "}}") 431 (python-tests-look-at "}}")
408 (should (eq (car (python-indent-context)) 'inside-paren)) 432 (should (eq (car (python-indent-context))
433 :inside-paren-at-closing-nested-paren))
409 (should (= (python-indent-calculate-indentation) 0)) 434 (should (= (python-indent-calculate-indentation) 0))
410 (python-tests-look-at "}") 435 (python-tests-look-at "}")
411 (should (eq (car (python-indent-context)) 'inside-paren)) 436 (should (eq (car (python-indent-context)) :inside-paren-at-closing-paren))
412 (should (= (python-indent-calculate-indentation) 0)))) 437 (should (= (python-indent-calculate-indentation) 0))))
413 438
439(ert-deftest python-indent-inside-paren-3 ()
440 "The simplest case possible."
441 (python-tests-with-temp-buffer
442 "
443data = ('these',
444 'are',
445 'the',
446 'tokens')
447"
448 (python-tests-look-at "data = ('these',")
449 (should (eq (car (python-indent-context)) :after-line))
450 (should (= (python-indent-calculate-indentation) 0))
451 (forward-line 1)
452 (should (eq (car (python-indent-context)) :inside-paren))
453 (should (= (python-indent-calculate-indentation) 8))
454 (forward-line 1)
455 (should (eq (car (python-indent-context)) :inside-paren))
456 (should (= (python-indent-calculate-indentation) 8))
457 (forward-line 1)
458 (should (eq (car (python-indent-context)) :inside-paren))
459 (should (= (python-indent-calculate-indentation) 8))))
460
461(ert-deftest python-indent-inside-paren-4 ()
462 "Respect indentation of first column."
463 (python-tests-with-temp-buffer
464 "
465data = [ [ 'these', 'are'],
466 ['the', 'tokens' ] ]
467"
468 (python-tests-look-at "data = [ [ 'these', 'are'],")
469 (should (eq (car (python-indent-context)) :after-line))
470 (should (= (python-indent-calculate-indentation) 0))
471 (forward-line 1)
472 (should (eq (car (python-indent-context)) :inside-paren))
473 (should (= (python-indent-calculate-indentation) 9))))
474
475(ert-deftest python-indent-inside-paren-5 ()
476 "Test when :inside-paren initial parens are skipped in context start."
477 (python-tests-with-temp-buffer
478 "
479while ((not some_condition) and
480 another_condition):
481 do_something_interesting(
482 with_some_arg)
483"
484 (python-tests-look-at "while ((not some_condition) and")
485 (should (eq (car (python-indent-context)) :after-line))
486 (should (= (python-indent-calculate-indentation) 0))
487 (forward-line 1)
488 (should (eq (car (python-indent-context)) :inside-paren))
489 (should (= (python-indent-calculate-indentation) 7))
490 (forward-line 1)
491 (should (eq (car (python-indent-context)) :after-block-start))
492 (should (= (python-indent-calculate-indentation) 4))
493 (forward-line 1)
494 (should (eq (car (python-indent-context)) :inside-paren-newline-start))
495 (should (= (python-indent-calculate-indentation) 8))))
496
497(ert-deftest python-indent-inside-paren-6 ()
498 "This should be aligned.."
499 (python-tests-with-temp-buffer
500 "
501CHOICES = (('some', 'choice'),
502 ('another', 'choice'),
503 ('more', 'choices'))
504"
505 (python-tests-look-at "CHOICES = (('some', 'choice'),")
506 (should (eq (car (python-indent-context)) :after-line))
507 (should (= (python-indent-calculate-indentation) 0))
508 (forward-line 1)
509 (should (eq (car (python-indent-context)) :inside-paren))
510 (should (= (python-indent-calculate-indentation) 11))
511 (forward-line 1)
512 (should (eq (car (python-indent-context)) :inside-paren))
513 (should (= (python-indent-calculate-indentation) 11))))
514
414(ert-deftest python-indent-after-block-1 () 515(ert-deftest python-indent-after-block-1 ()
415 "The most simple after-block case that shouldn't fail." 516 "The most simple after-block case that shouldn't fail."
416 (python-tests-with-temp-buffer 517 (python-tests-with-temp-buffer
417 " 518 "
418def foo(a, b, c=True): 519def foo(a, b, c=True):
419" 520"
420 (should (eq (car (python-indent-context)) 'no-indent)) 521 (should (eq (car (python-indent-context)) :no-indent))
421 (should (= (python-indent-calculate-indentation) 0)) 522 (should (= (python-indent-calculate-indentation) 0))
422 (goto-char (point-max)) 523 (goto-char (point-max))
423 (should (eq (car (python-indent-context)) 'after-beginning-of-block)) 524 (should (eq (car (python-indent-context)) :after-block-start))
424 (should (= (python-indent-calculate-indentation) 4)))) 525 (should (= (python-indent-calculate-indentation) 4))))
425 526
426(ert-deftest python-indent-after-block-2 () 527(ert-deftest python-indent-after-block-2 ()
@@ -432,9 +533,28 @@ def foo(a, b, c={
432}): 533}):
433" 534"
434 (goto-char (point-max)) 535 (goto-char (point-max))
435 (should (eq (car (python-indent-context)) 'after-beginning-of-block)) 536 (should (eq (car (python-indent-context)) :after-block-start))
436 (should (= (python-indent-calculate-indentation) 4)))) 537 (should (= (python-indent-calculate-indentation) 4))))
437 538
539(ert-deftest python-indent-after-block-3 ()
540 "A weird (malformed) sample, usually found in python shells."
541 (python-tests-with-temp-buffer
542 "
543In [1]:
544def func():
545pass
546
547In [2]:
548something
549"
550 (python-tests-look-at "pass")
551 (should (eq (car (python-indent-context)) :after-block-start))
552 (should (= (python-indent-calculate-indentation) 4))
553 (python-tests-look-at "something")
554 (end-of-line)
555 (should (eq (car (python-indent-context)) :after-line))
556 (should (= (python-indent-calculate-indentation) 0))))
557
438(ert-deftest python-indent-after-backslash-1 () 558(ert-deftest python-indent-after-backslash-1 ()
439 "The most common case." 559 "The most common case."
440 (python-tests-with-temp-buffer 560 (python-tests-with-temp-buffer
@@ -444,16 +564,16 @@ from foo.bar.baz import something, something_1 \\\\
444 something_4, something_5 564 something_4, something_5
445" 565"
446 (python-tests-look-at "from foo.bar.baz import something, something_1") 566 (python-tests-look-at "from foo.bar.baz import something, something_1")
447 (should (eq (car (python-indent-context)) 'after-line)) 567 (should (eq (car (python-indent-context)) :after-line))
448 (should (= (python-indent-calculate-indentation) 0)) 568 (should (= (python-indent-calculate-indentation) 0))
449 (python-tests-look-at "something_2 something_3,") 569 (python-tests-look-at "something_2 something_3,")
450 (should (eq (car (python-indent-context)) 'after-backslash)) 570 (should (eq (car (python-indent-context)) :after-backslash-first-line))
451 (should (= (python-indent-calculate-indentation) 4)) 571 (should (= (python-indent-calculate-indentation) 4))
452 (python-tests-look-at "something_4, something_5") 572 (python-tests-look-at "something_4, something_5")
453 (should (eq (car (python-indent-context)) 'after-backslash)) 573 (should (eq (car (python-indent-context)) :after-backslash))
454 (should (= (python-indent-calculate-indentation) 4)) 574 (should (= (python-indent-calculate-indentation) 4))
455 (goto-char (point-max)) 575 (goto-char (point-max))
456 (should (eq (car (python-indent-context)) 'after-line)) 576 (should (eq (car (python-indent-context)) :after-line))
457 (should (= (python-indent-calculate-indentation) 0)))) 577 (should (= (python-indent-calculate-indentation) 0))))
458 578
459(ert-deftest python-indent-after-backslash-2 () 579(ert-deftest python-indent-after-backslash-2 ()
@@ -471,40 +591,104 @@ objects = Thing.objects.all() \\\\
471 .values_list() 591 .values_list()
472" 592"
473 (python-tests-look-at "objects = Thing.objects.all()") 593 (python-tests-look-at "objects = Thing.objects.all()")
474 (should (eq (car (python-indent-context)) 'after-line)) 594 (should (eq (car (python-indent-context)) :after-line))
475 (should (= (python-indent-calculate-indentation) 0)) 595 (should (= (python-indent-calculate-indentation) 0))
476 (python-tests-look-at ".filter(") 596 (python-tests-look-at ".filter(")
477 (should (eq (car (python-indent-context)) 'after-backslash)) 597 (should (eq (car (python-indent-context))
598 :after-backslash-dotted-continuation))
478 (should (= (python-indent-calculate-indentation) 23)) 599 (should (= (python-indent-calculate-indentation) 23))
479 (python-tests-look-at "type='toy',") 600 (python-tests-look-at "type='toy',")
480 (should (eq (car (python-indent-context)) 'inside-paren)) 601 (should (eq (car (python-indent-context)) :inside-paren-newline-start))
481 (should (= (python-indent-calculate-indentation) 27)) 602 (should (= (python-indent-calculate-indentation) 27))
482 (python-tests-look-at "status='bought'") 603 (python-tests-look-at "status='bought'")
483 (should (eq (car (python-indent-context)) 'inside-paren)) 604 (should (eq (car (python-indent-context)) :inside-paren-newline-start))
484 (should (= (python-indent-calculate-indentation) 27)) 605 (should (= (python-indent-calculate-indentation) 27))
485 (python-tests-look-at ") \\\\") 606 (python-tests-look-at ") \\\\")
486 (should (eq (car (python-indent-context)) 'inside-paren)) 607 (should (eq (car (python-indent-context)) :inside-paren-at-closing-paren))
487 (should (= (python-indent-calculate-indentation) 23)) 608 (should (= (python-indent-calculate-indentation) 23))
488 (python-tests-look-at ".aggregate(") 609 (python-tests-look-at ".aggregate(")
489 (should (eq (car (python-indent-context)) 'after-backslash)) 610 (should (eq (car (python-indent-context))
611 :after-backslash-dotted-continuation))
490 (should (= (python-indent-calculate-indentation) 23)) 612 (should (= (python-indent-calculate-indentation) 23))
491 (python-tests-look-at "Sum('amount')") 613 (python-tests-look-at "Sum('amount')")
492 (should (eq (car (python-indent-context)) 'inside-paren)) 614 (should (eq (car (python-indent-context)) :inside-paren-newline-start))
493 (should (= (python-indent-calculate-indentation) 27)) 615 (should (= (python-indent-calculate-indentation) 27))
494 (python-tests-look-at ") \\\\") 616 (python-tests-look-at ") \\\\")
495 (should (eq (car (python-indent-context)) 'inside-paren)) 617 (should (eq (car (python-indent-context)) :inside-paren-at-closing-paren))
496 (should (= (python-indent-calculate-indentation) 23)) 618 (should (= (python-indent-calculate-indentation) 23))
497 (python-tests-look-at ".values_list()") 619 (python-tests-look-at ".values_list()")
498 (should (eq (car (python-indent-context)) 'after-backslash)) 620 (should (eq (car (python-indent-context))
621 :after-backslash-dotted-continuation))
499 (should (= (python-indent-calculate-indentation) 23)) 622 (should (= (python-indent-calculate-indentation) 23))
500 (forward-line 1) 623 (forward-line 1)
501 (should (eq (car (python-indent-context)) 'after-line)) 624 (should (eq (car (python-indent-context)) :after-line))
502 (should (= (python-indent-calculate-indentation) 0)))) 625 (should (= (python-indent-calculate-indentation) 0))))
503 626
627(ert-deftest python-indent-after-backslash-3 ()
628 "Backslash continuation from block start."
629 (python-tests-with-temp-buffer
630 "
631with open('/path/to/some/file/you/want/to/read') as file_1, \\\\
632 open('/path/to/some/file/being/written', 'w') as file_2:
633 file_2.write(file_1.read())
634"
635 (python-tests-look-at
636 "with open('/path/to/some/file/you/want/to/read') as file_1, \\\\")
637 (should (eq (car (python-indent-context)) :after-line))
638 (should (= (python-indent-calculate-indentation) 0))
639 (python-tests-look-at
640 "open('/path/to/some/file/being/written', 'w') as file_2")
641 (should (eq (car (python-indent-context))
642 :after-backslash-block-continuation))
643 (should (= (python-indent-calculate-indentation) 5))
644 (python-tests-look-at "file_2.write(file_1.read())")
645 (should (eq (car (python-indent-context)) :after-block-start))
646 (should (= (python-indent-calculate-indentation) 4))))
647
648(ert-deftest python-indent-after-backslash-4 ()
649 "Backslash continuation from assignment."
650 (python-tests-with-temp-buffer
651 "
652super_awful_assignment = some_calculation() and \\\\
653 another_calculation() and \\\\
654 some_final_calculation()
655"
656 (python-tests-look-at
657 "super_awful_assignment = some_calculation() and \\\\")
658 (should (eq (car (python-indent-context)) :after-line))
659 (should (= (python-indent-calculate-indentation) 0))
660 (python-tests-look-at "another_calculation() and \\\\")
661 (should (eq (car (python-indent-context))
662 :after-backslash-assignment-continuation))
663 (should (= (python-indent-calculate-indentation) 25))
664 (python-tests-look-at "some_final_calculation()")
665 (should (eq (car (python-indent-context)) :after-backslash))
666 (should (= (python-indent-calculate-indentation) 25))))
667
668(ert-deftest python-indent-after-backslash-5 ()
669 "Dotted continuation bizarre example."
670 (python-tests-with-temp-buffer
671 "
672def delete_all_things():
673 Thing \\\\
674 .objects.all() \\\\
675 .delete()
676"
677 (python-tests-look-at "Thing \\\\")
678 (should (eq (car (python-indent-context)) :after-block-start))
679 (should (= (python-indent-calculate-indentation) 4))
680 (python-tests-look-at ".objects.all() \\\\")
681 (should (eq (car (python-indent-context)) :after-backslash-first-line))
682 (should (= (python-indent-calculate-indentation) 8))
683 (python-tests-look-at ".delete()")
684 (should (eq (car (python-indent-context))
685 :after-backslash-dotted-continuation))
686 (should (= (python-indent-calculate-indentation) 16))))
687
504(ert-deftest python-indent-block-enders-1 () 688(ert-deftest python-indent-block-enders-1 ()
505 "Test de-indentation for pass keyword." 689 "Test de-indentation for pass keyword."
506 (python-tests-with-temp-buffer 690 (python-tests-with-temp-buffer
507 " 691 "
508Class foo(object): 692Class foo(object):
509 693
510 def bar(self): 694 def bar(self):
@@ -516,17 +700,18 @@ Class foo(object):
516 else: 700 else:
517 pass 701 pass
518" 702"
519 (python-tests-look-at "3)") 703 (python-tests-look-at "3)")
520 (forward-line 1) 704 (forward-line 1)
521 (should (= (python-indent-calculate-indentation) 8)) 705 (should (= (python-indent-calculate-indentation) 8))
522 (python-tests-look-at "pass") 706 (python-tests-look-at "pass")
523 (forward-line 1) 707 (forward-line 1)
524 (should (= (python-indent-calculate-indentation) 8)))) 708 (should (eq (car (python-indent-context)) :after-block-end))
709 (should (= (python-indent-calculate-indentation) 8))))
525 710
526(ert-deftest python-indent-block-enders-2 () 711(ert-deftest python-indent-block-enders-2 ()
527 "Test de-indentation for return keyword." 712 "Test de-indentation for return keyword."
528 (python-tests-with-temp-buffer 713 (python-tests-with-temp-buffer
529 " 714 "
530Class foo(object): 715Class foo(object):
531 '''raise lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do 716 '''raise lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
532 717
@@ -539,64 +724,68 @@ Class foo(object):
539 2, 724 2,
540 3) 725 3)
541" 726"
542 (python-tests-look-at "def") 727 (python-tests-look-at "def")
543 (should (= (python-indent-calculate-indentation) 4)) 728 (should (= (python-indent-calculate-indentation) 4))
544 (python-tests-look-at "if") 729 (python-tests-look-at "if")
545 (should (= (python-indent-calculate-indentation) 8)) 730 (should (= (python-indent-calculate-indentation) 8))
546 (python-tests-look-at "return") 731 (python-tests-look-at "return")
547 (should (= (python-indent-calculate-indentation) 12)) 732 (should (= (python-indent-calculate-indentation) 12))
548 (goto-char (point-max)) 733 (goto-char (point-max))
549 (should (= (python-indent-calculate-indentation) 8)))) 734 (should (eq (car (python-indent-context)) :after-block-end))
735 (should (= (python-indent-calculate-indentation) 8))))
550 736
551(ert-deftest python-indent-block-enders-3 () 737(ert-deftest python-indent-block-enders-3 ()
552 "Test de-indentation for continue keyword." 738 "Test de-indentation for continue keyword."
553 (python-tests-with-temp-buffer 739 (python-tests-with-temp-buffer
554 " 740 "
555for element in lst: 741for element in lst:
556 if element is None: 742 if element is None:
557 continue 743 continue
558" 744"
559 (python-tests-look-at "if") 745 (python-tests-look-at "if")
560 (should (= (python-indent-calculate-indentation) 4)) 746 (should (= (python-indent-calculate-indentation) 4))
561 (python-tests-look-at "continue") 747 (python-tests-look-at "continue")
562 (should (= (python-indent-calculate-indentation) 8)) 748 (should (= (python-indent-calculate-indentation) 8))
563 (forward-line 1) 749 (forward-line 1)
564 (should (= (python-indent-calculate-indentation) 4)))) 750 (should (eq (car (python-indent-context)) :after-block-end))
751 (should (= (python-indent-calculate-indentation) 4))))
565 752
566(ert-deftest python-indent-block-enders-4 () 753(ert-deftest python-indent-block-enders-4 ()
567 "Test de-indentation for break keyword." 754 "Test de-indentation for break keyword."
568 (python-tests-with-temp-buffer 755 (python-tests-with-temp-buffer
569 " 756 "
570for element in lst: 757for element in lst:
571 if element is None: 758 if element is None:
572 break 759 break
573" 760"
574 (python-tests-look-at "if") 761 (python-tests-look-at "if")
575 (should (= (python-indent-calculate-indentation) 4)) 762 (should (= (python-indent-calculate-indentation) 4))
576 (python-tests-look-at "break") 763 (python-tests-look-at "break")
577 (should (= (python-indent-calculate-indentation) 8)) 764 (should (= (python-indent-calculate-indentation) 8))
578 (forward-line 1) 765 (forward-line 1)
579 (should (= (python-indent-calculate-indentation) 4)))) 766 (should (eq (car (python-indent-context)) :after-block-end))
767 (should (= (python-indent-calculate-indentation) 4))))
580 768
581(ert-deftest python-indent-block-enders-5 () 769(ert-deftest python-indent-block-enders-5 ()
582 "Test de-indentation for raise keyword." 770 "Test de-indentation for raise keyword."
583 (python-tests-with-temp-buffer 771 (python-tests-with-temp-buffer
584 " 772 "
585for element in lst: 773for element in lst:
586 if element is None: 774 if element is None:
587 raise ValueError('Element cannot be None') 775 raise ValueError('Element cannot be None')
588" 776"
589 (python-tests-look-at "if") 777 (python-tests-look-at "if")
590 (should (= (python-indent-calculate-indentation) 4)) 778 (should (= (python-indent-calculate-indentation) 4))
591 (python-tests-look-at "raise") 779 (python-tests-look-at "raise")
592 (should (= (python-indent-calculate-indentation) 8)) 780 (should (= (python-indent-calculate-indentation) 8))
593 (forward-line 1) 781 (forward-line 1)
594 (should (= (python-indent-calculate-indentation) 4)))) 782 (should (eq (car (python-indent-context)) :after-block-end))
783 (should (= (python-indent-calculate-indentation) 4))))
595 784
596(ert-deftest python-indent-dedenters-1 () 785(ert-deftest python-indent-dedenters-1 ()
597 "Test de-indentation for the elif keyword." 786 "Test de-indentation for the elif keyword."
598 (python-tests-with-temp-buffer 787 (python-tests-with-temp-buffer
599 " 788 "
600if save: 789if save:
601 try: 790 try:
602 write_to_disk(data) 791 write_to_disk(data)
@@ -604,15 +793,15 @@ if save:
604 cleanup() 793 cleanup()
605 elif 794 elif
606" 795"
607 (python-tests-look-at "elif\n") 796 (python-tests-look-at "elif\n")
608 (should (eq (car (python-indent-context)) 'dedenter-statement)) 797 (should (eq (car (python-indent-context)) :at-dedenter-block-start))
609 (should (= (python-indent-calculate-indentation) 0)) 798 (should (= (python-indent-calculate-indentation) 0))
610 (should (equal (python-indent-calculate-levels) '(0))))) 799 (should (= (python-indent-calculate-indentation t) 0))))
611 800
612(ert-deftest python-indent-dedenters-2 () 801(ert-deftest python-indent-dedenters-2 ()
613 "Test de-indentation for the else keyword." 802 "Test de-indentation for the else keyword."
614 (python-tests-with-temp-buffer 803 (python-tests-with-temp-buffer
615 " 804 "
616if save: 805if save:
617 try: 806 try:
618 write_to_disk(data) 807 write_to_disk(data)
@@ -627,43 +816,50 @@ if save:
627 finally: 816 finally:
628 data.free() 817 data.free()
629" 818"
630 (python-tests-look-at "else\n") 819 (python-tests-look-at "else\n")
631 (should (eq (car (python-indent-context)) 'dedenter-statement)) 820 (should (eq (car (python-indent-context)) :at-dedenter-block-start))
632 (should (= (python-indent-calculate-indentation) 8)) 821 (should (= (python-indent-calculate-indentation) 8))
633 (should (equal (python-indent-calculate-levels) '(0 4 8))))) 822 (python-indent-line t)
823 (should (= (python-indent-calculate-indentation t) 4))
824 (python-indent-line t)
825 (should (= (python-indent-calculate-indentation t) 0))
826 (python-indent-line t)
827 (should (= (python-indent-calculate-indentation t) 8))))
634 828
635(ert-deftest python-indent-dedenters-3 () 829(ert-deftest python-indent-dedenters-3 ()
636 "Test de-indentation for the except keyword." 830 "Test de-indentation for the except keyword."
637 (python-tests-with-temp-buffer 831 (python-tests-with-temp-buffer
638 " 832 "
639if save: 833if save:
640 try: 834 try:
641 write_to_disk(data) 835 write_to_disk(data)
642 except 836 except
643" 837"
644 (python-tests-look-at "except\n") 838 (python-tests-look-at "except\n")
645 (should (eq (car (python-indent-context)) 'dedenter-statement)) 839 (should (eq (car (python-indent-context)) :at-dedenter-block-start))
646 (should (= (python-indent-calculate-indentation) 4)) 840 (should (= (python-indent-calculate-indentation) 4))
647 (should (equal (python-indent-calculate-levels) '(4))))) 841 (python-indent-line t)
842 (should (= (python-indent-calculate-indentation t) 4))))
648 843
649(ert-deftest python-indent-dedenters-4 () 844(ert-deftest python-indent-dedenters-4 ()
650 "Test de-indentation for the finally keyword." 845 "Test de-indentation for the finally keyword."
651 (python-tests-with-temp-buffer 846 (python-tests-with-temp-buffer
652 " 847 "
653if save: 848if save:
654 try: 849 try:
655 write_to_disk(data) 850 write_to_disk(data)
656 finally 851 finally
657" 852"
658 (python-tests-look-at "finally\n") 853 (python-tests-look-at "finally\n")
659 (should (eq (car (python-indent-context)) 'dedenter-statement)) 854 (should (eq (car (python-indent-context)) :at-dedenter-block-start))
660 (should (= (python-indent-calculate-indentation) 4)) 855 (should (= (python-indent-calculate-indentation) 4))
661 (should (equal (python-indent-calculate-levels) '(4))))) 856 (python-indent-line t)
857 (should (= (python-indent-calculate-indentation) 4))))
662 858
663(ert-deftest python-indent-dedenters-5 () 859(ert-deftest python-indent-dedenters-5 ()
664 "Test invalid levels are skipped in a complex example." 860 "Test invalid levels are skipped in a complex example."
665 (python-tests-with-temp-buffer 861 (python-tests-with-temp-buffer
666 " 862 "
667if save: 863if save:
668 try: 864 try:
669 write_to_disk(data) 865 write_to_disk(data)
@@ -676,29 +872,31 @@ if save:
676 do_cleanup() 872 do_cleanup()
677 else 873 else
678" 874"
679 (python-tests-look-at "else\n") 875 (python-tests-look-at "else\n")
680 (should (eq (car (python-indent-context)) 'dedenter-statement)) 876 (should (eq (car (python-indent-context)) :at-dedenter-block-start))
681 (should (= (python-indent-calculate-indentation) 8)) 877 (should (= (python-indent-calculate-indentation) 8))
682 (should (equal (python-indent-calculate-levels) '(0 8))))) 878 (should (= (python-indent-calculate-indentation t) 0))
879 (python-indent-line t)
880 (should (= (python-indent-calculate-indentation t) 8))))
683 881
684(ert-deftest python-indent-dedenters-6 () 882(ert-deftest python-indent-dedenters-6 ()
685 "Test indentation is zero when no opening block for dedenter." 883 "Test indentation is zero when no opening block for dedenter."
686 (python-tests-with-temp-buffer 884 (python-tests-with-temp-buffer
687 " 885 "
688try: 886try:
689 # if save: 887 # if save:
690 write_to_disk(data) 888 write_to_disk(data)
691 else 889 else
692" 890"
693 (python-tests-look-at "else\n") 891 (python-tests-look-at "else\n")
694 (should (eq (car (python-indent-context)) 'dedenter-statement)) 892 (should (eq (car (python-indent-context)) :at-dedenter-block-start))
695 (should (= (python-indent-calculate-indentation) 0)) 893 (should (= (python-indent-calculate-indentation) 0))
696 (should (equal (python-indent-calculate-levels) '(0))))) 894 (should (= (python-indent-calculate-indentation t) 0))))
697 895
698(ert-deftest python-indent-dedenters-7 () 896(ert-deftest python-indent-dedenters-7 ()
699 "Test indentation case from Bug#15163." 897 "Test indentation case from Bug#15163."
700 (python-tests-with-temp-buffer 898 (python-tests-with-temp-buffer
701 " 899 "
702if a: 900if a:
703 if b: 901 if b:
704 pass 902 pass
@@ -706,10 +904,10 @@ if a:
706 pass 904 pass
707 else: 905 else:
708" 906"
709 (python-tests-look-at "else:" 2) 907 (python-tests-look-at "else:" 2)
710 (should (eq (car (python-indent-context)) 'dedenter-statement)) 908 (should (eq (car (python-indent-context)) :at-dedenter-block-start))
711 (should (= (python-indent-calculate-indentation) 0)) 909 (should (= (python-indent-calculate-indentation) 0))
712 (should (equal (python-indent-calculate-levels) '(0))))) 910 (should (= (python-indent-calculate-indentation t) 0))))
713 911
714(ert-deftest python-indent-dedenters-8 () 912(ert-deftest python-indent-dedenters-8 ()
715 "Test indentation for Bug#18432." 913 "Test indentation for Bug#18432."
@@ -721,10 +919,99 @@ if (a == 1 or
721elif (a == 3 or 919elif (a == 3 or
722a == 4): 920a == 4):
723" 921"
922 (python-tests-look-at "elif (a == 3 or")
923 (should (eq (car (python-indent-context)) :at-dedenter-block-start))
924 (should (= (python-indent-calculate-indentation) 0))
925 (should (= (python-indent-calculate-indentation t) 0))
724 (python-tests-look-at "a == 4):\n") 926 (python-tests-look-at "a == 4):\n")
725 (should (eq (car (python-indent-context)) 'inside-paren)) 927 (should (eq (car (python-indent-context)) :inside-paren))
726 (should (= (python-indent-calculate-indentation) 6)) 928 (should (= (python-indent-calculate-indentation) 6))
727 (should (equal (python-indent-calculate-levels) '(0 4 6))))) 929 (python-indent-line)
930 (should (= (python-indent-calculate-indentation t) 4))
931 (python-indent-line t)
932 (should (= (python-indent-calculate-indentation t) 0))
933 (python-indent-line t)
934 (should (= (python-indent-calculate-indentation t) 6))))
935
936(ert-deftest python-indent-inside-string-1 ()
937 "Test indentation for strings."
938 (python-tests-with-temp-buffer
939 "
940multiline = '''
941bunch
942of
943lines
944'''
945"
946 (python-tests-look-at "multiline = '''")
947 (should (eq (car (python-indent-context)) :after-line))
948 (should (= (python-indent-calculate-indentation) 0))
949 (python-tests-look-at "bunch")
950 (should (eq (car (python-indent-context)) :inside-string))
951 (should (= (python-indent-calculate-indentation) 0))
952 (python-tests-look-at "of")
953 (should (eq (car (python-indent-context)) :inside-string))
954 (should (= (python-indent-calculate-indentation) 0))
955 (python-tests-look-at "lines")
956 (should (eq (car (python-indent-context)) :inside-string))
957 (should (= (python-indent-calculate-indentation) 0))
958 (python-tests-look-at "'''")
959 (should (eq (car (python-indent-context)) :inside-string))
960 (should (= (python-indent-calculate-indentation) 0))))
961
962(ert-deftest python-indent-inside-string-2 ()
963 "Test indentation for docstrings."
964 (python-tests-with-temp-buffer
965 "
966def fn(a, b, c=True):
967 '''docstring
968 bunch
969 of
970 lines
971 '''
972"
973 (python-tests-look-at "'''docstring")
974 (should (eq (car (python-indent-context)) :after-block-start))
975 (should (= (python-indent-calculate-indentation) 4))
976 (python-tests-look-at "bunch")
977 (should (eq (car (python-indent-context)) :inside-string))
978 (should (= (python-indent-calculate-indentation) 4))
979 (python-tests-look-at "of")
980 (should (eq (car (python-indent-context)) :inside-string))
981 (should (= (python-indent-calculate-indentation) 4))
982 (python-tests-look-at "lines")
983 (should (eq (car (python-indent-context)) :inside-string))
984 (should (= (python-indent-calculate-indentation) 4))
985 (python-tests-look-at "'''")
986 (should (eq (car (python-indent-context)) :inside-string))
987 (should (= (python-indent-calculate-indentation) 4))))
988
989(ert-deftest python-indent-inside-string-3 ()
990 "Test indentation for nested strings."
991 (python-tests-with-temp-buffer
992 "
993def fn(a, b, c=True):
994 some_var = '''
995 bunch
996 of
997 lines
998 '''
999"
1000 (python-tests-look-at "some_var = '''")
1001 (should (eq (car (python-indent-context)) :after-block-start))
1002 (should (= (python-indent-calculate-indentation) 4))
1003 (python-tests-look-at "bunch")
1004 (should (eq (car (python-indent-context)) :inside-string))
1005 (should (= (python-indent-calculate-indentation) 4))
1006 (python-tests-look-at "of")
1007 (should (eq (car (python-indent-context)) :inside-string))
1008 (should (= (python-indent-calculate-indentation) 4))
1009 (python-tests-look-at "lines")
1010 (should (eq (car (python-indent-context)) :inside-string))
1011 (should (= (python-indent-calculate-indentation) 4))
1012 (python-tests-look-at "'''")
1013 (should (eq (car (python-indent-context)) :inside-string))
1014 (should (= (python-indent-calculate-indentation) 4))))
728 1015
729(ert-deftest python-indent-electric-colon-1 () 1016(ert-deftest python-indent-electric-colon-1 ()
730 "Test indentation case from Bug#18228." 1017 "Test indentation case from Bug#18228."
@@ -1802,6 +2089,23 @@ def f():
1802 (python-nav-backward-up-list) 2089 (python-nav-backward-up-list)
1803 (should (looking-at "def f():")))) 2090 (should (looking-at "def f():"))))
1804 2091
2092(ert-deftest python-indent-dedent-line-backspace-1 ()
2093 "Check de-indentation on first call. Bug#18319."
2094 (python-tests-with-temp-buffer
2095 "
2096if True:
2097 x ()
2098 if False:
2099"
2100 (python-tests-look-at "if False:")
2101 (call-interactively #'python-indent-dedent-line-backspace)
2102 (should (zerop (current-indentation)))
2103 ;; XXX: This should be a call to `undo' but it's triggering errors.
2104 (insert " ")
2105 (should (= (current-indentation) 4))
2106 (call-interactively #'python-indent-dedent-line-backspace)
2107 (should (zerop (current-indentation)))))
2108
1805 2109
1806;;; Shell integration 2110;;; Shell integration
1807 2111
diff --git a/test/automated/regexp-tests.el b/test/automated/regexp-tests.el
index 31a4ee958c6..ee177b3e2e9 100644
--- a/test/automated/regexp-tests.el
+++ b/test/automated/regexp-tests.el
@@ -23,6 +23,8 @@
23 23
24;;; Code: 24;;; Code:
25 25
26(require 'regexp-opt)
27
26(ert-deftest regexp-test-regexp-opt () 28(ert-deftest regexp-test-regexp-opt ()
27 "Test the `compilation-error-regexp-alist' regexps. 29 "Test the `compilation-error-regexp-alist' regexps.
28The test data is in `compile-tests--test-regexps-data'." 30The test data is in `compile-tests--test-regexps-data'."