licht1stein / obsidian.el

Obsidian Notes for Emacs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Allow for custom note titles on obsidian-capture

milespossing opened this issue · comments

Obsidian.nvim has this feature where you're able to change the note name (specifically the file name) when creating:

    -- Optional, customize how names/IDs for new notes are created.
    note_id_func = function(title)
      -- Create note IDs in a Zettelkasten format with a timestamp and a suffix.
      -- In this case a note with the title 'My new note' will given an ID that looks
      -- like '1657296016-my-new-note', and therefore the file name '1657296016-my-new-note.md'
      local suffix = ""
      if title ~= nil then
        -- If title is given, transform it into valid file name.
        suffix = title:gsub(" ", "-"):gsub("[^A-Za-z0-9-]", ""):lower()
      else
        -- If title is nil, just add 4 random uppercase letters to the suffix.
        for _ = 1, 4 do
          suffix = suffix .. string.char(math.random(65, 90))
        end
      end
      return tostring(os.time()) .. "-" .. suffix
    end,

(here a note called Hello World would be converted to 202307061244-hello-world.md)

I know that slipbox isn't the most popular style of naming, but I've come to love it myself.

I was wondering if this would be a reasonable addition to your package. I don't have a lot of experience with lisp, but I'm willing to give this addition a shot if you think that it's worth doing (and possible/reasonably implemented in emacs).

Hi @milespossing, I think it's a good idea as long as it's optional and you can specify this as a setting. Thank you!

I'll start hacking (hopefully this weekend) and see what I come up with. I'll target some form of optional obsidian-format-title which can be configured, but defaults to identity

People normally want either a prefix or a suffix, if I understand correctly. So you can add obsidian-capture-title-prefix and obsidian-capture-title-suffix which default to nil, and can accept options that you want to implement, like 'timestamp, 'uuid etc.

How do they handle links when there's a prefix?

Normally what the nvim plugin does is it adds some front matter with an alias. Here is an example from mine:

---
id: "202306220817-emp-rules-processor-initial-architecture"
aliases:
  - "EMP Rules Processor Initial Architecture"
tags: []
---

# EMP Rules Processor Initial Architecture

In this case the note (or text over which I generated a link) was EMP Rules Processor Initial Architecture. So if I were to create a new link [[EMP Rules Processor Initial Architecture]] this would work (and does work in your package as well).

Some of my notes use the note title or id including the timestamp, others just use the title of the note

As I think of it, this might be a bit larger than simply adding in a prefix... A change like this would require enforcing front matters automatically in any case we would have a prefix/suffix

Well, if you feel like getting into it you can start with something smaller :)

Let me see what I come up with, it would be nice to at very least add a new command which creates new notes with the defined prefix if any. Maybe after a tiny bit of hacking it'll be more clear to me how I can put some of this stuff together and perhaps get a few of the features that I love from the nvim plugin in here

Sounds like a good plan, let me know if you have any questions :)