Advertisement
Guest User

Untitled

a guest
Aug 11th, 2021
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.35 KB | None | 0 0
  1.  
  2. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3. ;;
  4. ;; MODULE : init-sage.scm
  5. ;; DESCRIPTION : Initialize SageMath plugin
  6. ;; COPYRIGHT : (C) 2004 Ero Carrera
  7. ;; COPYRIGHT : (C) 2007 Mike Carrera
  8. ;;
  9. ;; This software falls under the GNU general public license version 3 or later.
  10. ;; It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
  11. ;; in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
  12. ;;
  13. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  14.  
  15. ;;(use-modules (dynamic session-edit) (dynamic program-edit))
  16.  
  17. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  18. ;; Plugin configuration
  19. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  20.  
  21. ;; Basically, the serializer makes the input preserve the newlines
  22. ;; and adds the string character "\n<EOF>\n" by the end.
  23. ;; I guess it could send "\x04" instead to signal a real EOF,
  24. ;; but I would need to check if that does not kill the pipe...
  25. ;; An alternative approach is to use the input-done? command
  26. ;; from TeXmacs, but, at the time of this writing, it did not work.--A
  27.  
  28. (define (sage-serialize lan t)
  29. (with u (pre-serialize lan t)
  30. (with s (texmacs->code (stree->tree u) "SourceCode")
  31. (string-append s "\n<EOF>\n"))))
  32.  
  33. (define (sage-entry)
  34. (if (url-exists? "$TEXMACS_HOME_PATH/plugins/tmpy")
  35. (system-url->string "$TEXMACS_HOME_PATH/plugins/tmpy/session/tm_sage.py")
  36. (system-url->string "$TEXMACS_PATH/plugins/tmpy/session/tm_sage.py")))
  37.  
  38. (define (texmacs-cygwin-path)
  39. (if (url-exists? "$TEXMACS_HOME_PATH/plugins/tmpy")
  40. (string-replace
  41. (string-replace
  42. (string-replace
  43. (string-replace
  44. (string-replace (getenv "TEXMACS_HOME_PATH")
  45. "C:" "/cygdrive/c")
  46. "\\" "/")
  47. " " "\\ ")
  48. "(" "\\(")
  49. ")" "\\)")
  50. (string-replace
  51. (string-replace
  52. (string-replace
  53. (string-replace
  54. (string-replace (getenv "TEXMACS_PATH")
  55. "C:" "/cygdrive/c")
  56. "\\" "/")
  57. " " "\\ ")
  58. "(" "\\(")
  59. ")" "\\)")))
  60.  
  61. ;; TODO: what if there are two different versions of SageMath
  62. (define (sagemath-win-app-url)
  63. (url-resolve "B:/SageMath*" "r"))
  64.  
  65. (define (sagemath-bash)
  66. (string-append (url->system (sagemath-win-app-url)) "\\runtime\\bin\\bash.exe"))
  67.  
  68. (define (sage-version)
  69. (string-replace
  70. (url->system (url-tail (sagemath-win-app-url)))
  71. "SageMath "
  72. ""))
  73.  
  74. (define (sage-launchers)
  75. (if (os-mingw?)
  76. `((:launch ,(string-append (raw-quote (sagemath-bash)) " --login -c '/opt/sagemath-" (sage-version) "/sage -python " (texmacs-cygwin-path) "/plugins/tmpy/session/tm_sage.py'")))
  77. `((:launch ,(string-append "sage -python " (sage-entry))))))
  78.  
  79. (define (sage-require)
  80. (if (os-mingw?)
  81. (url-exists? (sagemath-win-app-url))
  82. (url-exists-in-path? "sage")))
  83.  
  84. (plugin-configure sage
  85. (:macpath "Sage*" "Contents/Resources/sage")
  86. (:require (sage-require))
  87. ,@(sage-launchers)
  88. (:tab-completion #t)
  89. (:serializer ,sage-serialize)
  90. (:session "Sage")
  91. (:scripts "Sage"))
  92.  
  93. ;(set-session-multiline-input "sage" "default" #t)
  94. ;(set-program-multiline-input "sage" "default" #t)
  95.  
  96. (when (supports-sage?)
  97. (lazy-input-converter (sage-input) sage))
  98.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement