New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple mode implementation + mode keybindings #27

Merged
merged 4 commits into from Dec 14, 2015

Conversation

Projects
None yet
3 participants
@geksilla
Collaborator

geksilla commented Dec 10, 2015

Implemented basic mode functionality.
Added function to define mode with extra info.
Prefer to use inside init-layer! function, for example:

;; src/proton/layers/clojure
(defmethod init-layer! :clojure
  [_ config]
  ;; define mode name
  (mode/define-mode :clojure 
     ;; initialize for selected editor grammar
     :atom-grammars ["Clojure"] 
     ;; or initialize for file extension
     :file-extensions [#"\.proton$"]
     ;; custom init function on mode activation
     :init (fn []
            (atom-env/set-grammar "Clojure")))
  ;; define mode keybindings
  ;; also able to define within define-mode function using :mode-keybindings keyword
  ;; this one 
  (mode/define-keybindings :clojure
    {:t {:category "toggles"
         :p {:action "parinfer:toggleMode" :title "Toggle Parinfer Mode"}}})
   ;; same as
   (mode/define-mode :clojure
      :mode-keybindings {:p {:category "my-category"}})

Mode actions available via SPC m.
@dvcrn can you please review? Thanks.

@dvcrn

This comment has been minimized.

Owner

dvcrn commented Dec 10, 2015

Ohh very cool! This was something I wanted do look at for a long time. I'll check it out later!

Just on the first look, maybe it makes sense to put these modes in a separate multimethod like init-mode! or get-mode or something like this

@geksilla

This comment has been minimized.

Collaborator

geksilla commented Dec 10, 2015

@dvcrn agree about multimethod I'll try. I was thinking about something similar to emacs modes in the future, like provide ability to compose several modes, major/minor modes definitions etc. That's why I put it to separate file. But I'm ok with multimethod 👍

@sglyon

This comment has been minimized.

Contributor

sglyon commented Dec 10, 2015

That is so awesome! I'm excited to see this. Good work!

You even hooked up Julia for me, thanks!

@dvcrn

This comment has been minimized.

Owner

dvcrn commented Dec 10, 2015

Tested it and works really great :) Is this already ready for merge or do you have some more changes?

With multimethod I meant that you currently put the stuff in init-layer!. What I wanted to say is that it might be better in a separate multimethod. I have no problem with the separate file :)

For linking: #9

@dvcrn

This comment has been minimized.

Owner

dvcrn commented Dec 10, 2015

Also just an idea but one thing that I think would be pretty cool is if the user can bind files to languages from the ~/.proton file.

Something like, I want .abc to always get opened in clojure mode

@sglyon

This comment has been minimized.

Contributor

sglyon commented Dec 10, 2015

I've used the file-types package for this in the past

@dvcrn

This comment has been minimized.

Owner

dvcrn commented Dec 10, 2015

^ might need to check if we can somehow integrate with this

I only saw inside clojure/core.cljs that he is doing something similar here:

(mode/define-mode :clojure
+     :atom-grammars ["Clojure"]
+     :file-extensions [#"\.proton$"]
+     :init (fn []
+            (atom-env/set-grammar "Clojure")))

That's why the question 😛

@geksilla

This comment has been minimized.

Collaborator

geksilla commented Dec 10, 2015

Basic implementation almost done. Few things left.
Need to reset modes atom state on package deactivation.
Detect and enable mode for active editor when Atom session restored. For now there is observer for active panel item which triggers on tab creation and switching between tabs. I will try to finish this one today. Thanks.

@geksilla geksilla force-pushed the geksilla:feature/mode-keybindings branch from 37b2625 to 811bfc0 Dec 11, 2015

@geksilla geksilla force-pushed the geksilla:feature/mode-keybindings branch from 8262122 to 9e47be3 Dec 11, 2015

@geksilla

This comment has been minimized.

Collaborator

geksilla commented Dec 11, 2015

Added multimethod describe-mode. Example usage:

(defmethod describe-mode :lang/clojure []
  {:mode-name :clojure
   :atom-grammars ["Clojure"]
   :file-extensions [#"\.proton$"]
   :mode-keybindings
   {:t {:category "toggles"
        :p {:action "parinfer:toggleMode" :title "Toggle Parinfer Mode"}}}
   :init clojure-mode-init})

Added quick access key for mode specific keybindings by ,.
@dvcrn can you please review it? Thanks

@dvcrn

This comment has been minimized.

Owner

dvcrn commented Dec 11, 2015

Cool :) I'm actually very excited about this!
I will try to check it out tomorrow. Could you also edit the Layer README (and maybe include the mode keys for the clojure layer inside the clojure README but I could do that too after merge) to include your changes?

@geksilla

This comment has been minimized.

Collaborator

geksilla commented Dec 11, 2015

@dvcrn ok, will do.

@@ -35,3 +35,4 @@
(defmethod get-keybindings :git [] (get-keybindings :tools/git))
(defmethod get-initial-config :git [] (get-initial-config :tools/git))
(defmethod init-layer! :git [] (init-layer! :tools/git))
(defmethod describe-mode :git [] {})

This comment has been minimized.

@dvcrn

dvcrn Dec 14, 2015

Owner

We need to add the multimethod for :tools/git here. Changing this code to:

(defmethod describe-mode :git [] (describe-mode :tools/git))

Will make sure that backwards compatibility to the first version exists

@dvcrn

This comment has been minimized.

Owner

dvcrn commented Dec 14, 2015

Ah I just do that myself :) Merging this now

dvcrn added a commit that referenced this pull request Dec 14, 2015

Merge pull request #27 from geksilla/feature/mode-keybindings
Simple mode implementation + mode keybindings

@dvcrn dvcrn merged commit a2cd9cc into dvcrn:master Dec 14, 2015

@geksilla geksilla deleted the geksilla:feature/mode-keybindings branch Dec 22, 2015

dvcrn added a commit that referenced this pull request Mar 22, 2016

Merge pull request #27 from geksilla/feature/mode-keybindings
Simple mode implementation + mode keybindings
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment