Skip to content

Commit d484910

Browse files
committedJul 18, 2023
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.
1 parent eb3d8bb commit d484910

File tree

3 files changed

+34
-35
lines changed

3 files changed

+34
-35
lines changed
 

‎dot-emacs.el

+21-20
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,50 @@
11
;; -*- lexical-binding: t; -*-
2-
(require 'tuareg)
2+
;; (require 'tuareg)
33

44
;; See README
55
(setq tuareg-indent-align-with-first-arg nil)
66

7-
(add-hook
8-
'tuareg-mode-hook
9-
(lambda()
7+
(add-hook 'tuareg-mode-hook #'my-tuareg-mode-setup)
8+
(defun my-tuareg-mode-setup ()
109
(setq show-trailing-whitespace t)
1110
(setq indicate-empty-lines t)
1211

1312
;; Enable the representation of some keywords using fonts
14-
(when (functionp 'prettify-symbols-mode)
15-
(prettify-symbols-mode))
13+
(prettify-symbols-mode)
14+
15+
(flyspell-prog-mode) ;Spell check strings and comments.
16+
17+
;; Easy keys to navigate errors after compilation:
18+
(define-key tuareg-mode-map [(f12)] #'next-error)
19+
(define-key tuareg-mode-map [(shift f12)] #'previous-error)
1620

17-
(when (functionp 'flyspell-prog-mode)
18-
(flyspell-prog-mode))
1921
;; See README
2022
;;(setq tuareg-match-patterns-aligned t)
2123
;;(electric-indent-mode 0)
22-
))
23-
24+
)
2425

25-
;; Easy keys to navigate errors after compilation:
26-
(define-key tuareg-mode-map [(f12)] #'next-error)
27-
(define-key tuareg-mode-map [(shift f12)] #'previous-error)
2826

27+
;;;; Use Merlin when available ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2928

30-
;; Use Merlin if available
31-
(when (require 'merlin nil t)
32-
(setq merlin-command 'opam)
33-
(add-to-list 'auto-mode-alist '("/\\.merlin\\'" . conf-mode))
29+
;; FIXME: Should be included in Merlin's own support code.
30+
(add-to-list 'auto-mode-alist '("/\\.merlin\\'" . conf-mode))
3431

35-
(when (functionp 'merlin-document)
36-
(define-key tuareg-mode-map (kbd "\C-c\C-h") #'merlin-document))
32+
(with-eval-after-load 'merlin
33+
(when (fboundp 'merlin-document)
34+
(with-eval-after-load 'tuareg
35+
(define-key tuareg-mode-map (kbd "\C-c\C-h") #'merlin-document))))
3736

37+
(when (fboundp 'merlin-mode)
3838
;; Run Merlin if a .merlin file in the parent dirs is detected
3939
(add-hook 'tuareg-mode-hook
4040
(lambda()
4141
(let ((fn (buffer-file-name)))
4242
(if (and fn (locate-dominating-file fn ".merlin"))
4343
(merlin-mode))))))
4444

45-
;; Choose modes for related config. files
45+
;;;; Choose modes for related config files ;;;;;;;;;;;;;;;;;;
4646
(setq auto-mode-alist
47+
;; FIXME: Are these still in use? Which tools are they used for?
4748
(append '(("_oasis\\'" . conf-mode)
4849
("_tags\\'" . conf-mode)
4950
("_log\\'" . conf-mode))

‎tuareg-opam.el

+9-9
Original file line numberDiff line numberDiff line change
@@ -295,12 +295,11 @@ characters \\([0-9]+\\)-\\([0-9]+\\): +\\([^\n]*\\)$"
295295
map)
296296
"Keymap used in Tuareg-opam mode.")
297297

298-
(defun tuareg-opam-build-menu ()
299-
(easy-menu-define
300-
tuareg-opam-mode-menu (list tuareg-opam-mode-map)
301-
"Tuareg-opam mode menu."
302-
'("OPAM"
303-
["Skeleton" tuareg-opam-insert-opam-form t])))
298+
(easy-menu-define
299+
tuareg-opam-mode-menu (list tuareg-opam-mode-map)
300+
"Tuareg-opam mode menu."
301+
'("OPAM"
302+
["Skeleton" tuareg-opam-insert-opam-form t]))
304303

305304

306305
;;;###autoload
@@ -323,9 +322,7 @@ characters \\([0-9]+\\)-\\([0-9]+\\): +\\([^\n]*\\)$"
323322
(setq-local tuareg-opam--flymake-proc-err-line-patterns
324323
tuareg-opam--err-line-patterns)
325324
(when (and tuareg-opam-flymake buffer-file-name)
326-
(flymake-mode t))
327-
(tuareg-opam-build-menu)
328-
(run-mode-hooks 'tuareg-opam-mode-hook))
325+
(flymake-mode t)))
329326

330327
(defun tuareg-opam-config-env (&optional switch)
331328
"Get the opam environment for the given switch (or the default
@@ -417,6 +414,8 @@ mode-bar menu `\"OPSW\"'."
417414
switch before compiling."
418415
(let* ((env (tuareg-opam-config-env)))
419416
(when env
417+
;; FIXME: This blindly overrides other settings the user
418+
;; may have put into `compilation-environment'!
420419
(setq-local compilation-environment
421420
(mapcar (lambda(v) (concat (car v) "=" (cadr v)))
422421
(tuareg-opam-config-env))))))
@@ -426,3 +425,4 @@ switch before compiling."
426425

427426

428427
(provide 'tuareg-opam)
428+
;;; tuareg-opam.el ends here

‎tuareg.el

+4-6
Original file line numberDiff line numberDiff line change
@@ -1493,7 +1493,9 @@ Run only once."
14931493
(define-key map "\C-c\C-q" #'tuareg-indent-phrase)
14941494
(define-key map "\C-c\C-a" #'tuareg-find-alternate-file)
14951495
(define-key map "\C-c\C-c" #'compile)
1496-
(define-key map "\C-c\C-w" #'tuareg-opam-update-env)
1496+
(define-key map "\C-c\C-w" (if (fboundp 'opam-switch-set-switch)
1497+
#'opam-switch-set-switch
1498+
'tuareg-opam-update-env))
14971499
(define-key map "\M-\C-x" #'tuareg-eval-phrase)
14981500
(define-key map "\C-x\C-e" #'tuareg-eval-phrase)
14991501
(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."
35103512
(setq tuareg-interactive-program
35113513
(concat tuareg-opam " exec -- ocaml"))
35123514

3513-
(advice-add 'compile :before #'tuareg--compile-opam)
3514-
3515-
(defvar merlin-command) ;Silence byte-compiler.
3516-
(setq merlin-command 'opam)
3517-
)
3515+
(advice-add 'compile :before #'tuareg--compile-opam))
35183516

35193517

35203518
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

0 commit comments

Comments
 (0)
Please sign in to comment.