summaryrefslogtreecommitdiff
path: root/.emacs.d/lisp/yaml-mode.el
diff options
context:
space:
mode:
authorSimeon Simeonov2016-03-03 10:45:20 +0100
committerSimeon Simeonov2016-03-03 10:45:20 +0100
commita6a2922c75fa06fb2496d2ba59520a121205fd26 (patch)
tree88216e56eef5574249eb7debdfadf4cf494d3947 /.emacs.d/lisp/yaml-mode.el
parent481decd28b7940d1dae11fd0ff2dc06143c46ee8 (diff)
Handle .ino files with c++-mode. Upgrade yasnippet and yaml.
Diffstat (limited to '.emacs.d/lisp/yaml-mode.el')
-rw-r--r--.emacs.d/lisp/yaml-mode.el115
1 files changed, 48 insertions, 67 deletions
diff --git a/.emacs.d/lisp/yaml-mode.el b/.emacs.d/lisp/yaml-mode.el
index b932576..39c0e57 100644
--- a/.emacs.d/lisp/yaml-mode.el
+++ b/.emacs.d/lisp/yaml-mode.el
@@ -183,35 +183,33 @@ that key is pressed to begin a block literal."
183 183
184;; Mode setup 184;; Mode setup
185 185
186(defvar yaml-mode-map () 186(defvar yaml-mode-map
187 (let ((map (make-sparse-keymap)))
188 (define-key map "|" 'yaml-electric-bar-and-angle)
189 (define-key map ">" 'yaml-electric-bar-and-angle)
190 (define-key map "-" 'yaml-electric-dash-and-dot)
191 (define-key map "." 'yaml-electric-dash-and-dot)
192 (define-key map [backspace] 'yaml-electric-backspace)
193 map)
187 "Keymap used in `yaml-mode' buffers.") 194 "Keymap used in `yaml-mode' buffers.")
188(if yaml-mode-map
189 nil
190 (setq yaml-mode-map (make-sparse-keymap))
191 (define-key yaml-mode-map "|" 'yaml-electric-bar-and-angle)
192 (define-key yaml-mode-map ">" 'yaml-electric-bar-and-angle)
193 (define-key yaml-mode-map "-" 'yaml-electric-dash-and-dot)
194 (define-key yaml-mode-map "." 'yaml-electric-dash-and-dot)
195 (define-key yaml-mode-map [backspace] 'yaml-electric-backspace))
196 195
197(defvar yaml-mode-syntax-table nil 196(defvar yaml-mode-syntax-table
197 (let ((syntax-table (make-syntax-table)))
198 (modify-syntax-entry ?\' "\"" syntax-table)
199 (modify-syntax-entry ?\" "\"" syntax-table)
200 (modify-syntax-entry ?# "<" syntax-table)
201 (modify-syntax-entry ?\n ">" syntax-table)
202 (modify-syntax-entry ?\\ "\\" syntax-table)
203 (modify-syntax-entry ?- "w" syntax-table)
204 (modify-syntax-entry ?_ "_" syntax-table)
205 (modify-syntax-entry ?\( "." syntax-table)
206 (modify-syntax-entry ?\) "." syntax-table)
207 (modify-syntax-entry ?\{ "(}" syntax-table)
208 (modify-syntax-entry ?\} "){" syntax-table)
209 (modify-syntax-entry ?\[ "(]" syntax-table)
210 (modify-syntax-entry ?\] ")[" syntax-table)
211 syntax-table)
198 "Syntax table in use in `yaml-mode' buffers.") 212 "Syntax table in use in `yaml-mode' buffers.")
199(if yaml-mode-syntax-table
200 nil
201 (setq yaml-mode-syntax-table (make-syntax-table))
202 (modify-syntax-entry ?\' "\"" yaml-mode-syntax-table)
203 (modify-syntax-entry ?\" "\"" yaml-mode-syntax-table)
204 (modify-syntax-entry ?# "<" yaml-mode-syntax-table)
205 (modify-syntax-entry ?\n ">" yaml-mode-syntax-table)
206 (modify-syntax-entry ?\\ "\\" yaml-mode-syntax-table)
207 (modify-syntax-entry ?- "w" yaml-mode-syntax-table)
208 (modify-syntax-entry ?_ "_" yaml-mode-syntax-table)
209 (modify-syntax-entry ?\( "." yaml-mode-syntax-table)
210 (modify-syntax-entry ?\) "." yaml-mode-syntax-table)
211 (modify-syntax-entry ?\{ "(}" yaml-mode-syntax-table)
212 (modify-syntax-entry ?\} "){" yaml-mode-syntax-table)
213 (modify-syntax-entry ?\[ "(]" yaml-mode-syntax-table)
214 (modify-syntax-entry ?\] ")[" yaml-mode-syntax-table))
215 213
216;;;###autoload 214;;;###autoload
217(define-derived-mode yaml-mode text-mode "YAML" 215(define-derived-mode yaml-mode text-mode "YAML"
@@ -224,34 +222,37 @@ that key is pressed to begin a block literal."
224 (set (make-local-variable 'indent-line-function) 'yaml-indent-line) 222 (set (make-local-variable 'indent-line-function) 'yaml-indent-line)
225 (set (make-local-variable 'indent-tabs-mode) nil) 223 (set (make-local-variable 'indent-tabs-mode) nil)
226 (set (make-local-variable 'fill-paragraph-function) 'yaml-fill-paragraph) 224 (set (make-local-variable 'fill-paragraph-function) 'yaml-fill-paragraph)
227 (set (make-local-variable 'font-lock-defaults) 225
228 '(yaml-font-lock-keywords 226 (set (make-local-variable 'syntax-propertize-function)
229 nil nil nil nil 227 'yaml-mode-syntax-propertize-function)
230 (font-lock-syntactic-keywords . yaml-font-lock-syntactic-keywords))) 228 (setq font-lock-defaults '(yaml-font-lock-keywords)))
231 (if (fboundp 'font-lock-flush)
232 (font-lock-flush)
233 (with-no-warnings
234 (font-lock-fontify-buffer))))
235 229
236 230
237;; Font-lock support 231;; Font-lock support
238 232
239(defvar yaml-font-lock-keywords 233(defvar yaml-font-lock-keywords
240 (list 234 `((,yaml-constant-scalars-re . (1 font-lock-constant-face))
241 (cons yaml-constant-scalars-re '(1 font-lock-constant-face)) 235 (,yaml-tag-re . (0 font-lock-type-face))
242 (cons yaml-tag-re '(0 font-lock-type-face)) 236 (,yaml-node-anchor-alias-re . (0 font-lock-function-name-face))
243 (cons yaml-node-anchor-alias-re '(0 font-lock-function-name-face)) 237 (,yaml-hash-key-re . (1 font-lock-variable-name-face))
244 (cons yaml-hash-key-re '(1 font-lock-variable-name-face)) 238 (,yaml-document-delimiter-re . (0 font-lock-comment-face))
245 (cons yaml-document-delimiter-re '(0 font-lock-comment-face)) 239 (,yaml-directive-re . (1 font-lock-builtin-face))
246 (cons yaml-directive-re '(1 font-lock-builtin-face)) 240 (yaml-font-lock-block-literals 0 font-lock-string-face)
247 '(yaml-font-lock-block-literals 0 font-lock-string-face) 241 ("^[\t]+" 0 'yaml-tab-face t))
248 '("^[\t]+" 0 'yaml-tab-face t))
249 "Additional expressions to highlight in YAML mode.") 242 "Additional expressions to highlight in YAML mode.")
250 243
251(defvar yaml-font-lock-syntactic-keywords 244(defun yaml-mode-syntax-propertize-function (beg end)
252 (list '(yaml-syntactic-block-literals 0 ".")) 245 "Unhighlight foo#bar tokens between BEG and END."
253 "Additional syntax features to highlight in YAML mode.") 246 (save-excursion
254 247 (goto-char beg)
248 (while (search-forward "#" end t)
249 (save-excursion
250 (forward-char -1)
251 ;; both ^# and [ \t]# are comments
252 (when (and (not (bolp))
253 (not (memq (preceding-char) '(?\s ?\t))))
254 (put-text-property (point) (1+ (point))
255 'syntax-table (string-to-syntax "_")))))))
255 256
256(defun yaml-font-lock-block-literals (bound) 257(defun yaml-font-lock-block-literals (bound)
257 "Find lines within block literals. 258 "Find lines within block literals.
@@ -292,26 +293,6 @@ artificially limitted to the value of
292 bound t)) 293 bound t))
293 (set-match-data (nthcdr 2 (match-data))) t)))))) 294 (set-match-data (nthcdr 2 (match-data))) t))))))
294 295
295(defun yaml-syntactic-block-literals (bound)
296 "Find quote characters within block literals.
297Finds the first quote character within a block literal (if any) after
298point and prior to BOUND. Returns the position of the quote character
299in the match data, as consumed by matcher functions in
300`font-lock-syntactic-keywords'. This allows the mode to treat ['\"]
301characters in block literals as punctuation syntax instead of string
302syntax, preventing unmatched quotes in block literals from painting
303the entire buffer in `font-lock-string-face'."
304 (let ((found nil))
305 (while (and (not found)
306 (/= (point) bound)
307 (yaml-font-lock-block-literals bound))
308 (let ((begin (match-beginning 0)) (end (match-end 0)))
309 (goto-char begin)
310 (cond
311 ((re-search-forward "['\"]" end t) (setq found t))
312 ((goto-char end)))))
313 found))
314
315 296
316;; Indentation and electric keys 297;; Indentation and electric keys
317 298