-
Notifications
You must be signed in to change notification settings - Fork 40
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
imenu based fold parser #69
Comments
Wow, this looks awesome. So adding the elisp function + imenu is all that's required? |
yes, and adding the configuration so that it gets used for a specific major mode. and of course that major mode should have imenu support, which seems the case for quite a few that i tried. |
I couldn't get this to work in Python mode. What entry function should I be invoking? I tried origami-close-all-nodes. |
@sawan what you describe works for me and is indeed how this is supposed to work. what does your also try |
@wbolster thanks, sorry for late reply. I have added the function it to Now when I do |
@sawan are you sure you set it up correctly? i have a working config in my (use-package origami
:custom
(origami-show-fold-header t)
:commands
origami-parser-imenu-flat
:config
(defun origami-parser-imenu-flat (create)
"Origami parser producing folds for each imenu entry, without nesting."
(lambda (content)
(let ((orig-major-mode major-mode))
(with-temp-buffer
(insert content)
(delay-mode-hooks
(funcall orig-major-mode))
(let* ((items
(-as-> (imenu--make-index-alist t) items
(-flatten items)
(-filter 'listp items)))
(positions
(-as-> (-map #'cdr items) positions
(-filter 'identity positions)
(-map-when 'markerp 'marker-position positions)
(-filter 'natnump positions)
(cons (point-min) positions)
(-snoc positions (point-max))
(-sort '< positions)
(-uniq positions)))
(ranges
(-zip-pair positions (-map '1- (cdr positions))))
(fold-nodes
(--map
(-let*
(((range-beg . range-end) it)
(line-beg
(progn (goto-char range-beg)
(line-beginning-position)))
(offset
(- (min (line-end-position) range-end) line-beg))
(fold-node
(funcall create line-beg range-end offset nil)))
fold-node)
ranges)))
fold-nodes)))))) |
Hi @wbolster, I have added the parser function to my configuration: And here is the value of Am I doing anything wrong? |
Great idea! Do you want to send a pull request? |
@sawan that is also how i use it. not sure what's wrong at your side, do you have the latest |
@gregsexton sure, would that pr just include that function? or also change default configuration? (imenu and indent based folds are different.) |
@wbolster I have sent you an email with the stack trace attached. Origami version is 20180101.753 Thanks again.... |
@sawan i am not sure which email you are referring to... in any case, the only right place to put that stack trace is as a comment in this ticket. |
ah, found something. here's a trimmed down version
|
weird, that which emacs version? and no idea whether it's related, but do you have
|
Lexical Binding was indeed the problem!! I put
in my Thank you again and I hope you keep up the good work. |
@sawan awesome! |
Based on code published in issue gregsexton/origami.el#69.
@wbolster Care to open a PR for this useful feature? |
tbh i'm not sure this project is actually maintained. @gregsexton is it? |
@gregsexton Are you still maintaining this project, if you are just busy consider adding some collaborator or something that could keep this project maintained! Please keep this awesome project alive! Thank you! |
I like |
Hi, just want inform people here that have started a new branch here. If you don't mind using celpa, you can open the PR there instead! Thanks! For reason why? See elp-revive/origami.el#1. |
hi,
i wrote a
imenu
based parser that creates folds (without any nesting) fromimenu
entries. i think this is very useful behaviour. let me know what you think, and whether this would make sense to include withorigami
itself.i think it can be useful for many languages, e.g. #49, #29, #61, #58 and possibly others may benefit from this.
this parser can be used for any major mode that has sensible imenu entries, by putting it into the
origami-parser-alist
variable. this can be done in many ways, for instance viaCustomize
M-x customize-variable RET origami-parser-alist
, or using lisp code, which is what i do in myinit.el
using a helper fromevil-mode
:i use this for
python-mode
andrst-mode
. it results in very dense (no empty lines) and usable (for me at least) folding.here's how it looks for python:
here's how it looks for restructuredtext:
here's the
origami-parser-imenu-flat
function, which works for me, but i only tested it casually:The text was updated successfully, but these errors were encountered: