Use pcase in utop-compat-resolve

Simpler than cond (and pcase is available since emacs 24)
This commit is contained in:
Rudi Grinberg 2017-08-15 12:16:40 -04:00
parent 14c2282449
commit e838896e53
1 changed files with 10 additions and 8 deletions

View File

@ -18,6 +18,7 @@
;;; Code: ;;; Code:
(require 'easymenu) (require 'easymenu)
(require 'pcase)
;; tabulated-list is a part of Emacs 24 ;; tabulated-list is a part of Emacs 24
(require 'tabulated-list nil t) (require 'tabulated-list nil t)
@ -238,19 +239,20 @@ Caml toplevel")
(defun utop-compat-resolve (choices) (defun utop-compat-resolve (choices)
"Resolve a symbol based on the current major mode. CHOICES is a "Resolve a symbol based on the current major mode. CHOICES is a
list of 3 function symbols: (tuareg-symbol typerex-symbol caml-symbol)." list of 3 function symbols: (tuareg-symbol typerex-symbol caml-symbol)."
(cond (nth
((eq major-mode 'tuareg-mode ) (nth 0 choices)) (pcase major-mode
((eq major-mode 'typerex-mode ) (nth 1 choices)) ('tuareg-mode 0)
((eq major-mode 'caml-mode ) (nth 2 choices)) ('typerex-mode 1)
((eq major-mode 'reason-mode ) (nth 3 choices)) ('caml-mode 2)
(t (error (format "utop doesn't support the major mode \"%s\". It ('reason-mode 3)
(major-mode (error (format "utop doesn't support the major mode \"%s\". It
supports caml, tuareg, typerex and reason modes by default. For other supports caml, tuareg, typerex and reason modes by default. For other
modes you need to set these variables: modes you need to set these variables:
- `utop-next-phrase-beginning' - `utop-next-phrase-beginning'
- `utop-discover-phrase' - `utop-discover-phrase'
" " major-mode))))
(symbol-name major-mode)))))) choices))
(defun utop-compat-next-phrase-beginning () (defun utop-compat-next-phrase-beginning ()
(funcall (funcall