I would like to increase the text size of the side panel. I wrote a function to do that, but I have no idea how to call it when org-roam-buffer-toggle is activated. Is there a way to do it without hacking the org-roam code? Thank you in advance for any suggestion.
(defun org-roam-buffer-increase ()
"stub to increase the side buffer"
(interactive)
(save-excursion
(set-buffer org-roam-buffer)
(text-scale-adjust +1)))
I tried but it is way, way above my beginner’s ability. This is the code I put in:
(defun org-roam-buffer-increase ()
"stub to increase the side buffer"
(interactive)
(when (get-buffer org-roam-buffer)
(save-excursion
(set-buffer org-roam-buffer)
(text-scale-adjust +1))))
(add-hook 'org-roam-mode-hook (org-roam-buffer-increase))
but every time I open the side buffer I get “Symbol’s function definition is void: nil”.
I found a solution though. It works well enough for me. Instead of calling org-roam-buffer-toggle when I call my function, I include org-roam-buffer-toggle in the function and bind “C-c n l” to my function.
(use-package org-roam
:quelpa (:upgrade t)
:after org
:ensure t
:init
(setq org-roam-v2-ack t)
;; for org-roam-buffer-toggle
(add-to-list 'display-buffer-alist
'("\\*org-roam\\*"
(display-buffer-in-direction)
(direction . right)
(window-width . 0.33)
(window-height . fit-window-to-buffer)))
:custom
...
:config
(org-roam-bibtex-mode +1) ;; starts org-roam-bibtex-mode to make Helm-bibtex use Org-roam
...
(defun my/org-roam-buffer-increase ()
"stub to increase the side buffer text size"
(interactive)
(org-roam-buffer-toggle)
(save-excursion
(set-buffer org-roam-buffer)
(text-scale-adjust +1)))
:bind
(("C-c n l" . my/org-roam-buffer-increase)
...
)
I don’t use use-package which has its own syntax to use :hook. But for plain Elisp, you can simply put something like this outside the function definition:
This should call org-roam-buffer-increase function when org-roam-mode is enabled (this should be when you open the backlinks buffer). I believe it should be every time you open a new one but cannot be sure.
For some convention, some people add “#” to symbols to indicate functions as in (add-hook 'org-roam-mode-hook #'org-roam-buffer-increase) I don’t see any benefit with doing it – with/without “#” just works fine.
e.g. I have this in my config:
(add-hook 'org-roam-mode-hook #'olivetti-mode)
If you use hooks this way, I believe you don’t have to find and set org-roam-buffer explicitly – the function would just work on the “current-buffer”, which should be the org-roam-buffer in question – you can easily find out if this is true or not…
@nobiot
Ah, I confused the syntax between use-package and (add-hook)! Thank you for clarifying how the hook system works! So, I experimented a bit and learned a lot.
I tried add-hook first, and it works:
(defun org-roam-buffer-increase ()
"stub to increase the side buffer"
(interactive)
(when (get-buffer org-roam-buffer)
(save-excursion
(set-buffer org-roam-buffer)
(text-scale-adjust +1))))
(add-hook 'org-roam-mode-hook #'org-roam-buffer-increase)
You said:
… and indeed, you are right. If I do this, it works as well:
(defun org-roam-buffer-increase ()
"stub to increase the text in the side buffer"
(interactive)
(text-scale-adjust +1))
(add-hook 'org-roam-mode-hook #'org-roam-buffer-increase)
Then, I thought that I could avoid writing the function all together and use an anonymous function, and also this works:
@nobiot
The only code I wrote is a bit of shell code and I also used a scripting language from a scientific imaging software. Nothing more than few lines of code. I don’t know why, but elisp clicks with my weird brain, I tried so many times to learn coding from reading books and always failed miserably. With elisp, I look at code written by people like you, and I almost get it, and more I read it and more I get it. It is bizarre and I can’t understand why it is like this for me.
I saw the anonymous function used in init.el of some org-mode guru and it stuck with me, That’s all.
@QingshuiZheng I am a bit embarrassed to admit that I looked at the documentation several times, and I never noticed that in :hook you are supposed to remove “-hook” from the variable name. I am really grateful that you took the time to read my post and respond with the correct suggestion. I learned something, thanks to you. Of course, the code now works perfectly.
To summarize, if a org-roam user would like to change the size of the text in the side buffer, the most concise way to do it in the use-package framework, is the code shown in @QingshuiZheng above message. This is what I have included in my init file. Thank you again both to @nobiot and @QingshuiZheng . This community is amazing.