From b84865691c18c4d3c8eca0a595d55924ebb933b4 Mon Sep 17 00:00:00 2001 From: Mats Lidell Date: Fri, 10 Jul 2026 19:19:33 +0200 Subject: [PATCH 1/6] Make install check aware of alternative package managers * hypb.el (hypb:dependency-install-ask): 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. --- hypb.el | 51 +++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 12 deletions(-) diff --git a/hypb.el b/hypb.el index 2c34d3f8..8b179684 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: 11-Jul-26 at 14:36:06 by Mats Lidell ;; ;; SPDX-License-Identifier: GPL-3.0-or-later ;; @@ -93,6 +93,11 @@ delimiter." :type 'sexp :group 'hyperbole-commands) +(defcustom hypb:dependency-install-ask 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. @@ -1169,23 +1174,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 packet manager `package.el'. +If `hypb:dependency-install-ask' is non-nil query user if package should +be installed." + (when (or (not hypb:dependency-install-ask) + (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 From 1a09c2b021e66976e56d8b9f3f9769212328a07e Mon Sep 17 00:00:00 2001 From: Mats Lidell Date: Sun, 12 Jul 2026 17:37:44 +0200 Subject: [PATCH 2/6] Use hypb:require-package * 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): User require to check if markdown-mode is available. (hyrolo-install-markdown-mode): Copy hypb:ensure-dependency but add nongnu if is missing to package-archives before installation. --- hsys-consult.el | 10 +++------- hui-treemacs.el | 7 ++----- hypb.el | 5 ++--- hyrolo.el | 20 +++++++++++--------- 4 files changed, 18 insertions(+), 24 deletions(-) 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 8b179684..5bc61a36 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: 11-Jul-26 at 14:36:06 by Mats Lidell +;; Last-Mod: 12-Jul-26 at 00:06:03 by Mats Lidell ;; ;; SPDX-License-Identifier: GPL-3.0-or-later ;; @@ -186,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. diff --git a/hyrolo.el b/hyrolo.el index 3cba3864..f239ebae 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: 12-Jul-26 at 01:17:15 by Mats Lidell ;; ;; SPDX-License-Identifier: GPL-3.0-or-later ;; @@ -3095,7 +3095,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 +3231,15 @@ 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 (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. From 601858a60ccc4ba105d4ae0ef481d82b189ab655 Mon Sep 17 00:00:00 2001 From: Mats Lidell Date: Sun, 12 Jul 2026 22:05:42 +0200 Subject: [PATCH 3/6] Ask user before installing markdown-mode * hyrolo.el (hyrolo-install-markdown-mode): Ask user for install of markdown-mode. * test/hy-test-dependencies.el (hypb:dependency-install-ask): Set to nil for not asking about installing dynamic dependencies during test, i.e. markdown-mode. --- hyrolo.el | 18 +++++++++--------- test/hy-test-dependencies.el | 6 +++++- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/hyrolo.el b/hyrolo.el index f239ebae..9753e8eb 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: 12-Jul-26 at 01:17:15 by Mats Lidell +;; Last-Mod: 12-Jul-26 at 21:21:11 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. @@ -3233,12 +3231,14 @@ files to search." "Install `markdown-mode' package unless already installed." (or (require 'markdown-mode nil t) (pcase (hypb:users-package-manager) - ('package (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)) + ('package (when (or (not hypb:dependency-install-ask) + (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) diff --git a/test/hy-test-dependencies.el b/test/hy-test-dependencies.el index 62959ed2..ac1b3f73 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 22:59:31 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:dependency-install-ask nil) + (provide 'hy-test-dependencies) ;;; hy-test-dependencies.el ends here From 2209f3ff75adcc5c7981ed30062218e5d0476640 Mon Sep 17 00:00:00 2001 From: Mats Lidell Date: Sun, 12 Jul 2026 23:05:52 +0200 Subject: [PATCH 4/6] Add ChangeLog --- ChangeLog | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/ChangeLog b/ChangeLog index 5d1958a4..23b4046b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,26 @@ +2026-07-14 Mats Lidell + +* hyrolo.el (hyrolo-install-markdown-mode): Respect hypb:dependency-install-ask. +* test/hy-test-dependencies.el (hypb:dependency-install-ask): 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:dependency-install-ask): 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. From 2567d9e7287fe621f92ed3534c1d6556d0044161 Mon Sep 17 00:00:00 2001 From: Mats Lidell Date: Sun, 12 Jul 2026 23:07:53 +0200 Subject: [PATCH 5/6] Fix typo --- hypb.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hypb.el b/hypb.el index 5bc61a36..78f91940 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: 12-Jul-26 at 00:06:03 by Mats Lidell +;; Last-Mod: 12-Jul-26 at 23:07:23 by Mats Lidell ;; ;; SPDX-License-Identifier: GPL-3.0-or-later ;; @@ -1181,7 +1181,7 @@ Current supported package managers are `straight', `elpaca', and `package'." (t 'package))) (defun hypb:package-el-install (package) - "Install PACKAGE using the default packet manager `package.el'. + "Install PACKAGE using the default package manager `package.el'. If `hypb:dependency-install-ask' is non-nil query user if package should be installed." (when (or (not hypb:dependency-install-ask) From 27e61c31d93a69fccb4dd3d2a5349ef6a52f5668 Mon Sep 17 00:00:00 2001 From: Mats Lidell Date: Mon, 13 Jul 2026 20:43:52 +0200 Subject: [PATCH 6/6] Use name hypb:ask-to-install-package-flag --- ChangeLog | 6 +++--- hypb.el | 8 ++++---- hyrolo.el | 4 ++-- test/hy-test-dependencies.el | 4 ++-- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index 23b4046b..ef0b2aab 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,7 +1,7 @@ 2026-07-14 Mats Lidell -* hyrolo.el (hyrolo-install-markdown-mode): Respect hypb:dependency-install-ask. -* test/hy-test-dependencies.el (hypb:dependency-install-ask): Set to +* 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): @@ -12,7 +12,7 @@ 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:dependency-install-ask): Give user control if package +* 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. diff --git a/hypb.el b/hypb.el index 78f91940..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: 12-Jul-26 at 23:07:23 by Mats Lidell +;; Last-Mod: 13-Jul-26 at 20:43:12 by Mats Lidell ;; ;; SPDX-License-Identifier: GPL-3.0-or-later ;; @@ -93,7 +93,7 @@ delimiter." :type 'sexp :group 'hyperbole-commands) -(defcustom hypb:dependency-install-ask t +(defcustom hypb:ask-to-install-package-flag t "Non-nil if user shall be queried before installing a package." :type 'boolean :group 'hyperbole-commands) @@ -1182,9 +1182,9 @@ Current supported package managers are `straight', `elpaca', and `package'." (defun hypb:package-el-install (package) "Install PACKAGE using the default package manager `package.el'. -If `hypb:dependency-install-ask' is non-nil query user if package should +If `hypb:ask-to-install-package-flag' is non-nil query user if package should be installed." - (when (or (not hypb:dependency-install-ask) + (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))) diff --git a/hyrolo.el b/hyrolo.el index 9753e8eb..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: 12-Jul-26 at 21:21:11 by Mats Lidell +;; Last-Mod: 13-Jul-26 at 20:43:12 by Mats Lidell ;; ;; SPDX-License-Identifier: GPL-3.0-or-later ;; @@ -3231,7 +3231,7 @@ files to search." "Install `markdown-mode' package unless already installed." (or (require 'markdown-mode nil t) (pcase (hypb:users-package-manager) - ('package (when (or (not hypb:dependency-install-ask) + ('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)) diff --git a/test/hy-test-dependencies.el b/test/hy-test-dependencies.el index ac1b3f73..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 22:59:31 by Mats Lidell +;; Last-Mod: 14-Jul-26 at 23:00:58 by Mats Lidell ;; ;; SPDX-License-Identifier: GPL-3.0-or-later ;; @@ -55,7 +55,7 @@ ;; Allow dynamic loading with no questions asked of dependencies ;; i.e. markdown-mode -(setq hypb:dependency-install-ask nil) +(setq hypb:ask-to-install-package-flag nil) (provide 'hy-test-dependencies) ;;; hy-test-dependencies.el ends here