Skip to content

Commit

Permalink
Misc minor simplifications
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
monnier committed Jul 18, 2023
1 parent eb3d8bb commit d484910
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 35 deletions.
41 changes: 21 additions & 20 deletions dot-emacs.el
Original file line number Diff line number Diff line change
@@ -1,49 +1,50 @@
;; -*- 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()
(let ((fn (buffer-file-name)))
(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))
Expand Down
18 changes: 9 additions & 9 deletions tuareg-opam.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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))))))
Expand All @@ -426,3 +425,4 @@ switch before compiling."


(provide 'tuareg-opam)
;;; tuareg-opam.el ends here
10 changes: 4 additions & 6 deletions tuareg.el
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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))


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Expand Down

0 comments on commit d484910

Please sign in to comment.