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

How to debug the emacsWithPackagesFromUsePackage parser #374

Open
ParetoOptimalDev opened this issue Dec 20, 2023 · 1 comment
Open

How to debug the emacsWithPackagesFromUsePackage parser #374

ParetoOptimalDev opened this issue Dec 20, 2023 · 1 comment

Comments

@ParetoOptimalDev
Copy link

ParetoOptimalDev commented Dec 20, 2023

I had some issues that I weren't sure were:

  • from me
  • from some bug in the emacsWithPackagesFromUsePackage parser

That meant I needed to debug it. There isn't an easy way to do that currently.

Assuming you have the emacs-overlay repo locally just open nix-repl and follow the log below.

Full nix-repl log demonstrating debugging parser

nix-repl> pkgs = import <nixpkgs> {}
nix-repl> parse = pkgs.callPackage ./parse.nix { }

nix-repl> let configExampleTxt = ''
  (use-package org
    :commands org-mode
    :bind (("C-c a" . org-agenda)
           :map org-mode-map
           ([C-right] . org-demote-subtree)
           ([C-left] . org-promote-subtree)))
    (use-package direnv
    :ensure t
    :config (direnv-mode))
    (use-package paredit-mode
    :ensure paredit
    :hook (emacs-lisp-mode lisp-mode lisp-interaction-mode))
'';

# Note that isOrgModeFile is false
nix-repl> parse.parsePackagesFromUsePackage {configText = configExampleTxt; alwaysEnsure = true; isOrgModeFile = false; alwaysTangle = true; }
parse.parsePackagesFromUsePackage {configText = configExampleTxt; alwaysEnsure = true; isOrgModeFile = false; alwaysTangle = true; }
[ "use-package" "org" "use-package" "direnv" "use-package" "paredit" ]

nix-repl> let config = pkgs.lib.readFile "/tmp/simple.org"; in parse.parsePackagesFromUsePackage {configText = config; alwaysEnsure = true; isOrgModeFile = true; alwaysTangle = true; }
let config = pkgs.lib.readFile "/tmp/simple.org"; in parse.parsePackagesFromUsePackage {configText = config; alwaysEnsure = true; isOrgModeFile = true; alwaysTangle = true; }
[ "use-package" "org" "use-package" "direnv" "use-package" "paredit" ]


nix-repl> let configPath = "/tmp/simple.org"; 
              config = pkgs.lib.readFile configPath;
              packageList = parse.parsePackagesFromUsePackage {configText = config; alwaysEnsure = true; isOrgModeFile = true; alwaysTangle = true; }; 
              dedupedPackages = pkgs.lib.naturalSort (pkgs.lib.unique packageList); 
              packagesStr = (pkgs.lib.concatStringsSep "\n" dedupedPackages); 
          in pkgs.lib.trace "\n${packagesStr}" ""
let configPath = "/tmp/simple.org"; 
                        config = pkgs.lib.readFile configPath;
                        packageList = parse.parsePackagesFromUsePackage {configText = config; alwaysEnsure = true; isOrgModeFile = true; alwaysTangle = true; }; 
                        dedupedPackages = pkgs.lib.naturalSort (pkgs.lib.unique packageList); 
                        packagesStr = (pkgs.lib.concatStringsSep "\n" dedupedPackages); 
                    in pkgs.lib.trace "\n${packagesStr}" ""
trace: 
direnv
org
paredit
use-package
""

Question: Would it be worth adding a debug output to the flake so that code like the above could be called on an elisp or org file directly like:

nix eval --impure --apply "p: p.debugParser({configText = config; alwaysEnsure = true; isOrgModeFile = true; alwaysTangle = true; })" github:nix-community/emacs-overlay#debug
@573
Copy link

573 commented Dec 22, 2023

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants