Function: yaml-mode-syntax-propertize-function

yaml-mode-syntax-propertize-function is a natively compiled function defined in yaml-mode.el.

Signature

(yaml-mode-syntax-propertize-function BEG END)

Documentation

Override buffer's syntax table for special syntactic constructs.

Source Code

;; Defined in /nix/store/fxfawcfn8g3mqnf4q0lmvgvy0vp3nxrx-emacs-packages-deps/share/emacs/site-lisp/elpa/yaml-mode-20260830.2340/yaml-mode.el
(defun yaml-mode-syntax-propertize-function (beg end)
  "Override buffer's syntax table for special syntactic constructs."
  ;; Unhighlight foo#bar tokens between BEG and END.
  (save-excursion
    (goto-char beg)
    (while (search-forward "#" end t)
      (save-excursion
        (forward-char -1)
        ;; both ^# and [ \t]# are comments
        (when (and (not (bolp))
                   (not (memq (preceding-char) '(?\s ?\t))))
          (put-text-property (point) (1+ (point))
                             'syntax-table (string-to-syntax "_"))))))

  (save-excursion
    (goto-char beg)
    (while (and
            (> end (point))
            (re-search-forward "['\"]" end t))
      (when (get-text-property (point) 'yaml-block-literal)
        (put-text-property (1- (point)) (point)
                           'syntax-table (string-to-syntax "w")))
      (let* ((pt (point))
             (sps (save-excursion (syntax-ppss (1- pt)))))
        (when (not (nth 8 sps))
          (cond
           ((and (char-before (1- pt))
                 (char-equal ?' (char-before (1- pt)))
                 (char-equal ?' (char-before pt)))
            (put-text-property (- pt 2) pt
                               'syntax-table (string-to-syntax "w"))
            ;; Workaround for https://debbugs.gnu.org/41195.
            (let ((syntax-propertize--done syntax-propertize--done))
              ;; Carefully invalidate the last cached ppss.
              (syntax-ppss-flush-cache (- pt 2))))
           ;; If quote is detected as a syntactic string start but appeared
           ;; after a non-whitespace character, then mark it as syntactic word.
           ((and (char-before (1- pt))
                 (char-equal ?w (char-syntax (char-before (1- pt)))))
            (put-text-property (1- pt) pt
                               'syntax-table (string-to-syntax "w")))
           (t
            ;; We're right after a quote that opens a string literal.
            ;; Skip over it (big speedup for long JSON strings).
            (goto-char (1- pt))
            (condition-case nil
                (forward-sexp)
              (scan-error
               (goto-char end))))))))))