From 6fd355d978c0f6146ed101effa12661453ecea04 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Tue, 1 Jun 2021 22:30:05 -0500 Subject: Add ORG functionality --- init.el | 8 +++++++- lisp/acdw-org.el | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/init.el b/init.el index b970012..fc5927e 100644 --- a/init.el +++ b/init.el @@ -1047,7 +1047,13 @@ if ripgrep is installed, otherwise `consult-grep'." org-directory "~/org") (:bind "RET" acdw-org/return-dwim - "" acdw-org/org-table-copy-down) + "" acdw-org/org-table-copy-down + "M-SPC M-SPC" insert-zero-width-space + "C-c C-l" org-insert-link-dwim) + + (with-eval-after-load 'org-export + (add-to-list 'org-export-filter-final-output-functions + #'org-export-remove-zero-width-spaces)) (defun acdw/org-fix-lines-before-save () (add-hook 'before-save-hook #'acdw-org/fix-blank-lines-in-buffer 0 :local)) diff --git a/lisp/acdw-org.el b/lisp/acdw-org.el index 7e68712..a9c0a8c 100644 --- a/lisp/acdw-org.el +++ b/lisp/acdw-org.el @@ -301,5 +301,57 @@ the deletion might narrow the column." (message "%d words in buffer" (acdw-org/count-words (point-min) (point-max)))))) + +;;; Zero-width spaces +;; https://blog.tecosaur.com/tmio/2021-05-31-async.html#easy-zero-width + +(defun insert-zero-width-space () + "Insert a zero-width space." + (interactive) + (insert "\u200b")) +(defun org-export-remove-zero-width-spaces (text _backend _info) + "Remove zero-width spaces from TEXT." + (unless (org-export-derived-backend-p 'org) + (replace-regexp-in-string "\u200b" "" text))) + + +;;; Insert links .. DWIM +;; https://xenodium.com/emacs-dwim-do-what-i-mean/ + +(defun org-insert-link-dwim () + "Like `org-insert-link' but with personal dwim preferences." + (interactive) + (let* ((point-in-link (org-in-regexp org-link-any-re 1)) + (clipboard-url (when (string-match-p + (rx (sequence bos + (or "http" + "gemini" + "gopher"))) + (current-kill 0)) + (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-make-link-string clipboard-url region-content))) + ((and clipboard-url (not point-in-link)) + (insert (org-make-link-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))))) + + (provide 'acdw-org) +;; acdw-org.el ends here -- cgit 1.4.1-21-gabe81