diff options
| -rw-r--r-- | modules/dashboard-config.el | 4 | ||||
| -rw-r--r-- | modules/telega-config.el | 19 | ||||
| -rw-r--r-- | tests/test-telega-config.el | 29 |
3 files changed, 47 insertions, 5 deletions
diff --git a/modules/dashboard-config.el b/modules/dashboard-config.el index 2fbed716..b61129ad 100644 --- a/modules/dashboard-config.el +++ b/modules/dashboard-config.el @@ -184,7 +184,7 @@ Adjust this if the title doesn't appear centered under the banner image.") ;; Row 3 ((,(nerd-icons-faicon "nf-fa-telegram") "Telegram" "Telega Telegram Client" - (lambda (&rest _) (telega)) + (lambda (&rest _) (cj/telega)) nil " " "")))) ;; == content @@ -208,7 +208,7 @@ Adjust this if the title doesn't appear centered under the banner image.") (define-key dashboard-mode-map (kbd "s") (lambda () (interactive) (cj/slack-start))) (define-key dashboard-mode-map (kbd "t") (lambda () (interactive) (vterm))) (define-key dashboard-mode-map (kbd "d") (lambda () (interactive) (dirvish user-home-dir))) - (define-key dashboard-mode-map (kbd "g") (lambda () (interactive) (telega)))) + (define-key dashboard-mode-map (kbd "g") (lambda () (interactive) (cj/telega)))) ;; Override banner title centering (must be after dashboard-widgets loads) (with-eval-after-load 'dashboard-widgets diff --git a/modules/telega-config.el b/modules/telega-config.el index 003fa15d..1691a95b 100644 --- a/modules/telega-config.el +++ b/modules/telega-config.el @@ -46,7 +46,24 @@ :custom (telega-use-docker t)) -(keymap-set cj/custom-keymap "G" #'telega) +(defun cj/telega () + "Launch telega.el with a helpful message when it isn't installed yet. + +The =telega= Emacs package uses =:ensure nil= in this config so a +stale MELPA archive index can't take startup down with a 404. The +trade-off: a fresh clone needs a one-time install before this +launcher works. Without this wrapper, the autoload stub fails with +the cryptic =Cannot open load file: telega=; with it, the user gets +pointed at =scripts/setup-telega.sh= and the manual fallback." + (interactive) + (if (or (featurep 'telega) + (locate-library "telega")) + (telega) + (user-error + (concat "telega not installed -- run scripts/setup-telega.sh, " + "or `M-x package-install RET telega'")))) + +(keymap-set cj/custom-keymap "G" #'cj/telega) (with-eval-after-load 'which-key (which-key-add-key-based-replacements diff --git a/tests/test-telega-config.el b/tests/test-telega-config.el index ace96555..c642d1f6 100644 --- a/tests/test-telega-config.el +++ b/tests/test-telega-config.el @@ -18,8 +18,33 @@ (should (featurep 'telega-config))) (ert-deftest test-telega-config-launcher-binding-is-telega () - "Normal: =C-; G= invokes `telega'." - (should (eq (keymap-lookup cj/custom-keymap "G") #'telega))) + "Normal: =C-; G= invokes the launcher wrapper, which routes to +`telega' when installed or signals a helpful user-error otherwise." + (should (eq (keymap-lookup cj/custom-keymap "G") #'cj/telega))) + +(ert-deftest test-telega-config-launcher-without-package-signals-user-error () + "Error: with telega absent, the launcher signals a `user-error' that +mentions the recovery path instead of falling through to the autoload +stub's cryptic load-file failure." + (cl-letf (((symbol-function 'featurep) + (lambda (sym &optional _sub) + (and (not (eq sym 'telega)) t))) + ((symbol-function 'locate-library) + (lambda (lib &rest _) (unless (equal lib "telega") t)))) + (let* ((err (should-error (cj/telega) :type 'user-error)) + (msg (error-message-string err))) + (should (string-match-p "telega not installed" msg)) + (should (string-match-p "setup-telega\\.sh\\|package-install" msg))))) + +(ert-deftest test-telega-config-launcher-with-package-calls-telega () + "Normal: with telega loadable, the launcher delegates to `telega'." + (let (called) + (cl-letf (((symbol-function 'featurep) + (lambda (sym &optional _sub) (eq sym 'telega))) + ((symbol-function 'telega) + (lambda (&rest _) (setq called t)))) + (cj/telega)) + (should called))) (provide 'test-telega-config) ;;; test-telega-config.el ends here |
