unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* help with wrong-number-of-arguments
@ 2023-09-26 13:40 hw
  2023-09-26 14:11 ` Stephen Berman
  0 siblings, 1 reply; 3+ messages in thread
From: hw @ 2023-09-26 13:40 UTC (permalink / raw)
  To: help-gnu-emacs

Hi,

I created the function at [1] a while ago and bound it to C-x t i, and
it has been working fine.  Now when I press C-x t i, I'm getting


Debugger entered--Lisp error: (wrong-number-of-arguments #<subr my-perltidy-replace> 1)
  my-perltidy-replace(nil)
  funcall-interactively(my-perltidy-replace nil)
  command-execute(my-perltidy-replace)


What might have changed is the emacs version because I built one that
uses wayland, but I don't remember if it used to work with the wayland
version.

I'm guessing that emacs now figures that the function is getting an
argument where it doesn't take one, and I fail to make sense of
this. How can I fix this?


[1]:


(defun my-perltidy-replace ()
  "This function replaces the contents of the current buffer with
the output of perltidy, and makes a backup of the current buffer.
The backup is then saved."
  (interactive "P")
  (let ((tidy_buffer (generate-new-buffer (generate-new-buffer-name (concat "TidyBackup-" (buffer-name))))))
    (with-current-buffer (buffer-name)
      (shell-command-on-region (point-min) (point-max) "perltidy --standard-output" tidy_buffer)
      (buffer-swap-text tidy_buffer))
    (with-current-buffer tidy_buffer
      (let ((visiting_file (generate-new-buffer-name (concat "~/tmp/TidyBackup/" (buffer-name)))))
      (set-visited-file-name visiting_file)
      (save-buffer)
      (message "backup saved as %s" visiting_file)))))




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: help with wrong-number-of-arguments
  2023-09-26 13:40 help with wrong-number-of-arguments hw
@ 2023-09-26 14:11 ` Stephen Berman
  2023-09-26 16:14   ` SOVLED: " hw
  0 siblings, 1 reply; 3+ messages in thread
From: Stephen Berman @ 2023-09-26 14:11 UTC (permalink / raw)
  To: hw; +Cc: help-gnu-emacs

On Tue, 26 Sep 2023 15:40:08 +0200 hw <hw@adminart.net> wrote:

> Hi,
>
> I created the function at [1] a while ago and bound it to C-x t i, and
> it has been working fine.  Now when I press C-x t i, I'm getting
>
>
> Debugger entered--Lisp error: (wrong-number-of-arguments #<subr my-perltidy-replace> 1)
>   my-perltidy-replace(nil)
>   funcall-interactively(my-perltidy-replace nil)
>   command-execute(my-perltidy-replace)
>
>
> What might have changed is the emacs version because I built one that
> uses wayland, but I don't remember if it used to work with the wayland
> version.
>
> I'm guessing that emacs now figures that the function is getting an
> argument where it doesn't take one, and I fail to make sense of
> this. How can I fix this?

Change the line `(interactive "P")' to `(interactive")'.  I don't see
how it could have worked before, since `(interactive "P")' means the
command can be called with a raw prefix argument, so it would have to be
defined e.g. like this: (defun my-perltidy-replace (&optional arg)...

Steve Berman

>
>
> [1]:
>
>
> (defun my-perltidy-replace ()
>   "This function replaces the contents of the current buffer with
> the output of perltidy, and makes a backup of the current buffer.
> The backup is then saved."
>   (interactive "P")
>   (let ((tidy_buffer (generate-new-buffer (generate-new-buffer-name (concat "TidyBackup-" (buffer-name))))))
>     (with-current-buffer (buffer-name)
>       (shell-command-on-region (point-min) (point-max) "perltidy --standard-output" tidy_buffer)
>       (buffer-swap-text tidy_buffer))
>     (with-current-buffer tidy_buffer
>       (let ((visiting_file (generate-new-buffer-name (concat "~/tmp/TidyBackup/" (buffer-name)))))
>       (set-visited-file-name visiting_file)
>       (save-buffer)
>       (message "backup saved as %s" visiting_file)))))



^ permalink raw reply	[flat|nested] 3+ messages in thread

* SOVLED: help with wrong-number-of-arguments
  2023-09-26 14:11 ` Stephen Berman
@ 2023-09-26 16:14   ` hw
  0 siblings, 0 replies; 3+ messages in thread
From: hw @ 2023-09-26 16:14 UTC (permalink / raw)
  To: help-gnu-emacs

On Tue, 2023-09-26 at 16:11 +0200, Stephen Berman wrote:
> On Tue, 26 Sep 2023 15:40:08 +0200 hw <hw@adminart.net> wrote:
> 
> > Hi,
> > 
> > I created the function at [1] a while ago and bound it to C-x t i, and
> > it has been working fine.  Now when I press C-x t i, I'm getting
> > 
> > 
> > Debugger entered--Lisp error: (wrong-number-of-arguments #<subr my-perltidy-replace> 1)
> >   my-perltidy-replace(nil)
> >   funcall-interactively(my-perltidy-replace nil)
> >   command-execute(my-perltidy-replace)
> > 
> > 
> > What might have changed is the emacs version because I built one that
> > uses wayland, but I don't remember if it used to work with the wayland
> > version.
> > 
> > I'm guessing that emacs now figures that the function is getting an
> > argument where it doesn't take one, and I fail to make sense of
> > this. How can I fix this?
> 
> Change the line `(interactive "P")' to `(interactive")'.  I don't see
> how it could have worked before, since `(interactive "P")' means the
> command can be called with a raw prefix argument, so it would have to be
> defined e.g. like this: (defun my-perltidy-replace (&optional arg)...

Thank you very much, it works now :)

> 
> Steve Berman
> 
> > 
> > 
> > [1]:
> > 
> > 
> > (defun my-perltidy-replace ()
> >   "This function replaces the contents of the current buffer with
> > the output of perltidy, and makes a backup of the current buffer.
> > The backup is then saved."
> >   (interactive "P")
> >   (let ((tidy_buffer (generate-new-buffer (generate-new-buffer-name (concat "TidyBackup-" (buffer-name))))))
> >     (with-current-buffer (buffer-name)
> >       (shell-command-on-region (point-min) (point-max) "perltidy --standard-output" tidy_buffer)
> >       (buffer-swap-text tidy_buffer))
> >     (with-current-buffer tidy_buffer
> >       (let ((visiting_file (generate-new-buffer-name (concat "~/tmp/TidyBackup/" (buffer-name)))))
> >       (set-visited-file-name visiting_file)
> >       (save-buffer)
> >       (message "backup saved as %s" visiting_file)))))
> 





^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-09-26 16:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-26 13:40 help with wrong-number-of-arguments hw
2023-09-26 14:11 ` Stephen Berman
2023-09-26 16:14   ` SOVLED: " hw

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).