Processing in Emacs & other text editors

Hi all,

I don't think that a lot of Processing users are fans of command line and old school editors such as Emacs. Some of us are.

Here is how to do so.

In most linux distributions, you can do this : 

# create a bin dir in your home :  
  mkdir ~/bin 
  # link to processing binaries 
  cd ~/bin 
  ln -s $HOME/processing-2.2.1/processing . 
  ln -s $HOME/processing-2.2.1/processing-java . 

Obviously replace /processing-2.2.1 by the folder where Processing is installed

Another solution if you have root access :

# ln -s /home/tux/processing-2.2.1/processing-java /usr/local/bin/processing-java 

On windows you can do the same, look over the internet, here is a link

Once it is done you have access to processing-java from the command-line.

Then to compile you could place the Makefile below in your sketch folder.

PROCESSING_JAVA=processing-java    ## You could replace processing-java by /home/toto/processing-2.2.1/processing-java
SKETCH_NAME=$(shell pwd)
COMPILE_OPTIONS=  --force --run

all: sketch

sketch: 
    ${PROCESSING_JAVA} --sketch=${SKETCH_NAME} --output=${SKETCH_NAME}/build ${COMPILE_OPTIONS}

Instead of have the same Makefile in every folder, you could run the sketch with an emacs command ! I got quite lucky for this one as I have a .emacs that is 8 years old and full of old scripts. I changed one to work with Processing. So, you need to add this to your .emacs : 

(defun run-current-file ()
  "Execute the current with Processing-java
If the file is modified, ask if you want to save first."
  (interactive)
  (let* (
         (suffixMap
          `(
            ("pde" . "processing-java")
            )
          )
         (fName (buffer-file-name))
         (fSuffix (file-name-extension fName))
         (progName (cdr (assoc fSuffix suffixMap)))
     (compileOptions "--force --run")
     (folderName (file-name-directory (or load-file-name buffer-file-name)))
         (compileStr (concat progName " --sketch=" folderName " --output=" folderName "build " compileOptions))
         )

    (when (buffer-modified-p)
      (when (y-or-n-p "Buffer modified. Do you want to save first?")
          (save-buffer) ) )

    (if progName
    (progn
      (message "Running…")
      (compile compileStr)
      )
      (message "No recognized program file suffix for this file.")
          ) ) )

;; You can even set this to a key ... 
(global-set-key [f6]     'run-current-file)

If an emacs-lisp guru passes by you can improve it. My fingers and brain hurts every time I write Lisp code. * update Aug, 20, 2015

Sign In or Register to comment.