Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Don't pollute outer programs #239

Merged
merged 2 commits into from
Mar 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
* feat: Rename command `check-eask` to `analyze` (#230)
* feat(fmt): Add formatters (#232)
* feat(test): Add built-in `ecukes` test command (#236)
* fix: Don't pollute outer programs (#239)

## 0.9.x
> Released Nov 17, 2023
Expand Down
4 changes: 2 additions & 2 deletions cmds/core/emacs.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ exports.builder = async (yargs) => {
};

exports.handler = async (argv) => {
let _path = UTIL.el_script('core/emacs');
let s_path = UTIL.el_script('core/emacs');

let default_cmd = [EASK_EMACS, '-Q', '-l', _path];
let default_cmd = [EASK_EMACS, '-Q', '-l', s_path];
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename this due to some languages use _ to indicate the private variable.

let rest = process.argv.slice(3);
let cmd = default_cmd.concat(rest);

Expand Down
16 changes: 13 additions & 3 deletions docs/content/Development-API/_index.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,20 +129,30 @@ then,
(message "%s" (eask-command)) ; init
```

## 🔍 Function: eask-command-p (`commands`)

Return t if COMMANDS is the current command.

## 🔍 Function: eask-special-p ()

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
This allows 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.

## 🔍 Function: eask-execution-p ()

Return `t` if the command is the execution command.

This is added because we don't want to pollute `error` and `warn` functions.

## 🔍 Function: eask-checker-p ()

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.
Without this flag, the process will be terminated once the error is occurred.
This flag allows you to run through operations without reporting errors.

## 🔍 Function: eask-script (`script`)

Expand Down
10 changes: 10 additions & 0 deletions docs/content/Development-API/_index.zh-tw.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,23 @@ $ eask init
(message "%s" (eask-command)) ; init
```

## 🔍 函式: eask-command-p (`commands`)

如果 COMMANDS 是目前命令,則傳回 `t`。

## 🔍 函式: eask-special-p ()

如果在沒有 Eask 文件存在的情況下可以運行的命令,則返回 `t`。

這允許一些命令仍然可以在不定義用戶的情況下執行目錄。 當您想在沒有的情況下進行正常操作時,這會很方便
觸摸用戶目錄。

## 🔍 函式: eask-execution-p ()

如果命令是執行命令,則傳回 `t`。

加入這項功能是因為我們不想污染 `error` 和 `warn` 函數。

## 🔍 函式: eask-checker-p ()

如果運行 Eask 作為檢查器,則返回 `t`。
Expand Down
35 changes: 25 additions & 10 deletions lisp/_prepare.el
Original file line number Diff line number Diff line change
Expand Up @@ -152,20 +152,34 @@ will return `lint/checkdoc' with a dash between two subcommands."
(list script-file))
"/"))))

(defun eask-command-p (commands)
"Return t if COMMANDS is the current command."
(member (eask-command) (eask-listify commands)))

(defun eask-special-p ()
"Return t if the command that can be run without Eask-file existence.

These commands will first respect the current workspace. If the current
workspace has no valid Eask-file; it will load global workspace instead."
(member (eask-command) '("init" "init/source" "init/cask" "init/eldev" "init/keg"
"create/package" "create/elpa"
"bump" "cat" "keywords" "repl"
"generate/ignore" "generate/license"
"test/melpazoid")))
(eask-command-p '("init" "init/source" "init/cask" "init/eldev" "init/keg"
"create/package" "create/elpa"
"bump" "cat" "keywords" "repl"
"generate/ignore" "generate/license"
"test/melpazoid")))

(defun eask-execution-p ()
"Return t if the command is the execution command.

This is added because we don't want to pollute `error' and `warn' functions."
(eask-command-p '("load" "exec" "emacs" "eval" "repl"
"run/script" "run/command")))

(defun eask-checker-p ()
"Return t if running Eask as the checker."
(member (eask-command) '("analyze")))
"Return t if running Eask as the checker.

Without this flag, the process will be terminated once the error is occurred.
This flag allows you to run through operations without reporting errors."
(eask-command-p '("analyze")))

(defun eask-script (script)
"Return full SCRIPT filename."
Expand Down Expand Up @@ -1726,8 +1740,6 @@ Arguments FNC and ARGS are used for advice `:around'."
(eask--trigger-error))
(when debug-on-error (apply fnc args)))

(advice-add 'error :around #'eask--error)

(defun eask--warn (fnc &rest args)
"On warn.

Expand All @@ -1738,7 +1750,10 @@ Arguments FNC and ARGS are used for advice `:around'."
(run-hook-with-args 'eask-on-warning-hook 'warn msg))
(eask--silent (apply fnc args)))

(advice-add 'warn :around #'eask--warn)
;; Don't pollute outer exection.
(unless (eask-execution-p)
(advice-add 'error :around #'eask--error)
(advice-add 'warn :around #'eask--warn))

;;
;;; Log
Expand Down
Loading