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(special): Make better use for special commands #206

Merged
merged 5 commits into from
Nov 26, 2023
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 @@ -9,6 +9,7 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
> Released N/A

* fix: Unsilent in Eask-file by default (40d82becaf20f0851e5fc37aa17c5f6871c163a3)
* Make better use for `special` commands (#206)

## 0.9.x
> Released Nov 17, 2023
Expand Down
93 changes: 61 additions & 32 deletions lisp/_prepare.el
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@
package-archives nil ; Leave it to custom use
package-archive-priorities nil)

(defvar eask-dot-emacs-file nil
"Variable hold .emacs file location.")

(defun eask--load--adv (fnc &rest args)
"Prevent `_prepare.el' loading twice.

Expand Down Expand Up @@ -136,7 +139,10 @@ will return `lint/checkdoc' with a dash between two subcommands."
"/"))))

(defun eask-special-p ()
"Return t if the command that can be run without Eask-file existence."
"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/cask" "init/eldev" "init/keg"
"init/source"
"bump" "cat" "keywords"
Expand Down Expand Up @@ -907,14 +913,7 @@ If the optional argument INDEX is non-nil, return the element."
"Execute BODY with workspace setup."
(declare (indent 0) (debug t))
`(eask--batch-mode
(let (;; XXX: this will make command `info', `files' work as expected;
;; but the relative paths file spec will be lost...
;;
;; So commands like `load' would NOT work!
(default-directory (cond ((eask-global-p) eask-homedir)
((eask-config-p) user-emacs-directory)
(t default-directory)))
(alist))
(let ((alist))
(dolist (cmd eask--command-list)
(push (cons cmd (lambda (&rest _))) alist))
(setq command-switch-alist (append command-switch-alist alist))
Expand Down Expand Up @@ -1049,10 +1048,24 @@ This uses function `locate-dominating-file' to look up directory tree."
`(let* ((user-emacs-directory (expand-file-name (concat ".eask/" emacs-version "/") ,dir))
(package-user-dir (expand-file-name "elpa" user-emacs-directory))
(early-init-file (locate-user-emacs-file "early-init.el"))
(eask-dot-emacs-file (locate-user-emacs-file ".emacs"))
(user-init-file (locate-user-emacs-file "init.el"))
(custom-file (locate-user-emacs-file "custom.el")))
,@body))

(defun eask--load-config ()
"Load configuration if valid."
(let ((inhibit-config (eask-quick-p)))
(eask-with-progress
(ansi-green "Loading configuration... ")
(eask-with-verbosity 'all
(unless inhibit-config
(when (version<= "27" emacs-version)
(load early-init-file t))
(load eask-dot-emacs-file t)
(load user-init-file t)))
(ansi-green (if inhibit-config "skipped ✗" "done ✓")))))

(defmacro eask-start (&rest body)
"Execute BODY with workspace setup."
(declare (indent 0) (debug t))
Expand All @@ -1062,44 +1075,59 @@ This uses function `locate-dominating-file' to look up directory tree."
(eask--setup-env
(eask--handle-global-options)
(cond
((or (eask-global-p) (eask-special-p)) ; Commands without Eask-file needed!
((eask-config-p)
(let ((early-init-file (locate-user-emacs-file "early-init.el"))
(eask-dot-emacs-file (locate-user-emacs-file "../.emacs"))
(user-init-file (locate-user-emacs-file "init.el")))
;; We accept Eask-file in `config' scope, but it shouldn't be used
;; for the sandbox.
(eask-with-verbosity 'debug
(if (eask-file-try-load user-emacs-directory)
(eask-msg "✓ Loading config Eask file in %s... done!" eask-file)
(eask-msg "✗ Loading config Eask file... missing!"))
(eask-msg ""))
(package-activate-all)
(eask--load-config)
(eask--with-hooks ,@body)))
((eask-global-p)
(eask--setup-home (concat eask-homedir "../") ; `/home/user/', escape `.eask'
(let ((eask--first-init-p (not (file-directory-p user-emacs-directory))))
;; We accept Eask-file in `global' scope, but it shouldn't be used
;; for the sandbox.
(eask-with-verbosity 'debug
(eask-ignore-errors ; Again, without Eask-file needed!
(if (eask-file-try-load "./")
(eask-ignore-errors ; Eask-file is optional!
(if (eask-file-try-load eask-homedir)
(eask-msg "✓ Loading global Eask file in %s... done!" eask-file)
(eask-msg "✗ Loading global Eask file... missing!")))
(eask-msg ""))
(package-activate-all)
(ignore-errors (make-directory package-user-dir t))
(eask-with-verbosity 'debug (eask--load-config))
(eask--with-hooks ,@body))))
((eask-special-p) ; Commands without Eask-file needed!
;; First, try to find a valid Eask-file!
(eask-file-try-load default-directory)
;; Then setup the user directory according to the Eask-file!
(eask--setup-home (or eask-file-root
(concat eask-homedir "../"))
(let ((eask--first-init-p (not (file-directory-p user-emacs-directory)))
(scope (if eask-file-root "" "global ")))
(eask-with-verbosity 'debug
(eask-ignore-errors ; Again, without Eask-file needed!
(if (or eask-file-root
(eask-file-try-load eask-homedir))
(eask-msg "✓ Loading %sEask file in %s... done!" scope eask-file)
(eask-msg "✗ Loading %sEask file... missing!" scope)))
(eask-msg ""))
(package-activate-all)
(ignore-errors (make-directory package-user-dir t))
(eask-with-verbosity 'debug (eask--load-config))
(eask--with-hooks ,@body))))
((eask-config-p)
(let ((inhibit-config (eask-quick-p)))
;; We accept Eask-file in `config' scope, but it shouldn't be used
;; for the sandbox.
(eask-with-verbosity 'debug
(if (eask-file-try-load "./")
(eask-msg "✓ Loading config Eask file in %s... done!" eask-file)
(eask-msg "✗ Loading config Eask file... missing!"))
(eask-msg ""))
(package-activate-all)
(eask-with-progress
(ansi-green "Loading your configuration... ")
(eask-with-verbosity 'all
(unless inhibit-config
(load (locate-user-emacs-file "early-init.el") t)
(load (locate-user-emacs-file "../.emacs") t)
(load (locate-user-emacs-file "init.el") t)))
(ansi-green (if inhibit-config "skipped ✗" "done ✓")))
(eask--with-hooks ,@body)))
(t
(eask--setup-home nil ; `nil' is the `default-directory'
(let ((eask--first-init-p (not (file-directory-p user-emacs-directory))))
(eask-with-verbosity 'debug
(if (eask-file-try-load "./")
(if (eask-file-try-load default-directory)
(eask-msg "✓ Loading Eask file in %s... done!" eask-file)
(eask-msg "✗ Loading Eask file... missing!"))
(eask-msg ""))
Expand All @@ -1108,6 +1136,7 @@ This uses function `locate-dominating-file' to look up directory tree."
(package-activate-all)
(ignore-errors (make-directory package-user-dir t))
(eask--silent (eask-setup-paths))
(eask-with-verbosity 'debug (eask--load-config))
(eask--with-hooks ,@body))))))))))

;;
Expand Down
90 changes: 67 additions & 23 deletions lisp/core/status.el
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
;;
;;; Core

(defvar eask--status-info-count 0
"Count of the stratus info.")

(defun eask--environment-name ()
"Get the working environment name."
(cond ((eask-global-p) "global (~/)")
Expand All @@ -35,38 +38,79 @@
(eask-println (ansi-underscore title))
(eask-println ""))

(defun eask--print-info (pair)
"Print environment info PAIR."
(let ((title (eask-2str (car pair)))
(content (eask-2str (cdr pair))))
(eask-println " %-22s %s" title (ansi-bright-black content))))
(defun eask--print-info (fmt pair)
"Print environment info with FMT and PAIR."
(let ((title (eask-2str (nth 0 pair)))
(content (eask-2str (nth 1 pair)))
(note (eask-2str (or (nth 2 pair) ""))))
(eask-println fmt
title
(ansi-bright-black content)
note)))

(defun eask--list-max-length (lst index)
"Return the LST max length by its INDEX."
(let ((max-len 0)
(max-current))
(dolist (data lst)
(setq max-current (eask-2str (nth index data))
max-current (pcase index
(1 (ansi-bright-black max-current))
(_ max-current))
max-len (max (length max-current) max-len)))
max-len))

(defun eask--print-infos (lst)
"Print environment info LST."
(let* ((len-0 (eask-2str (eask--list-max-length lst 0)))
(len-1 (eask-2str (+ (eask--list-max-length lst 1) 2)))
(fmt (concat " %-21s %-" len-1 "s %s")))
(dolist (pair lst)
(when pair
(eask--print-info fmt pair)
(cl-incf eask--status-info-count)))))

(defun eask--status-file-dir (path)
"Return file directory status from PATH."
(unless (file-exists-p path)
(ansi-red "(missing)")))

(eask-start
(eask-println "In the %s environment" (eask--environment-name))
(eask-println "Your emacs home is point to %s" user-emacs-directory)
(eask-println "Your emacs home is point to %s" (expand-file-name user-emacs-directory))

(eask--print-title "System:")
(eask--print-info `("Emacs version" . ,emacs-version))
(eask--print-info `("Invocation" . ,invocation-directory))
(eask--print-info `("Build No." . ,emacs-build-number))
(eask--print-info `("System configuration" . ,system-configuration))
(when-let ((emacs-build-time)
(time (format-time-string "%Y-%m-%d" emacs-build-time)))
(eask--print-info `("Build time" . ,time)))
(eask--print-info `("System type" . ,system-type))
(eask--print-infos
`(("Emacs version" ,emacs-version)
("Invocation" ,invocation-directory)
("Build No." ,emacs-build-number)
("System configuration" ,system-configuration)
,(when-let ((emacs-build-time)
(time (format-time-string "%Y-%m-%d" emacs-build-time)))
`("Build time" ,time))
("System type" ,system-type)))

(eask--print-title "Environment:")
(eask--print-info `("Emacs directory" . ,user-emacs-directory))
(eask--print-info `("ELPA directory" . ,package-user-dir))
(eask--print-info `("early-init.el" . ,early-init-file))
(eask--print-info `("init.el" . ,user-init-file))
(eask--print-info `("custom.el" . ,custom-file))
(eask--print-infos
`(("Emacs directory" ,(expand-file-name user-emacs-directory)
,(eask--status-file-dir user-emacs-directory))
("ELPA directory" ,(expand-file-name package-user-dir)
,(eask--status-file-dir package-user-dir))
("early-init.el" ,(expand-file-name early-init-file)
,(eask--status-file-dir early-init-file))
(".emacs" ,(expand-file-name eask-dot-emacs-file)
,(eask--status-file-dir eask-dot-emacs-file))
("init.el" ,(expand-file-name user-init-file)
,(eask--status-file-dir user-init-file))
("custom.el" ,(if custom-file (expand-file-name custom-file)
"nil")
,(when custom-file (eask--status-file-dir custom-file)))))

(eask--print-title "Eask-file:")
(eask--print-info `("Eask file" . ,(or eask-file "missing")))
(eask--print-info `("Eask-file Count" . ,(length (eask--find-files default-directory))))
(eask--print-infos
`(("Eask file" ,(or eask-file "missing"))
("Eask-file Count" ,(length (eask--find-files default-directory)))))

;; XXX: Please increment the number everytime a new information is added!
(eask-info "(Total of %s states listed)" (+ 6 5 2)))
(eask-info "(Total of %s states listed)" eask--status-info-count))

;;; core/status.el ends here
Loading