Emacs org-mode

Welcome to the Emacs org-mode category.

You can subscribe to this category only via RSS!

I am working on restoring some of my related posts from my old blog, so keep checking here for new content.

Auto-generated description: A mythical creature resembling a satyr with glasses is sitting cross-legged in a forest setting, holding a glowing orb in front of a laptop.

    Emacs Config Gems - Part 3

    My actual configs start with pretty usual stuff you’d see across many other Emacs configs. As I was going through these however, I started to wonder how things work and why they ended up the way we have them today. In turn, that led to reading about the intention behind those, which led to more options I didn’t think about. Also, it’s kind of fun. I’ve made two more passes for this part alone in the last couple of weeks, and I could probably go for a third. When reading this post, if you want the good stuff (in my opinion), get lost in the footnotes as I did. There’s a lot to explore. I just scratched the surface.

    Load Melpa

    Melpa is where many Emacs packages live. The story behind it (from what I can tell) revolves around one of Emacs’ maintainers, Bozhidar Batsov, who pointed to Melpa at some point in 2012, when Emacs’s then go-to third-party package repository went offline. He is not its creator โ€” Melpa has been around before this post โ€” but this seems to be the turning point where Emacs package maintainers started to really use it. I don’t have good coder/repository maintainer knowledge, but from what I read, it’s built on the same idea as Homebrew (for Mac), which was familiar to many of the Emacs folks at the time.

    So let’s get Melpa:

    (require 'package)
    (add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
    

    UI and Fundamental Emacs tweaks:

    Most Emacs folks with a config file like this like to kill the toolbar, scrollbar, and menu bar. I find that the menu bar makes Emacs look more like the other programs, especially in macOS1. Besides, it’s nice to look every now and then and be reminded of good Emacs kung-fu I forgot exists (org-sort, I’m sorry my friend, I’ll keep saying hi more often).

    This is why the menu-bar is commented out in my config; I want it, but I also want to remember I could turn it off if I wanted:

    (tool-bar-mode -1)
    (scroll-bar-mode -1)
    ;; (menu-bar-mode -1) 
    

    By default, help commands2 display the help buffer in a new window without selecting it. I find this annoying: if I bring up the help window, it’s usually because I want to scroll down to find something or copy (yank) something. On the other hand, if I just want to skim quickly in the help buffer, it’s helpful that the marker is on it for a quick q for quit.

    In addition, we want to be able to navigate help menus as Emacs intended if we follow the links in a help buffer. help-window-keep-selected allows us to keep help in its own dedicated window, so it won’t open in a separate window once we follow a link. Going back to the original is the same as we do in other browser-like buffers in Emacs, with l (like in Eww, for example). Likewise, we can go forward with r. I should also expand here on various help options; they definitely deserve a mention, but this is another huge topic (you can get an idea from the footer) that will take a couple of weeks. I will come back to this someday.

    (setq help-window-select t)
    (setq help-window-keep-selected t)
    

    Lisp is full of parentheses, and it’s easy to lose track. Turning show-paren-mode on means that standing on an open or closed parentheses highlights its matching counterpart, which is handy.

    In addition, while we’re here: when we stand on an expression that is only showing a portion of an expression (meaning, we need to scroll down to see the rest) Emacs can highlight the expression for us to make sure we don’t get confused โ€” this is the mixed option below for show-paren-style. If you want to see the whole expression highlighted every time you’re on it, there’s the option expression, which I’m leaving here for reference for myself. For now, I think it’s too much visual noise, especially since we’re using org-edit-special, which also highlights what we’re working on.

      (show-paren-mode t)
      (setq show-paren-style 'mixed)
    ;; (setq show-paren-style 'expression)
    

    And now, a true Emacs classic. I don’t think I’ve seen a config without it: shortening “yes” or “no,” answer to “y” or “n” like any other program known to mankind. use-short-answers was introduced in Emacs 28.1, which is a more graceful way to do this, intended exactly for this purpose. Before that, back when I started to use Emacs, it was done with (fset 'yes-or-no-p 'y-or-n-p). If you have an older Emacs version, you’d need it.

    ;;  (fset 'yes-or-no-p 'y-or-n-p)
    (setq use-short-answers t)
    

    This one was annoying until I learned this option exists from someone else’s config years ago: “Emacs, please stop asking me if I want to kill process when exiting Emacs (Shell, etc.), just do it!” Yep.

    (setq confirm-kill-processes nil)
    

    Emacs has two annoying keyboard shortcuts that I should have disabled as soon as I started using it: C-x C-c (exit Emacs) and C-z (minimize Emacs). Both of them are too easy to press by mistake, especially C-z, which is undo in many other programs. If I had a penny for each time I minimized Emacs by mistakeโ€ฆ When we want to minimize Emacs (and why would you want to do that? Emacs deserves a prominent space on your screen), we can just do it by clicking the minimize window itself, shamefully using our mouse, as we do with other apps. And Exiting Emacs? With a shortcut that seems like it fits somewhere in org-mode? No thanks. Let’s disable those:

    (global-unset-key (kbd "C-x C-c"))
    (global-unset-key (kbd "C-z"))
    

    Turn off the annoying error beep, which I first discovered in SUSE Linux by turning on a visual warning (a flash) instead. This will flash the top and bottom lines of our window instead of going “beep!”

    (setq visible-bell t)
    

    Turn on visual line mode so text lines “wrap” inside the frame and don’t continue beyond the window’s edge. This is essential; I can’t read in Emacs without it. And a newcomer I discovered recently: since Emacs 30, we also have global-visual-wrap-prefix-mode, which preserves indentation on wrapped lines. For example, in a list in org-mode (made of dashes one under the other), a long line of text that wraps will align under its starting point (dash) in the list instead of jumping back to column 0 (the start of the window, to the most left). This has been a huge pet peeve. Finally!

    (global-visual-line-mode t)
    (global-visual-wrap-prefix-mode t)
    

    Winner mode (included in Emacs) is sort of “undo” for changes in windows’ layout in Emacs. C-c โ† goes back to our previous setting, and C-c โ†’ will “redo” the layout we just left. I use it all the time as in “oops, I closed the wrong window”3.

    (winner-mode t)
    

    Saw this over at https://emacsredux.com/blog/2026/04/07/stealing-from-the-best-emacs-configs/. This is a nice little trick, and it requires a bit of reading to understand what exactly it does: preventing Emacs from deleting whatever we have in the system’s clipboard when we kill a line, so it’s still in the kill ring. Here’s an example to help you grasp the idea and why it’s useful:

    1. We’re visiting a website with our default browser and copy its URL because we want to write about it in Emacs
    2. We go to Emacs, and we kill the line we’re on because we need some space
    3. Crap! Now we lost our paste in the clipboard, and we have to go back to the browser and grab that URL again!
    4. Wait, which tab was it? Did we close it? Should we look in our browsing history? Ugh!

    Not anymore! With this little guy, when we kill the line (step 2 above), Emacs “injects” it into the kill ring. Now, when we yank with C-y, we will still get the last line we killed, yes, butlook up the kill ring with M-y and voilร ! Your URL is there. No need to go find that URL again:

    (setq save-interprogram-paste-before-kill t)
    

    You know how for years Emacs “jumped” when you scrolled down large embedded images in your org buffers? Let’s turn on pixel-scroll-precision-mode for pixel scrolling instead of the default line scrolling to fix this. It’s pretty much what it reads: the default old way would “scroll” (it’s actually not scrolling at all) by a line of text at a time. Since our image of, say, 600px in height is treated as a single line of text, it will jump to the end of it. With this option turned on, Emacs would read the pixels from your mouse wheels as you scroll, and we get the smooth scrolling we’re used to.

    Interesting to know: moving up and down the line without a mouse (arrows, or C-p and C-n) is moving by text lines, utilizing auto-windows-vscroll and line-move, which basically does in Emacs what arrow movement seems to be doing in modern applications: these apply this principle from the other direction โ€” they natively work with pixels, so they treat these arrow movements as a fixed number of pixel movements, which is approximately a line of text. So, when you move up and down a large image (or say a PDF) in a browser, the browser thinks “ok, the user is moving up one line of text, which is.. hm.. let’s seeโ€ฆ ah, it says it’s exactly 40 pixels, so let me show that”.

    (pixel-scroll-precision-mode t)
    

    Footnotes

    Emacs is the editor of tinkerers and artisans; those who are eternally dissatisfied with all other tools because of their adamantine rigidity. Crafting, or shaping, your tools to meet your exacting needs is what Emacs excels at. Because of that, Emacs is โ€“ much to the chagrin of everyone who picks it up for the first time โ€“ squarely aimed at people who already know Emacs.

    In fact, if you’re curious about help and Emacs help, I suggest you head over there now and read that post. It expands on how to approach Emacs help by how to think Emacs, which is something that experienced Emacs users struggle to explain to newcomers.

    As for the history of help in Emacs, I think it’s pretty safe to say it’s been there since the start, or at least since Emacs became intended for public use, sometime around the 1980s. By that point, most of the core help parts we know today (the tutorial, C-h t; the Emacs Manual, C-h R; as well as the framework itself) were already in place. The help system was there before GNU Emacs, back in the days of TECO Emacs that RMS worked on at MIT in the 1970s. You could browse the original code from then (preserved by MIT) and see how Stallman explained what certain commands do in emacs.doc inside that repository. Another interesting find about Emacs itself (and the help system that comes with it) is the EMACS paper written by RMS back in 1981. For the help system, take a look at page 17: “6. Self-Documentation and Extensibility” and the following chapter in page 18: “7. History”. Fascinating stuff.


    1. And here, dear reader, I fell down a deep rabbit hole, one that pushed this post a couple of days. There are two parts to this. The Emacs part, which I will explore at some point in the near future, has to do with Emacs’ menu itself, which is controlled by easymenu.el. This is an old Emacs package that’s been around since 1994, written by RMS himself โ€” kind of. It was first created by Per Abrahamsen (who seems to be a bit of a mystery, but that’s digging for another day). In turn, this package was taken from lmenu.el, which was part of yet a different Emacs fork at the time. In a regular Emacs style, the menu bar can be completely reconstructed and changed โ€” and that’s something I want to explore soon as a way to recall useful functions I keep forgetting exist (like having an “organize” menu with something like “org-sort” under it). This will be a fun project of its own for another day. Meanwhile, the other, bigger rabbit hole is the story of the GUI menu itself as we have it today. Apple has a big role here, back in the days before Steve Jobs left Apple and worked on the Lisa. This seems to be the first usage of a graphical interface in personal computers, and the menu, which was taken from Xerox, was a big part of it (there’s a short YouTube video there that would give you a quick brief of what happened). This means that I am right on keeping the menu in theme with the rest of the Mac apps, based on history! ↩︎

    2. Emacs’ built-in help deserves its own series of posts. Looking at it now, from the eyes of someone who used it for a couple of years, I find Micky’s description satisfying, reflecting what I felt at the time: ↩︎

    3. I forget how exactly, but some research into winner-mode history (turns out it’s been around since 1997 โ€” also, a lot of goodies here to look into!) led me down the path of tabs in Emacs, tab-bar in particular. I didn’t think much about tabs in Emacs, but since I’ve been using Kubuntu for a while and experimented with its Workspaces, I understand the concept better. I looked into BSAG’s post, and it looks like you can hide the tabs while still displaying them on the mode line, and of course, you don’t have to use the mouse. The concept of having a whole workplace completed with its unique window arrangement available with a single keyboard shortcut is alluring. Now, instead of playing around with where and how I want my windows to display, I can just save (or re-create) those, and I always have a “work” environment vs a “personal” environment within the same Emacs frame. This can be a good organizational feature. I’m going to dig more into this one. ↩︎

    Still working on Emacs Config Gems part 3. Fell into a deep rabbit hole and got lost for a couple of days, then climbed out just to discover another one I have to explore next. I wanted to crunch the first few tweaks of my Emacs config in one post, but there’s too much to explore. I’m getting there!

    Em Dashes in org-mode and the Nuances of Abbrev

    Since I confessed my enjoyment of em dash in my writing last week, I started using them more freely. On a Mac, it’s Option Shift Hyphen, as Sasha would tell you. In Linux, it’s a bit more involved: Ctrl Shift U to bring up a search for Unicode number reference, and then the number for em dash: 2014.

    This is all good and well, but what about Emacs, where I write most of my text?

    Emacs comes with abbrev-mode, a powerful text-expanding option that automatically converts something like “om” to “org-mode”, or even “fox” to “The quick brown fox jumps over the lazy dog” if I wanted to. But the em dash is a bit more tricky. I could, if I wanted, create an abbreviation like “em” to simply expand to “โ€””. But this doesn’t make much sense.

    When converting org-mode to markdown (as I do when I post something), the built-in solution for Emacs’ markdown exporter is to convert --- (three dashes) to โ€”, em dash โ€” but this presents two annoyances. First, the built-in exporter would convert those to their character reference, as we just saw: ߞ. I explained this more in-depth previously. Second, even after I fixed this issue by using pandoc, I still see --- in org-mode, not โ€”. This looks like the kind of thing abbrev-mode was made for, right?

    But it’s a bit more complicated. abbrev-mode triggers only when you type a space after a letter. So, “em” to โ€” would work, but - to โ€” would not, because a dash is not part of a word1.

    The solution was simpler than I thought: expand-abbrev, which “Expands the abbrev before point, if there is an abbrev there. Effective when explicitly called even when ‘abbrev-mode’ is nil.” In other words, it calls expand-abbrev without needing to trigger it the usual way. We simply call the abbrev replacement directly.

    Now whenever I want an em dash, I type --- first, and then I make sure the marker is right after the last dash, and call expand-abbrev, which in my config is tied to C-x ‘. I then get an em dash in Emacs, and the exporter in Emacs (or pandoc, in my case) leaves it alone.


    1. Prot has a related, interesting video about expanding abbrevs with non-word-like characters, which I already use. The problem here is that there’s nothing “word-like” in —. We can work with something like “!word” or “word!” because the mechanism that catches abbrevs will recognize a word-like character before or after the “!” (using regex, as explained in the post) and trigger it, but in the case we have above, there’s nothing that looks like a word to trigger it at all, so it does not work. ↩︎

    Style & Emacs Config: A Semantic HTML Reckoning

    For years, I’ve been using verbatim emphasis in org-mode to mark files and keyboard strokes, while reserving code emphasis to show function names, variables, and other elements of code.

    With the reintroduction of <kbd></kbd> tags to the blog yesterday1, I wanted these tags to follow the same logic derived from my usage in org-mode: if I used verbatim in org-mode to indicate keystrokes and filenames, then I should use <kbd></kbd> tags on the blog to indicate the same thing. I explained in a footnote in the post: “The reason I have it different here is because I often talk about files in my posts without referring to code.” That might have been my preference, but it was wrong. We’ll get back to it in a minute.

    I wanted to get my markdown-exported posts to preserve the verbatim emphasis from org-mode. But Markdown doesn’t distinguish between verbatim and code emphasis in org-mode โ€” it treats both as ``, or <code></code> tags in HTML. So I started looking for a way to fix this.

    The abridged version (the research took over an hour): I ended up with a wrapper function that would add Markdown raw code injection specifically for that code (I’m still working on it) to work with Pandoc. Why Pandoc and not Emacs’s built-in Markdown exporter? Because Emacs’s built-in exporter outputs certain characters, like my now beloved em-dash again, as character reference numbers, which results in a character reference (โ€” specifically) instead of an em-dash. Why’s that? Look, have you eaten breakfast today? Because I haven’t. Let me just tell you, these rabbits dig deep holes.

    So now, after I had a working way (more or less) to produce my newly introduced <kbd></kbd> tags, I wanted to start using them for filenames. But I was bothered by the fact that while I can do whatever the hell I want this is not considered standard. And when I say “bothered,” I mean this is the thought I woke up to at around 05:40 this morning, which is what you get from a delirious dork Emacs brain like mine.

    I knew HTML has standards, but I didn’t connect the logic behind it to semantic HTML โ€” not until I browsed on my phone, in my bed, for another half an hour of impulsive research. Turns out, this is something that some folks take very seriously. And according to these folks, filenames and paths do not and should not have a dedicated HTML tag (surely not <kbd></kbd>, which is for keystrokes only โ€” actually, it’s for “textual user input” which can include voice, for example). Authority has it that I should be indicating filenames using the <code></code> tags (and code emphasis in org-mode), and there’s a good reason for that. Just take my word for it for now (breakfast, remember?)

    Reading through their tomb of standards, I realized I need to correct my headings on the blog too (I jump directly to <h3></h3> tags instead of going by order, because the CSS for these tags looks better โ€” in other words, I’ve been lazy by not fixing this), among potentially many other things. There are over a hundred semantic tags in HTML, and there’s a reason for each one.

    Damn those rabbits.


    1. I realize that most of you read this via RSS, which might translate these tags as code anyway, making the entire point moot… if you want to see what I mean, you might have to actually use your browser and visit my page as is, just this once. ↩︎

    Emacs Config Gems - Part 2

    You know how I said last time Part 1 was just the introduction? I lied.

    My emacs-settings.org file includes an introduction that covers what I already went over and more. I thought I’d skip it, but as I looked through the notes I left to myself โ€” various guidelines, warnings, and tips โ€” I realized that this is exactly the kind of stuff I should share.

    Style

    As I was writing this, I fell into a rabbit hole (of course) and made a couple of additional changes.

    Style and style guides are important to me. In college, as an editor, I used the AP Stylebook as a bible almost, along with the Chicago Manual of Style for academic papers. When I worked as a technical writer, it was Microsoft’s stylebook I checked constantly โ€” and some of it stuck (don’t say “click”; say “select”, don’t say “sign in”; say “log in,” etc.) The main point is to stick to a style and keep using it โ€” which one matters less.

    Here are the notes:

    1. Emacs keyboard shortcuts and file paths should be placed in verbatim (between = and =)1
    2. Code (as part of an explanation) should be placed in code (between and )

    Code blocks: use structure templates (C-c C-,) and choose emacs-lisp from the list (this is defined below). It should be in lower case: #+begin_src emacs-lisp and #+end_src.

    When explaining code: the explanation follows the code immediately (no space). Use a space after the code (new line) for the next item:

     explanation for item 1
     #+begin_src emacs-lisp
     code for item 1
     #+end_src
     
     explanation for item 2
     #+begin_src emacs-lisp
     code for item 2
     #+end_src
    

    My settings file is long and requires that I jump around to different sections. As I was working on revamping it, I’ve learned quite a few useful “tricks” that I started sharing in earlier posts. These are always good to know, not just in our setting file.

    Jump Back With the Mark Ring

    While registers (I have a section about them below) are a nice org-mode feature I keep forgetting about, they’re a bit of an in-between too much or too little for most cases in this file. For quickly getting around, we should use the mark ring:

    Use C-u C-SPC (built on set-mark-command) to jump back to where our marker was before, which is usually where we ended scrolling or moving to see something. Keep pressing to keep going back โ€” it remembers all the positions we landed on. By default, it remembers the last 16 positions.

    Editing Code Blocks

    Edit code blocks with C-c ‘ instead of just working with the text inside the org buffer directly2

    Don’t edit the text in a code block (#+begin_src#+end_src) directly. While it works, we’re missing out on the power of org-edit-special, and this is one powerful org-mode feature. Here are some of the highlights relevant to me, in bold:

      *When at a table, call the formula editor with 'org-table-edit-formulas'.*
     When at table.el table, edit it in dedicated buffer.
     When in a source code block, call 'org-edit-src-code'; with prefix
       argument, switch to session buffer.
     When in an example block, call 'org-edit-src-code'.
     *When in an inline code block, call 'org-edit-inline-src-code'.* **(this is what we're doing here!)**
     When in a fixed-width region, call 'org-edit-fixed-width-region'.
     When in an export block, call 'org-edit-export-block'.
     When in a comment block, call 'org-edit-comment-block'.
     When in a LaTeX environment, call 'org-edit-latex-environment'.
     When at an INCLUDE, SETUPFILE or BIBLIOGRAPHY keyword, visit the included file.
     *When at a footnote reference, call 'org-edit-footnote-reference'.*
     When at a planning line call, 'org-deadline' and/or 'org-schedule'.
     When at an active timestamp, call 'org-timestamp'.
    

    What it gives us when we work with the settings here:

    1. A separate temporary buffer, without the #+begin_src#+end_src, which we can evaluate any time, without worrying about being at the end of an expression (parentheses) and use C-x C-e3.
    2. Safety net: as long as we don’t close it with another C-c ‘, it doesn’t save the code, and we can run it in that separate buffer to see what it does.

    Also, nice bonus: it highlights the code we’re in with a separate color, and it will keep highlighting it as long as org-edit-special is open. Need a coffee refill? No problem, you know exactly where you left off.

    In my config, I started using links more often instead of setting registers (as I noted earlier, registers are too much for moving around, but too little as permanent location savers). I stole the thunder from this section in this post, but it deserves its own post anyway. org-mode internal links are very powerful, and I don’t think the manual explains them well enough (examples would be good), so go check it out.

    Registers

    Registers can save a location in a file to be recalled later from anywhere else in Emacs, or, to save a chunk of code to be pasted (yanked) later.

    1. To save a location: C-x r SPC, then a number or a letter to name the register. So C-x r SPC and then 1 will save a register called “1” in the position the marker is on.
    2. To jump to a saved location in a register: C-x r j, then the number/letter we previously selected. So in this example, C-x r j and then 1 will take us back to the location we saved as “1”.
    3. To save a region in a register: First, highlight (select) a region in Emacs. Then C-x r s, then a number or a letter to name the register. So selecting this sentence, then C-x r s and then 1 will save the sentence in register 1.4
    4. To insert a saved region: C-x r i, then the number/letter we previously selected.
    5. To view saved registers: M-x view-register, which allows you to select one by number. A good replacement for C-x r j if you need a visual reminder like I do.

    It’s a good idea to keep numbers for positions and letters for text so we don’t get them confused and overwrite our registers.

    Footnotes

    1 Most Emacs users, I believe, use code for file paths. The reason I have it different here is because I often talk about files in my posts without referring to code, and I will now make use of the <kbd></kbd> tags as well, which I forgot about. This is good for clarity, especially when we talk about Emacs, since Emacs and keyboard shortcuts are mentioned together all the time.

    2 Those of you who code and write functions on Emacs regularly would probably find this “trick” trivial. However, as a person who does not have this background, I’ve been editing my code blocks directly in org for years โ€” I had no idea org-edit-special exists. I’m sure some folks out there are in the same boat.

    3 Which is, as I explained in my previous footnote, exactly what I’ve been doing for years. It works, but it can lead to mistakes, and it’s not as safe (you’re changing your settings, so if something goes wrong, Emacs’ startup will stop at the error).

    4 In a usual discovery manner, I found out that C-x r + appends text to the register. So, if you were to select this footer here from the word “In” to the dot after “register”, you could then go to the word “So” and mark again to the word “footer” 7 words later, hit C-x r +, and then when you ready to yank (paste), hit C-x r i and both sections will be yanked as one. Actually, you could forgo C-x r i altogether and use C-x r + from the start, because if you append to an empty register, it will just append that first chunk.

    Emacs Config Gems - Part 1

    I’ve been working on my Emacs config for three weeks now, coming this weekend. It’s one of the deepest and most fun rabbit holes I’ve been exploring. As I stumble upon new ways to do things, I dig deeper, learn more, and keep tweaking my config, which makes this rabbit lair even bigger.

    Eventually I realized that if I wait until I’m done to upload the config file, it will never happen: by the time I’m done, I will accumulate enough fixes and additional tricks and tweaks to warrant a whole new file.

    The conclusion is what I should have done from the beginning: apply changes in chunks and explain what I’m doing and why as these happen.

    I’m starting with changes to my .emacs1 file on my mac2, before we’re even touching the “good stuff” in my main emacs-settings.org file. Why? Because Emacs was built with Linux in mind, and we need to make some important adjustments to how Emacs works on a Mac before we use it. As you will see, I’m using this conceptually too: while some of the configurations in the .emacs file (the “init” file) could technically be placed in the big emacs-settings.org file, I still place them in what I consider Emacs’ “booting” process.

    My .emacs file contains only these four code blocks, which are separated with spaces for visual convenience:

        (when (memq window-system '(mac ns x))
          (exec-path-from-shell-initialize))
        
        (setq insert-directory-program "gls" dired-use-ls-dired t)
        
        (setq custom-file (expand-file-name "emacs_custom.el" user-emacs-directory))
        (load custom-file 'noerror)
        
        (org-babel-load-file
         "/Users/user/Sync/Public/emacs_settings/emacs_settings.org")
    

    exec-path-from-shell-initialize

        (when (memq window-system '(mac ns x))
          (exec-path-from-shell-initialize))
    

    This tells Emacs that if its windowing system is macOS-related (ns or x; there’s also the old mac version of Emacs that is not being used today โ€” the Homebrew emacs-plus one we are using here is ns, which can be checked with M-x emacs-version), it should run exec-path-from-shell-initialize.

    This function copies the PATH from the shell, as if we were using a terminal program. By design, macOS GUI applications (those that live in the user’s Applications folder and have an .app extension) are not exposed to this PATH because they’re launched by a different process altogether (launchd)3. But Emacs needs this PATH, as many of its core components integrate with the OS as a terminal application, which is what it is, at its core.

    In fact, this is why we need this condition in a file that resides on a Mac, and why this condition is triggered by the windowing system, and not the OS itself (every other condition in our config would be written as eq system-type 'darwin or similar). If we run Emacs in terminal, the program already has access to PATH, and this execution is not needed.

    Use gls in Dired

        (setq insert-directory-program "gls" dired-use-ls-dired t)
    

    This doesn’t have to live in our .emacs file, as it can live as part of our Dired options in emacs-settings.org, which will come later. However, this is a macOS-only thing, and since we need to get gls from Homebrew, it’s one of those things to prepare before we start Emacs for the first time. After all, we will probably use Dired right away after install, and we want to make sure it’s ready.

    gls, GNU’s ls command, is bundled with other utilities inside coreutils, so we install it with brew install coreutils. Then the above command makes sense โ€” we’re telling Emacs to use this flavor of this ls command instead of the one that comes with macOS, which is lighter and doesn’t have what we’re used to seeing in Emacs Dired (at least, not for me). As it turns out, there are other well-known utilities in this package, such as rm and mkdir, but we don’t use them, so it’s really just for gls.

    Changing Emacs’ custom default file to emacs_custom.el

        (setq custom-file (expand-file-name "emacs_custom.el" user-emacs-directory))
        (load custom-file 'noerror)
    

    This is something I discovered while working on my .emacs file. It was cluttered with comments and configurations from Emacs’s custom, Emacs’ settings wizard. This is because by default, Emacs doesn’t have a definition for it:

    File used for storing customization information. The default is nil, which means to use your init file as specified by ‘user-init-file’. If the value is not nil, it should be an absolute file name.

    It makes sense if you use custom often, which probably means you don’t bother with babel (coming up) and writing long Emacs posts like this one, but in reality, I haven’t met an Emacs user who used it for more than a few months at most without getting their hands dirty. It’s just too tempting.

    The first line tells Emacs where the custom file config is (inside /.emacs.d/, the default for user-emacs-directory), and the second line tells it to “not worry” if the file is not there. Why? Because the first time we run Emacs (or a clean reinstall), we might not have this file at all yet, as it’s created by custom. If we don’t have this file, Emacs will do whatever it does whenever it encounters an error: tell us there’s an error and stop running the rest of the config. And this happens right at the beginning, so essentially our entire config will be skipped. So this is a good safety option4, and probably good practice.

    Org-babel: load the configuration from an org file

        (org-babel-load-file
         "/Users/user/Sync/Public/emacs_settings/emacs_settings.org")
    

    Now, after we put all the critical macOS5 configuration in place, it’s time to tell Emacs where the rest of the configurations are. This here was just the introduction, the Emacs “boot” for Mac only, after all6.


    So here we are, done with part 1. It took me way longer to write than I thought it would take (I’ve been standing at my desk for about 2 hours now), but this is exactly the sort of thing that keeps me hooked on Emacs. Everything leads to more… everything. There’s a story behind every dot, apparently. As you can see from my footnotes, I’ve found additional tangents to go on while writing this just now, and that’s on top of a growing list I already have, of about 10 other things I want to check โ€” and my config is only about 25% done. And as I said, by the time I’m done, it will be time for round 2, which in turn will probably lead to round 3…

    “Emacs. It really whips the GNU’s…” errm. Anyway. See you next time!

    Footnotes

    1 The story of dot files (files that start with a dot, like .emacs) is an interesting one. Turns out it was a programming mistake back in the days when Unix started, and it stuck as an idea. These became convenient to use as configuration files because they are the sort of files that are usually created when you install something and configure it once, probably to never see it again (this was before Emacs users started popping up, obviously), so the bug became a feature.

    2 On a Mac, you have several options when installing Emacs. The one I’ve been using over the years, and what seems to be the most popular, is emacs-plus at https://github.com/d12frosted/homebrew-emacs-plus. Some of the choices I made in my .emacs file are based on this fact.

    3 There’s another rabbit hole here I didn’t explore much: Emacs on Homebrew, at least in some versions, has incorporated the option to grab the PATH during installation; however, it seems Apple blocked this option at some point, so we need to run it like this. I don’t recall ever getting a warning that Emacs needs access to my PATH or something similar, but I wouldn’t be surprised if something to that effect is happening when you first install it.

    4 As I’m writing this, I realize there’s another worthwhile rabbit hole here: the option to tell Emacs to ignore errors for non-critical configurations, such as the theme, or the way org-mode displays, etc. While I want these in place, if there’s an error, I’d like Emacs to keep loading the config if it can. Since there are different “skip error” options depending on where and what is being skipped, and since I need to be sure what I’m skipping, I’ll do more digging another time.

    5 Ah ha, but that last one, the custom file location, is also good on Linux! Good thing I’m writing this blog post. When I go back to my Linux machine, I will include this line there as well.

    6 By the way, while there is no org-babel.el, it can almost be one from a quick look (yes, yet another rabbit hole). There are many different .el files scattered in Emacs that relate to org-babel which can do different things.

    Interesting trick, discovered by mistake:

    Dragging and dropping a file into Emacs while in a folder with Dired copies it there, just as Finder would. Did you know that? I didn’t!

    Still working with Claude on my Emacs settings as a reference. Need to start a new session, so asked it to write a summary with instructions on how I like it to help me. It wrote this:

    I know it’s complementing me on purpose, but that emphasized why? That’s why my blog is called this way ๐Ÿ˜‰

    Say you go jump to a header in org-mode somewhere with C-c C-o. Did you know that you can go back with C-c &? And that it has history, so you can keep going back??

    Years of isearch-backwards… wasted. Mind blown. ๐Ÿคฏ

    A Quick org-mode Internal Links Reference

    As I mentioned yesterday, I started organizing (and cleaning) my Emacs config. What may have seemed like an annoying and boring task has proven to be fun and addicting (reminds me of this, which is part of this video ๐Ÿ˜‚).

    I’ve already discovered a couple of new improvements to my current config as I was researching individual settings and why I have them, and as I said I do plan to share it. For now though, one important section I added to my config is a quick org-mode links reference. This is actually the first time I figured out the difference between radio links and “regular” plain links and how to use them.

    Here it is, slightly modified:

    Org-ID

    We know about links to other files using org-id: You give a header an :ID: property (this is generated automatically1 when you link to a header) and you get a slug, usually a UUID (for me it’s something slightly else, more on that soon below). This stores the links in org-id-locations, which in turn points to a local file with all of these unique IDs. This is good for linking between headers in different files.

    Custom-ID

    We can set a :CUSTOM_ID: property for a header, and it’s only active in that file. Kind of like a table of contents in a book, with chapters (= headers) listed. If you don’t have the book, you don’t have its table of contents, so you know nothing about it. To point to a header that has a custom ID: [[#custom-id-value][description]].

    These are buffer-specific only (no cross-reference between files). In this case, the links are tied to words (anchors), not headers. There are two kinds.

    The regular plain target link works when we set the anchor first with <<an anchor>>, then call it again with [[an anchor]].

    Its more “magical” brother is a radio target link, where we set an anchor like so <<<very special anchor>>> (three angle brackets) and then all we need to do is type very special anchor (no brackets this time), and it works. Note though that when you create a radio target for the first time, you have to revert the buffer or M-x org-update-radio-target-regexp for it to take effect.

    Footnotes

    1 : this can be done with a function, org-id-get-create. For a deeper dive into how and why I set my org-id with a date format (not UUID), look here.

Older Posts โ†’