Last active
August 29, 2015 13:56
-
-
Save johnmastro/9222113 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(require 'slime) | |
(require 'dash) | |
(require 'trident-mode) | |
(defvar trident-target-process nil | |
"The process that expansions will be sent to.") | |
(defun trident-list-process-buffers () | |
"Return a list of all buffers with an associated process." | |
(-filter #'get-buffer-process (buffer-list))) | |
(defun trident-read-process-buffer () | |
"Prompt for and read a buffer with an associated process." | |
(let ((buffers (trident-list-process-buffers))) | |
(when buffers | |
(completing-read "Process buffer: " (-map #'buffer-name buffers))))) | |
(defun trident-set-target-process (buffer-or-name) | |
"Set `trident-target-process' to BUFFER-OR-NAME. | |
If called interactively, prompt the user to select a buffer via | |
`completing-read'." | |
(interactive (list (trident-read-process-buffer))) | |
(setq trident-target-process (get-buffer-process buffer-or-name))) | |
(defun trident-send-expansion-to-proc (string) | |
"Expand STRING as Parenscript and send it to a process. | |
The value of `trident-target-process' determines what process the | |
code is sent to." | |
(interactive) | |
(if trident-target-process | |
(trident-with-expansion (code string) | |
(comint-send-string trident-target-process | |
(format "%s\n" code))) | |
(message "trident-target-process must be set first"))) | |
(defun trident-send-sexp-to-proc () | |
"Expand the sexp at point and send it to a process. | |
See `trident-send-expansion-to-proc'." | |
(interactive) | |
(trident-send-expansion-to-proc (slime-sexp-at-point))) | |
(defun trident-send-last-expression-to-proc () | |
"Expand the expression preceding point and send it to a process. | |
See `trident-send-expansion-to-proc'." | |
(interactive) | |
(trident-send-expansion-to-proc (slime-last-expression))) | |
(defun trident-send-defun-to-proc () | |
"Expand the current toplevel form and send it to a process. | |
See `trident-send-expansion-to-proc'." | |
(interactive) | |
(trident-send-expansion-to-proc (slime-defun-at-point))) | |
(defun trident-send-region-to-proc (beg end) | |
"Expand the currently active region and send it to a process. | |
See `trident-send-expansion-to-proc'." | |
(interactive "r") | |
(trident-send-expansion-to-proc (buffer-substring-no-properties beg end))) | |
(defun trident-send-buffer-to-proc () | |
"Expand the current buffer and send it to a process. | |
See `trident-send-expansion-to-proc'." | |
(interactive) | |
(trident-send-region-to-proc (point-min) (point-max))) | |
(defun trident-send-to-proc-dwim () | |
"Expand the region or toplevel form and send it to a process. | |
See `trident-send-expansion-to-proc'." | |
(interactive) | |
(if (use-region-p) | |
(trident-send-region-to-proc (region-beginning) (region-end)) | |
(trident-send-defun-to-proc))) | |
(provide 'trident-proc) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment