Skip to content

Commit

Permalink
fix: Don't pollute outer programs
Browse files Browse the repository at this point in the history
  • Loading branch information
jcs090218 committed Mar 23, 2024
1 parent 5334a00 commit 7dc66a4
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 15 deletions.
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];
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

0 comments on commit 7dc66a4

Please sign in to comment.