[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

auto-capitalization snippets

From: Dave Love
Subject: auto-capitalization snippets
Date: 30 Apr 2002 17:18:32 +0100
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.1.95

I think there are some fairly complicated approaches to
auto-capitalization around, but you can do it simply with abbrevs.
I'm sure this technique isn't new, but I don't recall seeing a recipe.
Here's one people might find useful.  No need to doff your caps.

I use the following functions, along with these sorts of abbrev

  (define-abbrev text-mode-abbrev-table "emacs" "Emacs")
  (define-abbrev text-mode-abbrev-table "i" "I" #'abbrev-not-at-stop)
  (define-abbrev text-mode-abbrev-table "i'm" "I'm") ; ... egocentric

(defun maybe-capitalize-bos ()
  "If point is at the end of the first word in a sentence, capitalize it."
  (if (= (point)
           (forward-word 1)
      (capitalize-word -1)))

;; Capitalize words at beginning of sentence.
(add-hook 'text-mode-hook (lambda ()
                            (make-local-hook 'pre-abbrev-expand-hook)
                            (add-hook 'pre-abbrev-expand-hook
                                      nil t)))

(defun abbrev-not-at-stop ()          ; avoid `i.e.' -> `I.e.'
  "Unexpand abbrev if it was just expanded by a full stop.
Intended as an abbrev hook function."
  (if (eq ?. last-command-char)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]