<commit_before>;; geiser-plt.el -- geiser support for PLT scheme

;; Copyright (C) 2009 <NAME>

;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the Modified BSD License. You should
;; have received a copy of the license along with this program. If
;; not, see <http://www.xfree86.org/3.3.6/COPYRIGHT2.html#5>.

;; Start date: Sat Apr 25, 2009 21:13




(require 'geiser-edit)
(require 'geiser-doc)
(require 'geiser-eval)
(require 'geiser-syntax)
(require 'geiser-custom)
(require 'geiser-base)



;;; Customization:

(defgroup geiser-plt nil
  "Customization for Geiser's PLT flavour."
  :group 'geiser)

(geiser-custom--defcustom geiser-plt-binary
  (cond ((eq system-type 'windows-nt) "MzScheme.exe")
        ((eq system-type 'darwin) "mzscheme")
        (t "mzscheme"))
  "Name to use to call the mzscheme executable when starting a REPL."
  :type '(choice string (repeat string))
  :group 'geiser-plt)

(geiser-custom--defcustom geiser-plt-collects nil
  "A list of paths to be added to mzscheme's collection directories."
  :type '(repeat file)
  :group 'geiser-plt)

(geiser-custom--defcustom geiser-plt-init-file "~/.plt-geiser"
  "Initialization file with user code for the mzscheme REPL."
  :type 'string
  :group 'geiser-plt)




;;; REPL support:

(defun geiser-plt-binary ()
  (if (listp geiser-plt-binary) (car geiser-plt-binary) geiser-plt-binary))

(defun geiser-plt-parameters ()
  "Return a list with all parameters needed to start mzscheme.
This function uses `geiser-plt-init-file' if it exists."
  (let ((init-file (and (stringp geiser-plt-init-file)
                        (expand-file-name geiser-plt-init-file))))
    `("-i" "-q"
      "-S" ,(expand-file-name "plt/" geiser-scheme-dir)
      ,@(apply 'append (mapcar (lambda (p) (list "-S" p)) geiser-plt-collects))
      ,@(and (listp geiser-plt-binary) (cdr geiser-plt-binary))
      ,@(and init-file (file-readable-p init-file) (list "-f" init-file))
      "-f" ,(expand-file-name "plt/geiser.ss" geiser-scheme-dir))))

(defconst geiser-plt-prompt-regexp "^mzscheme@[^ ]*?> ")

(defun switch-to-plt (&optional ask)
  (interactive "P")
  (switch-to-geiser ask 'plt))

(defun run-plt ()
  "Run Geiser using mzscheme."
  (interactive)
  (run-geiser 'plt))



;;; Evaluation support:

(defun geiser-plt-geiser-procedure (proc)
  (let ((proc (intern (format "geiser:%s" proc))))
    `(dynamic-require ''geiser ',proc)))

(defconst geiser-plt--module-re
  "^(module +\\([^ ]+\\)")

(defun geiser-plt--explicit-module ()
  (save-excursion
    (goto-char (point-min))
    (and (re-search-forward geiser-plt--module-re nil t)
         (ignore-errors
           (car (read-from-string (match-string-no-properties 1)))))))

(defsubst geiser-plt--implicit-module ()
  (save-excursion
    (goto-char (point-min))
    (if (re-search-forward "^#lang " nil t)
        (buffer-file-name)
      :f)))

(defun geiser-plt-get-module (&optional module)
  (cond ((and (null module) (buffer-file-name))) ;; (geiser-plt--explicit-module)
        ((null module) (geiser-plt--implicit-module))
        ((symbolp module) module)
        ((and (stringp module) (file-name-absolute-p module)) module)
        ((stringp module) (intern module))
        (t nil)))

(defun geiser-plt-symbol-begin (module)
  (save-excursion (skip-syntax-backward "^-()>") (point)))



;;; External help

(defun geiser-plt-external-help (symbol module)
  (message "Requesting help for '%s'..." symbol)
  (geiser-eval--send/wait
   `(:eval (get-help ',symbol (:module ,module)) geiser/autodoc))
  (minibuffer-message "%s done" (current-message))
  t)



;;; Error display

(defconst geiser-plt--file-rxs '("^\\([^:\n\"]+\\):\\([0-9]+\\):\\([0-9]+\\)"
                                 "path:\"?\\([^>\"\n]+\\)\"?>"
                                 "module: \"\\([^>\"\n]+\\)\""))

(defun geiser-plt--find-files (rx)
  (save-excursion
    (while (re-search-forward rx nil t)
      (geiser-edit--make-link (match-beginning 1)
                              (match-end 1)
                              (match-string 1)
                              (match-string 2)
                              (match-string 3)))))

(defun geiser-plt-display-error (module key msg)
  (when key
    (insert "Error: ")
    (geiser-doc--insert-button key nil 'plt)
    (newline 2))
  (when msg
    (let ((p (point)))
      (insert msg)
      (let ((end (point)))
        (goto-char p)
        (mapc 'geiser-plt--find-files geiser-plt--file-rxs)
        (goto-char end)
        (fill-region p end)
        (newline))))
  t)



;;; Trying to ascertain whether a buffer is mzscheme scheme:

(defun geiser-plt-guess ()
  (or (save-excursion
        (goto-char (point-min))
        (re-search-forward "#lang " nil t))
      (geiser-plt--explicit-module)))



;;; Implementation definition:

(define-geiser-implementation plt
  (binary geiser-plt-binary)
  (arglist geiser-plt-parameters)
  (startup)
  (prompt-regexp geiser-plt-prompt-regexp)
  (marshall-procedure geiser-plt-geiser-procedure)
  (find-module geiser-plt-get-module)
  (find-symbol-begin geiser-plt-symbol-begin)
  (display-error geiser-plt-display-error)
  (display-help geiser-plt-external-help)
  (check-buffer geiser-plt-guess))



(provide 'geiser-plt)
;;; geiser-plt.el ends here<commit_msg>PLT: Unsupported procedures listed.<commit_after>;; geiser-plt.el -- geiser support for PLT scheme

;; Copyright (C) 2009 <NAME>

;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the Modified BSD License. You should
;; have received a copy of the license along with this program. If
;; not, see <http://www.xfree86.org/3.3.6/COPYRIGHT2.html#5>.

;; Start date: Sat Apr 25, 2009 21:13




(require 'geiser-edit)
(require 'geiser-doc)
(require 'geiser-eval)
(require 'geiser-syntax)
(require 'geiser-custom)
(require 'geiser-base)



;;; Customization:

(defgroup geiser-plt nil
  "Customization for Geiser's PLT flavour."
  :group 'geiser)

(geiser-custom--defcustom geiser-plt-binary
  (cond ((eq system-type 'windows-nt) "MzScheme.exe")
        ((eq system-type 'darwin) "mzscheme")
        (t "mzscheme"))
  "Name to use to call the mzscheme executable when starting a REPL."
  :type '(choice string (repeat string))
  :group 'geiser-plt)

(geiser-custom--defcustom geiser-plt-collects nil
  "A list of paths to be added to mzscheme's collection directories."
  :type '(repeat file)
  :group 'geiser-plt)

(geiser-custom--defcustom geiser-plt-init-file "~/.plt-geiser"
  "Initialization file with user code for the mzscheme REPL."
  :type 'string
  :group 'geiser-plt)




;;; REPL support:

(defun geiser-plt-binary ()
  (if (listp geiser-plt-binary) (car geiser-plt-binary) geiser-plt-binary))

(defun geiser-plt-parameters ()
  "Return a list with all parameters needed to start mzscheme.
This function uses `geiser-plt-init-file' if it exists."
  (let ((init-file (and (stringp geiser-plt-init-file)
                        (expand-file-name geiser-plt-init-file))))
    `("-i" "-q"
      "-S" ,(expand-file-name "plt/" geiser-scheme-dir)
      ,@(apply 'append (mapcar (lambda (p) (list "-S" p)) geiser-plt-collects))
      ,@(and (listp geiser-plt-binary) (cdr geiser-plt-binary))
      ,@(and init-file (file-readable-p init-file) (list "-f" init-file))
      "-f" ,(expand-file-name "plt/geiser.ss" geiser-scheme-dir))))

(defconst geiser-plt-prompt-regexp "^mzscheme@[^ ]*?> ")

(defun switch-to-plt (&optional ask)
  (interactive "P")
  (switch-to-geiser ask 'plt))

(defun run-plt ()
  "Run Geiser using mzscheme."
  (interactive)
  (run-geiser 'plt))



;;; Evaluation support:

(defun geiser-plt-geiser-procedure (proc)
  (let ((proc (intern (format "geiser:%s" proc))))
    `(dynamic-require ''geiser ',proc)))

(defconst geiser-plt--module-re
  "^(module +\\([^ ]+\\)")

(defun geiser-plt--explicit-module ()
  (save-excursion
    (goto-char (point-min))
    (and (re-search-forward geiser-plt--module-re nil t)
         (ignore-errors
           (car (read-from-string (match-string-no-properties 1)))))))

(defsubst geiser-plt--implicit-module ()
  (save-excursion
    (goto-char (point-min))
    (if (re-search-forward "^#lang " nil t)
        (buffer-file-name)
      :f)))

(defun geiser-plt-get-module (&optional module)
  (cond ((and (null module) (buffer-file-name))) ;; (geiser-plt--explicit-module)
        ((null module) (geiser-plt--implicit-module))
        ((symbolp module) module)
        ((and (stringp module) (file-name-absolute-p module)) module)
        ((stringp module) (intern module))
        (t nil)))

(defun geiser-plt-symbol-begin (module)
  (save-excursion (skip-syntax-backward "^-()>") (point)))



;;; External help

(defun geiser-plt-external-help (symbol module)
  (message "Requesting help for '%s'..." symbol)
  (geiser-eval--send/wait
   `(:eval (get-help ',symbol (:module ,module)) geiser/autodoc))
  (minibuffer-message "%s done" (current-message))
  t)



;;; Error display

(defconst geiser-plt--file-rxs '("^\\([^:\n\"]+\\):\\([0-9]+\\):\\([0-9]+\\)"
                                 "path:\"?\\([^>\"\n]+\\)\"?>"
                                 "module: \"\\([^>\"\n]+\\)\""))

(defun geiser-plt--find-files (rx)
  (save-excursion
    (while (re-search-forward rx nil t)
      (geiser-edit--make-link (match-beginning 1)
                              (match-end 1)
                              (match-string 1)
                              (match-string 2)
                              (match-string 3)))))

(defun geiser-plt-display-error (module key msg)
  (when key
    (insert "Error: ")
    (geiser-doc--insert-button key nil 'plt)
    (newline 2))
  (when msg
    (let ((p (point)))
      (insert msg)
      (let ((end (point)))
        (goto-char p)
        (mapc 'geiser-plt--find-files geiser-plt--file-rxs)
        (goto-char end)
        (fill-region p end)
        (newline))))
  t)



;;; Trying to ascertain whether a buffer is mzscheme scheme:

(defun geiser-plt-guess ()
  (or (save-excursion
        (goto-char (point-min))
        (re-search-forward "#lang " nil t))
      (geiser-plt--explicit-module)))



;;; Implementation definition:

(define-geiser-implementation plt
  (binary geiser-plt-binary)
  (arglist geiser-plt-parameters)
  (startup)
  (unsupported-procedures '(callers callees generic-methods))
  (prompt-regexp geiser-plt-prompt-regexp)
  (marshall-procedure geiser-plt-geiser-procedure)
  (find-module geiser-plt-get-module)
  (find-symbol-begin geiser-plt-symbol-begin)
  (display-error geiser-plt-display-error)
  (display-help geiser-plt-external-help)
  (check-buffer geiser-plt-guess))



(provide 'geiser-plt)
;;; geiser-plt.el ends here
{'fraction_non_alphanumeric': 0.1716501588488133, 'fraction_numerical': 0.005980190618575967, 'mean_word_length': 2.8320802005012533, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3994229', 'n_tokens_mistral': 3993, 'n_tokens_neox': 3742, 'n_words': 902}