I sometimes work with long functions or big org subtrees and it’s not always clear what function or org subtree I’m in right now. I wish there is a package that can show me what function I’m in.
Turns out Emacs has this mode built-in so this functionality is just M-x which-function-mode
away.
It shows in the status line a function name I’m currently in (see [encode_terminal_code]
on the screenshot above).
It’s global mode so as soon as it’s enabled, you’ll see it’s working for every buffer.
You can have it enabled on Emacs startup by adding (which-function-mode)
to your config file.
I just started to get benefits of this mode but it’s already surprising how well it works:
It doesn’t seem to work in html files I tried it with or modes that use html (e.g. vuejs or laravel blade files).
It definitely not an issue for me so I’m going to continue using it and I suggest you to try it out.
Sometimes I use C-x C-b
to get list of buffers so I can
clean it up a little after some time.
To do it I mark some buffers with d
(to delete) and then press x
.
Today I wanted to filter that list of buffers to a particular project/folder and turned out I can’t.
There is no way to filter *Buffer List*.
If you look up for Buffer Menu in EmacsWiki you’ll find the Enhancements section which mentions IBufferMode
which is built-in since Emacs 22.
This mode is literally Buffer Menu on steroids. Looks pretty much the same so from UI perspective you’ll see no changes (almost).
To filter buffers by directory just type / F
and enter the project/folder name.
The only thing left is C-x h d x
to mark all buffers and delete them.
To remove all the applied filters just do / /
.
The number of filtering commands available by default is great.
You can find them by C-h m
(describe-mode) and then look for “Filtering commands” section. Go through other sections as well to get more familiar with ibuffer capabilities.
If you’re Doom user you probably already enjoying this mode since it’s enabled by default.
In Spacemacs you can enable it by turning on ibuffer
layer.
Both of these config distributions remap standard C-x C-b
to call ibuffer
and I suggest you do the same if you use custom config like me.
We all need to search in files sometimes, right?
I usually do it using grep -ri 'search term' .
in the terminal (often in vterm-mode)
and then I either open the file(s) in Emacs or in any other program.
But Emacs has better solution to it.
There is M-x find-grep-dired
already built-in to Emacs.
If you call it from Dired buffer it will auto-complete the current folder
and then you just need to enter the search term.
Cool thing is that result of this function is just filtered Dired buffer which means
you can perform regular Dired operations on the found files (delete them, move to another folder, etc).
This especially come in handy if you have (setq dired-dwim-target t)
and another Dired buffer opened in split so you
can quickly move files between splits (Far/Total Commander style).
M-x find-grep-dired
is as quick as grep
is.
According to this function’s help page you can change grep-program
variable
if you want to use rg, ag or whatever…
CAUTION: It’s pretty possible grep-program
may be used by other Emacs functions that may expect grep-specific output.
Surprisingly for me I just discovered that Emacs Lisp has equivalent
of Clojure’s ->
and ->>
macros.
And I’m not talking about dash.el
. I’m talking about built-in thread-first
and thread-last
.
If you’re not familiar with these beautiful macros, the main goal is to pipe a value through multiple functions and return the result.
->
passes a value as first argument of next function, then takes the result and passes it as first argument to next function, etc.
->>
does the same except that it passes the result as next function’s last argument
Instead of having this:
(+ (- (/ (+ 5 20) 25)) 40)
we can have this:
(->
5
(+ 20)
(/ 25)
-
(+ 40))
It’s way easier to modify and which is even more important - to read.
There is dash.el
library that provides us with similar macros (and many more) but emacs has built-in thread-first
and thread-last
.
(thread-first
5
(+ 20)
(/ 25)
-
(+ 40))
will work for you if you’re on Emacs 25 or newer.
I don’t write much elisp but every time I do I feel like I miss those ->
/->>
.
Not anymore!
]]>It has been almost a year since I started to use Org-Roam. I initially migrated from Obsidian even though I was incredibly happy with it.
Recently I started to take more notes than usual and noticed that Org-Roam has some issues that for me aren’t critical but disturbing.
There is just no something like M-x org-roam-search
.
I’m pretty sure there is no such thing because it’s Emacs and you can search any directory you want very quickly
using built-in grep
, rgrep
or other tools like that.
And of course you can make a function off of that and then bind it to a key chord you like.
But having such function already there will not force Org-Roam users to add more lines to their config.
org-roam-node-insert
is very useful. Is how you link notes together.
At the moment when note is typed I usually quickly review it and then connect it to other notes. In such a case I move my cursor to a word that I’m going to use as a link and type that command.
The minibuffer starts listing all the notes but the “linking word” my cursor is at isn’t used.
There is no such issue in case you mark a word and then call M-x org-roam-node-insert
.
Again, since it’s Emacs it should be quite easy to fix.
It would be nice to have it default though. I can’t find arguments against it.
Yes, it is in a file name BUT
if you use grep or even something like consult-grep for searching in your notes you will not be able to filter your results by a date.
It probably can be fixed with org roam templates.
I was able to find many complains about it.
For me it’s not that serious in terms of fear that my notes and links may stop working if I loose the roam db (the db is just a cache) or roam is not supported anymore (org files are text).
The main issue for me here is that I can’t understand the links if I open my notes in an editor that doesn’t have Org Mode. It sometimes happens. It happens on my Android. It happens on my Windows machine that I barely use and I don’t even need Emacs there.
In such a case I see the link with an ID and description of that link which sometimes doesn’t exactly match a note file name.
If org format is pure text and intended to be human readable, it’s probably should stay this way.
It should be understood that Org-Roam is open source and community driven. It definitely can be improved as, probably, any software.
The only person I can blame for not implementing those functionalities I mentioned is me. The project is opened for everyone to contribute (including me) so I hope I can fix those things somehow.
]]>By default only the tags directly attached to an org record will be saved in the archive file. I want to keep all the tags attached to an org record when I archive it, even the inherited ones.
In org-mode tags are inherited by default. In case of org tree like this:
* Header1 :tag1:
** Sub Header1 :subtag1:
you may find that Sub Header1 has :tag1:subtag1:
tags attached to it.
This is something reflected in Agenda view.
Also if you try to find headers with :tag1:
the Sub Header1 will be one of those even though
we didn’t directly attach that tag to it. That’s the tag inheritance.
If you try to archive Sub Header1 you will get this kind of record in the *_archive.org file:
* Sub Header1 :subtag1: <--- this is the tag
:PROPERTIES:
:ARCHIVE_TIME: <date>
:ARCHIVE_FILE: <original org file>
:ARCHIVE_OLPATH: <org path>
:ARCHIVE_CATEGORY: <org file category>
:ARCHIVE_ITAGS: tag1 <--- this is the inherited tags
:END:
As you can see the tag1
is missing in the heading. It is available in the ARCHIVE_ITAGS
though.
For me it would be much better if I can see all the tags immediately in the record heading. It will also allow me to filter
my archived records by those tags.
(setq org-archive-subtree-add-inherited-tags t)
It’s as easy as that. Now the archived heading will look like this:
* Sub Header1 :tag1:subtag1:
which is exactly what I wanted.
]]>I initially was a little afraid that I will not be able to understand what each Doom module does and there always will be some hidden functionaltiy that will be hard for me to find.
Fortunately there is M-x M-x doom/help-search-headings
that allows me to search through
Doom documentation. Specifically it allows me to search through org headings of the documentation.
I can easily find a module I’m interested in, let’s say lsp
.
Then I’ll go there and I can see all the documentation of the module. I can see what packages will be installed and what configuration
options available for the module (e.g. +eglot
for lsp
).
Being in the README.org
of a module I can also open config.el
which is in the same directory and I’ll be able to inspect
all the Elisp that module will add into my Emacs.
If you’d like to search not just headings but everything then M-x doom/help-search
is your friend.
I start to like Doom more and more every day.
]]>I don’t really like it because sometimes I open php files that I don’t need autocompletion for and I don’t want to remember that there is Eglot process now running that I have to stop to save some resources of my laptop.
It happens because I have defined php
module in init.el
as (php +lsp)
.
The reason I have it defined like this is because I need LSP.
I just don’t want to start it automatically every time I open a php file.
I like how easy it is in Doom to inspect the module implementation so I went to Doom’s modules/lang/php/config.el
and I found
that there is no flag that can force LSP to not start automatically.
What it has though is this line:
(add-hook 'php-mode-local-vars-hook #'lsp! 'append)
It looks to me like something that starts the LSP automatically. It looks like this mostly because everything else looks pretty much unrelated to LSP.
Since there is no flag, let’s solve it in our own config by directly removing that lsp!
piece from that variable:
(after! php-mode
(remove-hook 'php-mode-local-vars-hook #'lsp!))
This will remove that lsp!
piece from php-mode-local-vars-hook
and now LSP won’t start automatically.
It would make sense probably to add such a flag so users can easily turn off the auto-LSP but at the same time solution to this is just one line so maybe it wouldn’t make sense to add it.
]]>Today I decided to try it once again. I also wanted to use it in Evil mode to make my hands feel better.
One of my main pain point with someone else’s config is that I don’t know how to handle it, what options are available and why things work in the way they do.
Since I was on my own config for quite some time I believe I know enough about Emacs configuration to attempt Doom config once again.
Well, it’s not first. If I’m not mistaken it’s my third or fourth attempt to use Doom.
So far it feels ok. I ported some configuration from my vanilla config. Added packages I need and things seems working smoothly.
It’s interesting to see that Doom preferably switched to project
mode instead of projectile
at least this is what I see
based on keybindings that are set for project
mode and no keybindings at all for projectile
.
My custom org agendas and some other custom functions were ported with just simple copy-paste technique.
M-x doom/help
exists. Everything is documented or at least most of the things.M-x doom/help-search
which is very useful when you need to find a specific help.
evil escape sequence
to something different from default. At least the doom/help-search
mentions the evil-escape
package which user then can google and find how to change that escape sequence.projectile-run-vterm
. Easy fix though.+vterm/toggle
. It works great in one project but when I open a second one then this function still opens up the vterm that belongs to that first project.doom/reload-theme
- probably doesn’t work on my end. When I set doom-theme
variable to something else/non-default and then call M-x doom/reload-theme
nothing changes. I have to use M-x consult-theme
to actually change a theme.after!
. I initially thought that this macro’s first argument is something that is mentioned in init.el -> doom!
call but apparently I should specify an emacs package name there.In general, I love the feeling. It took me almost no time to get used to vim keybindings and keep coding like nothing’s changed. Probably my vim past is already too deep in my muscle memory. I’m glad my emacs past is also quite deep so I feel like I can seamlessly switch from one way of editing to another.
]]>I often use the latter but the issue here is that all my items got disappeared from Org Agenda view when archived.
You can tell Org Agenda to show archived records by pressing
v A
in *Org Agenda*
buffer.
Notice upper-cased A
. If you use lowercase a
then only internally
archived records will be shown.
What v A
does is it calling (org-agenda-archives-mode 'files)
which internally sets org-agenda-archives-mode
variable to t
.
This is what we can do in our init.el
:
(setq org-agenda-archives-mode t)
Done!
]]>