Use minor mode rather than overriding variables at runtime

This commit is contained in:
Mads Hartmann Jensen 2015-01-02 11:44:08 +01:00
parent 791d95b94f
commit 3c958ebf2e
1 changed files with 21 additions and 42 deletions

View File

@ -207,13 +207,15 @@ before the end of prompt.")
"The position of the cursor in the phrase sent to OCaml (where "The position of the cursor in the phrase sent to OCaml (where
to add the newline character if it is not accepted).") to add the newline character if it is not accepted).")
(defvar utop-package-list nil (make-variable-buffer-local
(defvar utop-package-list nil
"List of packages to load when visiting OCaml buffer. "List of packages to load when visiting OCaml buffer.
Useful as file variable.") Useful as file variable."))
(defvar utop-ocaml-preprocessor nil (make-variable-buffer-local
(defvar utop-ocaml-preprocessor nil
"Name of preprocesor. Currently supported camlp4o, camlp4r. "Name of preprocesor. Currently supported camlp4o, camlp4r.
Useful as file variable.") Useful as file variable."))
;; +-----------------------------------------------------------------+ ;; +-----------------------------------------------------------------+
;; | Compability | ;; | Compability |
@ -881,42 +883,6 @@ when byte-compiling."
;; Send the phrase to complete ;; Send the phrase to complete
(utop-complete-input input))))))) (utop-complete-input input)))))))
(defun utop-setup-ocaml-buffer ()
"Override caml/tuareg/typerex interactive functions by utop ones.
You can call this function after loading the caml/tuareg/typerex
mode to let it use utop instead of its builtin support for
interactive toplevel.
To automatically do that just add these lines to your .emacs:
(autoload 'utop-setup-ocaml-buffer \"utop\" \"Toplevel for OCaml\" t)
(add-hook 'caml-mode-hook 'utop-setup-ocaml-buffer)
(add-hook 'tuareg-mode-hook 'utop-setup-ocaml-buffer)
(add-hook 'typerex-mode-hook 'utop-setup-ocaml-buffer)"
(interactive)
;; Redefine caml/tuareg/typerex functions
(utop-choose-defun "eval-phrase" () (interactive) (utop-eval-phrase))
(utop-choose-defun "eval-region" (start end) (interactive "r") (utop-eval-region start end))
(utop-choose-defun "eval-buffer" () (interactive) (utop-eval-buffer))
(utop-choose-defun "interrupt-caml" () (interactive) (utop-interrupt))
(utop-choose-defun "kill-caml" () (interactive) (utop-kill))
(utop-choose-defun "run-caml" () (interactive) (utop))
;; Redefine this variable so menu will work
(set (utop-choose "interactive-buffer-name") utop-buffer-name)
;; Package list for this file
(make-local-variable 'utop-package-list)
;; Preprocessor to use
(make-local-variable 'utop-ocaml-preprocessor)
;; Load local file variables
(add-hook 'hack-local-variables-hook 'utop-hack-local-variables)
nil)
;; +-----------------------------------------------------------------+ ;; +-----------------------------------------------------------------+
;; | Edition functions | ;; | Edition functions |
;; +-----------------------------------------------------------------+ ;; +-----------------------------------------------------------------+
@ -1164,6 +1130,19 @@ defaults to 0."
(utop-insert "\nRestarting...\n\n") (utop-insert "\nRestarting...\n\n")
(utop-start arguments))) (utop-start arguments)))
(define-minor-mode utop-minor-mode
"Minor mode for utop."
:lighter " utop"
:keymap (let ((map (make-sparse-keymap)))
(define-key map (kbd "C-c C-z") 'utop)
(define-key map (kbd "C-x C-e") 'utop-eval-phrase)
(define-key map (kbd "C-x C-r") 'utop-eval-region)
(define-key map (kbd "C-c C-b") 'utop-eval-buffer)
(define-key map (kbd "C-c C-k") 'utop-kill)
map)
;; Load local file variables
(add-hook 'hack-local-variables-hook 'utop-hack-local-variables))
(define-derived-mode utop-mode fundamental-mode "utop" (define-derived-mode utop-mode fundamental-mode "utop"
"Set the buffer mode to utop." "Set the buffer mode to utop."