[Date Prev][Date Next][Thread Prev][][Date Index][Thread Index]


In [emacs-w3m:13457]
On Mon, 17 Jun 2019 16:12:26 +0900, Katsumi Yamaoka wrote:
> Still uses lexical-let, using the lexical-binding would be the
> next step.

Turned on lexical-binding in files that used to use lexical-let:
  mew-w3m.el, w3m-antenna.el, w3m-ems.el, w3m-favicon.el,
  w3m-image.el, w3m-proc.el, w3m-weather.el, w3m.el

lexical-binding basics:
  The values of arguments of a function or let-bound variables
are inherited to a sub process even if the sub process runs
after the parent function or the let-binding is released.  So,
this code works if `lexical-binding' is set to non-nil, whereas
the `(void-variable text)' error occurs if it is nil:

(let ((text "Hello World"))
  (run-at-time 3 nil (lambda () (message "%s" text))))

In such a case, we used to use this way:

(lexical-let ((text "Hello World"))
  (run-at-time 3 nil (lambda () (message "%s" text))))

  Turning on or off the lexical-binding should be done per an
ELisp source file.  To turn it on, add this cookie in the
beginning of a file: -*- lexical-binding: t -*-
In the *scratch* buffer, you can do: (setq lexical-binding t)

  It's quite easy, isn't it?  It is true in some cases, however
you will probably be annoyed with a lot of warnings when you
byte-compile a file.  They look like:

	Warning: Unused lexical argument `args'
	Warning: Unused lexical variable `handler'

  `args' is an argument of a function, and the warning means
the `args' argument is not referenced in the function definition.
This includes the case where the argument does not appear on the
looks of the function definition even though it is actually used

  To silence the compiler, rename `args' to `_args', or if it can
not be renamed, put `(ignore args)' just after the doc string of
the function. `(ignore..)' allows two or more names as well.
  But if you get this kind of warning after renaming,

	Warning: argument `_args' not left unused

the argument `_args' is referenced practically somewhere.  It
might be in the definition of a macro that the function uses.

  `handler' is a variable that `let' binds, and the warning means
it is not referenced within the `let' form.  The ways to silence
the byte compiler are the same as those for function arguments.