summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--lisp/+org.el30
1 files changed, 19 insertions, 11 deletions
diff --git a/lisp/+org.el b/lisp/+org.el index 06e70e4..48b3d42 100644 --- a/lisp/+org.el +++ b/lisp/+org.el
@@ -253,6 +253,18 @@ instead of the true count."
253 253
254;;; org-insert-link-dwim - https://xenodium.com/emacs-dwim-do-what-i-mean/ 254;;; org-insert-link-dwim - https://xenodium.com/emacs-dwim-do-what-i-mean/
255 255
256(defun +org-insert--get-title-and-headings (url)
257 "Retrieve title and headings from URL.
258Return as a list."
259 (with-current-buffer (url-retrieve-synchronously url)
260 (let ((dom (libxml-parse-html-region (point-min) (point-max))))
261 (cl-remove-if
262 (lambda (i) (string= i ""))
263 (apply #'append (mapcar (lambda (tag)
264 (mapcar #'dom-text
265 (dom-by-tag dom tag)))
266 '(title h1 h2 h3 h4 h5 h6)))))))
267
256(defun +org-insert-link-dwim (&optional interactivep) 268(defun +org-insert-link-dwim (&optional interactivep)
257 "Like `org-insert-link' but with personal dwim preferences." 269 "Like `org-insert-link' but with personal dwim preferences."
258 (interactive '(t)) 270 (interactive '(t))
@@ -267,20 +279,16 @@ instead of the true count."
267 (region-content (when (region-active-p) 279 (region-content (when (region-active-p)
268 (buffer-substring-no-properties (region-beginning) 280 (buffer-substring-no-properties (region-beginning)
269 (region-end)))) 281 (region-end))))
270 (org-link (when clipboard-url 282 (org-link (when (and clipboard-url (not point-in-link))
271 (org-link-make-string 283 (org-link-make-string
272 (string-trim clipboard-url) 284 (string-trim clipboard-url)
273 (or region-content 285 (or region-content
274 (read-string "title: " 286 (let ((clipboard-headings
275 (with-current-buffer 287 (+org-insert--get-title-and-headings clipboard-url)))
276 (url-retrieve-synchronously 288 (read-string "title (edit): "
277 clipboard-url) 289 (completing-read
278 (dom-text 290 "title: " clipboard-headings
279 (car 291 nil nil nil nil (car clipboard-headings)))))))))
280 (dom-by-tag (libxml-parse-html-region
281 (point-min)
282 (point-max))
283 'title))))))))))
284 (if interactivep 292 (if interactivep
285 (cond ((and region-content clipboard-url (not point-in-link)) 293 (cond ((and region-content clipboard-url (not point-in-link))
286 (delete-region (region-beginning) (region-end)) 294 (delete-region (region-beginning) (region-end))