diff options
author | Norbert Preining <norbert@preining.info> | 2019-09-02 13:46:59 +0900 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2019-09-02 13:46:59 +0900 |
commit | e0c6872cf40896c7be36b11dcc744620f10adf1d (patch) | |
tree | 60335e10d2f4354b0674ec22d7b53f0f8abee672 /support/iso-tex |
Initial commit
Diffstat (limited to 'support/iso-tex')
-rw-r--r-- | support/iso-tex/iso-html.el | 351 | ||||
-rw-r--r-- | support/iso-tex/iso-tex.el | 496 | ||||
-rw-r--r-- | support/iso-tex/multi-mode.el | 288 | ||||
-rw-r--r-- | support/iso-tex/prolog-indent.el | 371 |
4 files changed, 1506 insertions, 0 deletions
diff --git a/support/iso-tex/iso-html.el b/support/iso-tex/iso-html.el new file mode 100644 index 0000000000..31ab871c6a --- /dev/null +++ b/support/iso-tex/iso-html.el @@ -0,0 +1,351 @@ +;;; iso-html.el --- Translating HTML to ISO-8859/1 while editing a file +;;***************************************************************************** +;; $Id: iso-html.el,v 1.1 1994/10/27 10:18:55 gerd Exp gerd $ +;;***************************************************************************** +;; +;; Description: +;; When using HTML it is highly desirable to display national +;; characters contained in the ISO-8859/1 character set. Editing +;; files with ISO-8859/1 characters is enabled in GNU Emacs since +;; version 19. +;; +;; The solution is iso-html.el. The extended +;; character set is used only temporarily during editing of a +;; file in Emacs. The HTML file contains pure ASCII +;; representations of the extended characters. +;; +;; iso-html.el provides a minor mode which anchors itself in +;; various hooks to perform translations when reading or writing +;; files. +;; +;; No provisions are made to insert ISO-8859/1 characters since +;; other packages are availlable for this purpose. +;; +;; +;; Installation: +;; 1. Ensure that iso-html.el is on the load-path. +;; 2. For efficiency it might be desirable to byte-compile +;; iso-html.el. +;; 3. Put the following in your .emacs file or a similar place +;; where it is loaded when needed. +;; +;; (autoload 'iso-html-minor-mode +;; "iso-html" +;; "Translate HTML to ISO 8859/1 while visiting a file." +;; t) +;; +;; 4. Enable the iso-html minor mode for the appropriate +;; files. This depends on the major mode you use for editing +;; HTML files. For this purpose you can use the entry hook +;; of this mode. E.g. +;; +;; (setq html-mode-hook +;; (function (lambda () (interactive) +;; (iso-html-minor-mode 1) +;; ; and other initializations +;; ; ... +;; ))) +;; +;; Bugs and Problems: +;; +;; - There might be problems when saving a narrowed buffer. +;; - Point might not be restored properly. +;; +;; - Writing of a region is not supported. There seems to be no +;; appropriate hook. +;; +;; +;; To do: +;; - iso-html can be used for a wider range of translations when +;; reading and writing. Maybe it's worth extracting those +;; routines which are more general and make iso-html a sample +;; instance of the general routines. +;; +;; +;; Changes: +;; - Extracted from iso-tex.el +;; +;; Author: +;; Gerd Neugebauer +;; Ödenburger Str. 16 +;; 64295 Darmstadt (Germany) +;; +;; Net: gerd@imn.th-leipzig.de +;; +;;***************************************************************************** +;; LCD Archive Entry: +;; iso-html|Gerd Neugebauer|gerd@imn.th-leipzig.de| +;; Translating HTML to ISO-8859/1 while editing a file.| +;; $Date: 1994/10/27 10:18:55 $|$Revision: 1.1 $|| +;;***************************************************************************** +;; +;; Copyright (C) 1994 Gerd Neugebauer +;; +;; iso-html.el is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY. No author or distributor +;; accepts responsibility to anyone for the consequences of using it +;; or for whether it serves any particular purpose or works at all, +;; unless he says so in writing. Refer to the GNU General Public +;; License for full details. +;; +;; Everyone is granted permission to copy, modify and redistribute +;; iso-html.el, but only under the conditions described in the +;; GNU General Public License. A copy of this license is +;; supposed to have been given to you along with GNU Emacs so you +;; can know your rights and responsibilities. It should be in a +;; file named COPYING. Among other things, the copyright notice +;; and this notice must be preserved on all copies. +;; + +;;;---------------------------------------------------------------------------- +;;; Variable definitions and initializations + +(defvar iso-html-minor-mode nil + "Variable indicating when iso-html-minor-mode is active.") + +(or (assq 'iso-html-minor-mode minor-mode-alist) + (setq minor-mode-alist (cons '(iso-html-minor-mode " ISO-HTML") + minor-mode-alist))) + +(defvar iso-html-minor-mode-initialized nil + "Variable indicating if iso-html-minor-mode is already initialized in this +buffer. This variable is buffer local.") + +(make-variable-buffer-local 'iso-html-minor-mode-initialized) + +(defvar html-2-iso-regex + "&[a-zA-Z]*;" + "Regular expression to pre-select substrings to be translated by html-2-iso.") +(defvar iso-2-html-regex "[¡-ÿ]" + "Regular expression to pre-select substrings to be translated by iso-2-html.") +(defvar iso-2-html-alist nil + "Alist of CHAR.STRING pairs used by iso-2-html.") +(defvar html-2-iso-alist nil + "Alist of STRING.ISO-CHAR pairs used by html-2-iso.") + +(defun define-iso-html (char &optional string &rest names) + "Define a translation between ISO-8859/1 characters and Html sequences. +CHAR is the ISO-8859/1 character code as a single letter string. +If STRING is non nil then it is used as representation of CHAR. +The optional remaining arguments are used to translate Html sequences to +characters." + (if string (setq iso-2-html-alist (cons + (cons (string-to-char char) string) + iso-2-html-alist))) + (while names + (setq html-2-iso-alist (cons (cons (car names) char) + html-2-iso-alist)) + (setq names (cdr names)) + ) +) + +(if (null iso-2-html-alist) + (progn +; (define-iso-html "¡" "" "" ) +; (define-iso-html "¢" "" "" ) +; (define-iso-html "£" "" "" ) +; (define-iso-html "¤" "" "" ) + ; (define-iso-html "¥" "" "" ) + ; (define-iso-html "¦" "" "" ) + ; (define-iso-html "§" "" "" ) + ; (define-iso-html "¨" "" "" ) + ; (define-iso-html "©" "" "" ) + ; (define-iso-html "ª" "" "" ) + ; (define-iso-html "«" "" "" ) + ; (define-iso-html "¬" "" "" ) + ; (define-iso-html "" "" "" ) + ; (define-iso-html "®" "" "" ) + ; (define-iso-html "¯" "" "" ) + ; (define-iso-html "°" "" "" ) + ; (define-iso-html "±" "" "" ) + ; (define-iso-html "²" "" "" ) + ; (define-iso-html "³" "" "" ) + ; (define-iso-html "´" "" "" ) + ; (define-iso-html "µ" "" "" ) + ; (define-iso-html "¶" "" "" ) + ; (define-iso-html "·" "" "" ) + ; (define-iso-html "¸" "" "" ) + ; (define-iso-html "¹" "" "" ) + ; (define-iso-html "º" "" "" ) + ; (define-iso-html "»" "" "" ) + ; (define-iso-html "¼" "" "" ) + ; (define-iso-html "½" "" "" ) + ; (define-iso-html "¾" "" "" ) + ; (define-iso-html "¿" "" "" ) + (define-iso-html "À" "À" "À" ) + (define-iso-html "Á" "Á" "Á" ) + (define-iso-html "Â" "Â" "Â" ) + (define-iso-html "Ã" "Ã" "Ã" ) + (define-iso-html "Ä" "Ä" "Ä" ) + (define-iso-html "Å" "Å" "Å" ) + (define-iso-html "Æ" "Æ" "Æ" ) + (define-iso-html "Ç" "Ç" "Ç" ) + (define-iso-html "È" "È" "È" ) + (define-iso-html "É" "É" "É" ) + (define-iso-html "Ê" "Ê" "Ê" ) + (define-iso-html "Ë" "Ë" "Ë" ) + (define-iso-html "Ì" "Ì" "Ì" ) + (define-iso-html "Í" "Í" "Í" ) + (define-iso-html "Î" "Î" "Î" ) + (define-iso-html "Ï" "Ï" "Ï" ) + (define-iso-html "Ð" "Ð" "Ð" ) + (define-iso-html "Ñ" "Ñ" "Ñ" ) + (define-iso-html "Ò" "Ò" "Ò" ) + (define-iso-html "Ó" "Ó" "Ó" ) + (define-iso-html "Ô" "Ô" "Ô" ) + (define-iso-html "Õ" "Õ" "Õ" ) + (define-iso-html "Ö" "Ö" "Ö" ) +; (define-iso-html "×" "" "" ) + (define-iso-html "Ø" "Ø" "Ø" ) + (define-iso-html "Ù" "Ù" "Ù" ) + (define-iso-html "Ú" "Ú" "Ú" ) + (define-iso-html "Û" "Û" "Û" ) + (define-iso-html "Ü" "Ü" "Ü" ) + (define-iso-html "Ý" "Ý" "Ý" ) + (define-iso-html "Þ" "Þ" "Þ" ) + (define-iso-html "ß" "ß" "ß" ) + (define-iso-html "à" "à" "à" ) + (define-iso-html "á" "á" "á" ) + (define-iso-html "â" "â" "â" ) + (define-iso-html "ã" "ã" "ã" ) + (define-iso-html "ä" "ä" "ä" ) + (define-iso-html "å" "å" "å" ) + (define-iso-html "æ" "æ" "æ" ) + (define-iso-html "ç" "ç" "ç" ) + (define-iso-html "è" "è" "è" ) + (define-iso-html "é" "é" "é" ) + (define-iso-html "ê" "ê" "ê" ) + (define-iso-html "ë" "ë" "ë" ) + (define-iso-html "ì" "ì" "ì" ) + (define-iso-html "í" "í" "í" ) + (define-iso-html "î" "î" "î" ) + (define-iso-html "ï" "ï" "ï" ) + (define-iso-html "ð" "ð" "ð" ) + (define-iso-html "ñ" "ñ" "ñ" ) + (define-iso-html "ò" "ò" "ò" ) + (define-iso-html "ó" "ó" "ó" ) + (define-iso-html "ô" "ô" "ô" ) + (define-iso-html "õ" "õ" "õ" ) + (define-iso-html "ö" "ö" "ö" ) +; (define-iso-html "÷" "" "" ) + (define-iso-html "ø" "ø" "ø" ) + (define-iso-html "ù" "ù" "ù" ) + (define-iso-html "ú" "ú" "ú" ) + (define-iso-html "û" "û" "û" ) + (define-iso-html "ü" "ü" "ü" ) + (define-iso-html "ý" "ý" "ý" ) + (define-iso-html "þ" "þ" "þ" ) + (define-iso-html "ÿ" "ÿ" "ÿ" ) +)) + + +;;;---------------------------------------------------------------------------- +;;; Definition of the minor mode + +(defun iso-html-minor-mode (&optional arg) + "Minor mode to translate HTML sequences into ISO 8859/1 characters while +visiting a file. +Provisions are made to translate them back when writing." + (interactive) + + (if (null iso-html-minor-mode-initialized) + (progn + (setq iso-html-minor-mode-initialized t) + (add-hook 'write-contents-hooks 'iso-html-write) + ;; + (make-local-variable 'after-save-hook) + (add-hook 'after-save-hook 'iso-html-after-write) + ;; There seem to be two versions of this hook around + ;; Horrible to use such undocumented features :-) + (make-local-variable 'after-save-hooks) + (add-hook 'after-save-hooks 'iso-html-after-write) + ;; + (make-local-variable 'iso-html-minor-mode) + ) + ) + (setq iso-html-minor-mode + (if (null arg) (not iso-html-minor-mode) + (> (prefix-numeric-value arg) 0))) + (if iso-html-minor-mode (html-2-iso) (iso-2-html) ) +) + +(defun iso-html-write () + "Function anchored in the local-write-file-hooks. It is not removed but +disabled with the iso-html-minor-mode." + (if iso-html-minor-mode (iso-2-html)) +) + +(defun iso-html-after-write () + "Function anchored in the after-save-hooks. It is not removed but +disabled whith the iso-html-minor-mode." + (if iso-html-minor-mode (html-2-iso)) +) + +(defun iso-2-html () + "Translate ISO-8859/1 extended characters into Html sequences. +The variable iso-2-html-regex is used to preselect a character which is then +translated using the variable iso-2-html-alist. +Use the function define-iso-html instead of setting iso-2-html-alist." + + (let ((buffer-read-only nil) + (state (buffer-modified-p))) + (save-excursion + (goto-char (point-min)) + (while (search-forward-regexp iso-2-html-regex (point-max) t) + (let ((new (assq (string-to-char + (buffer-substring + (- (point) 1) + (point))) + iso-2-html-alist))) + (if new (progn (delete-backward-char 1) + (insert (cdr new)) ) + ) + ) + ) + ) + (set-buffer-modified-p state) + ) + nil +) + +(defun html-2-iso () + "Translate Html sequences into ISO-8859/1 extended characters. +The variable html-2-iso-regex is used to preselect a character which is then +translated using the variable html-2-iso-alist. +Use the function define-iso-html instead of setting html-2-iso-alist." + + (let ((buffer-read-only nil) + (state (buffer-modified-p))) + (save-excursion + (goto-char (point-min)) + (while (search-forward-regexp html-2-iso-regex (point-max) t) + (let ((hit (buffer-substring (match-beginning 0) (match-end 0))) + (b (match-beginning 0)) + (e (match-end 0)) ) + (setq hit (assoc hit html-2-iso-alist)) + (if hit + (progn + (delete-region b e) + (insert (cdr hit)) + ) + ) + ) + ) + ) + (set-buffer-modified-p state) + ) + nil +) + +; ¡¢£¤¥¦§ +; ¨©ª«¬®¯ +; °±²³´µ¶· +; ¸¹º»¼½¾¿ +; ÀÁÂÃÄÅÆÇ +; ÈÉÊËÌÍÎÏ +; ÐÑÒÓÔÕÖ× +; ØÙÚÛÜÝÞß +; àáâãäåæç +; èéêëìíîï +; ðñòóôõö÷ +; øùúûüýþÿ diff --git a/support/iso-tex/iso-tex.el b/support/iso-tex/iso-tex.el new file mode 100644 index 0000000000..1ee4d54d99 --- /dev/null +++ b/support/iso-tex/iso-tex.el @@ -0,0 +1,496 @@ +;;; iso-tex.el --- Translating TeX to ISO-8859/1 while editing a file +;;***************************************************************************** +;; $Id: iso-tex.el,v 1.21 1997/05/15 08:15:12 gerd Exp gerd $ +;;***************************************************************************** +;; +;; Description: +;; When using (La)TeX it is highly desirable to display national +;; characters contained in the ISO-8859/1 character set. Editing +;; files with ISO-8859/1 characters is enabled in GNU Emacs since +;; version 19. +;; +;; Two ways can be envisaged. The first one is to teach TeX the +;; meaning of the extended character set (e.g. via a sty file in +;; LaTeX). This solution has the disadvantage that it may collide +;; with other extended character sets. +;; +;; The second solution is used in iso-tex.el. The extended +;; character set is used only temporarily during editing of a +;; file in Emacs. The file processed by TeX contains pure ASCII +;; representations of the extended characters (if possible). +;; +;; iso-tex.el provides a minor mode which anchors itself in +;; various hooks to perform translations when reading or writing +;; files. +;; +;; No provisions are made to insert ISO-8859/1 characters since +;; other packages are availlable for this purpose. +;; +;; +;; Installation: +;; 1. Ensure that iso-tex.el is on the load-path. +;; 2. For efficiency it might be desirable to byte-compile +;; iso-tex.el. +;; 3. Put the following in your .emacs file or a similar place +;; where it is loaded when needed. +;; +;; (autoload 'iso-tex-minor-mode +;; "iso-tex" +;; "Translate TeX to ISO 8859/1 while visiting a file." +;; t) +;; +;; 4. Enable the iso-tex minor mode for the appropriate +;; files. This depends on the major mode you use for editing +;; (La)TeX files. For this purpose you can use the entry hook +;; of this mode. E.g. +;; +;; (setq TeX-mode-hook +;; (function (lambda () (interactive) +;; (iso-tex-minor-mode 1) +;; ; and other initializations +;; ; ... +;; ))) +;; +;; Alternatively tex-mode-hook, latex-mode-hook, or LaTeX-mode-hook +;; might be places to perform the initialization. +;; +;; For users of german.sty: +;; +;; Instead of the autoload command mentioned under point 3. use the +;; following initializations. They cause the german.sty umlaut +;; variants to be inserted. +;; +;; (load "iso-tex") +;; (define-iso-tex "Ä" "\"A" "\"A" ) ; german.sty +;; (define-iso-tex "Ë" "\"E" "\"E" ) ; german.sty +;; (define-iso-tex "Ï" "\"I" "\"I" ) ; german.sty +;; (define-iso-tex "Ö" "\"O" "\"O" ) ; german.sty +;; (define-iso-tex "Ü" "\"U" "\"U" ) ; german.sty +;; (define-iso-tex "ß" "\"s" "\\ss" "\\3" ) ; german.sty +;; (define-iso-tex "ä" "\"a" "\"a" ) ; german.sty +;; (define-iso-tex "ë" "\"e" "\\\"e" ) ; german.sty +;; (define-iso-tex "ï" "\"i" "\\\"\\i") ; german.sty +;; (define-iso-tex "ö" "\"o" "\\\"o" ) ; german.sty +;; (define-iso-tex "ü" "\"u" "\\\"u" ) ; german.sty +;; +;; +;; The same trick can be used to redefine any string +;; representation of the ISO characters. E.g. +;; +;; (define-iso-tex "µ" "\\MYmu " "\\MYmu" ) +;; +;; inserts the string "\MYmu" for µ. \MYmu can now be defined to +;; produce a µ in any environment. E.g. in LaTeX by +;; +;; \newcommand\MYmu{\mbox{\(\mu\)}} +;; +;; +;; Bugs and Problems: +;; - Some of the TeX sequences which are inserted by iso-tex are +;; not defined in plain (La)TeX. Don't use them or provide defs. +;; +;; - Some of the TeX sequences which are inserted by iso-tex are +;; only defined inside/outside math environments. Be careful! +;; +;; - There might be problems when saving a narrowed buffer. +;; - Point might not be restored properly. +;; +;; - There are quite a few ways to code accented characters in +;; TeX. Only some are captured in this program. +;; +;; - Writing of a region is not supported. There seems to be no +;; appropriate hook. +;; +;; +;; To do: +;; - iso-tex can be used for a wider range of translations when +;; reading and writing. Maybe it's worth extracting those +;; routines which are more general and make iso-tex a sample +;; instance of the general routines. +;; +;; +;; Changes: +;; - undefine-iso-tex function added to undo the effects of +;; define-iso-tex. +;; - allowing non-braced expansion. This is the new default. +;; set the variable iso-tex-extra-braces to t to get the old +;; behaviour. +;; If you are still running Emacs 18.* you might have to make +;; buffer-substring-no-properties an alias to buffer-substring. +;; +;; - using the macros from the textcomp package for the formerly +;; undefined characters. +;; - Understand more variants of combinations with \i. +;; +;; - solitary diaresis is now translated into a macro instead of pure +;; TeX code which may cause trouble. +;; +;; - enhanced patterns for recognition of accented characters in TeX +;; - german.sty (partially) supported +;; - minor bugs fixed to generate accented i. +;; +;; - after-save-hooks seems to be after-save-hook now. +;; +;; - german.sty support partially removed because it interfered e.g. +;; with BibTeX strings. +;; +;; - after-save-hooks and after-save-hook are both set. +;; +;; - Default TeX sequences changed to conform to BibTeX coding standart. +;; +;; +;; Author: +;; Gerd Neugebauer +;; Mainzer Str. 8 +;; 56321 Rhens (Germany) +;; +;; Net: gerd@informatik.uni-koblenz.de +;; gerd@imn.th-leipzig.de (old) +;; gerd@intellektik.informatik.th-darmstadt.de (ancient) +;; +;;***************************************************************************** +;; LCD Archive Entry: +;; iso-tex|Gerd Neugebauer|gerd@informatik.uni-koblenz.de| +;; Translating TeX to ISO-8859/1 while editing a file.| +;; $Date: 1997/05/15 08:15:12 $|$Revision: 1.21 $|| +;;***************************************************************************** +;; +;; Copyright (C) 1994-1996 Gerd Neugebauer +;; +;; iso-tex.el is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY. No author or distributor +;; accepts responsibility to anyone for the consequences of using it +;; or for whether it serves any particular purpose or works at all, +;; unless he says so in writing. Refer to the GNU General Public +;; License for full details. +;; +;; Everyone is granted permission to copy, modify and redistribute +;; iso-tex.el, but only under the conditions described in the +;; GNU General Public License. A copy of this license is +;; supposed to have been given to you along with GNU Emacs so you +;; can know your rights and responsibilities. It should be in a +;; file named COPYING. Among other things, the copyright notice +;; and this notice must be preserved on all copies. +;; + +;;;---------------------------------------------------------------------------- +;;; Variable definitions and initializations + +(defvar iso-tex-minor-mode nil + "Variable indicating when iso-tex-minor-mode is active.") + +(or (assq 'iso-tex-minor-mode minor-mode-alist) + (setq minor-mode-alist (cons '(iso-tex-minor-mode " ISO-TeX") + minor-mode-alist))) + +(defvar iso-tex-minor-mode-initialized nil + "Variable indicating if iso-tex-minor-mode is already initialized in this +buffer. This variable is buffer local.") + +(make-variable-buffer-local 'iso-tex-minor-mode-initialized) + +(defvar tex-2-iso-regex + (concat + "\\\\\\([\"'`^~]\\([a-zA-Z]\\({}\\)?\\|\\\\i[ \t]*\\|{\\\\i}\\|{}\\)" + "\\|c{[a-zA-Z]?}" + "\\|[a-zA-Z]+[ \t]*\\({}\\)?" + "\\)" + "\\|{\\(\\\\\\([\"'`^~]\\([a-zA-Z]\\|\\\\i\\|{\\\\i}\\)?\\({}\\)?" + "\\|c{[a-zA-Z]?}" + "\\|[a-zA-Z]+" + "\\)" + "\\|[!?]`" + "\\)}" + "\\|\"[a-zA-Z]" ; for german.sty + "\\|[!?]`" + ) + "Regular expression to pre-select substrings to be translated by tex-2-iso.") +(defvar iso-2-tex-regex "[€-ÿ]" + "Regular expression to pre-select substrings to be translated by iso-2-tex.") +(defvar iso-2-tex-alist nil + "Alist of CHAR.STRING pairs used by iso-2-tex.") +(defvar tex-2-iso-alist nil + "Alist of STRING.ISO-CHAR pairs used by tex-2-iso.") + +(defun define-iso-tex (char &optional string &rest names) + "Define a translation between ISO-8859/1 characters and TeX sequences. +CHAR is the ISO-8859/1 character code as a single letter string. +If STRING is non nil then it is used as representation of CHAR. +The optional remaining arguments are used to translate TeX sequences to +characters." + (if string (setq iso-2-tex-alist (cons + (cons (string-to-char char) string) + iso-2-tex-alist))) + (setq names (cons string names)) + (while names + (setq tex-2-iso-alist (cons (cons (car names) char) + tex-2-iso-alist)) + (setq names (cdr names)) + ) +) + +(defun undefine-iso-tex (char &optional string &rest names) + "Remove definitions from the translation tables. This reverses the effect of +define-iso-tex. + +CHAR is the ISO-8859/1 character code as a single letter string. +If STRING is non nil then it is used as representation of CHAR. +The optional remaining arguments are used to translate TeX sequences to +characters. + +If CHAR is NIL then only the translation from TeX to iso is disabled. +" + (let (al) + (and char + (setq al (assoc (string-to-char char) iso-2-tex-alist)) + (rplaca al nil)) + (setq names (cons string names)) + (while names + (and (setq al (assoc (car names) tex-2-iso-alist)) + (rplaca al nil)) + (setq names (cdr names)) + ) + ) +) + +(if (null iso-2-tex-alist) + (progn + (define-iso-tex "¡" "!`" ) + (define-iso-tex "¢" "\\textcent" ) ; from tc + (define-iso-tex "£" "\\pounds" ) + (define-iso-tex "¤" "\\textcurrency" ) ; from tc + (define-iso-tex "¥" "\\textyen" ) ; from tc + (define-iso-tex "¦" "\\textbrokenbar" ) ; from tc + (define-iso-tex "§" "\\S" ) + (define-iso-tex "¨" "\\texthighdiaeresis" ) ; from tc + (define-iso-tex "©" "\\copyright" ) + (define-iso-tex "ª" "\\textordfemenine" ) ; from tc + (define-iso-tex "«" "\\ll" ) ; math mode only + (define-iso-tex "¬" "\\neg" ) ; math mode only + (define-iso-tex "" "\\-" ) ; It's too hard to distinguish from - + (define-iso-tex "®" "\\textregistered" ) ; from tc + (define-iso-tex "¯" "\\textmacron" ) ; from tc + (define-iso-tex "°" "\\textdegree" ) ; from tc + (define-iso-tex "±" "\\pm" ) ; math mode only + (define-iso-tex "²" "\\texttwosuperior" ) ; from tc + (define-iso-tex "³" "\\textthreesuperior" ) ; from tc + (define-iso-tex "´" "\\'{}" "\\'" ) + (define-iso-tex "µ" "\\mu" ) ; math mode only + (define-iso-tex "¶" "\\P" ) + (define-iso-tex "·" "\\cdot" ) + (define-iso-tex "¸" "\\c{}" "\\c" ) + (define-iso-tex "¹" "\\textonesuperior" ) ; from tc + (define-iso-tex "º" "\\textordmasculine" ) ; usually undefined + (define-iso-tex "»" "\\gg" ) ; math mode only + (define-iso-tex "¼" "\\textonequater" ) ; from tc + (define-iso-tex "½" "\\textonehalf" ) ; from tc + (define-iso-tex "¾" "\\textthreequaters" ) ; from tc + (define-iso-tex "¿" "?`" ) + (define-iso-tex "À" "\\`A" ) + (define-iso-tex "Á" "\\'A" ) + (define-iso-tex "Â" "\\^A" ) + (define-iso-tex "Ã" "\\~A" ) + (define-iso-tex "Ä" "\\\"A" ) ; "\"A" german.sty + (define-iso-tex "Å" "\\AA" ) + (define-iso-tex "Æ" "\\AE" ) + (define-iso-tex "Ç" "\\c{C}" ) + (define-iso-tex "È" "\\`E" ) + (define-iso-tex "É" "\\'E" ) + (define-iso-tex "Ê" "\\^E" ) + (define-iso-tex "Ë" "\\\"E" ) ; "\"E" german.sty + (define-iso-tex "Ì" "\\`I" ) + (define-iso-tex "Í" "\\'I" ) + (define-iso-tex "Î" "\\^I" ) + (define-iso-tex "Ï" "\\\"I" ) ; "\"I" german.sty + (define-iso-tex "Ð" "\\Dstroke" ) ; usually undefined + (define-iso-tex "Ñ" "\\~N" ) + (define-iso-tex "Ò" "\\`O" ) + (define-iso-tex "Ó" "\\'O" ) + (define-iso-tex "Ô" "\\^O" ) + (define-iso-tex "Õ" "\\~O" ) + (define-iso-tex "Ö" "\\\"O" ) ; "\"O" german.sty + (define-iso-tex "×" "\\times" ) + (define-iso-tex "Ø" "\\O" ) + (define-iso-tex "Ù" "\\`U" ) + (define-iso-tex "Ú" "\\'U" ) + (define-iso-tex "Û" "\\^U" ) + (define-iso-tex "Ü" "\\\"U" ) ; "\"U" german.sty + (define-iso-tex "Ý" "\\'Y" ) + (define-iso-tex "Þ" "\\Thorn" ) ; usually undefined + (define-iso-tex "ß" "\\ss" "\\3" ) ; "\"s" german.sty + (define-iso-tex "à" "\\`a" ) + (define-iso-tex "á" "\\'a" ) + (define-iso-tex "â" "\\^a" ) + (define-iso-tex "ã" "\\~a" ) + (define-iso-tex "ä" "\\\"a" ) ; "\"a" german.sty + (define-iso-tex "å" "\\aa" ) + (define-iso-tex "æ" "\\ae" ) + (define-iso-tex "ç" "\\c{c}" ) + (define-iso-tex "è" "\\`e" ) + (define-iso-tex "é" "\\'e" ) + (define-iso-tex "ê" "\\^e" ) + (define-iso-tex "ë" "\\\"e" ) ; "\"e" german.sty + (define-iso-tex "ì" "\\`{\\i}" "\\`\\i" ) + (define-iso-tex "í" "\\'{\\i}" "\\'\\i" ) + (define-iso-tex "î" "\\^{\\i}" "\\^\\i" ) + (define-iso-tex "ï" "\\\"{\\i}" "\\\"\\i" ); "\"i" german.sty + (define-iso-tex "ð" "\\dstroke" ) ; usually undefined + (define-iso-tex "ñ" "\\~n" ) + (define-iso-tex "ò" "\\`o" ) + (define-iso-tex "ó" "\\'o" ) + (define-iso-tex "ô" "\\^o" ) + (define-iso-tex "õ" "\\~o" ) + (define-iso-tex "ö" "\\\"o" ) ; "\"o" german.sty + (define-iso-tex "÷" "\\div" ) + (define-iso-tex "ø" "\\o" ) + (define-iso-tex "ù" "\\`u" ) + (define-iso-tex "ú" "\\'u" ) + (define-iso-tex "û" "\\^u" ) + (define-iso-tex "ü" "\\\"u" ) ; "\"u" german.sty + (define-iso-tex "ý" "\\'y" ) + (define-iso-tex "þ" "\\thorn" ) ; usually undefined + (define-iso-tex "ÿ" "\\\"y" ) +)) + + +;;;---------------------------------------------------------------------------- +;;; Definition of the minor mode + +(defun iso-tex-minor-mode (&optional arg) + "Minor mode to translate TeX sequences into ISO 8859/1 characters while +visiting a file. +Provisions are made to translate them back when writing." + (interactive) + + (if (null iso-tex-minor-mode-initialized) + (progn + (setq iso-tex-minor-mode-initialized t) + (add-hook 'write-contents-hooks 'iso-tex-write) + ;; + (make-local-variable 'after-save-hook) + (add-hook 'after-save-hook 'iso-tex-after-write) + ;; There seem to be two versions of this hook around + ;; Horrible to use such undocumented features :-) + (make-local-variable 'after-save-hooks) + (add-hook 'after-save-hooks 'iso-tex-after-write) + ;; + (make-local-variable 'iso-tex-minor-mode) + ) + ) + (setq iso-tex-minor-mode + (if (null arg) (not iso-tex-minor-mode) + (> (prefix-numeric-value arg) 0))) + (if iso-tex-minor-mode (tex-2-iso) (iso-2-tex) ) +) + +(defun iso-tex-write () + "Function anchored in the local-write-file-hooks. It is not removed but +disabled with the iso-tex-minor-mode." + (if iso-tex-minor-mode (iso-2-tex)) +) + +(defun iso-tex-after-write () + "Function anchored in the after-save-hooks. It is not removed but +disabled with the iso-tex-minor-mode." + (if iso-tex-minor-mode (tex-2-iso)) +) + +(defvar iso-tex-extra-braces nil + "This variable indicates wether extra braces are needed around the strings +which are inserted by iso-2-tex. This variable is local in any buffer.") +(make-variable-buffer-local 'iso-tex-extra-braces) + + +(defun iso-2-tex () + "Translate ISO-8859/1 extended characters into TeX sequences. +The variable iso-2-tex-regex is used to preselect a character which is then +translated using the variable iso-2-tex-alist. +Use the function define-iso-tex instead of setting iso-2-tex-alist." + + (let ((buffer-read-only nil) + (state (buffer-modified-p))) + (save-excursion + (goto-char (point-min)) + (while (search-forward-regexp iso-2-tex-regex (point-max) t) + (let ((new (assq (string-to-char + (buffer-substring + (- (point) 1) + (point))) + iso-2-tex-alist))) + (if new + (progn (delete-backward-char 1) + (cond + (iso-tex-extra-braces (insert "{" (cdr new) "}")) + ((string-match "\\\\[a-zA-Z]+$" (cdr new)) + (insert (cdr new) "{}")) + (t (insert (cdr new)) ))) + ) + ) + ) + ) + (set-buffer-modified-p state) + ) + nil +) + +(defun tex-2-iso () + "Translate TeX sequences into ISO-8859/1 extended characters. +The variable tex-2-iso-regex is used to preselect a character which is then +translated using the variable tex-2-iso-alist. +Use the function define-iso-tex instead of setting tex-2-iso-alist." + + (let ((buffer-read-only nil) + (state (buffer-modified-p))) + (save-excursion + (goto-char (point-min)) + (while (search-forward-regexp tex-2-iso-regex (point-max) t) + (let ((hit (buffer-substring-no-properties (match-beginning 0) (match-end 0))) + (b (match-beginning 0)) + (e (match-end 0)) ) + ; Apply some simplifications + ; to reduce the numer of + ; entries in the alist + (cond + ( (string-match "^\\(\\\\['`^\"]\\({\\\\i}\\|\\\\i\\)\\({}\\|[ \t]+\\)\\)$" hit ) + (setq hit (substring hit (match-beginning 1) (match-end 1))) + ) + ( (string-match "^\\(\\\\[a-zA-Z0-9'`^\"]*\\)\\({}\\|[ \t]+\\)$" hit) + (setq hit (substring hit (match-beginning 1) (match-end 1))) + ) + ( (string-match "^{\\(.*\\)}$" hit ) + (setq hit (substring hit (match-beginning 1) (match-end 1))) + ) + ( (string-match "^\\(\\\\['`^\"]\\){\\(.\\)}$" hit ) + (setq hit (concat + (substring hit (match-beginning 1) (match-end 1)) + (substring hit (match-beginning 2) (match-end 2)))) + ) + ) + (setq hit (assoc hit tex-2-iso-alist)) + (if hit + (progn + (delete-region b e) + (insert (cdr hit)) + ) + ) + ) + ) + ) + (set-buffer-modified-p state) + ) + nil +) + + +; ¡¢£¤¥¦§ +; ¨©ª«¬®¯ +; °±²³´µ¶· +; ¸¹º»¼½¾¿ +; ÀÁÂÃÄÅÆÇ +; ÈÉÊËÌÍÎÏ +; ÐÑÒÓÔÕÖ× +; ØÙÚÛÜÝÞß +; àáâãäåæç +; èéêëìíîï +; ðñòóôõö÷ +; øùúûüýþÿ diff --git a/support/iso-tex/multi-mode.el b/support/iso-tex/multi-mode.el new file mode 100644 index 0000000000..48c9746178 --- /dev/null +++ b/support/iso-tex/multi-mode.el @@ -0,0 +1,288 @@ +;;; multi-mode.el --- Allowing multiple major modes in a buffer. +;;;**************************************************************************** +;;; $Id: multi-mode.el,v 1.2 1994/06/11 22:08:22 gerd Exp gerd $ +;;;**************************************************************************** +;; +;; +;; Description: +;; +;; Sometimes it is desirable to have different major modes in one +;; buffer. One such case occurs when editing comments in a +;; programming language buffer. Here it might be desirable to use a +;; totally different mode than the one used for editing the program +;; code itself. +;; +;; I have adoped this practice for editing Prolog. The code itself is +;; edited in prolog-mode, whereas the comments are edited in +;; LaTeX-mode. +;; +;; It is desirable to use different modes instead of enhancing one +;; mode because much efford has already been put in various modes +;; which needs not to be duplicated. +;; +;; The multi-mode minor mode provides a means to accomplish such a +;; feature. +;; +;; The modes are described by initializing strings. I assume that +;; certain tokens (i.e. transition strings) indicate the places where +;; a new mode should be entered. To determine the mode at a point it +;; is only neccessary to find the last transition string before point. +;; +;; The desired modes are described in a list of pairs or triples +;; consisting of a transition string and a mode (a symbol). +;; Optionally a function symbol can be specified which is evaluated to +;; activate the desired mode. Additionally the mode in absence of +;; preceding transition strings has to be specified. +;; +;; +;; +;; +;; Installation: +;; 1. Ensure that multi-mode.el is on the load-path. +;; 2. For efficiency it might be desirable to byte-compile +;; multi-mode.el. +;; 3. Put the following in your .emacs file or a similar place +;; where it is loaded when needed. +;; +;; (autoload 'multi-mode +;; "multi-mode" +;; "Allowing multiple major modes in a buffer." +;; t) +;; +;; 4. Define your own incarnation of multi mode to serve as major +;; mode. This can be done in your .emacs file. E.g. +;; +;; (defun multi-c-fundamental-mode () (interactive) +;; (multi-mode 1 +;; 'c-mode +;; '(\"/*\" fundamental-mode my-fundamental-setup) +;; '(\"*/\" c-mode))) +;; +;; This major mode can now be used to turn on the multi-mode in the +;; minibuffer, or in the auto-mode-alist, or in the local variables +;; of a file. E.g. +;; +;; (setq auto-mode-alist +;; (cons '("\\.[ch]$" . multi-c-fundamental-mode) +;; auto-mode-alist) +;; +;; +;; Bugs and Problems: +;; - It is rather easy to hang my whole workstation when +;; multi-mode-transitions has not a proper value. +;; For sake of efficiency I omit finer type checking to avoid this +;; problem. +;; CURE: Never try to change the variable yourself. Use the +;; function multi-mode instead. +;; +;; To do: +;; - The generalization of transition strings to regular expressions +;; seems to be straight forward. For efficience reasons I will do it +;; only upon request. +;; +;; - No provisions have been made to make the key bindings accessible +;; in all modes. This might be desirable. +;; +;; +;; Changes: +;; $Log: multi-mode.el,v $ +; Revision 1.2 1994/06/11 22:08:22 gerd +; *** empty log message *** +; +; Revision 1.1 1994/05/24 12:41:30 gerd +; A little hack has been enhanced to a minor mode. +;; +;; +;; Author: +;; Gerd Neugebauer +;; Ödenburger Str. 16 +;; 64295 Darmstadt (Germany) +;; +;; Net: gerd@intellektik.informatik.th-darmstadt.de +;; gerd@imn.th-leipzig.de +;; +;;***************************************************************************** +;; LCD Archive Entry: +;; multi-mode|Gerd Neugebauer|gerd@intellektik.informatik.th-darmstadt.de| +;; Minor mode allowing multiple major modes in a single buffer.| +;; $Date: 1994/06/11 22:08:22 $|$Revision: 1.2 $|| +;;***************************************************************************** +;; +;; Copyright (C) 1994 Gerd Neugebauer +;; +;; multi-mode.el is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY. No author or distributor +;; accepts responsibility to anyone for the consequences of using it +;; or for whether it serves any particular purpose or works at all, +;; unless he says so in writing. Refer to the GNU General Public +;; License for full details. +;; +;; Everyone is granted permission to copy, modify and redistribute +;; multi-mode.el, but only under the conditions described in the +;; GNU General Public License. A copy of this license is +;; supposed to have been given to you along with GNU Emacs so you +;; can know your rights and responsibilities. It should be in a +;; file named COPYING. Among other things, the copyright notice +;; and this notice must be preserved on all copies. +;; + +;;;---------------------------------------------------------------------------- +;;; Variable definitions and initializations + +(make-variable-buffer-local 'multi-mode-transitions) +(defvar multi-mode-transitions nil + "Transition definition for the multi-mode minor mode. +") + +(defvar multi-mode-beware '( (not isearch-mode) ) + "List of forms to check if multi-mode is desirable. If all forms evaluate to +t then a mode switch is allowed.") + +(make-variable-buffer-local 'multi-mode) +(defvar multi-mode nil + "This variable indicates if the multi-mode minor mode is active.") + + +;;;---------------------------------------------------------------------------- +;;; Definition of the minor mode + +(defun multi-mode (&optional arg &optional initial-mode &rest transitions) + "Allowing multiple major modes in a buffer. + +Toggle multi mode. With numeric argument turn on multi mode if the argument +is positive. + +Sometimes it is desirable to have different major modes in one buffer. One +such case occurs when editing comments in a programming language buffer. +Here it might be desirable to use a totally different mode than the one +used for editing the program code itself. + +It is desirable to use different modes instead of enhancing one mode +because much effort has already been put in various modes which needs not +to be duplicated. + +The multi-mode minor mode provides a means to accomplish such a feature. + +The modes are described by initializing strings. I assume that certain +tokens (i.e. transition strings) indicate the places where a new mode +should be entered. To determine the mode at a point it is only necessary +to find the last transition string before point. + +The desired modes are described in a list of pairs or triples consisting of +a transition string and a mode (a symbol). Optionally a function symbol +can be specified which is evaluated to activate the desired mode. +Additionally the mode in absence of preceding transition strings has to be +specified. + +When called not interactively there are additional arguments to specify the +transitions. + +INITIAL-MODE is a symbol denoting a major mode to be used before any +transition strings are present before point. + +The remaining optional arguments are pairs + (TOKEN MODE) +or triples + (TOKEN MODE FUNCTION) + +The first element TOKEN is a string which indicates the token to activate +the mode MODE specified in the second argument. Optionally a third argument +can be given. The symbol FUNCTION is used as a function to be called to +turn on the mode given as second argument. It defaults to MODE. + +Consider the following example: + +(multi-mode 1 + c-mode + (\"/*\" fundamental-mode my-fundamental-setup) + (\"*/\" c-mode)) + +The first argument forces multi-mode to be turned on. The second argument +declares the default mode to be c-mode. Thus at the beginning of the buffer +c-mode is turned on. If a '/*' is found before point then fundamental-mode +may be turned on. This is done using the function my-fundamental-setup. + +If a '*/' is found before point then c-mode may be activated. Which mode is +used depends on the last activating pattern before point. In this example +everything between /* and */ can be edited in fundamental mode. Everything +else is in c-mode. + +See also the documentation of multi-mode-beware." + (interactive "P") + (setq multi-mode ; + (if (null arg) (not multi-mode) ; Toggle multi-mode if no arg + (> (prefix-numeric-value arg) 0))) ; otherwise turn it on or off + (let ((ok t) ; result of type check + (tt transitions) ; transition table + trans) ; transition + (while tt ; Check the transition table + (setq trans (car tt) ; Get a single transition + tt (cdr tt)) ; Advance the table pointer + (if (or (not (listp trans)) ; Check the transition + (not (stringp (first trans))) ; + (not (symbolp (second trans)))) ; + (setq ok nil ; set error mark + tt nil)) ; stop checking + ) + (if (and ok ; if transition table is ok + initial-mode ; check the initial-mode + (symbolp initial-mode)) ; + (setq multi-mode-transitions ; set the local variable + (cons initial-mode transitions))) ; + ) + + (force-mode-line-update) ; show the new state +) + +(or (assq 'multi-mode minor-mode-alist) + (setq minor-mode-alist (cons '(multi-mode " MULTI") minor-mode-alist))) + + +(defun multi-mode-update-mode () + "Perform a mode switch if multi-mode is active." + ;; This function only starts to work if multi mode is on + ;; and a transition table is defined. Additionally the forms in + ;; multi-mode-beware are evaluated to see if a mode switch is desirable. + (if (and multi-mode + multi-mode-transitions + (eval (cons 'and multi-mode-beware)) + ) + (let* ((transition (cdr multi-mode-transitions)) ; get transitions + (mode (car multi-mode-transitions)) ; get initial mode + (mode-function mode) ; set initial mode switching function + (pos -1) ; set the initial position of a transit + hit ; new position of a transition string + tt) ; transition table + (while transition + (setq tt (car transition) ; extract a single transition + transition (cdr transition)) ; advance the transitions + (setq hit (save-excursion ; we don't want to change point + (if (search-backward ; unfailing backward search + (first tt) ; for the transition pattern + nil + t) + (point) ; upon sucess use the position + -2))) ; otherwise try to ignore it + (if (> hit pos) ; pattern is newer than prev. + (setq pos hit ; then save position + mode (second tt) ; the desired mode and an + mode-function (or (third tt) mode)); optional function + ) + ) + (if (not (equal major-mode mode)) ; if mode needs switching + (let ((transitions multi-mode-transitions)) ; save transition table + (if (fboundp mode-function) ; if mode function is defined + (funcall mode-function)) ; then call it + (setq multi-mode-transitions transitions ; restore transition + multi-mode t))) ; and minor mode + ) + ) +) + +;;;---------------------------------------------------------------------------- +;;; The function is hooked into the post-command-hook to be called after +;;; each function. +;;; +(add-hook 'post-command-hook 'multi-mode-update-mode) + +(provide 'multi-mode) diff --git a/support/iso-tex/prolog-indent.el b/support/iso-tex/prolog-indent.el new file mode 100644 index 0000000000..5e336068a6 --- /dev/null +++ b/support/iso-tex/prolog-indent.el @@ -0,0 +1,371 @@ +;;; prolog-indent.el --- Indentation of Prolog code. +;;;**************************************************************************** +;;; $Id: prolog-indent.el,v 0.00 1995/02/24 15:28:23 gerd Exp $ +;;;**************************************************************************** +;;; +;;; Description: +;;; +;;; This file implements additional routines to the prolog mode +;;; supplied with Emacs. The indentation is improved and some +;;; electric keys are activated. +;;; +;;; Installation: +;;; Put the following lines in your .emacs file: +;;; +;;; (require 'prolog-indent) +;;; +;;; This assumes that the file prolog-indent.el can be found on +;;; the load-path: +;;; +;;; (require 'cl) +;;; (setq load-path (adjoin "PROLOG-INDENT-DIRECTORY" load-path)) +;;; +;;; Bugs and Problems: +;;; Comments inside Prolog goals are not supported. +;;; Things might get mixed up for infix operators. +;;; +;;; To do: +;;; +;;; Changes: +;;; +;;; Author: +;;; Gerd Neugebauer +;;; Mainzer Str. 16 +;;; 56321 Rhens (Germany) +;;; Net: gerd@uni-koblenz.de +;;; +;;;**************************************************************************** +;;; LCD Archive Entry: +;;; Not yet. +;;;**************************************************************************** +;;; +;;; Copyright (C) 1995,1996 Gerd Neugebauer +;;; +;;; prolog-indent.el is distributed in the hope that it will be useful, +;;; but WITHOUT ANY WARRANTY. No author or distributor +;;; accepts responsibility to anyone for the consequences of using it +;;; or for whether it serves any particular purpose or works at all, +;;; unless he says so in writing. Refer to the GNU General Public +;;; License for full details. +;;; +;;; Everyone is granted permission to copy, modify and redistribute +;;; prolog-indent.el, but only under the conditions described in the +;;; GNU General Public License. A copy of this license is +;;; supposed to have been given to you along with GNU Emacs so you +;;; can know your rights and responsibilities. It should be in a +;;; file named COPYING. Among other things, the copyright notice +;;; and this notice must be preserved on all copies. +;;; + +;;;---------------------------------------------------------------------------- +;;; Load prolog.el if not already loaded. +(eval-when-compile (load-library "prolog")) +(if (null prolog-mode-map) (load-library "prolog")) + + +(defvar Prolog-prefix-op-regex "\\\\\\+" + "Regular expression of a Prolog prefix operator of length 2.") +(defvar Prolog-infix1-op-regex "[^:/=]=\\|.[*+]\\|[^*]/\\|[^:]-\\|.^" + "Regular expression of a Prolog infix operator") +(defvar Prolog-infix2-op-regex "\\(==\\|=<\\|>=\\|<<\\|>>\\|is\\)" + "Regular expression of a Prolog infix operator of length 2.") +(defvar Prolog-infix3-op-regex "=[:\\\\]=\\|=\\.\\.\\|\\\\==" + "Regular expression of a Prolog infix operator of length 3.") +(defvar Prolog-ascii-escape-regex "0'." + "Regular expression of a Prolog ASCII characters (length 3).") + +;;;---------------------------------------------------------------------------- +(defun backward-Prolog-goal (&optional fwd) + "Move point backward to the beginning of a Prolog goal. +This includes compound terms constructed with infix operators of low priority. +Some of those operators are built into this routine: + ++ - * / +\\+ +== =< >= << >> is +=.. =:= =\\\\== \\\\=== + +Comments inside a Prolog goal are not considered! +" + (if fwd (forward-char fwd)) + (Prolog-backward-to-noncomment (point-min)) + (forward-char -1) + (if (looking-at "!") ; the cut is a goal even if it is no sexp + nil + (forward-char 1) + (backward-sexp 1)) + (let ((beg (point))) + (Prolog-backward-to-noncomment (point-min)) + (or (bobp) (forward-char -1)) + (or (bobp) (forward-char -1)) + (cond + ((looking-at Prolog-prefix-op-regex) ) + ((looking-at Prolog-infix2-op-regex) + (backward-Prolog-goal)) + ((looking-at Prolog-infix1-op-regex) + (backward-Prolog-goal 1)) + ((looking-at Prolog-ascii-escape-regex) + (backward-Prolog-goal)) + ( (progn (or (bobp) (forward-char -1)) + (looking-at Prolog-infix3-op-regex)) + (backward-Prolog-goal)) + ( t (goto-char beg)))) + (or (bobp) + (progn + (forward-char -1) + (cond ((looking-at "[a-z_A-Z0-9'](") + (backward-Prolog-goal 1)) + ( t (forward-char 1)))))) + +;;;---------------------------------------------------------------------------- +(defun Prolog-indent (&optional lines) + "Indent current line as Prolog code. +With argument, indent any additional lines along with this one." + (interactive "p") + (if (numberp lines) + (let ((fwd (if (> lines 0) 1 -1))) + (if (< lines 0) (setq lines (- 0 lines))) + (while (> lines 1) + (setq lines (- lines 1)) + (Prolog-indent-line) + (forward-line fwd)))) + (Prolog-indent-line) +) + +;;;---------------------------------------------------------------------------- +(defun Prolog-indent-buffer () + "Indent the whole buffer as Prolog code." + (interactive) + (save-excursion + (goto-char (point-min)) + (end-of-line) + (while (not (eobp)) + (Prolog-indent-line) + (forward-line 1) + (end-of-line) + ))) + +;;;---------------------------------------------------------------------------- +(defun Prolog-in-comment-p () + "Check whether point is inside a C-style comment." + (let ((beg (if (bobp) + (point) + (save-excursion + (beginning-of-line) + (search-backward "/*" (point-min) 'move) + (point)))) + (pos (if (bobp) + (point-max) + (save-excursion + (beginning-of-line) + (search-backward "*/" (point-min) 'move) + (point))))) + (< pos beg))) + +;;;---------------------------------------------------------------------------- +(defun Prolog-indent-line () + "Indent current line as Prolog code." + (let (indent pos beg) + (if (Prolog-in-comment-p) + nil + (setq indent (Prolog-indentation-level) + pos (- (point-max) (point))) + (beginning-of-line) + (setq beg (point)) + (skip-chars-forward " \t") + (if (zerop (- indent (current-column))) + nil + (delete-region beg (point)) + (indent-to indent)) + (if (> (- (point-max) pos) (point)) + (goto-char (- (point-max) pos))) + ))) + +(defvar Prolog-colon-minus-indent tab-width + "Indentation of :- if at the beginning of a line.") + +(defvar Prolog-body-indent tab-width + "Indentation of the body after :- or --> at the end of a line.") + +(defvar Prolog-then-indent 2 + "Indentation of literals after ->") + +;;;---------------------------------------------------------------------------- +(defun Prolog-indentation-level () + "Compute the Prolog indentation level." + (save-excursion + (beginning-of-line) + (skip-chars-forward " \t") + (cond + ((looking-at "%[^%]") comment-column) ;Small comment starts + ((looking-at "%%%") 0) ;Large comment starts + ((looking-at "/\\*") 0) + ((looking-at "?-") 0) + ((looking-at "\\([)}]\\|]\\)") ;Closing parenthesis + (forward-char 1) ; is aligned at opening + (backward-sexp) + (current-column)) + ((looking-at ";") + (Prolog-backward-to-noncomment (point-min)) + (backward-Prolog-goal) + (max (- (current-column) prolog-indent-width) 0) + ) + ((looking-at ":-\\|-->") + (Prolog-backward-to-noncomment (point-min)) + (cond + ((or (bobp) + (= (preceding-char) ?.)) + 0 ) + ( t Prolog-colon-minus-indent))) + ((looking-at "->") + (Prolog-backward-to-noncomment (point-min)) + (backward-Prolog-goal) + (+ (current-column) prolog-indent-width)) + ((bobp) 0) + (t + (Prolog-backward-to-noncomment (point-min)) + (if (save-excursion + (beginning-of-line 1) + (skip-chars-forward " \t") + (looking-at "%%[^%]")) + (current-column) + (let ((pos (point))) + (skip-chars-backward " \t") + (or (bobp) (forward-char -1)) + (or (bobp) (forward-char -1)) ;Backward twice + (cond + ((looking-at ".;") + (goto-char pos) + (+ -1 (current-column) prolog-indent-width)) + ((looking-at ".,") + (backward-Prolog-goal 1) + (current-column)) + ((looking-at "->") + (cond + ((= (preceding-char) ?-) + Prolog-body-indent + ) + ( t + (backward-Prolog-goal) + (+ (current-column) Prolog-then-indent)))) + ((looking-at "[a-z_A-Z0-9'](") + (forward-char 2) + (current-column)) + ((looking-at ".[({]") + (forward-char 1) + (+ (current-column) prolog-indent-width)) + ((looking-at ":-") Prolog-body-indent) + ((looking-at ".[^.]") + (goto-char pos) + (max (- (current-column) prolog-indent-width) 0)) + (t 0 )) + )))))) + +;;;---------------------------------------------------------------------------- +;;; Taken from the prolog mode by Ken'ichi HANDA (handa@etl.go.jp) +(defun Prolog-backward-to-noncomment (lim) + (let (opoint stop) + (while (not stop) + (skip-chars-backward " \t\n\f" lim) + (setq opoint (point)) + (if (and (>= (point) (+ 2 lim)) + (= (preceding-char) ?/) (= (char-after (- (point) 2)) ?*)) + (search-backward "/*" lim 'mv) + (let ((p (max lim (save-excursion (beginning-of-line) (point))))) + (if (nth 4 (parse-partial-sexp p (point))) + (search-backward "%" p 'mv) + (goto-char opoint) + (setq stop t))))))) + + +(defvar Prolog-boc-regexp "^['a-z]") + +;;;---------------------------------------------------------------------------- +(defun Prolog-beginning-of-clause () + "Return the position of the beginning of the clause or nil." + (save-excursion + (catch 'boc + (while t + (cond + ((null (search-backward-regexp Prolog-boc-regexp (point-min) t)) + (throw 'boc nil)) + ((not (Prolog-in-comment-p)) + (throw 'boc (point)))))))) + +(defvar Prolog-eoc-regexp "\\.[ \t\f]*$") + +;;;---------------------------------------------------------------------------- +(defun Prolog-end-of-clause () + "Return the position of the beginning of the clause or nil." + (save-excursion + (catch 'boc + (while t + (cond + ((null (search-forward-regexp Prolog-eoc-regexp (point-max) t)) + (throw 'boc nil)) + ((not (Prolog-in-comment-p)) + (skip-chars-backward " \t\f\n") + (throw 'boc (point)))))))) + +;;;---------------------------------------------------------------------------- +(defun Prolog-indent-region (beg end) + (interactive "d\nm") + (let (tmp) + (if (null end) + (message "Mark not set") + (if (< end beg) (setq tmp end end beg beg tmp)) + (save-excursion + (setq end (- (point-max) end)) + (goto-char beg) + (Prolog-indent-line) + (forward-line 1) + (beginning-of-line) + (while (> (- (point-max) (point)) end) + (Prolog-indent-line) + (forward-line 1) + (beginning-of-line)))))) + +;;;---------------------------------------------------------------------------- +(defun Prolog-indent-clause () + (interactive) + (let ((beg (Prolog-beginning-of-clause)) + (end (Prolog-end-of-clause))) + (if (and beg end) (Prolog-indent-region beg end)))) + +;;;---------------------------------------------------------------------------- +(defun Prolog-fill-paragraph (&optional arg) (interactive) + (if (Prolog-in-comment-p) (fill-paragraph arg) (Prolog-indent-clause))) + +(defvar Prolog-electric t + "Variable indicating if the Prolog electric characters should be active.") + +;;;---------------------------------------------------------------------------- +;;; Taken from the prolog mode by Ken'ichi HANDA (handa@etl.go.jp) +;;; Modified +(defun Prolog-electic-char (arg) + "Insert character and correct line's indentation." + (interactive "P") + (if (or arg + (not Prolog-electric)) + (self-insert-command (prefix-numeric-value arg)) + (progn + (self-insert-command (prefix-numeric-value arg)) + (Prolog-indent-line)))) + +;;;---------------------------------------------------------------------------- +;;; Activate some additional keys +(define-key prolog-mode-map "(" 'Prolog-electic-char ) +(define-key prolog-mode-map ")" 'Prolog-electic-char ) +(define-key prolog-mode-map "{" 'Prolog-electic-char ) +(define-key prolog-mode-map "}" 'Prolog-electic-char ) +(define-key prolog-mode-map ";" 'Prolog-electic-char ) +(define-key prolog-mode-map "-" 'Prolog-electic-char ) +(define-key prolog-mode-map ">" 'Prolog-electic-char ) +(define-key prolog-mode-map "\t" 'Prolog-indent ) +(define-key prolog-mode-map "\M-q" 'Prolog-fill-paragraph ) + +;;;---------------------------------------------------------------------------- +(defun prolog-indent-line (&optional arg) (interactive "P") + (Prolog-indent (prefix-numeric-value arg))) + +(provide 'prolog-indent) |