* [Caml-list] What is the right way to configure Tuareg to get the same indentation as in Batteries Included?
@ 2017-10-30 10:08 Matej Košík
2017-11-21 19:59 ` Stefan Monnier
0 siblings, 1 reply; 4+ messages in thread
From: Matej Košík @ 2017-10-30 10:08 UTC (permalink / raw)
To: caml users
[-- Attachment #1.1: Type: text/plain, Size: 1512 bytes --]
Hi,
Tuareg and indentation does not work for me very well.
I am trying to figure out how should I configure it so that I get the same indentation behavior as is used in Batteries Included.
One (of several) problem is with the or-patterns in match-expressions.
Here is the original sample:
(behavior I like)
(* https://github.com/ocaml-batteries-team/batteries-included/blob/e069e28678a0d15d338721e1ff5e480fe0ad26c5/src/batComplex.ml#L82-L83 *)
match BatEnum.peek enum with
| None -> {re; im = multiplier}
| Some (Kwd ".")
| Some (Kwd "*") ->
BatEnum.junk enum;
parse_im ~multiplier re
| Some _token ->
parse_im ~multiplier re
However, Tuareg, in my currenct configuration does instead this:
match BatEnum.peek enum with
| None -> {re; im = multiplier}
| Some (Kwd ".")
| Some (Kwd "*") ->
BatEnum.junk enum;
parse_im ~multiplier re
| Some _token ->
parse_im ~multiplier re
I am using:
- Ocaml 4.06.0+beta2
- Tuareg 2.0.10 (installed via OPAM)
and my ~/.emacs file contains just this:
(load "~/.opam/4.06.0+beta2/share/emacs/site-lisp/tuareg-site-file")
(setq tuareg-indent-align-with-first-arg t)
(setq tuareg-match-patterns-aligned t)
which is, I guess, wrong/insufficient.
I'd be grateful for any hints concerning how to fix/complete the configuration in order to get indentation behavior consistent with Ocaml Batteries.
Is that possible (with Tuareg or whatever other tool)?
---
Matej
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] What is the right way to configure Tuareg to get the same indentation as in Batteries Included?
2017-10-30 10:08 [Caml-list] What is the right way to configure Tuareg to get the same indentation as in Batteries Included? Matej Košík
@ 2017-11-21 19:59 ` Stefan Monnier
2017-11-23 9:53 ` Matej Košík
0 siblings, 1 reply; 4+ messages in thread
From: Stefan Monnier @ 2017-11-21 19:59 UTC (permalink / raw)
To: caml-list
> match BatEnum.peek enum with
> | None -> {re; im = multiplier}
> | Some (Kwd ".")
> | Some (Kwd "*") ->
> BatEnum.junk enum;
> parse_im ~multiplier re
> | Some _token ->
> parse_im ~multiplier re
>
> However, Tuareg, in my currenct configuration does instead this:
>
> match BatEnum.peek enum with
> | None -> {re; im = multiplier}
> | Some (Kwd ".")
> | Some (Kwd "*") ->
> BatEnum.junk enum;
> parse_im ~multiplier re
> | Some _token ->
> parse_im ~multiplier re
Here's how you can do it:
- Go to the first line that Tuareg indents wrong (i.e. `| Some (Kwd "*") ->`)
- Change its indentation to match your expectation
- run `M-x smie-config-set-indent RET`
- this should suggest to set (:before "|-or") to 0, which you can accept.
- go to the next line (that Tuareg indents wrong)
- Change its indentation to match your expectation
- run `M-x smie-config-set-indent RET`
- this time it asks you which rule you want to change (because 2 rules
are used to determine this indentation): either (after "->") or
(before "->") depending on whether you want to also change
| Some (Kwd "*")
-> BatEnum.junk enum;
or not.
- once that is done, you should be able to do `M-x smie-config-save
RET`. To save the result into your Customize settings.
Stefan
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] What is the right way to configure Tuareg to get the same indentation as in Batteries Included?
2017-11-21 19:59 ` Stefan Monnier
@ 2017-11-23 9:53 ` Matej Košík
2017-11-24 2:20 ` Stefan Monnier
0 siblings, 1 reply; 4+ messages in thread
From: Matej Košík @ 2017-11-23 9:53 UTC (permalink / raw)
To: caml-list
[-- Attachment #1.1: Type: text/plain, Size: 4998 bytes --]
Hi Stefan,
On 11/21/17 20:59, Stefan Monnier wrote:
>> match BatEnum.peek enum with
>> | None -> {re; im = multiplier}
>> | Some (Kwd ".")
>> | Some (Kwd "*") ->
>> BatEnum.junk enum;
>> parse_im ~multiplier re
>> | Some _token ->
>> parse_im ~multiplier re
>>
>> However, Tuareg, in my currenct configuration does instead this:
>>
>> match BatEnum.peek enum with
>> | None -> {re; im = multiplier}
>> | Some (Kwd ".")
>> | Some (Kwd "*") ->
>> BatEnum.junk enum;
>> parse_im ~multiplier re
>> | Some _token ->
>> parse_im ~multiplier re
>
> Here's how you can do it:
> - Go to the first line that Tuareg indents wrong (i.e. `| Some (Kwd "*") ->`)
> - Change its indentation to match your expectation
> - run `M-x smie-config-set-indent RET`
> - this should suggest to set (:before "|-or") to 0, which you can accept.
> - go to the next line (that Tuareg indents wrong)
> - Change its indentation to match your expectation
> - run `M-x smie-config-set-indent RET`
> - this time it asks you which rule you want to change (because 2 rules
> are used to determine this indentation): either (after "->") or
> (before "->") depending on whether you want to also change
>
> | Some (Kwd "*")
> -> BatEnum.junk enum;
>
> or not.
>
> - once that is done, you should be able to do `M-x smie-config-save
> RET`. To save the result into your Customize settings.
So far so good.
After following the above instructions, I was able to tweak the Emacs behavior in the desired way.
Thank you!
What puzzled me was that once I restart Eamcs, I get the old behavior.
I am guessing that this is because I need to "save" the configuration somehow, which I failed to figure out.
So, first, one must "save SMIE configuration" to "customize setting".
And then one must "save customize settings" to ~/.emacs
QUESTION: Is that right?
MY ASSUMPTION WAS: Yes.
I have tried two things (and I failed in both cases);
the 1-st attempt:
-----------------
After doing "M-x smie-config-save", I have tried to use "M-x customize-save-variable smie-config".
Emacs responded:
Wrote /home/mkosik/.emacs
This sounded like a progress.
After I looked at ~/.emacs, I can see this:
(load "/home/mkosik/.opam/4.06.0/share/emacs/site-lisp/tuareg-site-file")
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(inhibit-startup-screen t)
'(smie-config nil))
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
)
This does not seem currect, does it?
(At least I would expect "smie-config" variable to be set to something interesting, not "nil".)
To confirm, I restarted Emacs and I can confirm, that the Emacs behaves again in the original undesired way
(defined in my first email)
FAIL
the 2-nd attempt
After repreating your helpful instructions and doing "M-x smie-config-save",
I tried to use "M-x customize-save-customized"
Emacs responded:
Wrote /home/mkosik/.emacs
That file changed in the following way:
(load "/home/mkosik/.opam/4.06.0/share/emacs/site-lisp/tuareg-site-file")
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(inhibit-startup-screen t)
'(smie-config
(quote
((tuareg-mode
(2 :after "->" 1)
(0 :before "|-or" nil))))))
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
)
This is more like it (I thought).
I optimistically restarted Emacs and again, unfortunatelly, Emacs behaves again in the original undesired way
(defined in my first email).
I find this strange because "M: (print smie-config)" gives me:
(tuareg-mode (2 :after "->" 1) (0 :before "|-or" nil)))
(tuareg-mode (2 :after "->" 1) (0 :before "|-or" nil)))
FAIL
Is this a bug?
Is this the expected behavior and I merely do not understadn SMIE and should read some more documentation? If yes, then which one?
I haven't noticed many questions about Ocaml indentation in Emacs, so I am guessing that this works for everyone perfectly.
Is that the case?
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] What is the right way to configure Tuareg to get the same indentation as in Batteries Included?
2017-11-23 9:53 ` Matej Košík
@ 2017-11-24 2:20 ` Stefan Monnier
0 siblings, 0 replies; 4+ messages in thread
From: Stefan Monnier @ 2017-11-24 2:20 UTC (permalink / raw)
To: caml-list
> After following the above instructions, I was able to tweak the Emacs
> behavior in the desired way.
> Thank you!
> What puzzled me was that once I restart Eamcs, I get the old behavior.
Turned out it was a bug in the smie-config code. This is fixed in
Emacs-26.
Stefan
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2017-11-24 2:20 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-30 10:08 [Caml-list] What is the right way to configure Tuareg to get the same indentation as in Batteries Included? Matej Košík
2017-11-21 19:59 ` Stefan Monnier
2017-11-23 9:53 ` Matej Košík
2017-11-24 2:20 ` Stefan Monnier
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).