From f1feb7b8db3b655a009d9b54c0402b86da7e7cbf Mon Sep 17 00:00:00 2001 From: Willem van den Ende Date: Thu, 12 Jan 2023 13:13:44 +0000 Subject: [PATCH] refactor rename plus old stuff --- README.org | 21 +++++++++++++++---- config.el | 60 +++++++++++++++++++++++++++++++++++++++++++++-------- custom.el | 7 ++++++- init.el | 2 +- packages.el | 1 + 5 files changed, 76 insertions(+), 15 deletions(-) diff --git a/README.org b/README.org index 601a925..56d934e 100644 --- a/README.org +++ b/README.org @@ -10,7 +10,8 @@ - [[#hacks][Hacks]] - [[#org-roam-server][Org-roam-server]] - [[#links-removal-for-blogposts-and-other-exports][Links removal for blogposts and other exports]] - - [[#diff-hl-errors-in-magit][diff-hl errors in magit]] + - [[#diff-hl-errors-in-magit-workaround][Diff-hl errors in magit workaround]] + - [[#shorter-previews-for-backlinks-in-roam-buffer][Shorter previews for backlinks in roam-buffer]] - [[#prerequisites][Prerequisites]] - [[#features][Features]] - [[#pdf-export-from-latex-in-tufte-style][PDF export from latex, in tufte style]] @@ -45,12 +46,10 @@ The README was generated by doom emacs when creating a README.org file with it. ** Hacks *** Org-roam-server Some in file:config.el. Port settings for ~org-roam-server~ are not standard, so need a function. - *** Links removal for blogposts and other exports Also some functions for replacing org-roam links with links to their website, useful for exports such as blog posts, where links to internal pages are not visible. +*** Diff-hl errors in magit workaround - -*** diff-hl errors in magit **** Why I think diff-hl shows changes at the side of a buffer, which I quite like. It seems configured with Doom emacs. For inside magit we now have `magit-delta` so it is not needed there. But for now, use one of the workarounds. @@ -63,6 +62,20 @@ file:config.el #+end_src adding diff-hl to the after! list did not seem to work. it is all a bit mysterious. +*** Shorter previews for backlinks in roam-buffer + +From https://github.com/org-roam/org-roam/issues/1934 by Jethro Kuan +#+begin_quote +(defun my/preview-fetcher () + (let* ((elem (org-element-context)) + (parent (org-element-property :parent elem))) + ;; TODO: alt handling for non-paragraph elements + (string-trim-right (buffer-substring-no-properties + (org-element-property :begin parent) + (org-element-property :end parent))))) + +(setq org-roam-preview-function #'my/preview-fetcher) +#+end_quote * Prerequisites Doom Emacs installation diff --git a/config.el b/config.el index 8e6531d..629bd39 100644 --- a/config.el +++ b/config.el @@ -291,16 +291,19 @@ the description. This may destroy existing links, or change their targets so use (delete-region link-begin (- link-end 1)) (insert new-link) )))))) +(defun qwan/string-as-markdown-image-link (a-string) + (concat "![alt-text goes here](" a-string ")")) -(defun qwan/image-mode-copy-filename-as-markdown-link () - "Push the currently visited file name onto the kill ring." +(defun qwan/image-mode-copy-filename-as-markdown-image-link () + "Push a markdown link to the currently visited image onto the kill ring." (interactive) (unless buffer-file-name (error "The current buffer doesn't visit an image file")) - (let ((path-from-attachements (qwan/relative-path-to-attachments buffer-file-name))) + (let ((markdown-link (qwan/string-as-markdown-image-link + (qwan/relative-path-to-attachments buffer-file-name)))) - (kill-new path-from-attachements) - (message "Copied %s" path-from-attachements))) + (kill-new markdown-link) + (message "Copied %s" markdown-link))) @@ -314,8 +317,47 @@ the description. This may destroy existing links, or change their targets so use (ert-deftest relative-path-to-attachments-does-not-remove-prefix-when-no-attachments () (should (equal (qwan/attachments-remove-prefix-path "prefix/somethingelse") "prefix/somethingelse"))) -(ert "relative.*") +(ert-deftest markdown-link-tokens-should-surround-string () + (should (equal (qwan/string-as-markdown-image-link "prefix/image.png") + "![alt-text goes here](prefix/image.png)"))) -(let ((full-path-in - "/Users/willem/MyDocuments/qwan/sites/qwaneu.github.io/attachments/blogposts/2023/time-for-improvement-game-changer.svg" - ))) + +(ert "markdown.*") +(defun qwan/echo (new-name) + (interactive "SRename function to:") + (message "Will rename to %s" new-name) + ) + +;; from @tbf@functional.cafe +(defun movd (from to) + (fset to (symbol-function from)) + (fset from nil) + to) + +;; from @tbf@functional.cafe +(defmacro frename (from to) + `(movd ',from ',to)) + + +(defun qrefactor/rename + (new-name) + "Rename function at point. You must modify references yourself" + (interactive "MRename function to:") + (let + ((bounds + (bounds-of-thing-at-point 'symbol))) + (if bounds + (progn + (let* + ((begin + (car bounds)) + (end + (cdr bounds)) + (old-name + (buffer-substring-no-properties begin end))) + (message "Will rename to %s" new-name) + (frename old-name new-name) + (delete-region begin end) + (insert (s-dashed-words new-name)) + (message "Renamed %s to %s." old-name new-name))) + (message "No symbol under cursor.")))) diff --git a/custom.el b/custom.el index 0f0ab04..a81f60a 100644 --- a/custom.el +++ b/custom.el @@ -49,7 +49,12 @@ (cons 320 "#6f4e52") (cons 340 "#5B6268") (cons 360 "#5B6268"))) - '(vc-annotate-very-old-color nil)) + '(vc-annotate-very-old-color nil) + '(warning-suppress-types + '((org-element-cache) + (org-element-cache) + (org-element-cache) + (defvaralias)))) (custom-set-faces ;; custom-set-faces was added by Custom. ;; If you edit it by hand, you could mess it up, so be careful. diff --git a/init.el b/init.el index f6f908a..8f8a070 100644 --- a/init.el +++ b/init.el @@ -149,7 +149,7 @@ ;;nim ; python + lisp at the speed of c ;;nix ; I hereby declare "nix geht mehr!" ;;ocaml ; an objective camel - (org +pretty +roam2 +download-dnd) ; organize your plain life in plain text + (org +gnuplot +pretty +roam2 +download-dnd) ; organize your plain life in plain text ;;php ; perl's insecure younger brother plantuml ; diagrams for confusing people more purescript ; javascript, but functional diff --git a/packages.el b/packages.el index ca6c34c..1b4593f 100644 --- a/packages.el +++ b/packages.el @@ -10,6 +10,7 @@ ;(package! some-package) (package! magit-delta) (package! diff-hl) +(package! puni) ;; To install a package directly from a remote git repo, you must specify a ;; `:recipe'. You'll find documentation on what `:recipe' accepts here: ;; https://github.com/raxod502/straight.el#the-recipe-format