Skip to content
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

deft--org-complete is generating broken links #117

Open
gabrielhidasy opened this issue Feb 24, 2024 · 1 comment
Open

deft--org-complete is generating broken links #117

gabrielhidasy opened this issue Feb 24, 2024 · 1 comment

Comments

@gabrielhidasy
Copy link

The current implementation for deft--org-complete selects 'file' from (deft-find-all-files-no-prefix) and concats "deft:" and with (substring file 1)`, but file is already the file name, so it is removing the first character and making an invalid link.

(defun deft--org-complete ()
  (let ((file (completing-read "file" (deft-find-all-files-no-prefix))))
    (concat "deft:" (substring file 1))))

This can be fixed by removing (substring file 1), and for a bit more clarity replacing "file" with "file: " looks a bit better

(defun deft--org-complete ()
  (let ((file (completing-read "file: " (deft-find-all-files-no-prefix))))
    (concat "deft:" file)))
@gabrielhidasy
Copy link
Author

Btw, my deft--org-complete is a bit different, I wanted to display note titles instead of filenames, but that's more of a preference

(defun deft--file-title-and-name (f)
  (let ((title (deft-file-title f))
	(fn (replace-regexp-in-string
	     (expand-file-name deft-directory) "" f)))
    (list title fn)))

(defun deft--org-complete ()
  (let ((file (car
	       (let ((choices
		      (mapcar 'deft--file-title-and-name
			      (deft-find-all-files))))
  (alist-get
   (completing-read "file: " choices)
   choices nil nil 'equal)))))
    (concat "deft:" file)))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant