Search code examples
emacselisp

How to retrieve a name of the frame in Emacs?


I'd like to retrieve a name of the current frame using elisp. I have discovered that name is a part of frame's properties. The properties is an associated list. I do the following:

(cdr (assoc 'name (frame-parameters)))

But instead of the expected name I receive a mixed list of the name and some properties:

#("main-1" 0 5 (face nil) 5 6 (face nil))

How can I extract "main-1" from this?


Solution

  • There are text properties on that string. You can use substring-no-properties to extract the plain string.

    (substring-no-properties
     (cdr (assoc 'name (frame-parameters))))
    

    Note that you may not need to do this. The propertized string is still a string, and equal to its no-properties version.

    See also: C-hig (elisp) Text Props and Strings RET