;;; shrtn.el (defun shrtn (text n) "Shorten TEXT to N characters. For readability, preserve first and last characters and discard vowels back-to-front, then consonants back-to-front until the result is N characters long." (interactive "MText: \nNTo N characters: ") (message (shorten-to text n))) (defun shorten-to (text n) "Shorten TEXT to N characters. For readability, preserve first and last characters and discard vowels back-to-front, then consonants back-to-front until the result is N characters long." ; iterative ... (dotimes (i (- (length text) n) text) (setq text (shorten-by-1 text)))) ; recursive ... ; (if (<= (length text) n) ; text ; (shorten-to (shorten-by-1 text) n))) (defun shorten-by-1 (text) "Return copy of TEXT with one character removed. Preserve first and last characters. Discard vowels back-to-front, then consonants back-to-front until the result is N characters long." (concat (substring text 0 1) (if (string-match ".*[aeiouAEIOU]" (substring text 0 -1) 1) (concat (substring text 1 (1- (match-end 0))) (substring text (match-end 0) -1)) (substring text 1 -2)) (substring text -1))) (defun s5n (text) "Abbreviate TEXT as <initial><ellided-letter-count><terminal>." (interactive "MText: ") (message (ellide-count text))) (defun ellide-count (text) "Substitute internal letters with count." (concat (substring text 0 1) (number-to-string (- (length text) 2)) (substring text -1)))