@@ -88,6 +88,27 @@ vim.api.nvim_create_autocmd({ "BufEnter", "TextChanged", "InsertLeave" }, {
88
88
if M .helpers .deleted_invalid_autocmd (buf , event ) then
89
89
return
90
90
end
91
+
92
+ local filename = vim .api .nvim_buf_get_name (buf )
93
+ local dir = vim .fn .fnamemodify (filename , " :h" )
94
+
95
+ local name = vim .fn .fnamemodify (filename , " :t" )
96
+ local _ , _ , prefix = name :find (" ^(.*)_[^_]*$" )
97
+ name = prefix and name :sub (# prefix + 2 ) or name
98
+
99
+ local lines = vim .api .nvim_buf_get_lines (buf , 0 , - 1 , false )
100
+ local headers , _ , _ = M .helpers .parse_headers (lines )
101
+ local topic = headers [" topic" ] or " "
102
+ topic = topic :gsub (" [^%w%s]" , " " ):lower ()
103
+ topic = topic :gsub (" %s+" , " _" ):gsub (" ^_+" , " " ):gsub (" _+$" , " " )
104
+
105
+ if topic and topic ~= " " and topic ~= prefix then
106
+ local new_filename = dir .. " /" .. topic .. " _" .. name
107
+ M .logger .debug (" gpchat: renaming buffer " .. buf .. " from " .. filename .. " to " .. new_filename )
108
+ vim .api .nvim_buf_set_name (buf , new_filename )
109
+ M .helpers .delete_file (filename )
110
+ end
111
+
91
112
-- M.logger.debug("gpchat: saving buffer " .. buf .. " " .. vim.json.encode(event))
92
113
vim .api .nvim_command (" silent! write" )
93
114
end ,
0 commit comments