-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathnesmusic.el
94 lines (79 loc) · 3.28 KB
/
nesmusic.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
;; -*- coding: utf-8; lexical-binding: t -*-
;;;; Emacs minor-mode for composing NES music
(require 'cl)
(define-minor-mode nesmusic-mode
"\\<nesmusic-mode-map>\
Compose music for the Nintendo Entertainment System
\\[nesmusic-audition] - Audition pattern"
nil
" NESmusic"
'(("\C-c\C-a" . nesmusic-audition)))
(defun nesmusic-slime-search-buffer-package ()
(interactive)
(let ((case-fold-search t)
(regexp "^(\\(cl:\\|nesmus:\\)?define-song\\>[ ']*\"\\([[:alnum:]\|[:upper:]\|[:space:]]*\\)"))
(save-excursion
(if (or (re-search-backward regexp nil t)
(re-search-forward regexp nil t))
(format "%s (song)" (match-string-no-properties 2))
(slime-search-buffer-package)))))
(setq slime-find-buffer-package-function
'nesmusic-slime-search-buffer-package)
(defcustom nesmusic-player-path nil
"Path to NSF player"
:type 'string
:group 'nesmusic)
(defun nesmusic-ensure-player-path-set ()
(interactive)
(unless nesmusic-player-path
(setq nesmusic-player-path
(expand-file-name (read-file-name "NSF Player: " nil nil t "festalon" 'file-executable-p)))))
;; (message "Directory %s" (slime-eval `(swank:default-directory)))
(defun nesmusic-audition (&optional repeat-count)
(interactive "P")
(nesmusic-ensure-player-path-set)
(unless (and (integerp repeat-count) (> repeat-count 0))
(setq repeat-count 1))
(message "%s" repeat-count)
(slime-connection)
(let* ((region (slime-region-for-defun-at-point))
(start-offset (first region))
(string (apply 'buffer-substring-no-properties region)))
(slime-flash-region (first region) (second region))
(apply 'run-hook-with-args 'slime-before-compile-functions region)
(let* ((line (save-excursion
(goto-char start-offset)
(list (line-number-at-pos) (1+ (current-column)))))
(position `((:position ,start-offset) (:line ,@line))))
(slime-eval-async
`(swank:compile-string-for-emacs
,string
,(buffer-name)
',position
,(if (buffer-file-name) (slime-to-lisp-filename (buffer-file-name)))
',slime-compilation-policy)
(lambda (result)
(hacked-slime-compilation-finished result repeat-count))))))
(defun hacked-slime-compilation-finished (result repeat-count)
(with-struct (slime-compilation-result. notes duration successp
loadp faslfile) result
(setf slime-last-compilation-result result)
(slime-show-note-counts notes duration (cond ((not loadp) successp)
(t (and faslfile successp))))
(when slime-highlight-compiler-notes
(slime-highlight-notes notes))
(run-hook-with-args 'slime-compilation-finished-hook notes)
(cond
((and loadp faslfile
(or successp
(slime-load-failed-fasl-p)))
(slime-eval-async `(swank:load-file ,faslfile)
(lambda (_)
(nesmusic-audition-last-pattern repeat-count))))
(successp
(nesmusic-audition-last-pattern repeat-count)))))
(defun nesmusic-audition-last-pattern (repeat-count)
(slime-eval-async `(nesmus::play-audition
,repeat-count
,nesmusic-player-path)))
(provide 'nesmusic)