2

Is it possible to comment the string "emacs" below while keeping this code one line? If so, how?

 (message "hi") "emacs" (message "hi!")
6

For the usual meaning of "comment", the answer is mostly no (see Dan answer for details), but if you just want to prevent code from being executed, then you can simply do nothing in your case, since the execution of "emacs" will not have any visible effect. If you want to use it on elements whose execution does have visible effects, you can use

(defmacro comment-out (&rest args) nil)

after which you can do things like:

(message "foo") (comment-out (message "bar")) (message "baz")
  • can't believe this! This is the closest match in answers I have seen being posted at the same time :D – Kaushal Modi Aug 12 '16 at 20:00
  • Of course this is valid in a progn or similar construct, not e.g. in the middle of function arguments. – YoungFrog Aug 13 '16 at 9:54
4

It looks like the answer is no, you cannot.

The elisp manual node on Comments states that:

In Lisp, a semicolon (;) starts a comment if it is not within a string or character constant. The comment continues to the end of line.

It also, however, goes on to say that:

The #@count construct, which skips the next count characters, is useful for program-generated comments containing binary data. The Emacs Lisp byte compiler uses this in its output files (see Byte Compilation). It isn't meant for source files, however.

The manual index links the #@count construct to Documentation Strings and Compilation. It states:

Internally, the dynamic loading of documentation strings is accomplished by writing compiled files with a special Lisp reader construct, #@count. This construct skips the next count characters. It also uses the #$ construct, which stands for "the name of this file, as a string". Do not use these constructs in Lisp source files; they are not designed to be clear to humans reading the file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.