Skip to content

Commit 34356cd

Browse files
committed
feat!(core): replace straight with the builtin package
1 parent 898ccc5 commit 34356cd

File tree

234 files changed

+685
-747
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

234 files changed

+685
-747
lines changed

core/me-backports.el

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
;;; me-backports.el --- Port the `use-package's `:vc' feature for Emacs 29 -*- lexical-binding: t; -*-
2+
3+
;; Copyright (C) 2022-2024 Abdelhak Bougouffa
4+
5+
;; Author: Abdelhak Bougouffa (rot13 "nobhtbhssn@srqbencebwrpg.bet")
6+
7+
;;; Commentary:
8+
9+
;;; Code:
10+
11+
(when (> emacs-major-version 29)
12+
(error "This module should only be used from Emacs 29"))
13+
14+
(require 'use-package)
15+
(require 'package-vc)
16+
17+
(add-to-list 'use-package-keywords :vc)
18+
19+
(defvar use-package-vc-prefer-newest nil)
20+
21+
(defun use-package-vc-install (arg &optional local-path)
22+
(pcase-let* ((`(,name ,opts ,rev) arg)
23+
(spec (if opts (cons name opts) name)))
24+
(unless (package-installed-p name)
25+
(if local-path
26+
(package-vc-install-from-checkout local-path (symbol-name name))
27+
(package-vc-install spec rev)))))
28+
29+
(defun use-package-handler/:vc (name _keyword arg rest state)
30+
(let ((body (use-package-process-keywords name rest state))
31+
(local-path (car (plist-get state :load-path))))
32+
;; See `use-package-handler/:ensure' for an explanation.
33+
(if (bound-and-true-p byte-compile-current-file)
34+
(funcall #'use-package-vc-install arg local-path) ; compile time
35+
(push `(use-package-vc-install ',arg ,local-path) body)) ; runtime
36+
body))
37+
38+
(defconst use-package-vc-valid-keywords '(:url :branch :lisp-dir :main-file :vc-backend :rev :shell-command :make :ignored-files))
39+
40+
(defun use-package-normalize--vc-arg (arg)
41+
(cl-flet* ((ensure-string (s)
42+
(if (and s (stringp s)) s (symbol-name s)))
43+
(ensure-symbol (s)
44+
(if (and s (stringp s)) (intern s) s))
45+
(normalize (k v)
46+
(pcase k
47+
(:rev (pcase v
48+
('nil (if use-package-vc-prefer-newest nil :last-release))
49+
(:last-release :last-release)
50+
(:newest nil)
51+
(_ (ensure-string v))))
52+
(:vc-backend (ensure-symbol v))
53+
(:ignored-files (if (listp v) v (list v)))
54+
(_ (ensure-string v)))))
55+
(pcase-let* ((`(,name . ,opts) arg))
56+
(if (stringp opts) ; (NAME . VERSION-STRING) ?
57+
(list name opts)
58+
(let ((opts (use-package-split-when
59+
(lambda (el)
60+
(seq-contains-p use-package-vc-valid-keywords el))
61+
opts)))
62+
;; Error handling
63+
(cl-loop for (k . _) in opts
64+
if (not (member k use-package-vc-valid-keywords))
65+
do (use-package-error
66+
(format "Keyword :vc received unknown argument: %s. Supported keywords are: %s"
67+
k use-package-vc-valid-keywords)))
68+
;; Actual normalization
69+
(list name
70+
(cl-loop for (k . v) in opts
71+
if (not (eq k :rev))
72+
nconc (list k (normalize k (if (length= v 1) (car v) v))))
73+
(normalize :rev (car (alist-get :rev opts)))))))))
74+
75+
(defun use-package-normalize/:vc (name _keyword args)
76+
(let ((arg (car args)))
77+
(pcase arg
78+
((or 'nil 't) (list name)) ; guess name
79+
((pred symbolp) (list arg)) ; use this name
80+
((pred stringp) (list name arg)) ; version string + guess name
81+
(`(,(pred keywordp) . ,(pred listp)) ; list + guess name
82+
(use-package-normalize--vc-arg (cons name arg)))
83+
(`(,(pred symbolp) . ,(or (pred listp) ; list/version string + name
84+
(pred stringp)))
85+
(use-package-normalize--vc-arg arg))
86+
(_ (use-package-error "Unrecognized argument to :vc")))))
87+
88+
89+
(provide 'me-backports)
90+
;;; me-backports.el ends here

core/me-bootstrap.el

Lines changed: 34 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
;; me-bootstrap.el --- Bootstrap packages (straight & use-package) -*- lexical-binding: t; -*-
1+
;; me-bootstrap.el --- Initialize package management -*- lexical-binding: t; -*-
22

33
;; Copyright (C) 2022-2024 Abdelhak Bougouffa
44

@@ -8,45 +8,13 @@
88

99
;;; Code:
1010

11-
(setq
12-
;; Base directory
13-
straight-base-dir minemacs-local-dir
14-
;; Add Emacs version and the Git hash to the build directory to avoid problems
15-
straight-build-dir (format "build-%s%s" emacs-version (if emacs-repository-version (format "-%s" (substring emacs-repository-version 0 8)) ""))
16-
;; Use the "develop" branch on straight.el's repo.
17-
straight-repository-branch "develop"
18-
;; Do not slow startup by checking for package modifs, check only on demand
19-
straight-check-for-modifications '(check-on-save find-when-checking))
20-
21-
;; Bootstrapping straight.el
22-
;; See: https://github.com/radian-software/straight.el#bootstrapping-straightel
23-
(defvar bootstrap-version)
24-
(let ((bootstrap-file (concat straight-base-dir "straight/repos/straight.el/bootstrap.el"))
25-
(install-url "https://raw.githubusercontent.com/radian-software/straight.el/develop/install.el")
26-
(bootstrap-version 7))
27-
(unless (file-exists-p bootstrap-file)
28-
(with-current-buffer (url-retrieve-synchronously install-url 'silent 'inhibit-cookies)
29-
(goto-char (point-max))
30-
(eval-print-last-sexp)))
31-
(load bootstrap-file nil 'nomessage))
32-
33-
;; HACK+PERF: Reduce installation time and disk usage using "--filter=tree:0",
34-
;; this cuts the size of the "repos" directory by more than half (from 807M to
35-
;; 362M) while keeping it possible to download older commits on-demand (unlike
36-
;; "--depth=N"). The parameter is injected in `straight--process-run' which is
37-
;; called from `straight-vc-git--clone-internal'
38-
(advice-add
39-
'straight--process-run :around
40-
(lambda (fn &rest a)
41-
(apply fn (if (equal (list (car a) (cadr a)) '("git" "clone")) `(,(car a) ,(cadr a) "--filter=tree:0" ,@(cddr a)) a))))
42-
43-
;; Configure `use-package'
44-
(unless (require 'use-package nil t)
45-
(straight-use-package 'use-package))
46-
47-
(cl-callf append straight-built-in-pseudo-packages
48-
'(treesit ; Some packages like `ts-movement' depends on it
49-
docker-tramp)) ; Needed by some packages like `ros', but provided by `tramp'
11+
(require 'me-lib)
12+
(require 'package)
13+
(require 'use-package)
14+
15+
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
16+
(add-to-list 'package--builtins '(treesit . [nil nil "Tree-Sitter integration"])) ; Some packages like `ts-movement' depends on it
17+
(add-to-list 'package--builtins '(docker-tramp . [nil nil "Tree-Sitter integration"])) ; Needed by some packages like `ros', but provided by `tramp'
5018

5119
(setq
5220
;; Set `use-package' to verbose when MinEmacs is started in verbose mode
@@ -57,21 +25,38 @@
5725
;; Make the expanded code as minimal as possible, do not try to catch errors
5826
use-package-expand-minimally (not minemacs-debug-p))
5927

60-
;; Add the `:pin-ref' extension to integrate `straight' with `use-package'. And
61-
;; add support for `minemacs-disabled-packages'.
62-
(require 'me-use-package-extra)
6328

64-
;; Extra utilities
29+
;;; `use-package' extensions
30+
;; Add `:vc' support for `use-package' in Emacs 29
31+
(unless (> emacs-major-version 29) (require 'me-backports))
32+
33+
;; Prefer the newest commit over the latest release
34+
(setq use-package-vc-prefer-newest t)
35+
36+
;; Add `:trigger-commands', allow loading the package before executing a
37+
;; specific external command/function.
38+
(add-to-list 'use-package-keywords :trigger-commands)
39+
40+
;; `:trigger-commands' implementation
41+
(defun use-package-normalize/:trigger-commands (name keyword args)
42+
(setq args (use-package-normalize-recursive-symlist name keyword args))
43+
(if (consp args) args (list args)))
44+
45+
(defun use-package-handler/:trigger-commands (name _keyword arg rest state)
46+
(use-package-concat
47+
(unless (plist-get state :demand)
48+
`((satch-add-advice ',(delete-dups arg) :before (lambda (&rest _args) (require ',name)) nil :transient t)))
49+
(use-package-process-keywords name rest state)))
50+
51+
52+
;;; Extra utilities
6553
;; Be cautious about the installed revision of `once' and `satch' as they aren't stable yet
6654
(use-package once
67-
:straight (:host github :repo "emacs-magus/once")
68-
:pin-ref "a6f950c29c846a50018bc63695f24f611c1a58be")
55+
:vc (:url "https://github.com/emacs-magus/once" :rev "a6f950c29c846a50018bc63695f24f611c1a58be"))
6956

7057
(use-package satch
71-
:straight (:host github :repo "emacs-magus/satch.el")
72-
:pin-ref "77993b711cccf16702fdc8d21d8f8ba10d7bd0fb")
58+
:vc (:url "https://github.com/emacs-magus/satch.el" :rev "77993b711cccf16702fdc8d21d8f8ba10d7bd0fb"))
7359

7460

7561
(provide 'me-bootstrap)
76-
7762
;;; me-bootstrap.el ends here

core/me-builtin.el

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,7 @@ or file path may exist now."
221221
(+setq-hook! python-mode comment-inline-offset 2))
222222

223223
(use-package compat
224-
:straight (:source gnu-elpa-mirror)
225-
:demand)
224+
:ensure t)
226225

227226
(use-package crm
228227
:config
@@ -234,15 +233,15 @@ or file path may exist now."
234233
(cons (format "[CRM%s] %s" (replace-regexp-in-string "\\`\\[.*?]\\*\\|\\[.*?]\\*\\'" "" crm-separator) (car args)) (cdr args)))))
235234

236235
(use-package transient
237-
:straight (:source gnu-elpa-mirror)
236+
:ensure t
238237
:autoload transient-define-prefix transient-define-infix transient-define-suffix
239238
:bind (:map
240239
transient-map ; Map ESC and q to quit transient
241240
("q" . transient-quit-one)
242241
("<escape>" . transient-quit-one)))
243242

244243
(use-package which-key
245-
:straight (:source gnu-elpa-mirror)
244+
:ensure t
246245
:hook (minemacs-lazy . which-key-mode)
247246
:custom
248247
(which-key-idle-delay 1.0)
@@ -258,7 +257,7 @@ or file path may exist now."
258257
(which-key-setup-minibuffer))
259258

260259
(use-package tramp
261-
:straight (:source gnu-elpa-mirror)
260+
:ensure t
262261
:init
263262
(if (+emacs-options-p 'os/win)
264263
(when (executable-find "plink")
@@ -328,7 +327,7 @@ or file path may exist now."
328327
(doc-view-mupdf-use-svg (+emacs-options-p 'rsvg)))
329328

330329
(use-package project
331-
:straight (:source gnu-elpa-mirror)
330+
:ensure t
332331
:commands (project-remember-projects-under)
333332
:hook (kill-emacs . +project-forget-zombie-projects)
334333
:custom
@@ -401,14 +400,14 @@ or file path may exist now."
401400
(setcdr (assq 'explicit-name tab) 'def)))
402401

403402
(use-package editorconfig
404-
:straight t
405-
:hook (minemacs-first-file . editorconfig-mode)
406-
:config
407-
;; Exclude compressed files
408-
(push "\\.\\(zip\\|epub\\|\\(doc\\|xls\\|ppt\\)x\\)\\'" editorconfig-exclude-regexps))
403+
:ensure t
404+
:hook (minemacs-first-file . editorconfig-mode))
405+
;; :config
406+
;; ;; Exclude compressed files
407+
;; (push "\\.\\(zip\\|epub\\|\\(doc\\|xls\\|ppt\\)x\\)\\'" editorconfig-exclude-regexps))
409408

410409
(use-package flymake
411-
:straight (:source gnu-elpa-mirror)
410+
:ensure t
412411
:hook ((prog-mode conf-mode) . flymake-mode)
413412
:custom
414413
(flymake-fringe-indicator-position 'right-fringe)
@@ -586,7 +585,7 @@ or file path may exist now."
586585
hs-special-modes-alist '((t)))))
587586

588587
(use-package xref
589-
:straight (:source gnu-elpa-mirror)
588+
:ensure t
590589
:custom
591590
;; Use completion in the minibuffer instead of definitions buffer
592591
(xref-show-definitions-function #'xref-show-definitions-completing-read)
@@ -603,7 +602,7 @@ or file path may exist now."
603602
(+setq-hook! xref--xref-buffer-mode truncate-lines t))
604603

605604
(use-package eglot
606-
:straight (:source gnu-elpa-mirror)
605+
:ensure t
607606
:custom
608607
(eglot-autoshutdown t) ; shutdown after closing the last managed buffer
609608
(eglot-sync-connect 0) ; async, do not block
@@ -654,7 +653,7 @@ or file path may exist now."
654653
(imenu-max-item-length 120)) ; Show longer definitions (def. 60)
655654

656655
(use-package eldoc
657-
:straight (:source gnu-elpa-mirror)
656+
:ensure t
658657
:custom
659658
(eldoc-documentation-strategy #'eldoc-documentation-compose))
660659

@@ -694,7 +693,7 @@ or file path may exist now."
694693
(gdb-display-io-nopopup nil)) ; in case we enabled the IO buffer, we don't want it to popup when hidden
695694

696695
(use-package org
697-
:straight (:source gnu-elpa-mirror)
696+
:ensure t
698697
:preface
699698
;; Set to nil so we can detect user changes (in config.el)
700699
(setq org-directory nil)

core/me-lib.el

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ If `minemacs-verbose-p' is non-nil, do not print any message to
223223
(+error! "Cannot load theme %S, trying to load the default theme %S" minemacs-theme default-theme)
224224
(unless (ignore-errors (load-theme default-theme t))
225225
(+error! "Cannot load default theme %S, falling back to the builtin tsdh-light theme" default-theme)
226-
(load-theme 'tsdh-light t)))))
226+
(load-theme 'modus-operandi t)))))
227227
;; Run hooks
228228
(run-hooks 'minemacs-after-load-theme-hook))
229229

0 commit comments

Comments
 (0)