| title | Development API |
|---|---|
| weight | 700 |
This document provides a reference to the public Eask API, which you may use in your projects and extensions to Eask.
{{< toc >}}
Load lisp/_prepare.el to start using other Eask API.
(load (expand-file-name
"../_prepare.el"
(file-name-directory (nth 1 (member "-scriptload" command-line-args))))
nil t)Each Elisp scripts should have this snippet at the very top of the file.
Command entry point. Each command file should contain this macro somewhere in the file.
(eask-start
;; TODO: design your command here!
)Points to lisp directory from the project root.
Return the current command in string.
Return t if the command that can be run without Eask-file existence.
This allow some commands can still be executed without defining the user directory. This can be handy when you want to do normal operations without touching the user directory.
Return t if running Eask as the checker.
Without this flag, the process will be terminated once the error is occured. This flag allows you to run through operations without report error.
Return full script filename.
(eask-script "extern/pacakge") ; {project-root}/lisp/extern/package.elLoad another eask script.
(eask-load "extern/ansi") ; load {project-root}/lisp/extern/ansi.el fileCall another eask script.
(eask-call "clean/elc") ; call command `eask clean-elc`{{< hint info >}} 💡 This is rarely used! {{< /hint >}}
Define scope if Emacs version is below specific version.
VERSION is an integer and will be compared with emacs-major-version.
(eask-defvc< 28
;; This is missing before Emacs 28; define it
(defvar package-native-compile nil)
){{< hint info >}} 💡 This is used for Emacs compatibility! {{< /hint >}}
Mute all messages from standard output inside the scope.
(eask--unsilent (message "You can't hear me! :("))Unmute all messages from standard output inside the scope.
(eask--unsilent (message "You can hear me! :)"))Return a list of dependencies.
Elements should either be (NAME . VERSION) or (NAME . RECIPE-FORMAT).
Initialize packages for use.
(eask-start
(eask-pkg-init)
;; Now you can use packages installed in `package-user-dir'
){{< hint info >}} 💡 This is usually called after eask-start! {{< /hint >}}
Scope that temporary makes archives available.
ARCHIVES can either be a string or a list of strings.
(eask-with-archives "melpa"
(eask-package-install 'package-build)) ; install packages that are only defined in MELPA{{< hint info >}} 💡 This is handy when you need certain packages from certain archives. {{< /hint >}}
Build package descriptor for a package.
CURRENT means installed packages; otherwise it will return any available
packages from selected package archives.
Return a command-line argument by index.
Return a list that is extracted from command-line arguments.
$ eask info --verbose 4 foo barIt will ignore --verbose and 4, and only returns foo, and bar.
Path to currently loaded Eask-file.
Directory to currently loaded Eask-file.
Return t if the current Emacs session allows insecure network connections.
Return t if the global option is enabled.
(if (eask-global-p)
user-emacs-directory ; ~/.emacs.d
user-emacs-directory) ; ./.eask/{emacs-version}/Return t if the all option is enabled.
(when (eask-all-p)
;; Run all tests
...)Return t if the quick option is enabled.
(unless (eask-quick-p)
(load user-init-file)
...)Return t if the force option is enabled.
(package-delete .. (eask-force-p))Return t if the development option is enabled.
(when (eask-dev-p)
(package-install 'ert-runner)) ; install development dependencyReturn t if the debug option is enabled.
(when (eask-debug-p)
(error "Executing in debug mode..."))Return t if the strict option is enabled.
(setq byte-compile-error-on-warn (eask-strict-p))Return t/nil if the timestamps option is enabled/disabled.
These flags can't co-exist in the same command.
(when (eask-timestamps-p)
(message "Print log with timestamps!"))Return t/nil if the log-level option is enabled/disabled.
These flags can't co-exist in the same command.
(when (eask-log-level-p)
(message "Print log with level prefix!"))(when (eask-log-file-p)
(message "Let's create a log file!"))Return t if the color option is enabled.
(unless (eask-no-color-p)
(message "This string has no ansi code!"))Return t if the allow-error option is enabled.
(unless (eask-allow-error-p)
(error "Stop here."))Return t if the insecure option is enabled.
(when (eask-insecure-p)
;; Do some dangerous tasks?
)Return a string represents hostname + port number.
$ eask [command] --proxy "localhost:1000"
$ eask [command] --http-proxy "localhost:2000"
$ eask [command] --https-proxy "localhost:3000"
$ eask [command] --no-proxy "localhost:4000"Return a string represents the destination (output path).
(write-file (or (eask-destination) "./dist")) ; write file to destinationReturn an integer represents the depth of the current print level.
(setq print-level (eask-depth))Return an integer represents the verbosity level.
(when (= (eask-verbose) 4)
(setq byte-compile-verbose t))These functions are the actual implementation of Eask-file DSL; and
have the word eask- as the function prefix.
See DSL section for more information.
It holds package's NAME, VERSION, and DESCRIPTION in a plist.
(plist-get eask-package :name) ; return package nameThree functions that are extended from this variable:
(eask-package-name)(eask-package-version)(eask-package-description)
Points to package main file.
Package descriptor from the package main file.
(package-desc-p eask-package-desc) ; return t{{< hint warning >}} ⚠ This can be nil if the package-descriptor cannot be constructed correctly! {{< /hint >}}
Holds a list of files pattern in wildcard specification.
Holds a list of available scripts that can be executed by user using the
eask run-script command.
Holds information about Emacs minimum version.
(depends-on "emacs" "26.1")Function will return Emacs version in string.
(eask-depends-emacs-version)- return"26.1"
Holds a list of dependencies.
Holds a list of dependencies that are development used.
Alias of package.
Alias of website-url.
Alias of keywords.
Alias of package-file.
Alias of files.
Alias of script.
Alias of source.
Alias of depends-on.
Alias of development.
Alias of exec-paths.
Alias of load-paths.
Logger utility with timestamps and log level.
The log level value is defined in function eask--verb2lvl.
| Level | Description | Value |
|---|---|---|
debug |
Designates fine-grained informational events that are most useful to debug an application. | 4 |
log |
Designates normal messages. | 3 |
info |
Designates informational messages that highlight the progress of the application at coarse-grained level. | 2 |
warn |
Designates potentially harmful situations. | 1 |
error |
Designates error events that might still allow the application to continue running. | 0 |
The default level is log.
The verbosity level is represented as an integer.
(setq eask-verbosity 4) ; you could set from 0 to 4Log messages with timestamps.
(setq eask-timestamps t)Output:
2022-04-14 13:44:46 This is a message with timestamps
Log messages with level. (default: nil)
(setq eask-log-level t)Output:
[DEBUG] This is a DEBUG message with log level
Weather to generate log files. (default: nil)
(setq eask-log-level t)Use command cat to see the log,
$ cat /.log/messages.log
Define each log level color.
(setq eask-level-color
'((debug . ansi-blue)
(log . ansi-white)
(info . ansi-cyan)
(warn . ansi-yellow)
(error . ansi-red)))Define executions with the verbosity level.
(eask-with-verbosity 'debug
;; TODO: execution here..
)Everything in the scope of this macro will be muted unless the verbosity
reaches. It will only be printed when you have specified --verbose 4
global option.
(eask-debug "This is DEBUG message")2022-04-14 17:31:54 [DEBUG] This is DEBUG message
(eask-log "This is LOG message")2022-04-14 17:31:54 [LOG] This is LOG message
(eask-info "This is INFO message")2022-04-14 17:31:54 [INFO] This is INFO message
(eask-warn "This is WARNING message")2022-04-14 17:31:54 [WARNING] This is WARNING message
(eask-error "This is ERROR message")2022-04-14 17:31:54 [ERROR] This is ERROR message
Like message function but will replace unicodes with color.
(eask-msg "Print this message with newline!")Like eask-msg function but without newline at the end.
(eask-write "Print this message without newline...")Report error/warning depends on strict flag.
(eask-report "This can be warning or error")See option --strict
Return the possible package name.
Return a list of package files.
Return a list of package files with .el extension.
Return a list of package files with .elc extension.
Return nil if single file package.
Return t if single file package.
Return size of the current package.
{{< hint warning >}}
Create execution with the responsive message output.
(eask-with-progress
"Downloading files... "
(eask-with-verbosity 'debug ; Often used with `eask-with-verbosity'
;; Execute some operations..
)
"done ✓")Expect output:
Downloading files... done ✓
Print buffer and highlight the errors and warnings.
(eask-print-log-buffer "*Package-Lint*"){{< hint info >}} 💡 This is handy for linters that create a buffer to display errors and warnings. {{< /hint >}}
Print help manual located under lisp/help/ directory.
(eask-help "core/search"){{< hint info >}} 💡 This is used when a command fails, and would like to give users some tips! {{< /hint >}}