0

There is a nice concept of 'WYSIWYG' meaning 'What You See Is What You Get', but it seems that it is hard to get what I can see in an 'Emacs window' ('Emacs window' is what would in common sense be called 'multiline text element/widget').

If I choose to save what I see in an 'Emacs window' some information which must be available in the underlying 'Emacs buffer' to allow to follow links or to show images get lost.

Is there a way to save what I will describe as 'complete internal data representation' of what is visualized by Emacs in an 'Emacs window'?


UPDATE explaining more about the context of the question as answer to a comment asking What is it you really want to be able to do?

I would like to be able to save the to me shown content to view it later without triggering of its entire context when such context is maybe later on no more available.

If I want to see or modify what I see on the info-help-pages I go to the source code of them and change it. If I want to see and modify a web page I work on the HTML code of it. If I want to modify an image I work on the binary data of the image file. Isn't there a kind of "language" Emacs is using to provide the visual and interactive features? Like info-pages or man-pages do or XML or other markup approaches allow?

I want to be able to go down to the 'source code' of the graphical content seen on the screen I order to be able to reuse it in own context or even to just only to be able to see it again as it was displayed to me. It's like saving a Terminal session with all the escape formatting and other control codes used to display the text.

OK ... it's probably already more about the context as was asked for. Is the question now clear and focused on one specific detail? In other words the core of the question is:

How to export the internal Emacs buffer representation in order to load it again later and see the same graphical output including the embedded interactive behavior?

4
  • Not really. You would need to save lots of stuff about the current state of Emacs and the buffer displayed in the window, including its overlays. This sounds a lot like an X-Y question. What is it you really want to be able to do?
    – Drew
    Mar 22 at 16:49
  • I can't see how the X-Y question relates to what I am asking for. I want just to re-display interactive graphical content like I do saving the HTML of a web-page. And if the answer is "not really", that raises another question about what "Open Source" actually is if you screw it to a degree that it becomes too complex for not-involved to be able to work on it. The industry has shown already how to screw HTML with JavaScript and CSS so that it's no more possible to work on the actual source code of the displayed web-page or even get all of what is needed to display what you see ...
    – Claudio
    Mar 22 at 19:53
  • 1
    Emacs is Free Software ( fsf.org/about/what-is-free-software ) which has absolutely no relevance to the complexity or simplicity of a program and/or its data formats. (The same thing applies equally to Open Source.)
    – phils
    Mar 22 at 22:45
  • 3
    In Emacs Lisp, variables can be buffer-local, that is to say, the buffer is more or less part of the environment which affects variables’ bindings. If you want to copy some content (probably associated with some data structures) from one buffer to another, such a problem will present itself to you, i.e., HOW TO CREATE A SIMILAR ENVIRONMENT for the content. So in my opinion, you need to figure out for yourself what data you want to copy (and for that, you need to know some details).
    – shynur
    Mar 23 at 13:21

1 Answer 1

1

The internal format is not something you would want to edit by hand, and it doesn’t necessarily even contain all information sufficient to completely reproduce the appearance. For example, here is the internal representation of my *scratch* buffer, with just the default text in it:

