Comments (19)
Hello @morgandavidson!
What would be quite useful for denote users that also use tabs, would be to have the tabs only display the TITLE part of the file name.
Would that be feasible?
Do you know if centaur-tabs provides a function to rename buffers? If it does, then we can use it to achieve what you suggest. I have not used centaur-tabs for anything other than testing purposes (for my themes) and thus am not familiar with the technicalities. I can always check, but that requires time.
from denote.
Hello @protesilaos,
I don't know about centaur-tabs ability to rename buffers, I can ask the developers on centaur-tabs' Github. But is it about renaming buffers of tab names?
There are various ways of displaying tabs in Emacs (tabbar, centaur-tabs, moody, etc.). I'm not specifically focused on keeping using centaur-tabs, but rather on being able to use denote with tabs. Also, I guess that there might be denote users using tabs without centaur-tabs. So maybe the best possible solution would be something generic.
Also, rethinking about this issue, I thought that instead of having the tab name produced automatically (i.e. taking the TITLE), there could be an option to specify it, let's say #+tabname:
.
EDIT:
FYI I opened a question on emacs stackexchange and a ticket on centaur-tab github.
from denote.
From what I understand what could be done is the following:
- Automated naming version:
a new denote function will rename the buffer with the TITLE of the file usingrename-buffer
- Manual naming version:
#+tabname
option in the header will allow to give the buffer a specific name. A denote function will automatically change the buffer name with the value specified in#+tabname
.
from denote.
@morgandavidson I prefer the automated version because this is Emacs-specific. The #+tabname
adds noise because it has no meaning outside Emacs.
I will document how to do it as soon as possible.
from denote.
Please try this. We can refine it further, but it should be a starting point:
(defun my-denote-rename-file-buffer ()
(when-let* ((file (buffer-file-name))
((denote-file-has-identifier-p file))
(title (denote-retrieve-filename-title file)))
(rename-buffer title :unique)))
(add-hook 'find-file-hook #'my-denote-rename-file-buffer)
from denote.
Your code works quite well, thanks! The only issue I found is that when I open Emacs, it makes me land on the scratch buffer instead of the buffer I defined with setq initial-buffer-choice
.
Maybe both (auto and manual) could be implemented as options of a variable.
denote-rename-buffer
could take 3 exclusive values : a
for automatic, m
, for manual and nil
.
I am already using an implementation of the manual version (see my answer to this question), which I find quite useful.
There could also be a denote-rename-tab
variable, for the tab managers that support changing tab names without changing buffer names (see my answer to the above-mentioned emacs.stackexchange question). It is unfortunately not the case for centaur-tab at the moment.
I find the manual version more useful to me because sometimes my titles are quite long, which is good when you produce a document, but it is not practical to have such long titles as tab names.
For example, if I'm creating an org file having "The Hitchhiker's Guide to the Galaxy" as a title, it would be more practical to have H2G2 as a tab name.
from denote.
Hello @morgandavidson!
I am not familiar with centaur-tabs
. I think the manual approach makes more sense here. Adding such functionality to Denote is not trivial work because then we open up a whole new chapter of when renaming should happen: mode line, frame title, tabs, and maybe more.
Perhaps this is worth considering as an extension to the core package.
from denote.
Hello @protesilaos!
If the manual approach changes the buffer name, then it will work regardless of the tab package. Because to my knowledge, in all the tab packages, the tab name is the buffer name (and it can't be otherwise). There is an exception with tab-bar-mode
where the tab name is by default the buffer name, but can be different from it if specified (with tab-rename
).
I started trying alternatives to centaur-tabs
to use built-in Emacs modes when possible. I tried tab-bar-mode
but it wasn't adapted to my use case. Then I tried tab-line-mode
, which was fine but not as satisfying as centaur-tabs
. Now I'm using intuitive-tab-line-mode. For all these packages, the following snippet implemented the manual approach satisfyingly:
*** Specify buffer name with =#+tabname:= keyword
- Get =#+tabname:= value
#+begin_src emacs-lisp
(defun org-get-kw-value (kw)
"Get the value of keyword kw."
(save-excursion
(goto-char (point-min))
(let ((case-fold-search t))
(re-search-forward (format "^#\\+%s:\\(.+\\)" kw) nil t)
(when-let (kwval (match-string-no-properties 1))
(string-trim kwval)))))
#+end_src
- If =#+tabname:= exists set buffer-name to its value
#+begin_src emacs-lisp
(defun mda/org-hook-function ()
"If keyword TABNAME exists, set buffer-name to its value."
(when-let (new-buf-name (org-get-kw-value "tabname"))
(rename-buffer new-buf-name)))
(add-hook 'org-mode-hook #'mda/org-hook-function)
#+end_src
An alternative would be to use the org-element-api.
You're right when you say that it would not be trivial to have the mode-line
showing 20230410T021830--title-i-gave-to-the-org-file__tag1_tag2_tab3_tag4.org
and the tab showing My Org
due to #+tabname: My Org
. I don't even understand how it could be possible to have such a solution, working for all tab packages. Since tab name and buffer name are the same thing for them. Are you thinking of hacking the mode line
display?
from denote.
Hello again @morgandavidson!
Just to note that I have published a prototype of an extension: denote-rename-buffer.el
. It provides a minor mode that simply renames the Denote buffers. The idea is to make this configurable.
from denote.
Hello @protesilaos, thank you for letting me know,
If I understand correctly, there is one function that replaces the buffer name with the file title on demand, and a minor mode that replaces it automatically when activated. Am correct?
Do you plan to add a feature allowing users to name each buffer according to a name specifically chosen by them in the future?
from denote.
If I understand correctly, there is one function that replaces the buffer name with the file title on demand, and a minor mode that replaces it automatically when activated. Am correct? Do you plan to add a feature allowing users to name each buffer according to a name specifically chosen by them in the future?
Yes, your understanding is correct. The idea is to extend this basic functionality with user options. I will work on it as soon as I can.
from denote.
Hello @protesilaos!
That is great news. Thanks a lot!
from denote.
I defined a user option to allow users to specify the function they want to use. I wrote the details in the manual: https://protesilaos.com/emacs/denote#h:3ca4db16-8f26-4d7d-b748-bac48ae32d69.
Customize the user option
denote-rename-buffer-function
to affect how buffers are renamed. Its value must be the symbol of a function. The default is thedenote-rename-buffer-with-title
, with an alternative ofdenote-rename-buffer-with-identifier
.The user option also accepts an arbitrary function. Refer to the implementation details of
denote-rename-buffer-with-title
ordenote-rename-buffer-with-identifier
for guidance on how to write a custom function.
from denote.
This feature is now part of Denote version 2.0.0: https://protesilaos.com/codelog/2023-07-21-denote-2-0-0/
from denote.
Hello @protesilaos!
I just tested denote-rename-buffer-mode
Denote 2.0.0 and it's really cool. Thanks!
(denote-rename-buffer-mode 1)
changes the buffer name (and hence the tab name) to the note's title, and if you add
(setq denote-rename-buffer-function #'denote-rename-buffer-with-identifier)
it changes the buffer name to the note's identifier.
Also, you mention to look at denote-rename-buffer-with-title
and denote-rename-buffer-with-identifier
functions from denote-rename-buffer.el
for guidance on how to write a custom function.
These two functions respectively rely on denote--retrieve-title-or-filename
and denote-retrieve-filename-identifier
functions, defined in denote.el
.
I was wondering if there was an equivalent function, aiming to extract a custom buffer name specified within the buffer.
from denote.
from denote.
Hi @protesilaos,
Thank you for the help with the function. As it is a bit sophisticated in regard to my Elisp level, I didn't have the time to work on it yet.
However, I found an easy way to rename an org buffer/tab.
Generally, you can specify the buffer name (and consequently the tab name) of a given org file by putting the following snippet at the bottom of this file:
* Local Variables :noexport:
# Local Variables:
# eval: (rename-buffer "foo")
# End:
Unfortunately, it doesn't work with denote files. But what is odd is that running
#+begin_src emacs-lisp
(rename-buffer "foo")
#+end_src
inside a denote file works...
I was wondering if there was an equivalent of rename-buffer
that would work to specify a local variable for a denote file.
from denote.
from denote.
Hello Protesilaos,
Indeed I activated denote-rename-buffer-mode
since I would like to have #+title:
value as buffer name for most of my denote notes. In some cases though, I would have preferred to have a specific buffer name that is different from the #+title:
value.
from denote.
Related Issues (20)
- Hacking `denote-rename-file` to allow changing the ID HOT 15
- Enhancing `denote-rename-file` to handle not-yet-saved visiting buffer HOT 3
- Denote file names... without ID (cue ominous music) HOT 16
- Path in `denote-backlinks` buffer is wrong (extra directory in the link) HOT 5
- A `denote-filetype-heuristics` variant to help other code HOT 5
- sort by title outside of denote-directory HOT 5
- I use `denote-rename-file` as my main file renaming UI HOT 6
- `denote--edit-front-matter-p` docstring vs behavior HOT 1
- Possible to create a denote file outside denote-directory? HOT 5
- markdown links HOT 3
- Commit 232bd90 does not only apply to signatures HOT 13
- is it possible to create single tag with multiple words seperated by delimter? HOT 3
- Backlink buffer aware of org heading HOT 2
- Can't add link to file from within org-capture: "The current file type is not recognized by Denote" HOT 8
- Problem due to overloading `no-confirm` for "save" HOT 7
- How can I figure out which version of denote is currently used? HOT 4
- Templates are not working in denote-org-capture-with-prompts HOT 5
- Cannot add a denote link in `org-add-log-note` HOT 2
- update the link description if the target title is changed HOT 7
- Announcement: Some upcoming features available in my fork HOT 15
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from denote.