Mercurial > emacs
comparison lisp/textmodes/bib-mode.el @ 16285:0aa65f31f7e4
(bib-capitalize-title-stop-words): Renamed from capit...
(bib-capitalize-title-stop-regexp): Renamed from capit...
(bib-capitalize-title-region): Renamed from capitalize...
(bib-capitalize-title): Renamed from capitalize...
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Sun, 22 Sep 1996 21:48:30 +0000 |
parents | 83f275dcd93a |
children | 9b831f34ff7d |
comparison
equal
deleted
inserted
replaced
16284:f4cc8bf7ca84 | 16285:0aa65f31f7e4 |
---|---|
161 (setq beg-current (point)) | 161 (setq beg-current (point)) |
162 (setq new-key (bib-find-key bib-assoc)) | 162 (setq new-key (bib-find-key bib-assoc)) |
163 (if (and (not empty) bib-auto-capitalize | 163 (if (and (not empty) bib-auto-capitalize |
164 (looking-at bib-capitalized-fields)) | 164 (looking-at bib-capitalized-fields)) |
165 (save-excursion | 165 (save-excursion |
166 (capitalize-title-region (+ (point) 3) end-current))) | 166 (bib-capitalize-title-region (+ (point) 3) end-current))) |
167 (goto-char beg-current) | 167 (goto-char beg-current) |
168 (if empty | 168 (if empty |
169 (kill-line nil) | 169 (kill-line nil) |
170 (forward-line 1) | 170 (forward-line 1) |
171 ) | 171 ) |
193 (if (get-file-buffer unread-bib-file) | 193 (if (get-file-buffer unread-bib-file) |
194 (append-to-buffer (get-file-buffer unread-bib-file) (mark) (point)) | 194 (append-to-buffer (get-file-buffer unread-bib-file) (mark) (point)) |
195 (append-to-file (mark) (point) unread-bib-file))) | 195 (append-to-file (mark) (point) unread-bib-file))) |
196 | 196 |
197 | 197 |
198 (defvar capitalize-title-stop-words | 198 (defvar bib-capitalize-title-stop-words |
199 (concat | 199 (concat |
200 "the\\|and\\|of\\|is\\|a\\|an\\|of\\|for\\|in\\|to\\|in\\|on\\|at\\|" | 200 "the\\|and\\|of\\|is\\|a\\|an\\|of\\|for\\|in\\|to\\|in\\|on\\|at\\|" |
201 "by\\|with\\|that\\|its") | 201 "by\\|with\\|that\\|its") |
202 "Words not to be capitalized in a title (unless they're the first word | 202 "Words not to be capitalized in a title (unless the first word).") |
203 in the title).") | 203 |
204 | 204 (defvar bib-capitalize-title-stop-regexp |
205 (defvar capitalize-title-stop-regexp | 205 (concat "\\(" bib-capitalize-title-stop-words "\\)\\(\\b\\|'\\)")) |
206 (concat "\\(" capitalize-title-stop-words "\\)\\(\\b\\|'\\)")) | 206 |
207 | 207 (defun bib-capitalize-title-region (begin end) |
208 (defun capitalize-title-region (begin end) | |
209 "Like `capitalize-region', but don't capitalize stop words, except the first." | 208 "Like `capitalize-region', but don't capitalize stop words, except the first." |
210 (interactive "r") | 209 (interactive "r") |
211 (let ((case-fold-search nil) (orig-syntax-table (syntax-table))) | 210 (let ((case-fold-search nil) (orig-syntax-table (syntax-table))) |
212 (unwind-protect | 211 (unwind-protect |
213 (save-restriction | 212 (save-restriction |
219 (capitalize-word 1)) | 218 (capitalize-word 1)) |
220 (while (re-search-forward "\\<" nil t) | 219 (while (re-search-forward "\\<" nil t) |
221 (if (looking-at "[A-Z][a-z]*[A-Z]") | 220 (if (looking-at "[A-Z][a-z]*[A-Z]") |
222 (forward-word 1) | 221 (forward-word 1) |
223 (if (let ((case-fold-search t)) | 222 (if (let ((case-fold-search t)) |
224 (looking-at capitalize-title-stop-regexp)) | 223 (looking-at bib-capitalize-title-stop-regexp)) |
225 (downcase-word 1) | 224 (downcase-word 1) |
226 (capitalize-word 1))) | 225 (capitalize-word 1))) |
227 )) | 226 )) |
228 (set-syntax-table orig-syntax-table)))) | 227 (set-syntax-table orig-syntax-table)))) |
229 | 228 |
230 | 229 |
231 (defun capitalize-title (s) | 230 (defun bib-capitalize-title (s) |
232 "Like `capitalize', but don't capitalize stop words, except the first." | 231 "Like `capitalize', but don't capitalize stop words, except the first." |
233 (save-excursion | 232 (save-excursion |
234 (set-buffer (get-buffer-create "$$$Scratch$$$")) | 233 (set-buffer (get-buffer-create "$$$Scratch$$$")) |
235 (erase-buffer) | 234 (erase-buffer) |
236 (insert s) | 235 (insert s) |
237 (capitalize-title-region (point-min) (point-max)) | 236 (bib-capitalize-title-region (point-min) (point-max)) |
238 (buffer-string))) | 237 (buffer-string))) |
239 | 238 |
240 (provide 'bib-mode) | 239 (provide 'bib-mode) |
241 | 240 |
242 ;;; bib-mode.el ends here | 241 ;;; bib-mode.el ends here |