0

I am not sure how to translate this use-package :commands syntax into a regular elisp init.el file.

(use-package languagetool
:commands (languagetool-check
       languagetool-clear-suggestions
       languagetool-correct-at-point
       languagetool-correct-buffer
       languagetool-set-language
       languagetool-server-mode
       languagetool-server-start
       languagetool-server-stop))

I just tried to evalute them as functions, like so.

(languagetool-check)
(languagetool-clear-suggestions)
(languagetool-correct-at-point)
(languagetool-correct-buffer)
(languagetool-set-language)
(languagetool-server-mode)
(languagetool-server-start)
(languagetool-server-stop)  

But that throws an error Wrong number of arguments: languagetool-check, 0.

2

1 Answer 1

2

The main use of use-package is to delay loading (i.e. require) of the package until it is needed.

The :command syntax is to provide a list of functions to autoload, so that if they are called, the call will force the loading of the package.

So you don't need them if you are controlling the loading of the package in other ways.

You just need (require 'languagetool) before calling one of the listed functions.

To see what use-package does just expand it using macroexpand:

(pp
 (macroexpand
  '(use-package languagetool
    :commands (languagetool-check
               languagetool-clear-suggestions
               languagetool-correct-at-point
               languagetool-correct-buffer
               languagetool-set-language
               languagetool-server-mode
               languagetool-server-start
               languagetool-server-stop))))

===>

(progn
  (defvar use-package--warning1
    #'(lambda
        (keyword err)
        (let
            ((msg
              (format "%s/%s: %s" 'languagetool keyword
                      (error-message-string err))))
          (display-warning 'use-package msg :error))))
  (condition-case-unless-debug err
      (progn
        (unless
            (fboundp 'languagetool-check)
          (autoload #'languagetool-check "languagetool" nil t))
        (unless
            (fboundp 'languagetool-clear-suggestions)
          (autoload #'languagetool-clear-suggestions "languagetool" nil t))
        (unless
            (fboundp 'languagetool-correct-at-point)
          (autoload #'languagetool-correct-at-point "languagetool" nil t))
        (unless
            (fboundp 'languagetool-correct-buffer)
          (autoload #'languagetool-correct-buffer "languagetool" nil t))
        (unless
            (fboundp 'languagetool-set-language)
          (autoload #'languagetool-set-language "languagetool" nil t))
        (unless
            (fboundp 'languagetool-server-mode)
          (autoload #'languagetool-server-mode "languagetool" nil t))
        (unless
            (fboundp 'languagetool-server-start)
          (autoload #'languagetool-server-start "languagetool" nil t))
        (unless
            (fboundp 'languagetool-server-stop)
          (autoload #'languagetool-server-stop "languagetool" nil t)))
    (error
     (funcall use-package--warning1 :catch err))))

use-package is now part of emacs 29 and even before it was easily loaded so I don't see why it can't be in a regular init.el.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.