Back

Emacs 31: An unofficial guide to Markdown-ts-mode

150 points12 hoursrahuljuliato.com
RahulMJ10 hours ago

A bit of extra info:

- `ts` stands for "tree-sitter", meaning this mode uses tree-sitter under the hood, which is, among other things, very performant.

- There's support for the CommonMark spec and GFM, so things like `- [ ]` checkboxes and ~~strikethrough~~ work out of the box, along with many other small QoL features.

- This mode is BUILT-IN, so no extra packages are needed.

- This is currently in the experimental phase, so users need to "opt in" and load the mode to play with it, hence the first part of the guide.

lurght10 hours ago

I think in 31 registering the file types isnt necessary any more, the mode opens automatically for me (and i did manually delete the old markdown-mode)

dleslie9 hours ago

Tree sitter support is half baked in the same way official LSP support is, only kind of worse.

Eglot won't help you get your system ready for LSP work, it will only avail itself if what's there. It doesn't even auto detect and configure that, either. There's no user prompting, so you'll have to read the docs to know that this even needs to be done.

Similarly, tree sitter support doesn't include the grammars! And those aren't typically sitting in your package repository, so users have to find a grammar and compile it themselves. There's not even a good recommendation given by Emacs on where to get them, leaving users to hope that whatever repository showed up on a Google search is both in good working order and safe to use.

It's really quite a failure on Emacs.

femiagbabiaka9 hours ago

In Emacs 31 none of what you’re saying is true. Grammars auto install and setting them up is easy.

https://www.reddit.com/r/emacs/comments/1utghab/treesitter_s...

dleslie9 hours ago

Well that's a nice change; I'm still on Emacs 30.

But note that this is not the default. Users have to enable that behaviour, and know to enable it. That's a bad default.

+2
BeetleB8 hours ago
tpmoney8 hours ago

“ask” mode for installing tree-sitter grammars is the default setting. Tree-sitter modes broadly aren’t enabled by default, but that seems at least consistent with eMacs defaulting to very few modes enabled by default.

jhoechtl5 hours ago

The critique converning lsp and eglot support is nonetheless true.

chroma_zone8 hours ago

If it can't find an LSP binary, Eglot will prompt you to pick one, and tell you which one it was looking for. That seems reasonable to me. I wouldn't want Emacs to download and install random binaries on my system automatically.

dleslie7 hours ago

My experience with Emacs 30 is that Eglot will prompt and show nothing of meaningful assistance beyond a name. That leaves me to run a google search to find whatever binaries fit the description.

They host binaries already; why not host all of the binaries necessary for the supported features to function?

pjdesno11 hours ago

For those of us who have just been using Emacs, rather than following its recent evolution, "ts-mode" refers to a mode which uses tree-sitter for parsing, highlighting etc.

RahulMJ10 hours ago

Thanks for adding this. I just made a comment expanding a bit of what users may find in the new mode.

ggm4 hours ago

So I can get bold at a cost of shift* to get the star.

Or I can do ESC enable-this-mode-option and then press a single key.

I'm struggling with this. If it's cheaper in keystrokes to type the codes inline why enable the mode?

This isn't a vi vs emacs hate thing, It's a key count efficiency thing. I don't see the motivation even if translated to minimum prefix TAB complete terms. Its like 20x more presses.

rjprins4 hours ago

I still use my markdown-modern, and obsidian-style renderer. I read more markdown than I write and for that it works well. https://github.com/rjprins/markdown-modern

taude11 hours ago

One of the biggest reason I've stopped using Emacs, and I was a pretty heavy user before was that org-mode files weren't fully native Markdown files, which caused annoying friction when collaborating with others.

It would be interesting for me to have a new markdown-centric org-mode thing. I'd love to vibe lisp to customize my workflows, and I don't totally love Obsidian, which is what I've setup and configured now. I'd prefer to just have the config living in/around init.el/config.el (I used DoomEmacs most recently).

I realize that org/agenda, etc does a ton more than markdown offers, but most of my flow is just around: raw notes to be consumed, check lists, due dates on items, and other "basics" of org-mode.

Any recent Emacsers have similar workflows that are tgenible these days? I'd love to get Emacs back in use in my new antigenic Tmux-centric coding flows, and have it be a first class markdown editor, organizaer, and potentially collaboration.....

rpdillon10 hours ago

Org mode is a coherent whole, and has capabilities far beyond what Markdown can accomplish (Markdown is inherently HTML-based, org-mode is not). Markdown's history is littered with folks trying to augment it in just the right way to bring these sorts of features, which has resulted in a diaspora of flavors, none particularly dominant+powerful (which is to say, no real org-mode competitor has emerged, even though one could have). I've used Markdown and Org-mode for 20 years concurrently, and trying to make Markdown work like org-mode has never been successful for me.

