Naming my macros in Emacs

I love using macros in Emacs, they help me speed up several tasks in a regular basis. Writing a macro is a relative easy thing to do and a topic for another article. What I want to talk about today is how and why you could name a macro. If you don't know what a macro is, the concept is simple, it's a sequence of actions that can be recorded and reused later. [Read More]

Splitting a Ruby Array in equal parts

I'm working on a personal project that involves calendars. One of the features I wanted was to be able to print a calendar like this: | Mon | Tue | Wed | Thu | Fri | Sat | Sun | |-----+-----+-----+-----+-----+-----+-----| | 1 | 2 | 3 | 4 | 5 | 6 | 7 | | 8 | 9 | 10 | 11 | 12 | 13 | 14 | | 15 | 16 | 17 | 18 | 19 | 20 | 21 | | 22 | 23 | 24 | 25 | 26 | 27 | 28 | For that I needed to split a 28-ish Array into 4 or 5 rows (weeks). [Read More]

Re-indent the entire buffer in Emacs

One of the tasks I leave entirely to my editor is indentation. I don't like at all to indent by hand, except for the current line, but once I have two lines out of place, I tell Emacs to handle it for me. For that reason I've written this simple command (defun fdx/reindent-buffer () "Indent the current buffer." (interactive) (delete-trailing-whitespace) (indent-region (point-min) (point-max)) (untabify (point-min) (point-max))) This will select the whole buffer and apply the correct indentation, cleaning white-spaces in the process. [Read More]

Captureception

Today I was bored and my playful mind presented me with an idea I'm starting to use org-capture for lots of things, what if I create a capture entry for new capture entries? and that's what I did. It took me some time and didn't end up quite perfect, but good and useful enough. Assumptions We'll be using a plain type and use a non-org file as the target, so we are going to have to navigate and edit the file using elisp, and this assumes a specific structure. [Read More]

Listing all branches of the current repository using Magit

At work, I have a git project with several branches, one for each feature or bug I'm currently working on. Once in a while I like to clean those up in order to keep my sanity. In the interest of performing that cleanup, I went looking for a command to list all branches in Magit. I found magit-show-refs-popup, which brings a pop-up window (or panel if you're not used to Emacs's terminology) that lists all refs. [Read More]

Capturing files

So far we've been using org-capture to capture notes. To do this we set a template and indicate in which file to put it. But we do this in a static way, by providing the exact place we want it as a hardcoded string. (setq org-capture-templates '( ("i" "Post idea" entry (file "~/Dropbox/wordpress_rake/IDEAS.org") "* %?\n") ("w" "Woodworking project" entry (file "~/Dropbox/org-files/woodworking_projects.org") "* TODO %?\n") )) When I first learned to use org-capture, the main use case I wanted for it was to write blog posts. [Read More]

org-capture templates

We've talked about how to configure org-capture and the types of captures we can create. On that second topic, we showed the default templates for each type of note. On this article, we'll focus on templates. To lay out a definition, a template is the chunk of text that will be inserted by default into our note. They work as I've shown on the first part of this series, by adding a string as the fourth parameter for a note type: [Read More]

org-capture note types

On the last post we learned how to use and do a basic configuration for taking notes using org-capture. Today we'll explore capture templates. If you recall, on the previous article, you can add a new type of note like this (setq org-capture-templates '( ("k" "Entry description" entry (file "/path/to/file.org") "Template") )) The inner most list represents the note and it has five elements Key The key used to invoke the template after calling org-capture Description The description that'll be shown for the note type Type The type of note Target Target location for where the note should be written to Template The template for the note. [Read More]

Capture ideas and more with org-capture

I've recently started using org-capture. I heard great things about it long ago but never dag in on what it was, until I recently watched Rainer König's series on Getting yourself organized with OrgMode, which I can't recommend enough. In this article I'll explain how I understand it and use it. I'll leave a trick on the sleeve for a future post. What is org-capture? org-capture is a way to take notes in Emacs in an unobstructive way. [Read More]

Automatically refreshing files in Emacs

I like my editor to auto-refresh the file I'm visiting if it has changed on disc. To give a simple example, I tend to run the pessimize command after installing dependencies for a project. This adds version numbers to the project's Gemfile. But I usually do this right after adding or removing a gem from the file, which means it's almost a fact that the file will be opened in a buffer on Emacs. [Read More]