Fork me on GitHub
#spacemacs
<
2018-07-27
>
practicalli-john11:07:06

@eggsyntax I've always used hooks to add key mappings or load other things into a layer once its loaded.. Not sure if that makes it any easier. You still need to know the right mode to hook into 🙂 For example, I use the following to set my own tab spacess for editing HTML code

(defun jr0cket-web-mode-indent-hook ()
    "Indent settings for languages in Web mode, markup=html, css=css, code=javascript/php/etc."
    (setq web-mode-markup-indent-offset 2)
    (setq web-mode-css-indent-offset  2)
    (setq web-mode-code-indent-offset 2))

  (add-hook 'web-mode-hook  'jr0cket-web-mode-indent-hook)

eggsyntax13:07:06

Ah, yeah, interesting, I've seen hooks but never tried to write any. Cool, I'll give it a shot, thanks @jr0cket!

practicalli-john13:07:29

@eggsyntax This example might be more relevant to what you were doing

(add-hook 'cider-repl-mode-hook
            '(lambda ()
               (define-key cider-repl-mode-map (kbd "<up>") 'cider-repl-previous-input)
               (define-key cider-repl-mode-map (kbd "<down>") 'cider-repl-next-input)))
There are many examples of hooks in my dotspacemacs/user-config section of my .spacemacs file. Just search for add-hook https://gist.github.com/jr0cket/9f170c910491ce01d243ca58d1c07f12

4
eggsyntax15:07:23

Hey, that works! I guess that runs later than the lib code. Thanks @jr0cket, that's a big help! And actually I've had trouble with up/down for prev/next input, too, so it's a nice bonus that this makes those work too 🙂

practicalli-john16:07:14

Hooks run after a layer or mode is loaded into memory, so they should be the last thing to run. So in the previous example, hooks won't load until after the reply mode does.

eggsyntax16:07:02

Perfect 🙂

eggsyntax16:07:44

Wow, emacs just managed to crash my whole system (ubuntu 18.04). I'm impressed?

practicalli-john17:07:11

I've never had a crash of the OS from Spacemacs. I had Emacs hang on a process before, but very rarely. Are you sure it was Emacs?

eggsyntax17:07:56

No, I just figured out I was misinterpreting the role of files in /var/crash/. emacs did crash, but it may have been part of the broader system crash. I'm still learning how to figure out the causes of linux system crashes...

😀 4
eggsyntax17:07:20

I retract the above, it was totally wrong AFAICT. I apologize for my libel 😉

rustam.gilaztdinov18:07:20

guys, can you help with refactror-nrepl? i have this in .lein/profiles.clj

{:user {:plugins [[refactor-nrepl "2.3.1"]
                  [cider/cider-nrepl "0.17.0-SNAPSHOT" :exclusions [org.clojure/tools.nrepl]]]}}
when run lein repl I always get this:
Error loading refactor-nrepl.middleware: java.io.FileNotFoundException: Could not locate cider/nrepl/middleware/util/misc__init.class or cider/nrepl/middleware/util/misc.clj on classpath., compiling:(refactor_nrepl/middleware.clj:1:1)
Exception in thread "main" java.lang.RuntimeException: Unable to resolve var: refactor-nrepl.middleware/wrap-refactor in this context, compiling:(/private/var/folders/dd/yjt452yn0zs1hs4_sd077rsm0000gn/T/form-init8768462867645520700.clj:1:8336)
	at clojure.lang.Compiler.analyzeSeq(Compiler.java:6875)
	at clojure.lang.Compiler.analyze(Compiler.java:6669)
	at clojure.lang.Compiler.analyze(Compiler.java:6625)
	at clojure.lang.Compiler$InvokeExpr.parse(Compiler.java:3834)
	at clojure.lang.Compiler.analyzeSeq(Compiler.java:6870)
	at clojure.lang.Compiler.analyze(Compiler.java:6669)
        ...........
	at clojure.lang.AFn.applyToHelper(AFn.java:156)
	at clojure.lang.Var.applyTo(Var.java:700)
	at clojure.main.main(main.java:37)
Caused by: java.lang.RuntimeException: Unable to resolve var: refactor-nrepl.middleware/wrap-refactor in this context
	at clojure.lang.Util.runtimeException(Util.java:221)
	at clojure.lang.Compiler$TheVarExpr$Parser.parse(Compiler.java:710)
	at clojure.lang.Compiler.analyzeSeq(Compiler.java:6868)
	...

eggsyntax18:07:09

@rustam.gilaztdinov for current versions of spacemacs & cider, you shouldn't need to put either of those in your profiles; they should both be automatically loaded by CIDER. At least that's my understanding, and I don't have either of them in my profiles. There are def old tutorials floating around that tell you to add those, but to the best of my understanding they're outdated.

eggsyntax18:07:54

Hmm, although you may need [cider/cider-nrepl "0.17.0"] in your project's project.clj.

eggsyntax18:07:36

(in which case having it in your profiles instead should also work fine. So...I retract that part, but I think you def don't need to explicitly specify refactor-nrepl anywhere).

rustam.gilaztdinov18:07:53

hmm, so I should add

:profiles {:dev {:dependencies [[cider/cider-nrepl "0.17.0"]]
                   :plugins [[refactor-nrepl "2.3.1"]]
in project.clj ?

rustam.gilaztdinov18:07:14

this doesn't help(

rustam.gilaztdinov18:07:54

may you share your env for work with refactor?

eggsyntax18:07:51

I don't have refactor-nrepl anywhere in my ~/.lein/profiles.clj or my project's project.clj. I have cider-nrepl in my project's project.clj.

practicalli-john19:07:31

The CIDER docs recommend you define cider-nrepl as a plugin rather than a dependency in your project.clj

:plugins [[cider/cider-nrepl "0.17.0"]]
By adding cider-nrepl as a dependency then that library will be included in the jar or uberjar you create when deploying. Not a big issue, but its more classes to load when your application first runs.

eggsyntax18:07:06

(as a dependency, not a plugin).

eggsyntax18:07:21

Here, I'll post both (but they're very, very messy 😉 ):

eggsyntax18:07:23

I'll PM them since I can't put a snippet in a thread.

practicalli-john19:07:50

@rustam.gilaztdinov if you use cider-jack-in from Spacemace then you can simply remove the ~/.lein/profiles.clj file, it is not needed. If you use cider-connect instead, then you will need a profiles file as defined in https://cider.readthedocs.io/en/latest/installation/#setting-up-a-standalone-repl

practicalli-john19:07:58

For Leiningen, the ~/.lein/profies.clj would just contain

{:repl {:plugins [[cider/cider-nrepl "0.17.0"]]}}