diff --git a/ChangeLog b/ChangeLog index 5d1958a4..ef0b2aab 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,26 @@ +2026-07-14 Mats Lidell + +* hyrolo.el (hyrolo-install-markdown-mode): Respect hypb:ask-to-install-package-flag. +* test/hy-test-dependencies.el (hypb:ask-to-install-package-flag): Set to + nil for not asking about installing dynamic dependencies during test, + i.e. markdown-mode. +* hsys-consult.el (hsys-consult-require-version): + (hsys-consult--org-roam-call-function): +* hui-treemacs.el (treemacs): +* hypb.el (hypb:activate-interaction-log-mode): Use hypb:require-package. +* hyrolo.el (hyrolo-any-file-type-problem-p): Use require to check if + markdown-mode is available. + (hyrolo-install-markdown-mode): Copy hypb:ensure-dependency but add + nongnu if it is missing to package-archives before installation. +* hypb.el (hypb:ask-to-install-package-flag): Give user control if package + shall be installed when using package.el. + (hypb:users-package-manager): Users package manager. + (hypb:package-el-install): Install package using package.el. + (hypb:notify-manual-install-needed): Notify user manual install is needed. + (hypb:ensure-dependency): Ensure package is available using + hypb:package-el-install or hypb:notify-manual-install-needed. + (hypb:require-package): Use hypb:ensure-dependency. + 2026-07-14 Bob Weiner * test/hy-test-dependencies.el: Add 'markdown-ts-mode' declaration. diff --git a/hsys-consult.el b/hsys-consult.el index 0343a20c..d4a33d07 100644 --- a/hsys-consult.el +++ b/hsys-consult.el @@ -2,7 +2,7 @@ ;; Author: Bob Weiner ;; ;; Orig-Date: 4-Jul-24 at 09:57:18 -;; Last-Mod: 6-May-26 at 08:17:25 by Bob Weiner +;; Last-Mod: 12-Jul-26 at 00:03:44 by Mats Lidell ;; ;; SPDX-License-Identifier: GPL-3.0-or-later ;; @@ -116,9 +116,7 @@ Requires use of `vertico' for completions." Install `consult' package if not yet installed." (unless hsys-consult-flag (error "`%s' command requires `hsys-consult-flag' set to t" this-command)) - (unless (package-installed-p 'consult) - (package-install 'consult)) - (require 'consult) + (hypb:require-package 'consult) (let ((consult-version (hsys-consult-get-version))) ;; Multi-file support added after consult version "0.32" (when (not (and consult-version (string-greaterp consult-version "0.32"))) @@ -403,9 +401,7 @@ tag around point." "Install Org Roam if necessary and then call an Org Roam FUNC." (unless hsys-consult-flag (error "`%s' command requires `hsys-consult-flag' set to t" this-command)) - (unless (package-installed-p 'org-roam) - (package-install 'org-roam)) - (require 'org-roam) + (hypb:require-package 'org-roam) (unless (file-readable-p org-roam-directory) (make-directory org-roam-directory)) (unless org-roam-db-autosync-mode diff --git a/hui-treemacs.el b/hui-treemacs.el index b17f8b15..5ef6015e 100644 --- a/hui-treemacs.el +++ b/hui-treemacs.el @@ -3,7 +3,7 @@ ;; Author: Bob Weiner ;; ;; Orig-Date: 19-Nov-17 -;; Last-Mod: 7-Mar-26 at 22:39:17 by Bob Weiner +;; Last-Mod: 11-Jul-26 at 23:58:02 by Mats Lidell ;; ;; SPDX-License-Identifier: GPL-3.0-or-later ;; @@ -24,10 +24,7 @@ (require 'package) ;; Always keep this first (require 'seq) -(or (require 'treemacs nil t) - (and (package-installed-p 'treemacs) - (package-activate 'treemacs)) - (hypb:require-package 'treemacs)) +(hypb:require-package 'treemacs) (defvar treemacs-version) diff --git a/hypb.el b/hypb.el index 2c34d3f8..cb129fbe 100644 --- a/hypb.el +++ b/hypb.el @@ -3,7 +3,7 @@ ;; Author: Bob Weiner ;; ;; Orig-Date: 6-Oct-91 at 03:42:38 -;; Last-Mod: 10-Jul-26 at 17:16:28 by Bob Weiner +;; Last-Mod: 13-Jul-26 at 20:43:12 by Mats Lidell ;; ;; SPDX-License-Identifier: GPL-3.0-or-later ;; @@ -93,6 +93,11 @@ delimiter." :type 'sexp :group 'hyperbole-commands) +(defcustom hypb:ask-to-install-package-flag t + "Non-nil if user shall be queried before installing a package." + :type 'boolean + :group 'hyperbole-commands) + (defvar hypb:mail-address-mode-list '(fundamental-mode prog-mode text-mode) "List of major modes in which mail address implicit buttons are active. @@ -181,8 +186,7 @@ Uses the newer \"nadvice\" elisp library, not \"advice\"." This displays a clean log of Emacs keys used and commands executed." (interactive) ;; Ensure package is installed - (unless (package-installed-p 'interaction-log) - (package-install 'interaction-log)) + (hypb:require-package 'interaction-log) ;; Ensure interaction-log-mode is disabled to removes its command ;; hooks which are replaced below. @@ -1169,23 +1173,45 @@ WINDOW pixelwise." (string-join unreadable-dirs "\n")))) dirs) +(defun hypb:users-package-manager () + "Return the package manager in use. +Current supported package managers are `straight', `elpaca', and `package'." + (cond ((and (featurep 'straight) (fboundp 'straight-use-package)) 'straight) + ((and (featurep 'elpaca) (fboundp 'elpaca)) 'elpaca) + (t 'package))) + +(defun hypb:package-el-install (package) + "Install PACKAGE using the default package manager `package.el'. +If `hypb:ask-to-install-package-flag' is non-nil query user if package should +be installed." + (when (or (not hypb:ask-to-install-package-flag) + (y-or-n-p (format "Install `%s' to enable this feature? " package))) + (package-install package) + (require package))) + +(defun hypb:notify-manual-install-needed (package manager) + "Notify user that a manual install is needed for PACKAGE. +Suggest user to use the package MANAGER." + (user-error "Package '%s' is required by this command. Use your package manager '%s' to install it" package manager)) + +(defun hypb:ensure-dependency (package) + "Ensure PACKAGE is available. +Returns non-nil if the feature can be used." + (or (require package nil t) + (pcase (hypb:users-package-manager) + ('package (hypb:package-el-install package)) + (manager (hypb:notify-manual-install-needed package manager))))) + ;;;###autoload (defun hypb:require-package (package) - "Prompt user to install, if necessary, and require the Emacs PACKAGE-NAME. -PACKAGE-NAME may be a symbol or a string." + "Prompt user to install, if necessary, and require the Emacs PACKAGE. +PACKAGE may be a symbol or a string." (when (stringp package) (setq package (intern package))) (unless (symbolp package) (error "(hypb:require-package): package must be a symbol or string, not '%s'" package)) - (unless (or - ;; Allow for alternative package managers like elpaca that don't - ;; show up with a `package-installed-p' check - (require package nil t) - (package-installed-p package)) - (if (y-or-n-p (format "Install package `%s' required by this command?" package)) - (package-install package) - (keyboard-quit))) - (require package)) + (unless (hypb:ensure-dependency package) + (error "(hypb:require-package): package '%s' could not be found" package))) ;; Adapted from cl--do-remf in "cl-extra.el" but uses 'equal' for comparisons. ;;;###autoload diff --git a/hyrolo.el b/hyrolo.el index 3cba3864..07a719f3 100644 --- a/hyrolo.el +++ b/hyrolo.el @@ -3,7 +3,7 @@ ;; Author: Bob Weiner ;; ;; Orig-Date: 7-Jun-89 at 22:08:29 -;; Last-Mod: 13-Jun-26 at 13:33:38 by Bob Weiner +;; Last-Mod: 13-Jul-26 at 20:43:12 by Mats Lidell ;; ;; SPDX-License-Identifier: GPL-3.0-or-later ;; @@ -38,8 +38,6 @@ (require 'hsys-consult) (require 'hsys-org) ;; For `hsys-org-cycle-bob-file-list' (require 'hypb) ;; For `hypb:mail-address-regexp' and `hypb:add-to-invisibility-spec' -(eval-when-compile - `(hyrolo-install-markdown-mode)) (require 'outline) (require 'reveal) ;; Avoid any potential library name conflict by giving the load directory. @@ -3095,7 +3093,7 @@ package is not installed." package-archives) ;; 2. Skip this if the markdown-mode package is installed - (unless (package-installed-p 'markdown-mode) + (unless (require 'markdown-mode nil t) ;; 3. If any `hyrolo-file-list' file has a markdown file suffix, (when (delq nil (mapcar (lambda (suffix) (string-match-p (concat "\\(?:" hyrolo-markdown-suffix-regexp "\\)$") @@ -3231,13 +3229,17 @@ files to search." (defun hyrolo-install-markdown-mode () "Install `markdown-mode' package unless already installed." - (unless (package-installed-p 'markdown-mode) - (unless (assoc "nongnu" package-archives) - (setq package-archives (cl-copy-list package-archives)) - (add-to-list 'package-archives '("nongnu" . "https://elpa.nongnu.org/nongnu/") - t)) - (package-refresh-contents) - (package-install 'markdown-mode))) + (or (require 'markdown-mode nil t) + (pcase (hypb:users-package-manager) + ('package (when (or (not hypb:ask-to-install-package-flag) + (y-or-n-p (format "Install `%s' to enable this feature? " 'markdown-mode))) + (unless (assoc "nongnu" package-archives) + (setq package-archives (cl-copy-list package-archives)) + (add-to-list 'package-archives '("nongnu" . "https://elpa.nongnu.org/nongnu/") + t)) + (package-refresh-contents) + (package-install 'markdown-mode))) + (manager (hypb:notify-manual-install-needed 'markdown-mode manager))))) (defun hyrolo-isearch-for-regexp (regexp fold-search-flag) "Interactively search forward for the next occurrence of REGEXP. diff --git a/test/hy-test-dependencies.el b/test/hy-test-dependencies.el index 62959ed2..9aa2b967 100644 --- a/test/hy-test-dependencies.el +++ b/test/hy-test-dependencies.el @@ -3,7 +3,7 @@ ;; Author: Mats Lidell ;; ;; Orig-Date: 20-Feb-21 at 23:16:00 -;; Last-Mod: 14-Jul-26 at 09:39:15 by Bob Weiner +;; Last-Mod: 14-Jul-26 at 23:00:58 by Mats Lidell ;; ;; SPDX-License-Identifier: GPL-3.0-or-later ;; @@ -53,5 +53,9 @@ ;; Ignore publishing-related errors that don't affect the tests. (ignore-errors (hsys-org-log-and-fix-version)) +;; Allow dynamic loading with no questions asked of dependencies +;; i.e. markdown-mode +(setq hypb:ask-to-install-package-flag nil) + (provide 'hy-test-dependencies) ;;; hy-test-dependencies.el ends here