From 5ca2062bd6e04b034b8fbe1c7cb48febd822dc0c Mon Sep 17 00:00:00 2001 From: Albert Graef Date: Tue, 23 Jan 2018 11:52:22 +0100 Subject: [PATCH] Add Juan Romero's faust-mode, fixes #120. --- syntax-highlighting/README | 6 +- syntax-highlighting/faust-mode.el | 91 +++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 syntax-highlighting/faust-mode.el diff --git a/syntax-highlighting/README b/syntax-highlighting/README index d5bcd0a5da..0306f9248d 100644 --- a/syntax-highlighting/README +++ b/syntax-highlighting/README @@ -35,8 +35,12 @@ faust filetype file augroup END 6) EMACS -An EMACS Faust mode is provided by Juan Gabriel Alzate Romero at https://github.com/rukano/emacs-faust-mode +copy file faust-mode.el into /usr/share/emacs/site-lisp and add the following lines to your .emacs: +(require 'faust-mode) +(setq auto-mode-alist (cons '("\\.dsp$" . faust-mode) auto-mode-alist)) + +NB: This is the latest version of emacs-faust-mode created by Juan Gabriel Alzate Romero, cf. https://github.com/agraef/emacs-faust-mode. 7) NANO copy file faust.nanorc into folder /usr/share/nano/ diff --git a/syntax-highlighting/faust-mode.el b/syntax-highlighting/faust-mode.el new file mode 100644 index 0000000000..49790ce14f --- /dev/null +++ b/syntax-highlighting/faust-mode.el @@ -0,0 +1,91 @@ +;;; faust-mode.el --- Basic faust syntax colorizer for emacs. + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; FAUST Mode (very simple syntax colorizing!) +;; by rukano +;; based on the tutorial on: +;; http://xahlee.org/emacs/elisp_syntax_coloring.html +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +;; BIG TODOS: +;; Colorize Composition Operators +;; Colorize after keyword {} +;; Colorize arguments (numbers) +;; Colorize [] metadata in string? +;; Run Shell faust w/ custom defaults +;; *** Get rid of the No comment syntax defined warning + + +;; ROADMAP +;; export option and list possibilities +;; create hotkeys for every compilation +;; view graph + +(defvar faust-keywords + '("process" "with" "case" "seq" "par" "sum" "prod" + "include" "import" "component" "library" "environment" "declare" + "define" "undef" "error" "pragma" "ident" + "if" "def" "else" "elif" "endif" "line" "warning")) + +(defvar faust-functions + '("mem" "prefix" "int" "float" + "rdtable" "rwtable" "select2" "select3" + "ffunction" "fconstant" "fvariable" + "attach" "acos" "asin" "atan" "atan2" "cos" "sin" "tan" "exp" + "log" "log10" "pow" "sqrt" "abs" "min" "max" "fmod" + "remainder" "floor" "ceil" "rint")) + +(defvar faust-ui-keywords + '("button" "checkbox" "vslider" "hslider" "nentry" + "vgroup" "hgroup" "tgroup" "vbargraph" "hbargraph")) + +;; optimize regex for words +;;(defvar faust-math-op-regexp "[=\+()\{\}*-]") +(defvar faust-variables-regexp "[A-Za-z][A-Za-z]*") +(defvar faust-arguments-regexp "[0-9]") +(defvar faust-operator-regexp "\\([~!_@,<>:;]\\)") +(defvar faust-math-op-regexp "[=\+\{\}()/*-]") +(defvar faust-keywords-regexp (regexp-opt faust-keywords 'words)) +(defvar faust-function-regexp (regexp-opt faust-functions 'words)) +(defvar faust-ui-keywords-regexp (regexp-opt faust-ui-keywords 'words)) + +;; create the list for font-lock. +(setq faust-font-lock-keywords + `( + (,faust-function-regexp . font-lock-type-face) + (,faust-ui-keywords-regexp . font-lock-builtin-face) + (,faust-math-op-regexp . font-lock-function-name-face) + (,faust-operator-regexp . font-lock-constant-face) + (,faust-keywords-regexp . font-lock-keyword-face) + ;; (,faust-variables-regexp . font-lock-variable-name-face) + ;; (,faust-arguments-regexp . font-lock-warning-face) + )) + +;; define the mode +;;;###autoload +(define-derived-mode faust-mode fundamental-mode + "FAUST mode" + "Major mode for editing FAUST files (Functional Audio Stream)…" + + ;; code for syntax highlighting + (setq font-lock-defaults '((faust-font-lock-keywords))) +) + +;; comment dwin support +(defun faust-comment-dwim (arg) +"Comment or uncomment current line or region in a smart way. +For detail, see `comment-dwim'." + (interactive "*P") + (require 'newcomment) + (let ((deactivate-mark nil) (comment-start "//") (comment-end "")) + (comment-dwim arg))) + +(modify-syntax-entry ?/ ". 124b" faust-mode-syntax-table) +(modify-syntax-entry ?* ". 23" faust-mode-syntax-table) +(modify-syntax-entry ?\n "> b" faust-mode-syntax-table) +(modify-syntax-entry ?\^m "> b" faust-mode-syntax-table) + +(provide 'faust-mode) + +;; End: +;;; faust-mode.el ends here