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

[question / feature request] using deft in a custom link? #52

Open
mediapathic opened this issue Apr 1, 2018 · 5 comments
Open

[question / feature request] using deft in a custom link? #52

mediapathic opened this issue Apr 1, 2018 · 5 comments

Comments

@mediapathic
Copy link

I am trying to implement a zettlekasten-like system in emacs using deft and org-mode. I'm currently making a custom link type that allows for seeing all items that match that id rather than linking to a file directly. Put another way: I want a custom link type that has the effect of executing deft with the contents of the link being the search string. I feel like I essentially understand how to create a custom link type, but calling deft with an argument doesn't work. My code currently looks like this:

(org-add-link-type
               "id" 'zettel/deft-search-link)

(defun zettel/deft-search-link (uid)
; "run deft, hopefully with uid as a search term"
; "FIXME: 'deft' does not take an argument. Figure out how to do this, ask the author?"
(deft uid))

My question then, is, is there a function within deft that I could be calling that does take an argument and opens a deft buffer (preferably in other window)? If not, is it easy to modify deft to do so? Alternately, am I just going about this in a ridiculous way and there's already an easier solution?

Thanks!

@EFLS
Copy link

EFLS commented Apr 2, 2018

I have also been thinking about using deft to manage a Zettelkasten-like system. No clue as to how something like this could be implemented though.

Currently, I am creating an org-id for each header to link files together, but a true implementation does indeed require searching for unique IDs of files, rather than headers.

@mediapathic
Copy link
Author

@EFLS I'm doing something very similar. I'm creating my ids using the 201804021450 timestamp convention, which I have bound to an abbrev. Currently I'm copy-pasting ids into a deft field. I'd like a more efficient way of doing a bunch of things here. 😄

(Is there a place we could compare notes where we're not off-topic, if you've gotten farther on this problem than I have?)

@EFLS
Copy link

EFLS commented Apr 5, 2018

A function that would allow easier searching with deft would indeed be useful.

You also might want to check out the org-brain package, which looks promising (and which works nicely parallel to deft): https://github.com/Kungsgeten/org-brain

@saf-dmitry
Copy link

saf-dmitry commented Jul 2, 2018

Apparently, we can use deft-filter function for this (see also #54).

The first function provides an API for global search in Deft notes (can be added to Deft mode):

(defun deft-search-global (str)
  "Call Deft search on filter string STR."
  ;; Sanitize the filter string
  (setq str (replace-regexp-in-string "[[:space:]]+" " " str))
  ;; Call Deft search on the filter string
  (let ((deft-incremental-search t)) (deft) (deft-filter str t))
  ;; If there is a single match, open the file
  (when (= (length deft-current-files) 1)
    (deft-open-file (car deft-current-files))))

The second function calls deft-global-searchon wiki link, hashtag, or word at point and can be modified to understand your specific syntax:

(defun deft-search ()
  "Call Deft search on thing at point.
Thing can be a double-bracketed link, a hashtag, or a word."
  (interactive)
  (require 'thingatpt)
  (let* ((link-re "\\[\\[\\([^]]+\\)\\]\\]")
         (htag-re "\\([#@]\\(?:[[:alnum:]_-]+:\\)?[[:alnum:]_-]+\\)")
         (string (cond
                  ((thing-at-point-looking-at link-re)
                   (match-string-no-properties 1))
                  ((thing-at-point-looking-at htag-re)
                   (match-string-no-properties 1))
                  (t (thing-at-point 'word t)))))
    (if string
        (deft-search-global string)
      (user-error "No search term at point"))))

@EFLS
Copy link

EFLS commented Jul 9, 2018

Many thanks @saf-dmitry.

I'm fairly new to elisp, but I've taken your suggestion and made my own set of functions, attempting to expand deft into a Zettelkasten system.

Check it out here if you're interested: https://github.com/EFLS/zetteldeft

@mediapathic, check it out if you're still looking for a Zettelkasten setup based on deft.

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

3 participants