Custom tab size based on file extension - atom-editor

To get along better with my coworkers, I have atom configured with 2-space tabs, but in some files, I prefer 4. I'm trying to figure another file type, in this case, my Foo.pro files that are created with Qt Creator.
I've tried a few dozen things, and nothing seems to work. I'm editing my ~/.atom/config.cson and then restarting atom, and there's no change.
Here's my latest attempt:
"*":
core:
customFileTypes:
"source.pro": [
"pro"
]
disabledPackages: [
"autocomplete-plus"
"markdown-preview"
"markdown-preview-plus"
"spell-check"
]
telemetryConsent: "limited"
themes: [
"atom-light-ui"
"one-light-syntax"
]
editor: {}
"exception-reporting":
userId: "283f523f-3348-4956-97f6-a73675e6e9c6"
"tree-view":
hideVcsIgnoredFiles: true
welcome:
showOnStartup: false
".basic.html.text":
editor:
tabLength: 4
".html.source":
editor:
tabLength: 4
".source.pro":
editor:
tabLength: 4
".shell.source":
editor:
tabLength: 4
".shtml.source":
editor:
tabLength: 4
I'm fairly sure some of these others aren't working, either. Within Atom, if I open my .pro file and do Alt-Cmnd-P, it says the file type is text.plain.null-grammar. And tab width is still 2 characters. So clearly I'm doing something wrong.
You'll notice I'm attempting to define a custom file type (way at the top) and then define the tab length (near the bottom).

It seems like you need to install a grammar for .pro files, for example language-qtpro, otherwise the source.pro scope won't be active.
(I believe this works because of the fileTypes field of a grammar package, which activates the scopeName field.)

It appears, that Atom reverses the scopes for the language in config.cson, so rather than using .source.pro it should be .pro.source (as with the others in your example). At least that's what it does, when you set up indentation in the package settings for a language.
Since you mentioned that you want to get along better with colleagues: Have you looked into using the editor-agnostic EditorConfig standard to share indentation settings with them? Whenever your project contains an .editorconfig file, that will override your personal preferences that you would use when no such file exists. EditorConfig is supported by many editors, directly or through plugins.

Related

Why plugin z of zsh is not active inside the .zshrc?

