Skip to content

[Feature request] Ignore expression (#_) shortcut #505

@filipesilva

Description

@filipesilva

It would be handy to have a keybind shortcut to ignore an expression via #_ (https://cljs.github.io/api/syntax/ignore). It would be nice for the shortcut to be similar to the current ctrl+/ comment shortcut, perhaps ctrl+shift+/.

Personally I use ; and #_ with different intents: the first is mostly for text comments, the latter for disabling code. Whenever I use ; to disable code I feel I'm only doing it because it's easier (via VSCode shortcuts) than using #_.

But #_ is what I really want for code... because it applies correctly to the whole expression, instead of applying to lines. When I use ; to comment code I must think about start line, end line, and expression delimiters.

A couple of captured scenarios:

Calva has a concept of current form. This is the selected form when using the "expand selection" shortcut (ctrl+w).

If the user has the cursor on 2 in (+ 1 2 3), it is valid to ignore it and get (+ 1 #_2 3).

Regarding selections, consider the following:

(do
  (do 
    (inc 1)
    (inc 2)))

If we select rows 2, 3, and 4, we should get:

(do
  #_(do
    (inc 1)
    (inc 2)))

and not

(do
  #_(do
    #_(inc 1)
    #_(inc 2)))

But if we had select rows 3 and 4, then:

(do
  (do
    #_(inc 1)
    #_(inc 2)))

The comment shortcut also uncomments lines regardless if they are already commented. But since the ignore token "stacks", we shouldn't double ignore expressions. An example:

(do
  (do 
    (inc 1)
    #_(inc 2)))

Selecting lines 3 and 4, and pressing the ignore shortcut:

(do
  (do
    #_(inc 1)
    #_(inc 2)))

Pressing it again:

(do
  (do
    (inc 1)
    (inc 2)))

This was proposed by @AlexVPopov and discussed on the Clojurians slack with @PEZ.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions