Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
2026-07-14 Mats Lidell <matsl@gnu.org>

* 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 <rsw@gnu.org>

* test/hy-test-dependencies.el: Add 'markdown-ts-mode' declaration.
Expand Down
10 changes: 3 additions & 7 deletions hsys-consult.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
;;
Expand Down Expand Up @@ -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")))
Expand Down Expand Up @@ -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
Expand Down
7 changes: 2 additions & 5 deletions hui-treemacs.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
;;
Expand All @@ -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)

Expand Down
54 changes: 40 additions & 14 deletions hypb.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
;;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add quelpa too.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I read up on quelpa and it seems it is based on top of package.el. Users can mix installing using quelpa and package.el directly. So it is not clear a user would prefer to install the packages we dynamically depend on using quelpa. So we can let package.el handle a potential install for quelpa users. It will not cause any big problem for them if I understand things correctly.

((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
Expand Down
24 changes: 13 additions & 11 deletions hyrolo.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
;;
Expand Down Expand Up @@ -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))
Comment thread
matsl marked this conversation as resolved.
(require 'outline)
(require 'reveal)
;; Avoid any potential library name conflict by giving the load directory.
Expand Down Expand Up @@ -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 "\\)$")
Expand Down Expand Up @@ -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)))))
Comment on lines +3232 to +3242

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is implemented on its own to allow the insertion of nongnu if that is missing only in the case where package.el is used. An alternative would be to do that either always or if package.el is in use and then call hypb:require-package. Seeing it now it might more sense to do like that. WDYT?


(defun hyrolo-isearch-for-regexp (regexp fold-search-flag)
"Interactively search forward for the next occurrence of REGEXP.
Expand Down
6 changes: 5 additions & 1 deletion test/hy-test-dependencies.el
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
;; Author: Mats Lidell <matsl@gnu.org>
;;
;; 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
;;
Expand Down Expand Up @@ -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