emacsfodder / move-text

move current line or region up or down
196 stars 12 forks source link

Debugger entered--Lisp error: (void-variable repeat) #24

Closed failable closed 2 years ago

failable commented 2 years ago

After a recent update, I get the following error when using move-text-down

Debugger entered--Lisp error: (void-variable repeat)
  move-text-down(nil nil 1)
  funcall-interactively(move-text-down nil nil 1)
  call-interactively(move-text-down nil nil)
  command-execute(move-text-down)
jasonm23 commented 2 years ago

Please supply environment details:

jasonm23 commented 2 years ago

I am guessing that you're using 28.2

repeat is symbol that was recognized in cl-loop

See:

However, a quick check...

require 'cl-lib)
(cl-loop repeat 10 do (message "Hi %s" repeat))

Throws the same error, as you can see in the tests (Actions tab), this was working in all versions 24.x-28.x & on dev snapshot 29.x

jasonm23 commented 2 years ago

You should report it to GNU Emacs as a bug, please post the reference here once you're done.

failable commented 2 years ago

Hi, the environments is

jasonm23 commented 2 years ago

Does the sample code work in your *scratch*

(require 'cl-lib)
(cl-loop repeat 10 do (message "Hi"))
failable commented 2 years ago

No, it does not

Debugger entered--Lisp error: (void-variable repeat)
  (message "Hi %s" repeat)
  (while (>= (setq --cl-var-- (1- --cl-var--)) 0) (message "Hi %s" repeat))
  (let* ((--cl-var-- 10)) (while (>= (setq --cl-var-- (1- --cl-var--)) 0) (message "Hi %s" repeat)) nil)
  eval((let* ((--cl-var-- 10)) (while (>= (setq --cl-var-- (1- --cl-var--)) 0) (message "Hi %s" repeat)) nil) nil)
  elisp--eval-last-sexp(nil)
  #f(compiled-function (eval-last-sexp-arg-internal) "Evaluate sexp before point; print value in the echo area.\nInteractively, with a non `-' prefix argument, print output into\ncurrent buffer.\n\nThis commands handles `defvar', `defcustom' and `defface' the\nsame way that `eval-defun' does.  See the doc string of that\nfunction for details.\n\nNormally, this function truncates long output according to the\nvalue of the variables `eval-expression-print-length' and\n`eval-expression-print-level'.  With a prefix argument of zero,\nhowever, there is no such truncation.\nInteger values are printed in several formats (decimal, octal,\nand hexadecimal).  When the prefix argument is -1 or the value\ndoesn't exceed `eval-expression-print-maximum-character', an\ninteger value is also printed as a character of that codepoint.\n\nIf `eval-expression-debug-on-error' is non-nil, which is the default,\nthis command arranges for all errors to enter the debugger." (interactive "P") #<bytecode -0x1c0ccb60d49ed0ff>)(nil)
  #f(compiled-function (&rest _it) #<bytecode 0x51fde3bc4a7df66>)()
  eval-sexp-fu-flash-doit-simple(#f(compiled-function (&rest _it) #<bytecode 0x51fde3bc4a7df66>) #f(compiled-function (&rest args2) #<bytecode -0x1402661dfdb950a3>) #f(compiled-function (&rest args2) #<bytecode 0x227c22a7a10af45>))
  eval-sexp-fu-flash-doit(#f(compiled-function (&rest _it) #<bytecode 0x51fde3bc4a7df66>) #f(compiled-function (&rest args2) #<bytecode -0x1402661dfdb950a3>) #f(compiled-function (&rest args2) #<bytecode 0x227c22a7a10af45>))
  esf-flash-doit(#f(compiled-function (&rest _it) #<bytecode 0x51fde3bc4a7df66>) #f(compiled-function (&rest args2) #<bytecode -0x1402661dfdb950a3>) #f(compiled-function (&rest args2) #<bytecode 0x227c22a7a10af45>) #f(compiled-function (&rest args2) #<bytecode -0x1401e0bc3a5cc0a3>))
  ad-Advice-eval-last-sexp(#f(compiled-function (eval-last-sexp-arg-internal) "Evaluate sexp before point; print value in the echo area.\nInteractively, with a non `-' prefix argument, print output into\ncurrent buffer.\n\nThis commands handles `defvar', `defcustom' and `defface' the\nsame way that `eval-defun' does.  See the doc string of that\nfunction for details.\n\nNormally, this function truncates long output according to the\nvalue of the variables `eval-expression-print-length' and\n`eval-expression-print-level'.  With a prefix argument of zero,\nhowever, there is no such truncation.\nInteger values are printed in several formats (decimal, octal,\nand hexadecimal).  When the prefix argument is -1 or the value\ndoesn't exceed `eval-expression-print-maximum-character', an\ninteger value is also printed as a character of that codepoint.\n\nIf `eval-expression-debug-on-error' is non-nil, which is the default,\nthis command arranges for all errors to enter the debugger." (interactive "P") #<bytecode -0x1c0ccb60d49ed0ff>) nil)
  apply(ad-Advice-eval-last-sexp #f(compiled-function (eval-last-sexp-arg-internal) "Evaluate sexp before point; print value in the echo area.\nInteractively, with a non `-' prefix argument, print output into\ncurrent buffer.\n\nThis commands handles `defvar', `defcustom' and `defface' the\nsame way that `eval-defun' does.  See the doc string of that\nfunction for details.\n\nNormally, this function truncates long output according to the\nvalue of the variables `eval-expression-print-length' and\n`eval-expression-print-level'.  With a prefix argument of zero,\nhowever, there is no such truncation.\nInteger values are printed in several formats (decimal, octal,\nand hexadecimal).  When the prefix argument is -1 or the value\ndoesn't exceed `eval-expression-print-maximum-character', an\ninteger value is also printed as a character of that codepoint.\n\nIf `eval-expression-debug-on-error' is non-nil, which is the default,\nthis command arranges for all errors to enter the debugger." (interactive "P") #<bytecode -0x1c0ccb60d49ed0ff>) nil)
  eval-last-sexp(nil)
  funcall-interactively(eval-last-sexp nil)
  call-interactively(eval-last-sexp nil nil)
  command-execute(eval-last-sexp)
jasonm23 commented 2 years ago

How about this...

(require 'cl-lib)
(cl-loop repeat 10 do (message "Hi"))
failable commented 2 years ago

Yes, it evaluates to nil.

failable commented 2 years ago

I think the issue may due to missing lexical-binding in move-text.el

;;; move-text.el --- Move current line or region with M-up or M-down.  -*- lexical-binding: t; -*-
jasonm23 commented 2 years ago

Ok, it's a wierd error, the first sample code SHOULD have error'd

It has nothing to do with lexical binding FYI.

The repeat at L175 & L183 is just a keyword in cl-loop

M-x describe-function <RET> cl-loop
C-s repeat 
jasonm23 commented 2 years ago

Wait, Did you add lexical binding and try it?

failable commented 2 years ago

It has nothing to do with lexical binding FYI.

I don't know. I know little elisp. Adding the lexical-binding part and re-evaluate the whole file works for me.

jasonm23 commented 2 years ago

Oh, that's interesting. But had you re-eval'ed before and tried again already?

failable commented 2 years ago

OK, I tested multiple times. It is not related to lexical-binding, but evaluating the file manually. I use the following setup with straight.el and use-package.

(use-package move-text
  :bind
  (("M-p" . move-text-up)
   ("M-n" . move-text-down)))

After I start Emacs, the issue exists (by calling M-n) until I open move-text.el and evaluate it manually.

jasonm23 commented 2 years ago

ok, so without modification, it works if you re-eval?

failable commented 2 years ago

Yes!

jasonm23 commented 2 years ago

The issue you have is with the .elc being older than the .el.

Anyway you helped to uncover a related issue in 28.2... so hold on a moment while I push the update.

failable commented 2 years ago

But I've deleted build/move-text/move-text.elc in the straight.el directory... and rebuild multiple times...

Maximin@macOS: ~ rm ~/.emacs.d/straight/build/move-text/move-text.
move-text.el   move-text.elc  
Maximin@macOS: ~ rm ~/.emacs.d/straight/build/move-text/move-text.elc

The issue still exists.

jasonm23 commented 2 years ago

Ok the fix just requires cl-lib explicitly, which it should have done before.

jasonm23 commented 2 years ago

The error should be about cl-loop not defined.

failable commented 2 years ago

Works now! Thank you!

jasonm23 commented 2 years ago

Cool! Thanks for helping fix it.