Skip to content

Commit 9fa52f2

Browse files
authored
test: Fix no package error for foo-mode and foo-no-pkg (#323)
* test: Fix no package error for foo-mode and foo-no-pkg * feat: Rename and clean up * chore: Improve warning messages * chore: Improve warning messages 2 * fix: analyze test * ci: leave only one tar test * use no color * fix: coloring issue * fix function name * temporary disable workflwos * fix 1 * test: mark skip * fix ci 2 * revert test * use built-in control seq
1 parent 4b02dad commit 9fa52f2

File tree

20 files changed

+190
-167
lines changed

20 files changed

+190
-167
lines changed

.github/workflows/deprecated/.gitkeep

Whitespace-only changes.

.github/workflows/disabled/.gitkeep

Whitespace-only changes.

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
1515
* fix(extern): Avoid patching compat functions (524c02dc66e14449f8511d5cfc591e4fae91b3b2)
1616
* feat(_prepare.el): Respect global/system-wide packages (e0732f26a179ccceed96528cc71d9903b2f5fe4e)
1717
* fix(lisp/extern): Clean up `compat` (2b41f5db4b5bbe145c9671f95850f79a00dcbd48)
18+
* fix(lisp): Paint keywords with nested ansi codes (#323)
1819

1920
## 0.11.x
2021
> Released Apr 03, 2025

lisp/_prepare.el

Lines changed: 86 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,32 @@ and INHERIT-INPUT-METHOD see function `read-string' for more information."
381381
(declare (indent 0) (debug t))
382382
`(eask-with-buffer (erase-buffer) ,@body))
383383

384+
(defun eask-re-seq (regexp string)
385+
"Get a list of all REGEXP matches in a STRING."
386+
(save-match-data
387+
(let ((pos 0)
388+
matches)
389+
(while (string-match regexp string pos)
390+
(push (match-string 0 string) matches)
391+
(setq pos (match-end 0)))
392+
(reverse matches))))
393+
394+
(defun eask-ansi-codes (s)
395+
"Return a list of ansi codes from S."
396+
(eask-re-seq ansi-color-control-seq-regexp s))
397+
398+
(defun eask-s-replace-ansi (old new s)
399+
"Like the function `eask-s-replace' but work with ansi.
400+
401+
For arguments OLD, NEW and S; see the function `eask-s-replace'
402+
for more information."
403+
(if-let* ((data (eask-ansi-codes s))
404+
(start (nth 1 data))
405+
(end (nth 0 data))
406+
(splits (split-string s (regexp-quote old))))
407+
(mapconcat #'identity splits (concat start new end))
408+
(eask-s-replace old new s)))
409+
384410
;;
385411
;;; Progress
386412

@@ -1468,7 +1494,7 @@ This uses function `locate-dominating-file' to look up directory tree."
14681494
Argument NAME is the name of the package. VERSION is the string contains valid
14691495
version number. DESCRIPTION is the package description."
14701496
(if eask-package
1471-
(eask-error "Multiple definition of `package'")
1497+
(eask-error "Multiple definition of `package'")
14721498
(setq eask-package `(:name ,name :version ,version :description ,description))
14731499
(progn ; Run checker
14741500
(eask--checker-string "Name" name)
@@ -1478,28 +1504,28 @@ version number. DESCRIPTION is the package description."
14781504
(defun eask-f-website-url (url)
14791505
"Set website URL."
14801506
(if eask-website-url
1481-
(eask-error "Multiple definition of `website-url'")
1507+
(eask-error "Multiple definition of `website-url'")
14821508
(setq eask-website-url url)))
14831509

14841510
(defun eask-f-keywords (&rest keywords)
14851511
"Set package KEYWORDS."
14861512
(if eask-keywords
1487-
(eask-error "Multiple definition of `keywords'")
1513+
(eask-error "Multiple definition of `keywords'")
14881514
(setq eask-keywords keywords)))
14891515

14901516
(defun eask-f-author (name &optional email)
14911517
"Set package author's NAME and EMAIL."
14921518
(if (member name (mapcar #'car eask-authors))
1493-
(eask-warn "Warning regarding duplicate author name, %s" name)
1519+
(eask-warn "💡 Warning regarding duplicate author name, %s" name)
14941520
(when (and email
14951521
(not (string-match-p "@" email)))
1496-
(eask-warn "Email seems to be invalid, %s" email))
1522+
(eask-warn "💡 Email seems to be invalid, %s" email))
14971523
(push (cons name email) eask-authors)))
14981524

14991525
(defun eask-f-license (name)
15001526
"Set package license NAME."
15011527
(if (member name eask-licenses)
1502-
(eask-warn "Warning regarding duplicate license name, %s" name)
1528+
(eask-warn "💡 Warning regarding duplicate license name, %s" name)
15031529
(push name eask-licenses)))
15041530

15051531
(defun eask--try-construct-package-desc (file)
@@ -1526,11 +1552,11 @@ version number. DESCRIPTION is the package description."
15261552
(defun eask-f-package-file (file)
15271553
"Set package FILE."
15281554
(if eask-package-file
1529-
(eask-error "Multiple definition of `package-file'")
1555+
(eask-error "Multiple definition of `package-file'")
15301556
(setq eask-package-file (expand-file-name file))
15311557
(if (file-exists-p eask-package-file)
15321558
(eask--try-construct-package-desc eask-package-file)
1533-
(eask-warn "Package-file seems to be missing `%s'" file))
1559+
(eask-warn "💡 Package-file seems to be missing `%s'" file))
15341560
(when-let*
15351561
(((and (not eask-package-descriptor) ; prevent multiple definition error
15361562
(not eask-package-desc))) ; check if constructed
@@ -1543,16 +1569,16 @@ version number. DESCRIPTION is the package description."
15431569
"Set package PKG-FILE."
15441570
(cond
15451571
(eask-package-descriptor
1546-
(eask-error "Multiple definition of `package-descriptor'"))
1572+
(eask-error "Multiple definition of `package-descriptor'"))
15471573
((and eask-package-desc ; check if construct successfully
15481574
(equal (eask-pkg-el) pkg-file)) ; check filename the same
15491575
) ; ignore
15501576
(t
15511577
(setq eask-package-descriptor (expand-file-name pkg-file))
15521578
(cond ((not (string-suffix-p "-pkg.el" eask-package-descriptor))
1553-
(eask-error "Pkg-file must end with `-pkg.el'"))
1579+
(eask-error "Pkg-file must end with `-pkg.el'"))
15541580
((not (file-exists-p eask-package-descriptor))
1555-
(eask-warn "Pkg-file seems to be missing `%s'" pkg-file))
1581+
(eask-warn "💡 Pkg-file seems to be missing `%s'" pkg-file))
15561582
(t
15571583
(eask--try-construct-package-desc eask-package-descriptor))))))
15581584

@@ -1569,7 +1595,7 @@ contains extra shell commands, and it will eventually be concatenate with the
15691595
argument COMMAND."
15701596
(when (symbolp name) (setq name (eask-2str name))) ; ensure to string, accept symbol
15711597
(when (assoc name eask-scripts)
1572-
(eask-error "Run-script with the same key name is not allowed: `%s`" name))
1598+
(eask-error "Run-script with the same key name is not allowed: `%s`" name))
15731599
(push (cons name
15741600
(mapconcat #'identity (append (list command) args) " "))
15751601
eask-scripts))
@@ -1579,12 +1605,12 @@ argument COMMAND."
15791605
(when (symbolp name) (setq name (eask-2str name))) ; ensure to string, accept symbol
15801606
;; Handle local archive.
15811607
(when (equal name eask--local-archive-name)
1582-
(eask-error "Invalid archive name `%s'" name))
1608+
(eask-error "Invalid archive name `%s'" name))
15831609
;; Handle multiple same archive name!
15841610
(when (assoc name package-archives)
1585-
(eask-error "Multiple definition of source `%s'" name))
1611+
(eask-error "Multiple definition of source `%s'" name))
15861612
(setq location (eask-source-url name location))
1587-
(unless location (eask-error "Unknown package archive `%s'" name))
1613+
(unless location (eask-error "Unknown package archive `%s'" name))
15881614
(add-to-list 'package-archives (cons name location) t))
15891615

15901616
(defun eask-f-source-priority (name &optional priority)
@@ -1627,11 +1653,11 @@ argument COMMAND."
16271653
(let ((pkg (car recipe))
16281654
(minimum-version (cdr recipe)))
16291655
(cond ((member recipe eask-depends-on)
1630-
(eask-error "Define dependencies with the same name `%s'" pkg))
1656+
(eask-error "Define dependencies with the same name `%s'" pkg))
16311657
((cl-some (lambda (rcp)
16321658
(string= (car rcp) pkg))
16331659
eask-depends-on)
1634-
(eask-error "Define dependencies with the same name `%s' with different version" pkg)))))
1660+
(eask-error "Define dependencies with the same name `%s' with different version" pkg)))))
16351661