I wrote a bit about this back in 2021, in response to a query on Reddit "Why didn't org-mode just use Markdown?".

https://rpdillon.net/why-doesnt-emacs-org-mode-just-use-mark...

iLemming9 hours ago

I love Org-mode and use it for many things - the outline format is great, even for some unexpected cases - Jira tickets, Slack, Reddit and HN threads, etc. But of course, hard to escape Markdown these days, so I burned some tokens to implement this https://github.com/agzam/prisma.el

iLemming6 hours ago

For example, I just added the ability of seamlessly copy&pasting between two formats (prisma-yank-mode) - if the source was a markdown, and you're pasting it into org - it will convert and vice versa. And if you really need to insert it verbatim - you just call it with C-u arg.

taude3 hours ago

That's a neat trick. I know about org-md for exporting generally to a markdown file but going in/out via buffers is useful.

kodoman11 hours ago

What is wrong with markdown mode? Is it that you would rather do the org agenda or calendar via md rather then org? I do understand that if that is the case.

iLemming9 hours ago

> What is wrong with markdown mode?

Nothing. It's just not Org-mode, and thus many great features of Org just not possible - sparse tree search; timestamps with built-in calendaring features; outline features like narrow-to-subtree; editing the subtree in an indirect buffer; executable code blocks; embedded LaTeX snippets; real tables with spreadsheet-like capability; checkbox statistics cookies - [/] and [%]; org-sort; column views; tags and tag inheritance; etc.

