Git Product home page Git Product logo

Comments (6)

ViktorQvarfordt avatar ViktorQvarfordt commented on May 25, 2024

We currently have

<key>decreaseIndentPattern</key>
<string>^\s*(end|else|elseif|catch|finally).*$</string>

<key>increaseIndentPattern</key>
<string>^\s*(if|else|elseif|for|while|begin|function|type|macro|immutable|try|catch|finally|let|quote|do).*$</string>

in https://github.com/JuliaEditorSupport/Julia-sublime/blob/master/Indentation.tmPreferences.

Note the ^\s*, i.e. begin cannot be preceded by non-space characters in order to trigger auto-indent. One could of course remove ^\s*, but this might open up for problems such as auto-indent being triggered if you type 'begin' in a string.

What do you think about this?

from julia-sublime.

iamed2 avatar iamed2 commented on May 25, 2024

I looked at Ruby because it has a similar syntax. They go all in:

<?xml version="1.0" encoding="UTF-8"?>
<plist version="1.0">
<dict>
	<key>name</key>
	<string>Indent</string>
	<key>scope</key>
	<string>source.ruby</string>
	<key>settings</key>
	<dict>
		<key>decreaseIndentPattern</key>
		<string>^\s*([}\]]\s*$|(end|rescue|ensure|else|elsif|when)\b)</string>
		<key>increaseIndentPattern</key>
		<string>(?x)^
		(\s*
			(
				module|class|def
				|unless|if|else|elsif
				|case|when
				|begin|rescue|ensure
				|for|while|until
				|
				(?=.*? \b(do|begin|case|if|unless)\b )
				# the look-ahead above is to quickly discard non-candidates
				(
					"(\\.|[^\\"])*+"      # eat a double quoted string
					| '(\\.|[^\\'])*+'    # eat a single quoted string
					| [^#"']              # eat all but comments and strings
				)*
				(
					\s   (do|begin|case)
					| [-+=&amp;|*/~%^&lt;&gt;~](?&lt;!\$.) \s*+ (if|unless)
				)
			)\b
			(?! [^;]*+ ; .*? \bend\b )
			|
			(
				"(\\.|[^\\"])*+"          # eat a double quoted string
				| '(\\.|[^\\'])*+'        # eat a single quoted string
				| [^#"']                  # eat all but comments and strings
			)*
			(
				\{ (?!  [^}]*+ \} )
				| \[ (?! [^\]]*+ \] )
			)
		).*$
		</string>
	</dict>
</dict>
</plist>

from julia-sublime.

iamed2 avatar iamed2 commented on May 25, 2024

Another option that wouldn't exactly fix this but would fix my case would be to have a snippet for begin-end, if-end, etc. that would mimic the behaviour of {} in e.g., C. begin snippet would generate begin end with the cursor in the middle, and then pressing ENTER would expand to (using my example as a template):

    1 + begin
        # cursor here
    end

from julia-sublime.

ViktorQvarfordt avatar ViktorQvarfordt commented on May 25, 2024

Woah, looks interesting. I don't have time to look at this now. If you want, feel free to tweak the ruby version to work with Julia and submit at pull request. Regarding the snippet, you can add that manually, I don't think that should be part of the package.

Although, perhaps it would be nice to have snippets for all syntax that contains mandatory closing words (such as begin-end, if-end, while-end etc.). What do you think about this? Perhaps it would be annoying, perhaps one often re-writes code and types begin while end is already inserted, this would cause double ends...

from julia-sublime.

ViktorQvarfordt avatar ViktorQvarfordt commented on May 25, 2024

I feel discouraged from adding indentation regex similar to Ruby (it's quite messy, I prefer simplicity). I've changed my mind regarding a snippet for begin, it's a splendid idea that fixes this issue. I've pushed commit 54f5325 which adds such a snippet.

Feel free to reopen this issue, or open new ones if you feel anything can be improved.

from julia-sublime.

iamed2 avatar iamed2 commented on May 25, 2024

Works like a charm, thanks :)

I love the turnaround on Sublime package releases! I could just update within the editor with no fuss.

from julia-sublime.

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.