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: [ELPA] New package: Auto Correct Mode Date: Sun, 27 Aug 2017 12:06:06 -0400 Message-ID: <87zialc7wx.fsf@escafil> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1503850011 7101 195.159.176.226 (27 Aug 2017 16:06:51 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 27 Aug 2017 16:06:51 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Aug 27 18:06:47 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 1dm05C-0001ND-8t for ged-emacs-devel@m.gmane.org; Sun, 27 Aug 2017 18:06:42 +0200 Original-Received: from localhost ([::1]:33228 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dm05I-0001mD-MG for ged-emacs-devel@m.gmane.org; Sun, 27 Aug 2017 12:06:48 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:43462) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dm05C-0001m7-9O for emacs-devel@gnu.org; Sun, 27 Aug 2017 12:06:43 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dm05B-0000YQ-9B for emacs-devel@gnu.org; Sun, 27 Aug 2017 12:06:42 -0400 Original-Received: from fencepost.gnu.org ([2001:4830:134:3::e]:54930) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dm05B-0000YM-46 for emacs-devel@gnu.org; Sun, 27 Aug 2017 12:06:41 -0400 Original-Received: from [2604:6000:1010:176:da4d:3352:bae5:f50e] (port=59846 helo=escafil) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1dm05A-0002w0-PS for emacs-devel@gnu.org; Sun, 27 Aug 2017 12:06:41 -0400 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:217849 Archived-At: --=-=-= Content-Type: text/plain I'd like to submit auto-correct.el as a single-file package to ELPA. It's a small package that integrates with ispell and abbrev to provide auto-correct functionality in Emacs. It uses a separate abbrev table, which is only enabled in auto-correct-mode, and only auto-corrects if a buffer-local predicate returns true. As with the last two I've submitted today, if no one has any objections, I'll update the copyright and push it to the git repo. --=-=-= 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: ;;; 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 () (when auto-correct-predicate (funcall auto-correct-predicate))) (define-abbrev-table 'auto-correct-abbrev-table nil "" :enable-function #'auto-correct-expand-p) ;;;###autoload (defun auto-correct-fix-and-add (p) "Call `ispell-word', then create an abbrev for it. With prefix P, create local abbrev. Otherwise it will be global. Originally pulled from endless parenthesis." (interactive "P") (when-let ((word-before (thing-at-point 'word)) (correction (ispell-word nil 'quiet))) (when (and correction (consp correction)) ;; 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 () "Scans current buffer for misspelled words. When a misspelled word is found, offers to correct and add." (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) (interactive "r") (save-restriction (narrow-to-region start end) (auto-correct-scan-buffer))) ;;;###autoload (defun auto-correct-scan () "Scans the buffer or region." (interactive) (if (region-active-p) (auto-correct-scan-region (region-beginning) (region-end)) (auto-correct-scan-buffer))) ;;;###autoload (define-minor-mode auto-correct-mode "\\{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 --=-=-=--