unofficial mirror of bug-guix@gnu.org 
 help / color / mirror / code / Atom feed
blob b4a4fd1d9148c45d6fadcef4a0304718d5f2409c 4250 bytes (raw)
name: gnu/packages/aux-files/emacs/guix-emacs.el 	 # note: path name is non-authoritative(*)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
 
;;; -*- lexical-binding: t; -*-
;;; guix-emacs.el --- Emacs packages installed with Guix

;; Copyright © 2014, 2015, 2016, 2017 Alex Kost <alezost@gmail.com>
;; Copyright © 2017 Kyle Meyer <kyle@kyleam.com>
;; Copyright © 2019, 2023 Maxim Cournoyer <maxim.cournoyer@gmail.com>

;; This file is part of GNU Guix.

;; GNU Guix 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.

;; GNU Guix 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 program.  If not, see <http://www.gnu.org/licenses/>.

;;; Commentary:

;; This file provides auxiliary code to autoload Emacs packages
;; installed with Guix.

;;; Code:
(require 'seq)
(declare-function package-load-descriptor "package" (pkg-dir))

(defvar guix-emacs-autoloads-regexp
  (rx (* any) "-autoloads.el" (zero-or-one "c") string-end)
  "Regexp to match Emacs 'autoloads' file.")

(defun guix-emacs-find-autoloads (directory)
  "Return a list of Emacs 'autoloads' files in DIRECTORY.
The files in the list do not have extensions (.el, .elc)."
  ;; `directory-files' doesn't honor group in regexp.
  (delete-dups (mapcar #'file-name-sans-extension
                       (directory-files directory 'full-name
                                        guix-emacs-autoloads-regexp))))

(defun guix-emacs--non-core-load-path ()
  ;; Filter out core Elisp directories, which are already handled by Emacs.
  (seq-filter (lambda (dir)
                (string-match-p "/share/emacs/site-lisp" dir))
              load-path))

(defun guix-emacs--subdirs-files ()
  "Return the Guix subdirs.el files found on the (non-core) load path."
  (seq-filter #'file-exists-p
              (mapcar (lambda (dir)
                        (expand-file-name "subdirs.el" dir))
                      (guix-emacs--non-core-load-path))))

(defvar guix-emacs-autoload-packages-called nil
  "True if `guix-emacs-autoload-packages' was already run.")

;;;###autoload
(defun guix-emacs-autoload-packages ()
  "Autoload Emacs packages found in EMACSLOADPATH.

'Autoload' means to load the 'autoloads' files matching
`guix-emacs-autoloads-regexp'."
  (interactive)
  ;; Reload the subdirs.el files such as the one generated by the Guix profile
  ;; hook, so that newly installed Emacs packages located under
  ;; sub-directories are put on the load-path without having to restart Emacs.
  (if guix-emacs-autoload-packages-called
      (progn
        (mapc #'load-file (guix-emacs--subdirs-files))
        (setq load-path (delete-dups load-path)))
    (setq guix-emacs-autoload-packages-called t))

  (let ((autoloads (mapcan #'guix-emacs-find-autoloads
                           (guix-emacs--non-core-load-path))))
    (mapc (lambda (f)
            (load f 'noerror t))
          autoloads)))

;;;###autoload
(defun guix-emacs-load-package-descriptors ()
  "Load descriptors for packages found in EMACSLOADPATH via subdirs.el."
  (dolist (subdirs-file (guix-emacs--subdirs-files))
    (with-temp-buffer
      (insert-file-contents subdirs-file)
      (goto-char (point-min))
      (let ((subdirs (read (current-buffer))))
        (and (equal (car-safe subdirs) 'normal-top-level-add-to-load-path)
             (equal (car-safe (cadr subdirs)) 'list)
             (dolist (subdir (cdadr subdirs))
               (let ((pkg-dir (expand-file-name subdir dir)))
                 (when (file-directory-p pkg-dir)
                   (package-load-descriptor pkg-dir)))))))))

;; If emacs built with tree-sitter, read the value of the environment variable
;; to make tree-sitter grammars available in emacs out-of-the-box.
(with-eval-after-load 'treesit
  (when-let ((grammar-path (getenv "TREE_SITTER_GRAMMAR_PATH")))
    (mapcar (lambda (x) (add-to-list 'treesit-extra-load-path x))
            (split-string grammar-path ":"))))

(provide 'guix-emacs)

;;; guix-emacs.el ends here

debug log:

solving b4a4fd1d91 ...
found b4a4fd1d91 in https://yhetil.org/guix-bugs/84a6b9e11ec0f8fcdd865dae40ab41100a5c763c.1693199493.git.maxim.cournoyer@gmail.com/
found ed0c913163 in https://yhetil.org/guix-bugs/633948875c3119ecb741940aa54ead7d1896b893.1693199493.git.maxim.cournoyer@gmail.com/
found c98e7fe369 in https://git.savannah.gnu.org/cgit/guix.git
preparing index
index prepared:
100644 c98e7fe36998fe6cbfbcc8497b13e5377f7e22e6	gnu/packages/aux-files/emacs/guix-emacs.el

applying [1/2] https://yhetil.org/guix-bugs/633948875c3119ecb741940aa54ead7d1896b893.1693199493.git.maxim.cournoyer@gmail.com/
diff --git a/gnu/packages/aux-files/emacs/guix-emacs.el b/gnu/packages/aux-files/emacs/guix-emacs.el
index c98e7fe369..ed0c913163 100644


applying [2/2] https://yhetil.org/guix-bugs/84a6b9e11ec0f8fcdd865dae40ab41100a5c763c.1693199493.git.maxim.cournoyer@gmail.com/
diff --git a/gnu/packages/aux-files/emacs/guix-emacs.el b/gnu/packages/aux-files/emacs/guix-emacs.el
index ed0c913163..b4a4fd1d91 100644

Checking patch gnu/packages/aux-files/emacs/guix-emacs.el...
Applied patch gnu/packages/aux-files/emacs/guix-emacs.el cleanly.
Checking patch gnu/packages/aux-files/emacs/guix-emacs.el...
Applied patch gnu/packages/aux-files/emacs/guix-emacs.el cleanly.

index at:
100644 b4a4fd1d9148c45d6fadcef4a0304718d5f2409c	gnu/packages/aux-files/emacs/guix-emacs.el

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).