[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

how to force auto-save of buffers not visiting files, right now?

From: hw
Subject: how to force auto-save of buffers not visiting files, right now?
Date: Mon, 14 Mar 2022 05:55:34 +0100
User-agent: Evolution 3.42.4 (3.42.4-1.fc35)


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")
  (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)
    (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.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]