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 Capitalize Mode Date: Sun, 27 Aug 2017 12:02:21 -0400 Message-ID: <87d17hdmnm.fsf@escafil> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1503849788 30501 195.159.176.226 (27 Aug 2017 16:03:08 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 27 Aug 2017 16:03:08 +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:03:04 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 1dm01e-0007eO-JS for ged-emacs-devel@m.gmane.org; Sun, 27 Aug 2017 18:03:02 +0200 Original-Received: from localhost ([::1]:33190 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dm01l-0000Sq-Gr for ged-emacs-devel@m.gmane.org; Sun, 27 Aug 2017 12:03:09 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:42520) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dm01Y-0000RU-Ki for emacs-devel@gnu.org; Sun, 27 Aug 2017 12:02:57 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dm01X-0007R5-MX for emacs-devel@gnu.org; Sun, 27 Aug 2017 12:02:56 -0400 Original-Received: from fencepost.gnu.org ([2001:4830:134:3::e]:54884) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dm01X-0007Qz-I8 for emacs-devel@gnu.org; Sun, 27 Aug 2017 12:02:55 -0400 Original-Received: from [2604:6000:1010:176:da4d:3352:bae5:f50e] (port=52618 helo=escafil) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1dm01X-00055t-92 for emacs-devel@gnu.org; Sun, 27 Aug 2017 12:02:55 -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:217848 Archived-At: --=-=-= Content-Type: text/plain I'd like to submit auto-capitalize-mode.el to ELPA as a single-package file. It's a small package that creates a minor-mode for automatic sentence capitalization, complete with buffer-local enable predicate and sentence bound finding. If there are no issues, I'll push it to the git repo myself. --=-=-= Content-Type: application/emacs-lisp Content-Disposition: attachment; filename=auto-capitalize-mode.el Content-Transfer-Encoding: quoted-printable ;;; auto-capitalize-mode.el --- Minor mode to automatically capitalize the = start of a sentence. -*- lexical-binding: t; -*- ;; Copyright (C) 2017 Ian Dunn ;; Author: Ian Dunn ;; Maintainer: Ian Dunn ;; Keywords: editing ;; Version: 1.0 ;; Created: 11 Apr 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: ;; Automatically capitalizes the first word of a sentence as you type. The ;; bounds of a sentence are determined by local variable ;; `auto-capitalize-sentence-bounds-function'. ;; Auto-capitalize can be used as a local or global minor mode. Further co= ntrol ;; can be obtained by modifying the local variable `auto-capitalize-predica= te'. ;;; Code: (eval-when-compile (require 'subr-x)) (require 'thingatpt) (defvar-local auto-capitalize-predicate nil "Predicate to check for auto-capitalization. Should be a function of no arguments, and return non-nil if auto-capitalization should be performed at the current point. For example, this could be a function to check if point is in a comment.") (defun auto-capitalize-should-capitalize-p () "Returns non-nil if auto-capitalization should be performed." (when auto-capitalize-predicate (funcall auto-capitalize-predicate))) (defun auto-capitalize--default-sentence-bounds () (bounds-of-thing-at-point 'sentence)) (defvar-local auto-capitalize-sentence-bounds-function #'auto-capitalize--default-sentence-bounds "Function to determine the bounds of the current sentence. Should return the bounds just as `bounds-of-thing-at-point'.") (defun auto-capitalize--run () "Automatically capitalize the word at point if it is the start of a sente= nce." ;; Only do this if the last inserted character isn't part of a word, ;; (preceding-char) is the previously inserted character; ;; I also need the character before that (It must be a word constituent) (when (and (auto-capitalize-should-capitalize-p) (not (or (bobp) (eq (char-syntax (preceding-char)) ?w))) (eq (char-syntax (save-excursion (forward-char -1) (preceding-char))) ?w)) (save-excursion ;; Move back to the word that was just finished, and determine if it ;; starts a sentence. (backward-word-strictly) ;; Ensure we're still expected to capitalize. Case: New character pu= t us ;; inside a string, but backward-word-strictly brought us outside the ;; string. (when (auto-capitalize-should-capitalize-p) (when-let ((word-bounds (bounds-of-thing-at-point 'word)) (sentence-bounds (funcall auto-capitalize-sentence-bound= s-function))) (cond ((let ((case-fold-search nil)) (string-match-p "[[:upper:]]" (word-at-point))) nil) ((eq (car word-bounds) (car sentence-bounds)) (capitalize-word 1= )) ;; Word bound will only ever be one greater than the sentence bo= und if ;; the sentence begins with some sort of punctuation. Remember,= spaces ;; don=E2=80=99t count, so if we have a sentence starting with "= A ball...", ;; =E2=80=99ball=E2=80=99 wont trigger this, only =E2=80=99A=E2= =80=99. ((eq (car word-bounds) (1+ (car sentence-bounds))) (capitalize-word 1)))))))) ;;;###autoload (define-minor-mode auto-capitalize-mode "Automatically capitalize the start of a sentence." :init-value nil :lighter " Auto-Capitalize" :global nil (if auto-capitalize-mode (progn (add-hook 'post-self-insert-hook 'auto-capitalize--run nil t)) (remove-hook 'post-self-insert-hook 'auto-capitalize--run t))) (defun turn-on-auto-capitalize-mode () (auto-capitalize-mode 1)) ;;;###autoload (define-globalized-minor-mode global-auto-capitalize-mode auto-capitalize-mode turn-on-auto-capitalize-mode) (provide 'auto-capitalize-mode) ;;; auto-capitalize-mode.el ends here --=-=-= Content-Type: text/plain -- Ian Dunn --=-=-=--