diff options
author | John Mastro <john.b.mastro@gmail.com> | 2013-07-20 12:44:06 -0700 |
---|---|---|
committer | John Mastro <john.b.mastro@gmail.com> | 2013-07-20 12:44:06 -0700 |
commit | f5ef4e1756a9855de30f4d8d702b201a7672edd1 (patch) | |
tree | 0715c39ac5ff24292b71fca5a7fea8458f2f53f6 /sps-mode.el | |
parent | dbf4e2768a5aca45f36c804ae16d0717a5717991 (diff) | |
download | trident-mode.el-f5ef4e1756a9855de30f4d8d702b201a7672edd1.tar.gz trident-mode.el-f5ef4e1756a9855de30f4d8d702b201a7672edd1.tar.bz2 trident-mode.el-f5ef4e1756a9855de30f4d8d702b201a7672edd1.zip |
Some more commands
Add a couple expansion buffer commands (for copying to the kill
ring and saving the expansion) and sps-compile-buffer-to-file
which does pretty much as the name says.
Diffstat (limited to 'sps-mode.el')
-rw-r--r-- | sps-mode.el | 60 |
1 files changed, 37 insertions, 23 deletions
diff --git a/sps-mode.el b/sps-mode.el index a924956..c6fe472 100644 --- a/sps-mode.el +++ b/sps-mode.el @@ -35,8 +35,10 @@ two-key sequences behind a prefix of your choice.") (defvar sps-expansion-mode-map (let ((map (make-sparse-keymap))) + (define-key map (kbd "e") 'sps-send-expanded-code) + (define-key map (kbd "w") 'sps-kill-ring-save-dwim) + (define-key map (kbd "s") 'write-file) (define-key map (kbd "q") 'quit-window) - (define-key map (kbd "x") 'sps-send-expanded-code) map) "Keymap for `sps-expansion-mode' buffers.") @@ -58,7 +60,8 @@ what you're doing." ;; across it and gives it a try. ) -;;;; A few utilities + +;;;; Code expansion (defun sps-wrap-in-ps-form (string) "Return Parenscript STRING wrapped in a PS:PS form." @@ -68,12 +71,6 @@ what you're doing." "Return a form appropriate for evaluating STRING via Swank." `(swank:eval-and-grab-output ,(sps-wrap-in-ps-form string))) -(defun sps-file-name-base (filename) - "Return FILENAME's basename without it's extension." - (file-name-sans-extension (file-name-nondirectory filename))) - -;;;; Code expansion - (defun sps-expand (string) "Display the JavaScript generated from Parenscript STRING. @@ -96,21 +93,27 @@ buffer's major mode is determined by the variable (pop-to-buffer (current-buffer))))) (slime-current-package))) -;; (defun sps-compile-buffer-to-file (&optional append) -;; (interactive "p") -;; (when (and (buffer-modified-p) -;; (y-or-n-p "Save buffer? ")) -;; (save-buffer)) -;; (let* ((this buffer-file-name) -;; (dir (and this (file-name-directory this))) -;; (initial (and this (concat (sps-file-name-base this) ".js"))) -;; (destination (read-file-name "Destination: " dir nil nil initial nil)) -;; (string (buffer-substring-no-properties (point-min) (point-max)))) -;; (slime-eval-async (sps-swank-eval-expr string) -;; #'(lambda (result) -;; (let ((code (read (cadr result)))) -;; (write-region code nil destination append))) -;; (slime-current-package)))) +(defun sps-compile-buffer-to-file () + "Compile the current buffer and write the result. +Prompts for the destination. If a file already exists at the +destination it's overwritten." + (interactive) + (when (and (buffer-modified-p) + (y-or-n-p "Save buffer? ")) + (save-buffer)) + (let* ((this buffer-file-name) + (dir (and this (file-name-directory this))) + (initial (and this (concat (file-name-base this) ".js"))) + (destination (read-file-name "Destination: " dir nil nil initial nil)) + (string (buffer-substring-no-properties (point-min) (point-max)))) + (slime-eval-async (sps-swank-eval-expr string) + #'(lambda (result) + (let ((code (read (cadr result)))) + (with-temp-buffer + (erase-buffer) + (insert code) + (write-region 1 (point-max) destination)))) + (slime-current-package)))) (defun sps-expand-sexp () "Display the expansion of the form at point." @@ -194,6 +197,8 @@ If the region is active this is equivalent to invoking (sps-eval-region (region-beginning) (region-end)) (sps-eval-defun))) +;;;; Expansion buffer commands + (defun sps-send-expanded-code () "Send the expanded code to the browser. For use from `sps-expansion-mode' buffers." @@ -202,6 +207,15 @@ For use from `sps-expansion-mode' buffers." (buffer-substring-no-properties (point-min) (point-max)) #'skewer-post-minibuffer)) +(defun sps-kill-ring-save-dwim () + "Save the current buffer's content to the kill ring. +If the region is active, save it; otherwise save the entire +buffer." + (interactive) + (if (region-active-p) + (kill-ring-save (region-beginning) (region-end)) + (kill-ring-save (point-min) (point-max)))) + ;;;; Keybindings (defun sps-prefix-keys (prefix keys) |