16361662
(defun eask-f-depends-on (pkg &rest args)
16371663
"Specify a dependency (PKG) of this package.
@@ -1642,11 +1668,11 @@ ELPA)."
16421668
(cond
16431669
((string= pkg "emacs")
16441670
(if eask-depends-on-emacs
1645-
(eask-error "Define dependencies with the same name `%s'" pkg)
1671+
(eask-error "Define dependencies with the same name `%s'" pkg)
16461672
(let* ((minimum-version (car args))
16471673
(recipe (list pkg minimum-version)))
16481674
(if (version< emacs-version minimum-version)
1649-
(eask-error "This requires Emacs %s and above!" minimum-version)
1675+
(eask-error "This requires Emacs %s and above!" minimum-version)
16501676
(push recipe eask-depends-on-emacs))
16511677
recipe)))
16521678
;; Specified packages
@@ -1803,33 +1829,33 @@ detials."
18031829
"Send error message; see function `eask--msg' for arguments MSG and ARGS."
18041830
(apply #'eask--msg 'error "[ERROR]" msg args))
18051831

1806-
(defun eask--msg-paint-kwds (string)
1807-
"Paint keywords from STRING."
1808-
(let* ((string (eask-s-replace "" (ansi-green "") string))
1809-
(string (eask-s-replace "" (ansi-red "") string))
1810-
(string (eask-s-replace "💡" (ansi-yellow "💡") string)))
1811-
string))
1812-
1813-
(defun eask--msg-char-displayable (char replacement string)
1814-
"Ensure CHAR is displayable in STRING; if not, we fallback to REPLACEMENT
1832+
(defun eask--msg-char-displayable (char replacement s)
1833+
"Ensure CHAR is displayable in S; if not, we fallback to REPLACEMENT
18151834
character."
18161835
(if (char-displayable-p (string-to-char char))
1817-
string
1818-
(eask-s-replace char replacement string)))
1819-
1820-
(defun eask--msg-displayable-kwds (string)
1821-
"Make sure all keywords is displayable in STRING."
1822-
(let* ((string (eask--msg-char-displayable "" "v" string))
1823-
(string (eask--msg-char-displayable "" "X" string))
1824-
(string (eask--msg-char-displayable "💡" "<?>" string)))
1825-
string))
1836+
s
1837+
(eask-s-replace char replacement s)))
1838+
1839+
(defun eask--msg-displayable-kwds (s)
1840+
"Make sure all keywords is displayable in S."
1841+
(let* ((s (eask--msg-char-displayable "" "v" s))
1842+
(s (eask--msg-char-displayable "" "X" s))
1843+
(s (eask--msg-char-displayable "💡" "<?>" s)))
1844+
s))
1845+
1846+
(defun eask--msg-paint-kwds (s)
1847+
"Paint keywords from S."
1848+
(let* ((s (eask-s-replace-ansi "" (ansi-green "") s))
1849+
(s (eask-s-replace-ansi "" (ansi-red "") s))
1850+
(s (eask-s-replace-ansi "💡" (ansi-yellow "💡") s)))
1851+
s))
18261852

18271853
(defun eask--format-paint-kwds (msg &rest args)
18281854
"Paint keywords after format MSG and ARGS."
1829-
(let* ((string (apply #'format msg args))
1830-
(string (eask--msg-paint-kwds string))
1831-
(string (eask--msg-displayable-kwds string)))
1832-
string))
1855+
(let* ((s (apply #'format msg args))
1856+
(s (eask--msg-paint-kwds s))
1857+
(s (eask--msg-displayable-kwds s)))
1858+
s))
18331859

18341860
(defun eask-princ (object &optional stderr)
18351861
"Like function `princ'; with flag STDERR.
@@ -2070,14 +2096,17 @@ would send exit code of `1'."
20702096
(cond ((numberp print-or-exit-code)
20712097
(eask--exit print-or-exit-code))
20722098
(t ))) ; Don't exit with anything else.
2073-
(eask-error "Help manual missing %s" help-file))))
2099+
(eask-error "Help manual missing `%s`" help-file))))
20742100

20752101
;;
20762102
;;; Checker
20772103

20782104
(defun eask--checker-existence ()
20792105
"Return errors if required metadata is missing."
2080-
(unless eask-package (eask-error "Missing metadata package; make sure you have created an Eask-file with $ eask init!")))
2106+
(unless eask-package
2107+
(eask-error
2108+
(concat "✗ Missing metadata package; make sure you have created "
2109+
"an Eask-file with `$ eask init`!"))))
20812110

20822111
(defun eask--check-strings (fmt f p &rest args)
20832112
"Test strings (F and P); then print FMT and ARGS if not equal."
@@ -2100,46 +2129,46 @@ Arguments MSG1, MSG2, MSG3 and MSG4 are conditional messages."
21002129
(when-let* (((and eask-package eask-package-desc))
21012130
(def-point (if (eask-pkg-el) "-pkg.el file" "package-file")))
21022131
(eask--check-strings
2103-
"Unmatched package name `%s`; it should be `%s`"
2132+
"💡 Unmatched package name `%s`; it should be `%s`"
21042133
(eask-package-name) (package-desc-name eask-package-desc))
21052134
(when-let* ((ver-eask (eask-package-version))
21062135
(ver-pkg (package-desc-version eask-package-desc))
21072136
;; `package-version-join' returns only one of the possible
21082137
;; inverses, since `version-to-list' is a many-to-one operation
21092138
((not (equal (version-to-list ver-eask) ver-pkg))))
21102139
(eask--check-strings
2111-
"Unmatched version `%s`; it should be `%s`"
2140+
"💡 Unmatched version `%s`; it should be `%s`"
21122141
ver-eask (package-version-join ver-pkg)))
21132142
(eask--check-strings
2114-
"Unmatched summary `%s`; it should be `%s`"
2143+
"💡 Unmatched summary `%s`; it should be `%s`"
21152144
(eask-package-description) (package-desc-summary eask-package-desc))
21162145
(let ((url (eask-package-desc-url)))
21172146
(eask--check-optional
21182147
eask-website-url url
2119-
"Unmatched website URL `%s`; it should be `%s`"
2120-
(format "Unmatched website URL `%s`; add `%s` to %s" eask-website-url
2148+
"💡 Unmatched website URL `%s`; it should be `%s`"
2149+
(format "💡 Unmatched website URL `%s`; add `%s` to %s" eask-website-url
21212150
(if (string-prefix-p "-pkg.el" def-point)
21222151
(format ":url \"%s\"" eask-website-url)
21232152
(format ";; URL: %s" eask-website-url))
21242153
def-point)
2125-
(format "Unmatched website URL `%s`; add `(website-url \"%s\")` to Eask-file" url url)
2126-
(format "URL header is optional, but it's often recommended")))
2154+
(format "💡 Unmatched website URL `%s`; add `(website-url \"%s\")` to Eask-file" url url)
2155+
(format "💡 URL header is optional, but it's often recommended")))
21272156
(let ((keywords (eask-package-desc-keywords)))
21282157
(cond
21292158
((or keywords eask-keywords)
21302159
(dolist (keyword keywords)
21312160
(unless (member keyword eask-keywords)
2132-
(eask-warn "Unmatched keyword `%s`; add `(keywords \"%s\")` to Eask-file or consider removing it" keyword keyword)))
2161+
(eask-warn "💡 Unmatched keyword `%s`; add `(keywords \"%s\")` to Eask-file or consider removing it" keyword keyword)))
21332162
(dolist (keyword eask-keywords)
21342163
(unless (member keyword keywords)
2135-
(eask-warn "Unmatched keyword `%s`; add `%s` to %s or consider removing it"
2164+
(eask-warn "💡 Unmatched keyword `%s`; add `%s` to %s or consider removing it"
21362165
keyword
21372166
(if (string-prefix-p "-pkg.el" def-point)
21382167
(format ":keywords '(\"%s\")" keyword)
21392168
(format ";; Keywords: %s" keyword))
21402169
def-point))))
21412170
(t
2142-
(eask-warn "Keywords header is optional, but it's often recommended"))))
2171+
(eask-warn "💡 Keywords header is optional, but it's often recommended"))))
21432172
(let* ((dependencies (append eask-depends-on-emacs eask-depends-on))
21442173
(dependencies (mapcar #'car dependencies))
21452174
(dependencies (mapcar (lambda (elm) (eask-2str elm)) dependencies))
@@ -2148,10 +2177,10 @@ Arguments MSG1, MSG2, MSG3 and MSG4 are conditional messages."
21482177
(requirements (mapcar (lambda (elm) (eask-2str elm)) requirements)))
21492178
(dolist (req requirements)
21502179
(unless (member req dependencies)
2151-
(eask-warn "Unmatched dependency `%s`; add `(depends-on \"%s\")` to Eask-file or consider removing it" req req)))
2180+
(eask-warn "💡 Unmatched dependency `%s`; add `(depends-on \"%s\")` to Eask-file or consider removing it" req req)))
21522181
(dolist (dep dependencies)
21532182
(unless (member dep requirements)
2154-
(eask-warn "Unmatched dependency `%s`; add `(%s \"VERSION\")` to %s or consider removing it" dep dep def-point))))))
2183+
(eask-warn "💡 Unmatched dependency `%s`; add `(%s \"VERSION\")` to %s or consider removing it" dep dep def-point))))))
21552184

