help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Navigating Lisp data structures


From: Matt
Subject: Navigating Lisp data structures
Date: Sun, 04 Dec 2022 14:00:25 -0500
User-agent: Zoho Mail

I'm writing an Emacs package and struggling to figure out how to represent the 
data in a Lisp data structure.  I'm getting lost in whether it should be an 
alist of alists, a plist of plists, an alist of plists, etc.  Or maybe it would 
be better to use a cl-struct or a hash or a class or a vector or a record.  
Should I use keywords or not, etc.  

Here is a detailed explanation of my issue:

My Emacs package manages my project workflows (e.g. Python or C).  Each project 
has a name, associated files, one or more shell processes (comints), as well as 
commands for a specific shell and commands used across the shells.  It also 
sets my window layout.

In Python, I might structure the data something like this:

projects = {
    "my_c_project": {
        'shells': {
            "*build*": {"root": "/path/to/build/directory/", "setup": ("export 
MYBUILDVAR1=1", "export MYBUILDVAR2=0")},
            "*run*": {"root": "/path/to/run/directory/", "setup": ("export 
MYRUNVAR=1")}
        },
        'commands': ("./build_my_project.sh", "./run_my_build"),
        'files': ("/path/to/entrypoint.c", 
"/path/to/other/file/I/care/about.c"),
        'window_split': ("quad", ),  # C-x 3 C-x 2 other-window other-window 
C-x 2
    },
    "my_python_project": {
        'shells': {"*my_python_project*":  {"root": 
"/path/to/my/python/project", "setup": ("source venv/bin/activate")}},
        'commands': ("python3 -m my_python_project",
                     "python3 -m unittest discover tests/ --failfast --quiet", 
),
        'files': ("/path/to/my_python_project/entry_point.py", ),
        'window_split': ("half", ), # C-x 3
    }
}

I could then get the information I need through chaining look ups.  If we 
pretended that Emacs used Python, activating a project might look something 
like this:

(Pdb) # create shells
(Pdb) for name in projects['my_python_project']['shells']: pass  # call comint 
creation command
(Pdb) # setup shell environments
(Pdb) for command in 
projects['my_python_project']['shells']['*my_python_project*']['setup']: pass  
# pass each command in the comint
(Pdb) # load files
(Pdb) for file in projects['my_python_project']['files']: pass  #  run emacs 
find-file
(Pdb) # and so on

Of course the data could be represented using classes instead of dicts.  
However, I hope the problem is clear.

I'm obviously looking at the problem through the lens of Python key-value 
structures.  When I try to translate the data structure to something like 
nested plists, it feels messy.  Maybe that's me simply being uncomfortable with 
nested lists?  When I mix list types (e.g. an alist of plists), the lookup 
syntax becomes inconsistent (a mix of assocs and plist-gets, scattered with 
cars and cdrs and weird cases in which I have a list of strings I can't seem to 
access).  

Guidance would be sincerely appreciated.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]