;;; accent-html.el --- replace and auto-replace when saving of the HTML &foo; ;; Copyright (C) 1999, 2001 Stéphane Levant ;; Author: Stéphane Levant ;; Created: Feb 1999 ;; Keywords: wp, languages, i18n ;; Version: 1.1 ;; URL: http://arsunik.free.fr/emacs ;; This file 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 2, or (at your option) ;; any later version. ;; This file 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 GNU Emacs; see the file COPYING. If not, write to ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330, ;; Boston, MA 02111-1307, USA. ;;; Commentary: ;; Replace all the HTML special char &foo; (ç é ©...) ;; by the corresponding character (ç, é, ©...) or inversly, replace all these ;; characters by the corresponding &foo; ;; Special characters like & < and ≶ are unchanged ;; The remplacement can by done automaticaly when saving a file so you'll ;; never see any &foo; in the buffer, but they are already saved in the file. ;; I think the automatic remplacement is obsolete because: ;; * some HTML preprocessor can do that ;; * accents can be put directly in HTML files using the META TAGS: ;; ;; So, I only use the accent-html function. ;; INSTALL: Just adds this lines to your .emacs : ;; ;; accent-html ;; (autoload 'accent-html "accent-html.el" "" t) ;; (autoload 'accent-html-mode "accent-html.el" "" t) ;; You can bind a key to accent-html, for example: ;; (global-set-key "\^x\^h" 'accent-html) ;; USAGE: ;; To replace all the &foo; of the buffer: M-x accent-html ;; To do the inverse: C-- M-x accent-html ;; To never see &foo; in the buffer but to have them automaticaly saved in ;; file, add this line to your .emacs: ;; (add-hook 'html-mode-hook 'accent-html-mode) ;; NB: C-x C-s will localy be bound to accent-html-save-buffer ;; The latest version should be available at: ;; ;; TODO : ;; a minor-mode ;;; Code: (defvar accent-html-alist '((" " . " ") ("¡" . "¡") ("¢" . "¢") ("£" . "£") ("¤" . "¤") ("¥" . "¥") ("¦" . "¦") ("§" . "§") ("¨" . "¨") ("©" . "©") ("ª" . "ª") ("«" . "«") ("¬" . "¬") ("­" . "­") ("®" . "®") ("¯" . "¯") ("°" . "°") ("±" . "±") ("²" . "²") ("³" . "³") ("´" . "´") ("µ" . "µ") ("¶" . "¶") ("·" . "·") ("¸" . "¸") ("¹" . "¹") ("º" . "º") ("»" . "»") ("¼" . "¼") ("½" . "½") ("¾" . "¾") ("¿" . "¿") ("À" . "À") ("Á" . "Á") ("Â" . "Â") ("Ã" . "Ã") ("Ä" . "Ä") ("Å" . "Å") ("Æ" . "Æ") ("Ç" . "Ç") ("È" . "È") ("É" . "É") ("Ê" . "Ê") ("Ë" . "Ë") ("Ì" . "Ì") ("Í" . "Í") ("Î" . "Î") ("Ï" . "Ï") ("Ð" . "Ð") ("Ñ" . "Ñ") ("Ò" . "Ò") ("Ó" . "Ó") ("Ô" . "Ô") ("Õ" . "Õ") ("Ö" . "Ö") ("×" . "×") ("Ø" . "Ø") ("Ù" . "Ù") ("Ú" . "Ú") ("Û" . "Û") ("Ü" . "Ü") ("Ý" . "Ý") ("Þ" . "Þ") ("ß" . "ß") ("à" . "à") ("á" . "á") ("â" . "â") ("ã" . "ã") ("ä" . "ä") ("å" . "å") ("æ" . "æ") ("ç" . "ç") ("è" . "è") ("é" . "é") ("ê" . "ê") ("ë" . "ë") ("ì" . "ì") ("í" . "í") ("î" . "î") ("ï" . "ï") ("ð" . "ð") ("ñ" . "ñ") ("ò" . "ò") ("ó" . "ó") ("ô" . "ô") ("õ" . "õ") ("ö" . "ö") ("÷" . "÷") ("ø" . "ø") ("ù" . "ù") ("ú" . "ú") ("û" . "û") ("ü" . "ü") ("ý" . "ý") ("þ" . "þ") ("ÿ" . "ÿ"))) ;;;###autoload (defun accent-html (arg) "Replace all HTML &foo; by the corresponding char. With an argument, do the inverse. Special characters like & < and ≶ are unchanged" (interactive "P") (save-excursion (let ((l accent-html-alist) (maj case-fold-search)) (setq case-fold-search nil) (if arg (progn (while l (goto-char (point-min)) (while (search-forward (car (car l)) nil t) (replace-match (cdr (car l)) t t)) (setq l (cdr l)))) (while l (goto-char (point-min)) (while (search-forward (cdr (car l)) nil t) (replace-match (car (car l)) t t)) (setq l (cdr l)))) (setq case-fold-search maj)))) (defun accent-html-save-buffer() "Save the buffer with all special characters remplacing by &foo; Special characters like & < and ≶ are unchanged" (interactive) (let ((err nil)) (accent-html t) (condition-case t (save-buffer) (error (setq err nil))) (accent-html nil) (if err (error "Impossible de sauver le buffer") (set-buffer-modified-p nil)))) ;;;###autoload (defun accent-html-mode() "A minor mode which will automatically replace all HTML &foo; by the corresponding character when saving buffer. So you'll never see any &foo; in the buffer, but they are already saved in the file. Special characters like & < and ≶ are unchanged NB: C-x C-s will localy be bound to accent-html-save-buffer" (interactive) (local-set-key "\^x\^s" 'accent-html-save-buffer) (local-set-key [menu-bar files save-buffer] 'accent-html-save-buffer) (accent-html nil) (set-buffer-modified-p nil)) ;;; accent-html.el ends here