all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
blob aeb85f8487b733ad94ea6b8155ced503cd900f96 4924 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
107
108
109
110
111
112
113
114
115
116
117
118
 
;;; -*- 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.  To produce verbose messages useful while debugging, set the
;; GUIX-EMACS-VERBOSE variable to true.

;;; 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))))

(defcustom guix-emacs-verbose nil
  "Set to true to provide verbose messages, such as when loading packages."
  :type 'boolean
  :group 'guix-emacs)

(defun guix-emacs--load-file-no-error (file)
  "Load FILE, ignoring any errors"
  (load file 'noerror (not guix-emacs-verbose)))

(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 (&optional reload)
  "Autoload Emacs packages found in EMACSLOADPATH.

'Autoload' means to load the 'autoloads' files matching
`guix-emacs-autoloads-regexp'.  When the optional RELOAD prefix
argument is true, reload the subdirs.el files found on the load
path; this behavior is active by default unless you've started
Emacs with the '--no-site-file' option."
  (interactive "P")
  ;; 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 (or reload guix-emacs-autoload-packages-called)
      (progn
        (mapc #'guix-emacs--load-file-no-error (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 #'guix-emacs--load-file-no-error 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 (file-name-directory subdirs-file))))
                 (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 aeb85f8487 ...
found aeb85f8487 in https://yhetil.org/guix/6276f07557efac57cc135c1239b074f07281d124.1693235796.git.maxim.cournoyer@gmail.com/
found 84284dde39 in https://git.savannah.gnu.org/cgit/guix.git
preparing index
index prepared:
100644 84284dde39ac1db268b7e0b67d9d89d76d5f931a	gnu/packages/aux-files/emacs/guix-emacs.el

applying [1/1] https://yhetil.org/guix/6276f07557efac57cc135c1239b074f07281d124.1693235796.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 84284dde39..aeb85f8487 100644

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

index at:
100644 aeb85f8487b733ad94ea6b8155ced503cd900f96	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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.