format config.el with auto-fmt, fix python install
python not found, but python3 was on system. exec-shell-from-path fixes that
This commit is contained in:
@@ -6,8 +6,9 @@
|
|||||||
|
|
||||||
;; Some functionality uses this to identify you, e.g. GPG configuration, email
|
;; Some functionality uses this to identify you, e.g. GPG configuration, email
|
||||||
;; clients, file templates and snippets.
|
;; clients, file templates and snippets.
|
||||||
(setq user-full-name "Willem van den Ende"
|
(setq
|
||||||
user-mail-address "redacted@example.invalid")
|
user-full-name "Willem van den Ende"
|
||||||
|
user-mail-address "redacted@example.invalid")
|
||||||
;; Doom exposes five (optional) variables for controlling fonts in Doom. Here
|
;; Doom exposes five (optional) variables for controlling fonts in Doom. Here
|
||||||
;; are the three important ones:
|
;; are the three important ones:
|
||||||
;;
|
;;
|
||||||
@@ -25,12 +26,17 @@
|
|||||||
;; available. You can either set `doom-theme' or manually load a theme with the
|
;; available. You can either set `doom-theme' or manually load a theme with the
|
||||||
;; `load-theme' function. This is the default:
|
;; `load-theme' function. This is the default:
|
||||||
(setq doom-theme 'doom-solarized-light)
|
(setq doom-theme 'doom-solarized-light)
|
||||||
|
|
||||||
|
;; set python3 as python
|
||||||
|
(when (memq window-system '(mac ns x))
|
||||||
|
(exec-path-from-shell-initialize))
|
||||||
|
|
||||||
|
(exec-path-from-shell-copy-env "PYTHONPATH")
|
||||||
;; general editor customizations
|
;; general editor customizations
|
||||||
(setq display-line-numbers-type 'relative)
|
(setq display-line-numbers-type 'relative)
|
||||||
(setq linum-format "%3d \u2502'")
|
(setq linum-format "%3d \u2502'")
|
||||||
;; org-mode customizations
|
;; org-mode customizations
|
||||||
(setq org-superstar-headline-bullets-list
|
(setq org-superstar-headline-bullets-list '("⁖" "◉" "○" "✸" "✿"))
|
||||||
'("⁖" "◉" "○" "✸" "✿"))
|
|
||||||
(setq org-startup-with-inline-images t)
|
(setq org-startup-with-inline-images t)
|
||||||
;; org-roam customizations
|
;; org-roam customizations
|
||||||
;; If you use `org' and don't want your org files in the default location below,
|
;; If you use `org' and don't want your org files in the default location below,
|
||||||
@@ -43,24 +49,21 @@
|
|||||||
;; make sure that org-timer works and org-pomodoro therefore. Limit the number of agenda files searched
|
;; make sure that org-timer works and org-pomodoro therefore. Limit the number of agenda files searched
|
||||||
;; plus a utility function for flattening, since that is not part of the standard library of emacs
|
;; plus a utility function for flattening, since that is not part of the standard library of emacs
|
||||||
(defun flatten (list-of-lists)
|
(defun flatten (list-of-lists)
|
||||||
(apply #'append list-of-lists))
|
(apply #'append list-of-lists))
|
||||||
|
|
||||||
(setq org-agenda-files
|
(setq org-agenda-files
|
||||||
(flatten
|
(seq-map
|
||||||
(org-roam-db-query
|
'car
|
||||||
[:select
|
(org-roam-db-query
|
||||||
[file]
|
[:select
|
||||||
:from files :where
|
[file]
|
||||||
(like file "%daily\/2023%" )
|
:from files
|
||||||
:order-by
|
:where (like file "%daily\/2023%")
|
||||||
(desc file)
|
:order-by (desc file)
|
||||||
:limit 10])))
|
:limit 10])))
|
||||||
|
|
||||||
;; fix pdflatex for pdf export
|
;; fix pdflatex for pdf export
|
||||||
(setenv "PATH"
|
(setenv "PATH" (concat (getenv "PATH") ":/Library/TeX/texbin"))
|
||||||
(concat
|
|
||||||
(getenv "PATH")
|
|
||||||
":/Library/TeX/texbin"))
|
|
||||||
;; html export configuration, assuming use in a CMS or static site gerator that
|
;; html export configuration, assuming use in a CMS or static site gerator that
|
||||||
;; takes care of the layout
|
;; takes care of the layout
|
||||||
;; https://stackoverflow.com/questions/47508315/emacs-org-mode-export-to-html-without-syntax-highlighting
|
;; https://stackoverflow.com/questions/47508315/emacs-org-mode-export-to-html-without-syntax-highlighting
|
||||||
@@ -72,29 +75,30 @@
|
|||||||
;; utf-8 supported by the following lines
|
;; utf-8 supported by the following lines
|
||||||
(setq org-latex-compiler "xelatex")
|
(setq org-latex-compiler "xelatex")
|
||||||
(setq org-latex-pdf-process
|
(setq org-latex-pdf-process
|
||||||
(list
|
(list
|
||||||
(concat "latexmk -"
|
(concat
|
||||||
org-latex-compiler
|
"latexmk -"
|
||||||
" -recorder -synctex=1 -bibtex-cond %b")))
|
org-latex-compiler
|
||||||
|
" -recorder -synctex=1 -bibtex-cond %b")))
|
||||||
;; syntax highlighting for source code
|
;; syntax highlighting for source code
|
||||||
(setq org-latex-listings t)
|
(setq org-latex-src-block-backend t)
|
||||||
;; stuff taken care of by the classes that come in the next step can be set to nil.
|
;; stuff taken care of by the classes that come in the next step can be set to nil.
|
||||||
(setq org-latex-default-packages-alist
|
(setq org-latex-default-packages-alist
|
||||||
'(("" "graphicx" t)
|
'(("" "graphicx" t)
|
||||||
("" "grffile" t)
|
("" "grffile" t)
|
||||||
("" "longtable" nil)
|
("" "longtable" nil)
|
||||||
("" "wrapfig" nil)
|
("" "wrapfig" nil)
|
||||||
("" "rotating" nil)
|
("" "rotating" nil)
|
||||||
("normalem" "ulem" t)
|
("normalem" "ulem" t)
|
||||||
("" "amsmath" t)
|
("" "amsmath" t)
|
||||||
("" "textcomp" t)
|
("" "textcomp" t)
|
||||||
("" "amssymb" t)
|
("" "amssymb" t)
|
||||||
("" "capt-of" nil)
|
("" "capt-of" nil)
|
||||||
("" "hyperref" nil)))
|
("" "hyperref" nil)))
|
||||||
;; lots of latex
|
;; lots of latex
|
||||||
(setq org-latex-classes
|
(setq org-latex-classes
|
||||||
'(("article"
|
'(("article"
|
||||||
"\\RequirePackage{fix-cm}
|
"\\RequirePackage{fix-cm}
|
||||||
\\PassOptionsToPackage{svgnames}{xcolor}
|
\\PassOptionsToPackage{svgnames}{xcolor}
|
||||||
\\documentclass[11pt]{article}
|
\\documentclass[11pt]{article}
|
||||||
\\usepackage{fontspec}
|
\\usepackage{fontspec}
|
||||||
@@ -169,23 +173,25 @@
|
|||||||
\\AtBeginDocument{\\renewcommand{\\UrlFont}{\\ttfamily}}
|
\\AtBeginDocument{\\renewcommand{\\UrlFont}{\\ttfamily}}
|
||||||
[PACKAGES]
|
[PACKAGES]
|
||||||
[EXTRA]"
|
[EXTRA]"
|
||||||
("\\section{%s}" . "\\section*{%s}")
|
("\\section{%s}" . "\\section*{%s}")
|
||||||
("\\subsection{%s}" . "\\subsection*{%s}")
|
("\\subsection{%s}" . "\\subsection*{%s}")
|
||||||
("\\subsubsection{%s}" . "\\subsubsection*{%s}")
|
("\\subsubsection{%s}" . "\\subsubsection*{%s}")
|
||||||
("\\paragraph{%s}" . "\\paragraph*{%s}")
|
("\\paragraph{%s}" . "\\paragraph*{%s}")
|
||||||
("\\subparagraph{%s}" . "\\subparagraph*{%s}"))
|
("\\subparagraph{%s}" . "\\subparagraph*{%s}"))
|
||||||
("report" "\\documentclass[11pt]{report}"
|
("report"
|
||||||
("\\part{%s}" . "\\part*{%s}")
|
"\\documentclass[11pt]{report}"
|
||||||
("\\chapter{%s}" . "\\chapter*{%s}")
|
("\\part{%s}" . "\\part*{%s}")
|
||||||
("\\section{%s}" . "\\section*{%s}")
|
("\\chapter{%s}" . "\\chapter*{%s}")
|
||||||
("\\subsection{%s}" . "\\subsection*{%s}")
|
("\\section{%s}" . "\\section*{%s}")
|
||||||
("\\subsubsection{%s}" . "\\subsubsection*{%s}"))
|
("\\subsection{%s}" . "\\subsection*{%s}")
|
||||||
("book" "\\documentclass[11pt]{book}"
|
("\\subsubsection{%s}" . "\\subsubsection*{%s}"))
|
||||||
("\\part{%s}" . "\\part*{%s}")
|
("book"
|
||||||
("\\chapter{%s}" . "\\chapter*{%s}")
|
"\\documentclass[11pt]{book}"
|
||||||
("\\section{%s}" . "\\section*{%s}")
|
("\\part{%s}" . "\\part*{%s}")
|
||||||
("\\subsection{%s}" . "\\subsection*{%s}")
|
("\\chapter{%s}" . "\\chapter*{%s}")
|
||||||
("\\subsubsection{%s}" . "\\subsubsection*{%s}"))))
|
("\\section{%s}" . "\\section*{%s}")
|
||||||
|
("\\subsection{%s}" . "\\subsection*{%s}")
|
||||||
|
("\\subsubsection{%s}" . "\\subsubsection*{%s}"))))
|
||||||
;; make screenshot and paste
|
;; make screenshot and paste
|
||||||
;; https://zzamboni.org/post/how-to-insert-screenshots-in-org-documents-on-macos/
|
;; https://zzamboni.org/post/how-to-insert-screenshots-in-org-documents-on-macos/
|
||||||
|
|
||||||
@@ -211,29 +217,23 @@
|
|||||||
;; they are implemented.
|
;; they are implemented.
|
||||||
|
|
||||||
;; configure git-delta
|
;; configure git-delta
|
||||||
(after! magit
|
(after! magit (magit-delta-mode +1))
|
||||||
(magit-delta-mode +1))
|
|
||||||
;; HACK: disable diff-hl in magit - it appears to work ok inside files, but not in magit
|
;; HACK: disable diff-hl in magit - it appears to work ok inside files, but not in magit
|
||||||
;; Why? diff-hl-magit-post-refresh appears to be 'null' for some reason
|
;; Why? diff-hl-magit-post-refresh appears to be 'null' for some reason
|
||||||
;; When? after stage, unstage or commit an error appears in messages.
|
;; When? after stage, unstage or commit an error appears in messages.
|
||||||
(after!
|
(after!
|
||||||
(magit)
|
(magit) (remove-hook 'magit-post-refresh-hook 'diff-hl-magit-post-refresh))
|
||||||
(remove-hook 'magit-post-refresh-hook 'diff-hl-magit-post-refresh))
|
|
||||||
;; HACK show small snippets for backlinks preview in roam-buffer
|
;; HACK show small snippets for backlinks preview in roam-buffer
|
||||||
;; there is currently a problem in org-mode that shows an error
|
;; there is currently a problem in org-mode that shows an error
|
||||||
;; org-element--cache: Unregistered buffer modifications detected. Resetting. but this also happens without this function, it appears to be an interaction between org-roam and changes in orgmode.
|
;; org-element--cache: Unregistered buffer modifications detected. Resetting. but this also happens without this function, it appears to be an interaction between org-roam and changes in orgmode.
|
||||||
(defun qwan/brief-preview
|
(defun qwan/brief-preview ()
|
||||||
()
|
(let* ((elem (org-element-context))
|
||||||
(let*
|
(parent (org-element-property :parent elem)))
|
||||||
((elem
|
;; TODO: alt handling for non-paragraph elements
|
||||||
(org-element-context))
|
(string-trim-right
|
||||||
(parent
|
(buffer-substring-no-properties
|
||||||
(org-element-property :parent elem)))
|
(org-element-property :begin parent)
|
||||||
;; TODO: alt handling for non-paragraph elements
|
(org-element-property :end parent)))))
|
||||||
(string-trim-right
|
|
||||||
(buffer-substring-no-properties
|
|
||||||
(org-element-property :begin parent)
|
|
||||||
(org-element-property :end parent)))))
|
|
||||||
(setq org-roam-preview-function #'qwan/brief-preview)
|
(setq org-roam-preview-function #'qwan/brief-preview)
|
||||||
;; cursor moved back to ?beginning of line? too often
|
;; cursor moved back to ?beginning of line? too often
|
||||||
(setq evil-move-cursor-back nil)
|
(setq evil-move-cursor-back nil)
|
||||||
@@ -242,239 +242,154 @@
|
|||||||
(setq-default enable-local-variables t)
|
(setq-default enable-local-variables t)
|
||||||
;; two functions from:
|
;; two functions from:
|
||||||
;; https://zzamboni.org/post/my-emacs-configuration-with-commentary/#reformatting-an-org-buffer
|
;; https://zzamboni.org/post/my-emacs-configuration-with-commentary/#reformatting-an-org-buffer
|
||||||
(defun zz/org-reformat-buffer
|
(defun zz/org-reformat-buffer ()
|
||||||
()
|
(interactive)
|
||||||
(interactive)
|
(when (y-or-n-p "Really format current buffer? ")
|
||||||
(when
|
(let ((document (org-element-interpret-data (org-element-parse-buffer))))
|
||||||
(y-or-n-p "Really format current buffer? ")
|
(erase-buffer)
|
||||||
(let
|
(insert document)
|
||||||
((document
|
(goto-char (point-min)))))
|
||||||
(org-element-interpret-data
|
(defun afs/org-remove-link ()
|
||||||
(org-element-parse-buffer))))
|
"Replace an org link by its description or if empty its address"
|
||||||
(erase-buffer)
|
(interactive)
|
||||||
(insert document)
|
(if (org-in-regexp org-link-bracket-re 1)
|
||||||
(goto-char
|
(let ((remove (list (match-beginning 0) (match-end 0)))
|
||||||
(point-min)))))
|
(description
|
||||||
(defun afs/org-remove-link
|
(if (match-end 3)
|
||||||
()
|
(match-string-no-properties 3)
|
||||||
"Replace an org link by its description or if empty its address"
|
(match-string-no-properties 1))))
|
||||||
(interactive)
|
(apply 'delete-region remove)
|
||||||
(if
|
(insert description))))
|
||||||
(org-in-regexp org-link-bracket-re 1)
|
|
||||||
(let
|
|
||||||
((remove
|
(defun qwan/org-replace-link-by-link-description ()
|
||||||
(list
|
"Remove the link part of an org-mode link at point and keep
|
||||||
(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"
|
only the description"
|
||||||
(interactive)
|
(interactive)
|
||||||
(let
|
(let ((elem (org-element-context)))
|
||||||
((elem
|
(if (eq (car elem) 'link)
|
||||||
(org-element-context)))
|
(let* ((content-begin (org-element-property :contents-begin elem))
|
||||||
(if
|
(content-end (org-element-property :contents-end elem))
|
||||||
(eq
|
(link-begin (org-element-property :begin elem))
|
||||||
(car elem)
|
(link-end (org-element-property :end elem)))
|
||||||
'link)
|
(if (and content-begin content-end)
|
||||||
(let*
|
(let ((content
|
||||||
((content-begin
|
(buffer-substring-no-properties
|
||||||
(org-element-property :contents-begin elem))
|
content-begin content-end)))
|
||||||
(content-end
|
(delete-region link-begin (- link-end 1))
|
||||||
(org-element-property :contents-end elem))
|
(insert content)))))))
|
||||||
(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)
|
(bind-key "C-c r" 'qwan/org-replace-link-by-link-description)
|
||||||
(defun org-roam-replace-file-link-by-website-or-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
|
||||||
"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"
|
the description. This may destroy existing links, or change their targets so use in a copy of buffers you hold dearly as notes"
|
||||||
(interactive)
|
(interactive)
|
||||||
(let
|
(let ((elem (org-element-context)))
|
||||||
((elem
|
(if (eq (car elem) 'link)
|
||||||
(org-element-context)))
|
(let* ((content-begin (org-element-property :contents-begin elem))
|
||||||
(if
|
(content-end (org-element-property :contents-end elem))
|
||||||
(eq
|
(target-type (org-element-property :type elem))
|
||||||
(car elem)
|
(target-path (org-element-property :path elem))
|
||||||
'link)
|
(link-begin (org-element-property :begin elem))
|
||||||
(let*
|
(link-end (org-element-property :end elem)))
|
||||||
((content-begin
|
(if (and content-begin
|
||||||
(org-element-property :contents-begin elem))
|
content-end
|
||||||
(content-end
|
(string-equal target-type "file")
|
||||||
(org-element-property :contents-end elem))
|
target-path
|
||||||
(target-type
|
link-begin
|
||||||
(org-element-property :type elem))
|
link-end)
|
||||||
(target-path
|
(let ((new-link
|
||||||
(org-element-property :path elem))
|
(org-roam-description-file-to-org-url
|
||||||
(link-begin
|
(buffer-substring-no-properties content-begin content-end)
|
||||||
(org-element-property :begin elem))
|
target-path)))
|
||||||
(link-end
|
(delete-region link-begin (- link-end 1))
|
||||||
(org-element-property :end elem)))
|
(insert new-link)))))))
|
||||||
(if
|
(defun qwan/string-as-markdown-image-link (a-string)
|
||||||
(and content-begin content-end
|
(concat ""))
|
||||||
(string-equal target-type "file")
|
(defun qwan/image-mode-copy-filename-as-markdown-image-link ()
|
||||||
target-path link-begin link-end)
|
"Push a markdown link to the currently visited image onto the kill ring."
|
||||||
(let
|
(interactive)
|
||||||
((new-link
|
(unless buffer-file-name
|
||||||
(org-roam-description-file-to-org-url
|
(error "The current buffer doesn't visit an image file"))
|
||||||
(buffer-substring-no-properties content-begin content-end)
|
(let ((markdown-link
|
||||||
target-path)))
|
(qwan/string-as-markdown-image-link
|
||||||
(delete-region link-begin
|
(qwan/relative-path-to-attachments buffer-file-name))))
|
||||||
(- link-end 1))
|
(kill-new markdown-link)
|
||||||
(insert new-link)
|
(message "Copied %s" markdown-link)))
|
||||||
))))))
|
(defun qwan/relative-path-to-attachments (full-path)
|
||||||
(defun qwan/string-as-markdown-image-link
|
(substring full-path (string-search "/attachments" full-path 0)))
|
||||||
(a-string)
|
|
||||||
(concat ""))
|
|
||||||
(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
|
|
||||||
((markdown-link
|
|
||||||
(qwan/string-as-markdown-image-link
|
|
||||||
(qwan/relative-path-to-attachments buffer-file-name))))
|
|
||||||
(kill-new markdown-link)
|
|
||||||
(message "Copied %s" markdown-link)))
|
|
||||||
(defun qwan/relative-path-to-attachments
|
|
||||||
(full-path)
|
|
||||||
(substring full-path
|
|
||||||
(string-search "/attachments" full-path 0)
|
|
||||||
))
|
|
||||||
(require 'ert)
|
(require 'ert)
|
||||||
(ert-deftest relative-path-to-attachments-removes-prefix
|
(ert-deftest relative-path-to-attachments-removes-prefix ()
|
||||||
()
|
(should
|
||||||
(should
|
(equal
|
||||||
(equal
|
(qwan/attachments-remove-prefix-path "prefix/attachments") "/attachments")))
|
||||||
(qwan/attachments-remove-prefix-path "prefix/attachments")
|
(ert-deftest
|
||||||
"/attachments")))
|
relative-path-to-attachments-does-not-remove-prefix-when-no-attachments
|
||||||
(ert-deftest relative-path-to-attachments-does-not-remove-prefix-when-no-attachments
|
()
|
||||||
()
|
(should
|
||||||
(should
|
(equal
|
||||||
(equal
|
(qwan/attachments-remove-prefix-path "prefix/somethingelse")
|
||||||
(qwan/attachments-remove-prefix-path "prefix/somethingelse")
|
"prefix/somethingelse")))
|
||||||
"prefix/somethingelse")))
|
(ert-deftest markdown-link-tokens-should-surround-string ()
|
||||||
(ert-deftest markdown-link-tokens-should-surround-string
|
(should
|
||||||
()
|
(equal
|
||||||
(should
|
(qwan/string-as-markdown-image-link "prefix/image.png")
|
||||||
(equal
|
"")))
|
||||||
(qwan/string-as-markdown-image-link "prefix/image.png")
|
(defun qwan-echo (new-name)
|
||||||
"")))
|
(interactive "SRename function to:")
|
||||||
(defun qwan-echo
|
(message "Will rename to %s" new-name))
|
||||||
(new-name)
|
|
||||||
(interactive "SRename function to:")
|
|
||||||
(message "Will rename to %s" new-name)
|
|
||||||
)
|
|
||||||
;; from @tbf@functional.cafe
|
;; from @tbf@functional.cafe
|
||||||
(defun movd
|
(defun movd (from to)
|
||||||
(from to)
|
(fset to (symbol-function from))
|
||||||
(fset to
|
(fset from nil)
|
||||||
(symbol-function from))
|
to)
|
||||||
(fset from nil)
|
|
||||||
to)
|
|
||||||
;; from @tbf@functional.cafe
|
;; from @tbf@functional.cafe
|
||||||
(defmacro frename
|
(defmacro frename (from to)
|
||||||
(from to)
|
`(movd ',from ',to))
|
||||||
`(movd ',from ',to))
|
(defun qrefactor/rename (new-name)
|
||||||
(defun qrefactor/rename
|
"Rename function at point. You must modify references yourself"
|
||||||
(new-name)
|
(interactive "MRename function to:")
|
||||||
"Rename function at point. You must modify references yourself"
|
(let ((bounds (bounds-of-thing-at-point 'symbol)))
|
||||||
(interactive "MRename function to:")
|
(if bounds
|
||||||
(let
|
(progn
|
||||||
((bounds
|
(let* ((begin (car bounds))
|
||||||
(bounds-of-thing-at-point 'symbol)))
|
(end (cdr bounds))
|
||||||
(if bounds
|
(old-name (buffer-substring-no-properties begin end))
|
||||||
(progn
|
(new-function-name (as-function-name new-name)))
|
||||||
(let*
|
(message "Will rename to %s" new-function-name)
|
||||||
((begin
|
;; should use as-function-name here
|
||||||
(car bounds))
|
(movd (intern old-name) (intern new-function-name))
|
||||||
(end
|
(ert-make-test-unbound (intern old-name))
|
||||||
(cdr bounds))
|
(delete-region begin end)
|
||||||
(old-name
|
(insert new-function-name)
|
||||||
(buffer-substring-no-properties begin end))
|
(message "Renamed %s to %s." old-name new-name)))
|
||||||
(new-function-name
|
(message "No symbol under cursor."))))
|
||||||
(as-function-name new-name)))
|
(defun qrefactor/remove-test ()
|
||||||
(message "Will rename to %s" new-function-name)
|
"Renmove test at point from memory.
|
||||||
;; should use as-function-name here
|
|
||||||
(movd
|
|
||||||
(intern old-name)
|
|
||||||
(intern new-function-name))
|
|
||||||
(ert-make-test-unbound
|
|
||||||
(intern old-name))
|
|
||||||
(delete-region begin end)
|
|
||||||
(insert new-function-name)
|
|
||||||
(message "Renamed %s to %s." old-name new-name)))
|
|
||||||
(message "No symbol under cursor."))))
|
|
||||||
(defun qrefactor/remove-test
|
|
||||||
()
|
|
||||||
"Renmove test at point from memory.
|
|
||||||
See also ert-delete-test if you want to delete from a list of existing tests."
|
See also ert-delete-test if you want to delete from a list of existing tests."
|
||||||
(interactive)
|
(interactive)
|
||||||
(let
|
(let ((bounds (bounds-of-thing-at-point 'symbol)))
|
||||||
((bounds
|
(if bounds
|
||||||
(bounds-of-thing-at-point 'symbol)))
|
(progn
|
||||||
(if bounds
|
(let* ((begin (car bounds))
|
||||||
(progn
|
(end (cdr bounds))
|
||||||
(let*
|
(old-name (buffer-substring-no-properties begin end)))
|
||||||
((begin
|
(ert-make-test-unbound (intern old-name))
|
||||||
(car bounds))
|
(message "Undefined %s." old-name))))
|
||||||
(end
|
(message "No symbol under cursor.")))
|
||||||
(cdr bounds))
|
|
||||||
(old-name
|
|
||||||
(buffer-substring-no-properties begin end)))
|
|
||||||
(ert-make-test-unbound
|
|
||||||
(intern old-name))
|
|
||||||
(message "Undefined %s." old-name ))))
|
|
||||||
(message "No symbol under cursor.")))
|
|
||||||
;; tests are better than literate programming when you want to triangulate on the same function
|
;; tests are better than literate programming when you want to triangulate on the same function
|
||||||
;; org only shows the last return value by default, you can return a list of course, but still
|
;; org only shows the last return value by default, you can return a list of course, but still
|
||||||
(defun as-function-name
|
(defun as-function-name (candidate-name)
|
||||||
(candidate-name)
|
"Take the string and make it suitable to be a function name. Replaces space with dash and make string all lowercase."
|
||||||
"Take the string and make it suitable to be a function name. Replaces space with dash and make string all lowercase."
|
(declare (side-effect-free t))
|
||||||
(declare
|
(s-join "-" (mapcar 'downcase (split-string candidate-name " " t))))
|
||||||
(side-effect-free t))
|
|
||||||
(s-join "-"
|
|
||||||
(mapcar 'downcase
|
|
||||||
(split-string candidate-name " " t))))
|
|
||||||
;; (s-join "-" (mapcar 'downcase (s-split-words s))))
|
;; (s-join "-" (mapcar 'downcase (s-split-words s))))
|
||||||
(ert-deftest refactor-rename-should-leave-forward-slash()
|
(ert-deftest refactor-rename-should-leave-forward-slash ()
|
||||||
(should
|
(should (equal (as-function-name "qwan/echo") "qwan/echo")))
|
||||||
(equal
|
(ert-deftest refactor-rename-should-replace-space-with-dash ()
|
||||||
(as-function-name "qwan/echo")
|
(should (equal (as-function-name "qwan/echo chamber") "qwan/echo-chamber")))
|
||||||
"qwan/echo")))
|
(ert-deftest refactor-rename-replaces-uppercase-with-lowercase ()
|
||||||
(ert-deftest refactor-rename-should-replace-space-with-dash()
|
(should (equal (as-function-name "Echo-chamber") "echo-chamber")))
|
||||||
(should
|
(ert-deftest refactor-renamed-thrice ()
|
||||||
(equal
|
(should (equal 1 1)))
|
||||||
(as-function-name "qwan/echo chamber")
|
|
||||||
"qwan/echo-chamber")))
|
|
||||||
(ert-deftest refactor-rename-replaces-uppercase-with-lowercase()
|
|
||||||
(should
|
|
||||||
(equal
|
|
||||||
(as-function-name "Echo-chamber")
|
|
||||||
"echo-chamber")))
|
|
||||||
(ert-deftest refactor-renamed-thrice
|
|
||||||
()
|
|
||||||
(should
|
|
||||||
(equal 1 1)))
|
|
||||||
(ert-make-test-unbound 'refactor-rename-test-for-fun)
|
(ert-make-test-unbound 'refactor-rename-test-for-fun)
|
||||||
(ert "refactor.*")
|
;; (ert "refactor.*")
|
||||||
|
|||||||
@@ -12,6 +12,9 @@
|
|||||||
(package! diff-hl)
|
(package! diff-hl)
|
||||||
(package! puni)
|
(package! puni)
|
||||||
(package! crux)
|
(package! crux)
|
||||||
|
(package! exec-path-from-shell)
|
||||||
|
(package! elisp-autofmt)
|
||||||
|
|
||||||
;; To install a package directly from a remote git repo, you must specify a
|
;; To install a package directly from a remote git repo, you must specify a
|
||||||
;; `:recipe'. You'll find documentation on what `:recipe' accepts here:
|
;; `:recipe'. You'll find documentation on what `:recipe' accepts here:
|
||||||
;; https://github.com/raxod502/straight.el#the-recipe-format
|
;; https://github.com/raxod502/straight.el#the-recipe-format
|
||||||
|
|||||||
Reference in New Issue
Block a user