@@ -678,7 +678,9 @@ Implementation function for `clojure--find-indent-spec'."
678678 (let ((clojure--current-backtracking-depth (1+ clojure--current-backtracking-depth))
679679 (pos 0 ))
680680 ; ; Count how far we are from the start of the sexp.
681- (while (ignore-errors (clojure-backward-logical-sexp 1 ) t )
681+ (while (ignore-errors (clojure-backward-logical-sexp 1 )
682+ (not (or (bobp )
683+ (eq (char-before ) ?\n ))))
682684 (cl-incf pos))
683685 (let* ((function (thing-at-point 'symbol ))
684686 (method (or (when function ; ; Is there a spec here?
@@ -722,18 +724,20 @@ spec."
722724 " Return the normal indentation column for a sexp.
723725LAST-SEXP is the start of the previous sexp."
724726 (goto-char last-sexp)
727+ (forward-sexp 1 )
728+ (clojure-backward-logical-sexp 1 )
725729 (let ((last-sexp-start nil ))
726730 (unless (ignore-errors
727- (while (progn (skip-chars-backward " #?'`~@[:blank:]" )
728- (not (looking-at " ^" )))
731+ (while (string-match
732+ " [^[:blank:]]"
733+ (buffer-substring (line-beginning-position ) (point )))
729734 (setq last-sexp-start (prog1 (point )
730735 (forward-sexp -1 ))))
731736 t )
732737 ; ; If the last sexp was on the same line.
733738 (when (and last-sexp-start
734739 (> (line-end-position ) last-sexp-start))
735740 (goto-char last-sexp-start)))
736- (skip-chars-forward " [:blank:]" )
737741 (current-column )))
738742
739743(defun clojure--not-function-form-p ()
@@ -771,45 +775,47 @@ The property value can be
771775- a list, which is used by `clojure-backtracking-indent' .
772776
773777This function also returns nil meaning don't specify the indentation."
774- (let* ((forward-sexp-function #'clojure-forward-logical-sexp ))
775- ; ; Goto to the open-paren.
776- (goto-char (elt state 1 ))
777- ; ; Maps, sets, vectors and reader conditionals.
778- (if (clojure--not-function-form-p)
779- (1+ (current-column ))
780- ; ; Function or macro call.
781- (forward-char 1 )
782- (let ((method (clojure--find-indent-spec))
783- (containing-form-column (1- (current-column ))))
784- (pcase method
785- ((or (pred integerp) `(, method ))
786- (let ((pos -1 ))
787- ; ; `forward-sexp' will error if indent-point is after
788- ; ; the last sexp in the current sexp.
789- (ignore-errors
778+ ; ; Goto to the open-paren.
779+ (goto-char (elt state 1 ))
780+ ; ; Maps, sets, vectors and reader conditionals.
781+ (if (clojure--not-function-form-p)
782+ (1+ (current-column ))
783+ ; ; Function or macro call.
784+ (forward-char 1 )
785+ (let ((method (clojure--find-indent-spec))
786+ (containing-form-column (1- (current-column ))))
787+ (pcase method
788+ ((or (pred integerp) `(, method ))
789+ (let ((pos -1 ))
790+ (condition-case nil
790791 (while (<= (point ) indent-point)
791792 (clojure-forward-logical-sexp 1 )
792- (cl-incf pos)))
793- (cond
794- ((= pos (1+ method))
795- (+ lisp-body-indent containing-form-column))
796- ((> pos (1+ method))
797- (clojure--normal-indent calculate-lisp-indent-last-sexp))
798- (t
799- (+ (* 2 lisp-body-indent) containing-form-column)))))
800- (`:defn
801- (+ lisp-body-indent containing-form-column))
802- ((pred functionp)
803- (funcall method indent-point state))
804- ((and `nil
805- (guard (let ((function (thing-at-point 'sexp )))
806- (or (and clojure-defun-style-default-indent
807- ; ; largely to preserve useful alignment of :require, etc in ns
808- (not (string-match " ^:" function)))
809- (string-match " \\ `\\ (?:\\ S +/\\ )?\\ (def\\ |with-\\ )"
810- function)))))
811- (+ lisp-body-indent containing-form-column))
812- (_ (clojure--normal-indent calculate-lisp-indent-last-sexp)))))))
793+ (cl-incf pos))
794+ ; ; If indent-point is _after_ the last sexp in the
795+ ; ; current sexp, we detect that by catching the
796+ ; ; `scan-error' . In that case, we should return the
797+ ; ; indentation as if there were an extra sexp at point.
798+ (scan-error (cl-incf pos)))
799+ (cond
800+ ((= pos (1+ method))
801+ (+ lisp-body-indent containing-form-column))
802+ ((> pos (1+ method))
803+ (clojure--normal-indent calculate-lisp-indent-last-sexp))
804+ (t
805+ (+ (* 2 lisp-body-indent) containing-form-column)))))
806+ (`:defn
807+ (+ lisp-body-indent containing-form-column))
808+ ((pred functionp)
809+ (funcall method indent-point state))
810+ ((and `nil
811+ (guard (let ((function (thing-at-point 'sexp )))
812+ (or (and clojure-defun-style-default-indent
813+ ; ; largely to preserve useful alignment of :require, etc in ns
814+ (not (string-match " ^:" function)))
815+ (string-match " \\ `\\ (?:\\ S +/\\ )?\\ (def\\ |with-\\ )"
816+ function)))))
817+ (+ lisp-body-indent containing-form-column))
818+ (_ (clojure--normal-indent calculate-lisp-indent-last-sexp))))))
813819
814820; ;; Setting indentation
815821(defun put-clojure-indent (sym indent )
0 commit comments