mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-16 05:47:06 +09:00
Replaced IsNonAlphaNumeric() with IsNonWordChar()
This commit is contained in:
@@ -745,8 +745,8 @@ func (h *BufPane) Autocomplete() bool {
|
|||||||
}
|
}
|
||||||
r := h.Cursor.RuneUnder(h.Cursor.X)
|
r := h.Cursor.RuneUnder(h.Cursor.X)
|
||||||
prev := h.Cursor.RuneUnder(h.Cursor.X - 1)
|
prev := h.Cursor.RuneUnder(h.Cursor.X - 1)
|
||||||
if !util.IsAutocomplete(prev) || !util.IsNonAlphaNumeric(r) {
|
if !util.IsAutocomplete(prev) || util.IsWordChar(r) {
|
||||||
// don't autocomplete if cursor is on alpha numeric character (middle of a word)
|
// don't autocomplete if cursor is within a word
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -73,11 +73,11 @@ func (b *Buffer) GetWord() ([]byte, int) {
|
|||||||
return []byte{}, -1
|
return []byte{}, -1
|
||||||
}
|
}
|
||||||
|
|
||||||
if util.IsNonAlphaNumeric(b.RuneAt(c.Loc.Move(-1, b))) {
|
if util.IsNonWordChar(b.RuneAt(c.Loc.Move(-1, b))) {
|
||||||
return []byte{}, c.X
|
return []byte{}, c.X
|
||||||
}
|
}
|
||||||
|
|
||||||
args := bytes.FieldsFunc(l, util.IsNonAlphaNumeric)
|
args := bytes.FieldsFunc(l, util.IsNonWordChar)
|
||||||
input := args[len(args)-1]
|
input := args[len(args)-1]
|
||||||
return input, c.X - util.CharacterCount(input)
|
return input, c.X - util.CharacterCount(input)
|
||||||
}
|
}
|
||||||
@@ -166,7 +166,7 @@ func BufferComplete(b *Buffer) ([]string, []string) {
|
|||||||
var suggestions []string
|
var suggestions []string
|
||||||
for i := c.Y; i >= 0; i-- {
|
for i := c.Y; i >= 0; i-- {
|
||||||
l := b.LineBytes(i)
|
l := b.LineBytes(i)
|
||||||
words := bytes.FieldsFunc(l, util.IsNonAlphaNumeric)
|
words := bytes.FieldsFunc(l, util.IsNonWordChar)
|
||||||
for _, w := range words {
|
for _, w := range words {
|
||||||
if bytes.HasPrefix(w, input) && util.CharacterCount(w) > inputLen {
|
if bytes.HasPrefix(w, input) && util.CharacterCount(w) > inputLen {
|
||||||
strw := string(w)
|
strw := string(w)
|
||||||
@@ -179,7 +179,7 @@ func BufferComplete(b *Buffer) ([]string, []string) {
|
|||||||
}
|
}
|
||||||
for i := c.Y + 1; i < b.LinesNum(); i++ {
|
for i := c.Y + 1; i < b.LinesNum(); i++ {
|
||||||
l := b.LineBytes(i)
|
l := b.LineBytes(i)
|
||||||
words := bytes.FieldsFunc(l, util.IsNonAlphaNumeric)
|
words := bytes.FieldsFunc(l, util.IsNonWordChar)
|
||||||
for _, w := range words {
|
for _, w := range words {
|
||||||
if bytes.HasPrefix(w, input) && util.CharacterCount(w) > inputLen {
|
if bytes.HasPrefix(w, input) && util.CharacterCount(w) > inputLen {
|
||||||
strw := string(w)
|
strw := string(w)
|
||||||
|
|||||||
@@ -218,12 +218,19 @@ func FSize(f *os.File) int64 {
|
|||||||
return fi.Size()
|
return fi.Size()
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsWordChar returns whether or not the string is a 'word character'
|
// IsWordChar returns whether or not a rune is a 'word character'
|
||||||
// Word characters are defined as numbers, letters, or '_'
|
// Word characters are defined as numbers, letters or '_'
|
||||||
func IsWordChar(r rune) bool {
|
func IsWordChar(r rune) bool {
|
||||||
return unicode.IsLetter(r) || unicode.IsNumber(r) || r == '_'
|
return unicode.IsLetter(r) || unicode.IsNumber(r) || r == '_'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsNonWordChar returns whether or not a rune is not a 'word character'
|
||||||
|
// Non word characters are defined as all characters not being numbers, letters or '_'
|
||||||
|
// See IsWordChar()
|
||||||
|
func IsNonWordChar(r rune) bool {
|
||||||
|
return !IsWordChar(r)
|
||||||
|
}
|
||||||
|
|
||||||
// Spaces returns a string with n spaces
|
// Spaces returns a string with n spaces
|
||||||
func Spaces(n int) string {
|
func Spaces(n int) string {
|
||||||
return strings.Repeat(" ", n)
|
return strings.Repeat(" ", n)
|
||||||
@@ -445,14 +452,9 @@ func Clamp(val, min, max int) int {
|
|||||||
return val
|
return val
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsNonAlphaNumeric returns if the rune is not a number of letter or underscore.
|
|
||||||
func IsNonAlphaNumeric(c rune) bool {
|
|
||||||
return !unicode.IsLetter(c) && !unicode.IsNumber(c) && c != '_'
|
|
||||||
}
|
|
||||||
|
|
||||||
// IsAutocomplete returns whether a character should begin an autocompletion.
|
// IsAutocomplete returns whether a character should begin an autocompletion.
|
||||||
func IsAutocomplete(c rune) bool {
|
func IsAutocomplete(c rune) bool {
|
||||||
return c == '.' || !IsNonAlphaNumeric(c)
|
return c == '.' || IsWordChar(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ParseSpecial replaces escaped ts with '\t'.
|
// ParseSpecial replaces escaped ts with '\t'.
|
||||||
|
|||||||
Reference in New Issue
Block a user