From 7ce0db6401ced1729e141d3d66f569764aa9d559 Mon Sep 17 00:00:00 2001 From: Jen-Chieh Shen Date: Sat, 23 Mar 2024 15:05:40 -0700 Subject: [PATCH] fix: Don't pollute outer programs (#239) * fix: Don't pollute outer programs * changelog --- CHANGELOG.md | 1 + cmds/core/emacs.js | 4 +-- docs/content/Development-API/_index.en.md | 16 +++++++-- docs/content/Development-API/_index.zh-tw.md | 10 ++++++ lisp/_prepare.el | 35 ++++++++++++++------ 5 files changed, 51 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ba4b1f2d..0a9d3654 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/cmds/core/emacs.js b/cmds/core/emacs.js index 465bc1fb..75e85e25 100644 --- a/cmds/core/emacs.js +++ b/cmds/core/emacs.js @@ -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); diff --git a/docs/content/Development-API/_index.en.md b/docs/content/Development-API/_index.en.md index 637943f4..31d4bc95 100644 --- a/docs/content/Development-API/_index.en.md +++ b/docs/content/Development-API/_index.en.md @@ -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`) diff --git a/docs/content/Development-API/_index.zh-tw.md b/docs/content/Development-API/_index.zh-tw.md index 2c5dea21..d89b1923 100644 --- a/docs/content/Development-API/_index.zh-tw.md +++ b/docs/content/Development-API/_index.zh-tw.md @@ -128,6 +128,10 @@ $ eask init (message "%s" (eask-command)) ; init ``` +## 🔍 函式: eask-command-p (`commands`) + +如果 COMMANDS 是目前命令,則傳回 `t`。 + ## 🔍 函式: eask-special-p () 如果在沒有 Eask 文件存在的情況下可以運行的命令,則返回 `t`。 @@ -135,6 +139,12 @@ $ eask init 這允許一些命令仍然可以在不定義用戶的情況下執行目錄。 當您想在沒有的情況下進行正常操作時,這會很方便 觸摸用戶目錄。 +## 🔍 函式: eask-execution-p () + +如果命令是執行命令,則傳回 `t`。 + +加入這項功能是因為我們不想污染 `error` 和 `warn` 函數。 + ## 🔍 函式: eask-checker-p () 如果運行 Eask 作為檢查器,則返回 `t`。 diff --git a/lisp/_prepare.el b/lisp/_prepare.el index aa129d68..57b5c82c 100644 --- a/lisp/_prepare.el +++ b/lisp/_prepare.el @@ -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." @@ -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. @@ -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