Comments (15)
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.
from packages.
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.
@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.
@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.
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.
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.
/cc @jsiwek FYI
from packages.
I like this proposal a lot; it mirrors the options for brace placement styles in clang-format.
from packages.
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.
Is this plugin done and available somewhere?
from packages.
@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.
@jeffreyscottgraham did you need help with the implementation on your side?
from packages.
Thanks no.
from packages.
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)
- [Rust] Function call with with turbofish annotation missing scope
- [Markdown] LaTeX code block not highlighted HOT 8
- [Swift] Initial support HOT 6
- [C] Add more scopes for variable assignment HOT 1
- [Ruby] def end syntax pairing highlight gets confused by =begin =end comment pairs HOT 1
- [C#] Primary constructor
- [C#] required field
- [CSS] Different color for inheritable properties HOT 6
- [PHP] Named parameters affecting calls to closures in arrays
- [C++] Go to function append the return type of the function to the function name if separated on a different line if the return type is a custom type HOT 4
- [Python] Wrong highlighting of assignment after line continuation with string
- [CSS] Nesting at-rules (eg. `@media`) breaks syntax highlighting HOT 2
- [Batch] `> ...` is valid with `pause`
- [Python] Class name highlight HOT 1
- [BibTeX] Expand Selection does not work properly HOT 1
- [Python] Trailing `\\"` in `R"...\\"` should not be char escape
- [C] New C23 keywords
- view.replace not working
- [OCaml] "Quoted string" literals are not recognized HOT 2
- [C/C++] remove switch case auto unindent HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from packages.