Skip to content

Commit

Permalink
Add doc about slash
Browse files Browse the repository at this point in the history
  • Loading branch information
jcs090218 committed Mar 12, 2023
1 parent 17e6022 commit 095f51c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 9 deletions.
24 changes: 23 additions & 1 deletion docs/content/en/Getting Started/Advanced Usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,29 @@ This is also equivalent to option `--strict`:
$ eask compile [FILES..] --strict
```

Or hooks run on every command:
Or hooks that run on every command:

* `eask-before-command-hook`
* `eask-after-command-hook`

```elisp
(add-hook 'eask-before-command-hook
(lambda ()
(message "%s" (eask-command)))) ; print the current command
```

For subcommands that contain spaces, will concatenate with `/`:

```sh
$ eask lint checkdoc # lint/checkdoc
$ eask generate license # generate/license
```

therefore,

```elisp
(add-hook 'eask-before-lint/checkdoc-hook
(lambda ()
;; do stuff before checkdoc linting...
))
```
20 changes: 12 additions & 8 deletions lisp/_prepare.el
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,20 @@
"What's the current command?
If the command is with subcommand, it will return command with concatenate with
dash separator. For example, the following:
slash separator. For example, the following:
$ eask lint checkdoc [FILES..]
will return `lint/checkdoc' with a dash between two subcommands."
(let* ((script-dir (file-name-directory eask--script))
(script-file (file-name-sans-extension (file-name-nondirectory eask--script)))
(module-name (eask-s-replace eask-lisp-root "" script-dir))
(module-name (eask-s-replace "/" "" module-name)))
;; Ignore if it's inside core module
(if (member module-name '("core" "checker")) script-file
(concat module-name "/" script-file))))
(module-names (split-string module-name "/" t)))
;; Make certain commands the root command; e.g. `core', `checker', etc.
(if (member (nth 0 module-names) '("core" "checker")) script-file
(mapconcat #'identity (append module-names
(list script-file))
"/"))))

(defun eask-special-p ()
"Return t if the command that can be run without Eask-file existence."
Expand Down Expand Up @@ -692,11 +694,13 @@ This uses function `locate-dominating-file' to look up directory tree."
(defmacro eask--with-hooks (&rest body)
"Execute BODY with before/after hooks."
(declare (indent 0) (debug t))
`(progn
`(let* ((command (eask-command))
(before (concat "eask-before-" command "-hook"))
(after (concat "eask-after-" command "-hook")))
(run-hooks 'eask-before-command-hook)
(run-hooks (intern (concat "eask-before-" (eask-command) "-hook")))
(run-hooks (intern before))
,@body
(run-hooks (intern (concat "eask-after-" (eask-command) "-hook")))
(run-hooks (intern after))
(run-hooks 'eask-after-command-hook)))

(defmacro eask--setup-home (dir &rest body)
Expand Down

0 comments on commit 095f51c

Please sign in to comment.