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
Please see the new poll here: Which code editor or IDE do you use? (Poll) (2022 Edition) It’s been a while since we first asked this, I...
208 31695 143
New
PragTob
Hey everyone, this has been brewing in my head some time and it came up again while reading Adopting Elixir. GenServers, supervisors et...
New
New
wmnnd
The Go vs Elixir thread got me thinking: Would it be too hard to implement a simple mechanism for creating Go-style static app binaries f...
New
AstonJ
If so I (and hopefully others!) might have some tips for you :slight_smile: But first, please say which area you’re finding most challen...
New
thojanssens1
It would be nice to be able to define a redirect from one route to another from the router.ex file. E.g.: redirect "/", UserController, ...
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New

Other popular topics Top

KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36654 110
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New

We're in Beta

About us Mission Statement