diff options
| -rw-r--r-- | .emacs.d/lisp/yaml-mode.el | 44 |
1 files changed, 26 insertions, 18 deletions
diff --git a/.emacs.d/lisp/yaml-mode.el b/.emacs.d/lisp/yaml-mode.el index 9f76c38..66e41b3 100644 --- a/.emacs.d/lisp/yaml-mode.el +++ b/.emacs.d/lisp/yaml-mode.el | |||
| @@ -4,10 +4,10 @@ | |||
| 4 | 4 | ||
| 5 | ;; Author: Yoshiki Kurihara <clouder@gmail.com> | 5 | ;; Author: Yoshiki Kurihara <clouder@gmail.com> |
| 6 | ;; Marshall T. Vandegrift <llasram@gmail.com> | 6 | ;; Marshall T. Vandegrift <llasram@gmail.com> |
| 7 | ;; Maintainer: Vasilij Schneidermann <v.schneidermann@gmail.com> | 7 | ;; Maintainer: Vasilij Schneidermann <mail@vasilij.de> |
| 8 | ;; Package-Requires: ((emacs "24.1")) | 8 | ;; Package-Requires: ((emacs "24.1")) |
| 9 | ;; Keywords: data yaml | 9 | ;; Keywords: data yaml |
| 10 | ;; Version: 0.0.13 | 10 | ;; Version: 0.0.14 |
| 11 | 11 | ||
| 12 | ;; This file is not part of Emacs | 12 | ;; This file is not part of Emacs |
| 13 | 13 | ||
| @@ -117,7 +117,7 @@ that key is pressed to begin a block literal." | |||
| 117 | 117 | ||
| 118 | ;; Constants | 118 | ;; Constants |
| 119 | 119 | ||
| 120 | (defconst yaml-mode-version "0.0.13" "Version of `yaml-mode'.") | 120 | (defconst yaml-mode-version "0.0.14" "Version of `yaml-mode'.") |
| 121 | 121 | ||
| 122 | (defconst yaml-blank-line-re "^ *$" | 122 | (defconst yaml-blank-line-re "^ *$" |
| 123 | "Regexp matching a line containing only (valid) whitespace.") | 123 | "Regexp matching a line containing only (valid) whitespace.") |
| @@ -258,25 +258,33 @@ that key is pressed to begin a block literal." | |||
| 258 | (put-text-property (point) (1+ (point)) | 258 | (put-text-property (point) (1+ (point)) |
| 259 | 'syntax-table (string-to-syntax "_")))))) | 259 | 'syntax-table (string-to-syntax "_")))))) |
| 260 | 260 | ||
| 261 | ;; If quote is detected as a syntactic string start but appeared | ||
| 262 | ;; after a non-whitespace character, then mark it as syntactic word. | ||
| 263 | (save-excursion | 261 | (save-excursion |
| 264 | (goto-char beg) | 262 | (goto-char beg) |
| 265 | (while (re-search-forward "['\"]" end t) | 263 | (while (and |
| 264 | (> end (point)) | ||
| 265 | (re-search-forward "['\"]" end t)) | ||
| 266 | (when (get-text-property (point) 'yaml-block-literal) | 266 | (when (get-text-property (point) 'yaml-block-literal) |
| 267 | (put-text-property (1- (point)) (point) | 267 | (put-text-property (1- (point)) (point) |
| 268 | 'syntax-table (string-to-syntax "w"))) | 268 | 'syntax-table (string-to-syntax "w"))) |
| 269 | (when (nth 8 (syntax-ppss)) | 269 | (let* ((pt (point)) |
| 270 | (save-excursion | 270 | (sps (save-excursion (syntax-ppss (1- pt))))) |
| 271 | (forward-char -1) | 271 | (when (not (nth 8 sps)) |
| 272 | (cond ((and (char-equal ?' (char-before (point))) | 272 | (cond |
| 273 | (char-equal ?' (char-after (point))) | 273 | ((and (char-equal ?' (char-before (1- pt))) |
| 274 | (put-text-property (1- (point)) (1+ (point)) | 274 | (char-equal ?' (char-before pt))) |
| 275 | 'syntax-table (string-to-syntax "w")))) | 275 | (put-text-property (- pt 2) pt |
| 276 | ((and (not (bolp)) | 276 | 'syntax-table (string-to-syntax "w"))) |
| 277 | (char-equal ?w (char-syntax (char-before (point))))) | 277 | ;; If quote is detected as a syntactic string start but appeared |
| 278 | (put-text-property (point) (1+ (point)) | 278 | ;; after a non-whitespace character, then mark it as syntactic word. |
| 279 | 'syntax-table (string-to-syntax "w"))))))))) | 279 | ((and (char-before (1- pt)) |
| 280 | (char-equal ?w (char-syntax (char-before (1- pt))))) | ||
| 281 | (put-text-property (1- pt) pt | ||
| 282 | 'syntax-table (string-to-syntax "w"))) | ||
| 283 | (t | ||
| 284 | ;; We're right after a quote that opens a string literal. | ||
| 285 | ;; Skip over it (big speedup for long JSON strings). | ||
| 286 | (goto-char (1- pt)) | ||
| 287 | (ignore-errors (forward-sexp))))))))) | ||
| 280 | 288 | ||
| 281 | (defun yaml-font-lock-block-literals (bound) | 289 | (defun yaml-font-lock-block-literals (bound) |
| 282 | "Find lines within block literals. | 290 | "Find lines within block literals. |
| @@ -286,7 +294,7 @@ line in the match data, as consumed by `font-lock-keywords' matcher | |||
| 286 | functions. The function begins by searching backwards to determine | 294 | functions. The function begins by searching backwards to determine |
| 287 | whether or not the current line is within a block literal. This could | 295 | whether or not the current line is within a block literal. This could |
| 288 | be time-consuming in large buffers, so the number of lines searched is | 296 | be time-consuming in large buffers, so the number of lines searched is |
| 289 | artificially limitted to the value of | 297 | artificially limited to the value of |
| 290 | `yaml-block-literal-search-lines'." | 298 | `yaml-block-literal-search-lines'." |
| 291 | (if (eolp) (goto-char (1+ (point)))) | 299 | (if (eolp) (goto-char (1+ (point)))) |
| 292 | (unless (or (eobp) (>= (point) bound)) | 300 | (unless (or (eobp) (>= (point) bound)) |
