0

I've got a weird bug in a GraphQL encoder I'm writing that I've tracked down to one form:

(symbol-name 'world)

;; yields
#("world" 0 5
  (fontified t))

I can reproduce the issue in a *scratch* buffer in that same emacs session and with M-:, but it's not reproducible in a new emacs session (e.g., emacs -nw -Q).

This doesn't happen with all symbols; (symbol-name 'hello) yields just "hello".


The following snippet can reproduce the issue, but I still have no idea what would be using make-symbol in this way.

(let ((sym (make-symbol (let ((s "hello world"))
                          (set-text-properties 0 (length s) '(test property) s)
                          s))))
  (symbol-name sym))
  • Considering that you can't reproduce this problem in a new Emacs instance without your init file loaded, it could be the problem. Try building the minimal case with this problem with minimal configuration. – DoMiNeLa10 Dec 10 '17 at 17:18
  • If it were that simple, I would've done so (and probably wouldn't have needed to ask the Q) :-) I know from the C source that symbol-name is just retrieving the name property (a Lisp_Object) from the symbol (passing through macro XSYMBOL) which would leave me to believe the name was somehow fontified when the world symbol was interned (possibly when read), but I can't seem to validate that. – Sean Allred Dec 10 '17 at 17:31
  • As you know, the value of symbol-name is a string, and strings in Emacs Lisp can have text properties. Look for a use of make-symbol or intern that receives a propertized string as argument. Note that the Lisp reader creates and interns symbols when it reads. – Drew Dec 10 '17 at 17:32
  • @Drew thanks :-) I think all name-setting for lisp objects is funneled through set_symbol_name which in turn is only called by init_symbol which is exposed in make-symbol and indeed called in lread.c:define_symbol. The lisp object define_symbol passes to init_symbol as name is a plain old char * run through alloc.c:make_pure_c_string. At that point, it seems unlikely that we'd just be adding text properties arbitrarily, so I'm guessing there's some wacky use of make-symbol going on somewhere. – Sean Allred Dec 10 '17 at 17:39
  • And indeed, (let ((sym (make-symbol (let ((s "hello world")) (set-text-properties 0 (length s) '(test property) s) s)))) (symbol-name sym)) can reproduce the issue, but I still have no idea what would be using make-symbol in this way. – Sean Allred Dec 10 '17 at 17:43
2

The function symbol-at-point do such thing.

And it can be used in extensions of modes like auto-complete or font-lock or anywhere else for parse buffer. And in this case, each time, when it will be apply to point on symbol which is not yet interned, it will intern this symbol with all text properties.

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.