ndwarshuis / org-sql

SQL backend for Emacs Org-Mode
GNU General Public License v3.0
97 stars 9 forks source link

Add abbreviation column to the table links #18

Open jarofromel opened 1 year ago

jarofromel commented 1 year ago

Some of links are defined with the abbreviation. The link abbreviation is not present in the table links only the original link type. For example

* link defined as abbreviation
- [[wikipedia:Statistical_distance]]

which is defined in the org-link-abbrev-list as:

            '("wikipedia"   . "https://en.wikipedia.org/wiki/%s")

is stored without the abbreviation: image

Not important. Just nice to have there a new column with the abbreviation as well.

Use case: I use the abbreviation as a kind of metadata, e.g. for the same page I use more abbreviation (wiki_note, wiki_ref, wiki_quote).

17 describes the way I get here.

ndwarshuis commented 1 year ago

I haven't looked into this fully yet but at least limited abbreviation (that is, without any substitutions using %h and %s) shouldn't be hard to add to a new column

ndwarshuis commented 1 year ago

I added partial support in 140a9f78435def29235139cd4fcc94fe4db06ec1. Please test and see if this works for you.

Regarding why this is only 'partial', org-element will expand link abbreviations by itself, which means org-sql only sees the expanded link and thus must do a reverse lookup in org-link-abbrev-alist. This isn't a problem if the final expanded link has an exact match, but anything with %s or %h won't work because the tag information that subs into these replacement keys is effectively destroyed by the time the link reaches org-sql. Of course there's hacky ways around this, but nothing I can come up with is very clean or performant.

jarofromel commented 1 year ago

I tested with the following results: 1) new column link_abbrev is visible in the links table 2) only NULL value is there, i.e. no abbreviations were found in my org mode notes

Regarding the expansion I think the current solution is OK. The link abbreviation in the table tells me which logic was applied during the expansion (because the expansion logic is defined in the org-link-abbrev-list), thus I can reconstruct it by custom SQL (reversing the expanded link_path)