bard / emacs-run-command

Efficient and ergonomic external command invocation for Emacs
https://bard.github.io/emacs-run-command
GNU General Public License v3.0
102 stars 8 forks source link

Getting error when trying to run example recipe #12

Closed bsag closed 3 years ago

bsag commented 3 years ago

This is an exciting project, and one I know I will find useful for a number of different projects, so thanks for writing it!

I'm trying to set this up in Doom Emacs (with Selectrum), but I'm getting an error when trying out the simple example recipes.

When I try to run a command with the config below, both commands are displayed correctly in the minibuffer, but when I select either, I get the error 'Symbol's value as variable is void: command-name'. I do have sloccount installed and it works fine run manually, but the echo command example doesn't work either.

I suspect that the way I have added the examples to the run-command-recipes variable is wrong, but I'm a bit of a newbie with elisp and suspect that I somehow haven't quoted it properly (quoting still baffles me!).

Here's my configuration:

(defun run-command-recipe-example ()
  (list
   (list :command-name "say-hello"
         :command-line "echo Hello, World!")
   (when-let ((buffer-file (buffer-file-name)))
     (list :display "Count lines of code"
           :command-name "count-lines-of-code"
           :command-line (format "sloccount '%s'" buffer-file)))))

(use-package! run-command
  :config
  (setq run-command-recipes '(run-command-recipe-example))
  :bind ("C-c c" . run-command))

Any help you can give me would be much appreciated!

bard commented 3 years ago

Thanks for the report!

Your configuration looks fine, I tried it here and it works without problems. Can you tell me your Emacs version, and also do the following:

  1. M-x toggle-debug-on-error RET
  2. C-c c
  3. select a command
  4. a stack trace should appear
  5. copy and paste it here

You might want to also try the following as a hot patch. Paste it into Emacs, place the cursor after the last paretheses, and type C-x C-e:

(defun run-command--run (command-spec)
  "Run `COMMAND-SPEC'.  Back end for helm and ivy actions."
  (let* ((buffer-base-name (format "%s[%s]"
                                   (plist-get command-spec :command-name)
                                   (plist-get command-spec :scope-name)))
         (default-directory (plist-get command-spec :working-dir)))
    (with-current-buffer
        (cond
         ((run-command--experiment-p 'vterm-run-method)
          (run-command--run-vterm (plist-get command-spec :command-line) buffer-base-name))
         ((eq run-command-run-method 'compile)
          (run-command--run-compile (plist-get command-spec :command-line) buffer-base-name))
         ((eq run-command-run-method 'term)
          (run-command--run-term (plist-get command-spec :command-line) buffer-base-name)))
      (setq-local run-command-command-spec command-spec))))
ktfleming commented 3 years ago

Hey, just dropping in to say that I also noticed the same thing in Doom Emacs, and was able to get it working by disabling byte-compilation in packages.el:

(package! run-command
  ;; Leaving out "compile" and "native-compile" in the build steps will skip byte compilation
  :recipe (:build (autoloads info)))

It works fine in vanilla / non-Doom emacs though, and I'm not sure exactly why the combination of Doom + byte-compilation produces that error.

bard commented 3 years ago

@ktfleming were you also getting "Symbol's value as variable is void: command-name"? There is only one place in the code that uses command-name as variable, inside a cl-destructuring-bind. The patch above removes cl-seatructuring-bind in favor of plain plist-get calls, so it might fix it.

bard commented 3 years ago

I just pushed a change which removes cl-restructuring-bind, hopefully it fixes this.

(If you can paste a backtrace here before upgrading, much appreciated, it might clue me in to why it wasn't working it the first place.)

bsag commented 3 years ago

@bard Thanks for the quick response!

Here's the backtrace:

Debugger entered--Lisp error: (void-variable command-name)
  run-command--run((:command-name "say-hello" :command-line "echo Hello, World!" :display "say-hello" :working-dir "/Users/bsag/dotfiles/emacs/.doom.d/" :scope-name "~/dotfiles/emacs/.doom.d/"))
  run-command--completing-read()
  run-command()
  funcall-interactively(run-command)
  call-interactively(run-command nil nil)
  command-execute(run-command)

I then tried your hot patch which worked. I didn't yet try the change to byte-compilation suggested by @ktfleming, so your patch seems to work without that. I'll try updating now - thanks so much for the quick fix!

bsag commented 3 years ago

I've updated and can confirm it works perfectly. I'll close the issue now. Thanks again for such a useful package!

ktfleming commented 3 years ago

Late reply, but yeah I was seeing the same error message as @bsag, and can also confirm that the new version works without the byte-compile workaround. Thanks!