all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* sml-mode indentation for structures
@ 2014-10-06  9:26 Helmut Eller
  2014-10-06 12:45 ` Stefan Monnier
       [not found] ` <mailman.10564.1412599562.1147.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 8+ messages in thread
From: Helmut Eller @ 2014-10-06  9:26 UTC (permalink / raw
  To: help-gnu-emacs

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?

Helmut


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: sml-mode indentation for structures
  2014-10-06  9:26 sml-mode indentation for structures Helmut Eller
@ 2014-10-06 12:45 ` Stefan Monnier
       [not found] ` <mailman.10564.1412599562.1147.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 8+ messages in thread
From: Stefan Monnier @ 2014-10-06 12:45 UTC (permalink / raw
  To: help-gnu-emacs

> 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"




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: sml-mode indentation for structures
       [not found] ` <mailman.10564.1412599562.1147.help-gnu-emacs@gnu.org>
@ 2014-10-06 13:34   ` Helmut Eller
  2014-10-06 13:59     ` Stefan Monnier
       [not found]     ` <mailman.10568.1412603979.1147.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 8+ messages in thread
From: Helmut Eller @ 2014-10-06 13:34 UTC (permalink / raw
  To: help-gnu-emacs

On Mon, Oct 06 2014, Stefan Monnier wrote:

>> 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)))
>

Thanks!  That works very well.

> -- Stefan "guaranteed 100% untested"

I only had to replace smie-indent-rules with
(symbol-function 'sml-smie-rules).

Helmut


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: sml-mode indentation for structures
  2014-10-06 13:34   ` Helmut Eller
@ 2014-10-06 13:59     ` Stefan Monnier
       [not found]     ` <mailman.10568.1412603979.1147.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 8+ messages in thread
From: Stefan Monnier @ 2014-10-06 13:59 UTC (permalink / raw
  To: help-gnu-emacs

>> (add-function :around smie-indent-rules #'my-sml-rules)))
> I only had to replace smie-indent-rules with
> (symbol-function 'sml-smie-rules).

Oh, sorry, it should have been `smie-rules-function'.
Using (symbol-function 'sml-smie-rules) instead, ends up being more like
the `defadvice' case: it modifies the behavior of sml-mode globally
rather than only in the buffer where we run the code.


        Stefan




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: sml-mode indentation for structures
       [not found]     ` <mailman.10568.1412603979.1147.help-gnu-emacs@gnu.org>
@ 2014-10-06 17:57       ` Helmut Eller
  2014-10-06 18:09         ` Helmut Eller
  2014-10-06 18:11         ` Stefan Monnier
  0 siblings, 2 replies; 8+ messages in thread
From: Helmut Eller @ 2014-10-06 17:57 UTC (permalink / raw
  To: help-gnu-emacs

On Mon, Oct 06 2014, Stefan Monnier wrote:

>>> (add-function :around smie-indent-rules #'my-sml-rules)))
>> I only had to replace smie-indent-rules with
>> (symbol-function 'sml-smie-rules).
>
> Oh, sorry, it should have been `smie-rules-function'.
> Using (symbol-function 'sml-smie-rules) instead, ends up being more like
> the `defadvice' case: it modifies the behavior of sml-mode globally
> rather than only in the buffer where we run the code.

I see.  Actually I run the code with eval-after-load; but, yes, using
sml-mode-hook feels cleaner.

Helmut


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: sml-mode indentation for structures
  2014-10-06 17:57       ` Helmut Eller
@ 2014-10-06 18:09         ` Helmut Eller
  2014-10-06 18:14           ` Stefan Monnier
  2014-10-06 18:11         ` Stefan Monnier
  1 sibling, 1 reply; 8+ messages in thread
From: Helmut Eller @ 2014-10-06 18:09 UTC (permalink / raw
  To: help-gnu-emacs

On Mon, Oct 06 2014, Helmut Eller wrote:

> On Mon, Oct 06 2014, Stefan Monnier wrote:
>
>>>> (add-function :around smie-indent-rules #'my-sml-rules)))
>>> I only had to replace smie-indent-rules with
>>> (symbol-function 'sml-smie-rules).
>>
>> Oh, sorry, it should have been `smie-rules-function'.
>> Using (symbol-function 'sml-smie-rules) instead, ends up being more like
>> the `defadvice' case: it modifies the behavior of sml-mode globally
>> rather than only in the buffer where we run the code.
>
> I see.  Actually I run the code with eval-after-load; but, yes, using
> sml-mode-hook feels cleaner.

(add-function :around (local 'smie-indent-rules) #'my-sml-rules) seems
to be needed to make it work from sml-mode-hook.

Helmut


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: sml-mode indentation for structures
  2014-10-06 17:57       ` Helmut Eller
  2014-10-06 18:09         ` Helmut Eller
@ 2014-10-06 18:11         ` Stefan Monnier
  1 sibling, 0 replies; 8+ messages in thread
From: Stefan Monnier @ 2014-10-06 18:11 UTC (permalink / raw
  To: help-gnu-emacs

>>>> (add-function :around smie-indent-rules #'my-sml-rules)))
>>> I only had to replace smie-indent-rules with
>>> (symbol-function 'sml-smie-rules).
>> Oh, sorry, it should have been `smie-rules-function'.
>> Using (symbol-function 'sml-smie-rules) instead, ends up being more like
>> the `defadvice' case: it modifies the behavior of sml-mode globally
>> rather than only in the buffer where we run the code.
> I see.  Actually I run the code with eval-after-load; but, yes, using
> sml-mode-hook feels cleaner.

BTW: (add-function <foo> (symbol-function <bar>) <toto>) is generally
better written as (advice-add <bar> <foo> <toto>).  The difference is
that advice-add will work even if <bar> is not yet defined (i.e. no
need for eval-after-load), and it will work if <bar> is autoloaded, and if
it's a macro, etc...


        Stefan




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: sml-mode indentation for structures
  2014-10-06 18:09         ` Helmut Eller
@ 2014-10-06 18:14           ` Stefan Monnier
  0 siblings, 0 replies; 8+ messages in thread
From: Stefan Monnier @ 2014-10-06 18:14 UTC (permalink / raw
  To: help-gnu-emacs

> (add-function :around (local 'smie-indent-rules) #'my-sml-rules) seems
> to be needed to make it work from sml-mode-hook.

Duh, yes,


        Stefan




^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2014-10-06 18:14 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-10-06  9:26 sml-mode indentation for structures Helmut Eller
2014-10-06 12:45 ` Stefan Monnier
     [not found] ` <mailman.10564.1412599562.1147.help-gnu-emacs@gnu.org>
2014-10-06 13:34   ` Helmut Eller
2014-10-06 13:59     ` Stefan Monnier
     [not found]     ` <mailman.10568.1412603979.1147.help-gnu-emacs@gnu.org>
2014-10-06 17:57       ` Helmut Eller
2014-10-06 18:09         ` Helmut Eller
2014-10-06 18:14           ` Stefan Monnier
2014-10-06 18:11         ` Stefan Monnier

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.