summaryrefslogtreecommitdiffhomepage
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/doc/jao-org-focus.el47
-rw-r--r--lib/prog/jao-rust.el54
2 files changed, 83 insertions, 18 deletions
diff --git a/lib/doc/jao-org-focus.el b/lib/doc/jao-org-focus.el
index a135ff5..2383cfc 100644
--- a/lib/doc/jao-org-focus.el
+++ b/lib/doc/jao-org-focus.el
@@ -24,20 +24,40 @@
(defvar-local jao-org-focus--parent nil)
(defvar-local jao-org-focus--section nil)
+(defvar jao-org-focus-siblings '("escaleta.org" . "novela.org"))
+
+(defun jao-org-focus--header-title ()
+ (when-let* ((elem (org-element-at-point))
+ (header (if (eq 'headline (org-element-type elem))
+ elem
+ (org-previous-visible-heading 1)
+ (org-element-at-point))))
+ (org-element-property :title header)))
+
+(defun jao-org-focus--is-outline ()
+ (string= (car jao-org-focus-siblings)
+ (file-name-nondirectory (or (buffer-file-name) ""))))
+
+(defun jao-org-focus-jump-to-sibling ()
+ (interactive)
+ (when-let* ((title (save-excursion (jao-org-focus--header-title)))
+ (file (if (jao-org-focus--is-outline)
+ (cdr jao-org-focus-siblings)
+ (car jao-org-focus-siblings)))
+ (link (format "[[./%s::*%s]]" file title)))
+ (org-link-open-from-string link)))
+
;;; focus on subtree
(defun jao-org-focus ()
"Pop creatingly to an indirect buffer focused on the encloing subtree.
When invoked on an indirect buffer, pops back to its base."
(interactive)
+ (when (jao-org-focus--is-outline)
+ (jao-org-focus-jump-to-sibling))
(if-let* ((b (get-buffer (or jao-org-focus--parent ""))))
(pop-to-buffer b)
- (when-let* ((elem (org-element-at-point))
- (header (if (eq 'headline (org-element-type elem))
- elem
- (org-previous-visible-heading 1)
- (org-element-at-point)))
- (title (org-element-property :title header))
+ (when-let* ((title (jao-org-focus--header-title))
(parent (buffer-name))
(bname (format "%s [%s]" title parent)))
(if-let* ((b (get-buffer bname)))
@@ -119,17 +139,18 @@ With arg, offer to switch to all children, regardless of their parent."
(defvar jao-org-focus-consult-buffer-source
`(:name "Focus buffers"
- :category jao-org-focus-buffers
- :action switch-to-buffer
- :hidden t
- :narrow ,(cons ?o "focus")
- :history jao-org-focus--focused-history
- :items ,(lambda () (mapcar 'buffer-name (jao-org-focus-list t)))))
+ :category jao-org-focus-buffers
+ :action switch-to-buffer
+ :hidden t
+ :narrow ,(cons ?o "focus")
+ :history jao-org-focus--focused-history
+ :items ,(lambda () (mapcar 'buffer-name (jao-org-focus-list t)))))
(define-minor-mode org-focus-mode
"A mode where keeping track of focused children is on by default."
:lighter " ◎"
- :keymap '(("\C-cl" . jao-org-focus-switch)
+ :keymap '(("\C-ce" . jao-org-focus-jump-to-sibling)
+ ("\C-cl" . jao-org-focus-switch)
("\C-cR" . jao-org-focus-redisplay)
("\C-co" . jao-org-focus)
("\C-cw" . count-words)
diff --git a/lib/prog/jao-rust.el b/lib/prog/jao-rust.el
index 9c08e9b..436de00 100644
--- a/lib/prog/jao-rust.el
+++ b/lib/prog/jao-rust.el
@@ -20,7 +20,8 @@
;;; Code:
-(defun jao-rust--root () (project-root (project-current)))
+(defun jao-rust--root ()
+ (locate-dominating-file default-directory "Cargo.toml"))
(defun jao-rust-open-cargo ()
(interactive)
@@ -40,14 +41,45 @@
(replace-regexp-in-string "/\\(mod\\|lib\\|main\\)$" "")
(string-replace "/" "::"))))
+(defconst jao-rust--test-header-rx
+ (concat "#\\[" (regexp-opt '("test" "quickcheck" "tokio::test") t)))
+
+(defconst jao-rust--test-name-rx "^ *\\(pub\\)?\\( async\\)? fn \\([^(]+\\)(")
+
+(defun jao-rust-test-at-point ()
+ (when (looking-at jao-rust--test-name-rx) (match-string-no-properties 3)))
+
+(defun jao-rust-test-before-point ()
+ (save-excursion
+ (when (re-search-backward jao-rust--test-header-rx nil t)
+ (forward-line)
+ (jao-rust-test-at-point))))
+
+
+(defconst jao-rust--tests-mod-rx "^\\(pub\\)? *mod tests {")
+
+(defun jao-rust-goto-tests ()
+ (interactive)
+ (or (re-search-forward jao-rust--tests-mod-rx nil t)
+ (re-search-backward jao-rust--tests-mod-rx nil t)
+ (message "No tests module")))
+
+(defun jao-rust-test-current ()
+ (interactive)
+ (if-let* ((m (jao-rust-current-module-name))
+ (n (jao-rust-test-before-point)))
+ (let ((rustic-test-arguments (format "-- --exact %s::tests::%s" m n))
+ (rustic-cargo-use-last-stored-arguments t))
+ (rustic-cargo-test))
+ (message "No test before point")))
+
(defun jao-rust-buffer-tests ()
(save-excursion
(goto-char (point-min))
(let ((res '()))
- (while (re-search-forward "#\\[\\(tokio::test\\|test\\|quickcheck\\)" nil t)
+ (while (re-search-forward jao-rust--test-header-rx nil t)
(forward-line)
- (when (looking-at "^ *\\(pub\\)?\\( async\\)? fn \\([^(]+\\)(")
- (push (match-string-no-properties 3) res)))
+ (when-let* ((name (jao-rust-test-at-point))) (push name res)))
res)))
(defun jao-rust-test-module ()
@@ -57,13 +89,25 @@
(messages "No tests in this module")
(let* ((mod (jao-rust-current-module-name))
(tests (mapconcat (lambda (x) (format "%s::tests::%s" mod x)) tests " "))
- (rustic-test-arguments (format "-- --exact %s" tests)))
+ (rustic-test-arguments (format "-- --exact %s" tests))
+ (rustic-cargo-use-last-stored-arguments t))
(rustic-cargo-test)))))
+(defun jao-rust-retest ()
+ (interactive)
+ (let* ((rustic-test-arguments "-R latest")
+ (rustic-cargo-use-last-stored-arguments t))
+ (rustic-cargo-test)))
+
(defun jao-rust-test-workspace ()
(interactive)
(let ((rustic-test-arguments rustic-default-test-arguments))
(rustic-cargo-test)))
+
+(defun jao-rust-build-doc (deps)
+ (interactive "P")
+ (rustic-run-cargo-command `(,(rustic-cargo-bin) "doc" ,@(unless deps '("--no-deps")))))
+
(provide 'jao-rust)
;;; jao-rust.el ends here