diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b2b0e40..add51ffd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how * fix(install): Package installed calculation (a479d5355dfc832286288b790338652e174d606d) * fix(install-file): Get correct install package name (#318) +* feat: Add `:try` for `depends-on` DSL (#319) ## 0.11.x > Released Apr 03, 2025 diff --git a/docs/content/DSL/_index.en.md b/docs/content/DSL/_index.en.md index afd72e6a..9d7c5c3c 100644 --- a/docs/content/DSL/_index.en.md +++ b/docs/content/DSL/_index.en.md @@ -165,6 +165,14 @@ Specify dependencies in **vc** format: (depends-on "lsp-ui" :vc "emacs-lsp/lsp-ui") ``` +Specify dependencies in **try** format: + +```elisp +(depends-on "auto-rename-tag" :try "https://raw.githubusercontent.com/emacs-vs/auto-rename-tag/refs/heads/master/auto-rename-tag.el") + +(depends-on "lsp-ui" :try) ; Try it, don't install it. +``` + Specify dependencies in **recipe** format: ```elisp diff --git a/docs/content/DSL/_index.zh-tw.md b/docs/content/DSL/_index.zh-tw.md index 4d6adcb2..8674dbe7 100644 --- a/docs/content/DSL/_index.zh-tw.md +++ b/docs/content/DSL/_index.zh-tw.md @@ -161,6 +161,14 @@ weight: 200 (depends-on "lsp-ui" :vc "emacs-lsp/lsp-ui") ``` +以 **try** 格式指定依賴項: + +```elisp +(depends-on "auto-rename-tag" :try "https://raw.githubusercontent.com/emacs-vs/auto-rename-tag/refs/heads/master/auto-rename-tag.el") + +(depends-on "lsp-ui" :try) ; 只有試看看, 不安裝. +``` + 以 **recipe** 格式指定依賴項: ```elisp diff --git a/lisp/_prepare.el b/lisp/_prepare.el index 514a5bbe..10bfd9e5 100644 --- a/lisp/_prepare.el +++ b/lisp/_prepare.el @@ -566,6 +566,10 @@ For arguments FUNC and DEPS, see function `mapc' for more information." ((memq :vc dep) (let ((spec (cdr (memq :vc dep)))) (eask-package-vc-install name spec))) + ;; Try out packages using `try'. + ((memq :try dep) + (let ((url-or-package (nth 2 dep))) + (eask-package-try name url-or-package))) ;; Fallback to archive install. (t (eask-package-install name))))) @@ -694,6 +698,23 @@ Argument BODY are forms for execution." "Return non-nil if package (PKG) is installable." (assq (eask-intern pkg) package-archive-contents)) +(defun eask-package-try (pkg &optional url-or-package) + "To try a package (PKG) without actually install it. + +The optional argument URL-OR-PACKAGE is used in the function `try'." + (eask-defvc< 27 (eask-pkg-init)) ; XXX: remove this after we drop 26.x + (eask-with-progress + (format " - %sTrying out %s%s... " eask--action-prefix + (ansi-green (eask-2str pkg)) + (if url-or-package + (concat " in " (ansi-yellow url-or-package)) + "")) + (eask-with-verbosity 'debug + (eask-archive-install-packages '("gnu" "melpa") 'try) + (require 'try) + (try (or url-or-package pkg))) + "done ✓")) + (defun eask-package-vc-install (pkg spec) "To vc install the package (PKG) by argument SPEC." (eask-defvc< 27 (eask-pkg-init)) ; XXX: remove this after we drop 26.x @@ -757,23 +778,24 @@ Argument BODY are forms for execution." (unless (eask-package-installable-p pkg) (eask-error "Package not installable `%s'; make sure the package archive (source) is included" pkg)))) (t - (eask-with-progress - (format " - %s%snstalling %s (%s)... " eask--action-prefix - (if should-reinstall-p "Rei" "I") - name version) - (eask-with-verbosity 'debug - ;; Handle `--force` flag. - (when should-reinstall-p (package-delete (eask-package-desc pkg t) t)) - ;; XXX: Without ignore-errors guard, it will trigger error - ;; - ;; Can't find library xxxxxxx.el - ;; - ;; But we can remove this after Emacs 28, since function `find-library-name' - ;; has replaced the function `signal' instead of the `error'. - ;; - ;; Install it. - (eask-ignore-errors (package-install pkg))) - "done ✓"))))) + (eask--pkg-process pkg ; Second call to force refresh the data. + (eask-with-progress + (format " - %s%snstalling %s (%s)... " eask--action-prefix + (if should-reinstall-p "Rei" "I") + name version) + (eask-with-verbosity 'debug + ;; Handle `--force` flag. + (when should-reinstall-p (package-delete (eask-package-desc pkg t) t)) + ;; XXX: Without ignore-errors guard, it will trigger error + ;; + ;; Can't find library xxxxxxx.el + ;; + ;; But we can remove this after Emacs 28, since function `find-library-name' + ;; has replaced the function `signal' instead of the `error'. + ;; + ;; Install it. + (eask-ignore-errors (package-install pkg))) + "done ✓")))))) (defun eask-package-delete (pkg) "Delete the package (PKG)." @@ -783,7 +805,7 @@ Argument BODY are forms for execution." ((not installed-p) (eask-msg " - %sSkipping %s (%s)... not installed ✗" eask--action-prefix name version)) (t - (eask--pkg-process pkg + (eask--pkg-process pkg ; Second call to force refresh the data. (eask-with-progress (format " - %sUninstalling %s (%s)... " eask--action-prefix name version) (eask-with-verbosity 'debug @@ -800,12 +822,13 @@ Argument BODY are forms for execution." (eask-msg " - %sSkipping %s (%s)... not installed ✗" eask--action-prefix name version)) (t (eask-pkg-init) - (eask-with-progress - (format " - %sReinstalling %s (%s)... " eask--action-prefix name version) - (eask-with-verbosity 'debug - (package-delete (eask-package-desc pkg t) t) - (eask-ignore-errors (package-install pkg))) - "done ✓"))))) + (eask--pkg-process pkg ; Second call to force refresh the data. + (eask-with-progress + (format " - %sReinstalling %s (%s)... " eask--action-prefix name version) + (eask-with-verbosity 'debug + (package-delete (eask-package-desc pkg t) t) + (eask-ignore-errors (package-install pkg))) + "done ✓")))))) (defun eask-package-desc (name &optional current) "Build package description by its NAME. @@ -1547,6 +1570,7 @@ argument COMMAND." "Setup dependencies list." (setq eask-depends-on (reverse eask-depends-on) eask-depends-on-dev (reverse eask-depends-on-dev)) + ;; On recipe (when eask-depends-on-recipe-p (eask-with-progress (format "✓ Checking local archives %s... " @@ -1593,22 +1617,18 @@ ELPA)." (eask-error "This requires Emacs %s and above!" minimum-version) (push recipe eask-depends-on-emacs)) recipe))) - ;; No argument specify - ((<= (length args) 1) - (let* ((minimum-version (car args)) - (recipe (list pkg minimum-version))) - (unless (eask--check-depends-on recipe) - (push recipe eask-depends-on)) - recipe)) - ;; File packages - ((memq :file args) + ;; Specified packages + ((or (memq :file args) ; File packages + (memq :vc args) ; VC packages + (memq :try args)) ; Try packages (let* ((recipe (append (list (intern pkg)) args))) (unless (eask--check-depends-on recipe) (push recipe eask-depends-on)) recipe)) - ;; VC packages - ((memq :vc args) - (let* ((recipe (append (list (intern pkg)) args))) + ;; No argument specify + ((<= (length args) 1) + (let* ((minimum-version (car args)) + (recipe (list pkg minimum-version))) (unless (eask--check-depends-on recipe) (push recipe eask-depends-on)) recipe)) diff --git a/lisp/core/info.el b/lisp/core/info.el index 4225098a..f844df9f 100644 --- a/lisp/core/info.el +++ b/lisp/core/info.el @@ -27,11 +27,12 @@ offset (eask-2str eask-info--max-offset)) (dolist (dep dependencies) (let* ((target-version (cdr dep)) - (target-version (cond ((= (length target-version) 1) + (target-version (cond ((memq :file dep) "file") + ((memq :vc dep) "vc") + ((memq :try dep) "try") + ((= (length target-version) 1) (or (nth 0 target-version) ; verison number "archive")) - ((memq :file dep) "file") - ((memq :vc dep) "vc") (t "recipe")))) (eask-println (concat " %-" offset "s (%s)") (car dep) target-version) (eask-debug " Recipe: %s" (car dep))))))) diff --git a/test/jest/install/Eask b/test/jest/install/Eask index 8f132288..2f93335f 100644 --- a/test/jest/install/Eask +++ b/test/jest/install/Eask @@ -37,6 +37,10 @@ ;;(depends-on "msgu" :vc "https://github.com/jcs-elpa/msgu") ) +;; Try out +(depends-on "indent-control" :try) +(depends-on "auto-rename-tag" :try "https://raw.githubusercontent.com/emacs-vs/auto-rename-tag/refs/heads/master/auto-rename-tag.el") + ;; Recipe install (depends-on "watch-cursor" :repo "jcs-elpa/watch-cursor" :fetcher 'github)