Skip to content

(def s "a string") font locks "a string" as a docstring #445

Closed
@oskarkv

Description

@oskarkv

Expected behavior

Font lock the string "a string" as a string in (def s "a string").

Actual behavior

The string "a string" is font locked as a docstring in (def s "a string").

clojure-mode version information

clojure-mode (version 5.7.0-snapshot)

Proposed solution

I played around with this, and it can be solved by adding a check in this and https://github.com/clojure-emacs/clojure-mode/blob/master/clojure-mode.el#L898 in the function clojure-font-lock-syntactic-face-function. For example

(and ...
  (or (save-excursion
        (goto-char startpos)
        (not (= ?\) (char-after (+ startpos (length (sexp-at-point)) 2)))))
      (string= "defprotocol" firstsym)))

This, of course, checks for a closing paren after the string, and if so, it is not considered a docstring, except for defprotocol, which is the only kind of form that can have a docstring in the last position. Instead of checking for a paren, one could of course check for another element, but it is more involved.

Opinions, suggestions, etc?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions