2014-11-30 20:38:43 +00:00
|
|
|
;;; guix-emacs.el --- Emacs packages installed with Guix
|
|
|
|
|
2017-02-18 08:44:52 +00:00
|
|
|
;; Copyright © 2014, 2015, 2016, 2017 Alex Kost <alezost@gmail.com>
|
2017-07-27 05:01:26 +00:00
|
|
|
;; Copyright © 2017 Kyle Meyer <kyle@kyleam.com>
|
2019-10-30 02:07:55 +00:00
|
|
|
;; Copyright © 2019 Maxim Cournoyer <maxim.cournoyer@gmail.com>
|
2014-11-30 20:38:43 +00:00
|
|
|
|
|
|
|
;; 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:
|
|
|
|
|
2017-02-18 08:44:52 +00:00
|
|
|
;; This file provides auxiliary code to autoload Emacs packages
|
2014-11-30 20:38:43 +00:00
|
|
|
;; installed with Guix.
|
|
|
|
|
|
|
|
;;; Code:
|
2019-10-30 02:07:55 +00:00
|
|
|
(require 'seq)
|
2021-05-22 12:54:28 +00:00
|
|
|
(declare-function package-load-descriptor "package" (pkg-dir))
|
2014-11-30 20:38:43 +00:00
|
|
|
|
2015-12-03 10:03:19 +00:00
|
|
|
(defvar guix-emacs-autoloads-regexp
|
2019-10-30 02:07:55 +00:00
|
|
|
(rx (* any) "-autoloads.el" (zero-or-one "c") string-end)
|
2015-12-03 10:03:19 +00:00
|
|
|
"Regexp to match Emacs 'autoloads' file.")
|
|
|
|
|
2016-02-05 08:46:40 +00:00
|
|
|
(defun guix-emacs-find-autoloads (directory)
|
2015-12-03 10:03:19 +00:00
|
|
|
"Return a list of Emacs 'autoloads' files in DIRECTORY.
|
|
|
|
The files in the list do not have extensions (.el, .elc)."
|
2019-10-30 02:07:55 +00:00
|
|
|
;; `directory-files' doesn't honor group in regexp.
|
2019-12-06 06:12:32 +00:00
|
|
|
(delete-dups (mapcar #'file-name-sans-extension
|
|
|
|
(directory-files directory 'full-name
|
|
|
|
guix-emacs-autoloads-regexp))))
|
2014-11-30 20:38:43 +00:00
|
|
|
|
2021-05-22 12:54:28 +00:00
|
|
|
(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))
|
|
|
|
|
2014-11-30 20:38:43 +00:00
|
|
|
;;;###autoload
|
2019-10-30 02:07:55 +00:00
|
|
|
(defun guix-emacs-autoload-packages ()
|
|
|
|
"Autoload Emacs packages found in EMACSLOADPATH.
|
2016-02-05 08:46:40 +00:00
|
|
|
|
2019-10-30 02:07:55 +00:00
|
|
|
'Autoload' means to load the 'autoloads' files matching
|
2016-02-05 08:46:40 +00:00
|
|
|
`guix-emacs-autoloads-regexp'."
|
2019-10-30 02:07:55 +00:00
|
|
|
(interactive)
|
2021-05-22 12:54:28 +00:00
|
|
|
(let ((autoloads (mapcan #'guix-emacs-find-autoloads
|
|
|
|
(guix-emacs--non-core-load-path))))
|
2019-10-30 02:07:55 +00:00
|
|
|
(mapc (lambda (f)
|
2022-05-21 13:42:12 +00:00
|
|
|
(load f 'noerror t))
|
2019-10-30 02:07:55 +00:00
|
|
|
autoloads)))
|
2014-11-30 20:38:43 +00:00
|
|
|
|
2021-05-22 12:54:28 +00:00
|
|
|
;;;###autoload
|
|
|
|
(defun guix-emacs-load-package-descriptors ()
|
|
|
|
"Load descriptors for packages found in EMACSLOADPATH via subdirs.el."
|
|
|
|
(dolist (dir (guix-emacs--non-core-load-path))
|
|
|
|
(let ((subdirs-file (expand-file-name "subdirs.el" dir)))
|
|
|
|
(when (file-exists-p subdirs-file)
|
|
|
|
(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)))))))))))
|
|
|
|
|
2023-02-10 08:32:12 +00:00
|
|
|
;; 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 ":"))))
|
|
|
|
|
2014-11-30 20:38:43 +00:00
|
|
|
(provide 'guix-emacs)
|
|
|
|
|
|
|
|
;;; guix-emacs.el ends here
|