Skip to content

Commit cb74461

Browse files
committed
Fix module download URL when installed from MELPA
MELPA rewrites the Version header to a date-based string (e.g. 20260405.2019), so the download URL pointed to a non-existent GitHub release tag. Read the real semver from the file header via lm-header instead of using the package-alist version. Remove the now-redundant ghostel--elisp-version function.
1 parent 21abb3d commit cb74461

2 files changed

Lines changed: 16 additions & 30 deletions

File tree

ghostel.el

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -441,15 +441,17 @@ Choice: " url)
441441
(?s nil))))
442442

443443
(defun ghostel--package-version ()
444-
"Return ghostel package version string, or nil.
445-
Returns nil without error when `package.el' is unavailable."
446-
(when (and (require 'package nil t)
447-
(boundp 'package-alist)
448-
(fboundp 'package-desc-version)
449-
(fboundp 'package-version-join))
450-
(let ((pkg (car (alist-get 'ghostel package-alist))))
451-
(when pkg
452-
(package-version-join (package-desc-version pkg))))))
444+
"Return ghostel release version string, or nil.
445+
Reads the Version header from ghostel.el so the download URL
446+
matches the GitHub release tag even when MELPA rewrites the
447+
version to a date-based string."
448+
(require 'lisp-mnt nil t)
449+
(when (fboundp 'lm-header)
450+
(let ((lib (or load-file-name (locate-library "ghostel"))))
451+
(when lib
452+
(with-temp-buffer
453+
(insert-file-contents lib nil 0 1024)
454+
(lm-header "Version"))))))
453455

454456
(defun ghostel--download-file (url dest)
455457
"Download URL to DEST. Return non-nil on success."
@@ -499,22 +501,6 @@ The output is shown in a *ghostel-build* compilation buffer."
499501
default-directory))))
500502
(compile (expand-file-name "build.sh") t)))
501503

502-
(defun ghostel--elisp-version ()
503-
"Return the ghostel Elisp version from the package header."
504-
(or (ghostel--package-version)
505-
;; Fall back to parsing the header from the source file.
506-
(let ((file (or load-file-name
507-
(locate-library "ghostel")
508-
buffer-file-name)))
509-
(when file
510-
;; Ensure we read the .el source, not a .elc byte-compiled file.
511-
(when (string-suffix-p ".elc" file)
512-
(setq file (substring file 0 -1)))
513-
(when (file-exists-p file)
514-
(with-temp-buffer
515-
(insert-file-contents file nil 0 512)
516-
(when (re-search-forward "^;; Version: \\([0-9.]+\\)" nil t)
517-
(match-string 1))))))))
518504

519505
(defun ghostel--check-module-version (dir)
520506
"Check if the loaded module is older than required.

test/ghostel-test.el

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,11 +1163,11 @@ cell, so the visual line width must equal the terminal column count."
11631163
;; Test: module version check
11641164
;; -----------------------------------------------------------------------
11651165

1166-
(ert-deftest ghostel-test-elisp-version ()
1167-
"Test that `ghostel--elisp-version' returns a version string."
1168-
(let ((ver (ghostel--elisp-version)))
1166+
(ert-deftest ghostel-test-package-version ()
1167+
"Test that `ghostel--package-version' returns a version string."
1168+
(let ((ver (ghostel--package-version)))
11691169
(should (stringp ver))
1170-
(should (string-match-p "^[0-9]+\\.[0-9]+" ver))))
1170+
(should (string-match-p "^[0-9]+\\.[0-9]+\\.[0-9]+" ver))))
11711171

11721172
(ert-deftest ghostel-test-module-version-match ()
11731173
"Test that version check does nothing when module meets minimum."
@@ -1420,7 +1420,7 @@ cell, so the visual line width must equal the terminal column count."
14201420
ghostel-test-osc51-eval-unknown
14211421
ghostel-test-copy-mode-cursor
14221422
ghostel-test-copy-mode-hl-line
1423-
ghostel-test-elisp-version
1423+
ghostel-test-package-version
14241424
ghostel-test-module-version-match
14251425
ghostel-test-module-version-mismatch
14261426
ghostel-test-module-version-newer-than-minimum

0 commit comments

Comments
 (0)