Fork of midizap that works with djcontrol instinct
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

112 lines
3.6 KiB

;;; midizap-mode.el --- midizap syntax highlighting for Emacs.
;;; Commentary:
;;; This is a simple mode for editing midizaprc files which provides basic
;;; syntax highlighting, and a command midizap-mode-run, bound to C-c C-c,
;;; which lets you quickly launch a midizap session (with options) on the
;;; edited midizaprc file in an Emacs buffer.
;;; Install this anywhere where Emacs finds it (e.g., in the Emacs site-lisp
;;; directory -- usually under /usr/share/emacs/site-lisp on Un*x systems, or
;;; in any directory on the Emacs load-path) and load it in your .emacs as
;;; follows:
;;; (require 'midizap-mode)
;;; The mode also supports auto-completion of midizaprc keywords, to make this
;;; work you'll need the auto-complete package available from MELPA, please
;;; check:
;;; In the midizap-mode subdirectory you'll find some snippets to be used with
;;; yasnippet (; to use these, copy
;;; the entire folder to your ~/.emacs.d/snippets directory.
;;; Code:
(require 'comint)
(defconst midizap-keywords
;; keysyms
(define-generic-mode 'midizap-mode
'(("^[[:blank:]]*\\(#.*\\)" 1 'font-lock-comment-face t)
("[[:blank:]]+\\(#.*\\)" 1 'font-lock-comment-face t)
1 'font-lock-variable-name-face)
("\\<\\(\\([Kk][Pp]:\\)?[A-Ga-g][#Bb]?-?[0-9]+\\|\\([Mm]\\|[Cc][Hh]\\|[Pp][Bb]\\|[Pp][Cc]\\|[Cc][Cc]\\|[Cc][Pp]\\)[0-9]*\\|XK_[A-Za-z_0-9]+\\(/[UDH]\\)?\\)\\>" 1 'default)
("\\<\\([0-9]+\\)\\>" 1 'font-lock-constant-face))
(list "\\.midizaprc\\'")
(list 'midizap-mode-setup-function)
"Generic mode for midizap configuration files.")
(defvar midizap-mode-keymap (make-sparse-keymap)
"Keymap for midizap-mode.")
(defvar midizap-command "midizap -drk ")
(defvar ac-sources)
(defvar midizap-mode-ac-source
'((candidates . midizap-keywords)))
(defun midizap-mode-run (command)
"Run the current midizaprc file with COMMAND in a comint buffer."
(let ((command (eval midizap-command)))
(read-string "Run midizap with: " command))))
(unless (equal command (eval midizap-command))
(setq midizap-command command))
(let* ((file (buffer-file-name))
(buf-name (concat "*" file "*")))
(with-current-buffer (get-buffer-create buf-name)
(list "-c" (concat command " " file)))
(display-buffer buf-name))))
(define-key midizap-mode-keymap "\C-c\C-c" 'midizap-mode-run)
(defun midizap-mode-setup-function ()
"Custom setup function for midizap-mode."
(make-local-variable 'parse-sexp-ignore-comments)
(make-local-variable 'comment-start)
(make-local-variable 'comment-start-skip)
(make-local-variable 'comment-end)
(setq parse-sexp-ignore-comments t
comment-end ""
comment-start "# "
comment-start-skip "# *"
(if (boundp 'ac-sources)
(add-to-list 'ac-modes 'midizap-mode)
(add-to-list 'ac-sources 'midizap-mode-ac-source))
(message "You may want to install and use auto-complete"))
(use-local-map midizap-mode-keymap)
(provide 'midizap-mode)
;; End:
;;; midizap-mode.el ends here