Skip to content

Commit

Permalink
Add sonic-pi-send-dwim
Browse files Browse the repository at this point in the history
Function `sonic-pi-send-dwim` sends in a do wait I mean style.

If region is active, send it.
Then if there is an enclosing `live_loop' or `with_fx' sent it.
Otherwise send current line.
  • Loading branch information
TatriX committed Jan 26, 2021
1 parent 3cf101b commit 621ec00
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
4 changes: 2 additions & 2 deletions sonic-pi-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
(define-key map (kbd "C-c C-k") 'sonic-pi-send-buffer)
(define-key map (kbd "C-c C-r") 'sonic-pi-send-region)
(define-key map (kbd "C-c C-q") 'sonic-pi-quit)
(define-key map (kbd "C-c C-b") 'sonic-pi-stop-all)
(define-key map (kbd "C-c C-c") 'sonic-pi-send-live-loop)
(define-key map (kbd "C-c C-s") 'sonic-pi-stop-all)
(define-key map (kbd "C-c C-c") 'sonic-pi-send-dwim)
map))

;;;###autoload
Expand Down
20 changes: 20 additions & 0 deletions sonic-pi-osc.el
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,26 @@
(hlt-highlight-regexp-region s (point) ".+" 'eval-sonic-pi-flash nil))
(run-at-time flash-time nil 'hlt-unhighlight-region nil nil nil)))

(defun sonic-pi-send-dwim ()
"Send in a do wait I mean style.
If region is active, send it.
Then if there is an enclosing `live_loop' or `with_fx' sent it.
Otherwise send current line."
(interactive)
(cl-destructuring-bind (start end) (sonic-pi--dwim-region)
(message "Sending:\n%s" (buffer-substring start end))
(sonic-pi-osc-send-text start end)
(hlt-highlight-regexp-region start end ".+" 'eval-sonic-pi-flash nil))
(run-at-time flash-time nil 'hlt-unhighlight-region nil nil nil))

(defun sonic-pi--dwim-region ()
"Find region for dwim command."
(if (region-active-p)
(list (region-beginning) (region-end))
(if-let (start (save-excursion (re-search-backward "^\\(live_loop\\|with_fx\\)" nil t)))
(list start (save-excursion (ruby-end-of-block) (line-end-position)))
(list (line-beginning-position) (line-end-position)))))

(defun sonic-pi-osc-make-client (host port)
(make-network-process
:name "sonic-pi.el OSC client"
Expand Down

0 comments on commit 621ec00

Please sign in to comment.