Function: syntax-propertize

syntax-propertize is a byte-compiled function defined in syntax.el.gz.

Signature

(syntax-propertize POS)

Documentation

Ensure that syntax-table properties are set until POS (a buffer point).

Probably introduced at or before Emacs version 24.1.

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/syntax.el.gz
(defun syntax-propertize (pos)
  "Ensure that syntax-table properties are set until POS (a buffer point)."
  (when (< syntax-propertize--done pos)
    (if (memq syntax-propertize-function '(nil ignore))
        (setq syntax-propertize--done (max (point-max) pos))
      ;; (message "Needs to syntax-propertize from %s to %s"
      ;;          syntax-propertize--done pos)
      (setq-local parse-sexp-lookup-properties t)
      (when (< syntax-propertize--done (point-min))
        ;; *Usually* syntax-propertize is called via syntax-ppss which
        ;; takes care of adding syntax-ppss-flush-cache to b-c-f, but this
        ;; is not *always* the case, so since we share a single "flush" function
        ;; between syntax-ppss and syntax-propertize, we also have to make
        ;; sure the flush function is installed here (bug#29767).
        (add-hook 'before-change-functions
                  #'syntax-ppss-flush-cache 99 t))
      (save-excursion
        (with-silent-modifications
          (with-syntax-table (or syntax-ppss-table (syntax-table))
            (make-local-variable 'syntax-propertize--done) ;Just in case!
            ;; Make sure we let-bind it only buffer-locally.
            (make-local-variable 'syntax-ppss--updated-cache)
            (let* ((start (max (min syntax-propertize--done (point-max))
                               (point-min)))
                   (end (max pos
                             (min (point-max)
                                  (+ start syntax-propertize-chunk-size))))
                   (first t)
                   (repeat t)
                   (syntax-ppss--updated-cache nil))
              (while repeat
                (setq repeat nil)
                (run-hook-wrapped
                 'syntax-propertize-extend-region-functions
                 (lambda (f)
                   ;; Bind `syntax-propertize--done' to avoid recursion!
                   (let* ((syntax-propertize--done most-positive-fixnum)
                          (new (funcall f start end)))
                     (if (or (null new)
                             (and (>= (car new) start) (<= (cdr new) end)))
                         nil
                       (setq start (car new))
                       (setq end (cdr new))
                       ;; If there's been a change, we should go through the
                       ;; list again since this new position may
                       ;; warrant a different answer from one of the funs we've
                       ;; already seen.
                       (unless first (setq repeat t))))
                   (setq first nil))))
              ;; Flush ppss cache between the original value of `start' and that
              ;; set above by syntax-propertize-extend-region-functions.
              (syntax-ppss-flush-cache start)
              ;; Move the limit before calling the function, so it's
              ;; done in case of errors.
              (setq syntax-propertize--done end)
              ;; (message "syntax-propertizing from %s to %s" start end)
              (remove-text-properties start end
                                      '(syntax-table nil syntax-multiline nil))
              ;; Bind `syntax-propertize--done' to avoid recursion!
              (let ((syntax-propertize--done most-positive-fixnum))
                (funcall syntax-propertize-function start end)
                (when syntax-ppss--updated-cache
                  ;; `syntax-ppss' was called and updated the cache while we
                  ;; were propertizing so we need to flush the part of the
                  ;; cache that may have been rendered out-of-date by the new
                  ;; properties.
                  ;; We used to require syntax-propertize-functions to do that
                  ;; manually when applicable, but nowadays the `syntax-ppss'
                  ;; cache can be updated by too many functions, so the author
                  ;; of the syntax-propertize-function may not be aware it
                  ;; can happen.
                  (syntax-ppss-flush-cache start))))))))))