Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

origami-toggle-node cannot toogle at the beginning of the node #42

Closed
c02y opened this Issue Sep 18, 2016 · 10 comments

Comments

Projects
None yet
4 participants

c02y commented Sep 18, 2016 edited

Fox example:

>int main()
{
......
}

the point is at beginning of the "int main" line, the ">" position (or any position before the symbol "{"), executing origami-toggle-node will do nothing, but expected to toggle the whole function, it only works inside the function (inside the "{...}"). But origami-recursively-toggle-node or origami-toggle-all-nodes work as expected. even from the beginning of the node.

BTW: origami-toggle-node works at the beginning of a defun line in elisp file.

ninrod commented Oct 17, 2016

+1. @gregsexton!

Here's a screenshot to demonstrate:

point is above the z in zsh. I cannot open or close the fold in this position. I have to place point somewhere inside the braces on that line so that origami can open and close folds for me.

Being able to open or close a fold anywhere in a line that contains a fold would be a significant comfort improvement.

screen shot 2016-10-17 at 10 15 06

ninrod commented Oct 17, 2016

In my specific use case, I think the way to go would be to change the regex listed here. Makes sense?

ninrod added a commit to ninrod/dotfiles that referenced this issue Oct 18, 2016

+1 I don't think any other folding packages support this behavior.

I like how vim does its folding.

ninrod commented Jan 27, 2017 edited

you can circumvent the behaviour by constructing a custom function with save-excursion, like here.

@ninrod That's a good head start.

        public void FunctionName([Variable one)
        {

I'll probably have to tweak it to do a 'lookahead' for 1 or 2 lines before giving up and going upwards up the stack.

ninrod commented Jan 27, 2017

@jojojames yes that's the spirit.

@ninrod
Here's a quick slathering, if I have time, I'll try to improve it more. Would also appreciate anyone taking and running with it to improve the folding experience.

Uses s.el for the string parsing.

  (defun jojo/origami-toggle-node ()
    (interactive)
    (if (not (member major-mode
                     '(c-mode
                       java-mode csharp-mode c++-mode js-mode
                       js2-mode php-mode json-mode ruby-mode
                       motion-mode swift-mode css-mode)))
        (call-interactively #'origami-toggle-node)
      (cond
       ((s-ends-with? "{" (s-trim (thing-at-point 'line t)))
        (save-excursion
          (goto-char (point-at-eol))
          (call-interactively #'origami-toggle-node)))
       ((save-excursion
          (forward-line 1)
          (when (s-starts-with? "{" (s-trim (thing-at-point 'line t)))
            (goto-char (point-at-eol))
            (call-interactively #'origami-toggle-node)
            t))
        t)
       (t
        (call-interactively #'origami-toggle-node)))))

ninrod commented Jan 27, 2017

@jojojames, I only use vim's #{{{ #}}} triple bracket style folding, but your example looks promising.

Owner

gregsexton commented Jan 28, 2017

The behaviour of origami-toggle-node you describe is by design. You should use origami-forward-toggle-node. IIRC, this won't work across lines though - again this is by design so as not to be surprising.

You should be able to easily compose origami-forward-fold (jumps to the next folding point) and origami-toggle-node to get the behaviour you want. No need to parse the buffer.

@gregsexton gregsexton closed this Jan 28, 2017

ninrod commented Jan 28, 2017

by the way thank you for the awesome package @gregsexton!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment