aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lisp/emacs-lisp/lisp-mode.el27
-rw-r--r--test/lisp/emacs-lisp/lisp-mode-tests.el13
2 files changed, 26 insertions, 14 deletions
diff --git a/lisp/emacs-lisp/lisp-mode.el b/lisp/emacs-lisp/lisp-mode.el
index 1e38d44e1b1..59db00d5f96 100644
--- a/lisp/emacs-lisp/lisp-mode.el
+++ b/lisp/emacs-lisp/lisp-mode.el
@@ -773,11 +773,9 @@ complete sexp in the innermost containing list at position
773 (:constructor lisp-indent-initial-state 773 (:constructor lisp-indent-initial-state
774 (&aux (ppss (lisp-ppss)) 774 (&aux (ppss (lisp-ppss))
775 (ppss-point (point)) 775 (ppss-point (point))
776 (depth (car ppss)) 776 (stack (make-list (1+ (car ppss)) nil)))))
777 (stack (make-list (1+ depth) nil)))))
778 stack ;; Cached indentation, per depth. 777 stack ;; Cached indentation, per depth.
779 ppss 778 ppss
780 depth
781 ppss-point) 779 ppss-point)
782 780
783(defun lisp-indent-calc-next (state) 781(defun lisp-indent-calc-next (state)
@@ -785,9 +783,11 @@ complete sexp in the innermost containing list at position
785STATE is updated by side effect, the first state should be 783STATE is updated by side effect, the first state should be
786created by `lisp-indent-initial-state'. This function may move 784created by `lisp-indent-initial-state'. This function may move
787by more than one line to cross a string literal." 785by more than one line to cross a string literal."
788 (pcase-let (((cl-struct lisp-indent-state 786 (pcase-let* (((cl-struct lisp-indent-state
789 (stack indent-stack) ppss depth ppss-point) 787 (stack indent-stack) ppss ppss-point)
790 state)) 788 state)
789 (indent-depth (car ppss)) ; Corresponding to indent-stack.
790 (depth indent-depth))
791 ;; Parse this line so we can learn the state to indent the 791 ;; Parse this line so we can learn the state to indent the
792 ;; next line. 792 ;; next line.
793 (while (let ((last-sexp (nth 2 ppss))) 793 (while (let ((last-sexp (nth 2 ppss)))
@@ -799,22 +799,22 @@ by more than one line to cross a string literal."
799 (if (and (not (nth 2 ppss)) (= depth (car ppss))) 799 (if (and (not (nth 2 ppss)) (= depth (car ppss)))
800 (setf (nth 2 ppss) last-sexp) 800 (setf (nth 2 ppss) last-sexp)
801 (setq last-sexp (nth 2 ppss))) 801 (setq last-sexp (nth 2 ppss)))
802 (setq depth (car ppss))
802 ;; Skip over newlines within strings. 803 ;; Skip over newlines within strings.
803 (nth 3 ppss)) 804 (nth 3 ppss))
804 (let ((string-start (nth 8 ppss))) 805 (let ((string-start (nth 8 ppss)))
805 (setq ppss (parse-partial-sexp (point) (point-max) 806 (setq ppss (parse-partial-sexp (point) (point-max)
806 nil nil ppss 'syntax-table)) 807 nil nil ppss 'syntax-table))
807 (setf (nth 2 ppss) string-start)) ; Finished a complete string. 808 (setf (nth 2 ppss) string-start) ; Finished a complete string.
809 (setq depth (car ppss)))
808 (setq ppss-point (point))) 810 (setq ppss-point (point)))
809 (setq ppss-point (point)) 811 (setq ppss-point (point))
810 (let* ((next-depth (car ppss)) 812 (let* ((depth-delta (- depth indent-depth)))
811 (depth-delta (- next-depth depth)))
812 (cond ((< depth-delta 0) 813 (cond ((< depth-delta 0)
813 (setq indent-stack (nthcdr (- depth-delta) indent-stack))) 814 (setq indent-stack (nthcdr (- depth-delta) indent-stack)))
814 ((> depth-delta 0) 815 ((> depth-delta 0)
815 (setq indent-stack (nconc (make-list depth-delta nil) 816 (setq indent-stack (nconc (make-list depth-delta nil)
816 indent-stack)))) 817 indent-stack)))))
817 (setq depth next-depth))
818 (prog1 818 (prog1
819 (let (indent) 819 (let (indent)
820 (cond ((= (forward-line 1) 1) nil) 820 (cond ((= (forward-line 1) 1) nil)
@@ -826,7 +826,6 @@ by more than one line to cross a string literal."
826 ;; This only happens if we're in a string. 826 ;; This only happens if we're in a string.
827 (t (error "This shouldn't happen")))) 827 (t (error "This shouldn't happen"))))
828 (setf (lisp-indent-state-stack state) indent-stack) 828 (setf (lisp-indent-state-stack state) indent-stack)
829 (setf (lisp-indent-state-depth state) depth)
830 (setf (lisp-indent-state-ppss-point state) ppss-point) 829 (setf (lisp-indent-state-ppss-point state) ppss-point)
831 (setf (lisp-indent-state-ppss state) ppss)))) 830 (setf (lisp-indent-state-ppss state) ppss))))
832 831
diff --git a/test/lisp/emacs-lisp/lisp-mode-tests.el b/test/lisp/emacs-lisp/lisp-mode-tests.el
index f2fe7a6cf41..582041cfc2d 100644
--- a/test/lisp/emacs-lisp/lisp-mode-tests.el
+++ b/test/lisp/emacs-lisp/lisp-mode-tests.el
@@ -185,6 +185,19 @@ Test indentation in emacs-lisp-mode\"
185 (indent-region (point) (point-max)) 185 (indent-region (point) (point-max))
186 (should (equal (buffer-string) correct))))) 186 (should (equal (buffer-string) correct)))))
187 187
188(ert-deftest lisp-indent-region-after-string-literal ()
189 (with-temp-buffer
190 (insert "\
191\(user-error \"Unexpected initialization file: `%s'
192Expected initialization file: `%s'\"
193 (abbreviate-file-name user-init-file)
194 (abbreviate-file-name this-init-file))")
195 (let ((indent-tabs-mode nil)
196 (correct (buffer-string)))
197 (emacs-lisp-mode)
198 (indent-region (point-min) (point-max))
199 (should (equal (buffer-string) correct)))))
200
188 201
189(provide 'lisp-mode-tests) 202(provide 'lisp-mode-tests)
190;;; lisp-mode-tests.el ends here 203;;; lisp-mode-tests.el ends here