From cdb3176891095594d7cb4e8d94f5db4b1c3147e2 Mon Sep 17 00:00:00 2001 From: stephen Date: Mon, 3 Oct 2005 10:58:32 +0000 Subject: [PATCH] (ess-s-versions-list): New variable. (ess-s-versions): New variable. (ess-s-versions-create): New defun to allow other versions of S to be added to ESS, similar to ess-r-versions-create. git-svn-id: https://svn.r-project.org/ESS/trunk@3386 0bbaf3bd-34e0-0310-bf65-c717079852d4 --- lisp/essd-sp6.el | 145 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 145 insertions(+) diff --git a/lisp/essd-sp6.el b/lisp/essd-sp6.el index 5ab39594..98cfc6fe 100644 --- a/lisp/essd-sp6.el +++ b/lisp/essd-sp6.el @@ -119,6 +119,151 @@ New way to do it." (interactive) (ess-transcript-mode S+6-customize-alist)) +(defvar ess-s-versions-list nil + "List of other versions of S to add to ESS. +Each element of this list is itself a list: + \(FUNCTION PATH ARGS\) +e.g. + \(\"mysplus\" \"/usr/splus7/bin/splus7\" \"-j\"\) +FUNCTION is the name of the function to be created by Emacs. +PATH is the full path to the variant of S that you want to run. +ARGS (optional) are start-up arguments that you want to pass to S. +") + +(defvar ess-s-versions '("Splus") + "List of partial strings for versions of S to access within ESS. +Each string specifies the start of a filename. If a filename +beginning with one of these strings is found on `exec-path', a M-x +command for that version of S is made available. For example, if the +file \"Splus7\" is found and this variable includes the string +\"Splus\", a function called `M-x Splus7' will be available to run that +version of S. +If duplicate versions of the same program are found (which happens if +the same path is listed on `exec-path' more than once), they are +ignored by calling `ess-uniq-list'. +If you set this variable, you need to restart Emacs (and set this variable +before ess-site is loaded) for it to take effect. + +See also `ess-s-versions-list' for another way to add other S +processes to ESS. ") + +(defun ess-s-versions-create () + "Generate defuns for starting other versions of S. +See `ess-s-versions' for strings that determine which functions are created. +It assumes these versions of S can be run as a substitute for Splus6. + +This function returns the list of S defuns, if any, that were +created. The defuns will normally be placed on the menubar upon +ESS initialisation." + + ;; This works by creating a temp buffer where the template function is + ;; edited so that X.Y is replaced by the version name + (let ((template "") + (template-args) + (beg) + (versions) + (version) + (eval-buf (get-buffer-create "*ess-temp-s-evals*")) + (ess-s-versions-created) + + (ess-s-versions-list ess-s-versions-list) + ;; make local copy so it won't be destroyed globally + ) + ;; + ;; This is the template function used for creating M-x Splus + (setq template "(defun S-X.Y () + \"Call S-X.Y, i.e., the S version 'S-X.Y' using ESS. +This function was generated by `ess-s-versions-create'.\" + (interactive \"\") + (let ((inferior-S+6-program-name \"S-X.Y\")) + (S+6))) + +") + (save-excursion + (set-buffer eval-buf) + ;; clear the buffer. + (delete-region (point-min) (point-max)) + + ;; Find which versions of S we want. Remove the pathname, leaving just + ;; the name of the executable. + (setq versions + (ess-uniq-list + (mapcar 'file-name-nondirectory + (apply 'nconc + (mapcar 'ess-find-exec-completions + ess-s-versions))))) + (ess-write-to-dribble-buffer + (format "(S): ess-s-versions-create making M-x defuns for %s" + (mapconcat 'identity versions " "))) + (setq ess-s-versions-created versions) ;keep copy for returning at end. + ;; Iterate over each string in VERSIONS, creating a new defun each time. + (while versions + (setq version (car versions) + versions (cdr versions)) + (setq beg (point)) + (insert template) + (goto-char beg) + (while (search-forward "S-X.Y" nil t) + (replace-match version t t)) + (goto-char (point-max)) + ) + + + ;; Check if we have any static defuns to evaluate. + (when ess-s-versions-list + + ;; Need a slightly different template for static defuns. + (setq template "(defun S-X.Y () + \"Call S-X.Y, i.e., the S version 'S-X.Y' using ESS. +This function will run S-FULL-PATH +This function was generated by `ess-s-versions-create'.\" + (interactive \"\") + (let ((inferior-S+6-program-name \"S-FULL-PATH\")) + (S+6))) + +") + ;; need another version of template, with args. + (setq template-args "(defun S-X.Y () + \"Call S-X.Y, i.e., the S version 'S-X.Y' using ESS. +This function will run S-FULL-PATH +This function was generated by `ess-s-versions-create'.\" + (interactive \"\") + (let ((inferior-S+6-program-name \"S-FULL-PATH\") + (inferior-Splus-args \"S-MYARGS\")) + (S+6))) + +") + (while ess-s-versions-list + (setq this-S-version (car ess-s-versions-list) + S-defun (car this-S-version) + S-path (cadr this-S-version) + S-args (caddr this-S-version) + ess-s-versions-list (cdr ess-s-versions-list)) + ;; Could do error checking here, that S-defun is not defined + ;; before, and that S-path is valid. + (setq beg (point)) + (insert + (if S-args + template-args + template)) + (goto-char beg) + (while (search-forward "S-X.Y" nil t) + (replace-match S-defun t t)) + (goto-char beg) + (while (search-forward "S-FULL-PATH" nil t) + (replace-match S-path t t)) + (when S-args + (goto-char beg) + (while (search-forward "S-MYARGS" nil t) + (replace-match S-args t t))) + (goto-char (point-max)) + (add-to-list 'ess-s-versions-created S-defun 'append)) + ;; buffer has now been created with defuns, so eval them! + (eval-buffer) + ;;(kill-buffer eval-buf) + ) + ess-s-versions-created))) + ; Provide package (provide 'essd-sp6) -- 2.11.4.GIT