Fork me on GitHub
#proton2015-12-11
>
sglyon03:12:02

Hmm, didn’t work.

dvcrn03:12:09

huh? let me try

sglyon03:12:23

haha the real proton is killing it

sglyon03:12:35

Probably need to add it to my packages list

dvcrn03:12:37

ah you have to of course put :proton inside your dotfile 😛

sglyon03:12:04

Yeah, not working for me still

sglyon03:12:42

I’ll just roll back to an old commit of one of my other packages

dvcrn03:12:55

ah this works @sglyon :

dvcrn03:12:04

go into ~/.atom/packages/<any-package>

dvcrn03:12:08

change the version inside package.json

dvcrn03:12:19

/tmp/proton/plugin
λ apm outdated
Package Updates Available (1)
└── vim-mode 0.62.0 -> 0.63.0

sglyon03:12:20

Oh geez I don’t want anything to do with that json output though

dvcrn03:12:40

maybe a regex match from ── to a number or something

sglyon03:12:49

I mean the json isn’t so bad

sglyon03:12:00

it is an array of json objects, each of which has a name field

sglyon03:12:05

I can skip the rest of it

sglyon03:12:47

Is there a way to turn this stdout into a vector of maps?

dvcrn03:12:55

(.parse js/JSON) to get an object and js->clj to convert it into a clojure map. Though david nolen mentioned before that it would be better to use goog libraries for dealing with js objects instead of converting them to clojure

sglyon03:12:35

I’m happy to leave it as json as long as I can ask the json what name is for each object in the array

dvcrn03:12:00

try js/JSON then simple_smile

sglyon03:12:37

wait… can I access the proton ns/commands from the devtools?

sglyon03:12:49

That’d be killer

dvcrn03:12:01

maybe from the REPL but from the devtools console, no

sglyon03:12:09

I’m seeing them now

sglyon03:12:14

(they tab complete)

sglyon03:12:36

proton.lib.package_manager.get_apm_path()
"/opt/homebrew-cask/Caskroom/atom/1.1.0/Atom.app/Contents/Resources/app/apm/bin/apm”

sglyon03:12:44

That came from the atom devtools console

dvcrn03:12:59

how did you compile it?

sglyon03:12:17

I’ve got a lein run -m build/dev-repl process running right now

sglyon03:12:32

So all the stuff is already js (no more clojure), but I can still interact with it

dvcrn03:12:44

maybe because it is not optimized? @thheller can answer that probably 😛

dvcrn03:12:48

Didn't know that was possible

sglyon03:12:54

Not sure, but I’m pretty happy it is possible simple_smile

sglyon03:12:00

JSON.parse worked — gave me an array of json obejcts

dvcrn04:12:59

anything useful in there?

sglyon04:12:51

