2022-04-20 15:43:20 +00:00
|
|
|
;;; +org-drawer-list.el --- Add stuff to org drawers easy-style -*- lexical-binding: t; -*-
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
|
|
|
(require 'org)
|
|
|
|
(require '+org)
|
|
|
|
(require 'ol)
|
|
|
|
(require 'org-drawer-list)
|
|
|
|
|
|
|
|
(defcustom +org-drawer-list-resources-drawer "RESOURCES"
|
|
|
|
"Where to add links with `+org-drawer-list-add-resource'.")
|
|
|
|
|
|
|
|
(defun +org-drawer-list-add-resource (url &optional title)
|
|
|
|
"Add URL to the resource drawer of the current tree.
|
|
|
|
The resource drawer is given by the variable
|
|
|
|
`+org-drawer-list-resources-drawer'. If optional TITLE is given,
|
|
|
|
format the list item as an Org link."
|
|
|
|
(interactive
|
|
|
|
(let* ((clipboard-url (if (string-match-p (rx (sequence bos
|
|
|
|
(or "http"
|
|
|
|
"gemini"
|
|
|
|
"gopher"
|
|
|
|
"tel"
|
|
|
|
"mailto")))
|
|
|
|
(current-kill 0))
|
|
|
|
(string-trim (current-kill 0))
|
2022-05-24 01:12:53 +00:00
|
|
|
(read-string "Resource URL: ")))
|
2022-04-20 15:43:20 +00:00
|
|
|
(url-title (let ((clipboard-headings
|
|
|
|
(+org-insert--get-title-and-headings clipboard-url)))
|
|
|
|
(read-string "title (edit): "
|
|
|
|
(completing-read
|
|
|
|
"title: " clipboard-headings
|
|
|
|
nil nil nil nil (car clipboard-headings))))))
|
|
|
|
(list clipboard-url url-title)))
|
2022-05-24 01:12:53 +00:00
|
|
|
(let (current-visible-mode visible-mode)
|
|
|
|
;; XXX: This is not the "proper" way to fix the issue I was having --- I've
|
|
|
|
;; isolated the bug to somewhere in `org-insert-item', but this fix works
|
|
|
|
;; well enough™ for now.
|
|
|
|
(visible-mode +1)
|
|
|
|
(org-drawer-list-add +org-drawer-list-resources-drawer
|
|
|
|
(org-link-make-string url title))
|
|
|
|
(visible-mode (if current-visible-mode +1 -1))))
|
2022-04-20 15:43:20 +00:00
|
|
|
|
|
|
|
(provide '+org-drawer-list)
|
|
|
|
;;; +org-drawer-list.el ends here
|