Commit graph

266 commits

Author SHA1 Message Date
Henrik Lissner
a320c8183a
revert: fix(cli): set LC_ALL to force english output
LC_ALL must be set to a locale that exists on the current system, and
there is no locale I can safely expect all systems to have (see #7361).
Fortunately, c8070f1 seems to have addressed the underlying issue, so
this fix can be reverted.

Fix: #7361
Revert: #7331
Revert: 150ccd630565
Ref: c8070f11a448
2024-05-21 17:15:48 +02:00
Henrik Lissner
a0da9225ed
fix(cli): set LC_ALL to force english output
Close: #7331
Co-authored-by: xz-dev <xz-dev@users.noreply.github.com>
2024-05-21 17:15:46 +02:00
Henrik Lissner
0ecf69afaf
fix(cli): increment __DOOMSTEP in elisp instead
Some shells (like ksh on SDF) may complain about $((...)) arithmetic
expansion syntax. Rather than wrestle with old shells, I'll offload this
trivial operation to elisp instead.

Close: #6970
2023-03-20 20:42:36 -04:00
Henrik Lissner
c1c966c811
docs: assume ~/.config/emacs by default
From now on, our documentation will assume your Emacs config lives in
~/.config/emacs, by default, rather than ~/.emacs.d. Support for the
latter is not going away, it will simply be mentioned less in the
literature, as all supported versions of Emacs going forward (and future
versions of Doom) will support (and prefer) XDG conventions.

The user manual will be updated separately.

Close: #6965
Co-authored-by: gagbo <gagbo@users.noreply.github.com>
2023-02-25 20:47:28 -05:00
Libin Dang
9f22a0a2a5 fix(cli): split tput call into separate calls
Sync definition of __DOOMGEOM in bin/doomscript with corresponding
variable of bin/doom.

* bin/doomscript (__DOOMGEOM): split tput call into two separate calls

Ref: beef0aef02
2022-10-07 19:48:23 +02:00
Henrik Lissner
5bfe0ba53f
fix(cli): load $DOOMRC relative to $PWD
Rather than doing so relative to bin/doom.
2022-09-26 12:31:27 +02:00
Henrik Lissner
f9201eb218
refactor: introduce doom-context
Introduces a system to announce what execution contexts are active, so I
can react appropriately, emit more helpful logs/warnings in the case of
issues, and throw more meaningful errors.

* bin/doom: load module CLIs in the 'modules' context.
* lisp/cli/doctor.el: load package files in 'packages' context.
* lisp/doom-cli.el:
  - (doom-before-init-hook, doom-after-init-hook): trigger hooks at the
    correct time. This may increase startup load time, as the benchmark
    now times more of the startup process.
  - (doom-cli-execute, doom-cli-context-execute,
    doom-cli-context-restore, doom-cli-context-parse,
    doom-cli--output-benchmark-h, doom-cli-call, doom-cli--restart,
    doom-cli-load, run!): remove redundant context prefix in debug logs,
    it's now redundant with doom-context, which doom-log now prefixes
    them with.
* lisp/doom-lib.el (doom-log): prefix doom-context to doom-log output,
  unless it starts with :.
* lisp/doom-packages.el (package!, doom-packages--read): throw error if
  not used in a packages.el file or in the context of our package
  manager.
* lisp/doom-profiles.el (doom-profile--generate-init-vars,
  doom-profile--generate-load-modules): use modules doom-context instead
  of doom-init-time to detect startup.
* lisp/doom-start.el (doom-load-packages-incrementally-h): move function
  closer to end of doom-after-init-hook.
* lisp/doom.el:
  - (doom-before-init-hook, doom--set-initial-values-h,
    doom--begin-init-h): rename doom--set-initial-values-h to
    doom--begin-init-h and ensure it runs as late in
    doom-before-init-hook as possible, as that is the point where Doom's
    "initialization" formally begins.
  - (doom-after-init-hook): don't trigger at the end of command-line-1
    in non-interactive sessions. This will be triggered manually in
    doom-cli.el's run!.
* lisp/lib/config.el (doom/reload, doom/reload-autoloads,
  doom/reload-env): use 'reload' context for reload commands.
* modules/lang/emacs-lisp/autoload.el (+emacs-lisp-eval): use 'eval'
  context.
* modules/lang/org/config.el: remove doom-reloading-p; check for
  'reload' doom context instead.
2022-09-24 22:09:05 +02:00
Henrik Lissner
5a5195b84d
fix: add :depth field to modules
This introduces a depth field for modules so that they may dictate their
load order explicitly, it also treats depths <= -100 or >= 100 as
special depths, which will be loaded early, before their respective
doom-{before,after}-module-{init,config}-hook. This permits psuedo
modules like :core and :user modules to be treated as normal modules
without too many special cases.

This also fixes a module load order issue on Emacs 29 (#6813), caused by
emacs-mirror/emacs@4311bd0bd7, which changed the return value order of
hash-table-{keys,values} causing modules to be loaded in reverse order;
resulting in the loss of evil keybinds, among other things.

Other notable changes:
- Changes the data structure for module data caches from a list to a
  vector. Uses less memory and permits faster lookups. Also adds two
  depth fields to the front of it.
- Changes the signature of doom-module-list and doom-package-list.
- Renames doom--read-packages -> doom-packages--read for consistency
  with naming convention.
- Add doom-module-depth function.
- Adds a temporary doom-core-dir/init.el file, which is responsible for
  loading doom-*.el.

Fix: #6813
Ref: emacs-mirror/emacs@4311bd0bd7
2022-09-24 18:46:21 +02:00
Henrik Lissner
31be70b565
tweak(cli): add --debug-init if $DEBUG=1
For more debug output, and sooner.
2022-09-20 13:34:58 +02:00
Henrik Lissner
f99cf0ccc8
feat(cli): introduce DOOMPROFILELOAD{FILE,PATH} envvars
- Adds $DOOMPROFILELOADFILE: Controls where to read and write the
  profile loader. Changing this may be helpful for users on nix/guix,
  who have deployed Doom to a read-only location. This sets
  `doom-profile-load-file`.
- Changed profile load file's default location (used to be
  $EMACSDIR/profiles/init.el, is now $EMACSDIR/profiles/load.el). The
  gitignore was updated to reflect this.
- Adds $DOOMPROFILELOADPATH: A colon-delimited list of profile config
  files and directories (semi-colon on Windows) which dictate what Doom
  reads in order to discover your profiles. Config files are required to
  have an *.el extension. This sets `doom-profile-load-path`.
- Changes the nomenclature around this loader script. I used to refer to
  it as the profile bootstrapper. I'll now refer to it as the profile
  load file, and I've renamed `doom-profiles-bootstrap-file` to
  `doom-profile-load-file` to reflect this.
- The variables `doom-profile-dirs` and `doom-profile-config-files` were
  merged into doom-profile-load-path.
- Both envvars have also been documented in `doom help` (and
  $DOOMPROFILE's has been updated).

Ref: #6794
2022-09-18 00:28:13 +02:00
Henrik Lissner
7fc0cbff5e
perf(cli): use nosuffix loading early-init
Don't waste file IO time looking for
early-init.el{.so{,.gz},.elc{,.gz},.el{,gz}}.
2022-09-17 21:41:43 +02:00
Henrik Lissner
b804a2f34f
refactor(lib): convert cli/autoloads.el to lib 2022-09-16 13:07:28 +02:00
Henrik Lissner
b914830403
refactor!: complete profile gen and init systems
BREAKING CHANGE: This commit makes three breaking changes:

- Doom now fully and dynamically generates (and byte-compiles) your
  profile and its init files, which includes your autoloads, loading
  your init files and modules, and then some. This replaces
  doom-initialize-modules, doom-initialize-core-modules, and
  doom-module-loader, which have been removed. This has also improved
  startup time by a bit, but if you use these functions in your CLIs,
  for instance, this will be a breaking change.
- `doom sync` is now required for Doom to see your profiles (and must be
  run whenever you change them, or when you up/downgrade Emacs across
  major versions).
- $DOOMDIR/init.el is now read much earlier than it used to be. Before
  any of doom-{ui,keybinds,editor,projects}, before any autoloads are
  loaded, and before your load-path has been populated with your
  packages. It now runs in the context of early-init.el, giving users
  freer range over what they can affect, but a more minimalistic
  environment to do it in.

  If you must have some logic run when all that is set up, add it to one
  of the module hooks added in e08f68b or 283308a.

This also poses a significant change to Doom's load order (see the
commentary change in lib/doom.el), along with the following (non
breaking) changes:

1. Adds a new `doom profiles sync` command. This will forcibly resync
   your profiles, while `doom sync` will only do so if your profiles
   have changed.
2. Doom now fully and dynamically generates (and byte-compiles) your
   user-init-file, which includes loading all your init files, modules,
   and custom-file. This replaces the job of doom-initialize-modules,
   doom-initialize-core-modules, and doom-module-loader, which have been
   removed. This has also improved startup time by a bit.
3. Defines new doom-state-dir variable, though not used yet (saving that
   and the other breaking changes for the 3.0 release).
4. Redesigns profile directory variables (doom-profile-*-dir) to prepare
   for future XDG-compliance.
5. Removed unused/unimportant profile variables in doom.el.
6. Added lisp/doom-profiles.el. It's hardly feature complete, but it's
   enough to power the system as it is now.
7. Updates the "load order" commentary in doom.el to reflect these
   changes.
2022-09-16 01:14:23 +02:00
Henrik Lissner
0c918f3b2d
refactor: change doom-module-list signature
Used to return the hash-table `doom-modules` (if not all-p), but I've
changed it to return a list of cons cells (:CATEGORY . MODULE),
representing all enabled modules, in the order they were enabled.

The purpose of this change is to prepare for a change in the structure
of doom-modules, and how Doom stores its module metadata.
2022-09-16 01:14:21 +02:00
Henrik Lissner
775ee2f04a
refactor: rethink doom-module-*-path functions
- Rename doom-module-path -> doom-module-expand-path, to better reflect
  its purpose.
- Optimize doom-module-locate-path to try caches and
  locate-file-internal, before looping through doom-modules-dirs.
- Rely on file-name-concat to join paths, rather than string
  concatenation. file-name-concat is more robust for the purpose and
  has lower overhead than expand-file-name.
2022-09-16 01:14:21 +02:00
Henrik Lissner
b7bd27d22b
refactor(cli,lib): print levels & output redirection
This refactors how Doom captures and redirects its output (to stdout and
stderr) into a more general with-output-to! macro, and:

- Simplifies the "print level" system. The various doom-print-*-level
  variables have been removed.
- Adds a new print level: notice, which will be the default level for
  all standard output (from print!, doom-print, prin[ct1], etc).
- Adds a with-output-to! macro for capturing and redirecting
  output to multiple streams (without suppressing it from stdout). It
  can also be nested.
- Changes the following about doom-print:
  - Default :format changed to nil (was t)
  - Default :level changed to t (was `doom-print-level`)
  - No longer no-ops if OUTPUT is only whitespace
2022-09-16 01:14:20 +02:00
Henrik Lissner
6cac7b05b6
refactor(lib): tidy doom-log output
This commit reduces the debug log noise, makes it easier to
read/parse/search, and soft-introduces a convention for doom-log
messages, where they are prefixed with a unique identifier loosely named
after it's running context or calling function.

I haven't enforced it everywhere doom-log is used yet, but this is a
start.
2022-09-12 16:01:43 +02:00
Henrik Lissner
bcf7a8a554
refactor!(cli): rename cli definers for consistency
BREAKING CHANGE: If anyone is using Doom's CLI framework and are
defining their own CLIs with any of the following macros, they'll need
to be updated to their new names:

- defautoload! -> defcli-autoload!
- defgroup! -> defcli-group!
- defstub! -> defcli-stub!
- defalias! -> defcli-alias!
- defobsolete! -> defcli-obsolete!

These were renamed to make their relationship with CLIs more obvious;
they were too ambiguous otherwise.
2022-09-12 11:45:59 +02:00
Jeff Kowalski
29e30e8af4 fix(cli): follow-on syntax fixes to #6772
While fixing #6772, we also address several other issues found by
sh-shellcheck:

L47C39 SC1007:Remove space after = if trying to assign a value
(for empty string, use var='' ... ).

L47C46 SC2046:Quote this to prevent word splitting.

L62C20 SC2086:Double quote to prevent globbing and word splitting.

L82C9  SC2154:tmpdir is referenced but not assigned
(did you mean 'TMPDIR'?).
2022-09-12 11:44:11 +02:00
Jeff Kowalski
571ab7425a fix(cli): #6772 - trivial doomscripts fail
When trying to establish the value of EMACSDIR, the proper fallback
when BASH_SOURCE is undefined is $0 rather than 0, in correct shell-
scripting parlance.
2022-09-12 11:44:11 +02:00
Henrik Lissner
c747d218ae
refactor(cli): throw error if Doom fails to load 2022-09-10 18:36:23 +02:00
Henrik Lissner
0172b180a9
refactor(cli): remove superfluous emacs switches
Neither --no-x-resources or --no-splash are relevant to a noninteractive
session.
2022-09-07 17:25:01 +02:00
Henrik Lissner
ceae154751
fix(cli): reading dir perms on a non-existent dir
This is a regression from c05e615. doom.el changes user-emacs-directory
to doom-cache-dir, which may not exist yet, at the time of this check,
causing file-attributes to return nil, and causing = to throw a type
error (see #6754).

In addition to fixing this, I've also made the check more liberal about
failures, in the odd case that doom-emacs-dir, too, does not exist at
the time bin/doom is called (it'd be very hard to pull that off, but not
impossible).

Fix: #6754
Amend: c05e61536e
2022-09-07 17:25:01 +02:00
Henrik Lissner
18887163f9
tweak(cli): add lisp/cli to doom-cli-load-path by default 2022-09-07 17:25:00 +02:00
Henrik Lissner
8594c1a0c4
fix(cli): failure to autoload 'doom refresh' error
Amend: cee89a5d3f
2022-09-07 11:32:41 +02:00
Henrik Lissner
085b5563fc
nit(cli): tidy comments & correct grammar in error 2022-09-06 23:04:17 +02:00
Henrik Lissner
aef14f078d
feat(cli): add --benchmark switch 2022-09-06 22:55:48 +02:00
Henrik Lissner
0100b08402
refactor(cli): handle more errors & POSIX-ify doomscript 2022-09-06 22:55:48 +02:00
Henrik Lissner
c05e61536e
refactor: make early-init.el Doom's universal bootstrapper
This centralizes Doom's core startup optimizations and, as a
side-effect, reduces the runtime of bin/doom commands substantially.
This also simplifies the user story for loading Doom remotely (for batch
sessions or doomscripts).
2022-09-06 22:55:47 +02:00
Henrik Lissner
a5c80fcb4b
refactor: deprecate doom-private-dir for doom-user-dir
- Deprecates the doom-private-dir variable in favor of doom-user-dir.
- Renames the pseudo category for the user's module: :private -> :user.
- Renames the doom-private-error error type to doom-user-error.

Emacs uses the term "user" to refer to the "things" in user space (e.g.
user-init-file, user-emacs-directory, user-mail-address, xdg-user-dirs,
package-user-dir, etc), and I'd like to be consistent with that. It also
has the nice side-effect of being slightly shorter. I also hope
'doom-user-error' will be less obtuse to beginners than
'doom-private-error'.
2022-08-14 20:43:35 +02:00
Henrik Lissner
9c04998e9c
tweak(cli): load doomrc quietly 2022-08-08 18:23:47 +02:00
Henrik Lissner
9b8ed397e8
feat!(cli): load project .doomrc instead of ci.el
BREAKING CHANGE: Before, 'doom ci' would load
$GIT_WORKING_TREE/.github/ci.el, to give users/projects an opportunity
to provide project-local configuration for bin/doom (mainly for CI/CD).
Now, this ci.el file is no longer loaded and instead, *all* bin/doom
sessions will walk up the file tree and load the first .doomrc it finds.

This gives bin/doom users a more general place configure all of its
commands, and not just 'doom ci' commands.

Extras:
- Adds .doomrc to auto-mode-alist (so that it starts in
  emacs-lisp-mode).
2022-08-07 19:43:28 +02:00
Henrik Lissner
d3f2b4d9ca
docs(cli): fix issue tracker URL in 'doom help' 2022-08-01 22:36:33 +02:00
Henrik Lissner
b9933e6637
refactor!: restructure Doom core
BREAKING CHANGE: This restructures the project in preparation for Doom
to be split into two repos. Users that have reconfigured Doom's CLI
stand a good chance of seeing breakage, especially if they've referred
to any core-* feature, e.g.

  (after! core-cli-ci ...)

To fix it, simply s/core-/doom-/, i.e.

  (after! doom-cli-ci ...)

What this commit specifically changes is:
- Renames all core features from core-* to doom-*
- Moves core/core-* -> lisp/doom-*
- Moves core/autoloads/* -> lisp/lib/*
- Moves core/templates -> templates/

Ref: #4273
2022-07-30 22:41:13 +02:00
Henrik Lissner
743b740e79
fix(cli): verbose output in debug mode 2022-07-28 18:15:15 +02:00
Henrik Lissner
314463bd49
fix(cli): ignored --{profile,doomdir,emacsdir,debug}
Fixes an edge case where --profile, --doomdir, --emacsdir, and --debug
were ignored if used in a nested bin/doom call. Now possible thanks to
49d3f1e.

Ref: 49d3f1e96c
2022-07-28 18:15:06 +02:00
Henrik Lissner
5af38fb08e
feat: make bin/doom profile aware
- Fixes Doom's former inability to (trivially) juggle multiple profiles
  based on the same EMACSDIR (see #6593).
- Adds '--profile NAME' switch to bin/doom (also recognized
  $DOOMPROFILE).
- Adds new doom-profile* variables. These will eventually replace
  doom-{local,etc,cache}-dir and doom-{autoloads,env}-file.

This is intentionally messy to ensure backwards compatibility for a
little while longer. This will be fixed over the next couple weeks.

Ref: #6593
2022-07-28 12:01:02 +02:00
Henrik Lissner
33c5f3721a
fix(cli): __DOOMPIPE+=0: not found errors
The string append operator is a bashism, and therefore is not POSIX
complaint. It will throw errors when /bin/sh isn't symlinked to bash.
2022-07-09 21:10:40 +02:00
Henrik Lissner
6cb2c6e962
fix(cli): recognize global options for pseudo CLIs
The global options (like --debug and --pager) weren't recognized for
pseudo command like :help and :version (in particular, rendering --pager
ineffective).

Fix: #6526
2022-07-04 02:58:17 +02:00
Henrik Lissner
af4c18e283
fix(cli): recognize command argument for --pager
--pager incorrectly expected a boolean argument, when it should accept
any arbitrary pager command (set to a blank string to disable the
pager).

Ref: #6526
2022-07-04 02:58:17 +02:00
Henrik Lissner
14b2395424
refactor: remove unused core variables
doom-debug-p and doom-interactive-p have always been intentionally
redundant, because changing the variables they replaced had other
side-effects, which made writing tests for them difficult. Since our
new (yet unpublished) tests lean heavily toward integration testing more
than unit testing, this becomes an implementation detail.

And doom-init-p's only use was refactor out at some point in the past,
so it's no longer used.

Also done to reduce Doom's footprint, in general.
2022-06-29 18:14:20 +02:00
Henrik Lissner
4dcfc37199
nit(cli): clarify comments in bin/doomscript 2022-06-22 23:04:59 +02:00
Henrik Lissner
d2fbe6a0c9
fix(cli): restore doom {refresh,re} alias
Amend: 6c0b7e1530
2022-06-22 23:04:58 +02:00
Henrik Lissner
666cc1fda7
refactor(cli): remove :stub, :obsolete, :deprecated, :since
I've removed these CLI properties because they were either
unused (:deprecated and :since) or poorly implemented (:stub and
:obsolete). And I'd rather have fewer magical properties, and instead
delegate these roles to the defobsolete! and (new) defstub!  macros.
Also, in the future, the help API will ascertain :since dynamically, so
it won't be very useful.

In summary:
- Use defstub! instead of :stub
- Use defobsolete! instead of :obsolete or :deprecated
- This removes the doom-cli-deprecated-error type (it's not really an
  error to begin with).
- Removes :stub, :obsolete, :deprecated, and :since
2022-06-22 23:04:14 +02:00
Henrik Lissner
209092c578
refactor(cli): don't reboot bin/doom on --pager
Also adds comments to explain why we're rebooting (or not) for these
settings.
2022-06-22 11:48:11 +02:00
Henrik Lissner
f0a11da072
tweak(cli): less verbosity on -!/--force
The notice will still be logged, but let's not potentially ruin piped
output with unneeded noise.
2022-06-22 11:42:25 +02:00
Henrik Lissner
3ea9051890
fix(cli): remove set -e from bin/doom{,script}
This killed the script prematurely (without displaying the error) if
Emacs failed to execute. In versions prior to bash 4, set -e would not
terminate the script if a non-zero exit code occurred within a subshell,
but it will in bash 4+.

In any case, we don't need this fallback to begin with. The script
handles its errors sufficiently otherwise.
2022-06-22 01:23:39 +02:00
Henrik Lissner
90a6bdb751
nit(cli): update comments wrt deferring site-lisp and -Q
Ref: 3b3c008b1b (commitcomment-76653206)
2022-06-21 23:31:16 +02:00
Henrik Lissner
5519c030ff
fix(cli): -!/--force being ignored
Forgot to adapt the old code to use doom-cli-context struct!

Fix: #6485
2022-06-21 23:00:00 +02:00
Henrik Lissner
3b3c008b1b
fix(cli): site file loader
I had missed the fact that -Q implies not only
--no-site-file (intended), but --no-site-lisp (unintended). Without the
latter, no site-lisp directory is left in load-path, and any attempt to
load it after-the-fact (which I do in core-cli.el) will fail. Thanks to
@yamanq for noticing this!

Fix: #6473
Fix: #4198
Co-authored-by: Yaman Qalieh <yamanq@users.noreply.github.com>
2022-06-21 22:48:43 +02:00