Repository: zyedidia/micro
File: internal/buffer/settings.go (Go)

Code before:
	"crypto/md5"
	"reflect"

	"github.com/zyedidia/micro/v2/internal/config"
	ulua "github.com/zyedidia/micro/v2/internal/lua"
	"github.com/zyedidia/micro/v2/internal/screen"
	luar "layeh.com/gopher-luar"
)

func (b *Buffer) ReloadSettings(reloadFiletype bool) {
	settings := config.ParsedSettings()

	_, local := b.LocalSettings["filetype"]
	_, volatile := config.VolatileSettings["filetype"]
	if reloadFiletype && !local && !volatile {
		// need to update filetype before updating other settings based on it
		b.Settings["filetype"] = "unknown"
		if v, ok := settings["filetype"]; ok {
			b.Settings["filetype"] = v
		}
	}

	// update syntax rules, which will also update filetype if needed
	b.UpdateRules()

	config.UpdateFileTypeLocals(settings, b.Settings["filetype"].(string))
	for k, v := range config.DefaultCommonSettings() {
		if k == "filetype" {
			// prevent recursion
			continue
		}
		if _, ok := config.VolatileSettings[k]; ok {
			// reload should not override volatile settings
			continue
		}
		if _, ok := b.LocalSettings[k]; ok {
			// reload should not override local settings
			continue
		}
		if _, ok := settings[k]; ok {
			b.DoSetOptionNative(k, settings[k])
		} else {
			b.DoSetOptionNative(k, v)
		}
	}
}

func (b *Buffer) DoSetOptionNative(option string, nativeValue interface{}) {
	oldValue := b.Settings[option]
	if reflect.DeepEqual(oldValue, nativeValue) {
		return

Review comment (suggestion):
Technically this is a regression (although fixed by https://github.com/zyedidia/micro/pull/3662/commits/e16c8de0b2364ac9d0a6d95c1a4b9a7e9105e059 afterwards): glob settings no longer updated on reload.

I.e. if we don't want any single commit to introduce regressions (to keep it bisection-friendly etc), we should call both `UpdatePathGlobLocals()` and `UpdateFileTypeLocals()` here, and then in https://github.com/zyedidia/micro/pull/3662/commits/e16c8de0b2364ac9d0a6d95c1a4b9a7e9105e059 move `UpdatePathGlobLocals()` (and change the commit message of https://github.com/zyedidia/micro/pull/3662/commits/e16c8de0b2364ac9d0a6d95c1a4b9a7e9105e059 to describe the issue it actually fixes).

BTW right now this commit message in https://github.com/zyedidia/micro/pull/3662/commits/e16c8de0b2364ac9d0a6d95c1a4b9a7e9105e059 sounds quite tongue-twisted, describing the trees rather than the forest, making a very simple issue and a very simple fix sound like it was quantum physics, instead of simply saying something like "we need to update glob-based local settings on reload as well" (or if we rearrange the 2 commits as I've suggested, then something like "Like in NewBuffer(), we need to update glob-based local settings before updating the filetype, since the filetype itself may be among those glob-based local settings").

Code after:
	"crypto/md5"
	"reflect"

	"github.com/zyedidia/micro/v2/internal/config"
	ulua "github.com/zyedidia/micro/v2/internal/lua"
	"github.com/zyedidia/micro/v2/internal/screen"
	luar "layeh.com/gopher-luar"
)

func (b *Buffer) ReloadSettings(reloadFiletype bool) {
	settings := config.ParsedSettings()
	config.UpdatePathGlobLocals(settings, b.AbsPath)

	oldFiletype := b.Settings["filetype"].(string)

	_, local := b.LocalSettings["filetype"]
	_, volatile := config.VolatileSettings["filetype"]
	if reloadFiletype && !local && !volatile {
		// need to update filetype before updating other settings based on it
		b.Settings["filetype"] = "unknown"
		if v, ok := settings["filetype"]; ok {
			b.Settings["filetype"] = v
		}
	}

	// update syntax rules, which will also update filetype if needed
	b.UpdateRules()

	curFiletype := b.Settings["filetype"].(string)
	if oldFiletype != curFiletype {
		b.doCallbacks("filetype", oldFiletype, curFiletype)
	}

	config.UpdateFileTypeLocals(settings, curFiletype)

	for k, v := range config.DefaultCommonSettings() {
		if k == "filetype" {
			// prevent recursion
			continue
		}
		if _, ok := config.VolatileSettings[k]; ok {
			// reload should not override volatile settings
			continue
		}
		if _, ok := b.LocalSettings[k]; ok {
			// reload should not override local settings
			continue
		}
		if _, ok := settings[k]; ok {
			b.DoSetOptionNative(k, settings[k])
		} else {