3 title: add 'ignore errors'
| link

Revert all open buffers (and ignore errors)

2 added 193 characters in body
source | link

When working on a project under version control with git, I often want to do some things in a shell that affect many of my open files, then revert every buffer that I have open to make sure that I don't accidentally clobber the new version with whatever I had open. I know magit can be helpful here, but I'm used to my workflow in the shell and I'd like to keep it for now. So instead, I'd like to revert all open buffers, and maybe close any that have stopped existing (e.g. because of a git checkout of a branch that no longer has that file).

I have the following snippet of elisp that I grabbed from a Google search:

(defun revert-all-buffers ()
  "Refreshes all open buffers from their respective files"
  (interactive)
  (let* ((list (buffer-list))
         (buffer (car list)))
    (while buffer
      (when (and (buffer-file-name buffer) 
                 (not (buffer-modified-p buffer)))
        (set-buffer buffer)
        (revert-buffer t t t))
      (setq list (cdr list))
      (setq buffer (car list))))
  (message "Refreshed open files"))

But this breaks if it hits an error in one of my open files, i.e. when reverting B1, B2, B3,...,Bn an error while trying to revert B2 prevents B3-Bn from being reverted.

How can I tell emacs to ignore any errors that pop up in this case? I don't want to use global-auto-revert-mode because each revert triggers some heavy duty stuff like my auto-complete and syntax checker re-parsing the file, hanging emacs for a second or so.

When working on a project under version control with git, I often want to do some things in a shell that affect many of my open files, then revert every buffer that I have open to make sure that I don't accidentally clobber the new version with whatever I had open. I know magit can be helpful here, but I'm used to my workflow in the shell and I'd like to keep it for now. So instead, I'd like to revert all open buffers, and maybe close any that have stopped existing (e.g. because of a git checkout of a branch that no longer has that file).

I have the following snippet of elisp that I grabbed from a Google search:

(defun revert-all-buffers ()
  "Refreshes all open buffers from their respective files"
  (interactive)
  (let* ((list (buffer-list))
         (buffer (car list)))
    (while buffer
      (when (and (buffer-file-name buffer) 
                 (not (buffer-modified-p buffer)))
        (set-buffer buffer)
        (revert-buffer t t t))
      (setq list (cdr list))
      (setq buffer (car list))))
  (message "Refreshed open files"))

But this breaks if it hits an error in one of my open files, i.e. when reverting B1, B2, B3,...,Bn an error while trying to revert B2 prevents B3-Bn from being reverted.

How can I tell emacs to ignore any errors that pop up in this case?

When working on a project under version control with git, I often want to do some things in a shell that affect many of my open files, then revert every buffer that I have open to make sure that I don't accidentally clobber the new version with whatever I had open. I know magit can be helpful here, but I'm used to my workflow in the shell and I'd like to keep it for now. So instead, I'd like to revert all open buffers, and maybe close any that have stopped existing (e.g. because of a git checkout of a branch that no longer has that file).

I have the following snippet of elisp that I grabbed from a Google search:

(defun revert-all-buffers ()
  "Refreshes all open buffers from their respective files"
  (interactive)
  (let* ((list (buffer-list))
         (buffer (car list)))
    (while buffer
      (when (and (buffer-file-name buffer) 
                 (not (buffer-modified-p buffer)))
        (set-buffer buffer)
        (revert-buffer t t t))
      (setq list (cdr list))
      (setq buffer (car list))))
  (message "Refreshed open files"))

But this breaks if it hits an error in one of my open files, i.e. when reverting B1, B2, B3,...,Bn an error while trying to revert B2 prevents B3-Bn from being reverted.

How can I tell emacs to ignore any errors that pop up in this case? I don't want to use global-auto-revert-mode because each revert triggers some heavy duty stuff like my auto-complete and syntax checker re-parsing the file, hanging emacs for a second or so.

1
source | link

Revert all open buffers

When working on a project under version control with git, I often want to do some things in a shell that affect many of my open files, then revert every buffer that I have open to make sure that I don't accidentally clobber the new version with whatever I had open. I know magit can be helpful here, but I'm used to my workflow in the shell and I'd like to keep it for now. So instead, I'd like to revert all open buffers, and maybe close any that have stopped existing (e.g. because of a git checkout of a branch that no longer has that file).

I have the following snippet of elisp that I grabbed from a Google search:

(defun revert-all-buffers ()
  "Refreshes all open buffers from their respective files"
  (interactive)
  (let* ((list (buffer-list))
         (buffer (car list)))
    (while buffer
      (when (and (buffer-file-name buffer) 
                 (not (buffer-modified-p buffer)))
        (set-buffer buffer)
        (revert-buffer t t t))
      (setq list (cdr list))
      (setq buffer (car list))))
  (message "Refreshed open files"))

But this breaks if it hits an error in one of my open files, i.e. when reverting B1, B2, B3,...,Bn an error while trying to revert B2 prevents B3-Bn from being reverted.

How can I tell emacs to ignore any errors that pop up in this case?