Skip to content

Instantly share code, notes, and snippets.

@habamax
habamax / emacs-python-treesitter-eglot.org
Last active April 22, 2024 11:39
Setup Emacs for Python with Treesitter and Eglot

Emacs, Python, Treesitter and Eglot

Treesitter (“better”/faster syntax highlighting)

  1. Make sure you have Emacs with treesitter support:

    M-: (treesit-available-p) RET should return t

  2. Make sure you have installed python treesitter grammar

Some useful custom text objects for vim

Collection of my custom text objects I use quite often.

97975602 6e90ee00 1dda 11eb 9286 6894300457e3

Numbers

Put it into your .vimrc:

Simple Templates In Vim

Vim has :h skeleton help topic for when you want to read a skeleton (template) file into a new file.

For me the idea of automatic templates is not that appealing, instead I would rather insert a template when I need it:

:r ~/.vim/asciidoctor/template_for_entity_relation_diagram

Annoying vim search highlight "everyone" tries to get rid of

You have turned on hlsearch for some reason in your vim config (well obviously to highlight your searches) but it gets in your way, right?

Now you try to find a solution to this problem, like

  1. spam random searches /klsdf<CR>

  2. do :nohl command or

"better" gx for vim

Vim has built-in gx mapping to open an URL under the cursor defined in the bundled netrw plugin. It is limited to barebone urls and quite often that is not enough.

I have come up with a better gx mapping (for me of course) that is able to open:

  • markdown links [Hacker news](https://news.ycombinator.com 'link to Hacker news website');

  • asciidoc links https://news.ycombinator.com[Hacker news];

" Author: Maxim Kim <habamax@gmail.com>
" Desc: Sync current buffer with the github gist having the same file name.
"
" Prereqs:
" 1. Install and setup https://cli.github.com/
" 2. Put this file to ~/.vim/autoload/gist.vim
"
" Usage: Open file and :call gist#sync()
"
" Create helper command if needed

Simple journal with vim

So how would you use your text editor to make a daily notes?

For vim I end up using simple approach:

  • have a ~/docs/journal/ directory where I keep yearly journals in asciidoc format (one can use markdown of course).

  • have a mapping to quickly open a journal ready to enter you thoughts, notes or a todos for a day.

"Swap words" in vim

Quite a common task to swap words on a single line might be really cumbersome.

Consider following text transormation: