Re: [vpp-dev] Some Emacs lisp to auto run indent on save.

2019-05-20 Thread Christian Hopps


Ray Kinsella  writes:


Hi Chris,

How does it differ from what is already available in extras.

https://git.fd.io/vpp/tree/extras/emacs/fix-coding-style.el

Is it the extra hook that triggers the functionality on save.


It looks like that file is adding those "INDENT-OFF/INDENT-ON" pairs around 
various coding patterns used by VPP.

My thing runs the buffer through the actual "indent" command (which is what VPP 
checkstyle is going to do) just prior to saving, and then it does it again. If the results are the 
same it changes the buffer to that result which is then saved. If the results are different it 
leaves the buffer (which is then saved) and it opens an error buffer with the diff between the two 
indent runs, as something in the code is giving the "indent" tool problems and probably 
needs to be wrapped in INDENT-OFF/INDENT-ON pair by hand.

FWIW, Emacs go-mode has this too, it can run the code through go-fmt prior to saving. You 
get used to this very quickly (i.e., write a bit of code not caring too much about 
indent, save, watch the buffer fix itself, or become odd looking which shows you 
immediately you forgot a ";" or something similar :).

Didn't know about that emacs dir, BTW. :)

Thanks,
Chris.




Ray K


On 19/05/2019 17:43, Christian Hopps wrote:

Hi vpp-devs,

Having gotten bit by a checkstyle failure on my first submission, I
decided to port the "go-like" functionality of auto-formatting the file
(using indent since that's what vpp uses) on file save in Emacs.. Here's
the lisp

 https://gist.github.com/choppsv1/c45a857ced56d4f9713eb7a555cfba2d

in case anyone would find it useful too. Personally, I like clang-format
better (as it appears to have deterministic results), but that's not
what the project chose. :)

FWIW, it only does the re-format on save if the file contains the magic
string:

 "fd.io coding-style-patch-verification: ON"

Thanks,
Chris.

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.

