Skip to content

Commit cff7453

Browse files
vmiklosflashcode
authored andcommitted
buffer_autoclose.py 0.6: add setting to prefer closing some buffers
E.g. the Matrix script maps private rooms with multiple people to buffers in weechat which are nominally not private. This means that these rooms pile up, which is normally solved for real 1:1 private chats. Fix the problem by adding a way to autoclose also non-private buffers. No behavior is changed unless the new config option is set.
1 parent 2db7f4a commit cff7453

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

python/buffer_autoclose.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
# (this script requires WeeChat 0.3.0 or newer)
2121
#
2222
# History:
23+
# 2024-05-04, Miklos Vajna
24+
# version 0.6: Allow autoclosing explicitly listed non-private buffers as well
2325
# 2018-04-10, Sébastien Helleu <[email protected]>
2426
# version 0.5: fix infolist_time for WeeChat >= 2.2 (WeeChat returns a long
2527
# integer instead of a string)
@@ -37,14 +39,15 @@
3739

3840
SCRIPT_NAME = "buffer_autoclose"
3941
SCRIPT_AUTHOR = "xt <[email protected]>"
40-
SCRIPT_VERSION = "0.5"
42+
SCRIPT_VERSION = "0.6"
4143
SCRIPT_LICENSE = "GPL3"
4244
SCRIPT_DESC = "Automatically close inactive private message buffers"
4345

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

5053
if w.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE,
@@ -64,8 +67,13 @@ def get_all_buffers():
6467
'''Returns list with pointers of all open buffers.'''
6568
buffers = []
6669
infolist = w.infolist_get('buffer', '', '')
70+
preferlist = w.config_get_plugin('prefer').split(',')
6771
while w.infolist_next(infolist):
6872
buffer_type = w.buffer_get_string(w.infolist_pointer(infolist, 'pointer'), 'localvar_type')
73+
name = w.buffer_get_string(w.infolist_pointer(infolist, 'pointer'), 'name')
74+
if name in preferlist:
75+
buffers.append(w.infolist_pointer(infolist, 'pointer'))
76+
continue
6977
if buffer_type == 'private': # we only close private message buffers for now
7078
buffers.append(w.infolist_pointer(infolist, 'pointer'))
7179
w.infolist_free(infolist)

0 commit comments

Comments
 (0)