Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

buffer_autoclose.py 0.6: add setting to prefer closing some buffers #554

Merged
merged 1 commit into from
May 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion python/buffer_autoclose.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
# (this script requires WeeChat 0.3.0 or newer)
#
# History:
# 2024-05-04, Miklos Vajna
# version 0.6: Allow autoclosing explicitly listed non-private buffers as well
# 2018-04-10, Sébastien Helleu <[email protected]>
# version 0.5: fix infolist_time for WeeChat >= 2.2 (WeeChat returns a long
# integer instead of a string)
Expand All @@ -37,14 +39,15 @@

SCRIPT_NAME = "buffer_autoclose"
SCRIPT_AUTHOR = "xt <[email protected]>"
SCRIPT_VERSION = "0.5"
SCRIPT_VERSION = "0.6"
SCRIPT_LICENSE = "GPL3"
SCRIPT_DESC = "Automatically close inactive private message buffers"

settings = {
'interval': '1', # How often in minutes to check
'age_limit': '30', # How old in minutes before auto close
'ignore': '', # Buffers to ignore (use full name: server.buffer_name)
'prefer': '', # Buffers to prefer, even if they are not private (use full name: server.buffer_name)
}

if w.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE,
Expand All @@ -64,8 +67,13 @@ def get_all_buffers():
'''Returns list with pointers of all open buffers.'''
buffers = []
infolist = w.infolist_get('buffer', '', '')
preferlist = w.config_get_plugin('prefer').split(',')
while w.infolist_next(infolist):
buffer_type = w.buffer_get_string(w.infolist_pointer(infolist, 'pointer'), 'localvar_type')
name = w.buffer_get_string(w.infolist_pointer(infolist, 'pointer'), 'name')
if name in preferlist:
buffers.append(w.infolist_pointer(infolist, 'pointer'))
continue
if buffer_type == 'private': # we only close private message buffers for now
buffers.append(w.infolist_pointer(infolist, 'pointer'))
w.infolist_free(infolist)
Expand Down
Loading