|
173 | 173 | (not (or (memq (char-before) '(?\{ ?\[))
|
174 | 174 | (looking-back elixir-smie--operator-regexp (- (point) 3) t))))
|
175 | 175 |
|
| 176 | +(defun elixir-smie-last-line-end-with-block-operator-p () |
| 177 | + "Return non-nil if the previous line ends with a `->' operator." |
| 178 | + (save-excursion |
| 179 | + (forward-line -1) |
| 180 | + (move-end-of-line 1) |
| 181 | + (looking-back elixir-smie--block-operator-regexp (- (point) 3) t))) |
| 182 | + |
| 183 | +(defun elixir-smie-last-line-start-with-block-operator-p () |
| 184 | + (save-excursion |
| 185 | + (forward-line -1) |
| 186 | + (beginning-of-line) |
| 187 | + (looking-at "^\s+->.+$"))) |
| 188 | + |
176 | 189 | (defun elixir-smie--semi-ends-match ()
|
177 | 190 | "Return non-nil if the current line concludes a match block."
|
178 | 191 | (when (not (eobp))
|
|
292 | 305 | (t (smie-rule-parent))))
|
293 | 306 | (`(:before . "MATCH-STATEMENT-DELIMITER")
|
294 | 307 | (cond
|
295 |
| - ((smie-rule-parent-p "MATCH-STATEMENT-DELIMITER") |
| 308 | + ((and (smie-rule-parent-p "do") |
| 309 | + (smie-rule-hanging-p)) |
296 | 310 | (smie-rule-parent))
|
297 | 311 | ((and (not (smie-rule-sibling-p))
|
298 | 312 | (nth 2 smie--parent)
|
|
302 | 316 | (not (nth 2 smie--parent))
|
303 | 317 | (smie-rule-hanging-p))
|
304 | 318 | (smie-rule-parent))))
|
| 319 | + (`(:after . "MATCH-STATEMENT-DELIMITER") |
| 320 | + (cond |
| 321 | + ((and (smie-rule-parent-p "MATCH-STATEMENT-DELIMITER") |
| 322 | + (smie-rule-hanging-p) |
| 323 | + (smie-rule-sibling-p)) |
| 324 | + (if (elixir-smie-last-line-end-with-block-operator-p) |
| 325 | + (smie-rule-parent) |
| 326 | + 0)) |
| 327 | + (t |
| 328 | + (smie-rule-parent)))) |
305 | 329 | (`(:before . "fn")
|
306 | 330 | (smie-rule-parent))
|
307 | 331 | (`(:before . "do:")
|
308 | 332 | (cond
|
309 | 333 | ((smie-rule-parent-p "def" "if")
|
310 | 334 | (smie-rule-parent))))
|
| 335 | + (`(:before . "do") |
| 336 | + (cond |
| 337 | + ((and (smie-rule-parent-p "case") |
| 338 | + (smie-rule-hanging-p)) |
| 339 | + (smie-rule-parent 2)) |
| 340 | + (t |
| 341 | + elixir-smie-indent-basic))) |
311 | 342 | (`(:before . "end")
|
312 | 343 | (smie-rule-parent))
|
313 | 344 | ;; Closing paren on the other line
|
|
323 | 354 | ;; ()
|
324 | 355 | ;; .....
|
325 | 356 | ((smie-rule-parent-p "do")
|
326 |
| - (smie-rule-parent elixir-smie-indent-basic)) |
| 357 | + (smie-rule-parent)) |
327 | 358 | (t (smie-rule-parent))))
|
328 | 359 | (`(:before . "[")
|
329 | 360 | (cond
|
330 | 361 | ((smie-rule-hanging-p)
|
331 | 362 | (smie-rule-parent))))
|
| 363 | + (`(:before . "{") |
| 364 | + (cond |
| 365 | + ;; Example |
| 366 | + ;; |
| 367 | + ;; case parse do |
| 368 | + ;; { [ help: true ], _, _ } |
| 369 | + ;; -> :help |
| 370 | + ;; { _, [ user, project, count ], _ } |
| 371 | + ((and (not (smie-rule-hanging-p)) |
| 372 | + (smie-rule-parent-p "do")) |
| 373 | + (smie-rule-parent)) |
| 374 | + ((and (smie-rule-parent-p "MATCH-STATEMENT-DELIMITER") |
| 375 | + (not (smie-rule-hanging-p))) |
| 376 | + (if (elixir-smie-last-line-end-with-block-operator-p) |
| 377 | + (smie-rule-parent elixir-smie-indent-basic) |
| 378 | + (if (elixir-smie-last-line-start-with-block-operator-p) |
| 379 | + (smie-rule-parent -2) |
| 380 | + (smie-rule-parent)))))) |
332 | 381 | (`(:after . "{")
|
333 | 382 | (cond
|
334 | 383 | ((smie-rule-hanging-p)
|
|
346 | 395 | (`(:before . "->")
|
347 | 396 | (cond
|
348 | 397 | ((smie-rule-hanging-p)
|
349 |
| - (smie-rule-parent elixir-smie-indent-basic)))) |
| 398 | + (smie-rule-parent elixir-smie-indent-basic)) |
| 399 | + ;; Example |
| 400 | + ;; |
| 401 | + ;; case parse do |
| 402 | + ;; { [ help: true ], _, _ } |
| 403 | + ;; -> :help |
| 404 | + ;; ... |
| 405 | + ((and (not (smie-rule-hanging-p)) |
| 406 | + (smie-rule-parent-p "do")) |
| 407 | + elixir-smie-indent-basic) |
| 408 | + ((and (not (smie-rule-hanging-p)) |
| 409 | + (smie-rule-parent-p "MATCH-STATEMENT-DELIMITER")) |
| 410 | + (smie-rule-parent) |
| 411 | + ) |
| 412 | + )) |
350 | 413 | (`(:after . "->")
|
351 | 414 | (cond
|
352 | 415 | ;; This first condition is kind of complicated so I'll try to make this
|
|
372 | 435 | ;; Otherwise, if just indent by two.
|
373 | 436 | ((smie-rule-hanging-p)
|
374 | 437 | (cond
|
375 |
| - ((smie-rule-parent-p "after" "catch" "do" "rescue" "try") |
376 |
| - elixir-smie-indent-basic) |
| 438 | + ((smie-rule-parent-p "catch" "rescue") |
| 439 | + (smie-rule-parent (+ elixir-smie-indent-basic |
| 440 | + elixir-smie-indent-basic))) |
| 441 | + ((smie-rule-parent-p "after" "do" "try") |
| 442 | + (smie-rule-parent elixir-smie-indent-basic)) |
377 | 443 | (t (smie-rule-parent elixir-smie-indent-basic))))))
|
378 | 444 | (`(:before . ";")
|
379 | 445 | (cond
|
|
390 | 456 | ((and (smie-rule-parent-p "if")
|
391 | 457 | (smie-rule-hanging-p))
|
392 | 458 | (smie-rule-parent))
|
| 459 | + ((and (smie-rule-parent-p "else") |
| 460 | + (smie-rule-hanging-p)) |
| 461 | + (smie-rule-parent elixir-smie-indent-basic)) |
393 | 462 | ((smie-rule-parent-p "after" "catch" "def" "defmodule" "defp" "do" "else"
|
394 | 463 | "fn" "if" "rescue" "try" "unless")
|
395 |
| - (smie-rule-parent elixir-smie-indent-basic)) |
| 464 | + (smie-rule-parent)) |
| 465 | + ;; Example |
| 466 | + ;; |
| 467 | + ;; case parse do |
| 468 | + ;; { [ help: true ], _, _ } |
| 469 | + ;; -> :help |
| 470 | + ;; { _, [ user, project, count ], _ } |
| 471 | + ;; -> { user, project, count } |
| 472 | + ;; ... |
| 473 | + ((and (smie-rule-parent-p "->") |
| 474 | + (smie-rule-hanging-p)) |
| 475 | + (smie-rule-parent)) |
396 | 476 | ))
|
397 | 477 | (`(:after . ";")
|
398 | 478 | (cond
|
399 | 479 | ((smie-rule-parent-p "def")
|
400 | 480 | (smie-rule-parent))
|
401 | 481 | ((smie-rule-parent-p "if")
|
402 | 482 | (smie-rule-parent))
|
| 483 | + ((smie-rule-parent-p "after") |
| 484 | + (smie-rule-parent elixir-smie-indent-basic)) |
403 | 485 | ((and (smie-rule-parent-p "(")
|
404 | 486 | (boundp 'smie--parent)
|
405 | 487 | (save-excursion
|
|
0 commit comments