Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file process.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460open!Core_kernelopen!Async_kernelopen!ImportmoduleQ=structincludeQletcall_process="call-process"|>Symbol.internandcall_process_region="call-process-region"|>Symbol.internandclosed="closed"|>Symbol.internandconnect="connect"|>Symbol.internandexit_="exit"|>Symbol.internandfailed="failed"|>Symbol.internandlisten="listen"|>Symbol.internandlocal="local"|>Symbol.internandmake_network_process="make-network-process"|>Symbol.internandopen_="open"|>Symbol.internandrun="run"|>Symbol.internandsignal="signal"|>Symbol.internandstart_process="start-process"|>Symbol.internandstop="stop"|>Symbol.internendincludeProcess0moduleStatus=structmoduleT=structtypet=|Closed|Connect|Exit|Failed|Listen|Open|Run|Signal|Stop[@@derivingenumerate,sexp_of]endincludeTlettype_=Value.Type.enum[%sexp"process-status"](moduleT)(Symbol.to_value<<function|Closed->Q.closed|Connect->Q.connect|Exit->Q.exit_|Failed->Q.failed|Listen->Q.listen|Open->Q.open_|Run->Q.run|Signal->Q.signal|Stop->Q.stop);;lett=type_letof_value_exn=Value.Type.of_value_exntype_letto_value=Value.Type.to_valuetype_endletis_alive=Funcall.("process-live-p"<:t@->returnbool)letequal=eqletbuffer=Funcall.("process-buffer"<:t@->return(nil_orBuffer.t))letprocess_command=Funcall.("process-command"<:t@->returnvalue)letcommandt=letv=process_commandtinifValue.is_nilv||Value.eqvValue.tthenNoneelseSome(v|>Value.to_list_exn~f:Value.to_utf8_bytes_exn);;letname=Funcall.("process-name"<:t@->returnstring)letprocess_id=Funcall.("process-id"<:t@->return(nil_orint))letpidt=process_idt|>Option.map~f:Pid.of_intletmark=Funcall.("process-mark"<:t@->returnMarker.t)letquery_on_exit=Funcall.("process-query-on-exit-flag"<:t@->returnbool)letset_query_on_exit=Funcall.("set-process-query-on-exit-flag"<:t@->bool@->returnnil);;letget_property=Funcall.("process-get"<:t@->Symbol.t@->return(nil_orvalue))letset_property=Funcall.("process-put"<:t@->Symbol.t@->value@->returnnil)letstatus=Funcall.("process-status"<:t@->returnStatus.t)moduleExit_status=structtypet=|Not_exited|Exitedofint|Fatal_signalofint[@@derivingsexp]endletprocess_exit_status=Funcall.("process-exit-status"<:t@->returnint)letexit_statust:Exit_status.t=matchstatustwith|Exit->Exited(process_exit_statust)|Signal->Fatal_signal(process_exit_statust)|Closed|Connect|Failed|Listen|Open|Run|Stop->Not_exited;;letfind_by_name=Funcall.("get-process"<:string@->return(nil_ort))letall_emacs_children=Funcall.("process-list"<:nullary@->return(listt))letcreateprogargs~name?buffer()=Symbol.funcallNQ.start_process([name|>Value.of_utf8_bytes;(matchbufferwith|None->Value.nil|Someb->b|>Buffer.to_value);prog|>Value.of_utf8_bytes]@(args|>List.map~f:Value.of_utf8_bytes))|>of_value_exn;;letkill=Funcall.("delete-process"<:t@->returnnil)letcreate_unix_network_process()~filter~name~socket_path=of_value_exn(Symbol.funcallNQ.make_network_process[Q.K.name|>Symbol.to_value;name|>Value.of_utf8_bytes;Q.K.family|>Symbol.to_value;Q.local|>Symbol.to_value;Q.K.server|>Symbol.to_value;Q.t|>Symbol.to_value;Q.K.service|>Symbol.to_value;socket_path|>Value.of_utf8_bytes;Q.K.filter|>Symbol.to_value;Function.to_value(Defun.lambda[%here]~docstring:"Network process filter."(ReturnsValue.Type.unit)(let%map_open.Defun()=return()andprocess=required"process"tandoutput=required"output"Text.tinfilterprocessoutput))]);;moduleCall=structmoduleInput=structtypet=|Dev_null|Fileofstring[@@derivingsexp_of]letto_value=function|Dev_null->Value.nil|Filefile->file|>Value.of_utf8_bytes;;endmoduleRegion_input=structtypet=|Regionof{start:Position.t;end_:Position.t;delete:bool}|Stringofstring[@@derivingsexp_of]endmoduleOutput=structmoduleStdout=structtypet=|Before_point_inofBuffer.t|Before_point_in_current_buffer|Dev_null|Overwrite_fileofstring[@@derivingsexp_of]letto_value=function|Before_point_inbuffer->buffer|>Buffer.to_value|Before_point_in_current_buffer->Value.t|Dev_null->Value.nil|Overwrite_filestring->Value.list[Q.K.file|>Symbol.to_value;string|>Value.of_utf8_bytes];;endmoduleStderr=structtypet=|Dev_null|Overwrite_fileofstring[@@derivingsexp_of]letto_value=function|Dev_null->Value.nil|Overwrite_filestring->string|>Value.of_utf8_bytes;;endtypet=|Before_point_inofBuffer.t|Before_point_in_current_buffer|Dev_null|Overwrite_fileofstring|Splitof{stderr:Stderr.t;stdout:Stdout.t}[@@derivingsexp_of]letto_value=function|Before_point_inbuffer->buffer|>Buffer.to_value|Before_point_in_current_buffer->Value.t|Dev_null->Value.nil|Overwrite_filestring->Value.list[Q.K.file|>Symbol.to_value;string|>Value.of_utf8_bytes]|Split{stderr;stdout}->Value.list[stdout|>Stdout.to_value;stderr|>Stderr.to_value];;endmoduleResult=structtypet=|Exit_statusofint|Signaledofstring[@@derivingsexp_of]letof_value_exnvalue=ifValue.is_integervaluethenExit_status(value|>Value.to_int_exn)elseifValue.is_stringvaluethenSignaled(value|>Value.to_utf8_bytes_exn)elseraise_s[%message"[Process.Call.Result.of_value_exn] got unexpected value"(value:Value.t)];;endendletcall_region_exn?(input=Call.Region_input.Region{start=Point.min();end_=Point.max();delete=false})?(output=Call.Output.Dev_null)?(redisplay_on_output=false)?(working_directory=Working_directory.Root)progargs=Working_directory.withinworking_directory~f:(fun()->letstart,end_,delete=matchinputwith|Region{start;end_;delete}->start|>Position.to_value,end_|>Position.to_value,delete|Strings->s|>Value.of_utf8_bytes,Value.nil,falseinSymbol.funcallNQ.call_process_region([start;end_;prog|>Value.of_utf8_bytes;delete|>Value.of_bool;output|>Call.Output.to_value;redisplay_on_output|>Value.of_bool]@(args|>List.map~f:Value.of_utf8_bytes))|>Call.Result.of_value_exn);;letcall_result_exn?(input=Call.Input.Dev_null)?(output=Call.Output.Dev_null)?(redisplay_on_output=false)?(working_directory=Working_directory.Root)progargs=Working_directory.withinworking_directory~f:(fun()->Symbol.funcallNQ.call_process([prog|>Value.of_utf8_bytes;input|>Call.Input.to_value;output|>Call.Output.to_value;redisplay_on_output|>Value.of_bool]@(args|>List.map~f:Value.of_utf8_bytes))|>Call.Result.of_value_exn);;moduleLines_or_sexp=structincludeAsync_unix.Process.Lines_or_sexpletof_texttext=text|>Text.to_utf8_bytes|>String.strip|>createendletcall_exn?input?working_directory?(strip_whitespace=true)?(verbose_exn=true)progargs=Current_buffer.set_temporarily_to_temp_bufferSync(fun()->matchcall_result_exnprogargs?input?working_directory~output:Before_point_in_current_bufferwith|Exit_status0->letbuffer_contents=Current_buffer.contents()|>Text.to_utf8_bytesinifstrip_whitespacethenString.stripbuffer_contentselsebuffer_contents|result->letoutput=Current_buffer.contents()|>Lines_or_sexp.of_textin(matchverbose_exnwith|true->raise_s[%message"[Process.call_exn] failed"(prog:string)(args:stringlist)(result:Call.Result.t)(output:Lines_or_sexp.t)]|false->raise_s[%sexp(output:Lines_or_sexp.t)]));;letcall_expect_no_output_exn?input?working_directory?(strip_whitespace=false)?verbose_exnprogargs=letresult=call_exn?input?working_directory?verbose_exn~strip_whitespaceprogargsinifString.is_emptyresultthen()elseraise_s[%message"[Process.call_expect_no_output_exn] produced unexpected output"(prog:string)(args:stringlist)(result:string)~output:(Current_buffer.contents()|>Lines_or_sexp.of_text:Lines_or_sexp.t)];;letbash="/bin/bash"letshell_command_result?input?output?redisplay_on_output?working_directorycommand=call_result_exnbash["-c";command]?input?output?redisplay_on_output?working_directory;;letshell_command_exn?input?working_directory?verbose_exncommand=call_exnbash["-c";command]?input?working_directory?verbose_exn;;letshell_command_expect_no_output_exn?input?working_directory?verbose_exncommand=call_expect_no_output_exnbash["-c";command]?input?working_directory?verbose_exn;;letprocess_sentinel=Funcall.("process-sentinel"<:t@->return(nil_orFunction.t))letset_process_sentinel=Funcall.("set-process-sentinel"<:t@->Function.t@->returnnil);;letextend_sentinel(typea)heret(returns:(unit,a)Defun.Returns.t)~(sentinel:event:string->a)=letprevious_sentinel=process_sentineltinset_process_sentinelt(Defun.lambdaherereturns(let%map_open.Defun()=return()andprocess=required"process"valueandevent=required"event"valueinletrun_previous_sentinel()=matchprevious_sentinelwith|None->()|Someprevious_sentinel->Value.funcall2_i(previous_sentinel|>Function.to_value)processeventinmatchreturnswith|Returns_->run_previous_sentinel();Background.Private.mark_running_in_background[%here]~f:(fun()->(sentinel~event:(event|>Value.to_utf8_bytes_exn):a))|Returns_deferred_->let%bind.Deferred()=Value.Private.run_outside_async[%here]~allowed_in_background:truerun_previous_sentinelinBackground.Private.mark_running_in_background[%here]~f:(fun()->sentinel~event:(event|>Value.to_utf8_bytes_exn))));;moduleExited=structtypet=|Exitedofint|Fatal_signalofint[@@derivingsexp_of]letsuccessfully=function|Exited0->true|Exited_|Fatal_signal_->false;;endletexited=letproperty="exited"|>Symbol.interninlettype_=Caml_embed.create_type(Type_equal.Id.create~name:"exited"[%sexp_of:Exited.tDeferred.t])infunt->letcheck_status():Exited.toption=matchexit_statustwith|Not_exited->None|Exitedi->Some(Exitedi)|Fatal_signali->Some(Fatal_signali)inmatchget_propertytpropertywith|Somev->v|>Value.Type.of_value_exntype_|None->(matchcheck_status()with|Somex->returnx|None->letivar:Exited.tIvar.t=Ivar.create()inextend_sentinel[%here]t(ReturnsValue.Type.unit)~sentinel:(fun~event:_->Option.iter(check_status())~f:(Ivar.fill_if_emptyivar));letexited=Ivar.readivarinset_propertytproperty(exited|>Value.Type.to_valuetype_);exited);;