Anyone who's familiar with even a small subset of things that's possible in Org-mode and unlikely ever be supported in Markdown (just because there's no agreed format standard) have no confusion about it - Org-mode is absolutely superior. But superior doesn't mean universally better for everyone. The biggest drag of Org-mode is that it can never fully exist outside of Emacs. Yet Markdown can't ever fully cover its grounds (even in Emacs), simply because Markdown has to exist and work outside of Emacs as well.

kodoman9 hours ago

Else where in this thread you can see my argument is that all org-mode features such as calendar dates, todo's, take your pick could be implemented separate to and utilize markdown (or any other format) for actually rending to. I am familiar with org mode but dislike how it sometimes pushes against simply using elisp for things like setting up todo nodes and possible todo values. couple that with the fact that one could in theory just render this all out to markdown instead and come up with some way to render todos into md.

iLemming8 hours ago

Rendering Org in markdown is a solved problem, but wanting Markdown as the source is nuanced. It's difficult to achieve because there's no single agreement or convention - Org is not just markup syntax, its headings have records with types slots: TODO keyword, priority, tags, properties drawer, clock entries, etc. - Markdown has none of this. A CommonMark heading is a line of text; the spec does not even define a subtree, so folding, refiling and archiving need tree semantics layered on top.

So, you need to invent slots. Logseq did exactly that - all the org-mode specific lines get lifted verbatim into .md. Obsidian did it differently with emoji fields or Dataview inline fields (or whatever they called). Neither produces portable Markdown. GitHub renders those files as literal noise. The portability benefit that motivated the move evaporates the moment you add the metadata you need.

And then you'd have to build a specialized parser - there's no equivalent of `org-element` for Markdown. Sure, tree-sitter helps to some extent, but you're still lacking a semantic layer that turns nodes into records.

In essence - for Emacs to treat Markdown as Org-mode, we need to change Markdown, once that happens (if ever) Emacs can follow. But at this point it is already such a mess, it's crazy. Take front-matter alone - it's not CommonMark, it is a Jekyll convention that each tool does differently, and it is per-file, so your unit of thought is limited to become a file. That is the Obsidian/Denote/zk design, it works - but it moves your outline into the filesystem. You lose refile, subtree archive, narrowing, cut-and-yank of a subtree, and "this TODO belongs under that project heading". Org gives you both: file keywords at the top, property drawers on every heading, with inheritance down the subtree that front-matter structurally cannot express.

+1
Jtsummers8 hours ago
taude11 hours ago

Yeup, I would love to have some of the org/agenda operations/views on a regular markdown file. Especially so I could just copy it raw out, and paste into other markdown-centric tools, github md files, etc. for colaborating with others.

Since markdown is becoming so prevalent. Even our product managers are becoming natively conversant with it, I'd just prefer to have as markdown first world.

(don't get me started ranting about how Atlassian and Slack have migrated away from markdown and to proprietary formats....).

kodoman10 hours ago

Yes must say I have found myself moving away from org and looking at it as an annoyance wrapping up many excellent features that could be wrapped up in simple elisp function and structures that could then just be encoded in what every way one likes, it seems to me that for example todo lists are actually better as nested lisp lists, And then you can simply render as what ever you like. Of course one might like to serialize back as well but I have often wondered about it.

I definitely think markdown has won (at org was never going to 'win' of course given it's limited scope) and actually is probably what we should just all be using and accept.

+1
taude10 hours ago
mfld10 hours ago

Not tested this myself, but there are ways to improve markdown/org-mode interop, like in https://youtu.be/RJqRwlVvB3E

julienchastang6 hours ago

org-mode is a way more powerful literate programming environment which can be exported to many different formats including markdown. In the past, I have collaborated with others with markdown as the sort of interface format. But on the collaboration front and not everyone liking emacs, I found that there's no way around that. I am a huge fan of emacs and use it every day but it is not that great of a collaboration tool due to it not being everyone's cup of tea.

kelvinjps1010 hours ago

I use markdown and nvim with telekasten plugin on desktop and mobile obsidian and for me is good enough

edgyquant11 hours ago

What are people’s workflows for using eMacs with generative coding? I’m trying to get a workflow where I can generate code and approve it like a PR (maybe leave comments for a next round of generation) but I’m new to eMacs and the ai coding package isn’t working with the latest eMacs

remedan11 hours ago

Agent Shell connected via ACP to local Claude Code.

https://github.com/xenodium/agent-shell

wilkystyle11 hours ago

Can't say enough good things about agent-shell.el! Xenodium has done amazing work there.

aag10 hours ago

I'm a huge fan of agent-shell, too. It keeps getting better and better, and it's infinitely customizable, like any good Emacs package.

bryanlarsen11 hours ago

I'll have to try it again. It definitely feels like the right way to do things, but when I tried it it had a couple of show-stopper limitations and a show-stopper bug, so I've been using claude-code-ide.el instead.

mplanchard2 hours ago

Seconded, agent-shell is my favorite LLM interface bar none

banjomonster11 hours ago

I’ve been using gptel, I’ll have it generate org babel blocks I can tangle (write to files) or have it use tools to write and edit files in the project I’m working in, and then review with magit.

jwr9 hours ago

I use cLaude cOde in my eMacs (through ghostel, which is unbelievably great!) to generate code :-)

I then use mAgit to review it.

tom_9 hours ago

The iPhone autocorrects it to eMacs... it's so annoying.

mimischi7 hours ago

https://en.wikipedia.org/wiki/EMac

Setting up a keyboard replacement is the way to go here. Solves the issue for all devices.

sebastianavina10 hours ago

I use windows 11, wsl2, WezTerm.

emacs -nw directly on the shell.

its like working on a linux computer, but from windows.

I run vterm inside emacs, and claude code inside vterm. I have special commands for extracting file routes, and flow between dired and magit. Everything runs like magic.

I also have copilot-chat and copilot-mode installed. From time to time I use it to review what claude has done, or to chat a little bit.

scoops_8 hours ago

I’m trying to use a similar workflow, but when I attempt to use Claude code in vterm, I have issues.

My use case is resuming a session and not being able to scroll back to the past history. Otherwise if I start a new session, it works fine.

It’s probably related to me being on an old version of vterm, but I’m just wondering if you ever have come across this.

scoops_4 hours ago

I found my answer, I needed to be using page up and page down keys to “scroll” through the claude history - which is apparently required due to Claude capturing my C-v and M-v’s in its “text-box”.

suprfnk7 hours ago

Definitely try ghostel, it's really solid.

scoops_6 hours ago

Thanks, I would, and I’ve used it on my personal machines (it works great), but I’m trying to stick to the apt package repos on my $WORK machine.

Ubuntu has a fair number of elpa packages in its repos, so I’m trying to make it work if possible. Not sure if I’m missing anything config wise within the confines of vterm

bryanlarsen11 hours ago

IMO, generative coding on Emacs works nicely because magit is awesome for code review. A good agent integration package is going to have a command you can use to send the current cursor line & file to the agent so you can reference and comment.

kreyenborgi11 hours ago

Which AI coding package? Agent-shell? Gptel-agent?

edgyquant10 hours ago

It’s just called ai-code I’m new to eMacs so this popped up but had a bunch of issues I was trying to debug https://github.com/tninja/ai-code-interface.el

internet_points8 hours ago

Never heard of that one. The most popular ways for agent stuff seems to be https://github.com/xenodium/agent-shell , or just opening a terminal in emacs and using claude code. If you want to run it through an emacs terminal, consider using https://github.com/dakra/ghostel#ghostel (or vterm, or eat)

mplanchard2 hours ago

Thanks for posting the ghostel link, I hadn’t heard of it. Excited to try it out and see how it compares to vterm

seamossfet8 hours ago

just switched to doom emacs this month, absolutely loving it tbh

cpach7 hours ago

“You probably heard of this new markdown-ts-mode and decided to check it out.”

Uhm, no, I haven’t.

Why should I care if the Markdown mode uses Treesitter or not…? Does it affect the performance or UX somehow?

mplanchard2 hours ago

One option would be to read the section of the linked article talking about features: https://rahuljuliato.com/posts/markdown-ts-mode-emacs-31#a-q...