package ecaml

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Source file ecaml.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
(* We export all the Ecaml modules before doing [open!]s, because we want to
   export Ecaml modules that shadow [Core_kernel] ones. *)

module Advice = Advice
module Ansi_color = Ansi_color
module Async_ecaml = Async_ecaml
module Auto_mode_alist = Auto_mode_alist
module Backup = Backup
module Browse_url = Browse_url
module Buffer = Buffer
module Buffer_local = Buffer_local
module Char_code = Char_code
module Color = Color
module Command = Command
module Comment = Comment
module Compilation = Compilation
module Completing = Completing
module Current_buffer = Current_buffer
module Customization = Customization
module Debugger = Debugger
module Defconst = Defconst
module Defun = Defun
module Defvar = Defvar
module Directory = Directory
module Display = Display
module Display_property = Display_property
module Documentation = Documentation
module Echo_area = Echo_area
module Elisp_time = Elisp_time
module Face = Face
module Feature = Feature
module File = File
module Filename = Filename
module Find_function = Find_function
module Form = Ecaml_value.Form
module Frame = Frame
module Funcall = Funcall
module Function = Ecaml_value.Function
module Grep = Grep
module Hash_table = Hash_table
module Help = Help
module Hook = Hook
module Input_event = Input_event
module Key_sequence = Key_sequence
module Keymap = Keymap
module Load = Load
module Load_history = Load_history
module Major_mode = Major_mode
module Marker = Marker
module Minibuffer = Minibuffer
module Minor_mode = Minor_mode
module Modified_tick = Modified_tick
module Obarray = Obarray
module Obsolete = Obsolete
module Ocaml_or_elisp_value = Ocaml_or_elisp_value
module Org_table = Org_table
module Overlay = Overlay
module Plist = Plist
module Point = Point
module Position = Position
module Process = Process
module Regexp = Regexp
module Rx = Rx
module Selected_window = Selected_window
module Symbol = Symbol
module Syntax_table = Syntax_table
module System = System
module Tabulated_list = Tabulated_list
module Terminal = Terminal
module Text = Text
module Thing_at_point = Thing_at_point
module Timer = Timer
module User = User
module Value = Ecaml_value.Value
module Valueable = Ecaml_value.Valueable
module Var = Var
module Vector = Vector
module Window = Window
module Working_directory = Working_directory
open! Core_kernel
open! Async_kernel
open! Import

module Q = struct
  include Q

  let inhibit_read_only = "inhibit-read-only" |> Symbol.intern
end

let ( << ) = ( << )
and ( >> ) = ( >> )
and concat = concat
and defalias = Defun.defalias
and defconst = Defconst.defconst
and defconst_i = Defconst.defconst_i
and defcustom = Customization.defcustom
and define_derived_mode = Major_mode.define_derived_mode
and define_minor_mode = Minor_mode.define_minor_mode
and defun = Defun.defun
and defun_nullary = Defun.defun_nullary
and defun_nullary_nil = Defun.defun_nullary_nil
and defvar = Defvar.defvar
and defvaralias = Defvar.defvaralias
and inhibit_messages = Echo_area.inhibit_messages
and lambda = Defun.lambda
and lambda_nullary = Defun.lambda_nullary
and lambda_nullary_nil = Defun.lambda_nullary_nil
and message = Echo_area.message
and messagef = Echo_area.messagef
and message_s = Echo_area.message_s
and print_s = print_s
and raise_string = raise_string
and sec_ns = sec_ns
and wrap_message = Echo_area.wrap_message

let provide =
  Ecaml_callback.(register end_of_module_initialization)
    ~should_run_holding_async_lock:true
    ~f:(fun () -> message_s [%message "Loaded Ecaml."]);
  Async_ecaml.initialize ();
  Caml_embed.initialize;
  Import.initialize_module;
  Find_function.initialize ();
  User.initialize ();
  Value.initialize_module;
  (Feature.provide [@warning "-3"])
;;

let inhibit_read_only = Var.create Q.inhibit_read_only Value.Type.bool
let inhibit_read_only f = Current_buffer.set_value_temporarily inhibit_read_only true ~f

let () =
  let symbol = "ecaml-test-raise" |> Symbol.intern in
  defun
    symbol
    [%here]
    ~interactive:No_arg
    (Returns Value.Type.unit)
    (let open Defun.Let_syntax in
     let%map_open n = optional Q.number int in
     let n = Option.value n ~default:0 in
     if n <= 0
     then raise_s [%message "foo" "bar" "baz"]
     else Funcall.(symbol <: option int @-> return nil) (Some (n - 1));
     ());
  (* Replace [false] with [true] to define a function for testing
     [Minibuffer.read_from]. *)
  if false
  then (
    defun_nullary
      ("ecaml-test-minibuffer-y-or-n-with-timeout" |> Symbol.intern)
      [%here]
      ~interactive:No_arg
      Returns_unit_deferred
      (fun () ->
         let%bind int =
           Minibuffer.y_or_n_with_timeout
             ~prompt:"prompt"
             ~timeout:(Time_ns.Span.second, 13)
         in
         message_s [%message (int : int Minibuffer.Y_or_n_with_timeout.t)];
         return ());
    defun_nullary
      ("ecaml-test-minibuffer" |> Symbol.intern)
      [%here]
      ~interactive:No_arg
      Returns_unit_deferred
      (fun () ->
         let test ?default_value ?history ?history_pos ?initial_contents () ~prompt =
           let%bind result =
             Minibuffer.read_from
               ()
               ?default_value
               ?history
               ?history_pos
               ?initial_contents
               ~prompt:(concat [ prompt; ": " ])
           in
           message (concat [ "result: "; result ]);
           return ()
         in
         let%bind () = test () ~prompt:"test 1" in
         let%bind () = test () ~prompt:"test 2" ~default_value:"some-default" in
         let%bind () = test () ~prompt:"test 3" ~initial_contents:"some-contents" in
         test
           ()
           ~prompt:"test 4"
           ~history:
             (Var.create ("some-history-list" |> Symbol.intern) Value.Type.(list string))))
;;

let debug_embedded_caml_values () = Caml_embed.debug_sexp ()