Hacker News new | past | comments | ask | show | jobs | submit login
Ask HN: What's the weirdest/best thing you've done with Emacs?
72 points by toomanyducks 22 days ago | hide | past | favorite | 42 comments
I'm slowly becoming addicted to Emacs, and I'm curious about what everyone else is doing. What are some of your favorite hacks and changes you've implemented over the years?

The weirdest thing I have done in Emacs is using it to generate WAVE files, with a visual interface. The music loops, so you can keep playing with it. I've given talks about the package at !!Con 2021 and EmacsConf 2020.

Info about this at https://zck.org/bangbangcon2021. Video at https://www.youtube.com/watch?v=BeTDIrJeriI. Bonus: the presentation itself is done from within Emacs, in another library I wrote.

Awesome! It's actually would be nice to have something like a library of MIDI snippets that you can record and store under org-mode bullets, sort them by tags (mood, tempo, genre) and then quickly copy them into a DAW. It would give another dimension to musicians, not only they can store verbally formulated ideas about their music in form of notes, but actually have a library of materials they can use.

Maybe not so amazing, or even Emacs specific. But I use a text file to store my browser bookmarks. I type a brief description above each url. I can add search tags.

    description blah blah blah
    tags: programming performance
I view the file with Emacs mode goto-address-mode. So all the hyperlinks are clickable with the mouse or a keybind.

I can run M-x occur. To search and get a nice list of matches by tag or description text.

I think it's superior to any bookmark feature built into a browser. Simply using a text-based format, and a few built-in Emacs features.

Hi thanks for your sharing your usage! I'm very interested in doing this. I tried to use a sqlite database (using dbrowser gui) to handle my resources for my researching. But I'm not a programmer so I struggled to learn SQL.

Couple questions:

How do you handle mistyping the wrong tag? Is there something you use that could lint mistakes?

Is there a way to show all the tags that's available or you've used? Like grepping to show all the unique tags, but in emacs.

How do you handle stale links (links you no longer visit)? Delete them, move them, mark them stale or something?

If you wanted to see everything related to say tag1, tag2, keyword1, and keyword2, is there some way to like "grab" all those links and view them in a separate buffer? I guess it's more like filtering and reactively changing the list to show you what you want.

> Is there a way to show all the tags that's available or you've used?


But I could implement that in a few minutes. I could search for "tags:" headers, add the trailing text items to a list, then call function delete-dups.

Or I could use a pre-defined list of tags and have a function that lets me select from that. But this starts moving away from the "just a text file" thing, and I'd have to start creating my own custom mode. That's nice but then I'm also forcing rules, structure, and even custom user interface that's beyond "just a text file".

Minimal structure and rules is a feature too, it's easier to add new bookmarks.

> How do you handle stale links

I haven't had a stale link yet. If I ever notice one, I'll delete or correct. Or maybe add a flag STALE: in front of the URL if i want to keep it for historical purposes.

> see everything related to say tag1, tag2, keyword1, and keyword2, is there some way to like "grab" all those links and view them in a separate buffer?

Sort of. I use grep-like line based searching. It searching lines only, not "records". So it treats each line as it's own thing. But it gets the job done. I use the swiper package. With it's out-of-order matching mode. So my search query might be:

    food meat
It would find lines that contained both search items in any order. I only bother with "and" style search not "or".

It is flawed. If food and meat are on separate lines, it would not find the match. A more advanced search feature that understands the file format could solve that. Or a better suited database file structure. But not worth it for me. 99% of the time I'm searching 1 keyword only.

Thanks for answering! I looked into everything you said and gained a lot of ideas from this.

For anyone who uses vim or anyone interested reading, because the setup is pretty simple, I managed to put together a similar setup in vim.

I'm using bookmarks.txt for web and files.txt for local files (I have a TON of pdfs, books, .md, .txt, .doc, etc. to cross reference).

