Annotation of OpenXM_contrib/pari-2.2/emacs/with-syntax.el, Revision 1.1
1.1 ! noro 1: ;; This file is to be used with pari.el and with pari-translator.el
! 2: ;; where further explanations may be found. See also the file pariemacs.txt.
! 3:
! 4: ;; Created November 22 1998 by Olivier Ramare (ramare@gat.univ-lille1.fr)
! 5:
! 6: ;; Description:
! 7: ;; A lisp file used in gp-script-mode to use the syntax 'with'.
! 8: ;; See the function 'translate-with for more details.
! 9: ;; To use it in an edited gp-program, introduce the following
! 10: ;; lines in this program:
! 11: ;; /*@
! 12: ;; (load-file "with-syntax.el")
! 13: ;; (setq gp-input-filter-hook (list 'translate))
! 14: ;; */
! 15:
! 16: ;; You should load some general functions for translating,
! 17: ;; and the name below may be different on your system:
! 18: (require 'pari-translator
! 19: (concat gp-gphelp-dir "pari-translator.el"))
! 20:
! 21: ;; Here is the master function:
! 22: (defun translate nil
! 23: (gp-translate-on-other-file)
! 24:
! 25: ;; Now starts the translation:
! 26: (translate-with)
! 27: )
! 28:
! 29:
! 30: ;;---------------------
! 31: ;; Translation of with
! 32: ;;---------------------
! 33:
! 34: (defvar translate-with-number 0
! 35: "The next variable of a `with' function will be replaced by the
! 36: identifier whose name is the concatenation of \"with\" with this
! 37: number.")
! 38:
! 39: (defun translate-with nil
! 40: "Understand the syntax \"with(foo,to_do)\" in a gp-program, where foo
! 41: is an expression evaluating to a vector, as follows: any subsequent
! 42: dot `.' not preceded by a character of the set []a-zA-Z0-9_] is
! 43: replaced by this evaluation. An auxiliary variable with# is used where
! 44: # is an integer given by the variable 'translate-with-number.
! 45: Imbricated with are allowed and the innermost one has priority. "
! 46:
! 47: (goto-char (point-max))
! 48: (while (re-search-backward "\\([^a-zA-Z_0-9]\\|\\`\\)with(" nil t)
! 49: (goto-char (match-end 0))
! 50: (let ((father (buffer-substring (point)
! 51: (gp-looking-at-rat-exp)))
! 52: (replacement
! 53: (concat "with" (number-to-string translate-with-number)))
! 54: (p-end (save-excursion
! 55: (forward-char -1) (forward-sexp)
! 56: (- (point) 1))))
! 57: (setq translate-with-number (+ 1 translate-with-number))
! 58: ;; Erase the command:
! 59: (forward-char -5)
! 60: (delete-char (+ 6 (length father)))
! 61: ;; Insert new variable:
! 62: (insert (concat replacement "=" father ";\n"))
! 63: (setq p-end (- p-end
! 64: (- (length replacement) 3)))
! 65: ;; Erase last ):
! 66: (save-excursion (goto-char p-end) (delete-char 1))
! 67: ;; Replace proper `.' by new variable:
! 68: (while (re-search-forward "[^]a-zA-Z0-9_]\\." (- p-end 1) t)
! 69: (forward-char -1) (delete-char 1)
! 70: (insert replacement)
! 71: (setq p-end (+ p-end (- (length replacement) 1)))
! 72: (forward-char 1))))
! 73: ;; Set the counter back to 0 to avoid creating to many
! 74: ;; variables:
! 75: (setq translate-with-number 0))
! 76:
! 77:
! 78: ;; with-syntax.el ends here
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>