proton.lib.package_manager.child_process.exec(proton.lib.package_manager.get_apm_path().concat(" outdated --json"), function (error, stdout, stderr) {
    var json_stdout = JSON.parse(stdout)
    var names = json_stdout.map(function(x){return x.name;});
    console.log(names)
});
> ChildProcess {domain: null, _events: Object, _eventsCount: 2, _maxListeners: undefined, _closesNeeded: 3…}
>  ["vim-mode”]

sglyon04:12:17

Now I just need to figure out how to return that names variable

sglyon04:12:35

Ahh is that what the channel is for in the install and remove package methods?

dvcrn04:12:00

well there is also execSync, but I used a channel because otherwise each installation would block the entire editor

dvcrn04:12:18

now it's async so it executes and we just pull the result of that execution back and display it

sglyon04:12:31

That’s very nice. I think I’m close

dvcrn04:12:48

in theory just pipe it into the channel, close it and you should be good simple_smile

dvcrn04:12:58

I'm going for lunch, will be back in 1h ish

sglyon04:12:02

quick question?

sglyon04:12:12

I’ve got the array of json objects

sglyon04:12:17

now I want to do something like this:

sglyon04:12:29

(map #(.name %) (.parse js/JSON stdout))

sglyon04:12:50

where I was hoping the .name would give me the name field on that json object, but it didn't

sglyon04:12:54

How should I access that field?

dvcrn04:12:07

to access properties, you have to use (.-name %)

dvcrn04:12:15

.- is the interop for that

sglyon04:12:48

So can I shove the result of that map into the chan?

dvcrn04:12:15

yep, or use the execSync version if it's fast enough for non async

sglyon04:12:34

Last question, how do I get it out of the chan?

sglyon04:12:44

(defn outdated-packages-chan []
  (println "finding outdated packages")
  (let [c (chan)]
    (go
      (.exec child-process "apm outdated --json"
        (fn [err stdout stderr]
          (if (nil? err)
            (do
              (println (str "The json is here: " (map #(.-name %) (.parse js/JSON stdout))))
              (go (>! c (map #(.-name %) (.parse js/JSON stdout))))
              (close! c))
            (do
              (go (>! c false))
              (close! c))))))
    c))

dvcrn04:12:44

especially if you never used core.async it might be a bit tricky to understand 😛

sglyon04:12:57

Haha i’ve never used clojure...

dvcrn04:12:18

(<! channel) is for pulling out of a channel, put in cljs you can only use it inside a go block which is also a channel

sglyon04:12:50

so instead of that c at the end should I just do (go (<! c)) to return the actual list of package names I want?

dvcrn04:12:06

so you have to do something like

(go 
   (let [result (<! mychannel)]
    (println result))

dvcrn04:12:15

no, (go) is also returning a channel

dvcrn04:12:57

you can't really return a value out of a go block. If you work with async, just put it inside the channel that you return (`c` in that case) and let the receiving part just pull that value out of it

dvcrn04:12:04

oooor use the execSync version 😛

sglyon04:12:08

haha — I’m determined to learn the async stuff

dvcrn04:12:36

really fun stuff, but also not that easy to grasp

dvcrn04:12:43

I also have a lot of problems with it

sglyon04:12:45

I’ve seen these concepts in go

sglyon04:12:52

But haven’t done a ton with them

sglyon04:12:15

what about returning (<!! c)

sglyon04:12:23

takes a val from port. Will return nil if closed. Will block
if nothing is available.

dvcrn04:12:33

that's clojure. You can't use that in clojurescript

dvcrn04:12:38

in cljs everything has to be inside a go block

dvcrn04:12:56

<!! is for real threads afaik which we don't really have in cljs simple_smile

sglyon04:12:17

Oh I think I see what to do

sglyon04:12:19

return the channel

sglyon04:12:43

Then have my update-packages command just call the apm update methods from within a go block?

dvcrn04:12:55

well if you copied my code then update-packages is also a async operation that uses channels. So calling update-package will give you a channel back

dvcrn04:12:24

but yeah that should work. But feel free to experiment a bit around with it

dvcrn04:12:58

what helps me understand is that everything inside a go block is getting executed async

sglyon04:12:11

Pretty cool stuff

dvcrn04:12:29

high recommendation for that talk up there. It's more clojure stuff but very cool

dvcrn04:12:48

now going for lunch 🍞

sglyon04:12:57

But it’s about time for me to call it a night, so I might balk and just do execSync

sglyon04:12:14

This is a single call, so async doesn’t earn us anything (I think)

dvcrn04:12:36

well I think atom is doing some requests to the repository though so it could take a while

dvcrn04:12:41

I could rewrite it later on in async if you want simple_smile

dvcrn04:12:46

if you get the sync version up

sglyon04:12:49

That’d be a good way to learn

thheller09:12:18

@sglyon @dvcrn sorry didn't follow the conversation. what was the issue? 😛

sglyon12:12:32

No problem. There wasn't really an issue, @dvcrn was just helping me out with some basic stuff as I've never used clojurescript or clojure before.

osdf14:12:42

Hi there.

osdf14:12:54

@dvcrn what is the 'proton prompt'?

osdf14:12:21

installed atom via .deb package from their site.

osdf14:12:28

then

apm install proton-mode
as given on the github site.

osdf14:12:40

after startup proton does some stuff.

dvcrn14:12:40

that should work

dvcrn14:12:52

and it still doesn’t work? Open a file and hit space

dvcrn14:12:13

Do you have any errors in your console?

dvcrn14:12:26

I just tested the store listed version and don’t have problems hmm

osdf14:12:52

would it be possible to start opening a file with space?

osdf14:12:59

like space f f

osdf14:12:02

like in spacemacs?

osdf14:12:29

so i open a file with ctrl-o.

dvcrn14:12:44

you mean on initial start?

dvcrn14:12:29

that’s on the list simple_smile We need to get atom somehow to accept our command chain without a editor context

dvcrn14:12:39

definitely something that should come soon

osdf14:12:39

ah, i see.

dvcrn14:12:50

if you have a file open though you can do <spc> p f to open the file searcher

osdf14:12:52

so for now e.g. opening files is always with ctrl -o?

dvcrn14:12:20

<spc> p r for recents and <spc> b b for buffers is also in

osdf14:12:14

so does atom have a fuzzy file finder?

osdf14:12:24

just asking, because maybe i can help a bit?

osdf14:12:34

(though no expereience with clojure script)

osdf14:12:45

<spc> f f would use the finder then, i guess?

dvcrn14:12:24

p f is already fuzzy but if you want something even fuzzier, you can open ~/.proton and replace the OpenFileProvider :normal with :nuclide, though I can only recommend it if you have a medium powerful machine because it does a lot of babel compiling first

dvcrn14:12:32

always looking for help simple_smile

dvcrn14:12:56

Here’s also a doc how to contribute layers to get started https://github.com/dvcrn/proton/blob/master/HOW-TO-LAYER.md

dvcrn14:12:40

it’s a fun project to get started with clojurescript

osdf14:12:51

for sure simple_smile

dvcrn14:12:35

<spc> _ d opens your .proton file by the way

osdf14:12:26

just killed the only buffer, and

<spc>
menue at the bottom freezes/stays.

dvcrn14:12:09

hrm yeah we definitely should put more focus on getting it work on non buffers

osdf14:12:21

just a couple of questions:

osdf14:12:30

how can i get highlighted search?

osdf14:12:48

I search with "/" and then start typing

osdf14:12:52

input is at the bottom

osdf15:12:42

how can i change themes? I see the line in the .proton file, is it always like ["core.themes" ["theme-ui", "theme-syntax"]]?

dvcrn15:12:54

ok for the first part, this is a limitation on atoms site but I already have that working on my local machine. Gonna merge that back in and then incremental search and highlights will work

dvcrn15:12:55

for themes

osdf15:12:09

that is super cool!

dvcrn15:12:42

add your theme package inside additional-packages and change

["core.themes" ["atom-material-ui" "atom-material-syntax"]]
to reflect that

dvcrn15:12:48

the first part is the ui, the second part the syntax theme

dvcrn15:12:21

by default we use material but to get the default atom one back for example, just change it to [“core.themes” [“one-dark-ui” “one-dark-syntax”]]

dvcrn15:12:53

if you are not sure about the name, you can also use the package installer to browse themes, change it and open your atom config (in the settings menu) to see how it is called internally. Then just add that to your .proton file

dvcrn15:12:06

proton will get rid of all the stuff you tested and don’t need on next start

osdf15:12:16

ah, ok! thanks!