unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* how to force auto-save of buffers not visiting files, right now?
@ 2022-03-14  4:55 hw
  2022-03-14 12:48 ` Eli Zaretskii
  2022-03-16  0:51 ` Michael Heerdegen
  0 siblings, 2 replies; 53+ messages in thread
From: hw @ 2022-03-14  4:55 UTC (permalink / raw)
  To: Help GNU Emacs


Hi,

how do I force auto-saving of a particular buffer, or of all buffers,
that are not visiting a file, right now?

I would like to improve below function by auto-saving the backup:


(defun my-perltidy-replace (arg)
  "Replace the contents of the current buffer with the output of
perltidy, and make a backup of the current buffer."
  (interactive "P")
  (save-some-buffers)
  (let ((tidy_buffer (generate-new-buffer (generate-new-buffer-name (concat "TidyBackup-" (buffer-name))))))
    (with-current-buffer (buffer-name)
      ;; swapping the text can screw up linum mode with two buffers in
      ;; the same frame when automatically enabled by cperl-mode
      (linum-mode -1)
      (shell-command-on-region (point-min) (point-max) "perltidy --standard-output" tidy_buffer)
      (buffer-swap-text tidy_buffer))
    (with-current-buffer tidy_buffer
      (auto-save-mode nil)
      (cperl-mode))
    (linum-mode 1)
    (message "buffer contents replaced with output of perltidy; backup is in %s" tidy_buffer)))


I want an autosave of the backup once the buffer contents were swapped
to keep the original in case something goes wrong.  If nothing went
wrong, I'll eventually kill the buffer holding the backup, which is
why I don't want to save it to a file the buffer would be visiting
and which I would have to explicitly delete at some time (and because
some of the files would have to be saved on remote hosts, which would
make things rather unwieldy).

The problem is with "right now".  Without further ado, the backup is
automatically being saved after "a while", but I need it saved
"right now" since meanwhile, things can go wrong.

Or is this a bad idea?

Another question would be how I can copy all modes of a buffer and
apply them to another one.  Just enabling cperl-mode works for me,
but it's not really nice like this.  Somehow, that seems difficult
to do.




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

end of thread, other threads:[~2022-03-23  9:25 UTC | newest]

Thread overview: 53+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-03-14  4:55 how to force auto-save of buffers not visiting files, right now? hw
2022-03-14 12:48 ` Eli Zaretskii
2022-03-15  5:20   ` hw
2022-03-15  6:47     ` Jean Louis
2022-03-15  7:24       ` Emanuel Berg via Users list for the GNU Emacs text editor
2022-03-17  4:35       ` hw
2022-03-17  5:00         ` Emanuel Berg via Users list for the GNU Emacs text editor
2022-03-18  7:31           ` hw
2022-03-18 14:45             ` [External] : " Drew Adams
2022-03-19  2:33               ` hw
2022-03-19  2:38                 ` Emanuel Berg via Users list for the GNU Emacs text editor
2022-03-15 14:07     ` Eli Zaretskii
2022-03-16  0:51 ` Michael Heerdegen
2022-03-16  1:45   ` [External] : " Drew Adams
2022-03-17 19:23   ` hw
2022-03-17 22:07     ` Michael Heerdegen
2022-03-18  8:28       ` hw
2022-03-19  1:18         ` Michael Heerdegen
2022-03-19  3:14           ` hw
2022-03-19  3:47             ` Michael Heerdegen
2022-03-19  6:24               ` hw
2022-03-19  7:34                 ` Emanuel Berg via Users list for the GNU Emacs text editor
2022-03-19  7:51                 ` Emanuel Berg via Users list for the GNU Emacs text editor
2022-03-20  6:02                   ` hw
2022-03-20  6:26                     ` Emanuel Berg via Users list for the GNU Emacs text editor
2022-03-19  9:58                 ` Michael Albinus
2022-03-20  6:36                   ` hw
2022-03-20  7:04                     ` Emanuel Berg via Users list for the GNU Emacs text editor
2022-03-21 16:22                       ` [External] : " Drew Adams
2022-03-20  7:29                     ` tomas
2022-03-20  8:05                       ` volatile /tmp [was: how to force auto-save of buffers not visiting files, right now?] tomas
2022-03-20 10:36                         ` hw
2022-03-20 11:13                           ` tomas
2022-03-21  3:41                             ` hw
2022-03-21  5:53                               ` tomas
2022-03-21  8:47                               ` Michael Albinus
2022-03-20  9:57                       ` how to force auto-save of buffers not visiting files, right now? Michael Albinus
2022-03-20 10:21                         ` tomas
2022-03-20 10:19                       ` hw
2022-03-20 10:30                         ` tomas
2022-03-21  3:55                           ` hw
2022-03-21  4:13                             ` Emanuel Berg via Users list for the GNU Emacs text editor
2022-03-21 12:22                             ` Eli Zaretskii
2022-03-23  6:12                               ` hw
2022-03-23  9:25                                 ` Michael Albinus
2022-03-20  0:21                 ` Michael Heerdegen
2022-03-20  4:56                   ` Emanuel Berg via Users list for the GNU Emacs text editor
2022-03-20  7:39                   ` hw
2022-03-20  8:08                     ` Emanuel Berg via Users list for the GNU Emacs text editor
2022-03-22  7:06                       ` hw
2022-03-22 19:50                         ` Emanuel Berg via Users list for the GNU Emacs text editor
2022-03-22 21:45                         ` Emanuel Berg via Users list for the GNU Emacs text editor
2022-03-21  7:22               ` Jean Louis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).