├── .gitignore ├── .travis.yml ├── Cask └── arduino-mode.el /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled 2 | *.elc 3 | 4 | # Packaging 5 | .cask 6 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: emacs-lisp 2 | env: 3 | - EVM_EMACS=emacs-24.3-travis 4 | - EVM_EMACS=emacs-24.4-travis 5 | - EVM_EMACS=emacs-24.5-travis 6 | before_install: 7 | - export PATH="$HOME/.cask/bin:$HOME/.evm/bin:$PATH" 8 | - git clone https://github.com/rejeep/evm.git $HOME/.evm 9 | - evm config path /tmp 10 | - evm install $EVM_EMACS --use --skip 11 | - git clone https://github.com/cask/cask.git $HOME/.cask 12 | install: 13 | - cask install 14 | script: 15 | - emacs --version 16 | - cask build 17 | -------------------------------------------------------------------------------- /Cask: -------------------------------------------------------------------------------- 1 | (source gnu) 2 | (source melpa) 3 | -------------------------------------------------------------------------------- /arduino-mode.el: -------------------------------------------------------------------------------- 1 | ;;; Arduino-mode.el --- Major mode for the Arduino language 2 | 3 | ;; Copyright (C) 2008 Christopher Grim 4 | 5 | ;; Author: Christopher Grim 6 | ;; Keywords: languages, arduino 7 | ;; Version: 1.0 8 | 9 | ;; This file is free software; you can redistribute it and/or modify 10 | ;; it under the terms of the GNU General Public License as published by 11 | ;; the Free Software Foundation; either version 3, or (at your option) 12 | ;; any later version. 13 | 14 | ;; This file is distributed in the hope that it will be useful, 15 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | ;; GNU General Public License for more details. 18 | 19 | ;; You should have received a copy of the GNU General Public License 20 | ;; along with GNU Emacs; see the file COPYING. If not, write to 21 | ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 22 | ;; Boston, MA 02110-1301, USA. 23 | 24 | ;;; Commentary: 25 | ;; 26 | ;; Based on derived-mode-ex.el found here: 27 | ;; 28 | ;; . 29 | ;; 30 | 31 | ;;; Code: 32 | (require 'cc-mode) 33 | 34 | (eval-when-compile 35 | (require 'cl) 36 | (require 'cc-langs) 37 | (require 'cc-fonts) 38 | (require 'cc-menus)) 39 | 40 | (eval-and-compile 41 | ;; fall back on c-mode 42 | (c-add-language 'arduino-mode 'c-mode)) 43 | 44 | (c-lang-defconst c-primitive-type-kwds 45 | arduino (append '("boolean" "byte") 46 | (c-lang-const c-primitive-type-kwds))) 47 | 48 | (c-lang-defconst c-constant-kwds 49 | arduino (append 50 | '("HIGH" "LOW" 51 | "INPUT" "OUTPUT" "INPUT_PULLUP" 52 | "LED_BUILTIN" 53 | "true" "false") 54 | (c-lang-const c-constant-kwds))) 55 | 56 | (c-lang-defconst c-simple-stmt-kwds 57 | arduino (append 58 | '(;; Digital I/O 59 | "pinMode" 60 | "digitalWrite" 61 | "digitalRead" 62 | ;; Analog I/O 63 | "analogReference" 64 | "analogRead" 65 | "analogWrite" 66 | ;; Due only 67 | "analogReadResolution" 68 | "analogWriteResolution" 69 | ;; Advanced I/O 70 | "tone" 71 | "noTone" 72 | "shiftOut" 73 | "shiftIn" 74 | "pulseIn" 75 | ;; Time 76 | "millis" 77 | "micros" 78 | "delay" 79 | "delayMicroseconds" 80 | ;; Math 81 | "min" 82 | "max" 83 | "abs" 84 | "constrain" 85 | "map" 86 | "pow" 87 | "sqrt" 88 | ;; Trigonometry 89 | "sin" 90 | "cos" 91 | "tan" 92 | ;; Random Numbers 93 | "randomSeed" 94 | "random" 95 | ;; Bits and Bytes 96 | "lowByte" 97 | "highByte" 98 | "bitRead" 99 | "bitWrite" 100 | "bitSet" 101 | "bitClear" 102 | "bit" 103 | ;; External Interrupts 104 | "attachInterrupt" 105 | "detachInterrupt" 106 | ;; Interrupts 107 | "interrupts" 108 | "noInterrupts") 109 | (c-lang-const c-simple-stmt-kwds))) 110 | 111 | (c-lang-defconst c-primary-expr-kwds 112 | arduino (append 113 | '(;; Communication 114 | "Serial" 115 | ;; USB (Leonoardo based boards and Due only) 116 | "Keyboard" 117 | "Mouse") 118 | (c-lang-const c-primary-expr-kwds))) 119 | 120 | (defgroup arduino nil "Arduino mode customizations" 121 | :group 'languages) 122 | 123 | (defcustom arduino-font-lock-extra-types nil 124 | "*List of extra types (aside from the type keywords) to recognize in Arduino mode. 125 | Each list item should be a regexp matching a single identifier." :group 'arduino) 126 | 127 | (defcustom arduino-executable "arduino" 128 | "*The arduino executable" 129 | :group 'arduino 130 | :type 'string) 131 | 132 | (defconst arduino-font-lock-keywords-1 (c-lang-const c-matchers-1 arduino) 133 | "Minimal highlighting for Arduino mode.") 134 | 135 | (defconst arduino-font-lock-keywords-2 (c-lang-const c-matchers-2 arduino) 136 | "Fast normal highlighting for Arduino mode.") 137 | 138 | (defconst arduino-font-lock-keywords-3 (c-lang-const c-matchers-3 arduino) 139 | "Accurate normal highlighting for Arduino mode.") 140 | 141 | (defvar arduino-font-lock-keywords arduino-font-lock-keywords-3 142 | "Default expressions to highlight in ARDUINO mode.") 143 | 144 | (defvar arduino-mode-syntax-table nil 145 | "Syntax table used in arduino-mode buffers.") 146 | (or arduino-mode-syntax-table 147 | (setq arduino-mode-syntax-table 148 | (funcall (c-lang-const c-make-mode-syntax-table arduino)))) 149 | 150 | (defvar arduino-mode-abbrev-table nil 151 | "Abbreviation table used in arduino-mode buffers.") 152 | 153 | (c-define-abbrev-table 'arduino-mode-abbrev-table 154 | ;; Keywords that if they occur first on a line might alter the 155 | ;; syntactic context, and which therefore should trigger 156 | ;; reindentation when they are completed. 157 | '(("else" "else" c-electric-continued-statement 0) 158 | ("while" "while" c-electric-continued-statement 0))) 159 | 160 | (defvar arduino-mode-map 161 | (let ((map (c-make-inherited-keymap))) 162 | ;; Add bindings which are only useful for Arduino 163 | map) 164 | "Keymap used in arduino-mode buffers.") 165 | 166 | (easy-menu-define arduino-menu arduino-mode-map "Arduino Mode Commands" 167 | (cons "Arduino" (c-lang-const c-mode-menu arduino))) 168 | 169 | ;;;###autoload 170 | (add-to-list 'auto-mode-alist '("\\.pde\\'" . arduino-mode)) 171 | ;;;###autoload 172 | (add-to-list 'auto-mode-alist '("\\.ino\\'" . arduino-mode)) 173 | 174 | ;;;###autoload 175 | (defun arduino-mode () 176 | "Major mode for editing Arduino code. 177 | 178 | The hook `c-mode-common-hook' is run with no args at mode 179 | initialization, then `arduino-mode-hook'. 180 | 181 | Key bindings: 182 | \\{arduino-mode-map}" 183 | (interactive) 184 | (kill-all-local-variables) 185 | (c-initialize-cc-mode t) 186 | (set-syntax-table arduino-mode-syntax-table) 187 | (setq major-mode 'arduino-mode 188 | mode-name "Arduino" 189 | local-abbrev-table arduino-mode-abbrev-table 190 | abbrev-mode t 191 | imenu-generic-expression cc-imenu-c-generic-expression) 192 | (use-local-map c-mode-map) 193 | ;; `c-init-language-vars' is a macro that is expanded at compile 194 | ;; time to a large `setq' with all the language variables and their 195 | ;; customized values for our language. 196 | (c-init-language-vars arduino-mode) 197 | ;; `c-common-init' initializes most of the components of a CC Mode 198 | ;; buffer, including setup of the mode menu, font-lock, etc. 199 | ;; There's also a lower level routine `c-basic-common-init' that 200 | ;; only makes the necessary initialization to get the syntactic 201 | ;; analysis and similar things working. 202 | (c-common-init 'arduino-mode) 203 | (easy-menu-add arduino-menu) 204 | (run-hooks 'c-mode-common-hook) 205 | (run-hooks 'arduino-mode-hook) 206 | (c-update-modeline)) 207 | 208 | (defun arduino-run-arduino () 209 | (interactive) 210 | (start-file-process "arduino" () arduino-executable (buffer-file-name))) 211 | 212 | (provide 'arduino-mode) 213 | ;;; arduino-mode.el ends here 214 | --------------------------------------------------------------------------------