From: Jakub Czajka Date: Thu, 22 Dec 2022 21:05:02 +0000 (+0100) Subject: [emacs] Structure working with packages. X-Git-Url: https://git.ekhem.eu.org/?a=commitdiff_plain;h=acc80bdc8ff358e90b2804067c39a78ee748153e;p=guix.git [emacs] Structure working with packages. Elisp code can be packaged and shared as a package. This commit structures how emacs should work with packages. It installs `use-package` which simplifies installation of other packages. --- diff --git a/conf/home/emacs.scm b/conf/home/emacs.scm index fc29073..223cf3d 100644 --- a/conf/home/emacs.scm +++ b/conf/home/emacs.scm @@ -8,6 +8,7 @@ #:use-module (gnu home services) #:use-module (gnu home services shepherd) #:use-module (gnu packages emacs) + #:use-module (gnu packages emacs-xyz) #:use-module (gnu services) #:use-module (guix gexp) #:export (emacs-services)) @@ -25,6 +26,15 @@ (simple-service 'emacs-daemon-service home-shepherd-service-type (list emacs-daemon-shepherd-service))) + +(define emacs-package-service + (service home-program-service-type + (home-program-configuration + (packages + (list emacs-exec-path-from-shell + emacs-use-package)) + (dotfiles + (list "emacs/.config/emacs/conf/conf-package.el"))))) (define emacs-service (service home-program-service-type (home-program-configuration @@ -38,4 +48,5 @@ (define emacs-services (list emacs-daemon-service + emacs-package-service emacs-service)) diff --git a/emacs/.config/emacs/conf/conf-package.el b/emacs/.config/emacs/conf/conf-package.el new file mode 100644 index 0000000..b089a81 --- /dev/null +++ b/emacs/.config/emacs/conf/conf-package.el @@ -0,0 +1,63 @@ +;; Copyright (c) 2022 Jakub Czajka +;; License: GPL-3.0 or later. +;; +;; conf-package.el - configuration for managing packages. + +(require 'package) +(require 'conf-variables) + +(push '("melpa" . "https://melpa.org/packages/") package-archives) + +(defun conf:install-if-missing (package) + "Install PACKAGE if it is not already installed." + (unless (package-installed-p package) + (package-refresh-contents t) + (package-install package))) + +(conf:install-if-missing 'use-package) + +(eval-when-compile + (require 'use-package)) +;; Required by the `:bind' directive in `use-package'. +(use-package bind-key) + +(defun conf:executables-p (execs) + "Returns `t' if all the names in EXECS can be found in `exec-path'. Otherwise \ +returns `nil'. +EXECS should be a list of names of executables, with or without their full \ +path. Example: + +\(conf:executables-p \(list \"git\" \"pass\"\)\)" + (seq-every-p #'executable-find execs)) + +(defun conf:libraries--lib-exists (lib) + (let* ((ld-path (concat (getenv "LD_LIBRARY_PATH") ":/usr/lib")) + (ld-paths (split-string ld-path ":" t))) + (seq-find (lambda (ld-path) + (file-exists-p (expand-file-name lib ld-path))) + ld-paths))) + +(defun conf:libraries-p (libs) + "Returns `t' if all the names in LIBS can be found in the shared library \ +linking path. Otherwise returns `nil'. +LIBS should be a list of names of libraries, with or without their full path, \ +in the format `libexample.\{so,a\}'. `conf:with-libraries' looks for each \ +library in paths specified by `$LD_LIBRARY_PATH' and in `/usr/lib'. Example: + +\(conf:libraries-p \(list \"libcurl.so\" \"libX11.so\"\)\)" + (seq-every-p #'conf:libraries--lib-exists libs)) + +;; == CUSTOM VARIABLES == +(use-package cus-edit + :init + (setq custom-file + (expand-file-name "custom-variables.el" + user-emacs-directory)) + (load custom-file)) + +;; == ENVIRONMENT VARIABLES == +;; https://emacs.stackexchange.com/a/18490 +(use-package exec-path-from-shell + :ensure t) + +(provide 'conf-package)