Commits

Peter Szilagyi committed 87d73b8

support unset environment variables, with OMakeroot defaults

Comments (0)

Files changed (11)

 =======
 - defaulted tuareg-indent-comments to nil to avoid accidentally
   clobbering carefully indented comments
+- omake server protocol version increment to support unset environment
+  variables, whose default values are determined by the project
+  OMakeroot rather than Jane Elisp
 
 bug fixes
 =========
 - highlighting of long lines in Emacs 24
-- ocaml-indenter: customize-variable choice menu
+- ocaml-indenter: customize-variable choice menu (easier to customize)
 - friend commander password prompts
 
 ================================================================================

elisp/omake/omake-env.el

 (defun Omake.Env.value-p (v)
   (assert (symbolp v))
   (case v
-    ((true false) t)
+    ((true false nil) t)
     (t nil)))
 
 (defstruct
     (intern (completing-read "Var: " vars nil t))))
 
 (defun Omake.Env.completing-read-value ()
-  (let ((vals '("true" "false")))
+  (let ((vals '("true" "false" "nil")))
     (intern (completing-read "Value: " vals nil t))))
 ;; (Omake.Env.completing-read-value)
 
 
 (defun Omake.Env.not (env)
   (case env
-   ('true 'false)
-   ('false 'true)
-   (t (error "Omake.Env.not error: %s" env))))
+    ((true) 'false)
+    ((false nil) 'true)
+    (t (error "Omake.Env.not error: %s" env))))
 ;; (Omake.Env.not "true")
 
 (defun Omake.Env.var-to-string (var val new-val)
+  (unless val (setq val '<default>))
+  (unless new-val (setq new-val '<default>))
   (let ((val (if (equal val new-val) val
                (format "%s (on next compilation: %s)" val new-val))))
     (Omake.Model.verbose-line var val)))

elisp/omake/omake-server.el

      "client" "set-project-env" id key data)))
 ;; (Omake.Server.setenv (Omake.Id.of-path "~/ocaml/lib") 'X_LIBRARY_INLINING 'true)
 ;; (Omake.Server.setenv (Omake.Id.of-path "~/ocaml/lib") 'X_LIBRARY_INLINING 'false)
+;; (Omake.Server.setenv (Omake.Id.of-path "~/local/jane-elisp") 'X_LIBRARY_INLINING 'true)
+;; (Omake.Server.setenv (Omake.Id.of-path "~/local/jane-elisp") 'X_LIBRARY_INLINING 'false)
+;; (Omake.Server.setenv (Omake.Id.of-path "~/local/jane-elisp") 'X_LIBRARY_INLINING nil)
 
 (defun Omake.Server.getenv (id key)
   (assert (Omake.Id.is id))

elisp/omake/omake-version.el

 
 ;; Detect version changes
 
-(defconst Omake.pre-version 16
+(defconst Omake.pre-version 17
   "We use a version number to synchronize the elisp code the omake server
 To roll a new version of elisp that is incompatible with ocaml or vice
 versa, you must bump the version number.  This prevents old elisp code

ocaml/omake/lib/config.ml

   T.set t ~key ~data:(String.lowercase value)
 
 let remove t key =
-  T.remove t key
+  T.remove t (String.lowercase key)
 
 let iter t ~f =
   T.iter t ~f:(fun ~key ~data -> f ~key ~value:data)

ocaml/omake/lib/env.ml

 
 type t = Config.t
 
-(* These defaults should match the variables in OMakeroot.  We
-   thought about parsing OMakeroot to get the defaults, but decided
-   it was too much trouble.  They shouldn't ever change. *)
-(* CR pszilagyi: They should and do change. *)
-let default = function
-| FOUR_POINT_ZERO         -> false
-| LIMIT_SUBDIRS_FOR_SPEED -> false
-| LINK_EXECUTABLES        -> true
-| VERSION_UTIL_SUPPORT    -> true
-| X_LIBRARY_INLINING      -> true
-
 let all_vars =
   [ FOUR_POINT_ZERO
   ; LIMIT_SUBDIRS_FOR_SPEED
 
 let value t v =
   let key = var_to_string v in
-  let default = Bool.to_string (default v) in
-  Bool.of_string (Config.lookup t ~key ~default)
+  if Config.mem t key
+  then Some (Bool.of_string (Config.lookup t ~key ~default:"INCONCEIVABLE"))
+  else None
 
-let to_elisp t = sprintf "
-      (Omake.Env.create
-        :four-point-zero %s
-        :limit-subdirs-for-speed %s
-        :link-executables %s
-        :version-util-support %s
-        :x-library-inlining %s)"
-  (Elisp.env_value (value t FOUR_POINT_ZERO))
-  (Elisp.env_value (value t LIMIT_SUBDIRS_FOR_SPEED))
-  (Elisp.env_value (value t LINK_EXECUTABLES))
-  (Elisp.env_value (value t VERSION_UTIL_SUPPORT))
-  (Elisp.env_value (value t X_LIBRARY_INLINING))
+let to_elisp t =
+  "
+      (Omake.Env.create" ^ String.concat (List.map all_vars ~f:fun var ->
+        "
+        :" ^ String.tr ~target:'_' ~replacement:'-' (String.lowercase (var_to_string var))
+        ^ " " ^ Option.value_map ~default:"nil" ~f:Elisp.env_value (value t var))
+  ^ ")"
 
 (* Save the variables in a file in ~/.omake-server/PROJ/env.sexp *)
 

ocaml/omake/lib/env.mli

 
 type t
 
-val value : t -> var -> bool
+val value : t -> var -> bool option
 
 val to_elisp : t -> Elisp.t
 val get : Id.t -> t

ocaml/omake/lib/query.ml

 | List_projects_emacs
 (* Env vars *)
 | Get_project_env     of Id.t * Env.var
-| Set_project_env     of Id.t * Env.var * bool
+| Set_project_env     of Id.t * Env.var * bool option
 (* Config *)
 | Kill_when_unwatched
 | Omake_command
     | Get_project_env (id, x) ->
       let env = Env.get id in
       let b = Env.value env x in
-      let res = if b then "'true" else "'false" in
+      let res = Option.value_map b ~default:"nil" ~f:(fun b -> "'" ^ Bool.to_string b) in
       Emacs.Sync.send writer "%s" res;
       Deferred.unit
     | Set_project_env (id, x, b) ->
       begin
-        Env.set id x b;
-        Log.printf "Server: %s set to %b" (Env.var_to_string x) b;
+        begin
+          match b with
+          | None ->
+            Env.remove id x;
+            Log.printf "Server: %s removed" (Env.var_to_string x)
+          | Some b ->
+            Env.set id x b;
+            Log.printf "Server: %s set to %b" (Env.var_to_string x) b
+        end;
         match Projects.get id with
         | Some p ->
           let env = Env.get id in
       Writer.writef writer "%s\n" (Elisp.bool (Server_config.kill_when_unwatched ()));
       Deferred.unit
     | Warn_when_setting_env_vars ->
-      Writer.writef writer "%s\n" (Elisp.bool (Server_config.warn_when_setting_env_vars ()));
+      Writer.writef writer "%s\n"
+        (Elisp.bool (Server_config.warn_when_setting_env_vars ()));
       Deferred.unit
     | Don't_warn_when_setting_env_vars ->
       Server_config.don't_warn_when_setting_env_vars ();

ocaml/omake/lib/query.mli

 | List_projects_emacs
 (* Env vars *)
 | Get_project_env     of Id.t * Env.var
-| Set_project_env     of Id.t * Env.var * bool
+| Set_project_env     of Id.t * Env.var * bool option
 (* Config *)
 | Kill_when_unwatched
 | Omake_command

ocaml/omake/lib/top.ml

     Command.Spec.( empty
                    +> anon ("id" %: string)
                    +> anon ("var" %: string)
-                   +> anon ("value" %: bool) )
+                   +> anon ("value" %: string) )
     (fun id var v ->
+      let v = if v = "nil" then None else Some (Bool.of_string v) in
       let id = Id.of_string id in
       let var = Env.var_of_string var in
       send (Q.Set_project_env (id, var, v)))

ocaml/omake/lib/version.ml

 
 (* Use a version number to synchronize with the elisp code. *)
-let version = 16
+let version = 17