Skip to content

Syntax highlighting broken for digits after the first in % args #671

Closed
@daveliepmann

Description

@daveliepmann

While working on #670 I noticed that syntax highlighting for %<n> args does not match Clojure reader syntax or behavior.

Disclaimer: I acknowledge that %15 is unidiomatic and this is an insignificant corner case that shouldn't arise in 99.999% of Clojure programming. Nevertheless I'm reporting it because it's a clear bug.

Expected behavior

Reader-legal numbered percent-style parameters %1, %2...%n to shorthand-syntax anonymous functions #() should be syntax-highlighted.

Actual behavior

Only the first digit of %<n> anonymous functions #() parameters is syntax-highlighted. Additional digits are not. So %1, %2, ... %9 work, but %10 and further display incorrectly.

Screenshot 2023-11-24 at 08 44 14

Steps to reproduce the problem

It is legal Clojure to provide up to MAX_POSITIONAL_ARITY args, per Compiler.java. More than that throws an exception "Can't specify more than 20 params". This matches observed behavior, which clearly supports up to %20:

(apply #(max %1 %10 %20)
       (take 20 (range)))
;; => 19

(apply #(max %1 %10 %21)
       (take 21 (range)))
;; => syntax error: Can't specify more than 20 params
Screenshot 2023-11-24 at 11 59 17

(I don't think it's important or necessarily our job to distinguish between functional % args and syntax-legal ones, especially since the limit is parameterized (see below), so I say we fix %999 as well as %19.)

Environment & Version information

clojure-mode version

clojure-mode (version 5.18.0)

Emacs version

28.2

Operating system

macOS 13.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions