[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: sml-mode indentation for structures
From: |
Stefan Monnier |
Subject: |
Re: sml-mode indentation for structures |
Date: |
Mon, 06 Oct 2014 08:45:31 -0400 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.4.50 (gnu/linux) |
> I'm using sml-mode version 6.5 from ELPA, but the indentation of
> structures drives me nuts. I would like to use a style like this:
> structure Foo =
> struct
> fun foo x = x
> end
> but by default sml-mode indents it like this:
> structure Foo =
> struct
> fun foo x = x
> end
> Can somebody tell me how sml-mode indentation rules can be configured?
I guess the "right" way to do that, would be:
(defun my-sml-rules (orig kind token)
(pcase (cons kind token)
(`(:before . "d=")
(if (smie-rule-parent-p "structure" "signature" "functor") 2
(funcall orig kind token)))
(`(:after . "struct") 2)
(_ (funcall orig kind token))))
(add-hook 'sml-mode-hook
(lambda ()
(add-function :around smie-indent-rules #'my-sml-rules)))
But since `add-function' is new in 24.4, you'll probably want something
more like:
(defadvice sml-smie-rules (around my-sml-rules activate)
(let ((i (pcase (cons (ad-get-arg 0) (ad-get-arg 1))
(`(:before . "d=")
(if (smie-rule-parent-p "structure" "signature" "functor") 2))
(`(:after . "struct") 2))))
(if i
(setq ad-return i)
ad-do-it)))
-- Stefan "guaranteed 100% untested"