Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exit-code-success-p does not accept inline lambda definition #53

Open
montchr opened this issue Jun 7, 2024 · 2 comments
Open

exit-code-success-p does not accept inline lambda definition #53

montchr opened this issue Jun 7, 2024 · 2 comments

Comments

@montchr
Copy link

montchr commented Jun 7, 2024

By my reading of the documentation for reformatter-define, :exit-code-success-p could be a lambda. But with the following expression, I get an error:

(reformatter-define phpcbf-fmt
    :program (format "%s/vendor/bin/phpcbf" (getenv "PRJ_ROOT"))
    :args (list "--stdin-path" input-file
                "-q"
                "-")
    :exit-code-success-p (lambda (exit-code)
                           (or (= 0 exit-code)
                               (= 1 exit-code))))

Error:

  cl--assertion-failed((functionp exit-code-success-p))

Judging from the backtrace output, it looks like the lambda is being sharp-quoted:

  (reformatter-define phpcbf-fmt :program (format "%s/vendor/bin/phpcbf" (getenv "PRJ_ROOT")) :args (list "--stdin-path" input-file "-q" "-") :exit-code-success-p #'(lambda (exit-code) (or (= 0 exit-code) (= 1 exit-code))))
Backtrace (with irrelevant stuff from Elpaca removed towards the end)
Debugger entered--Lisp error: (cl-assertion-failed ((functionp exit-code-success-p) nil))
  cl--assertion-failed((functionp exit-code-success-p))
  #f(compiled-function (arg1 &rest rest) "Define a reformatter command with NAME.\n\nWhen called, the reformatter will use PROGRAM and any ARGS to\nreformat the current buffer.  The contents of the buffer will be\npassed as standard input to the reformatter, which should output\nthem to standard output.  A nonzero exit code will be reported as\nfailure, and the output of the command to standard error will be\ndisplayed to the user.\n\nThe macro accepts the following keyword arguments:\n\nPROGRAM (required)\n\n  Provides a form which should evaluate to a string at runtime,\n  e.g. a literal string, or the name of a variable which holds\n  the program path.\n\nARGS\n\n  Command-line arguments for the program.  If provided, this is a\n  form which evaluates to a list of strings at runtime.  Default\n  is the empty list.  This form is evaluated at runtime so that\n  you can use buffer-local variables to influence the args passed\n  to the reformatter program: the variable `input-file' will be\n  lexically bound to the path of a file containing the text to be\n  reformatted: see the keyword options INPUT-FILE, STDIN and\n  STDOUT for more information.\n\nSTDIN\n\n  When non-nil (the default), the program is passed the input\n  data on stdin.  Set this to nil when your reformatter can only\n  operate on files in place.  In such a case, your ARGS should\n  include a reference to the `input-file' variable, which will be\n  bound to an input path when evaluated.\n\nSTDOUT\n\n  When non-nil (the default), the program is expected to write\n  the reformatted text to stdout.  Set this to nil if your\n  reformatter can only operate on files in place, in which case\n  the contents of the temporary input file will be used as the\n  replacement text.\n\nINPUT-FILE\n\n  Sometimes your reformatter program might expect files to be in\n  a certain directory or have a certain file extension.  This option\n  lets you handle that.\n\n  If provided, it is a form which will be evaluated before each\n  run of the formatter, and is expected to return a temporary\n  file path suitable for holding the region to be reformatted.\n  It must not produce the same path as the current buffer's file\n  if that is set: you shouldn't be operating directly on the\n  buffer's backing file.  The temporary input file will be\n  deleted automatically.  You might find the functions\n  `reformatter-temp-file-in-current-directory' and\n  `reformatter-temp-file' helpful.\n\nMODE\n\n  Unless nil, also generate a minor mode that will call the\n  reformatter command from `before-save-hook' when enabled.\n  Default is t.\n\nGROUP\n\n  If provided, this is the custom group used for any generated\n  modes or custom variables.  Don't forget to declare this group\n  using a `defgroup' form.\n\nLIGHTER\n\n  If provided, this is a mode lighter string which will be used\n  for the \"-on-save\" minor mode.  It should have a leading\n  space.  The supplied value will be used as the default for a\n  generated custom variable which specifies the mode lighter.\n  Default is nil, ie. no lighter.\n\nKEYMAP\n\n  If provided, this is the symbol name of the \"-on-save\" mode's\n  keymap, which you must declare yourself.  Default is no keymap.\n\nEXIT-CODE-SUCCESS-P\n\n  If provided, this is a function object callable with `funcall'\n  which accepts an integer process exit code, and returns non-nil\n  if that exit code is considered successful.  This could be a\n  lambda, quoted symbol or sharp-quoted symbol.  If not supplied,\n  the code is considered successful if it is `zerop'." #<bytecode 0x71344507b5c722c>)(phpcbf-fmt :program (format "%s/vendor/bin/phpcbf" (getenv "PRJ_ROOT")) :args (list "--stdin-path" input-file "-q" "-") :exit-code-success-p #'(lambda (exit-code) (or (= 0 exit-code) (= 1 exit-code))))
  (reformatter-define phpcbf-fmt :program (format "%s/vendor/bin/phpcbf" (getenv "PRJ_ROOT")) :args (list "--stdin-path" input-file "-q" "-") :exit-code-success-p #'(lambda (exit-code) (or (= 0 exit-code) (= 1 exit-code))))
  #f(lambda () [t] (reformatter-define php-cs-fixer-fmt :program (format "%s/vendor/bin/php-cs-fixer" (getenv "PRJ_ROOT")) :args '("fix" "--diff" "--using-cache=no" "-q" "-")) (reformatter-define phpcbf-fmt :program (format "%s/vendor/bin/phpcbf" (getenv "PRJ_ROOT")) :args (list "--stdin-path" input-file "-q" "-") :exit-code-success-p #'(lambda (exit-code) (or (= 0 exit-code) (= 1 exit-code)))))()
  eval-after-load-helper("/home/cdom/.cache/ceamx/packages/30.0/elpaca/builds/reformatter/reformatter.elc")
  do-after-load-evaluation("/home/cdom/.cache/ceamx/packages/30.0/elpaca/builds/reformatter/reformatter.elc")
  require(reformatter)
  (progn (require 'reformatter))
  eval((progn (require 'reformatter)) t)
...
@DamienCassou
Copy link
Contributor

I tried the same and it works for me.

@purcell
Copy link
Owner

purcell commented Aug 5, 2024

Yes, same here @DamienCassou. Is this error reproducible for you, @montchr? If so, what Emacs and reformatter versions do you have?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants