Extract buffer-local value handling into a macro.