-
-
Notifications
You must be signed in to change notification settings - Fork 55
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
Support doing buttonization, and inserting links, in unrecognized file types (e.g. source code?) #364
Comments
I just adviced denote's function to test whether a file type is supported to always return true, and links between denote notes and code files worked beautifully, as did buttonization. |
One way to handle this is to always format links using the Org syntax. Then use |
That's a very good point, that would work to open a note link, but it wouldn't allow inserting the note link, despite all the information necessary to do so being at hand, and it also wouldn't highlight any available links. The solution I went with was this: (advice-add 'denote-file-has-supported-extension-p :filter-return (lambda (x) t)) And then relying on I'm not sure if this has any unforseen drawbacks, but as far as I can tell it doesn't — denote just treats the file like an org mode file. |
Thanks to Alexis Purslane for suggesting this idea in issue 364: <#364>.
I just added this to the manual, which is probably safer: (defun my-denote-link-global (file file-type description &optional id-only)
"Like the `denote-link', but works in any buffer.
The FILE, FILE-TYPE, DESCRIPTION, and ID-ONLY have the same meaning as
in `denote-link'."
(interactive
(let* ((file (denote-file-prompt nil "Link to FILE"))
(file-type (denote-filetype-heuristics buffer-file-name))
(description (when (file-exists-p file)
(denote--link-get-description file))))
(list file file-type description current-prefix-arg)))
(unless (file-exists-p file)
(user-error "The linked file does not exists"))
(let ((beg (point)))
(denote--delete-active-region-content)
(insert (denote-format-link file description file-type id-only))
(unless (derived-mode-p 'org-mode)
(make-button beg (point) 'type 'denote-link-button)))) I am open to having something like this in denote.el though it is just that nobody asked for it before. In such cases, we keep the code in the manual and think what to do about it once we have more feedback. Note that if you are tracking denote.git, this depends on commit |
Thank you so much! I'll try it out |
From: Alexis Purslane ***@***.***>
Date: Mon, 20 May 2024 03:38:13 -0700
Thank you so much! I'll try it out
You are welcome!
…--
Protesilaos Stavrou
https://protesilaos.com
|
FYI, I put this in my config and gave it a spin and it seems to work great! I haven't used it in anger yet, but I don't see why it would stop working. |
From: Alexis Purslane ***@***.***>
Date: Mon, 20 May 2024 18:13:45 -0700
> If you do try it, please let me know if it works for you.
FYI, I put this in my config and gave it a spin and it seems to work
great! I haven't used it in anger yet, but I don't see why it would
stop working.
Sounds good! I say we close this issue then and if a problem arises then
we reopen it.
…--
Protesilaos Stavrou
https://protesilaos.com
|
Oh, I did find an issue with your more surgical code (as opposed to my sledgehammer approach): with the original file-type-recognized function intact, denote-link-buttonize-buffer now only works on file types it considers "safe", so buttonization only works in e.g. code comments the first time you insert it, and not subsequently. I don't know how I missed that the first time around. I guess I don't restart emacs that often. |
When I saw that Denote supported buttonization in non-org modes like Markdown and plain text, it occurred to me that this could be used to link to Denote notes from basically any file, including the comments of source code, which could be extremely useful.
Additionally, there's no reason you couldn't insert a Denote link in any file type, even if it isn't recognized, right? There would just need to be a variable set to tell it how to format that link by default, since it wouldn't be able to tell what markup to use based on the filetype. Maybe the
denote-file-type
variable could do double duty for that?Or, hell, you could do in unrecognized text files what you already do in plain text files and just default to org format!
If you're interested I'd be willing to attempt to make a PR to do this.
The text was updated successfully, but these errors were encountered: