Skip to content

Commit 3d91ef3

Browse files
authored
fix(special): Make better use for special commands (#206)
* fix(special): Make better use for special commands * changelog * Add Eask load config * fix: Early init only exists after 27 * define dot emacs file
1 parent 358ffba commit 3d91ef3

File tree

3 files changed

+129
-55
lines changed

3 files changed

+129
-55
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
99
> Released N/A
1010
1111
* fix: Unsilent in Eask-file by default (40d82becaf20f0851e5fc37aa17c5f6871c163a3)
12+
* Make better use for `special` commands (#206)
1213

1314
## 0.9.x
1415
> Released Nov 17, 2023

lisp/_prepare.el

Lines changed: 61 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@
6868
package-archives nil ; Leave it to custom use
6969
package-archive-priorities nil)
7070

71+
(defvar eask-dot-emacs-file nil
72+
"Variable hold .emacs file location.")
73+
7174
(defun eask--load--adv (fnc &rest args)
7275
"Prevent `_prepare.el' loading twice.
7376
@@ -136,7 +139,10 @@ will return `lint/checkdoc' with a dash between two subcommands."
136139
"/"))))
137140

138141
(defun eask-special-p ()
139-
"Return t if the command that can be run without Eask-file existence."
142+
"Return t if the command that can be run without Eask-file existence.
143+
144+
These commands will first respect the current workspace. If the current
145+
workspace has no valid Eask-file; it will load global workspace instead."
140146
(member (eask-command) '("init/cask" "init/eldev" "init/keg"
141147
"init/source"
142148
"bump" "cat" "keywords"
@@ -907,14 +913,7 @@ If the optional argument INDEX is non-nil, return the element."
907913
"Execute BODY with workspace setup."
908914
(declare (indent 0) (debug t))
909915
`(eask--batch-mode
910-
(let (;; XXX: this will make command `info', `files' work as expected;
911-
;; but the relative paths file spec will be lost...
912-
;;
913-
;; So commands like `load' would NOT work!
914-
(default-directory (cond ((eask-global-p) eask-homedir)
915-
((eask-config-p) user-emacs-directory)
916-
(t default-directory)))
917-
(alist))
916+
(let ((alist))
918917
(dolist (cmd eask--command-list)
919918
(push (cons cmd (lambda (&rest _))) alist))
920919
(setq command-switch-alist (append command-switch-alist alist))
@@ -1049,10 +1048,24 @@ This uses function `locate-dominating-file' to look up directory tree."
10491048
`(let* ((user-emacs-directory (expand-file-name (concat ".eask/" emacs-version "/") ,dir))
10501049
(package-user-dir (expand-file-name "elpa" user-emacs-directory))
10511050
(early-init-file (locate-user-emacs-file "early-init.el"))
1051+
(eask-dot-emacs-file (locate-user-emacs-file ".emacs"))
10521052
(user-init-file (locate-user-emacs-file "init.el"))
10531053
(custom-file (locate-user-emacs-file "custom.el")))
10541054
,@body))
10551055

1056+
(defun eask--load-config ()
1057+
"Load configuration if valid."
1058+
(let ((inhibit-config (eask-quick-p)))
1059+
(eask-with-progress
1060+
(ansi-green "Loading configuration... ")
1061+
(eask-with-verbosity 'all
1062+
(unless inhibit-config
1063+
(when (version<= "27" emacs-version)
1064+
(load early-init-file t))
1065+
(load eask-dot-emacs-file t)
1066+
(load user-init-file t)))
1067+
(ansi-green (if inhibit-config "skipped ✗" "done ✓")))))
1068+
10561069
(defmacro eask-start (&rest body)
10571070
"Execute BODY with workspace setup."
10581071
(declare (indent 0) (debug t))
@@ -1062,44 +1075,59 @@ This uses function `locate-dominating-file' to look up directory tree."
10621075
(eask--setup-env
10631076
(eask--handle-global-options)
10641077
(cond
1065-
((or (eask-global-p) (eask-special-p)) ; Commands without Eask-file needed!
1078+
((eask-config-p)
1079+
(let ((early-init-file (locate-user-emacs-file "early-init.el"))
1080+
(eask-dot-emacs-file (locate-user-emacs-file "../.emacs"))
1081+
(user-init-file (locate-user-emacs-file "init.el")))
1082+
;; We accept Eask-file in `config' scope, but it shouldn't be used
1083+
;; for the sandbox.
1084+
(eask-with-verbosity 'debug
1085+
(if (eask-file-try-load user-emacs-directory)
1086+
(eask-msg "✓ Loading config Eask file in %s... done!" eask-file)
1087+
(eask-msg "✗ Loading config Eask file... missing!"))
1088+
(eask-msg ""))
1089+
(package-activate-all)
1090+
(eask--load-config)
1091+
(eask--with-hooks ,@body)))
1092+
((eask-global-p)
10661093
(eask--setup-home (concat eask-homedir "../") ; `/home/user/', escape `.eask'
10671094
(let ((eask--first-init-p (not (file-directory-p user-emacs-directory))))
10681095
;; We accept Eask-file in `global' scope, but it shouldn't be used
10691096
;; for the sandbox.
10701097
(eask-with-verbosity 'debug
1071-
(eask-ignore-errors ; Again, without Eask-file needed!
1072-
(if (eask-file-try-load "./")
1098+
(eask-ignore-errors ; Eask-file is optional!
1099+
(if (eask-file-try-load eask-homedir)
10731100
(eask-msg "✓ Loading global Eask file in %s... done!" eask-file)
10741101
(eask-msg "✗ Loading global Eask file... missing!")))
10751102
(eask-msg ""))
10761103
(package-activate-all)
10771104
(ignore-errors (make-directory package-user-dir t))
1105+
(eask-with-verbosity 'debug (eask--load-config))
1106+
(eask--with-hooks ,@body))))
1107+
((eask-special-p) ; Commands without Eask-file needed!
1108+
;; First, try to find a valid Eask-file!
1109+
(eask-file-try-load default-directory)
1110+
;; Then setup the user directory according to the Eask-file!
1111+
(eask--setup-home (or eask-file-root
1112+
(concat eask-homedir "../"))
1113+
(let ((eask--first-init-p (not (file-directory-p user-emacs-directory)))
1114+
(scope (if eask-file-root "" "global ")))
1115+
(eask-with-verbosity 'debug
1116+
(eask-ignore-errors ; Again, without Eask-file needed!
1117+
(if (or eask-file-root
1118+
(eask-file-try-load eask-homedir))
1119+
(eask-msg "✓ Loading %sEask file in %s... done!" scope eask-file)
1120+
(eask-msg "✗ Loading %sEask file... missing!" scope)))
1121+
(eask-msg ""))
1122+
(package-activate-all)
1123+
(ignore-errors (make-directory package-user-dir t))
1124+
(eask-with-verbosity 'debug (eask--load-config))
10781125
(eask--with-hooks ,@body))))
1079-
((eask-config-p)
1080-
(let ((inhibit-config (eask-quick-p)))
1081-
;; We accept Eask-file in `config' scope, but it shouldn't be used
1082-
;; for the sandbox.
1083-
(eask-with-verbosity 'debug
1084-
(if (eask-file-try-load "./")
1085-
(eask-msg "✓ Loading config Eask file in %s... done!" eask-file)
1086-
(eask-msg "✗ Loading config Eask file... missing!"))
1087-
(eask-msg ""))
1088-
(package-activate-all)
1089-
(eask-with-progress
1090-
(ansi-green "Loading your configuration... ")
1091-
(eask-with-verbosity 'all
1092-
(unless inhibit-config
1093-
(load (locate-user-emacs-file "early-init.el") t)
1094-
(load (locate-user-emacs-file "../.emacs") t)
1095-
(load (locate-user-emacs-file "init.el") t)))
1096-
(ansi-green (if inhibit-config "skipped ✗" "done ✓")))
1097-
(eask--with-hooks ,@body)))
10981126
(t
10991127
(eask--setup-home nil ; `nil' is the `default-directory'
11001128
(let ((eask--first-init-p (not (file-directory-p user-emacs-directory))))
11011129
(eask-with-verbosity 'debug
1102-
(if (eask-file-try-load "./")
1130+
(if (eask-file-try-load default-directory)
11031131
(eask-msg "✓ Loading Eask file in %s... done!" eask-file)
11041132
(eask-msg "✗ Loading Eask file... missing!"))
11051133
(eask-msg ""))
@@ -1108,6 +1136,7 @@ This uses function `locate-dominating-file' to look up directory tree."
11081136
(package-activate-all)
11091137
(ignore-errors (make-directory package-user-dir t))
11101138
(eask--silent (eask-setup-paths))
1139+
(eask-with-verbosity 'debug (eask--load-config))
11111140
(eask--with-hooks ,@body))))))))))
11121141

11131142
;;

lisp/core/status.el

Lines changed: 67 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
;;
2424
;;; Core
2525

26+
(defvar eask--status-info-count 0
27+
"Count of the stratus info.")
28+
2629
(defun eask--environment-name ()
2730
"Get the working environment name."
2831
(cond ((eask-global-p) "global (~/)")
@@ -35,38 +38,79 @@
3538
(eask-println (ansi-underscore title))
3639
(eask-println ""))
3740

38-
(defun eask--print-info (pair)
39-
"Print environment info PAIR."
40-
(let ((title (eask-2str (car pair)))
41-
(content (eask-2str (cdr pair))))
42-
(eask-println " %-22s %s" title (ansi-bright-black content))))
41+
(defun eask--print-info (fmt pair)
42+
"Print environment info with FMT and PAIR."
43+
(let ((title (eask-2str (nth 0 pair)))
44+
(content (eask-2str (nth 1 pair)))
45+
(note (eask-2str (or (nth 2 pair) ""))))
46+
(eask-println fmt
47+
title
48+
(ansi-bright-black content)
49+
note)))
50+
51+
(defun eask--list-max-length (lst index)
52+
"Return the LST max length by its INDEX."
53+
(let ((max-len 0)
54+
(max-current))
55+
(dolist (data lst)
56+
(setq max-current (eask-2str (nth index data))
57+
max-current (pcase index
58+
(1 (ansi-bright-black max-current))
59+
(_ max-current))
60+
max-len (max (length max-current) max-len)))
61+
max-len))
62+
63+
(defun eask--print-infos (lst)
64+
"Print environment info LST."
65+
(let* ((len-0 (eask-2str (eask--list-max-length lst 0)))
66+
(len-1 (eask-2str (+ (eask--list-max-length lst 1) 2)))
67+
(fmt (concat " %-21s %-" len-1 "s %s")))
68+
(dolist (pair lst)
69+
(when pair
70+
(eask--print-info fmt pair)
71+
(cl-incf eask--status-info-count)))))
72+
73+
(defun eask--status-file-dir (path)
74+
"Return file directory status from PATH."
75+
(unless (file-exists-p path)
76+
(ansi-red "(missing)")))
4377

4478
(eask-start
4579
(eask-println "In the %s environment" (eask--environment-name))
46-
(eask-println "Your emacs home is point to %s" user-emacs-directory)
80+
(eask-println "Your emacs home is point to %s" (expand-file-name user-emacs-directory))
4781

4882
(eask--print-title "System:")
49-
(eask--print-info `("Emacs version" . ,emacs-version))
50-
(eask--print-info `("Invocation" . ,invocation-directory))
51-
(eask--print-info `("Build No." . ,emacs-build-number))
52-
(eask--print-info `("System configuration" . ,system-configuration))
53-
(when-let ((emacs-build-time)
54-
(time (format-time-string "%Y-%m-%d" emacs-build-time)))
55-
(eask--print-info `("Build time" . ,time)))
56-
(eask--print-info `("System type" . ,system-type))
83+
(eask--print-infos
84+
`(("Emacs version" ,emacs-version)
85+
("Invocation" ,invocation-directory)
86+
("Build No." ,emacs-build-number)
87+
("System configuration" ,system-configuration)
88+
,(when-let ((emacs-build-time)
89+
(time (format-time-string "%Y-%m-%d" emacs-build-time)))
90+
`("Build time" ,time))
91+
("System type" ,system-type)))
5792

5893
(eask--print-title "Environment:")
59-
(eask--print-info `("Emacs directory" . ,user-emacs-directory))
60-
(eask--print-info `("ELPA directory" . ,package-user-dir))
61-
(eask--print-info `("early-init.el" . ,early-init-file))
62-
(eask--print-info `("init.el" . ,user-init-file))
63-
(eask--print-info `("custom.el" . ,custom-file))
94+
(eask--print-infos
95+
`(("Emacs directory" ,(expand-file-name user-emacs-directory)
96+
,(eask--status-file-dir user-emacs-directory))
97+
("ELPA directory" ,(expand-file-name package-user-dir)
98+
,(eask--status-file-dir package-user-dir))
99+
("early-init.el" ,(expand-file-name early-init-file)
100+
,(eask--status-file-dir early-init-file))
101+
(".emacs" ,(expand-file-name eask-dot-emacs-file)
102+
,(eask--status-file-dir eask-dot-emacs-file))
103+
("init.el" ,(expand-file-name user-init-file)
104+
,(eask--status-file-dir user-init-file))
105+
("custom.el" ,(if custom-file (expand-file-name custom-file)
106+
"nil")
107+
,(when custom-file (eask--status-file-dir custom-file)))))
64108

65109
(eask--print-title "Eask-file:")
66-
(eask--print-info `("Eask file" . ,(or eask-file "missing")))
67-
(eask--print-info `("Eask-file Count" . ,(length (eask--find-files default-directory))))
110+
(eask--print-infos
111+
`(("Eask file" ,(or eask-file "missing"))
112+
("Eask-file Count" ,(length (eask--find-files default-directory)))))
68113

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

72116
;;; core/status.el ends here

0 commit comments

Comments
 (0)