21562185
(add-hook 'eask-file-loaded-hook #'eask--checker-existence)
21572186
(add-hook 'eask-file-loaded-hook #'eask--checker-metadata)
@@ -2162,9 +2191,9 @@ Arguments MSG1, MSG2, MSG3 and MSG4 are conditional messages."
21622191
Argument NAME represent the name of that package's metadata. VAR is the actual
21632192
variable we use to test validation."
21642193
(unless (stringp var)
2165-
(eask-error "%s must be a string" name))
2194+
(eask-error "%s must be a string" name))
21662195
(when (string-empty-p var)
2167-
(eask-warn "%s cannot be an empty string" name)))
2196+
(eask-warn "💡 %s cannot be an empty string" name)))
21682197

21692198
;;
21702199
;;; User customization

lisp/core/install-file.el

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -24,35 +24,39 @@
2424

2525
(defun eask-install-file--get-package-name (path)
2626
"Get the package name from PATH, which is a file, directory or archive."
27-
(cond
28-
((not (file-exists-p path))
29-
(eask-error "File does not exist %s" path))
30-
;; TAR file
31-
((string-match-p "[.]+tar[.]*" path)
32-
;; Note this can throw strange errors if
33-
;;
34-
;; - there is no -pkg.el in the tar file
35-
;; - the tar file was built in a folder with a different name
36-
;;
37-
;; TAR files created with eask package are fine.
38-
(require 'tar-mode)
39-
(let ((pkg-desc (with-current-buffer (find-file (expand-file-name path))
40-
(eask-ignore-errors-silent (package-tar-file-info)))))
41-
(unless pkg-desc
42-
;; `package-dir-info' will return nil if there is no `-pkg.el'
43-
;; and no `.el' files at path
44-
(eask-error "No package in %s" path))
45-
(package-desc-name pkg-desc)))
46-
;; .el file or directory
47-
(t
48-
;; Note `package-dir-info' doesn't work outside of dired mode!
49-
(let ((pkg-desc (with-current-buffer (dired (expand-file-name path))
50-
(eask-ignore-errors-silent (package-dir-info)))))
51-
(unless pkg-desc
52-
;; `package-dir-info' will return nil if there is no `-pkg.el'
53-
;; and no `.el' files at path
54-
(eask-error "No package in %s" path))
55-
(package-desc-name pkg-desc)))))
27+
(let ((path (expand-file-name path)))
28+
(cond
29+
((not (file-exists-p path))
30+
(eask-error "✗ File does not exist in `%s`" path))
31+
;; TAR file
32+
((string-match-p "[.]+tar[.]*" path)
33+
;; Note this can throw strange errors if
34+
;;
35+
;; - there is no -pkg.el in the tar file
36+
;; - the tar file was built in a folder with a different name
37+
;;
38+
;; TAR files created with eask package are fine.
39+
(require 'tar-mode)
40+
(let ((pkg-desc (with-temp-buffer
41+
(insert-file-contents-literally path)
42+
(tar-mode)
43+
(ignore-errors (package-tar-file-info)))))
44+
(unless pkg-desc
45+
;; `package-dir-info' will return nil if there is no `-pkg.el'
46+
;; and no `.el' files at path
47+
(eask-error "✗ No package in `%s`" path))
48+
(package-desc-name pkg-desc)))
49+
;; .el file or directory
50+
(t
51+
;; Note `package-dir-info' doesn't work outside of dired mode!
52+
(let ((pkg-desc (with-temp-buffer
53+
(dired path)
54+
(ignore-errors (package-dir-info)))))
55+
(unless pkg-desc
56+
;; `package-dir-info' will return nil if there is no `-pkg.el'
57+
;; and no `.el' files at path
58+
(eask-error "✗ No package in `%s`" path))
59+
(package-desc-name pkg-desc))))))
5660

5761
(defun eask-install-file--packages (files)
5862
"The file install packages with FILES."

0 commit comments

Comments
 (0)