Skip to content

Commit

Permalink
ADD abbreviation to table
Browse files Browse the repository at this point in the history
  • Loading branch information
ndwarshuis committed Sep 25, 2022
1 parent ea00013 commit 140a9f7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
14 changes: 14 additions & 0 deletions org-sql.el
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,8 @@ to store them. This is in addition to any properties specifified by
:constraints (notnull))
(:link_text :desc "text of this link that isn't part of the path"
:type text)
(:link_abbrev :desc "abbreviation for this link"
:type text)
(:link_type :desc "type of this link (eg http, mu4e, file, etc)"
:properties (:type)
:type text
Expand Down Expand Up @@ -1380,6 +1382,17 @@ list of headline nodes."
(let ((children (if preamble (cons preamble headlines) headlines)))
`(org-data nil ,@children)))

(defun org-sql--link-get-abbrev (link)
"Return the abbreviation for LINK node.
This depends on the value of `org-link-abbrev-alist' and will do
nothing if this variable is nil."
(when org-link-abbrev-alist
(let ((fullpath (->> (org-ml-to-trimmed-string link)
(s-match "\\[\\[\\([^][]+\\)\\]\\(\\[[^][]+\\]\\)?\\]")
(nth 1))))
(car (rassoc fullpath org-link-abbrev-alist)))))

;; org-element tree -> logbook entry (see `org-sql--to-entry')

;; Define these myself because the RE's in org-mode itself have lots of capture
Expand Down Expand Up @@ -1724,6 +1737,7 @@ CONTENTS is a list corresponding to that returned by
:link_id (org-sql--acc-get :link-id acc)
:headline_id (org-sql--acc-get :headline-id acc)
:link_path (org-ml-get-property :path link)
:link_abbrev (org-sql--link-get-abbrev link)
:link_text (-some->> (org-ml-get-children link)
(-map #'org-ml-to-string)
(s-join ""))
Expand Down
4 changes: 2 additions & 2 deletions test/org-sql-test-stateful.el
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,8 @@
'(1 4 integerp integerp "this is a clock note")))
(it "check links table"
(expect-db-has-table-contents 'links
'(1 4 "/dev/null" "NULL" "file")
'(2 5 "//downloadmoreram.gov" nil "https"))))
'(1 4 "/dev/null" "NULL" nil "file")
'(2 5 "//downloadmoreram.gov" nil nil "https"))))


;; (expect-db-has-table-contents 'file_metadata
Expand Down
16 changes: 11 additions & 5 deletions test/org-sql-test-stateless.el
Original file line number Diff line number Diff line change
Expand Up @@ -718,12 +718,12 @@ list then join the cdr of IN with newlines."
"file:///the/glass/prison")
"multiple (included)"
nil
`((links (2 1 "/the/glass/prison" nil "file")
(1 1 "//example.org" nil "https")))
`((links (2 1 "/the/glass/prison" nil nil "file")
(1 1 "//example.org" nil nil "https")))

"multiple (exclude some)"
((org-sql-excluded-link-types '("file")))
`((links (1 1 "//example.org" nil "https")))
`((links (1 1 "//example.org" nil nil "https")))

"multiple (exclude all)"
((org-sql-excluded-link-types 'all))
Expand All @@ -733,12 +733,18 @@ list then join the cdr of IN with newlines."
(expect-sql-tbls (links) (list "* parent"
"** child"
"https://example.com")
`((links (1 2 "//example.com" nil "https")))))
`((links (1 2 "//example.com" nil nil "https")))))

(it "with description"
(expect-sql-tbls (links) (list "* parent"
"[[https://example.org][relevant]]")
`((links (1 1 "//example.org" "relevant" "https"))))))
`((links (1 1 "//example.org" "relevant" nil "https")))))

(it "with abbrev"
(let ((org-link-abbrev-alist '(("love" . "https://ra.ge"))))
(expect-sql-tbls (links) (list "* parent"
"[[love][wins]]")
`((links (1 1 "//ra.ge" "wins" "love" "https")))))))

(describe "properties"
(it "single"
Expand Down

0 comments on commit 140a9f7

Please sign in to comment.