zsh-users
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-users@zsh.org
Subject: Re: spell check on the command line
Date: Sat, 25 Oct 2014 00:24:53 -0700	[thread overview]
Message-ID: <141025002453.ZM22210@torch.brasslantern.com> (raw)
In-Reply-To: <mailbox-30175-1414185414-780483@pepper.0.0.200>

On Oct 24, 11:19pm, Eric Smith wrote:
}
} ~> setopt CORRECTALL
} ~> touch this_settting_doess_not_yet_check_the_spelling_of_these_tags_in_a_filename.txt

Oh, so you want a regular spelling dictionary applied in some way, to
substrings within each command-line argument.  Or perhaps only to
substrings within file names, but since it's not possible to tell in
general which arguments are file names (a shortcoming correctall has
already), it's effectively the same problem.

Let's ignore the complications of shell keywords like "elif", complex
commands like loops, and multi-line buffers.  Your basic choices are:

- override the accept-line widget; or
- create (or add to if already using one) a zle-line-finish widget; or
- attempt to handle it all in prexec.

The simplest one is zle-line-finish so I'll do a quick example of that
here.  If you do it in preexec it's more difficult to implement the
(a)bort and (e)dit cases.

I'll assume that anything matching [[:punct:]] is taken as a word break,
and also that a program or function "suggest" exists that will spit out
pairs of wrong words and their replacments (unlike "spell" which emits
only the wrong words).

    zle-line-finish() {
      local spelt misspelt nyae
      print -R ${BUFFER//[[:punct:][:digit:]]/$'\n'} | suggest |
      while read misspelt spelt
      do
	read -k 1 nyae$'?\n'"correct '$misspelt' to '$spelt' [nyae]? "
	case ${nyae:l} in
	(a) zle send-break;;
	(e) zle push-line; return;;
	(y) BUFFER=${BUFFER/$misspelt/$spelt};;
	esac
        [[ -n $nyae ]] && print -nR $nyae
      done
      [[ -n $nyae ]] && { print; zle redisplay }
    }
    zle -N zle-line-finish

Use at your own risk.


  reply	other threads:[~2014-10-25  7:25 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-24 10:54 Eric Smith
2014-10-24 15:36 ` Bart Schaefer
2014-10-24 21:19   ` Eric Smith
2014-10-25  7:24     ` Bart Schaefer [this message]
2014-10-25  8:17       ` Eric Smith
2014-10-25 18:06         ` Bart Schaefer
2014-10-27 11:18           ` Eric Smith

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=141025002453.ZM22210@torch.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).