-
-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
denote-rename-buffer should not be used for files that are not notes #261
Comments
Thank you @brabalan for reporting this! You are right. I think we can work around this by tweaking
Yes, we can have this. Though I think a more do-the-right-thing sort of approach is better here to give meaningful, albeit not always perfect, names at all times. |
Perhaps this change is enough? (defun denote-rename-buffer--format (buffer)
"Parse the BUFFER through the `denote-rename-buffer-format'."
(when-let ((file (buffer-file-name buffer))
(type (denote-filetype-heuristics file)))
(string-trim
(format-spec denote-rename-buffer-format
(list (cons ?t (cond
((not (denote-file-is-writable-and-supported-p file))
(denote-retrieve-filename-title file))
((denote-retrieve-front-matter-title-value file type))
(t "")))
(cons ?i (or (denote-retrieve-filename-identifier file) ""))
(cons ?d (or (denote-retrieve-filename-identifier file) ""))
(cons ?s (or (denote-retrieve-filename-signature file) ""))
(cons ?k (cond
((not (denote-file-is-writable-and-supported-p file))
(denote-retrieve-filename-keywords file))
((denote-retrieve-front-matter-keywords-value-as-string file type))
(t "")))
(cons ?% "%"))
'delete)))) The diff: denote-rename-buffer.el | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/denote-rename-buffer.el b/denote-rename-buffer.el
index 4230b35..91a93cc 100644
--- a/denote-rename-buffer.el
+++ b/denote-rename-buffer.el
@@ -93,11 +93,19 @@ (defun denote-rename-buffer--format (buffer)
(type (denote-filetype-heuristics file)))
(string-trim
(format-spec denote-rename-buffer-format
- (list (cons ?t (or (denote-retrieve-front-matter-title-value file type) ""))
+ (list (cons ?t (cond
+ ((not (denote-file-is-writable-and-supported-p file))
+ (denote-retrieve-filename-title file))
+ ((denote-retrieve-front-matter-title-value file type))
+ (t "")))
(cons ?i (or (denote-retrieve-filename-identifier file) ""))
(cons ?d (or (denote-retrieve-filename-identifier file) ""))
(cons ?s (or (denote-retrieve-filename-signature file) ""))
- (cons ?k (or (denote-retrieve-front-matter-keywords-value-as-string file type) ""))
+ (cons ?k (cond
+ ((not (denote-file-is-writable-and-supported-p file))
+ (denote-retrieve-filename-keywords file))
+ ((denote-retrieve-front-matter-keywords-value-as-string file type))
+ (t "")))
(cons ?% "%"))
'delete))))
|
Thanks! This would work, but about the following logic: "if |
You mean it does not return a value right now? When I test this on my end, it prompts for a file and then returns its title: (let* ((file (denote-file-prompt))
(type (denote-filetype-heuristics file)))
(cond
;; ((not (denote-file-is-writable-and-supported-p file))
;; (denote-retrieve-filename-title file))
((denote-retrieve-front-matter-title-value file type))
(t ""))) Or did I miss something? |
What I mean is that the code for the title could be this: (let* ((file (denote-file-prompt))
(type (denote-filetype-heuristics file)))
(cond
;; ((not (denote-file-is-writable-and-supported-p file))
;; (denote-retrieve-filename-title file))
((denote-retrieve-front-matter-title-value file type))
((denote-retrieve-filename-title file))
(t ""))) I tested it and it works both with a note (returning the title from the front matter) and with a binary file (returning the title from the file name). |
…matter Thanks to Alan Schmitt for reporting the relevant issue with PDFs and for commenting on the code I suggested. This was done in issue 261: <#261>.
Done, thank you! |
Thank you! |
I have set-up `denote-rename-buffer' as follows:
My problem is that it is used for every denote file, including my pdfs stored in denote and viewed in emacs. For them, the buffer name is
[D] ()
, as there is no title nor keyword to retrieve from the front matter. I see there is some code that prevents the renaming when the string is empty, but as I configureddenote-rename-buffer-format
, this is never the case for me.Could it be possible to (have an option to) only rename buffers that are notes?
The text was updated successfully, but these errors were encountered: