Path: utzoo!utgpu!watserv1!watmath!att!occrsh!uokmax!apple!sun-barr!rutgers!rochester!smithln From: smithln@honeydew.cs.rochester.edu (Neil Smithline) Newsgroups: comp.emacs Subject: Re: ALL CAPS-->Mixed case converter? Message-ID: <1990Sep4.194615.5303@cs.rochester.edu> Date: 4 Sep 90 19:46:15 GMT References: <3245@nems.dt.navy.mil> Sender: smithln@cs.rochester.edu (Neil Smithline) Reply-To: smithln@honeydew.cs.rochester.edu (Neil Smithline) Organization: University of Rochester Lines: 75 In-Reply-To: science@nems.dt.navy.mil (Mark Zimmermann) In article <3245@nems.dt.navy.mil>, science@nems (Mark Zimmermann) writes: >does anybody have (a pointer to) an Emacs way to convert ALL CAPITAL >LETTER TEXT into nice mixed-case text? There are obviously many >degrees of sophistication in doing this; I'd like to be able to give >the system a file of words to be capitalized and/or words to be >lowercased and/or words to be all caps (NASA, USA, etc.), to >customize, and it should try to find and capitalize the first word of >each sentence. Any suggestions?? Is this better done in C or awk >than in Emacs?? Tnx for help! - ^z - science@nems.dt.navy.mil Good idea - just wrote a function to do it. The function FIX-CASE takes two arguments or the region and fixes the case. It also will make the words of FIX-CASE-SPECIALS appear as they do in the list. I have included only the word "I" in the list - other good ideas would be your name, organization, etc... Feel free to mail mail me any comments/suggestions/bugs - Neil ================================================================ ;;; ;;; Fix the case of a region of text. ;;; Capitalizes first word of sentences leaving all other words lowercase. ;;; fix-case-specials is a list of words (strings with no whitespace) ;;; that are to be special cased. ;;; Kinda disgusting lisp code but... ;;; Neil Smithline - Tue Sep 4 15:26:35 1990 ;;; (defvar fix-case-specials '("I") "Special words to deal with.") (defun fix-case (start end) "Fix the case of text between point and mark or START and END if called from a program." (interactive "r") (save-excursion (downcase-region start end) ; start with lowercase region (goto-char start) ; skip initial whitespace (skip-chars-forward " \C-i\C-j" end) (setq start (point)) ;; Handle first sentence specially to detect sentence beginning at ;; word at buffer position START (let ((cur (point))) (forward-char 1) (backward-sentence 1) (when (= cur (point)) ; first char should be capitalized (capitalize-word 1))) (goto-char start) ; goto start of next sentence (forward-sentence 1) (let (cur) (while (< (point) end) ; loop through region (setq cur (point)) ; capitalizing each sentence start (capitalize-word 1) (goto-char cur) (forward-sentence 1) (skip-chars-forward " \C-i\C-j" end))) (save-restriction (narrow-to-region start end) ; now fix FIX-CASE-SPECIALS (let ((case-fold-search t) (case-replace t) (specials fix-case-specials)) (while specials ; loop through list of specials (goto-char (point-min)) (replace-string (car specials) (car specials) t) (setq specials (cdr specials))))))) -- ======================================================================== Neil Smithline ARPA: smithln@cs.rochester.edu UUCP: ..!rutgers!rochester!smithln Mail: CS Dept., University of Rochester, Rochester NY 14627 -- ======================================================================== Neil Smithline ARPA: smithln@cs.rochester.edu UUCP: ..!rutgers!rochester!smithln