GithubHelp home page GithubHelp logo

Comments (15)

wbond avatar wbond commented on May 19, 2024 2

Jon and I have not yet discussed ideas surrounding the improvement of dealing with different indentation rules. I would not expect such enhancements to be part of the next dev build. In general, I think we may want a larger change to how indentation rules are implemented and how preferences may affect those.

@keith-hall mentioned recently the idea of working on documenting the current behavior and features surrounding indentation. This would be helpful in us coming up with a more elegant solution for dealing with these sorts of issues moving forward.

from packages.

jrappen avatar jrappen commented on May 19, 2024

from packages.

FichteFoll avatar FichteFoll commented on May 19, 2024

If there was better tmPreferences integration for variables such as these, things like SublimeText/AsciiDoc@c8ea594 could also become feasable. Currently those have a bit too high barrier of entry and would basically require a plugin to walk users through the changes, imo.

from packages.

jrappen avatar jrappen commented on May 19, 2024

@wbond Maybe you could ask Jon to implement some improvements regarding the variables in those TextMate files (see FichteFoll's link) in the next build. I believe this would be a quick fix and require only minor changes? Especially the dropdown lists support would greatly enhance snippets and completions for all languages.

from packages.

jrappen avatar jrappen commented on May 19, 2024

@wbond have you decided, yet?


linking @keith-hall's docs on indentation here, too: https://forum.sublimetext.com/t/everything-you-n-ever-wanted-to-know-about-indentation-in-st3/26207

from packages.

wbond avatar wbond commented on May 19, 2024

No, my focus recently has been on performance issues related to default packages. Unfortunately indentation stuff is somewhat low priority, in the grand scheme of things.

from packages.

jrappen avatar jrappen commented on May 19, 2024

Extended proposal

I'd like to extend:

  • use five variables
    • WHITESPACE_BEFORE
    • WHITESPACE_INSIDE_FIRST
    • WHITESPACE_INSIDE
    • WHITESPACE_INSIDE_LAST
    • WHITESPACE_AFTER

One could argue that WHITESPACE_AFTER doesn't make sense cause it's the same for all styles...but just for clarity's sake to get my point across I included it here.

compare the usage:

return_value func_name(params)${WHITESPACE_BEFORE}{${WHITESPACE_INSIDE_FIRST}func_a();${WHITESPACE_INSIDE}func_b();${WHITESPACE_INSIDE_LAST}}${WHITESPACE_AFTER}$0

for some fake code like (pipe indicates cursor pos for $0):

output: Allman style

return_value func_name(params)
{
    func_a();
    func_b();
}
|

output: Whitesmiths style

return_value func_name(params)
    {
    func_a();
    func_b();
    }
|

output: K-and-R style

return_value func_name(params) {
    func_a();
    func_b();
}
|

output: pico style

return_value func_name(params)
{  func_a();
    func_b(); }
|

compare https://en.wikipedia.org/wiki/Indentation_style

from packages.

jrappen avatar jrappen commented on May 19, 2024

/cc @jsiwek FYI

from packages.

rwols avatar rwols commented on May 19, 2024

I like this proposal a lot; it mirrors the options for brace placement styles in clang-format.

from packages.

jrappen avatar jrappen commented on May 19, 2024

Implementation idea

Using mdpopups works great for feeding it a small code block to use sublime_plugin.ListInputHandler for displaying a preview for each indent style during the selection via the command palette.

Make a package with:

package_root/
    main.py
    indent_styles/
        allman.xml # metadata for copy & paste
        allman.cpp # example code
        gnu.xml
        gnu.cpp
        horstmann.xml
        horstmann.cpp
        ...

and the following code:

#!/usr/bin/env python
# coding: utf-8


import sublime
import sublime_plugin

import os
import mdpopups


PKG_NAME = __package__.split('.')[0]
STYLES_DIR = None
INDENT_STYLE = None


def set_indent_style(name='allman'):

    try:
        styles = [
            'allman',
            'gnu',
            'horstmann',
            'k_and_r',
            'lisp',
            'pico',
            'ratliff',
            'whitesmiths'
        ]

        if name not in styles:
            name = 'allman'

        new_style = sublime.load_resource('{}/{}.xml'\
                                          .format(STYLES_DIR, name))

        with open(INDENT_STYLE, mode='w', newline='\n') as file:
            file.write(new_style)

    except Exception as e:
        print(e)


def check_existance_of_indent_style():

    global INDENT_STYLE
    INDENT_STYLE = os.path.join(sublime.packages_path(),
                                    'User',
                                    'INDENT_STYLE.tmPreferences')

    if not os.path.exists(INDENT_STYLE):
        set_indent_style('allman')


def plugin_loaded():

    check_existance_of_indent_style()

    global STYLES_DIR
    STYLES_DIR = 'Packages/{}/indent_styles'\
                 .format(PKG_NAME)


class IndentStyleSelectionInputHandler(sublime_plugin.ListInputHandler):

    def name(self):
        return 'name'

    def placeholder(self):
        return 'Allman'

    def list_items(self):
        items = [
            ('Allman', 'allman'),
            ('GNU', 'gnu'),
            ('Horstmann', 'horstmann'),
            ('K & R', 'k_and_r'),
            ('Lisp', 'lisp'),
            ('Pico', 'pico'),
            ('Ratliff', 'ratliff'),
            ('Whitesmiths', 'whitesmiths')
        ]
        return items

    def preview(self, value):
        items = [
            'allman',
            'gnu',
            'horstmann',
            'k_and_r',
            'lisp',
            'pico',
            'ratliff',
            'whitesmiths'
        ]
        if value not in items:
            return None

        v = sublime.active_window().active_view()
        code_block = sublime.load_resource('{}/{}.cpp'\
                                          .format(STYLES_DIR, value))
        code_block = '```cpp\n{}\n```'.format(code_block)

        return sublime.Html(mdpopups.md2html(v, code_block))


class ChangeIndentCommand(sublime_plugin.WindowCommand):

    def run(self, name):
        set_indent_style(name)

    def input(self, args):
        if 'name' not in args:
            return IndentStyleSelectionInputHandler()
        return None

from packages.

jeffreyscottgraham avatar jeffreyscottgraham commented on May 19, 2024

Is this plugin done and available somewhere?

from packages.

jrappen avatar jrappen commented on May 19, 2024

@jeffreyscottgraham mdpopups is available as a Sublime Text 3 dependency for your plug-in.

https://packagecontrol.io/docs/dependencies

https://github.com/facelessuser/sublime-markdown-popups

from packages.

jrappen avatar jrappen commented on May 19, 2024

@jeffreyscottgraham did you need help with the implementation on your side?

from packages.

jeffreyscottgraham avatar jeffreyscottgraham commented on May 19, 2024

Thanks no.

from packages.

FichteFoll avatar FichteFoll commented on May 19, 2024

Random thought I had the other day:

This would be easier if snippets could also read variables from other locations, such as a view's settings, or if plugins could inject shellVariables (which are per selector), so they wouldn't have to generate tmPreferences files in some temporary location.

from packages.

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.