#(";; This buffer is for text that is not saved, and for Lisp evaluation.
;; To create a file, visit it with C-x C-f and enter text in its buffer.
"
  0 2 (face font-lock-comment-delimiter-face fontified t)
  2 3 (face whitespace-space fontified t)
  3 7 (face font-lock-comment-face fontified t)
  7 8 (face whitespace-space fontified t)
  8 14 (face font-lock-comment-face fontified t)
  14 15 (face whitespace-space fontified t)
  15 17 (face font-lock-comment-face fontified t)
  17 18 (face whitespace-space fontified t)
  18 21 (face font-lock-comment-face fontified t)
  21 22 (face whitespace-space fontified t)
  22 26 (face font-lock-comment-face fontified t)
  26 27 (face whitespace-space fontified t)
  27 31 (face font-lock-comment-face fontified t)
  31 32 (face whitespace-space fontified t)
  32 34 (face font-lock-comment-face fontified t)
  34 35 (face whitespace-space fontified t)
  35 38 (face font-lock-comment-face fontified t)
  38 39 (face whitespace-space fontified t)
  39 45 (face font-lock-comment-face fontified t)
  45 46 (face whitespace-space fontified t)
  46 49 (face font-lock-comment-face fontified t)
  49 50 (face whitespace-space fontified t)
  50 53 (face font-lock-comment-face fontified t)
  53 54 (face whitespace-space fontified t)
  54 58 (face font-lock-comment-face fontified t)
  58 59 (face whitespace-space fontified t)
  59 71 (face font-lock-comment-face fontified t)
  71 73 (face font-lock-comment-delimiter-face fontified t)
  73 74 (face whitespace-space fontified t)
  74 76 (face font-lock-comment-face fontified t)
  76 77 (face whitespace-space fontified t)
  77 83 (face font-lock-comment-face fontified t)
  83 84 (face whitespace-space fontified t)
  84 85 (face font-lock-comment-face fontified t)
  85 86 (face whitespace-space fontified t)
  86 91 (face font-lock-comment-face fontified t)
  91 92 (face whitespace-space fontified t)
  92 97 (face font-lock-comment-face fontified t)
  97 98 (face whitespace-space fontified t)
  98 100 (face font-lock-comment-face fontified t)
  100 101 (face whitespace-space fontified t)
  101 105 (face font-lock-comment-face fontified t)
  105 106 (face whitespace-space fontified t)
  106 109 (face font-lock-comment-face fontified t font-lock-face help-key-binding)
  109 110 (face whitespace-space fontified t font-lock-face help-key-binding)
  110 113 (face font-lock-comment-face fontified t font-lock-face help-key-binding)
  113 114 (face whitespace-space fontified t)
  114 117 (face font-lock-comment-face fontified t)
  117 118 (face whitespace-space fontified t)
  118 123 (face font-lock-comment-face fontified t)
  123 124 (face whitespace-space fontified t)
  124 128 (face font-lock-comment-face fontified t)
  128 129 (face whitespace-space fontified t)
  129 131 (face font-lock-comment-face fontified t)
  131 132 (face whitespace-space fontified t)
  132 135 (face font-lock-comment-face fontified t)
  135 136 (face whitespace-space fontified t)
  136 144 (face font-lock-comment-face fontified t))

Notice that I have carefully wrapped it to show the “structure” of it more clearly; it will normally be given to you on a single line.

I got this by evaluating (buffer-substring (point-min) (point-max)) using M-:, but there are several other ways to do it all with advantages and disadvantages of their own.

Nobody ever writes or edits this crap by hand, ever. It’s purely an internal implementation detail of Emacs and is subject to changes from version to version. As you can see, while it specifies that some of the text is styled with font-lock-comment-face and other parts with whitespace-face, it doesn’t tell you what those faces look like. Those will look different for you than for me, because we have different config files, we use different themes, etc.

What you should do instead is edit some other type of file and rely on Emacs to render it the same way each time. You could write an org-mode file, for example, or enriched-mode, or html-mode or any other that is useful to you. Each of these has documentation that comes with Emacs. Org mode comes with it’s own entire manual, while the others just get a chapter in the Emacs manual. There are of course thousands of modes, and any one of them might suit you better than the ones I’ve mentioned.

8
  • Or slightly more succinct: M-: (buffer-string)
    – phils
    Mar 22 at 22:54
  • I forgot about that one :)
    – db48x
    Mar 23 at 5:02
  • I would like to be able to save the to me shown content in order to view it later . So how to view it later? And how to preload the right font face values?
    – Claudio
    Mar 23 at 12:36
  • I am getting on the same buffer a much shorter output (8 lines in total). Text-blocks are divided by comment markings only (and not at each whitespace).
    – Claudio
    Mar 23 at 12:57
  • I know, what we each see is highly dependent on our individual preferences.
    – db48x
    Mar 23 at 13:53

Your Answer

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

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