-
Notifications
You must be signed in to change notification settings - Fork 79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Function indentation #5
Comments
I personally like the new behavior. But a configuration option would be nice I guess. |
The behaviour changed at commit 3933dc4, when SMIE became the default, but nowadays disabling SMIE doesn't revert to the old indentation (which is a good thing of course) |
A parameter to set a maximum indentation with respect to the previous non-empty line would work great for me. I'm used to the following style: with_connection (fun conn ->
do_something conn x;
...
) and logf `Info "User %s has %i new messages"
(Uid.to_string uid)
(List.length new_messages); How can I achieve this? If the feature seems reasonable but needs to be added, what part of the code should I look at? |
This new behaviour is very annoying when working on a code base that has been indented using the old behaviour. Also not everyone likes to use indentation for alignment. So some configurable options would be really nice here. Or would the "proper" solution be to just go with ocp-indent? |
There's clearly some interest in providing some way for SMIE modes to I'd be happy to provide it, but I generally find it difficult to find
E.g. let's take Martin's example: let x = with_connection (fun conn -> and let's pass it to ocp-indent: let x = with_connection (fun conn -> OK, it looks like ocp-indent found a set of rules that cover this case let x = with_connection (fun conn -> gets indented by ocp-indent as: let x = with_connection (fun conn -> I don't know about you, but I consider the above indentation as a bug. And ocp-indent has an "easier" problem than we do, because by design, it Martin's suggestion to just "bound" the additional indentation could let x = with_connection (fun conn -> in the best case, and if it's not supported by additional changes it let x = with_connection (fun conn -> which I find rather unpalatable.
|
For the record, I installed ocp-indent via opam, and added a
in my |
[ Somehow my first email reply was included above, but my second was ignored. So here it is, inserted via the web interface instead. ] Regarding indentation of:
Could you try the patch below, then -- Stefan
|
OK, I have another work-in-progress patch which (combined with the previous
This is still not what ocp-indent does, but it's a step in that direction. I think I can get pretty close to ocp-indent's behaviour with one more change (specifically when indenting args in "blabla = fun args"). |
@monnier I think your comment just ended up here #24. With the patch applied (on top of Emacs 24.4) and smie-indent-align-args set to nil the example you give indents like this. This looks broken to me. But maybe I'm just asking for different things than the original reporter. let () =
logf `Info "User %s has %i new messages"
(Uid.to_string uid)
(List.length new_messages) I guess it will not be feasible to reproduce tuareg-mode's old indentation behavior exactly with smie. |
btw, having unit tests could help for this kinds of issues. See for instance the ocp-indent ones (and the failing ones) |
(derived-mode-p): Assume Emacs > 21. (tuareg-smie-grammar): Add dummy "-dlpd-" terminal. (tuareg-smie-forward-token): Fix handling of "|]". (tuareg-smie-backward-token): Refine last fix so we also recognize "exception" right after "with". (tuareg-smie-rules): Add special rule to reduce indentation depth for CPS-style code (see Issue #5). (tuareg--eval-when-macrop): New macro. (tuareg--hanging-eolp-advice): New function. (tuareg--common-mode-setup): Use them for smie--hanging-eolp-function. (tuareg-mode): Call tuareg-make-indentation-regexps even if we use SMIE, since we still have code that uses the tuareg_indent functions. (tuareg-beginning-of-phrase-syms-re): Remove variable. (tuareg-beginning-of-phrase-syms): Redefine. (tuareg--beginning-of-phrase): Remove case made redundant by earlier changes. (tuareg-discover-phrase): Make sure we select a region *around* point. (tuareg-split-long-list): Fix handling when tail is nil.
(tuareg-smie--args): New function. (tuareg--common-mode-setup): Use it (Issue #5).
I installed a patch that introduces a new config var tuareg-indent-align-with-first-arg which should let you express your preference for the "logf" example above. |
Could you guys try the latest code and see how you like the result? Some of the changes depend on a new (and undocumented :-( ) feature in Emacs-24.5, so make sure you try it in Emacs-24.5 (it should not break in older Emacsen, but it won't give the same indentation results). I'll close this issue now, so if the result is not "good enough", please open a new issue. |
Version 2.0.8 indents function bodys the following way
while olders versions used to indent it this way:
Is there a simple way to revert to the old behavior? Thanks!
The text was updated successfully, but these errors were encountered: