Long time, no commits

This commit is contained in:
Willem van den Ende
2021-03-21 21:03:22 +00:00
parent 3e1e5ec7e1
commit 84baf90147
7 changed files with 245 additions and 4 deletions
+87
View File
@@ -59,3 +59,90 @@
;;
;; You can also try 'gd' (or 'C-c c d') to jump to their definition and see how
;; they are implemented.
;;
(setq evil-move-cursor-back nil)
;;
;; from https://github.com/org-roam/org-roam-server/issues/115
;; but modified the open to browse-url-button-open-url
(use-package org-roam-server
:config
(setq org-roam-server-host "127.0.0.1"
org-roam-server-port 8427
org-roam-server-authenticate nil
org-roam-server-export-inline-images t
org-roam-server-serve-files nil
org-roam-server-served-file-extensions '("pdf" "mp4" "ogv")
org-roam-server-network-poll t
org-roam-server-network-arrows nil
org-roam-server-network-label-truncate t
org-roam-server-network-label-truncate-length 60
org-roam-server-network-label-wrap-length 20))
(defun org-roam-server-open ()
"Ensure the server is active, then open the roam graph."
(interactive)
(org-roam-server-mode 1)
(browse-url-button-open-url (format "http://localhost:%d" org-roam-server-port)))
(after! org-roam
(org-roam-server-mode))
;; two functions from:
;; https://zzamboni.org/post/my-emacs-configuration-with-commentary/#reformatting-an-org-buffer
(defun zz/org-reformat-buffer ()
(interactive)
(when (y-or-n-p "Really format current buffer? ")
(let ((document (org-element-interpret-data (org-element-parse-buffer))))
(erase-buffer)
(insert document)
(goto-char (point-min)))))
(defun afs/org-remove-link ()
"Replace an org link by its description or if empty its address"
(interactive)
(if (org-in-regexp org-link-bracket-re 1)
(let ((remove (list (match-beginning 0) (match-end 0)))
(description (if (match-end 3)
(org-match-string-no-properties 3)
(org-match-string-no-properties 1))))
(apply 'delete-region remove)
(insert description))))
(defun qwan/org-replace-link-by-link-description ()
"Remove the link part of an org-mode link at point and keep
only the description"
(interactive)
(let ((elem (org-element-context)))
(if (eq (car elem) 'link)
(let* ((content-begin (org-element-property :contents-begin elem))
(content-end (org-element-property :contents-end elem))
(link-begin (org-element-property :begin elem))
(link-end (org-element-property :end elem)))
(if (and content-begin content-end)
(let ((content (buffer-substring-no-properties content-begin content-end)))
(delete-region link-begin (- link-end 1))
(insert content)))))))
(bind-key "C-c r" 'qwan/org-replace-link-by-link-description)
(defun org-roam-replace-file-link-by-website-or-description ()
"If a linked org-roam file has a website as key, use that as the link target instead of the filename. Otherwise, remove the link, and leave just
the description. This may destroy existing links, or change their targets so use in a copy of buffers you hold dearly as notes"
(interactive)
(let ((elem (org-element-context)))
(if (eq (car elem) 'link)
(let* ((content-begin (org-element-property :contents-begin elem))
(content-end (org-element-property :contents-end elem))
(target-type (org-element-property :type elem))
(target-path (org-element-property :path elem))
(link-begin (org-element-property :begin elem))
(link-end (org-element-property :end elem)))
(if (and content-begin content-end (string-equal target-type "file") target-path link-begin link-end)
(let ((new-link (org-roam-description-file-to-org-url
(buffer-substring-no-properties content-begin content-end)
target-path)))
(delete-region link-begin (- link-end 1))
(insert new-link)
))))))