Commit b9f7144e45561f87d968b13ba7fde7b83b39638a
- Diff rendering mode:
- inline
- side by side
processing-mode.el
(141 / 41)
|   | |||
| 2 | 2 | ||
| 3 | 3 | ;; Processing.org language based on Java mode. Adds keyword | |
| 4 | 4 | ;; highlighting for all recognized Processing language functions. | |
| 5 | ;; Allows compilation of buffers and "sketches" from within Emacs but | ||
| 6 | ;; only for more recent versions of Processing. | ||
| 5 | 7 | ||
| 6 | 8 | ;; Copyright (C) 2008 Rudolf Olah <omouse@gmail.com> | |
| 7 | 9 | ;; Licensed under the GNU GPL version 3 or later | |
| … | … | ||
| 13 | 13 | "Major mode for Processing. | |
| 14 | 14 | \\{java-mode-map}") | |
| 15 | 15 | ||
| 16 | (defvar processing-location nil | ||
| 17 | "The directory where Processing can be found. Assumes you have | ||
| 18 | downloaded the standalone package.") | ||
| 19 | |||
| 20 | (defconst processing-platform | ||
| 21 | (cond ((string= system-type "gnu/linux") | ||
| 22 | "linux") | ||
| 23 | ((or (string= system-type "darwin") (string= system-type "macos")) | ||
| 24 | "macosx") | ||
| 25 | ((or (string= system-type "ms-dos") (string= system-type "windows-nt") | ||
| 26 | (string= system-type "cygwin")) | ||
| 27 | "windows")) | ||
| 28 | "The platform that Processing is running on. It can be `linux', `macosx' or `windows'.") | ||
| 29 | |||
| 30 | ;; Functions | ||
| 31 | (defun concat-with-delim (delim &rest strings) | ||
| 32 | "Returns a string that is the concatenation of all ``strings'' | ||
| 33 | separated by the delimiter ``delim''. | ||
| 34 | For example, | ||
| 35 | (concat-with-delim \".\" \"hello\" \"world\") | ||
| 36 | returns | ||
| 37 | \"hello.world\" | ||
| 38 | " | ||
| 39 | (reduce (lambda (x y) (concat x delim y)) strings)) | ||
| 40 | |||
| 41 | (defun make-java-classpath (&rest args) | ||
| 42 | (apply 'concat-with-delim ":" args)) | ||
| 43 | |||
| 44 | (defun processing-commander (sketch-dir output-dir cmd &optional platform) | ||
| 45 | "Runs the Processing compiler targetting the sketch files found | ||
| 46 | in ``sketch-dir'', with the output being stored in | ||
| 47 | ``output-dir''. The command flag that is executed on the sketch | ||
| 48 | depends on the type of ``cmd''. Valid types of commands are: | ||
| 49 | - \"preprocess\" | ||
| 50 | - \"build\" | ||
| 51 | - \"run\" | ||
| 52 | - \"present\" | ||
| 53 | - \"export-applet\" | ||
| 54 | - \"export-application\" | ||
| 55 | |||
| 56 | When ``cmd'' is set to \"export-application\", the ``platform'' | ||
| 57 | must be set to one of \"windows\", \"macosx\", or \"linux\". If | ||
| 58 | no platform is selected, the default platform that Emacs is | ||
| 59 | running on will be selected." | ||
| 60 | (cd (expand-file-name processing-location)) | ||
| 61 | (compile (concat "./java/bin/java -classpath \"" | ||
| 62 | (apply 'make-java-classpath | ||
| 63 | '("./java/lib/rt.jar" | ||
| 64 | "./java/lib/tools.jar" | ||
| 65 | "./lib/antlr.jar" "./lib/core.jar" | ||
| 66 | "./lib/ecj.jar" "./lib/jna.jar" | ||
| 67 | "./lib/pde.jar")) | ||
| 68 | "\" processing.app.Commander" | ||
| 69 | " --sketch=" (expand-file-name sketch-dir) | ||
| 70 | " --output=" (expand-file-name output-dir) | ||
| 71 | " --" cmd | ||
| 72 | (if (string= cmd "export-application") | ||
| 73 | (concat " --platform=" | ||
| 74 | (if platform platform (processing-platform))))))) | ||
| 75 | |||
| 76 | (defun processing-preprocess-sketch () | ||
| 77 | "Preprocess a sketch into .java files." | ||
| 78 | ;(processing-commander "~/sketchbook/test" "~/sketchbook/test/output" "run") | ||
| 79 | t) | ||
| 80 | |||
| 81 | (defun processing-build-sketch () | ||
| 82 | "Preprocess and compile a sketch into .class files." | ||
| 83 | t) | ||
| 84 | |||
| 85 | (defun processing-run-sketch () | ||
| 86 | "Preprocess, compile, and run a Processing sketch." | ||
| 87 | t) | ||
| 88 | |||
| 89 | (defun processing-present-sketch () | ||
| 90 | "Preprocess, compile, and run a Processing sketch full screen." | ||
| 91 | t) | ||
| 92 | |||
| 93 | (defun processing-export-applet () | ||
| 94 | "Turns the Processing sketch into a Java applet." | ||
| 95 | t) | ||
| 96 | |||
| 97 | (defun processing-export-application () | ||
| 98 | "Turns the Processing sketch into a Java application. Assumes | ||
| 99 | that the platform target is whatever platform Emacs is running | ||
| 100 | on." | ||
| 101 | t) | ||
| 102 | |||
| 103 | ;; Key bindings | ||
| 104 | (define-key processing-mode-map | ||
| 105 | [C-c C-r] 'processing-run-sketch) | ||
| 106 | |||
| 107 | ;; Font-lock, keywords | ||
| 16 | 108 | (defconst processing-font-lock-keywords-1 | |
| 17 | 109 | (eval-when-compile | |
| 18 | 110 | `(;; Shape functions | |
| … | … | ||
| 135 | 135 | "Default expressions to highlight in Processing mode.") | |
| 136 | 136 | ||
| 137 | 137 | ;; YASnippets | |
| 138 | (if (fboundp 'yas/define-snippets) | ||
| 139 | (yas/define-snippets | ||
| 140 | 'processing-mode | ||
| 141 | '( | ||
| 142 | ;; (key template name condition) | ||
| 143 | ("tri" "triangle(${x1}, ${y1}, ${x2}, ${y2}, ${x3}, ${y3});" | ||
| 144 | "triangle" nil) | ||
| 145 | ("l(" "line(${x1}, ${y1}, ${x2}, ${y2});" "line 2d" nil) | ||
| 146 | ("l(.3d" "line(${x1}, ${y1}, ${z1}, ${x2}, ${y2}, ${z2});" "line 3d" nil) | ||
| 147 | ("arc" "arc(${x}, ${y}, ${width}, ${height}, ${start}, ${stop});" "arc" nil) | ||
| 148 | ("p(" "point(${x}, ${y});" "point 2d" nil) | ||
| 149 | ("p(.3d" "point(${x}, ${y}, ${z});" "point 3d" nil) | ||
| 150 | ("quad" "quad(${x1}, ${y1}, ${x2}, ${y2}, ${x3}, ${y3}, ${x4}, ${y4});" | ||
| 151 | "quad" nil) | ||
| 152 | ("ell" "ellipse(${x}, ${y}, ${width}, ${height});" "ellipse" nil) | ||
| 153 | ("rect" "rect(${x}, ${y}, ${width}, ${height});" "rect" nil) | ||
| 154 | |||
| 155 | ;; Color | ||
| 138 | (if (fboundp 'yas/minor-mode) | ||
| 139 | (progn | ||
| 140 | (require 'yasnippet) | ||
| 141 | (message "processing-mode: defining YASnippets") | ||
| 142 | (yas/define-snippets | ||
| 143 | 'processing-mode | ||
| 144 | '( | ||
| 145 | ;; (key template name condition) | ||
| 146 | ("tri" "triangle(${x1}, ${y1}, ${x2}, ${y2}, ${x3}, ${y3});" | ||
| 147 | "triangle" nil) | ||
| 148 | ("l(" "line(${x1}, ${y1}, ${x2}, ${y2});" "line 2d" nil) | ||
| 149 | ("l(.3d" "line(${x1}, ${y1}, ${z1}, ${x2}, ${y2}, ${z2});" "line 3d" nil) | ||
| 150 | ("arc" "arc(${x}, ${y}, ${width}, ${height}, ${start}, ${stop});" "arc" nil) | ||
| 151 | ("p(" "point(${x}, ${y});" "point 2d" nil) | ||
| 152 | ("p(.3d" "point(${x}, ${y}, ${z});" "point 3d" nil) | ||
| 153 | ("quad" "quad(${x1}, ${y1}, ${x2}, ${y2}, ${x3}, ${y3}, ${x4}, ${y4});" | ||
| 154 | "quad" nil) | ||
| 155 | ("ell" "ellipse(${x}, ${y}, ${width}, ${height});" "ellipse" nil) | ||
| 156 | ("rect" "rect(${x}, ${y}, ${width}, ${height});" "rect" nil) | ||
| 157 | |||
| 158 | ;; Color | ||
| 156 | 159 | ;;; Setting | |
| 157 | ("background" "background(${gray_or_color_or_hex});" "background .." nil) | ||
| 158 | ("background.ca" "background(${gray_or_color_or_hex}, ${alpha});" | ||
| 159 | "background .. alpha" nil) | ||
| 160 | ("background.rgb" "background(${red}, ${green}, ${blue});" "background RGB" nil) | ||
| 161 | ("background.rgba" "background(${red}, ${green}, ${blue}, ${alpha});" | ||
| 162 | "background RGBA" nil) | ||
| 163 | ("colorm" "colorMode(${RGB_or_HSV});" "color mode" nil) | ||
| 164 | ("colorm.r" "colorMode(${RGB_or_HSV}, ${range});" "color mode range" nil) | ||
| 165 | ("colorm.rgb" "colorMode(${RGB_or_HSV}, ${range1}, ${range2}, ${range3});" | ||
| 166 | "color mode RGB/HSV range" nil) | ||
| 167 | ("colorm.rgba" "colorMode(${RGB_or_HSV}, ${range1}, ${range2}, ${range3}, ${range4});" | ||
| 168 | "color mode RGB/HSV, A range" nil) | ||
| 169 | ("stroke" "stroke(${gray_or_color_or_hex});" "stroke .." nil) | ||
| 170 | ("stroke.ca" "stroke(${gray_or_color_or_hex}, ${alpha});" "stroke .. alpha" nil) | ||
| 171 | ("stroke.rgb" "stroke(${red}, ${green}, ${blue});" "stroke RGB" nil) | ||
| 172 | ("stroke.rgba" "stroke(${red}, ${green}, ${blue}, ${alpha});" "stroke RGBA" nil) | ||
| 173 | ("fill" "fill(${gray_or_color_or_hex});" "fill .." nil) | ||
| 174 | ("fill.ca" "fill(${gray_or_color_or_hex}, ${alpha});" "fill .. alpha" nil) | ||
| 175 | ("fill.rgb" "fill(${red}, ${green}, ${blue});" "fill RGB" nil) | ||
| 176 | ("fill.rgba" "fill(${red}, ${green}, ${blue}, ${alpha});" "fill RGBA" nil) | ||
| 177 | ) | ||
| 178 | 'java-mode) | ||
| 179 | (message "YASnippets not installed. Not defining any processing-mode snippets.")) | ||
| 160 | ("background" "background(${gray_or_color_or_hex});" "background .." nil) | ||
| 161 | ("background.ca" "background(${gray_or_color_or_hex}, ${alpha});" | ||
| 162 | "background .. alpha" nil) | ||
| 163 | ("background.rgb" "background(${red}, ${green}, ${blue});" "background RGB" nil) | ||
| 164 | ("background.rgba" "background(${red}, ${green}, ${blue}, ${alpha});" | ||
| 165 | "background RGBA" nil) | ||
| 166 | ("colorm" "colorMode(${RGB_or_HSV});" "color mode" nil) | ||
| 167 | ("colorm.r" "colorMode(${RGB_or_HSV}, ${range});" "color mode range" nil) | ||
| 168 | ("colorm.rgb" "colorMode(${RGB_or_HSV}, ${range1}, ${range2}, ${range3});" | ||
| 169 | "color mode RGB/HSV range" nil) | ||
| 170 | ("colorm.rgba" "colorMode(${RGB_or_HSV}, ${range1}, ${range2}, ${range3}, ${range4});" | ||
| 171 | "color mode RGB/HSV, A range" nil) | ||
| 172 | ("stroke" "stroke(${gray_or_color_or_hex});" "stroke .." nil) | ||
| 173 | ("stroke.ca" "stroke(${gray_or_color_or_hex}, ${alpha});" "stroke .. alpha" nil) | ||
| 174 | ("stroke.rgb" "stroke(${red}, ${green}, ${blue});" "stroke RGB" nil) | ||
| 175 | ("stroke.rgba" "stroke(${red}, ${green}, ${blue}, ${alpha});" "stroke RGBA" nil) | ||
| 176 | ("fill" "fill(${gray_or_color_or_hex});" "fill .." nil) | ||
| 177 | ("fill.ca" "fill(${gray_or_color_or_hex}, ${alpha});" "fill .. alpha" nil) | ||
| 178 | ("fill.rgb" "fill(${red}, ${green}, ${blue});" "fill RGB" nil) | ||
| 179 | ("fill.rgba" "fill(${red}, ${green}, ${blue}, ${alpha});" "fill RGBA" nil) | ||
| 180 | ) | ||
| 181 | 'java-mode) | ||
| 182 | t) | ||
| 183 | (progn | ||
| 184 | (message "processing-mode: YASnippets not installed. Not defining any snippets.") | ||
| 185 | nil)) |

