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

Feature Request: Folding code and data #1269

Closed
laurentsenta opened this issue Feb 22, 2016 · 8 comments
Closed

Feature Request: Folding code and data #1269

laurentsenta opened this issue Feb 22, 2016 · 8 comments
Labels
new Marks issues describing new features released Marks issues which have had the fixes released in a stable build
Milestone

Comments

@laurentsenta
Copy link

Folding let and data would be handy, especially when working with html:

(defn x [a]
  (let [b (+ 1 a)
        c (+ 1 a)
        d (+ 1 a)
        f (fn [x] (println b))]
    (println b)))

=>

(defn x [a]
  (let [b c d f]
    (println b)))

And for large hiccup-like defs

[:html
  [:body
   [:div#page-container.sidebar-l.sidebar-o.side-scroll.header-navbar-fixed
    "<!-- Side Overlay-->"
    [:aside#side-overlay
     "<!-- Side Overlay Scroll Container -->"
     [:div#side-overlay-scroll
      {:style ""}
      "<!-- Side Header -->"
      [:div.side-header.side-content
       "<!-- Layout API, functionality initialized in App() -> uiLayoutApi() -->"
       [:button.btn.btn-default.pull-right
        {:data-action "side_overlay_close",
         :data-toggle "layout",
         :type "button"}
        [:i.fa.fa-times]]
       [:span
        [:img.img-avatar.img-avatar32
         {:alt "", :src "assets/img/avatars/avatar10.jpg"}]
        [:span.font-w600.push-10-l "Ryan Hall"]]]
      "<!-- END Side Header -->"
      "<!-- Side Content -->"
      [:div.side-content.remove-padding-t
       "<!-- Side Overlay Tabs -->"
       [:div.block.pull-r-l.border-t
        [:ul.nav.nav-tabs.nav-tabs-alt.nav-justified
         {:data-toggle "tabs"}
         [:li.active
          [:a
           {:href "#tabs-side-overlay-overview"}
           [:i.fa.fa-fw.fa-coffee]
           "\n                                Overview"]]
         [:li
          [:a
           {:href "#tabs-side-overlay-sales"}
           [:i.fa.fa-fw.fa-line-chart]
           " Sales"]]]

=>

[:html
  [:body
   [:div#page-container.sidebar-l.sidebar-o.side-scroll.header-navbar-fixed
    [:aside#side-overlay
     [:div#side-overlay-scroll ...]
     [:div.side-content.remove-padding-t ...]]]

(the example is not correct but you get the idea).

@cursive-ide
Copy link
Owner

Interesting idea, I especially like the let folding. The hiccup one is more difficult since it's hard to detect that a particular form is meant to be data, but this could possibly be triggered via metadata or something similar.

@laurentsenta
Copy link
Author

👍 You could do the same for maps,
{:a 1 :b 2 :c 3} => {:a :b :c}
(not sure how the UI should behave to show the folding explicitly)

For the hiccup one, tbh that's the main "issue" that brought me here, I have huge, "uninteresting", pile of nested vectors. wouldn't showing the first item be a nice "get started with folding" feature to have?

@lorddoig
Copy link

lorddoig commented Mar 2, 2016

Related - support for this IntelliJ feature would be nice: https://www.jetbrains.com/idea/help/folding-custom-regions-with-line-comments.html

@torbjornvatn
Copy link

I'd also like folding on fold comments, here's a new link to the documentation: https://www.jetbrains.com/help/idea/2016.2/code-folding.html#supported_comments

@RNGMonk
Copy link

RNGMonk commented Dec 9, 2016

This would also be a major feature add for me.

@akovantsev
Copy link

akovantsev commented Jun 2, 2017

original comment:
https://clojurians-log.clojureverse.org/cursive/2017-06-01.html#inst-2017-06-01T19:52:35.147550Z
https://clojurians.slack.com/archives/C0744GXCJ/p1496335955147550

Is there a way to style how folded blocks of code are displayed?
Here some current collapsed top level forms examples:

(let ...)
(defn foo ...)
(def bar ...)
(spec/def ...)

What I'd really like, is to show spec/defs keyword, and single-arity function's args (if those are on the same line, ofc.):

(defn foo [bar baz] ...)
(spec/def :foo/bar ...)

I know, there is a settings page for unresolved symbols to "alias" those to known macros structure, like "treat rum/defc just like defn".
Is there something like this, but for code folding representation?

@neuromantik33
Copy link

Folding on data structures is a big plus for me, especially useful for editing large edn files with many nested maps, collapsing some would greatly be appreciated! :)

@cursive-ide cursive-ide added this to the 1.8.0-eap7 milestone Aug 28, 2018
@cursive-ide
Copy link
Owner

I've fixed some of these cases for the next build, and broken the remaining cases (mostly around per-form customisation) out into #2042.

What is fixed here:

  1. You can now use fold comments using ; region Title and ; endregion comments, and there's a Surround With... option to wrap a block like this.
  2. Data structures in EDN files can now be folded, and Cursive will try to be smart about showing a preview.

Arbitrary data structures are not folded in Clojure code right now, since it's hard to distinguish them from syntax elements (e.g. let binding vectors). That's being tracked in #2042 and will be fixed there.

@cursive-ide cursive-ide added the new Marks issues describing new features label Sep 22, 2020
@cursive-ide cursive-ide added the released Marks issues which have had the fixes released in a stable build label Oct 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new Marks issues describing new features released Marks issues which have had the fixes released in a stable build
Projects
None yet
Development

No branches or pull requests

7 participants