branch: elpa/tuareg commit d484910213d6a241d72a651cb46b7de17dac1ad5 Author: Stefan Monnier <monn...@iro.umontreal.ca> Commit: Stefan Monnier <monn...@iro.umontreal.ca>
Misc minor simplifications * dot-emacs.el: Don't eagerly load packages. Don't set `merlin-command` to `opam` sine it's the default value anyway. Set a major mode for `.merlin` files even if `merlin-mode` is not installed. * tuareg-opam.el (tuareg-opam-build-menu): Move the function's body to top-level and delete the function. (tuareg-opam-mode): Don't call it. Don't redundantly run `tuareg-opam-mode-hook`. (tuareg--compile-opam): Add FIXME. * tuareg.el (tuareg-mode-map): Prefer `opam-switch-set-switch` if available. (tuareg-opam-insinuate): Don't set `merlin-command` to `opam` since that's its default value anyway. --- dot-emacs.el | 41 +++++++++++++++++++++-------------------- tuareg-opam.el | 18 +++++++++--------- tuareg.el | 10 ++++------ 3 files changed, 34 insertions(+), 35 deletions(-) diff --git a/dot-emacs.el b/dot-emacs.el index 809011e821..6e54088273 100644 --- a/dot-emacs.el +++ b/dot-emacs.el @@ -1,40 +1,40 @@ ;; -*- lexical-binding: t; -*- -(require 'tuareg) +;; (require 'tuareg) ;; See README (setq tuareg-indent-align-with-first-arg nil) -(add-hook - 'tuareg-mode-hook - (lambda() +(add-hook 'tuareg-mode-hook #'my-tuareg-mode-setup) +(defun my-tuareg-mode-setup () (setq show-trailing-whitespace t) (setq indicate-empty-lines t) ;; Enable the representation of some keywords using fonts - (when (functionp 'prettify-symbols-mode) - (prettify-symbols-mode)) + (prettify-symbols-mode) + + (flyspell-prog-mode) ;Spell check strings and comments. + + ;; Easy keys to navigate errors after compilation: + (define-key tuareg-mode-map [(f12)] #'next-error) + (define-key tuareg-mode-map [(shift f12)] #'previous-error) - (when (functionp 'flyspell-prog-mode) - (flyspell-prog-mode)) ;; See README ;;(setq tuareg-match-patterns-aligned t) ;;(electric-indent-mode 0) - )) - + ) -;; Easy keys to navigate errors after compilation: -(define-key tuareg-mode-map [(f12)] #'next-error) -(define-key tuareg-mode-map [(shift f12)] #'previous-error) +;;;; Use Merlin when available ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; Use Merlin if available -(when (require 'merlin nil t) - (setq merlin-command 'opam) - (add-to-list 'auto-mode-alist '("/\\.merlin\\'" . conf-mode)) +;; FIXME: Should be included in Merlin's own support code. +(add-to-list 'auto-mode-alist '("/\\.merlin\\'" . conf-mode)) - (when (functionp 'merlin-document) - (define-key tuareg-mode-map (kbd "\C-c\C-h") #'merlin-document)) +(with-eval-after-load 'merlin + (when (fboundp 'merlin-document) + (with-eval-after-load 'tuareg + (define-key tuareg-mode-map (kbd "\C-c\C-h") #'merlin-document)))) +(when (fboundp 'merlin-mode) ;; Run Merlin if a .merlin file in the parent dirs is detected (add-hook 'tuareg-mode-hook (lambda() @@ -42,8 +42,9 @@ (if (and fn (locate-dominating-file fn ".merlin")) (merlin-mode)))))) -;; Choose modes for related config. files +;;;; Choose modes for related config files ;;;;;;;;;;;;;;;;;; (setq auto-mode-alist + ;; FIXME: Are these still in use? Which tools are they used for? (append '(("_oasis\\'" . conf-mode) ("_tags\\'" . conf-mode) ("_log\\'" . conf-mode)) diff --git a/tuareg-opam.el b/tuareg-opam.el index 2ad3e80a9a..5211624564 100644 --- a/tuareg-opam.el +++ b/tuareg-opam.el @@ -295,12 +295,11 @@ characters \\([0-9]+\\)-\\([0-9]+\\): +\\([^\n]*\\)$" map) "Keymap used in Tuareg-opam mode.") -(defun tuareg-opam-build-menu () - (easy-menu-define - tuareg-opam-mode-menu (list tuareg-opam-mode-map) - "Tuareg-opam mode menu." - '("OPAM" - ["Skeleton" tuareg-opam-insert-opam-form t]))) +(easy-menu-define + tuareg-opam-mode-menu (list tuareg-opam-mode-map) + "Tuareg-opam mode menu." + '("OPAM" + ["Skeleton" tuareg-opam-insert-opam-form t])) ;;;###autoload @@ -323,9 +322,7 @@ characters \\([0-9]+\\)-\\([0-9]+\\): +\\([^\n]*\\)$" (setq-local tuareg-opam--flymake-proc-err-line-patterns tuareg-opam--err-line-patterns) (when (and tuareg-opam-flymake buffer-file-name) - (flymake-mode t)) - (tuareg-opam-build-menu) - (run-mode-hooks 'tuareg-opam-mode-hook)) + (flymake-mode t))) (defun tuareg-opam-config-env (&optional switch) "Get the opam environment for the given switch (or the default @@ -417,6 +414,8 @@ mode-bar menu `\"OPSW\"'." switch before compiling." (let* ((env (tuareg-opam-config-env))) (when env + ;; FIXME: This blindly overrides other settings the user + ;; may have put into `compilation-environment'! (setq-local compilation-environment (mapcar (lambda(v) (concat (car v) "=" (cadr v))) (tuareg-opam-config-env)))))) @@ -426,3 +425,4 @@ switch before compiling." (provide 'tuareg-opam) +;;; tuareg-opam.el ends here diff --git a/tuareg.el b/tuareg.el index c70470c350..fb8a09bf04 100644 --- a/tuareg.el +++ b/tuareg.el @@ -1493,7 +1493,9 @@ Run only once." (define-key map "\C-c\C-q" #'tuareg-indent-phrase) (define-key map "\C-c\C-a" #'tuareg-find-alternate-file) (define-key map "\C-c\C-c" #'compile) - (define-key map "\C-c\C-w" #'tuareg-opam-update-env) + (define-key map "\C-c\C-w" (if (fboundp 'opam-switch-set-switch) + #'opam-switch-set-switch + 'tuareg-opam-update-env)) (define-key map "\M-\C-x" #'tuareg-eval-phrase) (define-key map "\C-x\C-e" #'tuareg-eval-phrase) (define-key map "\C-c\C-e" #'tuareg-eval-phrase) @@ -3510,11 +3512,7 @@ OCaml uses exclusive end-columns but Emacs wants them to be inclusive." (setq tuareg-interactive-program (concat tuareg-opam " exec -- ocaml")) - (advice-add 'compile :before #'tuareg--compile-opam) - - (defvar merlin-command) ;Silence byte-compiler. - (setq merlin-command 'opam) - ) + (advice-add 'compile :before #'tuareg--compile-opam)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;