diff options
| author | Simeon Simeonov | 2018-02-19 10:27:32 +0100 |
|---|---|---|
| committer | Simeon Simeonov | 2018-02-19 10:27:32 +0100 |
| commit | 1e6b143b8949e09c1231f860a7d9662010b7cb75 (patch) | |
| tree | 7bf5bb4ecee62c7c0a4cf166d8d069a38311166d /.emacs.d/lisp/yaml-mode.el | |
| parent | 2f1a2df667f075ee07b65eff87261ea018a135d8 (diff) | |
Update all modes
Diffstat (limited to '.emacs.d/lisp/yaml-mode.el')
| -rw-r--r-- | .emacs.d/lisp/yaml-mode.el | 82 |
1 files changed, 55 insertions, 27 deletions
diff --git a/.emacs.d/lisp/yaml-mode.el b/.emacs.d/lisp/yaml-mode.el index e257379..c3416dd 100644 --- a/.emacs.d/lisp/yaml-mode.el +++ b/.emacs.d/lisp/yaml-mode.el | |||
| @@ -234,18 +234,19 @@ that key is pressed to begin a block literal." | |||
| 234 | ;; Font-lock support | 234 | ;; Font-lock support |
| 235 | 235 | ||
| 236 | (defvar yaml-font-lock-keywords | 236 | (defvar yaml-font-lock-keywords |
| 237 | `((,yaml-constant-scalars-re . (1 font-lock-constant-face)) | 237 | `((yaml-font-lock-block-literals 0 font-lock-string-face) |
| 238 | (,yaml-constant-scalars-re . (1 font-lock-constant-face)) | ||
| 238 | (,yaml-tag-re . (0 font-lock-type-face)) | 239 | (,yaml-tag-re . (0 font-lock-type-face)) |
| 239 | (,yaml-node-anchor-alias-re . (0 font-lock-function-name-face)) | 240 | (,yaml-node-anchor-alias-re . (0 font-lock-function-name-face)) |
| 240 | (,yaml-hash-key-re . (1 font-lock-variable-name-face)) | 241 | (,yaml-hash-key-re . (1 font-lock-variable-name-face)) |
| 241 | (,yaml-document-delimiter-re . (0 font-lock-comment-face)) | 242 | (,yaml-document-delimiter-re . (0 font-lock-comment-face)) |
| 242 | (,yaml-directive-re . (1 font-lock-builtin-face)) | 243 | (,yaml-directive-re . (1 font-lock-builtin-face)) |
| 243 | (yaml-font-lock-block-literals 0 font-lock-string-face) | ||
| 244 | ("^[\t]+" 0 'yaml-tab-face t)) | 244 | ("^[\t]+" 0 'yaml-tab-face t)) |
| 245 | "Additional expressions to highlight in YAML mode.") | 245 | "Additional expressions to highlight in YAML mode.") |
| 246 | 246 | ||
| 247 | (defun yaml-mode-syntax-propertize-function (beg end) | 247 | (defun yaml-mode-syntax-propertize-function (beg end) |
| 248 | "Unhighlight foo#bar tokens between BEG and END." | 248 | "Override buffer's syntax table for special syntactic constructs." |
| 249 | ;; Unhighlight foo#bar tokens between BEG and END. | ||
| 249 | (save-excursion | 250 | (save-excursion |
| 250 | (goto-char beg) | 251 | (goto-char beg) |
| 251 | (while (search-forward "#" end t) | 252 | (while (search-forward "#" end t) |
| @@ -255,7 +256,27 @@ that key is pressed to begin a block literal." | |||
| 255 | (when (and (not (bolp)) | 256 | (when (and (not (bolp)) |
| 256 | (not (memq (preceding-char) '(?\s ?\t)))) | 257 | (not (memq (preceding-char) '(?\s ?\t)))) |
| 257 | (put-text-property (point) (1+ (point)) | 258 | (put-text-property (point) (1+ (point)) |
| 258 | 'syntax-table (string-to-syntax "_"))))))) | 259 | 'syntax-table (string-to-syntax "_")))))) |
| 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 | ||
| 264 | (goto-char beg) | ||
| 265 | (while (re-search-forward "['\"]" end t) | ||
| 266 | (when (get-text-property (point) 'yaml-block-literal) | ||
| 267 | (put-text-property (1- (point)) (point) | ||
| 268 | 'syntax-table (string-to-syntax "w"))) | ||
| 269 | (when (nth 8 (syntax-ppss)) | ||
| 270 | (save-excursion | ||
| 271 | (forward-char -1) | ||
| 272 | (cond ((and (char-equal ?' (char-before (point))) | ||
| 273 | (char-equal ?' (char-after (point))) | ||
| 274 | (put-text-property (1- (point)) (1+ (point)) | ||
| 275 | 'syntax-table (string-to-syntax "w")))) | ||
| 276 | ((and (not (bolp)) | ||
| 277 | (char-equal ?w (char-syntax (char-before (point))))) | ||
| 278 | (put-text-property (point) (1+ (point)) | ||
| 279 | 'syntax-table (string-to-syntax "w"))))))))) | ||
| 259 | 280 | ||
| 260 | (defun yaml-font-lock-block-literals (bound) | 281 | (defun yaml-font-lock-block-literals (bound) |
| 261 | "Find lines within block literals. | 282 | "Find lines within block literals. |
| @@ -272,29 +293,36 @@ artificially limitted to the value of | |||
| 272 | (let ((begin (point)) | 293 | (let ((begin (point)) |
| 273 | (end (min (1+ (point-at-eol)) bound))) | 294 | (end (min (1+ (point-at-eol)) bound))) |
| 274 | (goto-char (point-at-bol)) | 295 | (goto-char (point-at-bol)) |
| 275 | (while (and (looking-at yaml-blank-line-re) (not (bobp))) | 296 | (while (and (looking-at yaml-blank-line-re) |
| 297 | (not (bobp))) | ||
| 276 | (forward-line -1)) | 298 | (forward-line -1)) |
| 277 | (let ((nlines yaml-block-literal-search-lines) | 299 | (let ((nlines yaml-block-literal-search-lines) |
| 278 | (min-level (current-indentation))) | 300 | (min-level (current-indentation))) |
| 279 | (forward-line -1) | 301 | (forward-line -1) |
| 280 | (while (and (/= nlines 0) | 302 | (while (and (/= nlines 0) |
| 281 | (/= min-level 0) | 303 | (/= min-level 0) |
| 282 | (not (looking-at yaml-block-literal-re)) | 304 | (not (looking-at yaml-block-literal-re)) |
| 283 | (not (bobp))) | 305 | (not (bobp))) |
| 284 | (set 'nlines (1- nlines)) | 306 | (setq nlines (1- nlines)) |
| 285 | (unless (looking-at yaml-blank-line-re) | 307 | (unless (looking-at yaml-blank-line-re) |
| 286 | (set 'min-level (min min-level (current-indentation)))) | 308 | (setq min-level (min min-level (current-indentation)))) |
| 287 | (forward-line -1)) | 309 | (forward-line -1)) |
| 288 | (cond | 310 | (cond |
| 289 | ((and (< (current-indentation) min-level) | 311 | ((and (< (current-indentation) min-level) |
| 290 | (looking-at yaml-block-literal-re)) | 312 | (looking-at yaml-block-literal-re)) |
| 291 | (goto-char end) (set-match-data (list begin end)) t) | 313 | (goto-char end) |
| 314 | (put-text-property begin end 'yaml-block-literal t) | ||
| 315 | (set-match-data (list begin end)) | ||
| 316 | t) | ||
| 292 | ((progn | 317 | ((progn |
| 293 | (goto-char begin) | 318 | (goto-char begin) |
| 294 | (re-search-forward (concat yaml-block-literal-re | 319 | (re-search-forward (concat yaml-block-literal-re |
| 295 | " *\\(.*\\)\n") | 320 | " *\\(.*\\)\n") |
| 296 | bound t)) | 321 | bound t)) |
| 297 | (set-match-data (nthcdr 2 (match-data))) t)))))) | 322 | (let ((range (nthcdr 2 (match-data)))) |
| 323 | (put-text-property (car range) (cadr range) 'yaml-block-literal t) | ||
| 324 | (set-match-data range)) | ||
| 325 | t)))))) | ||
| 298 | 326 | ||
| 299 | 327 | ||
| 300 | ;; Indentation and electric keys | 328 | ;; Indentation and electric keys |
| @@ -329,8 +357,8 @@ back-dent the line by `yaml-indent-offset' spaces. On reaching column | |||
| 329 | (if (and (equal last-command this-command) (/= ci 0)) | 357 | (if (and (equal last-command this-command) (/= ci 0)) |
| 330 | (indent-to (* (/ (- ci 1) yaml-indent-offset) yaml-indent-offset)) | 358 | (indent-to (* (/ (- ci 1) yaml-indent-offset) yaml-indent-offset)) |
| 331 | (indent-to need))) | 359 | (indent-to need))) |
| 332 | (if (< (current-column) (current-indentation)) | 360 | (if (< (current-column) (current-indentation)) |
| 333 | (forward-to-indentation 0)))) | 361 | (forward-to-indentation 0)))) |
| 334 | 362 | ||
| 335 | (defun yaml-electric-backspace (arg) | 363 | (defun yaml-electric-backspace (arg) |
| 336 | "Delete characters or back-dent the current line. | 364 | "Delete characters or back-dent the current line. |
| @@ -374,8 +402,8 @@ margin." | |||
| 374 | (self-insert-command (prefix-numeric-value arg)) | 402 | (self-insert-command (prefix-numeric-value arg)) |
| 375 | (save-excursion | 403 | (save-excursion |
| 376 | (beginning-of-line) | 404 | (beginning-of-line) |
| 377 | (if (and (not arg) (looking-at yaml-document-delimiter-re)) | 405 | (when (and (not arg) (looking-at yaml-document-delimiter-re)) |
| 378 | (delete-horizontal-space)))) | 406 | (delete-horizontal-space)))) |
| 379 | 407 | ||
| 380 | (defun yaml-narrow-to-block-literal () | 408 | (defun yaml-narrow-to-block-literal () |
| 381 | "Narrow the buffer to block literal if the point is in it, | 409 | "Narrow the buffer to block literal if the point is in it, |
| @@ -393,13 +421,13 @@ otherwise do nothing." | |||
| 393 | (/= min-level 0) | 421 | (/= min-level 0) |
| 394 | (not (looking-at-p yaml-block-literal-re)) | 422 | (not (looking-at-p yaml-block-literal-re)) |
| 395 | (not (bobp))) | 423 | (not (bobp))) |
| 396 | (set 'nlines (1- nlines)) | 424 | (setq nlines (1- nlines)) |
| 397 | (unless (looking-at-p yaml-blank-line-re) | 425 | (unless (looking-at-p yaml-blank-line-re) |
| 398 | (set 'min-level (min min-level (current-indentation)))) | 426 | (setq min-level (min min-level (current-indentation)))) |
| 399 | (forward-line -1)) | 427 | (forward-line -1)) |
| 400 | (when (and (< (current-indentation) min-level) | 428 | (when (and (< (current-indentation) min-level) |
| 401 | (looking-at-p yaml-block-literal-re)) | 429 | (looking-at-p yaml-block-literal-re)) |
| 402 | (set 'min-level (current-indentation)) | 430 | (setq min-level (current-indentation)) |
| 403 | (forward-line) | 431 | (forward-line) |
| 404 | (setq beg (point)) | 432 | (setq beg (point)) |
| 405 | (while (and (not (eobp)) | 433 | (while (and (not (eobp)) |
