package ecaml

  1. Overview
  2. Docs
Library for writing Emacs plugin in OCaml

Install

Dune Dependency

Authors

Maintainers

Sources

v0.17.0.tar.gz
sha256=87e76473915e12d718096100a5c4d15d98aba6f99ecbf21814b7389e8c28bb25

doc/src/ecaml/evil.ml.html

Source file evil.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
open! Core
open! Import
module Current_buffer = Current_buffer0

module Q = struct
  let evil = "evil" |> Symbol.intern
  let evil_mode = "evil-mode" |> Symbol.intern
  let evilified = "evilified" |> Symbol.intern
  let normal = "normal" |> Symbol.intern
end

let is_in_use () =
  Current_buffer.has_non_null_value { symbol = Q.evil_mode; type_ = Value.Type.bool }
;;

let evil_declare_ignore_repeat =
  Funcall.Wrap.("evil-declare-ignore-repeat" <: Symbol.t @-> return ignored)
;;

let declare_ignore_repeat command =
  Eval.after_load [%here] Q.evil ~f:(fun () -> evil_declare_ignore_repeat command)
;;

module Config = struct
  type one = Ignore_repeat
  type t = one list

  let apply_one command = function
    | Ignore_repeat -> declare_ignore_repeat command
  ;;

  let apply_to_defun t command = List.iter t ~f:(apply_one command)
end

module State = struct
  type t =
    | Evilified
    | Normal
    | Other of Symbol.t
  [@@deriving equal, sexp_of]

  let type_ =
    Value.Type.map
      Symbol.t
      ~name:[%sexp "evil-state"]
      ~of_:(fun sym ->
        if Symbol.equal Q.evilified sym
        then Evilified
        else if Symbol.equal Q.normal sym
        then Normal
        else Other sym)
      ~to_:(function
        | Evilified -> Q.evilified
        | Normal -> Q.normal
        | Other sym -> sym)
  ;;

  let t = type_
  let var = Var.Wrap.("evil-state" <: t)
  let get () = Current_buffer.value_exn var

  let insert =
    let evil_insert = Funcall.Wrap.("evil-insert" <: value @-> return nil) in
    fun () -> evil_insert Value.nil
  ;;
end

module Escape = struct
  let inhibit_functions = Var.Wrap.("evil-escape-inhibit-functions" <: list Function.t)
end

let define_key =
  Funcall.Wrap.(
    "evil-define-key*"
    <: list State.t @-> Keymap.t @-> Key_sequence.t @-> Keymap.Entry.t @-> return nil)
;;
OCaml

Innovation. Community. Security.