diff --git a/CHANGELOG.md b/CHANGELOG.md index e17944a7..25bda41f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how * Adapt `-a`/`--all` option for archives command (#83) * Merge command `list-all` to list with `-a`/`--all` option (#84) * Support JSON format with Eask-file linter (#85) +* Add priority as the 3rd argument to source alias (#78) ## 0.7.x > Released Sep 08, 2022 diff --git a/docs/content/en/DSL/_index.md b/docs/content/en/DSL/_index.md index 1205ce7a..db86c64c 100644 --- a/docs/content/en/DSL/_index.md +++ b/docs/content/en/DSL/_index.md @@ -69,15 +69,15 @@ scripts. # 🚩 Dependencies -## 🔍 **source** (`alias`) - -## 🔍 **source** (`name` `url`) +## 🔍 **source** (`alias-or-name` &optional `url` `priority`) Add a package archive to install dependencies from. ```elisp (source "gnu") (source "gnu" "https://elpa.gnu.org/packages/") +(source "gnu" "https://elpa.gnu.org/packages/" 10) +(source "gnu" nil 10) ``` Available aliases: @@ -96,14 +96,6 @@ Available aliases: 💡 Use **--insecure** to make **https** to **http**, but not recommended {{< /hint >}} -## 🔍 **source-priority** (`name` `priority`) - -Set archive priority. - -```elisp -(source-priority "gnu" 5) -``` - ## 🔍 **depends-on** (`package-name` `&optional minimum-version`) ## 🔍 **depends-on** (`package-name` `&rest recipe`) diff --git a/docs/content/en/Development API/_index.md b/docs/content/en/Development API/_index.md index acef0982..68edd1e9 100644 --- a/docs/content/en/Development API/_index.md +++ b/docs/content/en/Development API/_index.md @@ -440,14 +440,10 @@ Alias of `files`. Alias of `script`. -## 🔍 Function: eask-f-source (`name` &optional `location`) +## 🔍 Function: eask-f-source (`name` &optional `location` `priority`) Alias of `source`. -## 🔍 Function: eask-f-source-priority (`name` &optional `priority`) - -Alias of `source-priority`. - ## 🔍 Function: eask-f-depends-on (`pkg` &rest `args`) Alias of `depends-on`. diff --git a/lisp/_prepare.el b/lisp/_prepare.el index beb56c8c..cb589bb1 100644 --- a/lisp/_prepare.el +++ b/lisp/_prepare.el @@ -556,7 +556,7 @@ other scripts internally. See function `eask-call'.") '("package" "website-url" "keywords" "package-file" "files" "script" - "source" "source-priority" + "source" "depends-on" "development" "exec-paths" "load-paths") "List of Eask file keywords.") @@ -786,21 +786,32 @@ Eask file in the workspace." (mapconcat #'identity (append (list command) args) " ")) eask-scripts)) -(defun eask-f-source (name &optional location) - "Add archive NAME with LOCATION." +(defun eask-f-source (name &optional location priority) + "Add archive NAME alias. + +If LOCATION is a URL string, replace the default URL from `eask-source-mapping' +to it's value. Optional argument PRIORITY can be use to register to variable +`package-archive-priorities'. + +If LOCATION is a number, it will be treated like PRIORITY. When both optional +arguments LOCATION and PRIORITY are defined in number, then we will respect the +latter one." (when (assoc name package-archives) (eask-error "Multiple definition of source `%s'" name)) - (setq location (or location (cdr (assq (intern name) eask-source-mapping)))) + (let ((default-location (cdr (assq (intern name) eask-source-mapping)))) + (cond ((numberp location) + (setq priority (or priority location) ; still respect priority + location default-location)) + (t + (setq location (or location default-location))))) (unless location (eask-error "Unknown package archive `%s'" name)) (when (and location (gnutls-available-p) (not (eask-network-insecure-p))) (setq location (s-replace "https://" "http://" location))) - (add-to-list 'package-archives (cons name location) t)) - -(defun eask-f-source-priority (archive-id &optional priority) - "Add PRIORITY for to ARCHIVE-ID." - (add-to-list 'package-archive-priorities (cons archive-id priority) t)) + (add-to-list 'package-archives (cons name location) t) + (when priority + (add-to-list 'package-archive-priorities (cons name priority) t))) (defvar eask-depends-on-recipe-p nil "Set to t if package depends on recipe.")