use simpler emacs features for utop-compat-resolve

Some people have complained about this in the past IIRC.
This commit is contained in:
Jeremie Dimino 2015-01-12 09:56:50 +00:00
parent 1fa1b1f0b3
commit 0a386c3fb8
1 changed files with 33 additions and 18 deletions

View File

@ -217,13 +217,13 @@ Useful as file variable."))
"Name of preprocesor. Currently supported camlp4o, camlp4r. "Name of preprocesor. Currently supported camlp4o, camlp4r.
Useful as file variable.")) Useful as file variable."))
(defvar utop-skip-blank-and-comments 'compat-skip-blank-and-comments (defvar utop-skip-blank-and-comments 'utop-compat-skip-blank-and-comments
"The function used to skip blanks and comments.") "The function used to skip blanks and comments.")
(defvar utop-skip-to-end-of-phrase 'compat-skip-to-end-of-phrase (defvar utop-skip-to-end-of-phrase 'utop-compat-skip-to-end-of-phrase
"The function used to find the end of a phrase") "The function used to find the end of a phrase")
(defvar utop-discover-phrase 'compat-discover-phrase (defvar utop-discover-phrase 'utop-compat-discover-phrase
"The function used to discover a phrase") "The function used to discover a phrase")
(defvar utop-skip-after-eval-phrase t (defvar utop-skip-after-eval-phrase t
@ -236,25 +236,40 @@ Caml toplevel")
;; | Compability with different ocaml major modes | ;; | Compability with different ocaml major modes |
;; +-----------------------------------------------------------------+ ;; +-----------------------------------------------------------------+
(defun utop-compat-resolve (symbol) (defun utop-compat-resolve (choices)
"Resolve a symbol based on the current major mode." "Resolve a symbol based on the current major mode. CHOICES is a
list of 3 function symbols: (tuareg-symbol typerex-symbol caml-symbol)."
(cond (cond
((eq major-mode 'tuareg-mode) ((eq major-mode 'tuareg-mode ) (nth 0 choices))
(intern (concat "tuareg-" symbol))) ((eq major-mode 'typerex-mode ) (nth 1 choices))
((eq major-mode 'typerex-mode) ((eq major-mode 'caml-mode ) (nth 2 choices))
(intern (concat "typerex-" symbol))) (t (error (format "utop doesn't support the major mode \"%s\". It
((eq major-mode 'caml-mode) supports caml, tuareg and typerex modes by default. For other
(intern (concat "caml-" symbol))) modes you need to set these variables:
(error (concat "unsupported mode: " (symbol-name major-mode) ", utop support only caml, tuareg and typerex modes"))))
(defun compat-skip-blank-and-comments () - `utop-skip-blank-and-comments'
(funcall (utop-compat-resolve "skip-blank-and-comments"))) - `utop-skip-to-end-of-phrase'
- `utop-discover-phrase'
"
(symbol-name major-mode))))))
(defun compat-skip-to-end-of-phrase () (defun utop-compat-skip-blank-and-comments ()
(funcall (utop-compat-resolve "skip-to-end-of-phrase"))) (funcall
(utop-compat-resolve '(tuareg-skip-blank-and-comments
typerex-skip-blank-and-comments
caml-skip-blank-and-comments))))
(defun compat-discover-phrase () (defun utop-compat-skip-to-end-of-phrase ()
(funcall (utop-compat-resolve "discover-phrase"))) (funcall
(utop-compat-resolve '(tuareg-skip-to-end-of-phrase
typerex-skip-to-end-of-phrase
caml-skip-to-end-of-phrase))))
(defun utop-compat-discover-phrase ()
(funcall
(utop-compat-resolve '(tuareg-discover-phrase
typerex-discover-phrase
caml-discover-phrase))))
;; +-----------------------------------------------------------------+ ;; +-----------------------------------------------------------------+
;; | Compability with previous emacs version | ;; | Compability with previous emacs version |