all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* How to do write-region, but modify
@ 2014-10-25 14:58 Marcin Borkowski
  2014-10-25 18:44 ` Thien-Thi Nguyen
  0 siblings, 1 reply; 2+ messages in thread
From: Marcin Borkowski @ 2014-10-25 14:58 UTC (permalink / raw
  To: help-gnu-emacs

Hi all,

I'd like to have a variant of write-region, which (instead of saving to
a file) "saves" the region to a temporary buffer and lets me change it
somehow there.

What I'm doing now is something like this:

--8<---------------cut here---------------start------------->8---
(let ((text (buffer-substring beg end)))
  (with-temp-buffer
    (insert text)
    (do-some manipulation)
    (write-region (point-min) (point-max) filename)))
--8<---------------cut here---------------end--------------->8---

This feels not optimal, since the text is copied twice (once to the
variable `text' and then to the temporary buffer).

Any suggestions on how to improve this code?

TIA,

-- 
Marcin Borkowski
http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski
Adam Mickiewicz University



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

* Re: How to do write-region, but modify
  2014-10-25 14:58 How to do write-region, but modify Marcin Borkowski
@ 2014-10-25 18:44 ` Thien-Thi Nguyen
  0 siblings, 0 replies; 2+ messages in thread
From: Thien-Thi Nguyen @ 2014-10-25 18:44 UTC (permalink / raw
  To: help-gnu-emacs

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

() Marcin Borkowski <mbork@wmi.amu.edu.pl>
() Sat, 25 Oct 2014 16:58:22 +0200

   Any suggestions on how to improve this code?

‘insert’ is fine when you drop from above;
‘insert-buffer’ better for a sideways shove;
‘insert-buffer-substring’ best for nuanced love.

-- 
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] 2+ messages in thread

end of thread, other threads:[~2014-10-25 18:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-10-25 14:58 How to do write-region, but modify Marcin Borkowski
2014-10-25 18:44 ` Thien-Thi Nguyen

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.