-
Notifications
You must be signed in to change notification settings - Fork 31
List unknown words
This function lists all the words in the current buffer that do not appear in an external word list. If there are no such words, the function returns to the buffer. You can use the ^
command to return to the buffer (losing the list) or the M
command to return to the buffer and move the word list to another session. The function uses the external word list /usr/share/dict/words
by default. You can use multiple word lists. You can create your own word lists.
Suppose that the buffer includes the words "linux", "Linux", "LINUX", "word", "Word", and "WORD". Suppose that the external word list contains "Linux" and "word" but not "linux", "LINUX", "Word", or "WORD". When you do not pass the function an option argument, the function lists "linux", "LINUX", "Word", and "WORD" but not "Linux" or "word". When you pass the function the -i
option argument, the function lists "linux", "LINUX", and "WORD" but not "Linux", "word", or "Word". When you pass the function the -l
option argument, the function lists "LINUX", "Word", and "WORD" but not "linux", "Linux", or "word". When you pass the function the -u
option argument, the function lists "linux" and "Word" but not "Linux", "LINUX", "word", or "WORD". You can pass the function more than one option argument. When you pass the function the -i
, -l
, and -u
option arguments, the function does not list "linux", "Linux", "LINUX", "word", "Word", or "WORD".
# List the words that are not in a word list.
# usage: <spell [options] [<extra word lists>]
# With option -i, when "word" is in the external list, do not list "Word".
# With option -l, when "Intel" and "AMD" are in the external list, do not list "intel" or "amd".
# With option -u, when "word" and "Intel" are in the external list, do not list "WORD" or "INTEL".
# This function uses session 999 and ~/temporary_file.txt.
function:spell {
db0
# List the words in the buffer.
w999
e999
,s/\s+/\n/gf
,s/^[^[:alpha:]]+//gf
v/^https?:\/\//fs/[^[:alpha:]]+$//gf
g/^$/fd
# Check the external word list for each word.
# To use a different external word list, edit the next line.
w !awk 'BEGIN { for (i = 1; (i < ARGC) && (no_more_options == 0); i++) { if (ARGV[i] ~ /^-[ilu]*$/) { if (ARGV[i] ~ /i/) { initial_capital = 1 } if (ARGV[i] ~ /l/) { lower_case = 1 } if (ARGV[i] ~ /u/) { upper_case = 1 } ARGV[i] = "" } else if (ARGV[i] ~ /^--$/) { no_more_options = 1; ARGV[i] = "" } else { no_more_options = 1 } } } { word_list[$0]++ } END { while ((getline line < "/dev/stdin") > 0) { if (0 == word_list[line]++) { if ((initial_capital != 0) && (line ~ /^[[:upper:]][[:lower:]]*$/)) { if (0 == (tolower(line) in word_list)) { print line } } else if ((lower_case != 0) && (line ~ /^[[:lower:]]*$/)) { if ((0 == ((toupper(substr(line, 1, 1)) substr(line, 2)) in word_list)) && (0 == (toupper(line) in word_list))) { print line } } else if ((upper_case != 0) && (line ~ /^[[:upper:]]*$/)) { if ((0 == (tolower(line) in word_list)) && (0 == ((substr(line, 1, 1) tolower(substr(line, 2))) in word_list))) { print line } } else { print line } } } }' ~0 /usr/share/dict/words > ~/temporary_file.txt
bw
eret
q999
bw
enew
r ~/temporary_file.txt
!rm ~/temporary_file.txt
bw
# Delete the next line if you do not want this feedback.
=
1
if(?) {
^
}
}