jwiegley / use-package

A use-package declaration for simplifying your .emacs
https://jwiegley.github.io/use-package
GNU General Public License v3.0
4.41k stars 260 forks source link

minimal support for ensure by Debian packages #875

Closed thkoch2001 closed 1 year ago

thkoch2001 commented 4 years ago

I like my elisp to come from the Debian repository and this is the minimal init.el I came up with to support this:

(unless (package-installed-p 'use-package)
  (progn
    (message "WARNING: use-package not installed!")
    (throw 'no-use-package "use-package not installed!")
    )
  )

(package-initialize)

(use-package system-packages)

(defun use-package-ensure-debian (name args _state &optional _no-refresh)
  (dolist (ensure args)
    (let ((package
           (or (and (eq ensure t) (use-package-as-symbol name))
               ensure)))
      (when package
        (require 'package)
        (unless (package-installed-p package)
          (condition-case-unless-debug err
              (progn
                (system-packages-install (concat "elpa-" (symbol-name package)))
                t)
            (error
             (display-warning 'use-package
                              (format "Failed to install %s: %s"
                                      name (error-message-string err))
                              :error))))))))

(custom-set-variables
 '(system-packages-package-manager 'apt)
 '(system-packages-use-sudo t)
 '(use-package-ensure-function 'use-package-ensure-debian)
 )

(use-package haskell-mode
  :ensure t
  )

This is a feature request to support system-packages directly from use-package. Also I welcome any comments on the code above since I just finished reading through the elisp intro.

I initially wanted to write a function use-package-ensure-system-packages. However the mapping from melpa name to name in the package manager's repository is specific to Debian. I don't even know whether other repositories have a strict naming scheme like the Debian one.

a13 commented 4 years ago

why don't you use :ensure-system-package instead of redefining :ensure behavior?

skangas commented 1 year ago

@a13 answered this question, so I'm closing this issue. Please report back if there is more to do here, thanks.