Add my/kill-buffers-by-pattern function to utils.el
This commit adds the my/kill-buffers-by-pattern function to utils.el. Th is function allows the user to kill buffers whose names match a specifie d pattern. The function prompts the user for a pattern, searches through all buffers, and kills the buffers whose names match the pattern. The p attern is a regular expression that is compared against buffer names usi ng 'string-match-p'.
This commit is contained in:
parent
79dc8f01a7
commit
2576788254
1 changed files with 18 additions and 0 deletions
|
@ -513,6 +513,24 @@ Version: 2023-08-31"
|
|||
(pop-to-buffer existing-buffer))))
|
||||
|
||||
|
||||
(defun my/kill-buffers-by-pattern (pattern)
|
||||
"Kill buffers whose names match the specified pattern.
|
||||
|
||||
This function interactively prompts the user for a pattern and then searches
|
||||
through the list of all buffers. Buffers whose names match the given pattern
|
||||
are killed, effectively closing them. The pattern is a regular expression that
|
||||
is compared against buffer names using 'string-match-p'.
|
||||
|
||||
Version: 2023-08-16"
|
||||
(interactive "sEnter a pattern: ")
|
||||
(dolist (buffer (buffer-list))
|
||||
(let ((buffer-name (buffer-name buffer)))
|
||||
(message "Processing buffer: %s" buffer-name)
|
||||
(when (string-match-p pattern buffer-name)
|
||||
(kill-buffer buffer)
|
||||
(message "Killed buffer '%s'" buffer-name)))))
|
||||
|
||||
|
||||
|
||||
(provide 'init-utils)
|
||||
|
||||
|
|
Loading…
Reference in a new issue