Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix indent on immediately applied function definition/evaluation results. #102

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions hy-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
'("when" "unless"
"for" "for*" "for/a" "for/a*"
"while"
"except" "catch")
"except" "catch" "assoc")
"Symbols that will have following lines indented +1 when matched.

Examples:
Expand Down Expand Up @@ -196,16 +196,40 @@ commands."
(or (-contains? hy-indent--exactly sym)
(-some (-cut s-matches? <> sym) hy-indent--fuzzily))))

;;;; Helpers

(defun hy--closing-paren-end ()
"Get point after matching paren if looking at an open paren.

If `show-paren-data-function' returns nil, return point-max + 1
to fake point being inside the function definition, in which case
we should indent normally."
(let ((paren-data (funcall show-paren-data-function)))
(if paren-data (nth 3 paren-data) ; after closing paren
(1+ (point-max)))))

(defun hy-indent--current-column? (_indent-point)
"Returns t if we should indent to current-column, else nil.

The second case covers immediately applied function definitions
and evaluation results, e.g.
((fn [x y]
(+ x y))
7
11)"
(or (-contains? '(?\[ ?\{) (char-before))
(> _indent-point (hy--closing-paren-end))))

;;;; Indent Function

(defun hy-indent-function (_indent-point syntax)
"Given SYNTAX, the `parse-partial-sexp' corr. to _INDENT-POINT, get indent."
(hy--goto-inner-sexp syntax)

(cond ((-contains? '(?\[ ?\{) (char-before))
(cond ((hy-indent--current-column? _indent-point)
(current-column))

((hy-indent--syntax->indent-spec syntax)
((hy-indent--syntax->indent-spec syntax)
(1+ (current-column)))

(t (hy-indent--normal calculate-lisp-indent-last-sexp))))
Expand Down