For web I need to open urls with different profiles (firefox/opera/chrome).

  "Add chrome folder to env variables
  nnoremap <Leader>j :silent execute "!chrome <C-r><C-a>"<CR>
  "Add firefox folder to env variables
  nnoremap <Leader>k :silent execute "!firefox <C-r><C-a>"<CR>
For files I'm using cmd (windows) to open the files using the default applications under the cursor.

  nnoremap <Leader>h :silent execute '!explorer ' . shellescape(expand('<cfile>'), 1)<CR>
I picked FZF to find the files quickly in the terminal. Also using FZF Vim plugin to search tags in bookmarks.txt and files.txt. It has similar behavior to how you described swiper.

From https://github.com/junegunn/fzf/blob/master/README-VIM.md#ex..., I send the FZF buffer line results to the quickfix window so results persist and jump easily to each bookmark. Use :BLines, "tag1 tag2 keyword" or "tag: tag1 tag2", <ctrl-a> selects all results, then <ctrl-q> sends it to the quickfix results.

Didn't modify the code from the example at all:

  " An action can be a reference to a function that processes selected lines
  function! s:build_quickfix_list(lines)
    call setqflist(map(copy(a:lines), '{ "filename": v:val }'))
  let g:fzf_action = {
    \ 'ctrl-q': function('s:build_quickfix_list'),
    \ 'ctrl-t': 'tab split',
    \ 'ctrl-x': 'split',
    \ 'ctrl-v': 'vsplit' }
I would have liked to use the location list instead of the quickfix window. Unfortunately, I couldn't get the location list to work for the buffer lines results. Seems like it only works for file results. See: https://github.com/junegunn/fzf/issues/1885.

Using <f2> to open the quickfix window. Then using <ctrl+shift+n> (next) and <ctrl+shift+p> (previous) to jump to each results.

  command! -nargs=0 JojoToggleQuickFix if empty(filter(getwininfo(), "v:val.quickfix")) | copen | else | cclose | endif
  nnoremap <f2> :JojoToggleQuickFix<CR>
  nnoremap <C-S-n> :cnext<CR>
  nnoremap <C-S-p> :cprevious<CR>
I type "bmk" and it will expand to the following snippet.

  date: @2021-07-07
This is the abbreviation in vim.

  "Bookmark/File snippet
  iabbrev bmk title:<CR>
      \date: <C-R>=strftime("@%Y-%m-%d")<CR><CR>
I setup custom syntax highlighting (title:, link:, tags:, date:, description:, and tags) for .txt files in vim.

    title: "Pixologic ZBrush - YouTube" 
    tags: @youtube @zbrush @3d @modeling @learn 
    link: https://www.youtube.com/c/PixologicZBrush/videos
    description: Industry standard 3D sculpting application.

Also using AutoHotkey to open files in the clipboard:

  run, "%Clipboard%"
I'm using this when I'm outside of vim.

Oh nice. I like the use of snippets with a date stamp.

Do you use org mode at all?

No I don't use org. I find it too slow to load on my computer. Up to 30 seconds load time for a feature defeats the advantages of a lightweight text format.

I use an Emacs construct called an idle timer to maintain a file of (the start and end of) every interval 7 minutes long or longer during which I did not interact with Emacs, which enables me to figure out when I started or stopped some activity.

A typical use of the file is figuring out retroactively when I got out of bed even though I didn't make any record of the event at the time the event happened: specifically, I look in the file, see a interval of emacs-idleness 7 hours long, which information I combine with my memory that I used Emacs within minutes of getting out of bed.

The file would be even more useful if it pertained to all my interactions with the OS, not just interactions with Emacs, but that would prove much harder to implement particularly because I would need to implement anew every time I switch OSes. (I was using a different OS when I wrote the Emacs code described above than I am using now.)

The code has provided me much value relative to its implementation cost (time spent).

You might be interested in a generic time tracking daemon like arbtt[1]. It takes a snapshot of your activities across all programs in much more granular and configurable interval. It stores the data in binary format which is more space efficient but ships with tools that can spit out data for further scripting.

