all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* safe way to add contents to a file ?
@ 2019-12-18  0:03 Jean-Christophe Helary
  2019-12-18  0:36 ` Óscar Fuentes
  2019-12-18  3:59 ` Stefan Monnier
  0 siblings, 2 replies; 18+ messages in thread
From: Jean-Christophe Helary @ 2019-12-18  0:03 UTC (permalink / raw)
  To: help-gnu-emacs

I'm struggling with what is the ideal "elispy" way of adding contents to a file at a given position.

What I want it:
- create some content
- put that content at a specific location in a file saved on disk
 (current use case: add an xml block to an RSS file)

I thought write-region would do the trick but there are 2 issues with it

1) if APPEND is a number, that's the position from which my contents will *overwrite* the rest of the file (I want to *insert* my contents)

2) there are weird things like the whole code where I call this function is actually copied to the target file buffer and I have no idea how to prevent that.

So, I thought of something a bit convoluted:

use a temporary buffer
insert the contents of the file there
find the point where I want to insert my contents
find the end of the file
copy that region to a different buffer
write my contents from the point I specified above
append the copied region to that
write all that to the original file

But I thought, it's not like such things don't happen all the time in emacs, so there must be a better workflow.

But the reference is incredibly cryptic regarding that and the Intro does not address any file i/o at all...



Jean-Christophe Helary
-----------------------------------------------
http://mac4translators.blogspot.com @brandelune





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

end of thread, other threads:[~2019-12-23  0:08 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-12-18  0:03 safe way to add contents to a file ? Jean-Christophe Helary
2019-12-18  0:36 ` Óscar Fuentes
2019-12-18  3:20   ` Jean-Christophe Helary
2019-12-20 13:50   ` Jean-Christophe Helary
2019-12-20 16:00     ` Stefan Monnier
2019-12-22  3:14       ` Jean-Christophe Helary
2019-12-22  4:42         ` Jean-Christophe Helary
2019-12-22 14:37           ` Óscar Fuentes
2019-12-22 22:18             ` Jean-Christophe Helary
2019-12-23  0:08               ` Óscar Fuentes
2019-12-22 18:23         ` Stefan Monnier
2019-12-18  3:59 ` Stefan Monnier
2019-12-18  9:41   ` Jean-Christophe Helary
2019-12-18 13:10     ` Óscar Fuentes
2019-12-18 22:33       ` Jean-Christophe Helary
2019-12-18 14:10     ` Stefan Monnier
2019-12-18 22:25       ` Jean-Christophe Helary
2019-12-18 22:27       ` Jean-Christophe Helary

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.