Changing Atoms autocomplete - autocomplete

Okay. So Atom installs autocomplete-plus by default. Its quite helpful when I write code, but for example it writes std::cout << "/* message */" << '\n'; when I write cout, but I want it to write std::cout << "/* message */" << std::endl, cause there is a difference between those two, the second one flushes the buffer. How can I make it work my way?

You can specify your desired autocomplete behavior within your snippets.cson file.
Open snippets.cson by going to Edit -> Snippets...
Add the following to the file:
'.source.c':
'cout':
'prefix': 'cout'
'body': 'std::cout << "/* ${1:message} */" << std::endl$2'
The first line selects which grammar to activate on (C in this case, you can find more here).
The second line is a description of the snippet; it could be anything.
The third line (prefix) specifies what you would have to type in a C file for the snippet to work.
In this example, typing cout in a C file while show the description in the autocomplete menu and allow for tab-completion. The last line specifies what the snippet should expand to. Use the $ syntax to specify tab ordering.
Note, you can specify default values for tab stops within the snippet using syntax like ${1:message}. In this case, the snippet will expand and automatically select the text message for rapid editing. Hitting tab again will proceed to tab stop 2, or the end of the line.
Note, you can specify any number of additional snippets for each grammar, as in:
'.source.c':
'cout':
'prefix': 'cout'
'body': 'std::cout << "/* ${1:message} */" << std::endl$2'
'Another snippet description':
'prefix': 'something'
'body': 'Something is ${1:nice}'

Related

How to automatically add a newline after the program's output on the terminal?

Whenever I run the code, the output will be printed out, and immediately after the prompt for the path will be printed on the same line.
How do I display the path in a new line after printing the output?
Add \n to print a new line character like this:
printf("asdfg\n");
The \ indicates an escape character: there are other possible values (details here)
Go to your setting, type "code-runner.executorMap" this in search-box
click edit in settings.johnson
Click on Edit in settings.json
then add
"; echo -e"
At the end of line whatever language you code

Prevent typing more than one space in VSCode with the exception of the start of a line

I want to restrict more than one space to be typed in VS Code unless it is before the first non-space in a line.
Additionally, if you open a file that was like that already I want those multi-spaces to be removed when saved.
Here is Trailing Spaces - it looks like a workaround for what you're looking for.
You are really looking for a formatter for these two functionalities: format on type and format on save. However, you can get the first function - "restrict more than one space to be typed in Visual Studio Code unless it is before the first non-space in a line" with the help of an extension HyperSnips.
For setting up that extension, see https://stackoverflow.com/a/62562886/836330
Then say in your all.hsnips file put this:
snippet `(\S)( ){2,}` "found 2 consecutive spaces with no non-whitespace characters preceding" A
``rv = m[1] + " "``
endsnippet
That will work in all language files, you can restrict it to certain languages as mentioned in that answer linked to.
Run the command HyperSnips: Reload Snippets.
Basically you are running a snippet that uses (\S)( ){2,} as the prefix. It will be triggered whenever it detects two or more spaces in a row and will replace them with just one!
The snippet will only be triggered if those two spaces are preceded by a non-whitespace (so some character) and thus your second requirement that multiple spaces be allowed before the first character in a line.
It also works between existing words if you go there to edit - you will not be able to add a space to an existing space!!
Demo:
The gif doesn't really capture it well but every time I am trying to write a second consecutive space it deletes it leaving only the one.
Your second question was "if you open a file that was like that already I want those multispaces to be removed when saved".
I suggest running a script on save. Using, for example, Trigger on Task Save. In your settings:
"triggerTaskOnSave.tasks": {
"stripSpaces": [
"**/*.txt" // here restricting it to .txt files
],
},
This runs the stripSpaces task whener you save a .txt file. That task (in tasks.json) could look like:
{
"label": "stripSpaces",
"type": "shell",
"command": "awk -f stripSpaces.awk ${relativeFile} > temp; mv temp ${relativeFile}"
}
which runs this stripSpaces.awk script:
# strip multiple consecutive spaces from a file
# unless they are the beginning of the line
BEGIN {
regex="\\S( ){2,}";
}
{
if (match($0,regex)) {
gsub(/( ){2,}/, " ")
print
}
else print
}
Demo:

