Skip to content

Commit e501793

Browse files
authored
feat: Add :try for depends-on DSL (#319)
* feat: Add :try for depends-pon * docs: changelog * test: Add future test references * typo * docs: should use url instead * fix: better integrate try * feat: Add try test
1 parent 77688a3 commit e501793

File tree

6 files changed

+81
-39
lines changed

6 files changed

+81
-39
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
1010
1111
* fix(install): Package installed calculation (a479d5355dfc832286288b790338652e174d606d)
1212
* fix(install-file): Get correct install package name (#318)
13+
* feat: Add `:try` for `depends-on` DSL (#319)
1314

1415
## 0.11.x
1516
> Released Apr 03, 2025

docs/content/DSL/_index.en.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,14 @@ Specify dependencies in **vc** format:
165165
(depends-on "lsp-ui" :vc "emacs-lsp/lsp-ui")
166166
```
167167

168+
Specify dependencies in **try** format:
169+
170+
```elisp
171+
(depends-on "auto-rename-tag" :try "https://raw.githubusercontent.com/emacs-vs/auto-rename-tag/refs/heads/master/auto-rename-tag.el")
172+
173+
(depends-on "lsp-ui" :try) ; Try it, don't install it.
174+
```
175+
168176
Specify dependencies in **recipe** format:
169177

170178
```elisp

docs/content/DSL/_index.zh-tw.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,14 @@ weight: 200
161161
(depends-on "lsp-ui" :vc "emacs-lsp/lsp-ui")
162162
```
163163

164+
**try** 格式指定依賴項:
165+
166+
```elisp
167+
(depends-on "auto-rename-tag" :try "https://raw.githubusercontent.com/emacs-vs/auto-rename-tag/refs/heads/master/auto-rename-tag.el")
168+
169+
(depends-on "lsp-ui" :try) ; 只有試看看, 不安裝.
170+
```
171+
164172
**recipe** 格式指定依賴項:
165173

166174
```elisp

lisp/_prepare.el

Lines changed: 56 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,10 @@ For arguments FUNC and DEPS, see function `mapc' for more information."
566566
((memq :vc dep)
567567
(let ((spec (cdr (memq :vc dep))))
568568
(eask-package-vc-install name spec)))
569+
;; Try out packages using `try'.
570+
((memq :try dep)
571+
(let ((url-or-package (nth 2 dep)))
572+
(eask-package-try name url-or-package)))
569573
;; Fallback to archive install.
570574
(t (eask-package-install name)))))
571575

@@ -694,6 +698,23 @@ Argument BODY are forms for execution."
694698
"Return non-nil if package (PKG) is installable."
695699
(assq (eask-intern pkg) package-archive-contents))
696700

701+
(defun eask-package-try (pkg &optional url-or-package)
702+
"To try a package (PKG) without actually install it.
703+
704+
The optional argument URL-OR-PACKAGE is used in the function `try'."
705+
(eask-defvc< 27 (eask-pkg-init)) ; XXX: remove this after we drop 26.x
706+
(eask-with-progress
707+
(format " - %sTrying out %s%s... " eask--action-prefix
708+
(ansi-green (eask-2str pkg))
709+
(if url-or-package
710+
(concat " in " (ansi-yellow url-or-package))
711+
""))
712+
(eask-with-verbosity 'debug
713+
(eask-archive-install-packages '("gnu" "melpa") 'try)
714+
(require 'try)
715+
(try (or url-or-package pkg)))
716+
"done ✓"))
717+
697718
(defun eask-package-vc-install (pkg spec)
698719
"To vc install the package (PKG) by argument SPEC."
699720
(eask-defvc< 27 (eask-pkg-init)) ; XXX: remove this after we drop 26.x
@@ -757,23 +778,24 @@ Argument BODY are forms for execution."
757778
(unless (eask-package-installable-p pkg)
758779
(eask-error "Package not installable `%s'; make sure the package archive (source) is included" pkg))))
759780
(t
760-
(eask-with-progress
761-
(format " - %s%snstalling %s (%s)... " eask--action-prefix
762-
(if should-reinstall-p "Rei" "I")
763-
name version)
764-
(eask-with-verbosity 'debug
765-
;; Handle `--force` flag.
766-
(when should-reinstall-p (package-delete (eask-package-desc pkg t) t))
767-
;; XXX: Without ignore-errors guard, it will trigger error
768-
;;
769-
;; Can't find library xxxxxxx.el
770-
;;
771-
;; But we can remove this after Emacs 28, since function `find-library-name'
772-
;; has replaced the function `signal' instead of the `error'.
773-
;;
774-
;; Install it.
775-
(eask-ignore-errors (package-install pkg)))
776-
"done ✓")))))
781+
(eask--pkg-process pkg ; Second call to force refresh the data.
782+
(eask-with-progress
783+
(format " - %s%snstalling %s (%s)... " eask--action-prefix
784+
(if should-reinstall-p "Rei" "I")
785+
name version)
786+
(eask-with-verbosity 'debug
787+
;; Handle `--force` flag.
788+
(when should-reinstall-p (package-delete (eask-package-desc pkg t) t))
789+
;; XXX: Without ignore-errors guard, it will trigger error
790+
;;
791+
;; Can't find library xxxxxxx.el
792+
;;
793+
;; But we can remove this after Emacs 28, since function `find-library-name'
794+
;; has replaced the function `signal' instead of the `error'.
795+
;;
796+
;; Install it.
797+
(eask-ignore-errors (package-install pkg)))
798+
"done ✓"))))))
777799