I installed oh my zsh and zsh auto suggestion. Then I read here (https://www.sitepoint.com/zsh-tips-tricks/) about z zsh, an interesting plugin. And I really wanted to install it. So I put the plugin inside my .zshrc file. But the plugin feature is not active, it's not yellow like source command or alias (and those are properly working). I tried to change place of the plugin line (after / before source), but it didn't work. I did'nt understand the first line. My .zshrc, if someone could help...:
export PATH=$HOME/bin:/usr/local/bin:$PATH
export ZSH="/home/yanalolux/.oh-my-zsh"
ZSH_THEME="ys"
. /home/yanalolux/z.sh
source $ZSH/oh-my-zsh.sh
plugins=(z zsh-autosuggestions)
plugins=(zsh-autosuggestions)
In your .zshrc you have the following two lines:
plugins=(z zsh-autosuggestions)
plugins=(zsh-autosuggestions)
The second line remove the z plugin. You should have only one line with:
plugins=(z zsh-autosuggestions)
According to the ZSH-z plugin Github homepage:
ZSH-z is a command line tool that allows you to jump quickly to directories that you have visited frequently in the past, or recently -- but most often a combination of the two (a concept known as "frecency"). It works by keeping track of when you go to directories and how much time you spend in them. It is then in the position to guess where you want to go when you type a partial string, e.g. z src might take you to ~/src/zsh.

Customizing Powerleve10k prompt

I just added the Powerlevel10k theme to my zsh and i'm trying to configure certain parts.
It currently looks like this:
The ~/.p10k.zsh has a lot of configurations done and I've been trying to change certain things but i'm not there yet.
I don't want to print the whole path on the left prompt, just the directory. Also, not sure what those numbers indicate in the git section. And the right prompt is displaying my ruby version, although I haven't used Ruby in ages and want to change it to a different setting.
I've tried adding a PS1=... to .zshrc but it seems to be overriden by the P10K config file.
Any suggestions?
Display only the last directory segment
Open ~/.p10k.zsh.
Search for POWERLEVEL9K_SHORTEN_STRATEGY.
Change the value of this parameter to truncate_to_last.
Alternatively, change the value of POWERLEVEL9K_DIR_MAX_LENGTH to 1. This will maximally shorten current directory while keeping the transformation reversible. You can restore the original directory by copy-pasting the shortened directory to the command line and pressing TAB.
Ruby version
Powerlevel10k has several prompt segments that can display Ruby version. By default only those are enabled that display Ruby version when it has been manually overridden by some tool (e.g., rbenv or asdf).
To remove Ruby version from prompt:
Open ~/.p10k.zsh.
Search for POWERLEVEL9K_RIGHT_PROMPT_SEGMENTS.
Remove or comment out the following elements: rbenv, rvm and asdf.
Alternatively (and perhaps preferably), find out which tool is overriding Ruby version for you and remove the override if you no longer need it.
shorten dir segment to show only deepest directory
To show only last n significant path segments, you can set following in your config .zshrc, e.g n=1 means show only last folder in present working directory:
POWERLEVEL9K_SHORTEN_DIR_LENGTH=1
See https://stackoverflow.com/a/49027654
explain Git symbols
The question/exclamation mark in Git segment (vcs segment, next to path) means the number of files untracked (?) and unstaged (!). For detailed description see What do different symbols in Git status mean?
change version segment
You can change the version segment (on the right of prompt) to reflect another tool. For example to replace shown ruby version by python version replace the element within right promt elements in your config .zshrc:
POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(rbenv)
by
POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(pyenv)

How do I stop Atom from getting rid of all the empty space at the bottom when I save? [duplicate]

I use Sublime text. Now I am trying Atom. When I save any file in sublime text it does not include any trailing blank line. But saving any file in Atom leaves a trailing blank line. How do I force Atom not to leave trailing white spaces?
Under your Atom Preferences go to Packages tab and search for whitespace. Click on the whitespace package and uncheck Ensure Single Trailing Newline option
On global level this can be changed using settings in Whitespace package, but if you want to disable it for a specific language you have to use syntax-scoped properties in your config.cson.
'.text.html.php': # php overrides
whitespace:
ensureSingleTrailingNewline: false
removeTrailingWhitespace: false
'.source.ruby': # ruby overrides
whitespace:
ensureSingleTrailingNewline: false
removeTrailingWhitespace: false
To see the scope of language go to Packages tab and search for your language.
Click on the settings of the language package and you can see the scope:
Go to packages and find "whitespace", go to it's settings and uncheck the last checkbox.
Settings
Checkbox
To add to Dan Moldavan's answer.
I experienced this issue when working on a Rails Application.
I added a .editorconfig file with the following properties:
# editorconfig.org
root = true
[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
[*.md]
trim_trailing_whitespace = false
And I added a .gitattributes file with the following properties:
# Enforce Unix newlines
* text=auto eol=lf
And then my Atom Editor threw a problem:
1 problem affecting .gitattributes
whitespace: It is possible that the "whitespace"-package prevents the following properties from working reliably: insert_final_newline, trim_trailing_whitespace. You may try reconfiguring or disabling the "whitespace"-package to solve regarding issues.
Here's how I fixed it:
Open your Atom Editor
Go to Edit > Preferences > Packages
Type in whitespace
Click on the package that shows up
Untick the following:
Ensure Single Trailing Newline
Ignore Whitespace On Current Line
Leave Ignore Whitespace Only Lines unticked
Save and close the settings.
That's all.
I hope this helps

Atom - Force Tab Width 2

I just switched from Sublime Text to Atom in order to turn completely open source.
I have trouble with something very very simple: I want Atom to use always (!) and under any circumstances tab width 2 and replace tab with spaces. This setting is so simple in gedit or Sublime Text, but no matter what I am trying: When I start a new file, tab size is 2 (good!). When I use an existing file, tab size is sometimes 4. I find that a bit annoying.
My current setting in Editor are seen in the screenshot:
There is more than one tab setting
Each package (such as python-language) has its own tab setting(s). Whether the language uses the global default or its own default is up to whoever created the package, but you can generally override it.
In your screenshot, you have set the "Tab Type" to "soft". That will take care of using spaces rather than tabs. You have left the default tab width of 2. That is your global setting.
Now, if you look under "Packages" and search for "python" you will find a package named "language-python". Click on its settings button and you will find a number of syntax-specific settings.
Python Grammar
Python Console Grammar
Python Traceback Grammar
Regular Expressions (Python) Grammar
Each of those grammars has its own Tab Length setting. You can set them explicitly to 2 here to override the package's default. (You probably mostly care about the first one, Python Grammar.)
Python is different
In the case of Python, the package is explicitly configured to default to 4 spaces, probably because Python is very opinionated about whitespace, and PEP 8 recommends 4-space indents. You can see the default package setting here in the package's source:
https://github.com/atom/language-python/blob/master/settings/language-python.cson
'autoIndentOnPaste': false
'softTabs': true
'tabLength': 4
This overrides the global default. That's why Python Grammar does not honor the global tab width, the way that most packages do.
Sometimes there are package overrides
Additionally, certain packages will override your settings for syntax reasons. For example, language-make will override and use real tabs instead of spaces, because that is required by make.
In the case of Python, there is an override to use spaces. The language-python settings page offers a spot for you to change the indentation level, but it does not offer a way to switch to using tab characters. (That's probably justifiable, as tab characters and mixed indentation in Python are a very common cause of difficult-to-debug syntax errors.)
You might need to reload
Lastly, sometimes settings don't take effect completely until you reload the Atom window. You can use the Window: Reload command to do so. Or using the keyboard:
Mac: CtrlOptCmdL
Windows/Linux: CtrlAltR
This is what worked for me.
Disable all non-default packages
Open ~/.atom/config.cson, and append this (same level than the "*" element)
:
".python.source":
editor:
autoIndent: true
tabLength: 2
Re-enable all packages.
I got this help from someone else. Not my own discovery. However, for confidentiality, I cannot cite the source.
Based on soham's answer, I found that setting all tabLength: fields in ~/.atom/config.cson (assuming osx) to your desired length solved the problem.

Compile LESS files with source maps

How can I compile a LESS file to output a source map file (.css.map) in addition to a CSS file? Is there a way to do it on both command line (NodeJS's lessc) and on any GUI-based programs?
Update: New shortest answer
The docs have been updated! As new features hit LESS, sometimes the docs lag behind a bit, so if you're looking for bleeding-edge features, you're still probably better off running lessc (see longer answer) and checking what pops out of the help text.
http://lesscss.org/usage/
Short answer
You're looking for any number of the following options from the command line:
--source-map[=FILENAME] Outputs a v3 sourcemap to the filename (or output filename.map)
--source-map-rootpath=X adds this path onto the sourcemap filename and less file paths
--source-map-basepath=X Sets sourcemap base path, defaults to current working directory.
--source-map-less-inline puts the less files into the map instead of referencing them
--source-map-map-inline puts the map (and any less files) into the output css file
--source-map-url=URL the complete url and filename put in the less file
As I write this I'm not aware of any GUI options that generate maps (source maps were only added to LESS in the last few months) -- sorry to not have any better news. I'm sure they'll add support in as they update over the next year.
Longer answer
If you run lessc from the command line without any parameters it will give you all the options. (In my experience, this is more up to date than their documentation, so it'll at least get you pointed in the right direction.) with all the most recent map stuff included.
The easiest combo to use for dev is --source-map-less-inline --source-map-map-inline as that will give you your source maps embedded in your output css.
If you'd like to add a separate map file, you can use --source-map which, from my.less will output my.css and my.css.map
For reference: when I run my copy (v 1.6.1 at the moment) I get
usage: lessc [option option=parameter ...] <source> [destination]
If source is set to `-' (dash or hyphen-minus), input is read from stdin.
options:
-h, --help Print help (this message) and exit.
--include-path=PATHS Set include paths. Separated by `:'. Use `;' on Windows.
-M, --depends Output a makefile import dependency list to stdout
--no-color Disable colorized output.
--no-ie-compat Disable IE compatibility checks.
--no-js Disable JavaScript in less files
-l, --lint Syntax check only (lint).
-s, --silent Suppress output of error messages.
--strict-imports Force evaluation of imports.
--insecure Allow imports from insecure https hosts.
-v, --version Print version number and exit.
-x, --compress Compress output by removing some whitespaces.
--clean-css Compress output using clean-css
--clean-option=opt:val Pass an option to clean css, using CLI arguments from
https://github.com/GoalSmashers/clean-css e.g.
--clean-option=--selectors-merge-mode:ie8
and to switch on advanced use --clean-option=--advanced
--source-map[=FILENAME] Outputs a v3 sourcemap to the filename (or output filename.map)
--source-map-rootpath=X adds this path onto the sourcemap filename and less file paths
--source-map-basepath=X Sets sourcemap base path, defaults to current working directory.
--source-map-less-inline puts the less files into the map instead of referencing them
--source-map-map-inline puts the map (and any less files) into the output css file
--source-map-url=URL the complete url and filename put in the less file
-rp, --rootpath=URL Set rootpath for url rewriting in relative imports and urls.
Works with or without the relative-urls option.
-ru, --relative-urls re-write relative urls to the base less file.
-sm=on|off Turn on or off strict math, where in strict mode, math
--strict-math=on|off requires brackets. This option may default to on and then
be removed in the future.
-su=on|off Allow mixed units, e.g. 1px+1em or 1px*1px which have units
--strict-units=on|off that cannot be represented.
--global-var='VAR=VALUE' Defines a variable that can be referenced by the file.
--modify-var='VAR=VALUE' Modifies a variable already declared in the file.
-------------------------- Deprecated ----------------
-O0, -O1, -O2 Set the parser's optimization level. The lower
the number, the less nodes it will create in the
tree. This could matter for debugging, or if you
want to access the individual nodes in the tree.
--line-numbers=TYPE Outputs filename and line numbers.
TYPE can be either 'comments', which will output
the debug info within comments, 'mediaquery'
that will output the information within a fake
media query which is compatible with the SASS
format, and 'all' which will do both.
--verbose Be verbose.
If the command line doesn't suite you, Grunt is great at this type of thing. You can configure the grunt-contrib-less plugin to generate inline maps with a config like this:
less: {
options: {
sourceMap:true,
outputSourceFiles: true
},
lessFiles: {
expand: true,
flatten:false,
src: ['**/*.less'],
dest: ['dist/'],
ext: '.css',
}
},
https://github.com/gruntjs/grunt-contrib-less
Example to Create Map and CSS file from Less File
Install latest Node JS and go to command prompt and run npm install less, Now less installed successfully
Go to Command Prompt and move to less file folder that we are going to create
For e.g., I am going to change HelloWorld [Less File]
In Command prompt go to C:\Project\CSS or give the correct path in the below command.
Run following Command in Command Prompt
lessc HelloWorld.less HelloWorld.css --source-map=HelloWorld.css.map –verbose
Now CSS and Map file is generated in the respective folder.
For more reference check the link : royalarun.blogspot.com

Resources