From 0b4d9c8ce32658088b112488132760dd1114963b Mon Sep 17 00:00:00 2001 From: "wojciech.meyer" Date: Thu, 15 Mar 2012 04:16:45 +0100 Subject: [PATCH] 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 --- src/lib/uTop_main.ml | 4 ++++ src/top/utop.el | 24 +++++++++++++++++++----- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/lib/uTop_main.ml b/src/lib/uTop_main.ml index 7f22da1..bbdcd8b 100644 --- a/src/lib/uTop_main.ml +++ b/src/lib/uTop_main.ml @@ -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: *) diff --git a/src/top/utop.el b/src/top/utop.el index 6f08a8b..7f39656 100644 --- a/src/top/utop.el +++ b/src/top/utop.el @@ -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 | ;; +-----------------------------------------------------------------+