(77 comments)

We have switched from a custom, manually enforced style guide to using the clang-format tool. Our automated testing now fails with an error for pull requests that don't conform to the new clang-format style - it prints out a diff/patch of the changes necessary to conform with our coding style.

Formatting Your Code

You will need to have clang 3.9 or later installed. If your clang install is from the MOOSE environment package (i.e. the ones downloadable via the links on http://mooseframework.org/getting-started/) and you use Linux, you may need to upgrade to the newest MOOSE environment package version in order for clang-format to be available in your PATH. Many text editors have plugins and support for automatically running clang-format on the files you edit. We recommend using those. For example:

If you wish, you can also install a pre-commit hook that will prevent you from committing changes that don't comply with the new style. To install this hook, run the scripts/install-format-hook.sh script in the MOOSE repository.

You can manually run git clang-format [<commit>] to automatically format files changed since <commit> (or HEAD if omitted). You can also run clang-format -i [<file>...] to update the desired files. We recommend making sure your files comply with the clang-format style on every commit.

Updating In-flight Changes

Changes (pull requests, branches, etc.) that were started before we reformatted our codebase will have a lot of conflicts when attempting to merge into or rebase with the new mainline code. We have provided some tools to aid in this process. First you will need to install a custom git configuration by running (in the main MOOSE repo):

./scripts/install-clang-format-merge-hook

Then make sure ./scripts/clang_format_merge_driver is in your PATH. To rebase a branch onto the newly formatted MOOSE mainline devel branch run the rebase command like normal, e.g.:

git checkout [your-branch]
git checkout devel
git pull upstream devel
git checkout [your-branch]
git rebase devel
... # continue rebase like normal resolving any conflicts

Running a merge like normal will also use the the special clang-format merge driver.

Helpful Emacs Configuration

; Note: This hardcoded path will likely change in the future
; Need to set a variable or copy this file to a new location
(load "/opt/moose/llvm-3.9.0/share/clang/clang-format.el")
(global-set-key [C-M-tab] 'clang-format-region)


(if (null (getenv "MOOSE_DIR"))
    (setq MOOSE_DIR "~/projects/moose")
    (setq MOOSE_DIR (getenv "MOOSE_DIR")))

(setq my-moose-style-path-alist (list (expand-file-name MOOSE_DIR)))

(add-hook 'c++-mode-hook (lambda ()
                    (dolist (path my-moose-style-path-alist)
                  (if (string-match path (buffer-file-name))
                      (add-hook 'before-save-hook 'clang-format-buffer)))))
Current rating: 3

Comments

AndyW 2 years, 2 months ago

This worked for me, with a reasonably up-to-date moose environment package on Mac, but only after I updated emacs from 22.1.1 (which i think comes with MacOSX) to a later version (i chose 25.1.1).

Link | Reply
Currently unrated

AndyW 2 years, 2 months ago

Drat, i spoke too soon. The C++ mode hook is too eager. If I start emacs with a .C file, and then load a .tex file, it reformats the .tex file upon saving it as if it were C++ code. Help!

Link | Reply
Currently unrated

Cody 2 years, 2 months ago

Andy,

I had the same problem at first. The problem was that I had another before-save-hook active lower in my .emacs file to remove trailing whitespace on save. I'm not sure why that mattered but I moved that up above this new configuration and the over-aggressive behavior went away. It doesn't make any sense by that would be the case but it fixed it. Check and see if you have any other active hooks.

Link | Reply
Currently unrated

AndyW 2 years, 2 months ago

My .emacs contains only what you typed above.

Link | Reply
Currently unrated

AndyW 2 years, 1 month ago

I think
```
(add-hook 'before-save-hook 'clang-format-buffer)
```
should be replaced by
```
(add-hook 'before-save-hook 'clang-format-buffer nil 'make-it-local)
```
Works for me anyway.

Link | Reply
Current rating: 5

AlexL 2 years, 1 month ago

I get the same undesirable behavior as Andy (haven't tried his fix yet) when putting the clang-formatting logic at the bottom of my .emacs and saving even a .gitignore file in a totally different directory! I'm bamboozled for a variety of reasons...shouldn't this just be a c++ mode save-hook? And shouldn't that lisp logic be matching against the MOOSE path such that I shouldn't see this if I'm in a totally different directory?? Weird.

Link | Reply
Currently unrated

AlexL 2 years, 1 month ago

+1 for Andy's change

and thanks guys for putting this formatting out there. It's pretty cool stuff.

Link | Reply
Currently unrated

DanielS 2 years ago

For Atom this works very well: https://atom.io/packages/clang-format

Link | Reply
Currently unrated

worldstar hiphop 2 years ago

nice article i really loved it!!

Link | Reply
Currently unrated

pre owned machines 1 year, 9 months ago

The government should take some steps accordingly to keep the air free of danger.

Link | Reply
Currently unrated

happy birthday 2 years ago

happy birthday wishes
happy birthday greetings

Link | Reply
Currently unrated

check cashing 1 year, 12 months ago

thanks guys for putting this formatting out there.<a href="http://www.unitedcheckcashing.com/store-details/2848">check cashing</a>

Link | Reply
Currently unrated

BBA College in Punjab 1 year, 11 months ago

These are really a superb showcases here I am glad to have a review of it and feel to roll on its steps for my benefit always

Link | Reply
Currently unrated

https://www.rprogramminghelp.com/ 1 year, 10 months ago

Thanx for sharing such useful post keep it up

Link | Reply
Currently unrated

panddora estore 1 year, 9 months ago


Great Article it its really informative and innovative keep us posted with new updates.

Link | Reply
Currently unrated

https://www.lampungservice.com 1 month, 3 weeks ago

Thx u

Link | Reply
Currently unrated

panddora estore 1 year, 9 months ago

Great Article it its really informative and innovative keep us posted with new updates.

Link | Reply
Currently unrated

getwifipassword 1 year, 9 months ago

I loved the way you discuss the topic great work thanks for the share.Thanks!

Link | Reply
Currently unrated

live tv 1 year, 7 months ago

Once You the search for live tv apps for android or iOS for free, there is plenty of apps are available, but Most of the apps on google are paid versions except Mobdro online tv app.All the features of mobdro can be enjoyed on free version App

Link | Reply
Currently unrated

Write my Assignment for me 1 year, 6 months ago

We reformatted our codebase will have a lot of battles when endeavoring to combine into or rebase with the new main code.

Link | Reply
Currently unrated

Assignment Services 1 year, 6 months ago

Having a steady coding style is critical, yet it can likewise be a torment to depict and sets aside opportunity to go over in code surveys. Clank organize is one code arranging instrument I have been following for a long while now, alongside a few of its forerunners.

Link | Reply
Currently unrated

driving direction 1 year, 5 months ago

I think this is an informative post and it is very useful and knowledgeable. I really enjoyed reading this post. big fan, thank you!

Link | Reply
Currently unrated

iTube Mobi 1 year, 5 months ago

I used this clang format style on my website related to music downloads for android nameda iTube.Mobi.

You can download the APK file of iTube android music downloader App then you can see the format style.

Thanks.

Link | Reply
Currently unrated

Rohan Khanna 1 year, 5 months ago

Hello Friends, Check out best-musicdownlaoder.com for some best music downloader apps

Link | Reply
Currently unrated

chase phone number 1 year, 5 months ago

Great artcile, yet it would be better if in future you can share more about this subject. Continue posting.

Link | Reply
Currently unrated

happy wheels 1 year, 5 months ago

I would like to thank you for the efforts you have made in.

Link | Reply
Currently unrated

geometry dash 1 year, 5 months ago

The game is best known for its dark sense of humor and its graphic violence

Link | Reply
Currently unrated

dumb ways to die 1 year, 5 months ago

I am hoping the same best work from you in the future as well.

Link | Reply
Currently unrated

fireboy and watergirl 4 1 year, 5 months ago

I really appreciate your work. Thanks for you agree for me.

Link | Reply
Currently unrated

Digital Media Agency Pakistan 1 year, 4 months ago

Good way of telling, good post to take facts regarding my presentation subject matter, which i am going to deliver in my college

Link | Reply
Currently unrated

Case Study Solution 1 year, 4 months ago

I’m really impressed with your article, such great & usefull knowledge you mentioned here

Link | Reply
Currently unrated

cool math games 1 year, 3 months ago

I really like your point you have written very amazingly. Thanks for sharing your information with everyone and keep posting

Link | Reply
Currently unrated

color switch 1 year, 3 months ago

Oh! This article has suggested to me many new ideas. I will embark on doing it. Hope you can continue to contribute your talents in this area. Thank you.

Link | Reply
Currently unrated

playview 10 months, 4 weeks ago

Do you have any idea about PlayView apk? If you are new to this application then you can gather sufficient data from the content discussed

Link | Reply
Currently unrated

JSON validator 10 months, 3 weeks ago

I really appreciate this post. I've been looking all over for this!

Link | Reply
Currently unrated

<a href="https://www.google.co.uk/">Blog</a> 6 months, 3 weeks ago

nice bro

Link | Reply
Currently unrated

Blog 6 months, 3 weeks ago

Great Post and interesting.

Link | Reply
Currently unrated

happy anniversary to my wife 6 months ago

When i open the Give food to it provides me with many different garbled text, may be the concern on my small end?

Link | Reply
Currently unrated

windows 10 5 months, 3 weeks ago

Interesting blog. You wrote emotionally and beatifully. I enjoy reading it.

Link | Reply
Current rating: 4

Çeyrek Altın Kaç Gram 5 months, 3 weeks ago

CUMHURİYET ALTINI, devlet güvencesi altında, Darphane ve Damga Matbaası Genel Müdürlüğü tarafından basılmakta olup, değişik boyut ve ağırlıkları olan

Link | Reply
Current rating: 5

hava durumu 5 months, 2 weeks ago

12 Eylül Çarşamba günü Ege’nin iç kesimlerinde antalya hava durumu Denizli, Kütahya, Uşak ve Muğla’da hava durumu bölgesel gök gürültülü sağanaklar bekleniyor. 13 Eylül’de bu yağış bölgenin izmir hava durumu tamamına yayılacak. kesintili gök gürültülü sağanaklar 12-13-14 Eylül’de de devam edecek. Güneydoğu Anadolu bölgesi genelinde çoğunlukla güneş görülüyor. ankara hava durumu Ege bölgesinde hava parçalı bulutlu, dolayları 32 dereceleri ölçüyor.

Link | Reply
Currently unrated

ebook-gratuit.ws 5 months, 1 week ago

Thank you for sharing all this amazing information. absolutely perfect.

Link | Reply
Currently unrated

namaz vakitleri 5 months, 1 week ago

Bursa namaz vakitleri Bir bakıma küçük bir kongre olan Cuma namazı vesilesiyle bir araya gelen kardeşler, bu birliktelik sayesinde güçlenerek ayrılırlar. Haftada bir gün gerçekleşen bu kongre onları bir hafta boyunca canlı ve dinamik tutar.Allah Teâlâ, Mümin’dir; güven veren, izmir namaz vakitleri www.namazvakitler.com kendisine güvenenleri korkudan emin kılandır. Gönlünü açanlara iman bahşedendir. Müheymin’dir; her şeyi görüp gözetendir.

Link | Reply
Currently unrated

192.168.0.1 login 5 months, 1 week ago

I just want to say that this was simple.

Link | Reply
Currently unrated

My pham nhat 4 months, 3 weeks ago

I just want to say that this was simple.

Link | Reply
Currently unrated

my pham han quoc 4 months, 3 weeks ago

Thank you for sharing all this amazing information. absolutely perfect

Link | Reply
Currently unrated

hotmail login 4 months, 3 weeks ago

Hotmail is free webmail service provided by Microsoft, basically this email design for corporate and professional use. Start hotmail login account now.

Link | Reply
Currently unrated

Visit Website 3 months ago

Thank You for Posting Article. You just want to let you know just before the check out your site and you find it very interesting and informative.

Link | Reply
Currently unrated

Quality Cinema 2 months, 3 weeks ago

Informative post! I am actually getting ready to across this information, is very helpful me.

Link | Reply
Currently unrated

buat toko 2 months, 3 weeks ago

Probably the best and most professional tech blog in Indonesia: www.caramembuatwebsiteku.com

Link | Reply
Currently unrated

online blackjack 2 months, 2 weeks ago

Really interesting post. This kind of information very useful for me and reading to easy. Thank you for your assistance.

Link | Reply
Currently unrated

today bd job circular 2 months, 2 weeks ago

Great information. Thanks for sharing.

Link | Reply
Currently unrated

web designing company 2 months, 2 weeks ago

web designing company

Link | Reply
Currently unrated

web designing company 2 months, 2 weeks ago

web designing company

Link | Reply
Currently unrated

Kem chống nắng Neutrogena Beach Defense SPF70 2 months, 2 weeks ago

Kem chống nắng Neutrogena Beach Defense SPF70

Link | Reply
Currently unrated

sewa mobil lepas kunci bandung 2 months, 1 week ago

We have switched from a custom, manually enforced style guide to using the clang-format tool.

Link | Reply
Currently unrated

bubble shooter 2 months, 1 week ago

I like your blog post. Keep on writing this type of great stuff. I'll make sure to follow up on your blog in the future.

Link | Reply
Currently unrated

vize başvurusu kaç günde sonuçlanır 2 months, 1 week ago

This is staggering post here. This sort of data creature for me and looking focal.

Link | Reply
Currently unrated

sri lanka jobs 2 months ago

Much a devotion of gratefulness is all together to make such a stunning article on this point. This has truly made me think and I should need to tie additional.

Link | Reply
Currently unrated

adult diapers 2 months ago

I am impacting about your article and imagine your method to deal with our record. Grateful to you for sharing.

Link | Reply
Currently unrated

kem chống nắng Innisfree No Sebum 1 month, 4 weeks ago

Là kem chống nắng vật lý, kem chống nắng Innisfree No Sebum chính là sản phẩm thích hợp cho mọi cô nàng sở hữu làn da dầu hay hỗn hợp thiên dầu. Với khả năng chống nắng lên đến 35 PA+++, kem chống nắng Innisfree No Sebum vừa có thể giúp bạn chống nắng lại vừa có khả năng kiềm dầu

Link | Reply
Currently unrated

hoteis em bonito 1 month, 3 weeks ago

This is a stunning site zone. This sort of data strong for me and looking major. We are to make certain grateful for your blog limit. An obligation of appreciation is all together for the offer.

Link | Reply
Currently unrated

heavy duty towing Joliet IL 1 month, 3 weeks ago

This is a shocking post. I like this subject. This site has heaps of favored edge. I found diverse enchanting things from this site. It causes me from various points of view. A commitment of gratefulness is all together to post this over once more.

Link | Reply
Currently unrated

top 10 tarte mascara 1 month, 1 week ago

Your post is uncommon and lighting up. You have genuinely shared an instructive and captivating site segment. Thankful to you for sharing this article. I should need to get more posts.

Link | Reply
Currently unrated

Jasa Konveksi Online 1 month ago

Artikel yang bagus

Link | Reply
Currently unrated

tv advertising music 4 weeks, 1 day ago

Thanks for sharing,

Link | Reply
Currently unrated

Alexander Riley 4 weeks ago

Downloaded my clang from moose,made it easier.
very informative
Alexander Riley from <a href="https://rubbleremovalexperts.co.za"> Rubble Removal Experts</a>

Link | Reply
Currently unrated

Alexander Riley 4 weeks ago

very informative
Alexander Riley from <a href="https://rubbleremovalexperts.co.za"> Rubble Removal Experts</a>

Link | Reply
Currently unrated

Mitchell Robinson 4 weeks ago

I will definitely try it in my blog.

Link | Reply
Currently unrated

Bangalore to Mysore Train Timings 3 weeks, 5 days ago

Nice Article it is good to learn new thing from you Thaks for sharing

Link | Reply
Current rating: 4

gamestore 3 weeks, 1 day ago

Hello Thanks for share

Link | Reply
Currently unrated

릴게임 2 weeks, 4 days ago

The submit is fantastic and also useful. This type of details invaluable for me personally and also studying to be able to effortless. Many thanks regarding revealing this informative article. I am hoping to obtain a lot more content.

Link | Reply
Currently unrated

Anothony R Rocca 2 weeks ago

Don't you want your business to be explored in front of thousands of eyeballs? Check this out only if you're serious to get it exposed online.

Link | Reply
Currently unrated

Download Aadhar Card 1 week, 6 days ago

Woahhh! The Most Awesome Post I Have Ever Read ??
Thanking you will not be enough. This is really good. You are just exceptional.
Keep doing the good work ??


Link | Reply
Currently unrated

Best iPhone Apps Ever 1 week, 3 days ago

This text can be quite significant not to mention I'm sure expecting perusing further with the items. I am aware I’m a little bit of latter through post your short review the piece of writing was basically to the situation and then the data I just had become in search of. Are you aware of each and every ınternet sites on that topic area.

Link | Reply
Currently unrated

Pele Rivaldo 6 days, 12 hours ago

Thus, it is basic to find the manifestations of ineptitude, so you can have better capacity to get a compelling treatment.

Link | Reply
Currently unrated

بوتوكس المعده 4 days, 10 hours ago

I actually enjoy upon subjects you actually posting listed here. With thanks to get discussing an awesome details that is definitely essentially useful. I actually take a look at your website daily plus aim to master anything through the website. Thanks a ton plus ready for your personal innovative posting.

Link | Reply
Currently unrated

New Comment

required

required (not published)

optional

R&D 100

Recent Blog Posts

Using our new clang-format Style

2 years, 2 months ago

Steady State Algorithm Change

2 years, 11 months ago

Making an App inherit from an App

2 years, 12 months ago

Changing a published API (Deprecation)

3 years ago

DiscreteMaterial Objects

3 years, 2 months ago

Recent Posts

Archive

2017
2016
2015
2014

Tags

Authors

Feeds

RSS / Atom