Subject: bug#16116: 24.3.50; smie-indent-close aligns inner closing paren with the outer opening paren

From: Dmitry Gutov <[email-masked]>
Date: Sun, 15 Dec 2013 04:44:35 +0200

On 15.12.2013 03:50, Stefan Monnier wrote:
>> I believe this argument also works against doing it in the rules
>> function, and in favor of adding a defvar.
>
> I don't think so: setting the var is a one-liner, adding the rule to the
> rule-function is also a one-liner.  So either way is just as easy for
> the major-mode.

I mean in terms of code reuse: the rules function is also specific to a 
major mode. The rule itself doesn't look like it'll take just one line 
to me, AFAICS it'll have to duplicate most of the code in 
`smie-indent-close':

     (`(:before . ,(or `")" `"]" `"}"))
      (save-excursion
        (forward-char 1)
        (condition-case nil
           (progn
             (backward-sexp 1)
             (cons 'column . (smie-indent-virtual)))
          (scan-error nil))))

If any other major mode wants to do the same, they have to duplicate 
this, or extract this code to a helper function in smie.el.

Using the rules function will also add 2-3 lines to `smie-indent-close'.

> By contrast, setting smie-indent-functions buffer-locally, then
> removing smie-indent-close from it and adding some other function
> requires a lot more code, and a lot more brittle as well (the ordering
> in smie-indent-functions is important, the set of functions in there and
> their order is not guaranteed to stay unchanged in future versions, the
> replacement function needs to be written (delegating to
> smie-indent-close seems like it might not work), ...

Looks like three lines to me. :)

(setq-local smie-indent-functions (copy-sequence smie-indent-functions))
(setcar (memq 'smie-indent-close smie-indent-functions)
         'ruby--smie-indent-close)

And the replacement function wouldn't be much longer than the added rule.