Commit 305478a27651ef522839b435c52786bb56d4f047
- Diff rendering mode:
- inline
- side by side
ChangeLog
(18 / 0)
|   | |||
| 1 | 2009-02-06 Rudolf Olah <omouse@gmail.com> | ||
| 2 | |||
| 3 | * processing-mode.el: Added proper licensing notice for GPLv3 to | ||
| 4 | top of file. Added a hook to for processing-mode that sets the | ||
| 5 | buffer-local compile-command. | ||
| 6 | (concat-with-delims): Removed function. Was only used in one | ||
| 7 | location. | ||
| 8 | (make-java-classpath): Replaced 'apply call to 'concat-with-delims | ||
| 9 | with a lambda version. Added a documentation string explaining the | ||
| 10 | function. | ||
| 11 | (make-java-classpath): The delimiter is now dependent on the | ||
| 12 | platform. Patch by kantide@yahoo.com. | ||
| 13 | (processing-make-compile-command): New function. Creates a | ||
| 14 | compile-command that's used in the processing-mode-hook. | ||
| 15 | (processing-commander): Relocated code for compile-command | ||
| 16 | construction. | ||
| 17 | |||
| 18 | * README: Added instructions on how to setup processing-mode.el |
processing-mode.el
(76 / 44)
|   | |||
| 5 | 5 | ;; Allows compilation of buffers and "sketches" from within Emacs but | |
| 6 | 6 | ;; only for more recent versions of Processing. | |
| 7 | 7 | ||
| 8 | ;; Copyright (C) 2008 Rudolf Olah <omouse@gmail.com> | ||
| 9 | ;; Licensed under the GNU GPL version 3 or later | ||
| 8 | ;; Copyright (C) 2008, 2009 Rudolf Olah <omouse@gmail.com> | ||
| 10 | 9 | ||
| 11 | (require 'compile) | ||
| 12 | (require 'cl) | ||
| 10 | ;; This program is free software: you can redistribute it and/or modify | ||
| 11 | ;; it under the terms of the GNU General Public License as published by | ||
| 12 | ;; the Free Software Foundation, either version 3 of the License, or | ||
| 13 | ;; (at your option) any later version. | ||
| 13 | 14 | ||
| 15 | ;; This program is distributed in the hope that it will be useful, | ||
| 16 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 17 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 18 | ;; GNU General Public License for more details. | ||
| 19 | |||
| 20 | ;; You should have received a copy of the GNU General Public License | ||
| 21 | ;; along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 22 | |||
| 23 | (eval-when-compile | ||
| 24 | (require 'compile) | ||
| 25 | (require 'cl)) | ||
| 26 | |||
| 14 | 27 | (define-derived-mode processing-mode | |
| 15 | 28 | java-mode "Processing" | |
| 16 | 29 | "Major mode for Processing. | |
| … | … | ||
| 44 | 44 | "The platform that Processing is running on. It can be `linux', `macosx' or `windows'.") | |
| 45 | 45 | ||
| 46 | 46 | ;; Functions | |
| 47 | (defun concat-with-delim (delim &rest strings) | ||
| 48 | "Returns a string that is the concatenation of all ``strings'' | ||
| 49 | separated by the delimiter ``delim''. | ||
| 50 | For example, | ||
| 51 | (concat-with-delim \".\" \"hello\" \"world\") | ||
| 52 | returns | ||
| 53 | \"hello.world\" | ||
| 54 | " | ||
| 55 | (reduce (lambda (x y) (concat x delim y)) strings)) | ||
| 56 | |||
| 57 | 47 | (defun make-java-classpath (&rest args) | |
| 58 | (apply 'concat-with-delim ":" args)) | ||
| 48 | "Returns a string that is a Java CLASSPATH. Each arg is a | ||
| 49 | folder containing .class files or a .jar. The delimiter is based | ||
| 50 | on the platform, with MS Windows using \";\", and other platforms | ||
| 51 | using \":\"." | ||
| 52 | (reduce (lambda (x y) (concat x (if (string= processing-platform "windows") ";" ":") | ||
| 53 | y)) | ||
| 54 | args)) | ||
| 59 | 55 | ||
| 60 | 56 | (defvar processing-import-libraries | |
| 61 | 57 | '((minim "jl1.0" "mp3spi1.9.4" "tritonus_share" "tritonus_aos" | |
| … | … | ||
| 62 | 62 | strings.") | |
| 63 | 63 | ||
| 64 | 64 | (defun processing-import-library (library-name) | |
| 65 | "Generates a STRING that is a Java classpath, delimited by | ||
| 66 | colons (\":\"). The paths are constructed from the REST of the | ||
| 67 | library found in the alist ``processing-import-libraries''. The | ||
| 68 | suffix \".jar\" is added to each string." | ||
| 65 | "Generates a STRING that is a Java classpath. The paths are | ||
| 66 | constructed from the REST of the library found in the alist | ||
| 67 | ``processing-import-libraries''. The suffix \".jar\" is added to | ||
| 68 | each string." | ||
| 69 | 69 | (make-java-classpath (mapcar (lambda (x) (expand-file-name (concat processing-location | |
| 70 | 70 | "libraries/" | |
| 71 | 71 | (symbol-name library-name) | |
| … | … | ||
| 99 | 99 | (kill-buffer temp-buf))) | |
| 100 | 100 | nil))) | |
| 101 | 101 | ||
| 102 | (defun processing-commander (sketch-dir output-dir cmd &optional platform) | ||
| 103 | "Runs the Processing compiler targetting the sketch files found | ||
| 104 | in ``sketch-dir'', with the output being stored in | ||
| 105 | ``output-dir''. The command flag that is executed on the sketch | ||
| 106 | depends on the type of ``cmd''. Valid types of commands are: | ||
| 102 | (defun processing-make-compile-command (sketch-dir output-dir cmd &optional platform) | ||
| 103 | "Returns a string which is the compile-command for Processing | ||
| 104 | sketches, targetting the sketch files found in ``sketch-dir'', | ||
| 105 | with the output being stored in ``output-dir''. The command flag | ||
| 106 | that is executed on the sketch depends on the type of ``cmd''. | ||
| 107 | |||
| 108 | Valid types of commands are: | ||
| 109 | |||
| 107 | 110 | - \"preprocess\" | |
| 108 | 111 | - \"build\" | |
| 109 | 112 | - \"run\" | |
| … | … | ||
| 118 | 118 | must be set to one of \"windows\", \"macosx\", or \"linux\". If | |
| 119 | 119 | no platform is selected, the default platform that Emacs is | |
| 120 | 120 | running on will be selected." | |
| 121 | (concat processing-location "java/bin/java -classpath \"" | ||
| 122 | (apply 'make-java-classpath | ||
| 123 | (mapcar (lambda (x) (expand-file-name (concat processing-location x))) | ||
| 124 | '("java/lib/rt.jar" | ||
| 125 | "java/lib/tools.jar" | ||
| 126 | "lib/antlr.jar" "lib/core.jar" | ||
| 127 | "lib/ecj.jar" "lib/jna.jar" | ||
| 128 | "lib/pde.jar"))) | ||
| 129 | "\" processing.app.Commander" | ||
| 130 | " --sketch=\"" (expand-file-name sketch-dir) | ||
| 131 | "\" --output=\"" (expand-file-name output-dir) | ||
| 132 | ;; Remove this comment when Processing implements the --preferences=??? command-line option. | ||
| 133 | ;;"\" --preferences=\"" (expand-file-name "~/.processing/preferences.txt") | ||
| 134 | "\" --" cmd | ||
| 135 | (if (string= cmd "export-application") | ||
| 136 | (concat " --platform=" | ||
| 137 | (if platform platform (processing-platform)))))) | ||
| 138 | |||
| 139 | (defun processing-commander (sketch-dir output-dir cmd &optional platform) | ||
| 140 | "Runs the Processing compiler, using a compile-command | ||
| 141 | constructed using the ``processing-make-compile-command'' | ||
| 142 | function." | ||
| 121 | 143 | (let ((compilation-error-regexp-alist '(processing))) | |
| 122 | (compile (concat processing-location "java/bin/java -classpath \"" | ||
| 123 | (apply 'make-java-classpath | ||
| 124 | (mapcar (lambda (x) (expand-file-name (concat processing-location x))) | ||
| 125 | '("java/lib/rt.jar" | ||
| 126 | "java/lib/tools.jar" | ||
| 127 | "lib/antlr.jar" "lib/core.jar" | ||
| 128 | "lib/ecj.jar" "lib/jna.jar" | ||
| 129 | "lib/pde.jar"))) | ||
| 130 | "\" processing.app.Commander" | ||
| 131 | " --sketch=\"" (expand-file-name sketch-dir) | ||
| 132 | "\" --output=\"" (expand-file-name output-dir) | ||
| 133 | ;; Remove this comment when Processing implements the --preferences=??? command-line option. | ||
| 134 | ;;"\" --preferences=\"" (expand-file-name "~/.processing/preferences.txt") | ||
| 135 | "\" --" cmd | ||
| 136 | (if (string= cmd "export-application") | ||
| 137 | (concat " --platform=" | ||
| 138 | (if platform platform (processing-platform)))))))) | ||
| 144 | (compile (processing-make-compile-command sketch-dir output-dir cmd platform)))) | ||
| 139 | 145 | ||
| 140 | 146 | (defun processing-sketch-compile (&optional cmd) | |
| 141 | 147 | "Runs the Processing Commander application with the current | |
| … | … | ||
| 157 | 157 | (processing-sketch-compile "present")) | |
| 158 | 158 | ||
| 159 | 159 | (defun processing-sketch-build () | |
| 160 | "Runs the build command for a Processing sketch. Processing | ||
| 161 | will process the sketch into .java files and then compile them | ||
| 162 | into .class files." | ||
| 160 | 163 | (interactive) | |
| 161 | 164 | (processing-sketch-compile "build")) | |
| 162 | 165 | ||
| … | … | ||
| 169 | 169 | on." | |
| 170 | 170 | t) | |
| 171 | 171 | ||
| 172 | ;; Add hook so that when processing-mode is loaded, the local variable | ||
| 173 | ;; 'compile-command is set. | ||
| 174 | (add-hook 'processing-mode-hook | ||
| 175 | (lambda () | ||
| 176 | (let ((sketch-dir (file-name-directory buffer-file-name))) | ||
| 177 | (set (make-local-variable 'compile-command) | ||
| 178 | (processing-make-compile-command sketch-dir | ||
| 179 | (concat sketch-dir "output") | ||
| 180 | "build"))))) | ||
| 181 | |||
| 172 | 182 | ;; Key bindings | |
| 173 | 183 | (define-key processing-mode-map "\C-c\C-r" 'processing-sketch-compile) | |
| 174 | 184 | (define-key processing-mode-map "\C-c\C-p" 'processing-sketch-present) | |
| … | … | ||
| 195 | 195 | ;; Font-lock, keywords | |
| 196 | 196 | (defconst processing-font-lock-keywords-1 | |
| 197 | 197 | (eval-when-compile | |
| 198 | `(;; Shape functions | ||
| 198 | `( ;; Shape functions | ||
| 199 | 199 | (,(concat | |
| 200 | 200 | (regexp-opt '("triangle" "line" "arc" "point" "quad" "ellipse" | |
| 201 | 201 | "rect" "curve" "bezier") | |
| … | … | ||
| 243 | 243 | ("ell" "ellipse(${x}, ${y}, ${width}, ${height});" "ellipse" nil) | |
| 244 | 244 | ("rect" "rect(${x}, ${y}, ${width}, ${height});" "rect" nil) | |
| 245 | 245 | ||
| 246 | ;; Color | ||
| 247 | ;;; Setting | ||
| 246 | ;; Color Setting | ||
| 248 | 247 | ("background" "background(${gray_or_color_or_hex});" "background .." nil) | |
| 249 | 248 | ("background.ca" "background(${gray_or_color_or_hex}, ${alpha});" | |
| 250 | 249 | "background .. alpha" nil) | |
| … | … | ||
| 270 | 270 | (progn | |
| 271 | 271 | (message "processing-mode: YASnippets not installed. Not defining any snippets.") | |
| 272 | 272 | nil)) | |
| 273 | |||
| 274 | (provide 'processing-mode) |

