Skip to content

Commit 42bd470

Browse files
author
Daniel Dinnyes
committed
only use packages if neccessary executables are available
1 parent 83d5338 commit 42bd470

File tree

1 file changed

+16
-22
lines changed

1 file changed

+16
-22
lines changed

init.el

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,15 @@
5555
'display-line-numbers-mode
5656
'linum-mode))
5757

58+
(defun executables-missing (&rest commands)
59+
"Check if any of COMMANDS are missing."
60+
(let ((result nil))
61+
(dolist (command commands result)
62+
(unless (executable-find command)
63+
(message "Necessary executable '%s' is not found on exec-path" command)
64+
(setq result t)))
65+
result))
66+
5867
(use-package exec-path-from-shell
5968
:if (memq window-system '(mac ns x))
6069
:config
@@ -371,31 +380,18 @@
371380
(js2r-add-keybindings-with-prefix "C-c C-r"))
372381

373382
(use-package xref-js2
383+
:unless (executables-missing "ag")
374384
:after (js2-mode)
375-
:init
376-
(defun init-js2-xref-backend ()
377-
"Initialises JS2 Xref backend via hook"
378-
(cond
379-
((not (executable-find "ag"))
380-
(message "Necessary executable `ag' is not found on `exec-path'"))
381-
(t (message "Registered JS2 Xref backend")
382-
(add-hook 'xref-backend-functions 'xref-js2-xref-backend))))
383385
:hook
384-
(js2-mode . init-js2-xref-backend))
386+
(xref-backend-functions
387+
xref-js2-xref-backend))
385388

386389
(use-package company-tern
390+
:unless (executables-missing "tern")
387391
:after (company js2-mode)
388-
:init
389-
(defun enable-company-tern ()
390-
"Initialises Tern company backend"
391-
(cond
392-
((not (executable-find "tern"))
393-
(message "Necessary executable `tern' is not found on `exec-path'"))
394-
(t (message "Turning on company-mode using Tern")
395-
(company-mode)
396-
(tern-mode))))
397392
:hook
398-
(js2-mode . enable-company-tern)
393+
(js2-mode . company-mode)
394+
(js2-mode . tern-mode)
399395
:config
400396
(add-to-list 'company-backends 'company-tern)
401397
(unbind-key "M-." tern-mode-keymap)
@@ -430,9 +426,7 @@
430426
(use-package systemd)
431427

432428
(use-package markdown-mode
433-
:init
434-
(when (not (executable-find "markdown"))
435-
(message "Necessary executable `markdown' is not found on `exec-path'"))
429+
:unless (executables-missing "markdown")
436430
:hook
437431
(markdown-mode . markdown-live-preview-mode)
438432
(markdown-mode . visual-line-mode)

0 commit comments

Comments
 (0)