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
There should be no option at all (by default it is set). So this will work now with updated instruction.
4
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.
3
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].*)$
2
Popular in Discussions
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
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
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...
New
Phoenix Live View is now publicly available on GitHub.
Here’s Chris McCord’s tweet announcing making it public.
New
I wanted to capitalize a string, and tried using String.capitalize().
That generally works well, until you try to capitalize a word like...
New
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
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
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
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
Phoenix 1.4.0 released
Phoenix 1.4 is out! This release ships with exciting new features, most notably
with HTTP2 support, improved deve...
New
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
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...
New
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
Chat & Discussions>Discussions
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #hex
- #security









