Skip to content

Commit

Permalink
fix: Compatible to Emacs 26
Browse files Browse the repository at this point in the history
  • Loading branch information
jcs090218 committed Dec 29, 2023
1 parent d2cc4d8 commit 301a71f
Show file tree
Hide file tree
Showing 8 changed files with 2,113 additions and 13 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,14 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest] # XXX: `windows-latest` is not possible at the moment!
emacs-version:
- 29.1

steps:
- uses: jcs090218/setup-emacs@master
with:
version: ${{ matrix.emacs-version }}

- uses: actions/checkout@v4

- name: Install Docker
Expand Down
29 changes: 19 additions & 10 deletions lisp/_prepare.el
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,16 @@ Arguments FNC and ARGS are used for advice `:around'."
;;
;;; Package

(defun eask-install-package-build ()
"Correct way to install the package `package-build'."
(cond ((version< emacs-version "27.1")
(add-to-list 'load-path
(format "%sextern/package-build/%s/" eask-lisp-root
emacs-major-version)
t))
(t (eask-with-archives "melpa"
(eask-package-install 'package-build)))))

(defun eask--update-exec-path ()
"Add all bin directory to the variable `exec-path'."
(dolist (entry (directory-files package-user-dir t directory-files-no-dot-files-regexp))
Expand Down Expand Up @@ -537,8 +547,7 @@ scope of the dependencies (it's either `production' or `development')."
(eask-defvc< 27 (eask-pkg-init)) ; XXX: remove this after we drop 26.x
(when eask-depends-on-recipe-p
(eask-log "Installing required external packages...")
(eask-with-archives "melpa"
(eask-package-install 'package-build))
(eask-install-package-build)
(eask-with-progress
"Building temporary archives (this may take a while)... "
(eask-with-verbosity 'debug (github-elpa-build))
Expand Down Expand Up @@ -1971,14 +1980,6 @@ variable we use to test validation."
(eask-msg ""))
(setq eask-lint-first-file-p t))

;;
;;; Externals

(eask-load "extern/compat")
(eask-load "extern/ansi")
(eask-load "extern/package")
(eask-load "extern/package-build")

;;
;;; API

Expand All @@ -1993,4 +1994,12 @@ variable we use to test validation."
(setq eask-commands (delete-dups eask-commands))
`(defun ,name nil ,@body))

;;
;;; Externals

(eask-load "extern/compat")
(eask-load "extern/ansi")
(eask-load "extern/package")
(eask-load "extern/package-build")

;;; _prepare.el ends here
3 changes: 1 addition & 2 deletions lisp/core/package.el
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ Argument VERSION is a string represent the version number of this package."
(ignore-errors (make-directory eask-dist-path t))

(eask-defvc< 27 (eask-pkg-init)) ; XXX: remove this after we drop 26.x
(eask-with-archives "melpa"
(eask-package-install 'package-build))
(eask-install-package-build)
(eask-load "extern/package-build") ; override

(let* ((version (eask-package-version))
Expand Down
143 changes: 143 additions & 0 deletions lisp/extern/package-build/26/package-build-badges.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
;;; package-build-badges.el --- Create badges for packages -*- lexical-binding:t; coding:utf-8 -*-

;; Copyright (C) 2011-2023 Donald Ephraim Curtis
;; Copyright (C) 2012-2023 Steve Purcell
;; Copyright (C) 2018-2023 Jonas Bernoulli
;; Copyright (C) 2021-2023 Free Software Foundation, Inc
;; Copyright (C) 2009 Phil Hagelberg

;; Author: Donald Ephraim Curtis <[email protected]>
;; Homepage: https://github.com/melpa/package-build
;; Keywords: maint tools

;; SPDX-License-Identifier: GPL-3.0-or-later

;; This file is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published
;; by the Free Software Foundation, either version 3 of the License,
;; or (at your option) any later version.
;;
;; This file is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this file. If not, see <https://www.gnu.org/licenses/>.

;;; Commentary:

;; Create badges for packages.
;; The code in this file was lifted from `elpa-admin'.

;;; Code:

(defvar package-build-badge-data)

(defun package-build--write-badge-image ( name version target-dir
&optional archive color)
"Make badge svg file.
This is essentially a copy of `elpaa--make-badge'."
(let* ((file (expand-file-name (concat name "-badge.svg") target-dir))
(left (or archive (car package-build-badge-data) "myElpa"))
(right (url-hexify-string version))
(color (or color (cadr package-build-badge-data) "#ff491b"))
(lw (package-build-badge--string-width left))
(rw (package-build-badge--string-width right))
(pad (package-build-badge--string-width "x"))
(width (/ (+ lw rw (* 4 pad)) 10))
(offset -10) ;; Small alignment correction
(ctx `((offset . ,offset)
(left . ,left)
(right . ,right)
(lw . ,lw)
(rw . ,rw)
(width . ,width)
(color . ,color)
(pad . ,pad))))
(with-temp-buffer
(insert
(replace-regexp-in-string
"{\\([^}]+\\)}"
(lambda (str)
(url-insert-entities-in-string
(format "%s" (eval (read (match-string 1 str)) ctx))))
(eval-when-compile
(replace-regexp-in-string
"[ \t\n]+" " "
(replace-regexp-in-string
"'" "\""
"<?xml version='1.0'?>
<svg xmlns='http://www.w3.org/2000/svg'
xmlns:xlink='http://www.w3.org/1999/xlink'
width='{width}'
height='20'
role='img'
aria-label='{left}: {right}'>
<title>{left}: {right}</title>
<linearGradient id='s' x2='0' y2='100%'>
<stop offset='0' stop-color='#bbb' stop-opacity='.1'/>
<stop offset='1' stop-opacity='.1'/>
</linearGradient>
<clipPath id='r'>
<rect width='{width}' height='20' rx='3' fill='#fff'/>
</clipPath>
<g clip-path='url(#r)'>
<rect width='{(/ (+ lw (* 2 pad)) 10)}'
height='20' fill='#555'/>
<rect x='{(1- (/ (+ lw (* 2 pad)) 10))}'
width='{width}' height='20' fill='{color}'/>
<rect width='{width}' height='20' fill='url(#s)'/>
</g>
<g fill='#fff'
text-anchor='middle'
font-family='Verdana,Geneva,DejaVu Sans,sans-serif'
font-size='110'
text-rendering='geometricPrecision'>
<text aria-hidden='true'
x='{(+ (/ lw 2) pad offset)}'
y='150'
fill='#010101' fill-opacity='.3'
transform='scale(.1)' textLength='{lw}'>{left}</text>
<text x='{(+ (/ lw 2) pad offset)}'
y='140' transform='scale(.1)'
fill='#fff'
textLength='{lw}'>{left}</text>
<text aria-hidden='true'
x='{(+ lw (/ rw 2) (* 3 pad) offset)}'
y='150'
fill='#010101' fill-opacity='.3'
transform='scale(.1)' textLength='{rw}'>{right}</text>
<text x='{(+ lw (/ rw 2) (* 3 pad) offset)}'
y='140'
transform='scale(.1)'
fill='#fff' textLength='{rw}'>{right}</text>
</g>
</svg>")))))
(write-region (point-min) (point-max) file))))

(defun package-build-badge--string-width (str)
"Determine string width in pixels of STR."
(with-temp-buffer
;; ImageMagick 7.1.0 or later requires using the "magick" driver,
;; rather than "convert" directly, but Debian doesn't provide it
;; yet (2021).
(let ((args `(,@(if (executable-find "magick")
'("magick" "convert")
'("convert"))
"-debug" "annotate" "xc:" "-font" "DejaVu-Sans"
"-pointsize" "110" "-annotate" "0" ,str "null:")))
(apply #'call-process (car args) nil t nil (delq nil (cdr args)))
(goto-char (point-min))
(if (not (re-search-forward "Metrics:.*?width: \\([0-9]+\\)"))
(error "Could not determine string width")
(let ((width (string-to-number (match-string 1))))
;; This test aims to catch the case where the font is missing,
;; but it seems it only works in some cases :-(
(if (and (> (string-width str) 0) (not (> width 0)))
(progn (message "convert:\n%s" (buffer-string))
(error "Could not determine string width"))
width))))))

(provide 'package-build-badges)
;;; package-badges.el ends here
Loading

0 comments on commit 301a71f

Please sign in to comment.