I'd like to remove colon styling, which typically appears like:
goto:
The code that adds colon styling starts on line 457.
It's not necessary but would be nice if I could remove colon styling only in certain directories like:
/root/project/hi.c
/root/project_remove_colon/hi.c
Thanks!
One way to do this is to set c-label-face-name as a file local variable. For example, in your file /root/project_remove_colon/hi.c you could add the following comment block at the end of the file:
/* Local Variables: */
/* c-label-face-name: font-lock-reference-face */
/* End: */
An issue with this approach, though, is that c-label-face-name is not considered safe as a file-local variable, so when you visit the file, emacs will prompt you like this:
The local variables list in hi.c
contains variables that are risky (**).
Do you want to apply it? You can type
y -- to apply the local variables list.
n -- to ignore the local variables list.
** c-label-face-name : font-lock-reference-face
To avoid this prompt, you could customize safe-local-variable-values to mark the variable c-label-face-name as being safe.
Related
I'd like to add a suffix to all occurrences of a variable in a file (eg. pluralizing a variable number --> numbers).
VSCode offers a multiselect option thru the default "cmd+d", or editor.action.addSelectionToNextFindMatch. However, after I do this over all occurrences of number, the entire variable is selected. I really just need the cursor to be at the very end, so I can add an s. I would like not have to retype numbers.
How can I achieve this?
As an alternative, I use a regex:
\b(var1|var2|var3)\b
And I replace it with the same content $1 (since I capture the variable name in a group with ()) followed by 's': $1s
I would just copy the variable first. So:
Double-click your variable and Ctrl-C
Ctrl-F2 selects all occurences
Ctrl-V and add your 's'
The regex method is better if you have a few variables to change, but not if you have only one or two to change. Really simple to create a macro if you would be doing this a lot - you could get it down to a single keychord.
[This unfortunately selects occurrences of var1 and someOtherVar1 (the Var1 part) - so if this is a problem better to use a regex as it is easier to exclude instances of the var1 term appearing within another word, like someVar1 that you do not intend to change.]
For example this, at the top of a node.js source file:
#!/usr/bin/env node
...or unused local variables, etc.
Late to the party but in VSCode you can write // #ts-ignore just before the line you want to ignore.
It is important to notice that it will just ignore the line after the declaration.
There is more info about it in the official documentation.
For unused local variable, you can configure the user or the workspace settings.
From the preference menu item, choose user/workspace settings:
// Place your settings in this file to overwrite default and user settings.
{
// Unused local variable.
"javascript.validate.lint.unusedVariables": "ignore"
}
As for #!/usr/bin/env node what is the undesirable behavior that you want disable?
You can tell jshint to ignore lines, or just certain rules. Here's how to ignore a line, from http://jshint.com/docs/
// Code here will be linted with JSHint.
/* jshint ignore:start */
// Code here will be ignored by JSHint.
/* jshint ignore:end */
Now, I'm just assuming that Code honors these directive.
You can select suggestion from PROBLEMS by hovering over the red x in the circle and then click on the lamp :
You can do this via inline - e.g.: // eslint-disable-next-line [RULE] on the line prior to the line of code you want it to ignore. The RULE is optional, and will tell it to ignore a specific rule; if you don't specify one, it will tell it to ignore all rules.
Lots of other options available - see the docs for more detail: https://eslint.org/docs/user-guide/configuring#disabling-rules-with-inline-comments.
I'm using emacs (24.3.1) along with cc-mode and hideshow for programming c++. I am working on a project, where the coding styles requires that any keywords present in the header file must be repeated in the source file. In case that this is not allowed by the standard, the keyword must be placed in comments. Let me give you and example:
/* virtual */ void MyAwesomeFunction( int arg, int optarg /* = 0 */ ){
// stuff
}
Obviously there is a comment starting the line. It seems that hideshow can't cope with this sort of formatting. When I call hs-hide-all all code blocks are folded correctly, the same is true if I call hs-hide-block from anywhere within the function. However, if I call hs-hide-block whith point beeing somewhere in the opening line of the function (the first line of my codesnippet) now folding occurs and the error message:
(not enough comment lines to hide)
is printed. The only explicit configuration of hideshow I have done so far is:
(setq hs-hide-comments nil)
However, removing this line makes it even worse: Afterwards not even calling hs-hide-all works properly: all inner blocks are folded, but folding at the function level does not occurs for functions with a leading comment.
Anyone knows how to fix this?
It might help to explicitly hide comments first, either just within the region or throughout the buffer. You can use library hide-comnt.el to do that. A description is here.
For example I write code
if Foo do
# do something
end
And then, I paste in my code many lines.
if Foo do
# do something
# do something
# do something
# do something
# do something
end
How I can fast align added lines?
Do you want to align automatically on insert, or you want to align it later? For later you can use indent-region function (bound to C-M-\). For automatic align on insert you can use following recipe (I don't remember where I took it, so I'll refer to my config) - see lines 45-66. You will need to add more modes to yank-indent-modes, but concrete mode should provide working indent function.
Someplace I saw a snippet of code which told vi to use soft tabs and set the size of a tab. If you put this snippet at the bottom of a source file, then vi would magically use those settings for that file.
What is the syntax and rules for including that snippet in a source file? Can emacs be made to use these settings as well?
You can put this in a comment in your source file:
ex: set softtabstop=4 shiftwidth=4 tabstop=4 expandtab:
The comment syntax depends on the type of the source file.
For C/C++/Java, this would be:
// ex: set softtabstop=4 shiftwidth=4 tabstop=4 expandtab:
For JSP, this would be:
<%-- ex: set softtabstop=4 shiftwidth=4 tabstop=4 expandtab: --%>
This works if it is placed at the beginning of the source file, but I'm not sure that this'll work if placed at the end of it too.
This will not work for emacs. There might be a different way of achieving the same for emacs.
Check out :h modeline.
Example:
/* vim: ai set sw=4 ts=4 */
See :h modelines for how many lines into a file Vim will check for modeline info. The default is to check the first 5 lines.
As far as I know, vi didn't have this capability. You're likely thinking of the modeline feature of Vim. There is similar functionality in emacs, where you can put local variables in the file.
Note that, at least in Vim, modelines have had a history of vulnerabilities. This is primarily due to problematic options being specifically blacklisted instead of only allowing a certain subset of variables to be set in modelines. I'd suggest using a plugin like securemodelines.
Put this in your C++ source file:
// vim: set ft=cpp
The modeline feature looks for the string "vim:" and then executes what follows. Note: this could open up potential exploits if you don't trust the files you are opening, so think twice before enabling this feature.
Okay, first of all, in real vi you do this in the .exrc file.
Second, use
set autoindent tabstop=8 shiftwidth=4
because otherwise vi will insert tabs it thinks are only 4 characters wide. The resulting text file will not look like it makes sense in any other editor.