Hacker News new | ask | show | jobs
by mjgs 2027 days ago
That sounds kind of cool, though I’m not very familiar with emacs so it looks a bit strange to me.

Does it essentially create the emacs equivalent of an html form, that you fill out and it then adds what you added to preconfigured text files, with the path to the file you were looking at when you triggered the template?

2 comments

There are a number of different ways to do this in Emacs, but org capture is probably the place to start. This feature is very powerful. See [1].

> That sounds kind of cool, though I’m not very familiar with emacs so it looks a bit strange to me.

Yes, Emacs is an editor from another time and is a bit strange.

Like Vim/vi, Emacs has survived for something like 44 years. There have been hundreds of text editors created and used, some very widely, over the intervening decades.

Through a kind of evolutionary pressure, better editors survive and less capable editors decline in popularity. The best features are often adopted by the newer generations of text editors. By now, there are a pretty widely accepted set of features in modern editors, for example cut-copy-paste and undo. But, like the octopus, Emacs and Vim are just different than other creatures. Not necessarily better in every way, but different. So cut-copy-paste is supported by these editors if you insist, but they have their own highly refined way of improving even these elementary and widely used operations.

I like VS Code, Sublime Text, and Jet Brains IDEs; however, the editor I use the most is Emacs. It is, at the core, a set of low level primitives for editing text combined with a flexible programming language interpreter that higher level commands use to implement its unbelievable feature set. By now, millions of lines of code have been contributed to Emacs and it is likely to have whatever you want out of an editor.

There is a bit of a bump to get over when learning either one of these two paleolithic editors (Emacs or Vim). If you are a coder, I think it worth learning at least one of these two proven editors.

[1] https://www.youtube.com/watch?v=qCdScs4YO8k

Thanks for the elaboration, your description of vim and emacs as paleolithic editors made me smile.

I was introduced to vim a long time ago at a previous company, and so I went that route rather than emacs. I’m moderately good at vim now, but VSCode is just much easier to use.

Org-Capture creates a temporary buffer, inserts its template string, processes the special escape sequences (called "%-escapes")[1], and then lets the user edit the buffer before adding it as an entry. Where the entry goes is specified by the code that sets up the template.

The power here comes from the %-escapes, which range from asking the user for a prompt and pasting it in that location ("%^{PROMPT}") to arbitrary code execution ("%(EXP)") that can include text input from the user from other %-escapes. There are escapes to insert the file name ("%f") and the full file path ("%F") of the file that was visited when the template was triggered.

I think it's a lot easier to evaluate this kind of thing in action rather than in screenshots, so I've added an example screen recording[2] with a keylogger to show what a capture using a fairly simple template looks like. This Imgur album has both the screen recording as well as what the resulting entry looks like after it is saved.

[1]https://orgmode.org/manual/Template-expansion.html [2]https://imgur.com/a/l8jwbnN

It’s intersecting to get an idea of how to quickly do logging from within a code editor.

My linkblog uses a web app, with a bookmarklet frontend, so it’s easy to post when browsing the web from inside the browser.

But for a bug log it makes sense to be adding directly from the editor, though I could imagine that having a way to add entries using a web form might be useful too, making it possible to use touch screen devices.