[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/typo db35f44b9a 01/18: Initial revision
From: |
ELPA Syncer |
Subject: |
[elpa] externals/typo db35f44b9a 01/18: Initial revision |
Date: |
Sun, 26 Mar 2023 08:01:27 -0400 (EDT) |
branch: externals/typo
commit db35f44b9ad59db9e95ef1d598ee8806727ddbcb
Author: Philip Kaludercic <philip.kaludercic@fau.de>
Commit: Philip Kaludercic <philip.kaludercic@fau.de>
Initial revision
---
typo.el | 127 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 127 insertions(+)
diff --git a/typo.el b/typo.el
new file mode 100644
index 0000000000..a6db97e0c9
--- /dev/null
+++ b/typo.el
@@ -0,0 +1,127 @@
+;;; typo.el --- Completion style using typo analysis -*- lexical-binding: t -*-
+
+;; Copyright (C) 2021, 2022, 2023 Philip Kaludercic
+
+;; Author: Philip Kaludercic <philip.kaludercic@fau.de>
+;; URL: https://wwwcip.cs.fau.de/~oj14ozun/src+etc/typo.el
+;; Version: $Id$
+;; Package-Version: 1
+;; Keywords: convenience
+
+;; 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 <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; Typo.el implements a Norvig-Style[0] spell-corrector for Emacs'
+;; completion system.
+;;
+;; To initialize this completion style, evaluate
+;;
+;; (add-to-list 'completion-styles 'typo t)
+;;
+;; or configure the corresponding code in your initialisation file.
+;;
+;; [0] https://norvig.com/spell-correct.html
+
+;;; Code:
+
+(eval-when-compile (require 'inline))
+
+(defgroup typo nil
+ "Completion style using typo analysis."
+ :group 'minibuffer)
+
+(defcustom typo-level 16
+ "Number of edits from the current word to a completion."
+ :type 'natnum)
+
+(defcustom typo-shrink 1
+ "Number of characters a word may shrink."
+ :type 'natnum)
+
+(defcustom typo-expand 4
+ "Number of characters a word may expand."
+ :type 'natnum)
+
+(define-inline typo--test (word key)
+ (inline-letevals (word key)
+ (inline-quote
+ (and (<= (string-distance ,word ,key) typo-level)
+ (<= (- typo-shrink) (- (length ,word) (length ,key)) typo-expand)))))
+
+(defun typo-edits (word collection)
+ "Generate a list of all multi-edit typos of WORD.
+Only words that are in the COLLECTION will be returned. The
+variable `typo-level' specifies how many single-letter typos are
+searched."
+ (let (new-words)
+ (cond
+ ((and (listp collection) (consp (car collection))) ;alist
+ (dolist (entry collection new-words)
+ (let ((key (car entry)))
+ (when (symbolp key)
+ (setq key (symbol-name key)))
+ (when (typo--test word key)
+ (push key new-words)))))
+ ((listp collection) ;regular list
+ (dolist (entry collection new-words)
+ (when (typo--test word entry)
+ (push entry new-words))))
+ ((hash-table-p collection)
+ (maphash
+ (lambda (key _freq)
+ (when (typo--test word key)
+ (push key new-words)))
+ collection)
+ new-words)
+ ((obarrayp collection)
+ (mapatoms
+ (lambda (atom)
+ (setq atom (symbol-name atom))
+ (when (typo--test word atom)
+ (push atom new-words)))
+ collection)
+ new-words)
+ ((functionp collection)
+ (typo-edits word (funcall collection "" #'always t))))))
+
+;;;###autoload
+(defun typo-all-completions (string collection _pred _point)
+ "Generate all versions of the STRING using COLLECTION.
+COLLECTION are as defined in `all-completions'."
+ (typo-edits string collection))
+
+;;;###autoload
+(defun typo-try-completion (string collection _pred _point &optional _metadata)
+ "Generate the most probable version of STRING using COLLECTION.
+COLLECTION are as defined in `try-completion'."
+ (let* ((result (typo-edits string collection))
+ (best (car result)))
+ (dolist (other (cdr result))
+ (when (< (string-distance string other)
+ (string-distance string best))
+ (setq best other)))
+ (and best (cons best (length best)))))
+
+;;;###autoload
+(add-to-list 'completion-styles-alist
+ '(typo typo-try-completion typo-all-completions
+ "Typo-Fixing completion
+I.e. when completing \"foobor\", with \"foobar\" in the
+completion table, this style would attempt replace it with
+\"foobar\", because the two strings are close by."))
+
+(provide 'typo)
+
+;;; typo.el ends here
- [elpa] branch externals/typo created (now 281c9049c1), ELPA Syncer, 2023/03/26
- [elpa] externals/typo 88e9e7cd47 05/18: Summary: Document PRED in 'typo-{all, try}-completion', ELPA Syncer, 2023/03/26
- [elpa] externals/typo a1c54f44e5 07/18: Summary: Allow for 'typo-level' to be a function, ELPA Syncer, 2023/03/26
- [elpa] externals/typo 5be4704665 09/18: Update headers for Sourcehut, ELPA Syncer, 2023/03/26
- [elpa] externals/typo c0283a403d 08/18: Summary: Set 'typo-level' to 'sqrt' by default, ELPA Syncer, 2023/03/26
- [elpa] externals/typo dde7825cc0 06/18: Summary: Check functionp before listp, ELPA Syncer, 2023/03/26
- [elpa] externals/typo db35f44b9a 01/18: Initial revision,
ELPA Syncer <=
- [elpa] externals/typo e259ccabfb 15/18: Add a .gitignore, ELPA Syncer, 2023/03/26
- [elpa] externals/typo 281c9049c1 18/18: Bump version to 1.0.1 for GNU ELPA, ELPA Syncer, 2023/03/26
- [elpa] externals/typo 6c5e695ec2 13/18: Add licensing information, ELPA Syncer, 2023/03/26
- [elpa] externals/typo ffcd6d1d52 16/18: Add more links to the introductory README paragraph, ELPA Syncer, 2023/03/26
- [elpa] externals/typo ecec5009b5 10/18: Add user option 'typo-support-all-completions', ELPA Syncer, 2023/03/26
- [elpa] externals/typo f68cc15541 04/18: Summary: Add a "Package-Requires" header, ELPA Syncer, 2023/03/26
- [elpa] externals/typo e1002d78ab 02/18: Summary: Honor predicate when the collection is a function, ELPA Syncer, 2023/03/26
- [elpa] externals/typo 1a93ca65dd 12/18: Add a basic README file, ELPA Syncer, 2023/03/26
- [elpa] externals/typo e38daaf6cd 03/18: Summary: Lower 'typo-level' to 8, ELPA Syncer, 2023/03/26
- [elpa] externals/typo 2e1c408708 14/18: Add a .dir-locals.el, ELPA Syncer, 2023/03/26