Skip to main content
added 1265 characters in body
Source Link
John Kitchin
  • 12.1k
  • 1
  • 23
  • 45

This is already a functionality in emacs:

(ignore
 ...)

See: C-h f ignore.

As noted by @shynur, that is a function though, so the arguments will be evaluated, which is not desirable. A macro is the path to avoid that, but it will at a minimum expand to nil. There are scenarios where that is not the right thing to do though (e.g. https://stackoverflow.com/questions/75775454/how-to-define-a-macro-that-returns-nothing), and there are likewise scenarios where it is not correct to return nothing (i.e. as if the code was not there).

For the first case consider:

(+ 8 (off 4))

if off returns nil, this will be an error since you can't add 8 and nil.

For the second case example, consider:

(message "%s" (off (some-code)))

That will give rise to an error if somehow the off macro somehow results in nothing in that position because there would not be enough arguments for the format string.

There isn't a solution for both issues I think.

A comment approach is to wrap the body in (progn ...), and use something like lispy-comment that comments out the sexp if you type ; in front of it, and C-u ; to uncomment the body. There is nothing more simple than this. Even if you had a macro for off, undoing it is more work than this solution, unless you do something like replace off with progn I think.

This is already a functionality in emacs:

(ignore
 ...)

See: C-h f ignore

This is already a functionality in emacs:

(ignore
 ...)

See: C-h f ignore.

As noted by @shynur, that is a function though, so the arguments will be evaluated, which is not desirable. A macro is the path to avoid that, but it will at a minimum expand to nil. There are scenarios where that is not the right thing to do though (e.g. https://stackoverflow.com/questions/75775454/how-to-define-a-macro-that-returns-nothing), and there are likewise scenarios where it is not correct to return nothing (i.e. as if the code was not there).

For the first case consider:

(+ 8 (off 4))

if off returns nil, this will be an error since you can't add 8 and nil.

For the second case example, consider:

(message "%s" (off (some-code)))

That will give rise to an error if somehow the off macro somehow results in nothing in that position because there would not be enough arguments for the format string.

There isn't a solution for both issues I think.

A comment approach is to wrap the body in (progn ...), and use something like lispy-comment that comments out the sexp if you type ; in front of it, and C-u ; to uncomment the body. There is nothing more simple than this. Even if you had a macro for off, undoing it is more work than this solution, unless you do something like replace off with progn I think.

Source Link
John Kitchin
  • 12.1k
  • 1
  • 23
  • 45

This is already a functionality in emacs:

(ignore
 ...)

See: C-h f ignore