Function: clojure-font-lock-syntactic-face-function

clojure-font-lock-syntactic-face-function is a byte-compiled function defined in clojure-mode.el.

Signature

(clojure-font-lock-syntactic-face-function STATE)

Documentation

Find and highlight text with a Clojure-friendly syntax table.

This function is passed to font-lock-syntactic-face-function, which is called with a single parameter, STATE (which is, in turn, returned by parse-partial-sexp at the beginning of the highlighted region).

Source Code

;; Defined in ~/.emacs.d/elpa/clojure-mode-20260325.811/clojure-mode.el
(defun clojure-font-lock-syntactic-face-function (state)
  "Find and highlight text with a Clojure-friendly syntax table.

This function is passed to `font-lock-syntactic-face-function',
which is called with a single parameter, STATE (which is, in
turn, returned by `parse-partial-sexp' at the beginning of the
highlighted region)."
  (if (nth 3 state)
      ;; This is a (doc)string
      (let* ((startpos (nth 8 state))
             (listbeg (nth 1 state))
             (firstsym (and listbeg
                            (save-excursion
                              (goto-char listbeg)
                              (and (looking-at "([ \t\n]*\\(\\(\\sw\\|\\s_\\)+\\)")
                                   (match-string 1)))))
             (docelt (and firstsym
                          (function-get (intern-soft firstsym)
                                        lisp-doc-string-elt-property))))
        (if (or (and docelt
                     ;; It's a string in a form that can have a docstring.
                     ;; Check whether it's in docstring position.
                     (save-excursion
                       (when (functionp docelt)
                         (goto-char (match-end 1))
                         (setq docelt (funcall docelt)))
                       (goto-char listbeg)
                       (forward-char 1)
                       (ignore-errors
                         (while (and (> docelt 0) (< (point) startpos)
                                     (progn (forward-sexp 1) t))
                           ;; ignore metadata and type hints
                           (unless (looking-at "[ \n\t]*\\(\\^[A-Z:].+\\|\\^?{.+\\)")
                             (setq docelt (1- docelt)))))
                       (and (zerop docelt) (<= (point) startpos)
                            (progn (forward-comment (point-max)) t)
                            (= (point) (nth 8 state))))
                     ;; In a def, at last position is not a docstring
                     (not (and (string= "def" firstsym)
                               (save-excursion
                                 (goto-char startpos)
                                 (goto-char (end-of-thing 'sexp))
                                 (looking-at "[ \r\n\t]*\)")))))
                ;; Protocol method docstring: string is last in the
                ;; method form and parent form is defprotocol.
                (and listbeg
                     (save-excursion
                       (goto-char startpos)
                       (ignore-errors (forward-sexp))
                       (skip-chars-forward " \t\n\r")
                       (eq (char-after) ?\)))
                     (save-excursion
                       (let ((parent-beg (nth 1 (syntax-ppss listbeg))))
                         (and parent-beg
                              (goto-char parent-beg)
                              (looking-at "([ \t\n]*defprotocol\\>"))))))
            font-lock-doc-face
          font-lock-string-face))
    font-lock-comment-face))