Independent of data collection, arbtt also has a DSL that lets you tag your samples programmatically. Which means you can use logic such as conditionals and regex on data such as active program name, window title etc to mark a sample productive or distracted etc.

The weird thing I do with Emacs here is run a function every N minutes and figure out productive work ratio in that interval with help of other scripts. Then it compares the ratio to a target threshold and performs actions based on if it meets the goal or not. Usually I warn myself if I am not being productive, but when I am feeling particularly intolerant of procrastination I lock myself out of my own laptop for a few minutes, to clear up my head.

[1] https://arbtt.nomeata.de/

Sounds handy. Are you interested in sharing the source?


(Is there a more graceful way to publish a single file?)

GitHub Gist is exactly made for this!


I've taught a stripped down emacs/org-mode to my partner to manage a hand-crafted meatspace recipe book. Their only "computing" otherwise is done on a smartphone (no laptop or desktop usage at all).

They use org-mode to give structure to the document and then export to HTML with and embedded .css I made with appropriate styles added. This .html page gets printed from Chrome and cut up / added to the recipe book.

My partner couldn't be less interested in tech/computing, but is using emacs as a tool to create a handmade art project. I dunno about weirdest, but this is my example of how emacs can be anything to all peoples.

I control my browser through Emacs, since it's a lot faster/saner especially when I have close to 1000 tabs.

https://github.com/atomontage/osa-chrome (macOS, has some extra features)

https://github.com/anticomputer/chrome.el (OS agnostic)

Neat project!

Tons of weird/fun stuff. Emacs is generally my primary tool.

- I work in Incident Response and use emacs and orgmode as a second brain for case notes. I log commands in orgmode and try to build my notes to make sure the investigation is a repeatable.

- For a good while I was using emacs/gnus as my email client. It wasn't without its warts but compared to Outlook it was glorious.

- I needed something to distract me during chemotherapy sessions so I wrote an NTFS MFT parser in emacs-lisp. It was a super dumb project but I'd been ages since I'd read through Carrier's file system forensics and it was good exercise.

- For a time I was using emacs and the emacs lisp request library to track bitcoin payments made in suspected extortion cases. It was fun to map until the transfers hit bitcoin tumblers then it my laptop basically lit on fire.

At this one job I had, the org basically ran on stored procedures. Like thousands of them. So I whipped up a couple of functions and keybindings so if the cursor was on the name of a stored proc, I could surf to it. And then back and so on. Basically, it was a stored proc browser!

Currently working on a speedrun split timer written in elisp:


I've also written a real-time game pad input visualizer (heavily inspired by Chris Wellon's work here:


I did this for a couple of reasons. I couldn't find a decent split timer that was:

- available on Linux

- not Electron/browser based (These worked well enough, but at the cost of high CPU usage, which caused hiccups when recording gameplay)

I was easily able to set up the timer so that I can feed inputs to anti-micro, which are forwarded to Emacs. This allows me to control everything from the game pad. I also have a feature that allows me to record a mistake during a run. I have commands which can then pull out mistakes for a given range across multiple runs to analyze where I need to practice most.

Still a work in progress, but it's been fun to work on.

I don't think it's really weird but using it as an http rest client for testing apis with restclient.el

Postman frustrated me because it was taking up all the memory on my computer to do really simple calls. I remembered the "emacs rocks" episode on restclient and gave it a shot. Such a nice package. Really unfortunate that the maintainer doesn't update the melpa package.

I use emacs restclient as well. It's not just good - it keeps you in the flow. No context switching to a different environment, just a quick cut 'n paste of the path and data you're working on.

> Really unfortunate that the maintainer doesn't update the melpa package.

Last MELPA update is 05/11; did I miss something?

Melpa package still misses restclient-jq.el AFAICT, the receipe for the package is not correct. Seemed to work at some point since someone merged a PR about that.


Not OP, but I suspect this is what s/he meant

I made a basic game engine for Emacs. https://github.com/accidentalrebel/emacs-game-engine

Has easy to use coordibate system for placing characters on screen, shape drawing, keyboard and mouse output, and audio.

