Packages: [Clojure] Add support for keywords

Created on 1 Feb 2017  路  11Comments  路  Source: sublimehq/Packages

The syntax highlighter for Clojure doesn't support the valid highlighting of keywords, which are basically strings with a colon at the front:

:foo ; This is a keyword

Currently, though, Sublime highlights keywords like so (in Monokai):
clojure

Code:

(defn change-disp []
  [:div.change-disp
   [:input {:type "button"
            :value "Display stuff"
            :on-click #(swap! display? not)}]])

The colons are highlighted (presumably because it's punctuation), but the rest isn't highlighted.

Most helpful comment

Please include the text used in screenshots for easier reproduction via copy and paste.

All 11 comments

For context, clojure keywords should be scoped the same as Ruby/Scala symbols, since their usage is almost equivalent.

Also, functions with slashes in them (functions from other Clojure files) aren't highlighted at all - only the / is highlighted:

clojure2

Code:

(defstyles stylesheet
  {:output-to "resources/public/css/styles.css"}
  [style/at-import "https://fonts.googleapis.com/css?family=Fira+Mono"]
  [:body
   {:font-size (px 20)
    :font-family "\"Fira Mono\", monospace"
    :text-align "center"}]
  [(s/input (s/attr= :type :button))
   {:border "none"
    :border-radius (px 5)
    :background-color "lightgreen"
    :padding (px 10)
    :margin (px 5)
    :color "white"}]
  [(s/input (s/attr= :type :input))
   {:height (px 30)}]
  [:.hybrid
   {:height (px 35)
    :display "inline"}])

(This also demonstrates the first issue.)

Please include the text used in screenshots for easier reproduction via copy and paste.

@FichteFoll I included that.

Bump: anything useful yet?

Seems like you could just modify your color scheme to highlight source.symbol.clojure, no?

@keith-hall That did (partially) solve the issue for the highlighter, but the : was still being highlighted incorrectly as punctuation. I believe this might be a "bug" (maybe not) with the actual Clojure syntax thing itself.

Picture and code for reference:

clojure

(defproject experiments "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "http://example.com/FIXME"
  :license {:name "Eclipse Public License"
            :url "http://www.eclipse.org/legal/epl-v10.html"}

  :dependencies [[org.clojure/clojure "1.8.0"]]
  :main experiments.core/-main)

I guess you could work around it by also highlighting keyword.operator.symbol.clojure the same as source.symbol.clojure.

I guess the syntax def could scope the : as source.symbol.clojure and replace the keyword.operator.symbol.clojure scope with a punctuation scope, as most color schemes won't target these I think. I'll leave that for the experts to discuss/decide, I'm just spouting out ideas :)

Honestly it's probably easiest just to modify the mode to scope things appropriately. The Clojure mode is still pretty simple since it hasn't been updated to the new stateful hotness, so it should be almost as easy as tweaking a regex. That also has the advantage of being something that is pull requestable.

@wbond seems fixed by #1259

This issue has been solved by a previous commit, hence it is being closed.

Was this page helpful?
0 / 5 - 0 ratings