Giter Site home page Giter Site logo

Lack of auto-indent about pencilcode HOT 8 CLOSED

pencilcode avatar pencilcode commented on July 19, 2024
Lack of auto-indent

from pencilcode.

Comments (8)

davidbau avatar davidbau commented on July 19, 2024

This is an error message that comes from to the underlying coffeescript compiler that's used in the ace coffeescript mode.

from pencilcode.

davidbau avatar davidbau commented on July 19, 2024

Can you be more specific?

If I type something like this, it does auto-indent on the next line:

fn = (x) ->

On Tue, Mar 11, 2014 at 1:25 AM, Weihang Fan [email protected]:

Is it intended?

Reply to this email directly or view it on GitHubhttps://github.com//issues/43
.

from pencilcode.

weihang7 avatar weihang7 commented on July 19, 2024

It does not indent for statements such as if and for, which is (I think) caused by editor.setBehavioursEnabled(false) in line 1249 in editor_view.js.

from pencilcode.

davidbau avatar davidbau commented on July 19, 2024

Does that really do autoindenting in CoffeeScript? If I remember correctly, I found the BehaviorsEnabled flag really annoying for HTML documents where the autoindenting was too aggressive. Can you test it on a branch and see how it behaves?

from pencilcode.

weihang7 avatar weihang7 commented on July 19, 2024

It turns out that the code in ACE responsible identifying lines for autoindenting is line 53 in https://github.com/ajaxorg/ace/blob/master/lib/ace/mode/coffee.js. However, I can't understand this blob of regex enough to fix it.

from pencilcode.

davidbau avatar davidbau commented on July 19, 2024

Here is the regexp disassembled, perlre /x style:

/(?:
  [({[=:]      # Opening parentheses or brackets
 |[-=]>        # OR single or double arrow
 |\b(?:        # OR one of these words:
   else        #    else
  |switch      # OR switch
  |try         # OR try
  |catch       # OR catch, optionally followed by:
    (?:\s*[$A-Za-z_\x7f-\uffff][$\w\x7f-\uffff]*)?  # a variable
  |finally     # OR finally
 ))\s*$/       # all as the last thing on a line (allowing trailing space)

Here is a possible modification:

/(?:
  [({[=:]      # Opening parentheses or brackets
 |[-=]>        # OR single or double arrow
 |\b(?:        # OR one of these words:
   else        #    else
  |switch      # OR switch
  |try         # OR try
  |catch       # OR catch, optionally followed by:
    (?:\s*[$A-Za-z_\x7f-\uffff][$\w\x7f-\uffff]*)?  # a variable
  |finally     # OR finally
 ))\s*$        # all as the last thing on a line (allowing trailing space)
|              # ---- OR ---- some new stuff:
^\s*           # a line starting with optional space
(else\b\s*)?   # followed by an optional "else"
(?:            # followed by one of the following:
   if          #    if
  |for         # OR for
  |while       # OR while
  |loop        # OR loop
)\b            #    (as a word)
(?!.*\bthen\b) # ... but NOT followed by "then" on the line
/

In other words (without spaces or comments):

/(?:[({[=:]|[-=]>|\b(?:else|switch|try|catch(?:\s*[$A-Za-z_\x7f-\uffff][$\w\x7f-\uffff]*)?|finally))\s*$|^\s*(else\b\s*)?(?:if|for|while|loop)\b(?!.*\bthen\b)/

If you test this (or something like it) and it works, you should try to push it to ace upstream, and we can patch it to our fork of ace.

from pencilcode.

davidbau avatar davidbau commented on July 19, 2024

Frank - can I also ask you to patch it in to this repo? It's the specific fork of ace we're using for Pencil Code.

https://github.com/PencilCode/pencilcode-ace

from pencilcode.

weihang7 avatar weihang7 commented on July 19, 2024

Seems fixed.

from pencilcode.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.