Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Feature request: customize opening/closing brackets/etc. per-language #182

Closed
dead-claudia opened this issue Oct 19, 2015 · 10 comments
Closed

Comments

@dead-claudia
Copy link

Problem

The current set is a very sensible default for many C-based languages, but several languages, such as Haskell, OCaml, and various Lisps, use some of those characters for other reasons. Examples:

  • ' (single quote)
    • It's a valid identifier character in Haskell, as long as it's not the first. OCaml accepts it anywhere, and it's frequently used in function arguments. foo', foo'', etc. is the Haskell counterpart to foo1, foo2, etc. in most other languages.
    • It denotes symbols in multiple Lisps, including Clojure, and they represent to-be-evaluated identifiers. It's mostly used with macros.
  • - This is the syntax quote in most Lisps, including Clojure.
    - This denotes polymorphic variants in OCaml. It's used occasionally for duck-typing and code reuse, but infrequently because it reduces type safety.
    - This is the escape character in Windows PowerShell.
    
    

Most of these are common enough cases that they will appear in most non-trivial projects written in that language.

There's also the more obscure languages that allow for unbalanced braces as well, e.g. APL, J, and Forth.

Solution

Allow all opening/closing characters to be configured on a per-language basis via the Atom config and Atom services. In the case of the latter, anything there effectively becomes the language's default. The current default can stay the default, as it works with most common languages. It can be as simple as this:

Here:

// package.json
{
  "consumedServices": {
    "bracket-matcher": {
      "versions": {
        "1.0.0": "consumeConfig"
      }
    }
  }
}
# index.coffee
exports.consumeConfig = ({scope, match}) ->
  setAsDefaultConfig(scope, match)

Package: Clojure as an example

// package.json
{
  "providedServices": {
    "bracket-matcher": {
      "versions": {
        "1.0.0": "provideConfig"
      }
    }
  }
}
# index.coffee
exports.provideConfig = ->
  scope: 'source.clojure'
  match: [
    ['(', ')']
    ['{', '}']
    ['[', ']']
    ['"', '"']
  ]

Note that the scope name is basically the grammar's scopeName.

@joedaniels29
Copy link

seconding an idea like this. typing #'in lisp is quite difficult.

@Idyllei
Copy link

Idyllei commented Dec 7, 2015

I third this feature request. I am really getting annoyed with having to manually remove auto-closed backticks in Perl6 with multiline comments of the style #`(COMMENT). I really would hate to have to disable bracket-matcher.

#`(
This multiline
comment is
what I want to get.
)
#`(But I get
a backtick at the end.
)`

@otherjoel
Copy link

Another vote in favour. Manually disabling per language is a pain!

@MadcapJake
Copy link

Another vote for this and another with regards to Perl 6: there are actually numerous supported enclosing delimiters in the language (most non-letter characters).

Also in template languages there are a lot of unique delimiters chosen out of a need to be different enough to not show up in someone's actual content.

Another language I use (Nit) has a special set of brackets for native code:

fun sleep( t : Int ) `{ sleep( t ); `}

@boozedog
Copy link

+1 for this enhancement.

@novelistparty
Copy link

+1

@dead-claudia
Copy link
Author

I think it would come down to parameterizing these lines and enabling them to be mutated via a service. I'm considering taking a stab at this, but I'm time-strapped ATM. 😦

@boozedog
Copy link

As an interim step, can the "non-smart" quotes be a separate toggle similar to smart quotes? That'd certainly solve #171 ...

@utkarshkukreti
Copy link

I posted a workaround (good enough for me until this gets fixed) here: #171 (comment) cc @boozedog

@winstliu
Copy link
Contributor

Closing in favor of #121 - feel free to subscribe there for updates.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

10 participants