From e5826cc0353e2a1d666e2ae8708af231c2722137 Mon Sep 17 00:00:00 2001 From: KemoNine Date: Wed, 30 Aug 2023 09:09:50 -0400 Subject: [PATCH] add revert-buffer-all globally --- .../revert-buffer-all-autoloads.el | 32 +++++ .../revert-buffer-all-pkg.el | 12 ++ .../revert-buffer-all.el | 120 ++++++++++++++++++ common/_global.el | 2 +- .../revert-buffer-all-autoloads.el | 32 +++++ .../revert-buffer-all-pkg.el | 12 ++ .../revert-buffer-all.el | 120 ++++++++++++++++++ 7 files changed, 329 insertions(+), 1 deletion(-) create mode 100644 code/elpa/revert-buffer-all-20230109.536/revert-buffer-all-autoloads.el create mode 100644 code/elpa/revert-buffer-all-20230109.536/revert-buffer-all-pkg.el create mode 100644 code/elpa/revert-buffer-all-20230109.536/revert-buffer-all.el create mode 100644 org/elpa/revert-buffer-all-20230109.536/revert-buffer-all-autoloads.el create mode 100644 org/elpa/revert-buffer-all-20230109.536/revert-buffer-all-pkg.el create mode 100644 org/elpa/revert-buffer-all-20230109.536/revert-buffer-all.el diff --git a/code/elpa/revert-buffer-all-20230109.536/revert-buffer-all-autoloads.el b/code/elpa/revert-buffer-all-20230109.536/revert-buffer-all-autoloads.el new file mode 100644 index 0000000..58cc724 --- /dev/null +++ b/code/elpa/revert-buffer-all-20230109.536/revert-buffer-all-autoloads.el @@ -0,0 +1,32 @@ +;;; revert-buffer-all-autoloads.el --- automatically extracted autoloads -*- lexical-binding: t -*- +;; +;;; Code: + +(add-to-list 'load-path (directory-file-name + (or (file-name-directory #$) (car load-path)))) + + +;;;### (autoloads nil "revert-buffer-all" "revert-buffer-all.el" +;;;;;; (0 0 0 0)) +;;; Generated autoloads from revert-buffer-all.el + +(autoload 'revert-buffer-all "revert-buffer-all" "\ +Refresh all open buffers from their respective files. + +Buffers which no longer exist are closed. + +This can be useful when updating or checking out branches outside of Emacs." t nil) + +;;;*** + +;;;### (autoloads nil nil ("revert-buffer-all-pkg.el") (0 0 0 0)) + +;;;*** + +;; Local Variables: +;; version-control: never +;; no-byte-compile: t +;; no-update-autoloads: t +;; coding: utf-8 +;; End: +;;; revert-buffer-all-autoloads.el ends here diff --git a/code/elpa/revert-buffer-all-20230109.536/revert-buffer-all-pkg.el b/code/elpa/revert-buffer-all-20230109.536/revert-buffer-all-pkg.el new file mode 100644 index 0000000..4789ff8 --- /dev/null +++ b/code/elpa/revert-buffer-all-20230109.536/revert-buffer-all-pkg.el @@ -0,0 +1,12 @@ +(define-package "revert-buffer-all" "20230109.536" "Revert all open buffers" + '((emacs "24.3")) + :commit "08e90d2d75f5d5900ca2a0d2670592bcf2b2d68f" :authors + '(("Campbell Barton" . "ideasman42@gmail.com")) + :maintainers + '(("Campbell Barton" . "ideasman42@gmail.com")) + :maintainer + '("Campbell Barton" . "ideasman42@gmail.com") + :url "https://codeberg.org/ideasman42/emacs-buffer-revert-all") +;; Local Variables: +;; no-byte-compile: t +;; End: diff --git a/code/elpa/revert-buffer-all-20230109.536/revert-buffer-all.el b/code/elpa/revert-buffer-all-20230109.536/revert-buffer-all.el new file mode 100644 index 0000000..88f0f85 --- /dev/null +++ b/code/elpa/revert-buffer-all-20230109.536/revert-buffer-all.el @@ -0,0 +1,120 @@ +;;; revert-buffer-all.el --- Revert all open buffers -*- lexical-binding: t -*- + +;; SPDX-License-Identifier: GPL-2.0-or-later +;; Copyright (C) 2021 Campbell Barton + +;; Author: Campbell Barton + +;; URL: https://codeberg.org/ideasman42/emacs-buffer-revert-all +;; Version: 0.1 +;; Package-Requires: ((emacs "24.3")) + +;;; Commentary: + +;; Utility to revert all buffers, useful to run after external +;; changes to a project have been made such as applying a patch +;; or switching branches. +;; + +;;; Usage: + +;; ;; Bind the keys +;; (global-set-key (kbd "C-S-M-r") 'revert-buffer-all) + +;;; Code: + +(eval-when-compile + ;; For `pcase-dolist'. + (require 'pcase)) + +;;;###autoload +(defun revert-buffer-all () + "Refresh all open buffers from their respective files. + +Buffers which no longer exist are closed. + +This can be useful when updating or checking out branches outside of Emacs." + (interactive) + (let* ((filename-and-buffer-list + ;; Pairs of '(filename . buf)'. + (let ((temp-list nil)) + (dolist (buf (buffer-list)) + (let ((filename (buffer-file-name buf))) + (when filename + (push (cons filename buf) temp-list)))) + temp-list)) + + (message-prefix "Buffer Revert All:") + (count (length filename-and-buffer-list)) + (count-final 0) + (count-close 0) + (count-error 0) + ;; Keep text at a fixed width when redrawing. + (format-count (format "%%%dd" (length (number-to-string count)))) + (format-text + (concat message-prefix " reverting [" format-count " of " format-count "] %3d%%: %s")) + (index 1)) + + (message "%s beginning with %d buffers..." message-prefix count) + + (pcase-dolist (`(,filename . ,buf) filename-and-buffer-list) + ;; Revert only buffers containing files, which are not modified; + ;; do not try to revert non-file buffers such as '*Messages*'. + (message format-text index count (round (* 100 (/ (float index) count))) filename) + + (cond + ((file-exists-p filename) + ;; If the file exists, revert the buffer. + (cond + ((with-demoted-errors "Error: %S" + (with-current-buffer buf + (let ((no-undo (eq buffer-undo-list t))) + + ;; Disable during revert. + (unless no-undo + (setq buffer-undo-list t) + (setq pending-undo-list nil)) + + (unwind-protect + (revert-buffer :ignore-auto :noconfirm) + + ;; Enable again (always run). + (unless no-undo + ;; It's possible a plugin loads undo data from disk, + ;; check if this is still unset. + (when (and (eq buffer-undo-list t) (null pending-undo-list)) + (setq buffer-undo-list nil)))))) + t) + (setq count-final (1+ count-final))) + (t + (setq count-error (1+ count-error))))) + + (t + ;; If the file doesn't exist, kill the buffer. + ;; No query done when killing buffer. + (let ((kill-buffer-query-functions nil)) + (message "%s closing non-existing file buffer: %s" message-prefix buf) + (kill-buffer buf) + (setq count-close (1+ count-close))))) + + (setq index (1+ index))) + (message + (concat + message-prefix (format " finished with %d buffer(s)" count-final) + (cond + ((zerop count-close) + "") + (t + (format ", %d closed" count-close))) + (cond + ((zerop count-error) + "") + (t + (format ", %d error (see message buffer)" count-error))))))) + +(provide 'revert-buffer-all) +;; Local Variables: +;; fill-column: 99 +;; indent-tabs-mode: nil +;; End: +;;; revert-buffer-all.el ends here diff --git a/common/_global.el b/common/_global.el index 1e4dc01..fc573f7 100644 --- a/common/_global.el +++ b/common/_global.el @@ -13,7 +13,7 @@ (add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t) ; this goes in chemacs2 init -- DO NOT UNCOMMENT (package-initialize) ; this goes in chemacs2 init -- DO NOT UNCOMMENT (add-to-list 'package-selected-packages - '(centaur-tabs scratch persistent-scratch persp-mode rainbow-mode rainbow-delimiters markdown-mode focus zoom popwin dired-single diredfl doominhibitinhibit-modeline helpful helm helm-org dired-rainbow dired-rainbow-listing dired-single dash s origami modus-themes use-package) + '(revert-buffer-all centaur-tabs scratch persistent-scratch persp-mode rainbow-mode rainbow-delimiters markdown-mode focus zoom popwin dired-single diredfl doominhibitinhibit-modeline helpful helm helm-org dired-rainbow dired-rainbow-listing dired-single dash s origami modus-themes use-package) ) (when (not kmn/is-dayjob) (add-to-list 'package-selected-packages diff --git a/org/elpa/revert-buffer-all-20230109.536/revert-buffer-all-autoloads.el b/org/elpa/revert-buffer-all-20230109.536/revert-buffer-all-autoloads.el new file mode 100644 index 0000000..58cc724 --- /dev/null +++ b/org/elpa/revert-buffer-all-20230109.536/revert-buffer-all-autoloads.el @@ -0,0 +1,32 @@ +;;; revert-buffer-all-autoloads.el --- automatically extracted autoloads -*- lexical-binding: t -*- +;; +;;; Code: + +(add-to-list 'load-path (directory-file-name + (or (file-name-directory #$) (car load-path)))) + + +;;;### (autoloads nil "revert-buffer-all" "revert-buffer-all.el" +;;;;;; (0 0 0 0)) +;;; Generated autoloads from revert-buffer-all.el + +(autoload 'revert-buffer-all "revert-buffer-all" "\ +Refresh all open buffers from their respective files. + +Buffers which no longer exist are closed. + +This can be useful when updating or checking out branches outside of Emacs." t nil) + +;;;*** + +;;;### (autoloads nil nil ("revert-buffer-all-pkg.el") (0 0 0 0)) + +;;;*** + +;; Local Variables: +;; version-control: never +;; no-byte-compile: t +;; no-update-autoloads: t +;; coding: utf-8 +;; End: +;;; revert-buffer-all-autoloads.el ends here diff --git a/org/elpa/revert-buffer-all-20230109.536/revert-buffer-all-pkg.el b/org/elpa/revert-buffer-all-20230109.536/revert-buffer-all-pkg.el new file mode 100644 index 0000000..4789ff8 --- /dev/null +++ b/org/elpa/revert-buffer-all-20230109.536/revert-buffer-all-pkg.el @@ -0,0 +1,12 @@ +(define-package "revert-buffer-all" "20230109.536" "Revert all open buffers" + '((emacs "24.3")) + :commit "08e90d2d75f5d5900ca2a0d2670592bcf2b2d68f" :authors + '(("Campbell Barton" . "ideasman42@gmail.com")) + :maintainers + '(("Campbell Barton" . "ideasman42@gmail.com")) + :maintainer + '("Campbell Barton" . "ideasman42@gmail.com") + :url "https://codeberg.org/ideasman42/emacs-buffer-revert-all") +;; Local Variables: +;; no-byte-compile: t +;; End: diff --git a/org/elpa/revert-buffer-all-20230109.536/revert-buffer-all.el b/org/elpa/revert-buffer-all-20230109.536/revert-buffer-all.el new file mode 100644 index 0000000..88f0f85 --- /dev/null +++ b/org/elpa/revert-buffer-all-20230109.536/revert-buffer-all.el @@ -0,0 +1,120 @@ +;;; revert-buffer-all.el --- Revert all open buffers -*- lexical-binding: t -*- + +;; SPDX-License-Identifier: GPL-2.0-or-later +;; Copyright (C) 2021 Campbell Barton + +;; Author: Campbell Barton + +;; URL: https://codeberg.org/ideasman42/emacs-buffer-revert-all +;; Version: 0.1 +;; Package-Requires: ((emacs "24.3")) + +;;; Commentary: + +;; Utility to revert all buffers, useful to run after external +;; changes to a project have been made such as applying a patch +;; or switching branches. +;; + +;;; Usage: + +;; ;; Bind the keys +;; (global-set-key (kbd "C-S-M-r") 'revert-buffer-all) + +;;; Code: + +(eval-when-compile + ;; For `pcase-dolist'. + (require 'pcase)) + +;;;###autoload +(defun revert-buffer-all () + "Refresh all open buffers from their respective files. + +Buffers which no longer exist are closed. + +This can be useful when updating or checking out branches outside of Emacs." + (interactive) + (let* ((filename-and-buffer-list + ;; Pairs of '(filename . buf)'. + (let ((temp-list nil)) + (dolist (buf (buffer-list)) + (let ((filename (buffer-file-name buf))) + (when filename + (push (cons filename buf) temp-list)))) + temp-list)) + + (message-prefix "Buffer Revert All:") + (count (length filename-and-buffer-list)) + (count-final 0) + (count-close 0) + (count-error 0) + ;; Keep text at a fixed width when redrawing. + (format-count (format "%%%dd" (length (number-to-string count)))) + (format-text + (concat message-prefix " reverting [" format-count " of " format-count "] %3d%%: %s")) + (index 1)) + + (message "%s beginning with %d buffers..." message-prefix count) + + (pcase-dolist (`(,filename . ,buf) filename-and-buffer-list) + ;; Revert only buffers containing files, which are not modified; + ;; do not try to revert non-file buffers such as '*Messages*'. + (message format-text index count (round (* 100 (/ (float index) count))) filename) + + (cond + ((file-exists-p filename) + ;; If the file exists, revert the buffer. + (cond + ((with-demoted-errors "Error: %S" + (with-current-buffer buf + (let ((no-undo (eq buffer-undo-list t))) + + ;; Disable during revert. + (unless no-undo + (setq buffer-undo-list t) + (setq pending-undo-list nil)) + + (unwind-protect + (revert-buffer :ignore-auto :noconfirm) + + ;; Enable again (always run). + (unless no-undo + ;; It's possible a plugin loads undo data from disk, + ;; check if this is still unset. + (when (and (eq buffer-undo-list t) (null pending-undo-list)) + (setq buffer-undo-list nil)))))) + t) + (setq count-final (1+ count-final))) + (t + (setq count-error (1+ count-error))))) + + (t + ;; If the file doesn't exist, kill the buffer. + ;; No query done when killing buffer. + (let ((kill-buffer-query-functions nil)) + (message "%s closing non-existing file buffer: %s" message-prefix buf) + (kill-buffer buf) + (setq count-close (1+ count-close))))) + + (setq index (1+ index))) + (message + (concat + message-prefix (format " finished with %d buffer(s)" count-final) + (cond + ((zerop count-close) + "") + (t + (format ", %d closed" count-close))) + (cond + ((zerop count-error) + "") + (t + (format ", %d error (see message buffer)" count-error))))))) + +(provide 'revert-buffer-all) +;; Local Variables: +;; fill-column: 99 +;; indent-tabs-mode: nil +;; End: +;;; revert-buffer-all.el ends here