hauleth

hauleth

PSA - Elixir function declaration support in Git

I do not know how many of you have ever noticed that git diff shows current scope in the diff header. This is called hunk and can be useful in long diffs. The problem is that Elixir is not a language that is supported OOtB (no surprise there), but do not worry, with some Git-fu you can get it today. Installation is simple:

$ mkdir -p ~/.config/git
$ echo '*.ex diff=elixir' >> ~/.config/git/attributes
$ echo '*.exs diff=elixir' >> ~/.config/git/attributes
$ git config --global diff.elixir.xfuncname '^[ \t]*((def(macro|module|impl|guard|protocol)?p?|test)[ \t].*)$'

And change your diffs from this:

@@ -474,7 +472,7 @@
   """
   @spec reset_metadata(metadata) :: :ok
   def reset_metadata(keywords \\ []) do
-    :logger.set_process_metadata(%{})
+    :ok = :logger.set_process_metadata(%{})
     metadata(keywords)
   end
 

To this

@@ -474,7 +472,7 @@ def metadata() do
   """
   @spec reset_metadata(metadata) :: :ok
   def reset_metadata(keywords \\ []) do
-    :logger.set_process_metadata(%{})
+    :ok = :logger.set_process_metadata(%{})
     metadata(keywords)
   end
 

The difference is in first line of the snippets if you missed that.

Most Liked

hauleth

hauleth

There should be no option at all (by default it is set). So this will work now with updated instruction.

hauleth

hauleth

This feature have landed in Git 2.25 which has just landed. So after update to newest Git it will be a built in.

Eiji

Eiji

@hauleth: For me it gives:

$ git config --global --set diff.elixir.xfuncname '^[ \t]*((def(macro|module|impl|guard|protocol)?p?|test)[ \t].*)$'
error: unknown option `set'
# here the git config usage is displayed

I think that it should be --add instead of --set.

My result:

$ git config --global --add diff.elixir.xfuncname '^[ \t]*((def(macro|module|impl|guard|protocol)?p?|test)[ \t].*)$'
$ git config --global --get diff.elixir.xfuncname
^[ \t]*((def(macro|module|impl|guard|protocol)?p?|test)[ \t].*)$

Where Next?

Popular in Discussions Top

AstonJ
I’ve just started the Phoenix part of the utterly brilliant online course by @pragdave. On generating the Phoenix app he uses the --no-ec...
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 40042 209
New
slashdotdash
Phoenix Live View is now publicly available on GitHub. Here’s Chris McCord’s tweet announcing making it public.
New
mikl
I wanted to capitalize a string, and tried using String.capitalize(). That generally works well, until you try to capitalize a word like...
New
pillaiindu
I want to convert a Phoenix LiveView CRUD website to a CRUD mobile app. What do you think is the easiest way to do so?
New
crispinb
On reading dhh’s latest The One Person Framework it strikes me that Phoenix with LiveView is already pretty much this. However, never hav...
New

Other popular topics Top

baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 31494 112
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 49084 226
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New

We're in Beta

About us Mission Statement