ledit.el 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. ;;; ledit.el --- Emacs side of ledit interface
  2. ;; Copyright (C) 1985, 2001-2012 Free Software Foundation, Inc.
  3. ;; Maintainer: FSF
  4. ;; Keywords: languages
  5. ;; This file is part of GNU Emacs.
  6. ;; GNU Emacs is free software: you can redistribute it and/or modify
  7. ;; it under the terms of the GNU General Public License as published by
  8. ;; the Free Software Foundation, either version 3 of the License, or
  9. ;; (at your option) any later version.
  10. ;; GNU Emacs is distributed in the hope that it will be useful,
  11. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ;; GNU General Public License for more details.
  14. ;; You should have received a copy of the GNU General Public License
  15. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  16. ;;; Commentary:
  17. ;; This is a major mode for editing Liszt. See etc/LEDIT for details.
  18. ;;; Code:
  19. ;;; To do:
  20. ;;; o lisp -> emacs side of things (grind-definition and find-definition)
  21. (defvar ledit-mode-map nil)
  22. (defconst ledit-zap-file
  23. (expand-file-name (concat (user-login-name) ".l1") temporary-file-directory)
  24. "File name for data sent to Lisp by Ledit.")
  25. (defconst ledit-read-file
  26. (expand-file-name (concat (user-login-name) ".l2") temporary-file-directory)
  27. "File name for data sent to Ledit by Lisp.")
  28. (defconst ledit-compile-file
  29. (expand-file-name (concat (user-login-name) ".l4") temporary-file-directory)
  30. "File name for data sent to Lisp compiler by Ledit.")
  31. (defconst ledit-buffer "*LEDIT*"
  32. "Name of buffer in which Ledit accumulates data to send to Lisp.")
  33. ;;;###autoload
  34. (defconst ledit-save-files t "\
  35. *Non-nil means Ledit should save files before transferring to Lisp.")
  36. ;;;###autoload
  37. (defconst ledit-go-to-lisp-string "%?lisp" "\
  38. *Shell commands to execute to resume Lisp job.")
  39. ;;;###autoload
  40. (defconst ledit-go-to-liszt-string "%?liszt" "\
  41. *Shell commands to execute to resume Lisp compiler job.")
  42. (defun ledit-save-defun ()
  43. "Save the current defun in the ledit buffer."
  44. (interactive)
  45. (save-excursion
  46. (end-of-defun)
  47. (let ((end (point)))
  48. (beginning-of-defun)
  49. (append-to-buffer ledit-buffer (point) end))
  50. (message "Current defun saved for Lisp")))
  51. (defun ledit-save-region (beg end)
  52. "Save the current region in the ledit buffer"
  53. (interactive "r")
  54. (append-to-buffer ledit-buffer beg end)
  55. (message "Region saved for Lisp"))
  56. (defun ledit-zap-defun-to-lisp ()
  57. "Carry the current defun to Lisp."
  58. (interactive)
  59. (ledit-save-defun)
  60. (ledit-go-to-lisp))
  61. (defun ledit-zap-defun-to-liszt ()
  62. "Carry the current defun to liszt."
  63. (interactive)
  64. (ledit-save-defun)
  65. (ledit-go-to-liszt))
  66. (defun ledit-zap-region-to-lisp (beg end)
  67. "Carry the current region to Lisp."
  68. (interactive "r")
  69. (ledit-save-region beg end)
  70. (ledit-go-to-lisp))
  71. (defun ledit-go-to-lisp ()
  72. "Suspend Emacs and restart a waiting Lisp job."
  73. (interactive)
  74. (if ledit-save-files
  75. (save-some-buffers))
  76. (if (get-buffer ledit-buffer)
  77. (with-current-buffer ledit-buffer
  78. (goto-char (point-min))
  79. (write-region (point-min) (point-max) ledit-zap-file)
  80. (erase-buffer)))
  81. (suspend-emacs ledit-go-to-lisp-string)
  82. (load ledit-read-file t t))
  83. (defun ledit-go-to-liszt ()
  84. "Suspend Emacs and restart a waiting Liszt job."
  85. (interactive)
  86. (if ledit-save-files
  87. (save-some-buffers))
  88. (if (get-buffer ledit-buffer)
  89. (with-current-buffer ledit-buffer
  90. (goto-char (point-min))
  91. (insert "(declare (macros t))\n")
  92. (write-region (point-min) (point-max) ledit-compile-file)
  93. (erase-buffer)))
  94. (suspend-emacs ledit-go-to-liszt-string)
  95. (load ledit-read-file t t))
  96. (defun ledit-setup ()
  97. "Set up key bindings for the Lisp/Emacs interface."
  98. (unless ledit-mode-map
  99. (setq ledit-mode-map (make-sparse-keymap))
  100. (set-keymap-parent ledit-mode-map lisp-mode-shared-map))
  101. (define-key ledit-mode-map "\e\^d" 'ledit-save-defun)
  102. (define-key ledit-mode-map "\e\^r" 'ledit-save-region)
  103. (define-key ledit-mode-map "\^xz" 'ledit-go-to-lisp)
  104. (define-key ledit-mode-map "\e\^c" 'ledit-go-to-liszt))
  105. (ledit-setup)
  106. ;;;###autoload
  107. (defun ledit-mode ()
  108. "\\<ledit-mode-map>Major mode for editing text and stuffing it to a Lisp job.
  109. Like Lisp mode, plus these special commands:
  110. \\[ledit-save-defun] -- record defun at or after point
  111. for later transmission to Lisp job.
  112. \\[ledit-save-region] -- record region for later transmission to Lisp job.
  113. \\[ledit-go-to-lisp] -- transfer to Lisp job and transmit saved text.
  114. \\[ledit-go-to-liszt] -- transfer to Liszt (Lisp compiler) job
  115. and transmit saved text.
  116. \\{ledit-mode-map}
  117. To make Lisp mode automatically change to Ledit mode,
  118. do (setq lisp-mode-hook 'ledit-from-lisp-mode)"
  119. (interactive)
  120. (delay-mode-hooks (lisp-mode))
  121. (ledit-from-lisp-mode))
  122. ;;;###autoload
  123. (defun ledit-from-lisp-mode ()
  124. (use-local-map ledit-mode-map)
  125. (setq mode-name "Ledit")
  126. (setq major-mode 'ledit-mode)
  127. (run-mode-hooks 'ledit-mode-hook))
  128. (provide 'ledit)
  129. ;;; ledit.el ends here