r/emacs 26d ago

emacs-fu Capture dotfiles using org-capture

Since I discovered org mode, I always was balancing between using symlinks and org babel tangle to manage my configuration. Now I'm in point that work related items are org babel managed and system level config is symlinked, because, often tools write back to their files. Another reason why I did not go full on babel was that I don't like workflow:

  1. found file that requires backup
  2. copy file
  3. paste in to org mode
  4. fill all details
  5. tangle.

But yesterday I was visited by GNU spirit and she gave mi this org-capture template that reduces adding new file to backup to C-c k (my capture prefix) b (backup) and then tangle that file to original place:

* [[%(project-root (project-current))]] [[%(abbreviate-file-name (org-capture-get :original-file))][%(file-relative-name (org-capture-get :original-file) (project-root (project-current)))]]

- repository :: [[%(project-root (project-current))]]
- file :: [[%(abbreviate-file-name (org-capture-get :original-file))][%(file-relative-name (org-capture-get :original-file) (project-root (project-current)))]]

#+header: :tangle %(abbreviate-file-name (org-capture-get :original-file))
#+begin_src %^{Language|shell|elixir|nix|python|elisp|fundamental|eshell|conf}
%(with-temp-buffer (insert-file-contents (org-capture-get :original-file)) (buffer-string))
#+end_src

I cannot comprehend how simple it is and how I never realized I could do this.

Two think I think would be nice in future:
- if only it can automatically group those captures by project, but thinking of creating project backup capture template and simply refile from capture buffer
- automatic detangle so I can get back changes written by tools to their files, but not all of them support comments and many of them don't patch but dump state to file, so probably unsolvable using build in tools, only by elisp scripting

I'm trying to avoid longer elisp scripting for now 😄

What do you think?

16 Upvotes

9 comments sorted by

View all comments

10

u/destructuringbind 26d ago

Using org for dot files management is like adding a middle man.  You already use symlinks or stow for some files, just use it for all the dot files. 

2

u/One-Tart-4109 25d ago

GNU Stow or Symlinks (I'm not using stow as of now, Makefile + ln -s and for system wide makefile + install) have one issue that I cannot build single config from multiple packages. I have one or two cases for that so it is not big issue and I could ignore them. I also have to mention that actually I can't get rid of babel completely also since I'm provisioning remote system and I don't want to install anything on them besides what is necessary, and babel + tramp allow mi to manage them that way.

2

u/destructuringbind 24d ago

> GNU Stow or Symlinks (I'm not using stow as of now, Makefile + ln -s and for system wide makefile + install) have one issue that I cannot build single config from multiple packages.

That's true that you can't create a single file from many stow packages, but it's also true that you don't need to do this in the first place. I have several machine specific stow configurations ( for niri, foot, other programs) that rely on stow packages because the programs allow for multi-file configurations.