all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* How to save invisible (lisp) data in a text file
@ 2014-08-21 14:04 sokobania
  2014-08-21 18:28 ` Stefan Monnier
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: sokobania @ 2014-08-21 14:04 UTC (permalink / raw
  To: help-gnu-emacs

I would like to do the following:
- display some normal text in a buffer with some major
  mode named "my-special-mode"
- let the user interact with the buffer contents
- store in ram some lisp data generated by the user interaction
  (like marks and extra text not displayed in the buffer)
- store the normal text AND this extra data in a file

Then, when reopening the file, emacs would:
- display the normal text in a buffer with "my-special-mode"
- reinstall in ram the lisp data associated to the file

Is this possible with emacs?

Oops... As the answer to "Is this possible with emacs?"
is always "yes", I would rather ask:

Is there a simple way (functions, mode, package...) to do that?
Are there any (simple) emacs-lisp examples of such a thing?

At the moment, the solution I was thinking of
would be to use file variables.
The major mode "my-special-mode" would:
- delete the last lines of the buffer when invoked
- add a hook to save-file to write the extra data at the end
of the file in a few lines like:

<my-special-mode-delimiter>
Local Variables:
mode: my-special-mode
my-special-mode-data: '(all I need to save to rebuild the data)
End:

It seems rather simple. Is it correct/standard?
Is there any mode which does something similar?
(write data into the "Local Variables:" section)

)jack(


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: How to save invisible (lisp) data in a text file
       [not found] <mailman.185.1408636859.24723.help-gnu-emacs@gnu.org>
@ 2014-08-21 16:38 ` Buchs, Kevin J.
  0 siblings, 0 replies; 9+ messages in thread
