Skip to content

Commit 88427b9

Browse files
Merge branch 'FixNewBufferSettings' into dev
2 parents a6b3e1f + 80fd58e commit 88427b9

File tree

5 files changed

+31
-4
lines changed

5 files changed

+31
-4
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
> - [Fixing comment plugin not using user settings when overriding default setting #3424](https://github.com/zyedidia/micro/pull/3424)
1717
> - [Add the ability lock settings.json and bindings.json for plugins #3618](https://github.com/zyedidia/micro/pull/3618)
1818
> - [Add missing resize in TabMove #3619](https://github.com/zyedidia/micro/pull/3619)
19+
> - [Fixing settings not being applied when saving as a new file #3625](https://github.com/zyedidia/micro/pull/3625)
1920
>
2021
> To see the diff between this and upstream master, click [here](https://github.com/zyedidia/micro/compare/master...Neko-Box-Coder:micro-dev:dev)
2122

internal/action/bufpane.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,7 @@ func BufMapEvent(k Event, action string) {
100100
break
101101
}
102102

103-
// TODO: fix problem when complex bindings have these
104-
// characters (escape them?)
105-
idx := strings.IndexAny(action, "&|,")
103+
idx := util.IndexAnyUnquoted(action, "&|,")
106104
a := action
107105
if idx >= 0 {
108106
a = action[:idx]

internal/buffer/save.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,10 @@ func (b *Buffer) saveToFile(filename string, withSudo bool, autoSave bool) error
232232
absPath, _ := filepath.Abs(filename)
233233
b.AbsPath = absPath
234234
b.isModified = false
235+
ft := b.FileType()
235236
b.UpdateRules()
237+
if b.FileType() != ft {
238+
b.ReloadSettings(true)
239+
}
236240
return err
237241
}

internal/util/util.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,28 @@ func RunePos(b []byte, i int) int {
320320
return CharacterCount(b[:i])
321321
}
322322

323+
// IndexAnyUnquoted returns the first position in s of a character from chars.
324+
// Escaped (with backslash) and quoted (with single or double quotes) characters
325+
// are ignored. Returns -1 if not successful
326+
func IndexAnyUnquoted(s, chars string) int {
327+
var e bool
328+
var q rune
329+
for i, r := range s {
330+
if e {
331+
e = false
332+
} else if (q == 0 || q == '"') && r == '\\' {
333+
e = true
334+
} else if r == q {
335+
q = 0
336+
} else if q == 0 && (r == '\'' || r == '"') {
337+
q = r
338+
} else if q == 0 && strings.IndexRune(chars, r) >= 0 {
339+
return i
340+
}
341+
}
342+
return -1
343+
}
344+
323345
// MakeRelative will attempt to make a relative path between path and base
324346
func MakeRelative(path, base string) (string, error) {
325347
if len(path) > 0 {

runtime/help/keybindings.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ bindings, tab is bound as
6666

6767
This means that if the `Autocomplete` action is successful, the chain will
6868
abort. Otherwise, it will try `IndentSelection`, and if that fails too, it
69-
will execute `InsertTab`.
69+
will execute `InsertTab`. To use `,`, `|` or `&` in an action (as an argument
70+
to a command, for example), escape it with `\` or wrap it in single or double
71+
quotes.
7072

7173
## Binding commands
7274

0 commit comments

Comments
 (0)