Now it's possible to load packages defined with the file variable utop-package-list, therefore they can be loaded at startup to the toplevel. Desirable user interface has been implemented as part of it. To enable put something like:

Ignore-this: cd594a9e2a71feadba95000a15838d82

(add-hook 'typerex-mode-hook 'utop-setup-ocaml-buffer)
(add-hook 'hack-local-variables-hook 'utop-query-load-package-list)

in your .emacs

darcs-hash:20120315031645-33bd9-c602dacabd15aaa3a63fd3c4146e7f81f16e567d
This commit is contained in:
wojciech.meyer 2012-03-15 04:16:45 +01:00
parent 4d78acb1bd
commit 0b4d9c8ce3
2 changed files with 23 additions and 5 deletions

View File

@ -848,3 +848,7 @@ let main () =
Printexc.print_backtrace stderr;
flush stderr;
exit 2
(* Local variables: *)
(* utop-package-list: ("camomile" "lwt" "lwt.react" "lambda-term" "zed") *)
(* End: *)

View File

@ -181,6 +181,10 @@ before the end of prompt.")
"The position of the cursor in the phrase sent to OCaml (where
to add the newline character if it is not accepted).")
(defvar utop-package-list nil
"List of packages to load when visiting OCaml buffer.
Useful as file variable.")
;; +-----------------------------------------------------------------+
;; | Compability |
;; +-----------------------------------------------------------------+
@ -754,6 +758,7 @@ To automatically do that just add these lines to your .emacs:
(utop-choose-defun "run-caml" () (interactive) (utop))
;; Redefine this variable so menu will work
(set (utop-choose "interactive-buffer-name") utop-buffer-name)
(make-local-variable 'utop-package-list)
nil)
;; +-----------------------------------------------------------------+
@ -880,12 +885,13 @@ defaults to 0."
(insert-char ?\s (- width (length (elt cols 0))))
(insert (elt cols 1) "\n")))
(defun utop-load-package (package)
(when (y-or-n-p (format "Load package `%s'? " package))
;; Load it
(utop-send-string (format "require:%s\n" package))))
(defun utop-require-package-button-action (button)
(let ((package (button-label button)))
(when (y-or-n-p (format "Load package `%s'? " package))
;; Handle loading of packages
(utop-send-string (format "require:%s\n" package))
)))
(utop-load-package (button-label button)))
(defun utop-list-ocaml-packages (&optional buffer)
"Display a list of all ocaml findlib packages"
@ -898,6 +904,14 @@ defaults to 0."
(tabulated-list-print t)
(display-buffer buffer)))
(defun utop-query-load-package-list ()
"Load packages defined in utop-package-list buffer local variable."
(when (and utop-package-list
(y-or-n-p
"You've defined utop-package-list variable, but uTop toplevel is not running, would you like me to start the toplevel?"))
(with-current-buffer (utop))
(mapc 'utop-load-package utop-package-list)))
;; +-----------------------------------------------------------------+
;; | Menu |
;; +-----------------------------------------------------------------+