Ocaml filetype handling improvements
Manage indentation when creating a new line in Ocaml files
This commit is contained in:
parent
2c944f6415
commit
8d30efb109
|
@ -15,6 +15,8 @@ hook global WinSetOption filetype=ocaml %{
|
|||
require-module ocaml
|
||||
set-option window static_words %opt{ocaml_static_words}
|
||||
hook window InsertChar -group ocaml-insert '\*' ocaml-insert-closing-comment-bracket
|
||||
hook window InsertChar \n -group ocaml-insert ocaml-insert-on-new-line
|
||||
hook window ModeChange pop:insert:.* -group ocaml-trim-indent ocaml-trim-indent
|
||||
}
|
||||
|
||||
hook -group ocaml-highlight global WinSetOption filetype=ocaml %{
|
||||
|
@ -99,6 +101,23 @@ define-command ocaml-alternative-file -docstring 'Switch between .ml and .mli fi
|
|||
|
||||
}
|
||||
|
||||
# Remove trailing whitespaces
|
||||
define-command -hidden ocaml-trim-indent %{
|
||||
evaluate-commands -no-hooks -draft -itersel %{
|
||||
try %{ execute-keys -draft x s \h+$ <ret> d }
|
||||
}
|
||||
}
|
||||
|
||||
# Preserve indentation when creating new line
|
||||
define-command -hidden ocaml-insert-on-new-line %{
|
||||
evaluate-commands -draft -itersel %{
|
||||
# copy white spaces at the beginnig of the previous line
|
||||
try %{ execute-keys -draft k x s ^\h+ <ret> y jgh P x s \h+$ <a-d> }
|
||||
# increase indentation if the previous line ended with either '=' sign or do keyword
|
||||
try %{ execute-keys -draft k x s (=|\bdo)$ <ret> j <a-gt> }
|
||||
}
|
||||
}
|
||||
|
||||
# The OCaml comment is `(* Some comment *)`. Like the C-family this can be a multiline comment.
|
||||
#
|
||||
# Recognize when the user is trying to commence a comment when they type `(*` and
|
||||
|
|
Loading…
Reference in New Issue
Block a user