How to prevent line breaks (general)

I'm writing a text on C++. But often the line breaks after the first "+", so I get C+
+
This is just an example. How can I prevent line breaking of arbitrary parts in my odt doc?
There is no formatting option at the moment
Use the Unicode Character U+2060. Insert it an every point the line breaks, but it shouldn't. It glues two parts together.
Example for "C++" ( | represents the text cursor )
C|++
Press Ctrl+Shift+U
u will appear on the screen
Type in 2060
Press Enter
Now the line won't break between C and +.
Move cursor: C+|+
repeat process

LyX->Rnw conversion automatically inserts ligature breaks between repeated "<" characters

The title says it all; the screenshot below gives the gory details. (The .Rnw file in the temporary buffer folder is identical to the LaTeX Source in the image.) As you can imagine, knit() won't knit this crap. I cannot for the life of me figure out how to make those ligature breaks go away.
So I guess my question is... Help?
You probably did not read the manual, which has instructions on how to input R code in a LyX document: either through Insert --> TeX Code (Ctrl + L), or use the Chunk environment from the drop-down menu on the toolbar. You should not type R code as normal paragraphs in LyX.

What useful macros have you created in Netbeans? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 9 years ago.
I use Netbeans (nightly build) for Ruby on Rails development and I'm looking to beef up my macros. I've created a few myself:
copy identifier:
select-identifier copy-to-clipboard
paste clipboard over identifier:
select-identifier paste-from-clipboard
double quote element
select-element-next "\""
single quote element:
select-element-next "'"
But I'm looking for other useful ones and Google is giving me nothing.
The record macro feature usually doesn't work too well so I'd rather just "write" the macros myself but I can't even find a reference that lists what commands (like "select-identifier") are actually available.
Any Netbeans macro gurus out there?
Here is a list of macro codes with short explanations. Might be useful for someone.
Update: replaced old link with one to the Netbeans site and included the macro list in here.
abbrev-debug-line Debug Filename and Line Number
adjust-caret-bottom Move Insertion Point to Bottom
adjust-caret-center Move Insertion Point to Center
adjust-caret-top Move Insertion Point to Top
adjust-window-bottom Scroll Insertion Point to Bottom
adjust-window-center Scroll Insertion Point to Center
adjust-window-top Scroll Insertion Point to Top
all-completion-show Show All Code Completion Popup
annotations-cycling Annotations Cycling
beep Beep
build-popup-menu Build Popup Menu
build-tool-tip Build Tool Tip
caret-backward Insertion Point Backward
caret-begin Insertion Point to Beginning of Document
caret-begin-line Insertion Point to Beginning of Text on Line
caret-begin-word Insertion Point to Beginning of Word
caret-down Insertion Point Down
caret-end Insertion Point to End of Document
caret-end-line Insertion Point to End of Line
caret-end-word Insertion Point to End of Word
caret-forward Insertion Point Forward
caret-line-first-column Insertion Point to Beginning of Line
caret-next-word caret-next-word
caret-previous-word caret-previous-word
caret-up Insertion Point Up
collapse-all-code-block-folds Collapse All Java Code
collapse-all-folds Collapse All
collapse-all-javadoc-folds Collapse All Javadoc
collapse-fold Collapse Fold
comment Comment
complete-line Complete Line
complete-line-newline Complete Line and Create New Line
completion-show Show Code Completion Popup
copy-selection-else-line-down Copy Selection else Line down
copy-selection-else-line-up Copy Selection else Line up
copy-to-clipboard Copy
cut-to-clipboard Cut
cut-to-line-begin Cut from Insertion Point to Line Begining
cut-to-line-end Cut from Insertion Point to Line End
default-typed Default Typed
delete-next Delete Next Character
delete-previous Delete Previous Character
documentation-show Show Documentation Popup
dump-view-hierarchy Dump View Hierarchy
expand-all-code-block-folds Expand All Java Code
expand-all-folds Expand All
expand-all-javadoc-folds Expand All Javadoc
expand-fold Expand Fold
fast-import Fast Import
find-next Find Next Occurrence
find-previous Find Previous Occurrence
find-selection Find Selection
first-non-white Go to First Non-whitespace Char
fix-imports Fix Imports
format Format
generate-code Insert Code
generate-fold-popup Generate Fold Popup
generate-goto-popup Generate Goto Popup
generate-gutter-popup Margin
goto Go to Line...
goto-declaration Go to Declaration
goto-help Go to Javadoc
goto-implementation Go to Implementation
goto-source Go to Source
goto-super-implementation Go to Super Implementation
in-place-refactoring Instant Rename
incremental-search-backward Incremental Search Backward
incremental-search-forward Incremental Search Forward
insert-break Insert Newline
insert-date-time Insert Current Date and Time
insert-tab Insert Tab
introduce-constant Introduce Constant...
introduce-field Introduce Field...
introduce-method Introduce Method...
introduce-variable Introduce Variable...
java-next-marked-occurrence Navigate to Next Occurrence
java-prev-marked-occurrence Navigate to Previous Occurrence
jump-list-last-edit Last edit
jump-list-next Forward
jump-list-prev Back
last-non-white Go to Last Non-whitespace Char
make-getter Replace Variable With its Getter
make-is Replace Variable With its is* Method
make-setter Replace Variable With its Setter
match-brace Insertion Point to Matching Brace
move-selection-else-line-down Move Selection else Line down
move-selection-else-line-up Move Selection else Line up
org.openide.actions.PopupAction Show Popup Menu
page-down Page Down
page-up Page Up
paste-formated Paste Formatted
paste-from-clipboard Paste
redo Redo
reindent-line Re-indent Current Line or Selection
remove-line Delete Line
remove-line-begin Delete Preceding Characters in Line
remove-selection Delete Selection
remove-tab Delete Tab
remove-trailing-spaces Remove Trailing Spaces
remove-word-next remove-word-next
remove-word-previous remove-word-previous
replace Replace
run-macro Run Macro
scroll-down Scroll Down
scroll-up Scroll Up
select-all Select All
select-element-next Select Next Element
select-element-previous Select Previous Element
select-identifier Select Identifier
select-line Select Line
select-next-parameter Select Next Parameter
select-word Select Word
selection-backward Extend Selection Backward
selection-begin Extend Selection to Beginning of Document
selection-begin-line Extend Selection to Beginning of Text on Line
selection-begin-word Extend Selection to Beginning of Word
selection-down Extend Selection Down
selection-end Extend Selection to End of Document
selection-end-line Extend Selection to End of Line
selection-end-word Extend Selection to End of Word
selection-first-non-white Extend Selection to First Non-whitespace Char
selection-forward Extend Selection Forward
selection-last-non-white Extend Selection to Last Non-whitespace Char
selection-line-first-column Extend Selection to Beginning of Line
selection-match-brace Extend Selection to Matching Brace
selection-next-word selection-next-word
selection-page-down Extend Selection to Next Page
selection-page-up Extend Selection to Previous Page
selection-previous-word selection-previous-word
selection-up Extend Selection Up
shift-line-left Shift Line Left
shift-line-right Shift Line Right
split-line Split Line
start-macro-recording Start Macro Recording
start-new-line Start New Line
stop-macro-recording Stop Macro Recording
switch-case Switch Case
to-lower-case To Lowercase
to-upper-case To Uppercase
toggle-case-identifier-begin Switch Capitalization of Identifier
toggle-comment Toggle Comment
toggle-highlight-search Toggle Highlight Search
toggle-line-numbers Toggle Line Numbers
toggle-non-printable-characters Toggle Non-printable Characters
toggle-toolbar Toggle Toolbar
toggle-typing-mode Toggle Typing Mode
tooltip-show Show Code Completion Tip Popup
uncomment Uncomment
undo Undo
word-match-next Next Matching Word
word-match-prev Previous Matching Word
I needed to surround text fragments with HTML tags, but couldn't figure out how to do it quickly, so I came up with this macro:
cut-to-clipboard "<strong>" paste-from-clipboard "</strong>"
Simple, clean, and you can put any tag/text you want. Give it a shortcut like Alt+B and you have quick way to insert HTML
for php add semicolon to end line ("complete line")
but keep your cursor at the current point,
so you can keep typing the rest of the line
split-line
caret-down
caret-end-line ";"
caret-begin-line
selection-begin-line remove-selection
delete-previous
This is my first netbeans macro.
"echo '< pre >';print_r();die();"
my shortcut key => Alt+A
for this you can use any shortcut
Oh well, just experimenting with netbeans.
I add a simple new macro for netbeans.
name: "scrollup_newline"
code:
insert-break
scroll-up
It works well, so every i press enter, the editor move one line down. This way i can code and have the caret in the middle of the editor.
This is for HTML. I just made:
caret-begin-line "<li>" caret-end-line "</li>" caret-down
Mapped it to ctrl+shift+L This is my first netbeans macro. Later maybe I can make it work for an entire selection somehow.
Edit: Can't figure out doing it for selections, but adding "caret-down" at the end was almost as good.
Here is the macro I wrote today. I am very much missing an "extract method" or "introduce method" refactoring in PHP, so I wrote this macro. I know this is far less complex than the refactorings in Java, but it can be used and it saves a few copy/pastes and writing repetitive code.
cut-to-clipboard
"$this->UNNAMED_METHOD();"
collapse-fold
caret-end-line caret-backward caret-end-line insert-break
"private function UNNAMED_METHOD() {"insert-break
paste-from-clipboard insert-break
This macro inserts -moz- and -webkit- prefixed equivalents of a css3 style rule:
caret-end-line selection-begin-line copy-to-clipboard caret-backward insert-break caret-up "-webkit-" paste-from-clipboard insert-break "-moz-" paste-from-clipboard
insert-date-time remove-word-previous remove-word-previous
Mapped to CTRL+SHIFT+D to insert the short date, so useful cause I like to date my comments / TODOs but often don't know the date!
Although I think Code Templates and more useful, for example:
// <editor-fold defaultstate="collapsed" desc="${cursor}">
and
// </editor-fold>
Mapped to 'fold' then tab and 'endfold' then tab respectively.
Also
JOptionPane.showMessageDialog(null, "${EXP default="Got here"}");
Mapped to 'jop' then tab is handy.
Probably not the most efficient but it helps me out lol
"(() ? : );"
caret-backward
caret-backward
caret-backward
caret-backward
caret-backward
caret-backward
caret-backward
caret-backward
As one can see, this is for PHP quick conditionals. This then places the cursor in the spot where you start typing the condition. Perfect no matter where your throwing it into. I put this to Ctrl+NUMPAD0 for quick typing access. I orignally had it to two TABs but that quickly got annoying haha
I often like to have commas as the first character separating properties or list items in JavaScript; like so:
var foo = {
a : 'a'
//, b : 'B' //todo: make lcase
, c : 'c'
};
Sometimes, I either forget to do this, or have a mass of text to update. To fix these quickly, I bound the keyboard shortcut C-, C-, -- That's two presses of ',' while holding CTRL key -- to:
caret-end-line selection-next-word selection-next-word " " caret-backward caret-backward insert-break
I found Code Templates to be very useful, especially this one (for HTML):
<${tag}>${cursor}</${tag}>
The abbreviation is "tt", and it can also surround any text with custom tag, when called by the code template menu.
<${param_name default="tag"}${cursor}>
${selection}
</${param_name default="tag"}>
This one will surround anything with any tag. Select something, then Alt+F3, then just select this template from the menu. After that type the tag you want, e.g. "div".
This is a code template for creating a static logger in a class using SLF4J. I tie it to "Log".
private static final ${loggerType type="org.slf4j.Logger" default="Logger" editable="false"} log = ${loggerFactoryType type="org.slf4j.LoggerFactory" default="LoggerFactory" editable="false"}.getLogger(${classType editable="false" currClassName default="getClass()"}.class);
This makes a log.debug line which I tie to "log":
log.debug("${message}", "${variables}");