Right now, it seems like the name of org-roam note buffers simply copy the note’s file name. Does anyone else feel it would be nicer to have it copy the +TITLE of the note?
For example, all my note names have the format “%<%Y%m%d%H%M%S>”, a simple year, month, day, hour, minute, second timestamp. I like the uniformity this brings to my org-roam notes folder, and I like that note titles are decoupled from file names.
My most recent note is named “20200612171529.org”. It happens to have the +TITLE “Some Note-Taking Conventions”. It would be nice if the name of the buffer could be “Some Note-Taking Conventions” instead of “20200612171529.org”.
With the current state of things, C-x-b to switch-buffer (with ivy) shows me tons of notes named with timestamps like “20200612171529.org”. I know I can use org-roam-find-file instead, but it would be nice for the Emacs buffer list to be populated with informational names rather than timestamps.
I realize that org-roam would have to handle changing the buffer name should the name of the note be changed. This doesn’t seem like a huge problem to me, but I also don’t know much about the internals of org-roam. For all I know, this is already a feature and I’m unaware.
If this doesn’t exist already, should I submit a feature request somewhere? Could this be implemented simply in my init.el? Does anyone else even like this idea? Thanks for reading!
${slug} is by default a processed version of the title in which spaces and illegal symbols are replaced with underscores.
On the other hand, we’ve created commands which allow you to select notes based on their titles: org-roam-find-file. Because of this, you might prefer it to the traditional buffer-switching commands in Emacs.
I also use eyebrowse-mode to switch between different workspaces, so my note-taking environment is separated from whatever project I am working in Emacs.
I am already using org-roam-find-file, and it works great for limiting my search to only org-roam notes. I like the uniformity of my timestamp-named-files, especially because I sometimes choose to change the title of the note and there’s no point in having it coupled with the file.
Changing the name of the buffer itself seems cleaner to me. What are your thoughts on whether that’s possible/a good idea @zaeph ? Anywhere else you think I could post to get some more opinions?
Changing the name of the buffer is possible, but not advisable.
Buffers which are linked to files should always feature the name of the file. On the other hand, indirect buffer can get away with fancier names. The thing we might be able to do is include the title of the file at the end of the buffer-name, just as Emacs disambiguate buffers which would otherwise have the same name.
The result would be something like 20200407001953-foo.org<Foo>. Please open a PR on the tracker if you’d like us to consider this more formally.
hi @neilyio, pardon me if this has been part of the exchange above; is it possible that the org-roam-switch-to-buffer command does what you would like to achieve? You can assign a key binding for it, like C-c n b as an example. If notes in Org-roam are open as buffers, you should be able to see a list of their titles. I don’t use it myself, so I may be mistaken.
Thanks for pointing that out! That is exactly the way that I’m currently switching org-roam buffers, and there’s nothing wrong with it.
I guess I was just curious as to why, from an org-roam design perspective, my note buffers can’t be better integrated with regular old emacs buffer switching. Buffer switching is one of those reflexive actions you do without thinking about the shortcuts you’re pressing.
I find myself constantly wanting to switch between code files that I’m writing and notes that I’m writing, and it’s a little annoying when I hit the wrong shortcut. I have to remember that C-c n b is what I use to switch to a note buffer, and C-x b is what I use to switch to any other buffer.
I take @zaeph’s word for it that “buffers which are linked to files should always feature the name of the file”. These guys have done an outstanding job with org-roam so far, and I’m sure that design compromises like this have good reasons behind them.
If this is the way it is, I think I’ll follow @hieuphay’s advice and try and exclude these files from regular helm/ivy, and just maintain a “separate” area of emacs for org-roam. I suppose I could even try and re-bind C-x b to org-roam-find-file in that separate area. I usually don’t like to complicate my config with things like this, but org-roam is certainly worth it.
Still interested in the feature if anyone else wants to discuss it, but I’m glad everyone could pitch in here.
It works with C-x b. The column in the left shows file names, and the middle one, title if Org-roam notes.
Add a custom func like the one below to ivy-rich-display-transformers-list.
Personally, I don’t find this presentation clean, but it may be a way. Extending this idea, you could even
conditionally show either file name or title in one column…
This custom func below is just a quick proof of concept. It will likely fail if you have not loaded org-roam before hitting C-x b (because it relies on functions from org-roam).
This is definitely the better solution. I don’t think it’s a good idea to mess with the buffer name, if the buffer corresponds to the file. Might be more confusing than it is not.
With this, if I have a buffer that starts with #+TITLE:, the title is used instead of the file name when I call ibuffer (my favorite way of swiching buffers) or ivy-switch-buffers. It works like a charm, not only on org-roam but in all org-mode buffers.
(defun org+-buffer-name-to-title (&optional end)
"Rename buffer to value of #+TITLE:.
If END is non-nil search for #+TITLE: at `point' and
delimit it to END.
Start an unlimited search at `point-min' otherwise."
(interactive)
(let ((beg (or (and end (point))
(point-min))))
(save-excursion
(when end
(goto-char end)
(setq end (line-end-position)))
(goto-char beg)
(when (re-search-forward "^[[:space:]]*#\\+TITLE:[[:space:]]*\\(.*?\\)[[:space:]]*$" end t)
(rename-buffer (match-string 1)))))
nil)
(defun org+-buffer-name-to-title-config ()
"Configure Org to rename buffer to value of #+TITLE:."
(font-lock-add-keywords nil '(org+-buffer-name-to-title)))
(add-hook 'org-mode-hook #'org+-buffer-name-to-title-config)
After a second thought, I think it’s probably a bug in org-roam somewhere down org-roam–get-title-or-slug, so it probably should be addressed upstream rather than workaround like this.
Why isn’t this advisable? rename-buffer will rename the buffer without changing the underlying file the buffer is visiting. Any code dealing with manipulating the file should not be reliant on the buffer-name to do so.
This may not be relevant to you anymore, but if you are still looking for something like this, you may consider using one of the suggestions in this more recent thread: