-
Notifications
You must be signed in to change notification settings - Fork 15
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 notes show filename rather instead of title #14
Comments
Unfortunately there's no support for titles as opposed to filenames outside of consult-org-roam. The latter only works because I can directly query the roam db. I also use Denote, and for me this is not an issue since the filename mirrors the title and tags. I imagine you could create a custom grep/ripgrep search for title in denote-formatted files. But the default consult-multi listing of notes uses |
Ah yes, that makes sense. There's |
Yeah, seems like it would be less expensive to pass the value of |
So I hacked this together (with my limited elisp skills) in order to test this: (setq consult--source-denotes
`(:name "denote"
:items ,(lambda ()
(mapcar (lambda (f) (denote-retrieve-title-value f 'org))
(directory-files
denote-directory
'full-path
consult-notes-file-match)))))
(consult-notes '(consult--source-denotes)) ... this shows title notes, but I guess I then need to come up with an appropriate |
I think Deft has some sort of hashing of contents, including the title. Don't think it is grep. But the strength of Denote is that it doesn't use any hashing at all, so that’s not really the way to go. |
Yes, You might also look at the function |
This seems to work, so long as you don't mind seeing the id # in the list: (with-eval-after-load 'consult-notes
(defvar consult--source-denote
(list :name "Denote notes"
:narrow ?d
:category 'files
:items (lambda ()
(mapcar (lambda (f) (concat (denote-retrieve-filename-identifier f) " " (denote-retrieve-title-value f 'org)))
(directory-files
path-to-files.....
'full-path
consult-notes-file-match)))
:action (lambda (f)
(let* ((file-id (denote-retrieve-filename-identifier f))
(id-path (denote-get-path-by-id file-id)))
(denote-open-or-create id-path))))))
(defun consult-denote ()
(interactive)
(require 'denote)
(require 'consult-notes)
(consult-notes '(consult--source-denote))) |
This is great! Thanks for your help. I'll be looking at the code more closely. One thing that can be simplified is to use I was thinking that another way to achieve this, might be to use |
This is what I came up with for the time being: I include the full path in the The only drawback of this approach is that any Embark actions still use the full (defun efls/return-invisible-substring (string)
"Return the first invisible substring from STRING.
With 'invisible substring' is meant: text with the invisible property.
If no invisible text is found, return nil."
(with-temp-buffer
(insert string)
(if-let ((match (text-property-search-backward 'invisible)))
(buffer-substring-no-properties
(prop-match-beginning match)
(prop-match-end match)))))
(with-eval-after-load 'consult-notes
(setq consult--source-denote
(list :name "Denote notes"
:narrow ?d
:category 'files
:annotate (lambda (c) (consult-notes-annotate-denote c))
:items (lambda ()
(mapcar (lambda (f)
(concat
;; Prepend the full path as hidden text
(propertize f 'invisible t)
;; and append the title value
(denote-retrieve-filename-title f)))
(denote-directory-files)))
:action (lambda (f)
(find-file (efls/return-invisible-substring f))))))
(defun consult-notes-annotate-denote (cand)
(let* ((path (efls/return-invisible-substring cand))
(attrs (file-attributes path))
(ftime (consult-notes--time (file-attribute-modification-time attrs)))
(fsize (file-size-human-readable (file-attribute-size attrs)))
(keywords (denote-retrieve-keywords-value path 'org)))
(put-text-property 0 (length fsize) 'face 'consult-notes-size fsize)
(put-text-property 0 (length ftime) 'face 'consult-notes-time ftime)
(format "%-30s %5s %8s"
(if keywords
(concat "#: "
(mapconcat 'identity keywords " "))
"")
fsize
ftime)))
(defun consult-denote ()
(interactive)
(require 'denote)
(require 'consult-notes)
(consult-notes '(consult--source-denote))) |
Can't you propertize the title text with the path directly ? Like (with-eval-after-load 'consult-notes
(setq consult--source-denote
(list :name "Denote notes"
:narrow ?d
:category 'files
:annotate (lambda (c) (consult-notes-annotate-denote c))
:items (lambda ()
(mapcar (lambda (f)
(propertize (denote-retrieve-filename-title f) 'denote-path f))
(denote-directory-files)))
:action (lambda (f)
(find-file (get-text-property 0 'denote-path f))))))
(defun consult-notes-annotate-denote (cand)
(let* ((path (get-text-property 0 'denote-path cand))
(attrs (file-attributes path))
(ftime (consult-notes--time (file-attribute-modification-time attrs)))
(fsize (file-size-human-readable (file-attribute-size attrs)))
(keywords (denote-retrieve-keywords-value path 'org)))
(put-text-property 0 (length fsize) 'face 'consult-notes-size fsize)
(put-text-property 0 (length ftime) 'face 'consult-notes-time ftime)
(format "%-30s %5s %8s"
(if keywords
(concat "#: "
(mapconcat 'identity keywords " "))
"")
fsize
ftime)))
(defun consult-denote ()
(interactive)
(require 'denote)
(require 'consult-notes)
(consult-notes '(consult--source-denote))) with this you don't need your helper anymore. Text-properties are very useful to attach arbitrary data to any string |
Ooh that's even better. Great suggestion, thanks. |
I have modified the snippets above a little bit, it now could filter by denote-subdirectory, keywords. And it can create new node if no match being found. ;;; consult-denote.el --- find or create denote notes using consult -*- lexical-binding: t -*-
;;; Commentary:
;;; Code:
(require 'denote)
;; This dependency is not necessary.
(require 'consult-notes)
(defvar consult-denote--history nil)
(defconst consult-denote--source
(list :name "Denote notes"
:narrow ?d
:category 'files
:annotate #'consult-denote--annotate
:items (lambda ()
(let* ((max-width 0)
(cands (mapcar (lambda (f)
(let* ((title (denote-retrieve-filename-title f))
(folder (file-relative-name (file-name-directory f) denote-directory))
(folder+title (concat (if (equal "./" folder)
""
(concat (propertize folder 'face 'shadow) " - "))
title))
(keywords (denote-extract-keywords-from-path f)))
(let ((current-width (string-width folder+title)))
(when (> current-width max-width)
(setq max-width current-width)))
(propertize folder+title 'denote-path f 'denote-keywords keywords)))
(denote-directory-files))))
(mapcar (lambda (c)
(let ((keywords (get-text-property 0 'denote-keywords c)))
(concat c
;; align keywords
(propertize " " 'display `(space :align-to (+ left ,(+ 2 max-width))))
(format "%-30s"
(if keywords
(concat "#: "
(propertize (mapconcat 'identity keywords " ") 'face 'org-tag))
"")))))
cands)))
:action (lambda (f)
(find-file (get-text-property 0 'denote-path f)))
;; create new if not exist
:new (lambda (cand)
(let* ((f (expand-file-name cand denote-directory))
(f-dir (file-name-directory f))
(f-name-base (file-name-base f))
(file-type (consult-denote--extension-file-type f))
keywords date template)
(dolist (prompt denote-prompts)
(pcase prompt
('keywords (setq keywords (denote-keywords-prompt)))
('file-type (setq file-type (denote-file-type-prompt)))
('date (setq date (denote-date-prompt)))
('template (setq template (denote-template-prompt)))))
(denote (string-trim f-name-base) keywords file-type f-dir date template)))))
(defun consult-denote--extension-file-type (f)
"Return denote file-type of F."
(pcase (file-name-extension f)
("org" "org")
("md" "markdown-toml")
("txt" "text")))
(defun consult-denote--annotate (cand)
"Annotate CAND in `consult-denote'."
(let* ((path (get-text-property 0 'denote-path cand))
(attrs (file-attributes path))
(ftime (consult-notes--time (file-attribute-modification-time attrs)))
(fsize (file-size-human-readable (file-attribute-size attrs))))
(put-text-property 0 (length fsize) 'face 'consult-notes-size fsize)
(put-text-property 0 (length ftime) 'face 'consult-notes-time ftime)
(format "%5s %8s"
fsize
ftime)))
;;;###autoload
(defun consult-denote ()
"Find or create denote notes with consult.
Find notes: filter by denote-subdirectory, notes title and keywords.
Create notes: when a note not found in completion or exit minibufer with raw input.
Three scenarios:
Input \"foo\", then create \"id-foo\", file type is determined by
`denote-file-type' or choose manually when `denote-prompts'
includes 'file-type. For example, if `denote-file-type' is
nil , then create \"id-foo.org\".
Input \"foo.txt\", create \"id-foo.txt\", check
`consult-denote--extension-file-type' for more information.
Input \"bar/foo.txt\", create \"id-foo.txt\" in denote-subdirectory named \"bar\"."
(interactive)
(consult--multi '(consult-denote--source)
:prompt "Denote: "
:history consult-denote--history))
(provide 'consult-denote)
;;; consult-denote.el ends here
|
When I get some time (hopefully soon) I'll provide a denote back-end like I do for org-roam. |
Closed by 7451e51 |
Many thanks for your package. I'm testing it with Denote notes, and noticed that the files listed are showing their filename rather than their title.
I was expecting to see titles, but I'm not sure whether that is a correct expectation on my end. The screenshots in the README show both (filenames and note titles) -- but perhaps that's specifically for Org-roam notes?
The text was updated successfully, but these errors were encountered: