From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Ian Dunn Newsgroups: gmane.emacs.devel Subject: Re: [ELPA] New package: Auto Correct Mode Date: Sun, 27 Aug 2017 14:23:26 -0400 Message-ID: <87val8dg4h.fsf@escafil> References: <87zialc7wx.fsf@escafil> <83shgd3r71.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1503858290 8958 195.159.176.226 (27 Aug 2017 18:24:50 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 27 Aug 2017 18:24:50 +0000 (UTC) User-Agent: mu4e 0.9.19; emacs 26.0.50 Cc: emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Aug 27 20:24:43 2017 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dm2Ej-0001rN-29 for ged-emacs-devel@m.gmane.org; Sun, 27 Aug 2017 20:24:41 +0200 Original-Received: from localhost ([::1]:33570 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dm2Ep-0007oB-IM for ged-emacs-devel@m.gmane.org; Sun, 27 Aug 2017 14:24:47 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:59876) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dm2E6-0007nu-2g for emacs-devel@gnu.org; Sun, 27 Aug 2017 14:24:02 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dm2E5-00020l-8V for emacs-devel@gnu.org; Sun, 27 Aug 2017 14:24:02 -0400 Original-Received: from fencepost.gnu.org ([2001:4830:134:3::e]:56854) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dm2E5-00020h-3e for emacs-devel@gnu.org; Sun, 27 Aug 2017 14:24:01 -0400 Original-Received: from [2604:6000:1010:176:da4d:3352:bae5:f50e] (port=42448 helo=escafil) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1dm2E4-0003c0-JC; Sun, 27 Aug 2017 14:24:00 -0400 In-reply-to: <83shgd3r71.fsf@gnu.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:4830:134:3::e X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:217853 Archived-At: --=-=-= Content-Type: text/plain EZ> Thanks. Please allow me a few stylistic comments: I made the fixes you suggested, and ran checkdoc for good measure. --=-=-= Content-Type: application/emacs-lisp Content-Disposition: attachment; filename=auto-correct.el Content-Transfer-Encoding: quoted-printable ;;; auto-correct.el --- Support for auto-correction -*- lexical-binding: t;= -*- ;; Copyright (C) 2017 Ian Dunn ;; Author: Ian Dunn ;; Maintainer: Ian Dunn ;; Keywords: editing ;; Version: 1.0 ;; Created: 11 May 2016 ;; Modified: 11 May 2016 ;; This program is free software: you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with this program. If not, see . ;;; Commentary: ;; Runs auto-correct for Emacs. By default, nothing is corrected. One must ;; "train" auto-correct before any words are fixed. ;; To train it, use M-x `auto-correct-fix-and-add' with point on a misspell= ed ;; word. This will create a "fix" for the typo. From then on, whenever you ;; misspell that word the same way, `auto-correct-mode' will fix it for you. ;; Expansion is case-insensitive, so trying to fix alice as Alice won't wor= k. ;; Behind the scenes, auto-correct uses an abbrev table, so in order to cle= an ;; out or modify any fixes auto-correct has learned, use `list-abbrevs'. T= his ;; also means that fixes are saved between Emacs sessions along with the ab= brev ;; tables. ;; To add fixes for all misspelled words in a buffer, use ;; `auto-correct-scan-buffer'. ;;; Code: (eval-when-compile (require 'subr-x)) (defgroup auto-correct nil "Auto correction support." :prefix "auto-correct-" :group 'editing) (defvar-local auto-correct-predicate nil "Predicate to check for auto-correct abbrevs.") (defun auto-correct-expand-p () "Return non-nil if auto-correct should operate on the current point. To customize this behavior, set `auto-correct-predicate'." (when auto-correct-predicate (funcall auto-correct-predicate))) (define-abbrev-table 'auto-correct-abbrev-table nil "Abbrev table where automatic corrections are stored." :enable-function #'auto-correct-expand-p) ;;;###autoload (defun auto-correct-fix-and-add (p) "Use `ispell-word' to fix a misspelled word at point. Once the misspelled word is fixed, auto-correct will remember the fix and auto-correct it from then on, so long as `auto-correct-mode' is enabled. With a non-nil argument P (interactively, the prefix argument), create a fix for the typo that will be auto-corrected for buffers using the current local mode." (interactive "P") (when-let ((word-before (thing-at-point 'word)) (correction (ispell-word nil 'quiet))) (when (and correction (consp correction)) ;; The correction was entered by hand. (setq correction (car correction))) (if (and (not (or (eq correction 0) ;; Word was corrected from list (eq correction 'quit))) ;; Session was exited (not (equal word-before correction))) ;; Word was corrected (let ((bef (downcase word-before)) (aft (downcase correction))) (define-abbrev (if p local-abbrev-table auto-correct-abbrev-table) bef aft nil :count 1) ;; Save the abbrevs. (write-abbrev-file) (message "\"%s\" now expands to \"%s\"" bef aft)) (user-error "No correction made at or before point")))) ;;;###autoload (defun auto-correct-scan-buffer () "Scan current buffer for misspelled words. When a misspelled word is found, offer to correct the misspelled word and auto-correct the typo in the future." (interactive) (save-excursion (goto-char (point-min)) (while (forward-word) (auto-correct-fix-and-add nil)) (ispell-pdict-save))) (defun auto-correct-scan-region (start end) "Scan the region between START and END for misspelled words. Interactively, START and END are the current region. When a misspelled word is found, offer to correct the misspelled word and auto-correct the typo in the future." (interactive "r") (save-restriction (narrow-to-region start end) (auto-correct-scan-buffer))) ;;;###autoload (defun auto-correct-scan () "Scan the buffer or region for misspelled words. When a misspelled word is found, offer to correct the misspelled word and auto-correct the typo in the future." (interactive) (if (region-active-p) (auto-correct-scan-region (region-beginning) (region-end)) (auto-correct-scan-buffer))) ;;;###autoload (define-minor-mode auto-correct-mode "Minor mode for auto-correct. Auto correct expansions will only work when this mode is enabled, but auto-correct can be trained with `auto-correct-fix-and-add' even if this mode is disabled. \\{auto-correct-map}" :group 'auto-correct :global t :init-value nil :lighter " Auto-Correct" :keymap '(([remap (ispell-word)] . auto-correct-fix-and-add) ([remap (ispell)] . auto-correct-scan))) (add-to-list 'abbrev-minor-mode-table-alist `(auto-correct-mode ,auto-correct-abbrev-table) 'append #'equal) (provide 'auto-correct) ;;; auto-correct.el ends here --=-=-= Content-Type: text/plain -- Ian Dunn --=-=-=--