778800
(defun eask-package-delete (pkg)
779801
"Delete the package (PKG)."
@@ -783,7 +805,7 @@ Argument BODY are forms for execution."
783805
((not installed-p)
784806
(eask-msg " - %sSkipping %s (%s)... not installed ✗" eask--action-prefix name version))
785807
(t
786-
(eask--pkg-process pkg
808+
(eask--pkg-process pkg ; Second call to force refresh the data.
787809
(eask-with-progress
788810
(format " - %sUninstalling %s (%s)... " eask--action-prefix name version)
789811
(eask-with-verbosity 'debug
@@ -800,12 +822,13 @@ Argument BODY are forms for execution."
800822
(eask-msg " - %sSkipping %s (%s)... not installed ✗" eask--action-prefix name version))
801823
(t
802824
(eask-pkg-init)
803-
(eask-with-progress
804-
(format " - %sReinstalling %s (%s)... " eask--action-prefix name version)
805-
(eask-with-verbosity 'debug
806-
(package-delete (eask-package-desc pkg t) t)
807-
(eask-ignore-errors (package-install pkg)))
808-
"done ✓")))))
825+
(eask--pkg-process pkg ; Second call to force refresh the data.
826+
(eask-with-progress
827+
(format " - %sReinstalling %s (%s)... " eask--action-prefix name version)
828+
(eask-with-verbosity 'debug
829+
(package-delete (eask-package-desc pkg t) t)
830+
(eask-ignore-errors (package-install pkg)))
831+
"done ✓"))))))
809832

810833
(defun eask-package-desc (name &optional current)
811834
"Build package description by its NAME.
@@ -1547,6 +1570,7 @@ argument COMMAND."
15471570
"Setup dependencies list."
15481571
(setq eask-depends-on (reverse eask-depends-on)
15491572
eask-depends-on-dev (reverse eask-depends-on-dev))
1573+
;; On recipe
15501574
(when eask-depends-on-recipe-p
15511575
(eask-with-progress
15521576
(format "✓ Checking local archives %s... "
@@ -1593,22 +1617,18 @@ ELPA)."
15931617
(eask-error "This requires Emacs %s and above!" minimum-version)
15941618
(push recipe eask-depends-on-emacs))
15951619
recipe)))
1596-
;; No argument specify
1597-
((<= (length args) 1)
1598-
(let* ((minimum-version (car args))
1599-
(recipe (list pkg minimum-version)))
1600-
(unless (eask--check-depends-on recipe)
1601-
(push recipe eask-depends-on))
1602-
recipe))
1603-
;; File packages
1604-
((memq :file args)
1620+
;; Specified packages
1621+
((or (memq :file args) ; File packages
1622+
(memq :vc args) ; VC packages
1623+
(memq :try args)) ; Try packages
16051624
(let* ((recipe (append (list (intern pkg)) args)))
16061625
(unless (eask--check-depends-on recipe)
16071626
(push recipe eask-depends-on))
16081627
recipe))
1609-
;; VC packages
1610-
((memq :vc args)
1611-
(let* ((recipe (append (list (intern pkg)) args)))
1628+
;; No argument specify
1629+
((<= (length args) 1)
1630+
(let* ((minimum-version (car args))
1631+
(recipe (list pkg minimum-version)))
16121632
(unless (eask--check-depends-on recipe)
16131633
(push recipe eask-depends-on))
16141634
recipe))

lisp/core/info.el

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,12 @@
2727
offset (eask-2str eask-info--max-offset))
2828
(dolist (dep dependencies)
2929
(let* ((target-version (cdr dep))
30-
(target-version (cond ((= (length target-version) 1)
30+
(target-version (cond ((memq :file dep) "file")
31+
((memq :vc dep) "vc")
32+
((memq :try dep) "try")
33+
((= (length target-version) 1)
3134
(or (nth 0 target-version) ; verison number
3235
"archive"))
33-
((memq :file dep) "file")
34-
((memq :vc dep) "vc")
3536
(t "recipe"))))
3637
(eask-println (concat " %-" offset "s (%s)") (car dep) target-version)
3738
(eask-debug " Recipe: %s" (car dep)))))))

test/jest/install/Eask

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@
3737
;;(depends-on "msgu" :vc "https://github.com/jcs-elpa/msgu")
3838
)
3939

40+
;; Try out
41+
(depends-on "indent-control" :try)
42+
(depends-on "auto-rename-tag" :try "https://raw.githubusercontent.com/emacs-vs/auto-rename-tag/refs/heads/master/auto-rename-tag.el")
43+
4044
;; Recipe install
4145
(depends-on "watch-cursor"
4246
:repo "jcs-elpa/watch-cursor" :fetcher 'github)

0 commit comments

Comments
 (0)