 One of the things I love about Emacs is I'm constantly discovering really cool tools that I can use to help improve my workflow. So since moving from Vim to Emacs, one of the things I really loved about Emacs is org mode. I write everything in org mode now, and I'm talking about everything. So things where, you know, I would use to write things in markdowns such as documentation or articles, essays, things like that. I do all of that in org mode now, but also I do all of my scripting and all of my programming using org mode now. And it really saves a lot of time because used to what I would do is I would write a script, you know, I'd write like a bash script, you know, using bash. And then I would also have to write like a documentation read me, like a readme.md, for example, to explain what the script does. Well, now if I just write the script using org mode, well, this org document serves as both the documentation page and it also serves as the script itself. So it's really, it's a really cool piece of technology org mode is. Now, let me show you exactly what I'm talking about by saving time, by not having to write both a readme documentation and the script itself. Let me go to a repository here on my GitLab DM scripts. I'll just pick this because I know that this has a readme and the readme is an actual markdown file. Readme.md. So I had to write this readme right in markdown. This is not the actual script. This is just documentation, right? Just something to explain what all the various scripts in this repository do. Now, that's okay. I mean, that's just the standard way to do things. But what org mode does, org mode does something completely different. Now, let me go to my .files repository here and then I'm going to go into .xmonad, which of course has the config files for xmonad, you know, my version of xmonad here. And typically what you would have in a directory like this is just source code. For example, the xmonad config xmonad.hs. But my xmonad config that I actually write and spend time on is actually readme.org. And because it's labeled as readme.org, when you go into this repository on GitLab or on GitHub, GitHub works the same way, it finds a readme, readme.org. And the readme.org is the readme, but it's also, you will notice, it's got source code blocks in it as well. So you've got the things outside of the source code blocks that serve as the documentation. And of course the things within the source code blocks gets outputted to the appropriate files, you know, where they need to get placed. In this case, the readme.org, all the source code blocks get outputted to xmonad.hs, which is the proper file, right, the config file for xmonad. So it's really nice. I don't have to write two different things. I don't have to write a readme.org and xmonad.hs. I write the readme.org and all the source code blocks within it get outputted to xmonad.hs. But I still have, you know, the readme with the table of contents and all of the comments I added and any kind of pictures or tables, you know, all the documentation kind of stuff. And that's really cool. And because of that, you know, I spend all of my time now basically writing org like everything I do. Let me open up my xmonadreadme.org here. Let's go to the top of the document here and I'm going to zoom in a little bit. And one of the things I've discovered recently having used Emacs in org mode for about two or three years now is there was an action that I was constantly performing that I really just wanted to be automatic and that is tangling the source code blocks. So in your org documents, you have a header here. And typically what you'll do in these like a readme.org kind of files, you will have a property tag and in that I'll put header-org space colon tangle. Tangle is referring to a org program called org babble tangle. And what tangle does, it takes the source code blocks. So within this document, there's going to be various source code blocks. Let me scroll down. You'll see begin source Haskell. So this is the beginning of a source code block and at the end of it, you'll have the ending source tag. It's going to take all of the various source code blocks within this and it will tangle them meaning write them, output them to a specific file that I tell it to output to. In this case, it needs to of course be outputted to xmoned.ages, which is the proper xmoned config file. And the command to run is org babble tangle, right? So typically I'll be writing this org document and then here inside evil mode, I'll write so I'll do colon w, you know, standard vim command to write, but that just writes the readme. I also need to then perform the org babble tangle so it gets written also to xmoned.ages, which I have org babble tangle. If I do a look up here, you will see org babble tangle. I have key-binded to space m capital B. So space m capital B would then run the tangle and you see tangled 14 code blocks from readme.org. So for the last couple of years, it's almost become automatic anytime I'm working in an org document, I do colon w and then space m capital B, right? I've got a lot of keystrokes there to basically save the file two different ways. First to actually save the org document and then also to save it as org babble tangle being written to whatever config file it also needs to be saved to. And I was thinking the other day, it needs to be automatic. Is there a way for Emacs to know anytime I'm working in an org document to just automatically tangle the file? And of course I do some digging around on the internet and of course people have already figured this out. Someone has written this very nice Emacs program called org auto tangle. And all org auto tangle is, is you add a couple of lines to your config file and what happens is now when I actually save an org document, it will automatically tangle it as well. And that's going to save me, I've probably done that colon w to write space m capital B to run org babble tangle thousands of times, tens of thousands of times in the last couple years. And I know it's a small thing, but it was something that I really think is going to drastically improve my workflow because I was starting to get kind of confused because I perform that action all the time working in org documents. But when I'm not in org documents, I found myself sometimes accidentally doing a colon w to write in this space m capital B to tangle, you know, a file that's not even an org file. You know, it's just a bash script or a Python script or something, you know, even plain text, right? I was trying to do a org babble tangle, it's not even an org file because I'm so used to doing that all the time working in those org documents. You know, it's one of those things I really, I needed this plugin. So to get this plugin installed, it was very simple. I'll show you exactly how I did this on doom Emacs. So let me get back into Emacs here. And let me first go to the packages.el file. So this is the doom Emacs config file packages.el where you list all the packages, the third party packages that you want to install, you know, they're not part of the base doom Emacs packages here. And you can see I have this line here package exclamation space and then org dash auto dash tangle is the name of the program. So you add that to packages.el. And then let me go to my doom config, which is config.org because my doom config is an org file, of course, right? And somewhere in here I have a section for org babble tangle. And really that should actually just be org auto tangle. And you can see all I needed to do was add this block here use dash package exclamation space org auto tangle. And then we have colon config. And then we have set you org auto tangle default. And you see that is set to t, which is true. So the default behavior is to always auto tangle. If I set this instead of t to nil for false, then the default behavior would be to not auto tangle. So having added org auto tangle to the packages.el and adding this few lines here of the config file. Now all I need to do is restart doom Emacs. So if I do a space hrr, it will install the org auto tangle package and reload our config. Now I've already actually done this, so just take a second to restart here. Now having gotten it installed and adding those lines to our config file, there's one other thing you actually need to do. You actually need to place a specific line to any org document that you want to auto tangle when you save. So let me go to a config file of mine that I already have that line in. So let me go to my DTOS repository here locally on my system because the DTOS installation script is actually a bash script, right? But I wrote it using org, so it's a literate config, right? So you've got comments, you've got a table of contents and various other things, but then you also have the bash source code blocks that are the actual script. And now you have the same kind of tags here. You have the property tag header dash orgs colon tangle. Where does it need to tangle the readme.org to? It needs to tangle it to DTOS because that's the name of the script. It's simply called DTOS. But now I have this line up under it. You see auto underscore tangle and t for true, meaning now instead of having to do colon w to write readme.org and then space m capital B to run the org babble tangle so it gets outputted to the script DTOS. Now just a simple colon w should do both for me and let's actually verify that this is the case. So let me do a vertical split here. What I'm going to do is in this vertical split over here, I'm going to actually go to the actual script, the DTOS script, I'm going to zoom in and I'm going to find a line and we're just going to edit something and we're going to see if the org auto tangle actually works. Let me go to the beginning of the actual script here. So I'm going to find this very first source code block. Let me zoom out a little bit in this one here. What I'll do, this line here dependencies colon the only dependency for the DTOS installation script is the dialogue program. But let's imagine that I added something else. I'm going to go ahead and add bash as a dependency because it's a bash script. So obviously bash is a dependency. I really don't need to add bash as a dependency because the script is designed for Arch Linux based systems and Arch, the default shell on Arch Linux is bash. So I really don't need this line, but I just want to see if I do a colon w and write readme.org, does it also write this to DTOS? Does it do the auto tangle? So let me escape and then do colon w to write the readme.org. And now if I go over to the DTOS file over here, let me give it focus. You can see it changes that buffer updates itself and now I have dialogue and bash. So now no longer do I have to do that annoying two key binding thing to save. No longer do I have to do a colon w to write to the org document and then space M capital B to run the org babble tangle. So it gets outputted to the appropriate files as well. Now I really am pretty excited about this because now all I need to do is I need to go into all of my various org documents that use org babble tangle. And I need to make sure I just add this simple line auto underscore tangle colon T for true. So I just wanted to share org auto tangle with you guys. I know it's a simple little program, but if you are Emacs user, you're probably a org mode user. And if you're a org mode user, you're probably just like me. You're constantly doing org babble tangle, running that command. And this simple little program is going to save you so many key presses. Like I think it should probably just be a default package, you know, like part of the greater org mode package. Like I think it's that important. Now, before I go, I need to thank a few special people. I need to thank the producers of this episode. Dustin Gabe James, Matt Maxim, Michael Mitchell, Paul West. Why you ballin' on me? Alan Armoredragon, Chuck Commander, Rangry, Diokai, Dylan Mastrum, Erion Alexander, Peace Archimdor, Polytech, Realiteats 4 Less, Red Prophet, Steven Tools, Devler, and Willie, these guys. They're my highest tiered patrons over on Patreon without these guys. This episode about org auto tangle would not have been possible. The show is also brought to you by each and every one of these fine ladies and gentlemen, all of these names you're seeing on the screen right now. And these are all my supporters over on Patreon because I'm sponsored by you guys, the community. If you like these kind of videos about Linux and Emacs and free and open source software, subscribe to DistroTube over on Patreon. All right guys, peace.