Maybe not tbe greatest, but it is was the most fun I had.

Hand-authored a SVG file, using the REPL to compute math, for what would become a tattoo.

(In retrospect, I’d have designed the image with greater tolerances for ink dispersion in skin over time.)

This is not my hack, but I thought it was worth linking to.

Running a bakery on Emacs and PostgreSQL: https://bofh.org.uk/2019/02/25/baking-with-emacs/

in the mid 90s i taught my then 75 year old grandmother on her first computer how to write LaTeX documents in emacs. i created boilerplate templates for her various document types (letters, reports, etc) and she knew how to start emacs from the commandline, load those templates and save them into new documents. and of course preview and print too, but i don't remember if she did that from emacs or from the terminal

Play nethack while pretending to work.

Our test suite could take hours to complete but could occasionally fail and had to be restarted. Emacs multiwindow with a shell in a small window and a game in another one was what kept me sane that year.

In the full scope of what it can do it's not very weird, but I'd say it's the best I've done so far... is write a book!

It's in draft 2 at the moment, having been printed out and manually edited over the last couple months.

The path there was enlightening. From multiple crashes per attempt to lines and lines of customization. From unexpected crashes and automagical recovery. I've come to love this little word processor cum operating system. I only wish I had found it decades ago when I had more time to pour into a hobby.

It isn't really a hack but the best thing I've done is use org mode for organizing work. I make a file for each sprint and each ticket in that sprint gets its own file which is hyperlinked in the sprint file. I can open the sprint file then navigate to each ticket which will have a link to the Jira ticket and then may directly link to certain lines of code that may be a central focus of the ticket.

Another thing I did with org mode was create a release document of all commits that are going into a release as well as the link to that commit in github, then exported to PDF and sent to the team. We had to cherry pick a bunch of commits for a release and in order to make it clear what was going out I organized it by newest to oldest and had the commit hash as a hyperlink.

The weirdest thing was when I ran Dwarf Fortress Adventurer Mode in text-output in Emacs and fiddled with custom key-bindings. (I still think there's potential, esp. for macros :))

The best thing is very boring, but it's the best because I use it all day, every day, and it brings me joy: bringing all my text things to Emacs. Writing, project/task organizing, and email. Never thought I'd end up there.

back in the early days of internet go, I wrote a client for the ascii protocol that used '*' and 'o' for stones, and used it for a few years on an actual vt100.

not super weird, but it really took a lot less work than any of the alternatives and worked great.

The best thing in the last year was that I made a mode for my job. All of my work repos are under the same folder so the mode gets activated for any file under that folder.

It's small right now but has functionality like creating a new migration and switching to the new file. I also have yas-snippets for SQL tied to the mode. Using which-key helps me not have to remember all of the commands.


>Using which-key helps me not have to remember all of the commands.

I think the command's name is where-is, not which-key.

I think they meant this package: https://github.com/justbur/emacs-which-key

This isn't a hack, but the way org-columns combines a collapsible tree view with spreadsheet like functionality is neat. I use it for project estimations where breaking things down further and further results in a tree, and the estimate sums of lower items in the tree are combined for the higher items. I don't know if this can be done in a spreadsheet.

Not what I've done, but the single craziest thing I've ever seen emacs do was a mode that you could put the editor into where you could edit the Lisp atoms of the running emacs program. Using the emacs editor commands to do so.

That melts my brain.

I use it to connect to my chess server! I play on freechess.org and xboard is my client for it, but I launch it from an emacs shell that becomes my console to interact with freechess. I also added some elisp commands so private chats have their own buffers.

long before there were convenient tools like xpra to move a window from one X terminal to another i was able to connect emacs to multiple X terminals at once, and in that way switch between computers and keep using the same instance of emacs via gui.

given that emacs works just as well in a terminal, that is not a huge advantage, but it is noteworthy that emacs has this capability and had it for a long time. something any gui program could have in theory

I started using it.

Applications are open for YC Winter 2022

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact