reddit / emacs
Does any package exist to view code structure in a tree like manner?
JoeKazama · 2022-02-15 16:41
I have slowly transitioned from PyCharm to Emacs for my coding development and It's been about 6 months now and in general am very happy with my workflow in Emacs. There is just one thing that is still pulling me back to PyCharm and it is something that others might not find too useful but I constantly use.
It is the tree-like structure overview for your code that PyCharm has that you can toggle on the left and [it looks like this](https://i.imgur.com/nOKhY2R.png).
Now I know I can get a directory overview with the treemacs package and I also know about the iMenu command which is very nice but not exactly a static tree-like structure you can look at. I was wondering if there exists a package to show the class/functions/ structure of a file on the side as you can see on the picture above.
Thank you for your help.
*
*
*
Update for those curious:
I settled on treemacs and lsp-treemacs. [This is how it looks when I press F1](https://i.imgur.com/2hBDYNW.png) and pressing F1 again closes the sidebar. Thanks again for the help everyone
dpassen1 · 2022-02-15 17:26
Perhaps https://github.com/bmag/imenu-list ?
I'm sure there's an LSP based solution as well
crawsphi · 2022-02-15 17:37
Imenu is going to be the key to this: you're just looking for a viewer for that information. If Treemacs can't show imenu info, I think NeoTree can. There's also a package called imenu-list (EDIT: which I see was suggested while I was typing).
yyoncho · 2022-02-15 17:37
> I'm sure there's an LSP based solution as well
https://github.com/emacs-lsp/lsp-treemacs
JoeKazama · 2022-02-15 17:40
Wow this looks very promising, thank you!
JoeKazama · 2022-02-15 17:41
Thank you for the reply, this package looks good as well as the LSP-treemacs one /u/yyoncho mentioned. I will try out both later and update on which one I like.
JoeKazama · 2022-02-15 17:47
Yes you are right, I will see if imenu-list is better or lsp-treemacs. I haven't heard of NeoTree so that will also be in my radar in case the other options don't work. Thank you for your reply.
yyoncho · 2022-02-15 17:52
FWIW the "emacs way" is to use something like `helm-imenu`/`consult-imenu`/`whatever your completion frontend is` on-demand.
Human192 · 2022-02-16 12:21
I tried imenu-list for a while, but I could never get the right level of detail from it. I found that I was trying to do two things with it: understand the structure and navigate, but either there was too much extra noise, or the listed items were out of order relative to the source file. This is for typescript, by the way, perhaps imenu-list better for Python?
Now I'm using the built in hideshow library to understand the code (it does code folding), and counsel (i.e ivy completion) with imenu to navigate to a class or method or type.
For hideshow, (use `hs-minor-mode`) if I want to see the methods of a class, I first navigate to the class definition, then inside the class run `hs-hide-level` to see only the method signatures. Other commands `hs-toggle-hiding` lets you toggle a single level, and `hs-show-all` undoes hiding. A cool side-effect is that you can kill entire methods as single lines when collapsed.
Counsel (specifically the function `counsel-semantic-or-imenu`) extends `imenu` by providing the full path to methods instead of paging through classes>methods>other (this is typescript specific again). So to jump to `move()` inside class `Point` you could just type "Po mo" (which is like searching "Po.\*mo.\*") matching `Point.move: method` in the list.
deaddyfreddy · 2022-02-16 13:52
Projectile
KindlyRepeat · 2022-02-16 14:38
You could take a look at [moldable emacs](https://github.com/ag91/moldable-emacs). It seems to leverage [emacs tree-sitter](https://github.com/emacs-tree-sitter/elisp-tree-sitter) to be able to interact with the abstract syntax tree of the source code.
arthurno1 · 2022-02-16 22:20
Speedbar is included with Emacs. Looks old, but you can replace the icons, there was someone posting here on reddit a github repo where he/she did it. Can't Treemacs do it?
[I personally use just Dired](https://github.com/amno1/.emacs.d/blob/main/init.org), styled with [some addons](https://github.com/Fuco1/dired-hacks/blob/master/dired-subtree.el) and a [simple script](https://github.com/amno1/.emacs.d/blob/main/lisp/dired-extras.el) where I use dired-subtree to expand/fold subdirectories one level at the time. You can use dired-subtree to expand one directory at a time.
[You can see the result](https://postimg.cc/N5NtScsZ). I am not sure if it lives to your expectations, but works very well for me.
JoeKazama · 2022-02-18 01:33
Just an update, I am very happy with the results of treemacs + lsp-treemacs. [This is how it looks when I press F1](https://i.imgur.com/2hBDYNW.png) and pressing F1 again closes the sidebar. Thanks again for the help yyoncho.
yyoncho · 2022-02-18 06:13
If you keep these open, you may try https://github.com/noctuid/link-hint.el. It works with the treemacs windows.