Function: python--font-lock-f-strings

python--font-lock-f-strings is a byte-compiled function defined in python.el.gz.

Signature

(python--font-lock-f-strings LIMIT)

Documentation

Mark {...} holes as being code.

Remove the (presumably font-lock-string-face) face property from the {...} holes that appear within f-strings.

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/python.el.gz
(defun python--font-lock-f-strings (limit)
  "Mark {...} holes as being code.
Remove the (presumably `font-lock-string-face') `face' property from
the {...} holes that appear within f-strings."
  ;; FIXME: This will fail to properly highlight strings appearing
  ;; within the {...} of an f-string.
  ;; We could presumably fix it by running
  ;; `font-lock-default-fontify-syntactically-region' (as is done in
  ;; `sm-c--cpp-fontify-syntactically', for example) after removing
  ;; the `face' property, but I'm not sure it's worth the effort and
  ;; the risks.
  (let ((ppss (syntax-ppss)))
    (while
        (progn
          (while (and (not (python--f-string-p ppss))
                      (re-search-forward python--f-string-start-regexp limit 'move))
            (setq ppss (syntax-ppss)))
          (< (point) limit))
      (cl-assert (python--f-string-p ppss))
      (let ((send (save-excursion
                   (goto-char (nth 8 ppss))
                   (condition-case nil
                       (progn (let ((forward-sexp-function nil))
                                (forward-sexp 1))
                              (min limit (1- (point))))
                     (scan-error limit)))))
        (while (re-search-forward "{" send t)
          (if (eq ?\{ (char-after))
              (forward-char 1)          ;Just skip over {{
            (let ((beg (match-beginning 0))
                  (end (condition-case nil
                           (let ((forward-sexp-function)
                                 (parse-sexp-ignore-comments))
                             (up-list 1)
                             (min send (point)))
                         (scan-error send))))
              (goto-char end)
              (put-text-property beg end 'face nil))))
        (goto-char (min limit (1+ send)))
        (setq ppss (syntax-ppss))))))