From 9360a54e6208c87911530ea8005b626680fa2e88 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Fri, 7 Jan 2022 17:30:46 -0600 Subject: Gah, so many changes --- lisp/+org.el | 74 +++++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 53 insertions(+), 21 deletions(-) (limited to 'lisp/+org.el') diff --git a/lisp/+org.el b/lisp/+org.el index fc1caea..090af5a 100644 --- a/lisp/+org.el +++ b/lisp/+org.el @@ -253,9 +253,9 @@ instead of the true count." ;;; org-insert-link-dwim - https://xenodium.com/emacs-dwim-do-what-i-mean/ -(defun +org-insert-link-dwim () +(defun +org-insert-link-dwim (&optional interactivep) "Like `org-insert-link' but with personal dwim preferences." - (interactive) + (interactive '(t)) (let* ((point-in-link (org-in-regexp org-link-any-re 1)) (clipboard-url (when (string-match-p (rx (sequence bos @@ -266,25 +266,30 @@ instead of the true count." (current-kill 0))) (region-content (when (region-active-p) (buffer-substring-no-properties (region-beginning) - (region-end))))) - (cond ((and region-content clipboard-url (not point-in-link)) - (delete-region (region-beginning) (region-end)) - (insert (org-link-make-string clipboard-url region-content))) - ((and clipboard-url (not point-in-link)) - (insert (org-link-make-string - clipboard-url - (read-string "title: " - (with-current-buffer - (url-retrieve-synchronously - clipboard-url) - (dom-text - (car - (dom-by-tag (libxml-parse-html-region - (point-min) - (point-max)) - 'title)))))))) - (t - (call-interactively 'org-insert-link))))) + (region-end)))) + (org-link (when clipboard-url + (org-link-make-string + clipboard-url + (or region-content + (read-string "title: " + (with-current-buffer + (url-retrieve-synchronously + clipboard-url) + (dom-text + (car + (dom-by-tag (libxml-parse-html-region + (point-min) + (point-max)) + 'title)))))))))) + (if interactivep + (cond ((and region-content clipboard-url (not point-in-link)) + (delete-region (region-beginning) (region-end)) + (insert org-link)) + ((and clipboard-url (not point-in-link)) + (insert org-link)) + (t + (call-interactively 'org-insert-link))) + org-link))) ;;; Navigate headings with widening @@ -409,5 +414,32 @@ the deletion might narrow the column." (dotimes (_ fill-column) (insert "-"))) +;; Follow links, DWIM style + +(defun +org-open-at-point-dwim (&optional arg) + "Open thing at point, or if there isn't something, list things." + (interactive "P") + (save-excursion + (let* ((this-char-type (org-element-type (org-element-context))) + (prev-char-type (save-excursion + (backward-char) + (org-element-type (org-element-context)))) + (types '(citation citation-reference clock comment comment-block + footnote-definition footnote-reference headline + inline-src-block inlinetask keyword link + node-property planning src-block timestamp)) + (type this-char-type)) + (when (and (memq this-char-type types) (memq prev-char-type types)) + (backward-char) + (setq type prev-char-type)) ; what the fuckckckckck + (if (memq type types) + (progn (org-open-at-point arg)) + (while (not + (progn + (org-back-to-heading) + (car (org-offer-links-in-entry (current-buffer) (point) 1)))) + (org-up-heading-all 1)) + (org-open-at-point arg))))) + (provide '+org) ;;; +org.el ends here -- cgit 1.4.1-21-gabe81