| .gitignore | init | |
| README.md | update | |
| tasks.el | update | |
Tasks - a general-purpose task runner for Emacs
Installation
For elpaca user:
(use-package tasks
:ensure (:host codeberg :repo "meow_king/tasks"))
For other users, please figure it yourself.
Usage
Note: example file see my own configuration: my-tasks.el
- Define your custom task run function, and set customizable variable
tasks-function,tasks-project-function
Example:
(defun mk/tasks/run ()
(interactive)
(let ((file-extension (file-name-extension buffer-file-name)))
(cond
((derived-mode-p '(c-mode c-ts-mode))
(mk/tasks/c))
((derived-mode-p '(python-base-mode))
(mk/tasks/python))
((derived-mode-p '(rust-ts-mode))
(mk/tasks/rust))
((derived-mode-p '(zig-mode zig-ts-mode))
(mk/tasks/zig))
((derived-mode-p '(kotlin-ts-mode))
(mk/tasks/kotlin))
((string-match-p (regexp-opt '("puml" "plantuml")) file-extension)
(tasks-wrap-compile-command
'(concat "env PLANTUML_LIMIT_SIZE=327680 plantuml " rel-file-name
" && imv " bare-rel-file-name ".png")))
(t (message "No tasks defined for current condition.")))))
(defun mk/tasks/project-run ()
(interactive)
(let ((project-root-path (project-root (project-current))))
(cond
((file-exists-p (expand-file-name "Cargo.toml" project-root-path))
(mk/tasks/rust))
((file-exists-p (expand-file-name "build.zig" project-root-path))
(mk/tasks/zig))
(t (mk/tasks/run)))))
(setq tasks-function #'mk/tasks/run)
(setq tasks-project-function #'mk/tasks/project-run))
- Use utility functions provided by
tasksto define specific tasks for various condition.
Currently, tasks provides:
-
tasks-transient-define-prefixas a modified version oftransient-define-prefix, through which you can define a transient menu for easily managing and invoking tasks. (NOTE excellent resource to learn transient: transient-showcase) Example Usage:(tasks-transient-define-prefix mk/tasks/rust () "Tasks for Rust language." ["Options" ("-p" "package" mk/tasks-infix/rust/package)] [["Cargo" ("pc" "check" (concat "cargo check " (tasks-transient-get-arg "--package="))) ("pC" "clippy" (concat "cargo clippy " (tasks-transient-get-arg "--package="))) ("pf" "clippy fix" (concat "cargo clippy fix " (tasks-transient-get-arg "--package="))) ("pr" "run" (concat "cargo run " (tasks-transient-get-arg "--package=")))]])tasks-transient-define-prefixhas some special modifications oftransient-define-prefix. For command definition("pc" "check" "echo 1"), for the third argument:- when it is function-alias type (e.g defined by
transient-define-argumentmacro), it is handled the same astransient-define-prefix - when it is symbol type, it is treated as a command (interactive function) and
wrapped by
tasks-wrap-thingto make surerun-last-commandfunction working. - when it is of other types, it is evaluated as an Emacs expression using
eval. Some convenient variables such asdirectory-path,file-name,rel-file-pathare provided so you can directly use them like(concat "echo " file-name). More information can be referred fromtasks-wrap-compile-commandcommand (see its source code). Since transient normally treat expression as infix expression when the third argument is string type or list type, e.g.("-s" "switch" "--switch"), We recommend to use utility macros liketransient-define-argumentto define infix arguments. For example:(transient-define-argument mk/tasks-infix/rust/package () :class 'transient-option :argument "--package=")
- when it is function-alias type (e.g defined by
-
tasks-transient-get-arg: get the value of transient infix argument and return a-a=vlike string. -
tasks-wrap-thing,tasks-wrap-functionandtasks-wrap-compile-commandfor wrap your command withtasks. Currently this wrapper record the last run command so that you can invoke the last run command.
- commands provided by tasks
tasks-run, tasks-run-last-cmd, tasks-project-run, tasks-project-run-last-cmd