From: Buchs, Kevin J. @ 2014-08-21 16:38 UTC (permalink / raw
  To: help-gnu-emacs

Search these words: serialization in emacs lisp
and you will find some libraries/packages that can handle this for you.

Kevin Buchs   Research Computer Services   Phone: 507-538-5459
Mayo Clinic   200 1st. St SW   Rochester, MN 55905
http://mayoclinic.org  http://facebook.com/MayoClinic  http://youtube.com/MayoClinic  http://twitter.com/MayoClinic






^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: How to save invisible (lisp) data in a text file
  2014-08-21 14:04 How to save invisible (lisp) data in a text file sokobania
@ 2014-08-21 18:28 ` Stefan Monnier
  2014-08-22  6:13 ` Thien-Thi Nguyen
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 9+ messages in thread
From: Stefan Monnier @ 2014-08-21 18:28 UTC (permalink / raw
  To: help-gnu-emacs

> Is there a simple way (functions, mode, package...) to do that?

Yes.  ;-)

> Are there any (simple) emacs-lisp examples of such a thing?

enriched.el and ses.el come to mind (which use different approaches),
tho I'm sure there's more.


        Stefan




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: How to save invisible (lisp) data in a text file
  2014-08-21 14:04 How to save invisible (lisp) data in a text file sokobania
  2014-08-21 18:28 ` Stefan Monnier
@ 2014-08-22  6:13 ` Thien-Thi Nguyen
  2014-08-23 12:34 ` lee
  2014-08-29  9:26 ` sokobania.01
  3 siblings, 0 replies; 9+ messages in thread
From: Thien-Thi Nguyen @ 2014-08-22  6:13 UTC (permalink / raw
  To: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 819 bytes --]

() sokobania@gmail.com
() Thu, 21 Aug 2014 07:04:22 -0700 (PDT)

   Is there a simple way (functions, mode, package...) to do that?
   Are there any (simple) emacs-lisp examples of such a thing?

what is simple but hidden complexity?
so hiding is fun?  play hide the text (you see).
euclid-ish packing is more your cup of tea?
surf w/o froth to max out the density.

but anyway, who can say such things to your ears?
every day, Quality folds, and brains mold their fears.
composition, complaint, candor -- now what appears?
ruminations repo'd, w/ shared singes, shared sears.

-- 
Thien-Thi Nguyen
   GPG key: 4C807502
   (if you're human and you know it)
      read my lisp: (responsep (questions 'technical)
                               (not (via 'mailing-list)))
                     => nil

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 197 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: How to save invisible (lisp) data in a text file
  2014-08-21 14:04 How to save invisible (lisp) data in a text file sokobania
  2014-08-21 18:28 ` Stefan Monnier
  2014-08-22  6:13 ` Thien-Thi Nguyen
@ 2014-08-23 12:34 ` lee
  2014-08-29  9:26 ` sokobania.01
  3 siblings, 0 replies; 9+ messages in thread
From: lee @ 2014-08-23 12:34 UTC (permalink / raw
  To: help-gnu-emacs

sokobania@gmail.com writes:

> I would like to do the following:
> - display some normal text in a buffer with some major
>   mode named "my-special-mode"
> - let the user interact with the buffer contents
> - store in ram some lisp data generated by the user interaction
>   (like marks and extra text not displayed in the buffer)
> - store the normal text AND this extra data in a file
>
> Then, when reopening the file, emacs would:
> - display the normal text in a buffer with "my-special-mode"
> - reinstall in ram the lisp data associated to the file
>
> Is this possible with emacs?
>
> Oops... As the answer to "Is this possible with emacs?"
> is always "yes", I would rather ask:
>
> Is there a simple way (functions, mode, package...) to do that?
> Are there any (simple) emacs-lisp examples of such a thing?

You can apply information from another buffer to the current
buffer.  I've extended hi-lock-mode to do this, see
https://github.com/lee-/emacs

At least it shows you how it can be done.  To store all information in
one file, I would think about using a save hook which creates a tar
archive from the two files or about using a unique marker line in the
file after which the extra information is stored while limiting the
display to everything above the marker.


-- 
GNU Emacs 24.4.50.2 (x86_64-unknown-linux-gnu, X toolkit, Xaw3d scroll bars)
 of 2014-08-17 on yun.yagibdah.de



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: How to save invisible (lisp) data in a text file
  2014-08-21 14:04 How to save invisible (lisp) data in a text file sokobania
                   ` (2 preceding siblings ...)
  2014-08-23 12:34 ` lee
@ 2014-08-29  9:26 ` sokobania.01
  2014-08-29 20:03   ` Stefan Monnier
       [not found]   ` <mailman.7874.1409342719.1147.help-gnu-emacs@gnu.org>
  3 siblings, 2 replies; 9+ messages in thread
From: sokobania.01 @ 2014-08-29  9:26 UTC (permalink / raw
  To: help-gnu-emacs

Many thanks for the answers!

I had a look at enriched.el and ses.el.
I will use the method I described but, instead of 
deleting the lines concerning the file-local variables, 
I will just hide them using facemenu-set-invisible.

BTW, facemenu-set-invisible is NOT in the emacs command index:
https://www.gnu.org/software/emacs/manual/html_node/emacs/Command-Index.html

Is it a bug?


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: How to save invisible (lisp) data in a text file
  2014-08-29  9:26 ` sokobania.01
@ 2014-08-29 20:03   ` Stefan Monnier
       [not found]   ` <mailman.7874.1409342719.1147.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 9+ messages in thread
From: Stefan Monnier @ 2014-08-29 20:03 UTC (permalink / raw
  To: help-gnu-emacs

> I will just hide them using facemenu-set-invisible.

Please don't use facemenu-set-invisible.  Instead add the `invisible'
property with `put-text-property' (which is basically what
facemenu-set-invisible does internally).

> BTW, facemenu-set-invisible is NOT in the emacs command index:
> https://www.gnu.org/software/emacs/manual/html_node/emacs/Command-Index.html
> Is it a bug?

No: facemenu-set-invisible is a very little used thing, that's basically
useless in 99.99% of the cases.


        Stefan




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: How to save invisible (lisp) data in a text file
       [not found]   ` <mailman.7874.1409342719.1147.help-gnu-emacs@gnu.org>
@ 2014-09-01  8:31     ` sokobania.01
  2014-09-02  1:56       ` Stefan Monnier
  0 siblings, 1 reply; 9+ messages in thread
From: sokobania.01 @ 2014-09-01  8:31 UTC (permalink / raw
  To: help-gnu-emacs

Le vendredi 29 août 2014 22:03:14 UTC+2, Stefan Monnier a écrit :
> > I will just hide them using facemenu-set-invisible.
> 
> Please don't use facemenu-set-invisible.  Instead add the `invisible'
> property with `put-text-property' (which is basically what
> facemenu-set-invisible does internally).
> 
> No: facemenu-set-invisible is a very little used thing,
> that's basically useless in 99.99% of the cases.

Hmmm. I think I need an explanation!

In my GNU Emacs 24.3.1, facemenu-set-invisible is defined as:

(defun facemenu-set-invisible (start end)
  "Make the region invisible.
This sets the `invisible' text property; it can be undone with
`facemenu-remove-special'."
  (interactive "r")
  (add-text-properties start end '(invisible t)))

Imho, it seems:
- It does exactly what I need (make the region invisible).
- Its implementation is exactly the code you recommend.
- Even if it's only 1 line of code, it's (a little bit) 
  higher level than this mere line of code.
- It has the same implementation within Xemacs.

I imagine there is probably very little chance 
that this implementation changes.

Without your warning, I would have preferred to use a high
level function that makes the region invisible rather than 
having to deal with the internal aspects of doing that 
(I mean "rather than adding text properties").

So, can you explain why you don't recommend to use it?
Is it that anyone who wants to make the region invisible
should know that it must be done with text properties?


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: How to save invisible (lisp) data in a text file
  2014-09-01  8:31     ` sokobania.01
@ 2014-09-02  1:56       ` Stefan Monnier
  0 siblings, 0 replies; 9+ messages in thread
From: Stefan Monnier @ 2014-09-02  1:56 UTC (permalink / raw
  To: help-gnu-emacs

> So, can you explain why you don't recommend to use it?
> Is it that anyone who wants to make the region invisible
> should know that it must be done with text properties?

Exactly: you're not just going to make the text invisible, since you
also want to store this invisibility somewhere in a file.  So you'll
have to know how it works underneath.


        Stefan


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2014-09-02  1:56 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-08-21 14:04 How to save invisible (lisp) data in a text file sokobania
2014-08-21 18:28 ` Stefan Monnier
2014-08-22  6:13 ` Thien-Thi Nguyen
2014-08-23 12:34 ` lee
2014-08-29  9:26 ` sokobania.01
2014-08-29 20:03   ` Stefan Monnier
     [not found]   ` <mailman.7874.1409342719.1147.help-gnu-emacs@gnu.org>
2014-09-01  8:31     ` sokobania.01
2014-09-02  1:56       ` Stefan Monnier
     [not found] <mailman.185.1408636859.24723.help-gnu-emacs@gnu.org>
2014-08-21 16:38 ` Buchs, Kevin J.

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.