|
2 | 2 |
|
3 | 3 | (require 'smie) |
4 | 4 |
|
| 5 | +;; HACK: Patch for Emacs 24.3 smie that fix |
| 6 | +;; https://github.com/elixir-lang/emacs-elixir/issues/107. |
| 7 | +;; |
| 8 | +;; defadvice is used to change the behavior only for elixir-mode. |
| 9 | +;; Definition of advice is a definition of corresponding function |
| 10 | +;; in Emacs 24.4. |
| 11 | +(when (and (= 24 emacs-major-version) |
| 12 | + (= 3 emacs-minor-version)) |
| 13 | + (defadvice smie-rule-parent (around elixir-mode-patch activate) |
| 14 | + (if (not (eq major-mode 'elixir-mode)) |
| 15 | + (progn ad-do-it) |
| 16 | + (setq ad-return-value |
| 17 | + (save-excursion |
| 18 | + (goto-char (cadr (smie-indent--parent))) |
| 19 | + (cons 'column |
| 20 | + (+ (or offset 0) |
| 21 | + (smie-indent-virtual))))))) |
| 22 | + |
| 23 | + (defadvice smie-indent-comment (around elixir-mode-patch activate) |
| 24 | + (if (not (eq major-mode 'elixir-mode)) |
| 25 | + (progn ad-do-it) |
| 26 | + (setq ad-return-value |
| 27 | + (and (smie-indent--bolp) |
| 28 | + (let ((pos (point))) |
| 29 | + (save-excursion |
| 30 | + (beginning-of-line) |
| 31 | + (and (re-search-forward comment-start-skip (line-end-position) t) |
| 32 | + (eq pos (or (match-end 1) (match-beginning 0)))))) |
| 33 | + (save-excursion |
| 34 | + (forward-comment (point-max)) |
| 35 | + (skip-chars-forward " \t\r\n") |
| 36 | + (unless |
| 37 | + (save-excursion |
| 38 | + (let ((next (funcall smie-forward-token-function))) |
| 39 | + (or (if (zerop (length next)) |
| 40 | + (or (eobp) (eq (car (syntax-after (point))) 5))) |
| 41 | + (rassoc next smie-closer-alist)))) |
| 42 | + (smie-indent-calculate)))))))) |
| 43 | + |
5 | 44 | ;; FIXME: This is me being lazy. CL is a compile-time dep only. |
6 | 45 | ;; (But for now, there is no real file-compilation plot, so let's |
7 | 46 | ;; scrape by with the runtime dep.) |
|
0 commit comments