View/Reply Online (#13089): https://lists.fd.io/g/vpp-dev/message/13089
Mute This Topic: https://lists.fd.io/mt/31675798/675355
Group Owner: vpp-dev+ow...@lists.fd.io
Unsubscribe: https://lists.fd.io/g/vpp-dev/unsub  [m...@ashroe.eu]
-=-=-=-=-=-=-=-=-=-=-=-





signature.asc
Description: PGP signature
-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.

View/Reply Online (#13096): https://lists.fd.io/g/vpp-dev/message/13096
Mute This Topic: https://lists.fd.io/mt/31675798/21656
Group Owner: vpp-dev+ow...@lists.fd.io
Unsubscribe: https://lists.fd.io/g/vpp-dev/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-


Re: [vpp-dev] Some Emacs lisp to auto run indent on save.

2019-05-20 Thread Ray Kinsella
Hi Chris,

How does it differ from what is already available in extras.

https://git.fd.io/vpp/tree/extras/emacs/fix-coding-style.el

Is it the extra hook that triggers the functionality on save.

Ray K


On 19/05/2019 17:43, Christian Hopps wrote:
> Hi vpp-devs,
> 
> Having gotten bit by a checkstyle failure on my first submission, I
> decided to port the "go-like" functionality of auto-formatting the file
> (using indent since that's what vpp uses) on file save in Emacs.. Here's
> the lisp
> 
>  https://gist.github.com/choppsv1/c45a857ced56d4f9713eb7a555cfba2d
> 
> in case anyone would find it useful too. Personally, I like clang-format
> better (as it appears to have deterministic results), but that's not
> what the project chose. :)
> 
> FWIW, it only does the re-format on save if the file contains the magic
> string:
> 
>  "fd.io coding-style-patch-verification: ON"
> 
> Thanks,
> Chris.
> 
> -=-=-=-=-=-=-=-=-=-=-=-
> Links: You receive all messages sent to this group.
> 
> View/Reply Online (#13089): https://lists.fd.io/g/vpp-dev/message/13089
> Mute This Topic: https://lists.fd.io/mt/31675798/675355
> Group Owner: vpp-dev+ow...@lists.fd.io
> Unsubscribe: https://lists.fd.io/g/vpp-dev/unsub  [m...@ashroe.eu]
> -=-=-=-=-=-=-=-=-=-=-=-
> 



signature.asc
Description: OpenPGP digital signature
-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.

View/Reply Online (#13094): https://lists.fd.io/g/vpp-dev/message/13094
Mute This Topic: https://lists.fd.io/mt/31675798/21656
Group Owner: vpp-dev+ow...@lists.fd.io
Unsubscribe: https://lists.fd.io/g/vpp-dev/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-


Re: [vpp-dev] Some Emacs lisp to auto run indent on save.

2019-05-19 Thread Christian Hopps


Damjan Marion  writes:


On 19 May 2019, at 18:43, Christian Hopps  wrote:

Hi vpp-devs,

Having gotten bit by a checkstyle failure on my first submission, I decided to port the 
"go-like" functionality of auto-formatting the file (using indent since that's 
what vpp uses) on file save in Emacs.. Here's the lisp

https://gist.github.com/choppsv1/c45a857ced56d4f9713eb7a555cfba2d

in case anyone would find it useful too. Personally, I like clang-format better 
(as it appears to have deterministic results), but that's not what the project 
chose. :)


That was not the case some time ago when I was comparing outputs of 
clang-format 4.0 and 5.0. They were producing quite different outputs for GNU 
mode.
Maybe it is more stable today, but at that time it was quite bad...


Maybe it's better now, not sure. The case I ran into with indent was in 
ikev2.c, and clang format didn't have an issue with it (or the other files I've 
touched so far which admittedly is not that many).

#+begin_src c
  hash_set (
  km->per_thread_data[thread_index].sa_by_rspi,
  sa0->rspi,
  sa0 - km->per_thread_data[thread_index].sas);
#+end_src

The diff shows the results between first and second run of indent (the 
emacs-lisp I posted does 2 runs to make sure there are no diffs and doesn't 
perform the indent if so, but does display the diff).

#+begin_src diff
--- /tmp/vppfmt1sr7Cv3  2019-05-19 16:10:39.413561001 -0400
+++ /tmp/vppfmt248sTEv  2019-05-19 16:10:39.413561001 -0400
@@ -2168,8 +2168,9 @@
  pool_get (km->per_thread_data[thread_index].sas,
sa0);
  clib_memcpy_fast (sa0, &sa, sizeof (*sa0));
- hash_set (km->per_thread_data[thread_index].
-   sa_by_rspi, sa0->rspi,
+ hash_set (km->
+   per_thread_data[thread_index].sa_by_rspi,
+   sa0->rspi,
sa0 -
km->per_thread_data[thread_index].sas);
}
#+end_src


Thanks,
Chris.





FWIW, it only does the re-format on save if the file contains the magic string:

"fd.io coding-style-patch-verification: ON"


signature.asc
Description: PGP signature
-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.

View/Reply Online (#13092): https://lists.fd.io/g/vpp-dev/message/13092
Mute This Topic: https://lists.fd.io/mt/31675798/21656
Group Owner: vpp-dev+ow...@lists.fd.io
Unsubscribe: https://lists.fd.io/g/vpp-dev/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-


Re: [vpp-dev] Some Emacs lisp to auto run indent on save.

2019-05-19 Thread Damjan Marion via Lists.Fd.Io


> On 19 May 2019, at 18:43, Christian Hopps  wrote:
> 
> Hi vpp-devs,
> 
> Having gotten bit by a checkstyle failure on my first submission, I decided 
> to port the "go-like" functionality of auto-formatting the file (using indent 
> since that's what vpp uses) on file save in Emacs.. Here's the lisp
> 
> https://gist.github.com/choppsv1/c45a857ced56d4f9713eb7a555cfba2d
> 
> in case anyone would find it useful too. Personally, I like clang-format 
> better (as it appears to have deterministic results), but that's not what the 
> project chose. :)

That was not the case some time ago when I was comparing outputs of 
clang-format 4.0 and 5.0. They were producing quite different outputs for GNU 
mode.
Maybe it is more stable today, but at that time it was quite bad...

> 
> FWIW, it only does the re-format on save if the file contains the magic 
> string:
> 
> "fd.io coding-style-patch-verification: ON"

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.

View/Reply Online (#13090): https://lists.fd.io/g/vpp-dev/message/13090
Mute This Topic: https://lists.fd.io/mt/31675798/21656
Group Owner: vpp-dev+ow...@lists.fd.io
Unsubscribe: https://lists.fd.io/g/vpp-dev/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-


[vpp-dev] Some Emacs lisp to auto run indent on save.

2019-05-19 Thread Christian Hopps

Hi vpp-devs,

Having gotten bit by a checkstyle failure on my first submission, I decided to port the 
"go-like" functionality of auto-formatting the file (using indent since that's 
what vpp uses) on file save in Emacs.. Here's the lisp

 https://gist.github.com/choppsv1/c45a857ced56d4f9713eb7a555cfba2d

in case anyone would find it useful too. Personally, I like clang-format better 
(as it appears to have deterministic results), but that's not what the project 
chose. :)

FWIW, it only does the re-format on save if the file contains the magic string:

 "fd.io coding-style-patch-verification: ON"

Thanks,
Chris.


signature.asc
Description: PGP signature
-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.

View/Reply Online (#13089): https://lists.fd.io/g/vpp-dev/message/13089
Mute This Topic: https://lists.fd.io/mt/31675798/21656
Group Owner: vpp-dev+ow...@lists.fd.io
Unsubscribe: https://lists.fd.io/g/vpp-dev/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-