This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-12-02
Channels
- # adventofcode (47)
- # announcements (7)
- # aws (1)
- # babashka (52)
- # beginners (80)
- # boot (3)
- # calva (19)
- # cider (9)
- # cljs-dev (1)
- # clojure (48)
- # clojure-brasil (1)
- # clojure-dev (27)
- # clojure-europe (3)
- # clojure-madison (3)
- # clojure-nl (29)
- # clojure-spec (11)
- # clojure-sweden (1)
- # clojure-uk (49)
- # clojurescript (66)
- # core-async (20)
- # cryogen (4)
- # cursive (13)
- # data-science (7)
- # datomic (5)
- # emacs (30)
- # figwheel-main (11)
- # fulcro (15)
- # graphql (8)
- # jobs (5)
- # joker (17)
- # lambdaisland (1)
- # leiningen (2)
- # malli (2)
- # off-topic (5)
- # pathom (22)
- # re-frame (12)
- # reagent (29)
- # reitit (2)
- # ring (10)
- # shadow-cljs (57)
- # specter (3)
- # tools-deps (22)
- # vim (5)
- # xtdb (7)
Anybody had issues with font lock on big clojure files before? My emacs is hanging when I open a 6k lines cljs file (an edn i18n dictionary). I profiled it and looks like font-lock is the culprit :thinking_face:
Lucas, I recently introduced the following into my config for large files, whilst it won't address the initial loading issue, it may help for general navigation with any large file (not just Clojure code)
(use-package fast-scroll
:ensure t
:init
(add-hook 'fast-scroll-start (lambda () (flycheck-mode -1)))
(add-hook 'fast-scroll-end (lambda () (flycheck-mode 1)))
:config
(fast-scroll-config)
(fast-scroll-mode 1))
I'll give it a try! Thanks
You can see it happen with any large file and font-lock, or if the file is large enough emacs just grinds to a halt
Yep. The current font-locking engine is based on regular expressions, which results in pretty poor performance in certain cases.
Iām pretty sure we can improve the existing regular expressions, but I never found the time to profile and tweak them.
Yeah, if I open the file literally, it is very fast @royalaid
Well, it actually opens the file and I am able to navigate (slowly, but doable)
But it hangs for a while when I ask it to open the file :thinking_face: not a deal breaker, definitely
I noticed major slowdowns too when the file is basically a single huge sexp, in the case of edn data
made a lightweight edn-mode based on text-mode
to get around this - not sure if that would be something generally useful to people?
(defvar edn-font-lock-keywords
`((,(rx (group (repeat 1 2 ":"))
(group (+ (or (syntax word) (syntax symbol))))
(group "/")
(group (+ (or (syntax word) (syntax symbol)))))
(1 'clojure-keyword-face)
(2 font-lock-type-face)
(3 'default)
(4 'clojure-keyword-face))
(,(rx (group (repeat 1 2 ":"))
(group (+ (or (syntax word) (syntax symbol)))))
(1 'clojure-keyword-face)
(2 'clojure-keyword-face))))
(define-derived-mode edn-mode text-mode "EDN"
"Major mode for editing Extensible Data Notation files"
(set-syntax-table clojure-mode-syntax-table)
(setq-local tab-width 2)
(setq-local comment-start ";")
(setq-local comment-start-skip ";+ *")
(setq-local comment-add 1)
(setq-local font-lock-defaults '(edn-font-lock-keywords nil)))
(add-hook 'edn-mode-hook 'rainbow-delimiters-mode)
(with-eval-after-load 'clojure-mode
(add-to-list 'auto-mode-alist '("\\.edn\\'" . edn-mode))
(add-to-list 'auto-mode-alist '("deps.edn\\'" . clojure-mode))
(add-to-list 'auto-mode-alist '("shadow-cljs.edn\\'" . clojure-mode))
(add-to-list 'auto-mode-alist '("config.edn" . clojure-mode)))
the last part is basically a whitelist of edn config files like "deps.edn" where you still want prog-mode commands like structural editing
What is the emacs command for indenting the contents of a string like:
(deftest redefine-var-test
(eval* "(def ^:redef x 10)
(defn foo [] x)
(def x 11)
(println (foo))
"))