0

Windows 7, emacs 29.1

Is there a way to tell emacs to test for a null without entering a null in elisp?

Putting a null anywhere in my elisp produces "Error: End of file during parsing".

Variations of this won't compile:

(if (looking-at "X")     ;"X" is a null, i.e. CTRL-@ (CTRL-SHIFT-2).

                         ;I didn't want to insert a null in this post.

  (message "%s" "match")
  (message "%s" "not match")
)
5
  • emacs.stackexchange.com/tags/elisp/info Commented Jan 16, 2024 at 21:18
  • 1
    How are you trying to insert a null character/byte? Show your code, please, and format it using 3 backquotes before and after it. Commented Jan 16, 2024 at 21:19
  • ``` ; Here is my elisp, with a null byte in the looking-at ; I use CTRL-Q CTRL-@ to insert the null ;(The forum software has replaced my null with "\0".) (if (looking-at "\0") (message "%s" "match") (message "%s" "not match") ) ``` Commented Jan 16, 2024 at 22:56
  • 2
    As it happens (per the referenced docs), the forum software is correct. Commented Jan 16, 2024 at 23:46
  • Put such info in the question, not in a comment. Put all info relevant to your question in the question itself. Comments can be deleted at any time, and they're not searchable. Commented Jan 17, 2024 at 1:47

1 Answer 1

3

See the elisp manual:

  • C-hig (elisp)General Escape Syntax
  • C-hig (elisp)Non-ASCII in Strings

Per those docs, the null character syntax is ?\000 or just ?\0, and therefore you can include a null character in string syntax as "\000" or just "\0".

4
  • A good thought, but I haven't figured out how to get a null byte into looking-at's regular expression. Commented Jan 16, 2024 at 23:24
  • 2
    If you'd looked at that documentation you'd already know (see the final paragraph). Commented Jan 16, 2024 at 23:41
  • 1
    I've updated the answer with those details from the manual... but it was all there (and cross-linked) from the node I gave you initially. Please do read the docs that people point you to. Commented Jan 17, 2024 at 8:05
  • @phils while it's very helpful to provide references for your answer, it is the custom (and policy, afaik) on Stack Exchange to include at least a summary of the salient points in the answer, both in case the referenced document vanishes or is rewritten such that the desired information is no longer found in the indicated place, and also in case it's not totally obvious to the reader which parts are salient to the question and how. Commented Jul 25 at 18:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.