]> git.ekhem.eu.org Git - guix.git/commitdiff
[emacs] Structure working with packages.
authorJakub Czajka <jakub@ekhem.eu.org>
Thu, 22 Dec 2022 21:05:02 +0000 (22:05 +0100)
committerJakub Czajka <jczajka@google.com>
Sun, 24 Dec 2023 18:53:07 +0000 (19:53 +0100)
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.

conf/home/emacs.scm
emacs/.config/emacs/conf/conf-package.el [new file with mode: 0644]

index fc290738fa7d003380a378e93dc97eae995a4e9f..223cf3dbd3df87f2b995a5a3c41312577ddf036c 100644 (file)
@@ -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))
   (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 (file)
index 0000000..b089a81
--- /dev/null
@@ -0,0 +1,63 @@
+;; Copyright (c) 2022 Jakub Czajka <jakub@ekhem.eu.org>
+;; 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)