diff options
Diffstat (limited to 'lisp/+org.el')
-rw-r--r-- | lisp/+org.el | 74 |
1 files changed, 53 insertions, 21 deletions
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." | |||
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-link-dwim () | 256 | (defun +org-insert-link-dwim (&optional interactivep) |
257 | "Like `org-insert-link' but with personal dwim preferences." | 257 | "Like `org-insert-link' but with personal dwim preferences." |
258 | (interactive) | 258 | (interactive '(t)) |
259 | (let* ((point-in-link (org-in-regexp org-link-any-re 1)) | 259 | (let* ((point-in-link (org-in-regexp org-link-any-re 1)) |
260 | (clipboard-url (when (string-match-p | 260 | (clipboard-url (when (string-match-p |
261 | (rx (sequence bos | 261 | (rx (sequence bos |
@@ -266,25 +266,30 @@ instead of the true count." | |||
266 | (current-kill 0))) | 266 | (current-kill 0))) |
267 | (region-content (when (region-active-p) | 267 | (region-content (when (region-active-p) |
268 | (buffer-substring-no-properties (region-beginning) | 268 | (buffer-substring-no-properties (region-beginning) |
269 | (region-end))))) | 269 | (region-end)))) |
270 | (cond ((and region-content clipboard-url (not point-in-link)) | 270 | (org-link (when clipboard-url |
271 | (delete-region (region-beginning) (region-end)) | 271 | (org-link-make-string |
272 | (insert (org-link-make-string clipboard-url region-content))) | 272 | clipboard-url |
273 | ((and clipboard-url (not point-in-link)) | 273 | (or region-content |
274 | (insert (org-link-make-string | 274 | (read-string "title: " |
275 | clipboard-url | 275 | (with-current-buffer |
276 | (read-string "title: " | 276 | (url-retrieve-synchronously |
277 | (with-current-buffer | 277 | clipboard-url) |
278 | (url-retrieve-synchronously | 278 | (dom-text |
279 | clipboard-url) | 279 | (car |
280 | (dom-text | 280 | (dom-by-tag (libxml-parse-html-region |
281 | (car | 281 | (point-min) |
282 | (dom-by-tag (libxml-parse-html-region | 282 | (point-max)) |
283 | (point-min) | 283 | 'title)))))))))) |
284 | (point-max)) | 284 | (if interactivep |
285 | 'title)))))))) | 285 | (cond ((and region-content clipboard-url (not point-in-link)) |
286 | (t | 286 | (delete-region (region-beginning) (region-end)) |
287 | (call-interactively 'org-insert-link))))) | 287 | (insert org-link)) |
288 | ((and clipboard-url (not point-in-link)) | ||
289 | (insert org-link)) | ||
290 | (t | ||
291 | (call-interactively 'org-insert-link))) | ||
292 | org-link))) | ||
288 | 293 | ||
289 | ;;; Navigate headings with widening | 294 | ;;; Navigate headings with widening |
290 | 295 | ||
@@ -409,5 +414,32 @@ the deletion might narrow the column." | |||
409 | (dotimes (_ fill-column) | 414 | (dotimes (_ fill-column) |
410 | (insert "-"))) | 415 | (insert "-"))) |
411 | 416 | ||
417 | ;; Follow links, DWIM style | ||
418 | |||
419 | (defun +org-open-at-point-dwim (&optional arg) | ||
420 | "Open thing at point, or if there isn't something, list things." | ||
421 | (interactive "P") | ||
422 | (save-excursion | ||
423 | (let* ((this-char-type (org-element-type (org-element-context))) | ||
424 | (prev-char-type (save-excursion | ||
425 | (backward-char) | ||
426 | (org-element-type (org-element-context)))) | ||
427 | (types '(citation citation-reference clock comment comment-block | ||
428 | footnote-definition footnote-reference headline | ||
429 | inline-src-block inlinetask keyword link | ||
430 | node-property planning src-block timestamp)) | ||
431 | (type this-char-type)) | ||
432 | (when (and (memq this-char-type types) (memq prev-char-type types)) | ||
433 | (backward-char) | ||
434 | (setq type prev-char-type)) ; what the fuckckckckck | ||
435 | (if (memq type types) | ||
436 | (progn (org-open-at-point arg)) | ||
437 | (while (not | ||
438 | (progn | ||
439 | (org-back-to-heading) | ||
440 | (car (org-offer-links-in-entry (current-buffer) (point) 1)))) | ||
441 | (org-up-heading-all 1)) | ||
442 | (org-open-at-point arg))))) | ||
443 | |||
412 | (provide '+org) | 444 | (provide '+org) |
413 | ;;; +org.el ends here | 445 | ;;; +org.el ends here |