I'm using emmet-mode in Emacs24.
I want to expand php to <?php ?>, but Emmet doesn't support php abbreviation.
I thought if I insert a line (puthash "php" "<?php ?>;" tbl) between some other addreviation, but it doesn't work. Above all I don't want to write directly emmet-mode.el.
How can I define my abbreviation outside of mode elisp file?
I would use yasnippet for that. Anyway, for emmet-mode:
(puthash "pp" "<?php ${child} ?>" emmet-tag-snippets-table)
As far as I understand, all the preferences for emmet-mode is contained in the hash table emmet-snippets, it then contains nested hash table for per mode specific snippets and aliases.
emmet-snippets = {
"html": {
"snippets": {...}
"aliases": {...}
},
"css": {
"snippets": {...}
"aliases": {...}
}
}
M-x add-mode-abbrev works here with emmet-mode.
There is an inconvenience from add-mode-abbrev, as its uses backward-word internally to catch the expansion wanted. Thus call it without numeric argument, which will default to numeric arg 1, it will bind "php ?>" as expansion. Than M-x edit-abbrevs RET and fix that.
Related
To match my company's coding standards, I'm making custom snippets like so:
// php.json
{
"If block": {
"prefix": ["if"],
"body": ["if ( ${1:condition} )", "{", "\t$0", "}"],
"description": "if block",
},
// ...
}
Then, when I type if + Tab, I have two suggestions:
I'm forced to press enter to actually select the first one, which is my custom made snippet ; the second being PHP's default snippet.
Is there a way to actually ignore PHP's default snippets in case I have the exact same prefix?
Context: The Golang VS Code extension has built-in snippets/macros for creating a fmt.PrintX statement from a given variable:
Note how the variable name is filled in for me.
I frequently write methods, and the Golang extension's meth snippet, in my opinion, is slow, since there are 5 (!) tab stops:
So far, I've written a snippet that mimics the meth snippet:
"Struct Method": {
"prefix": ".meth",
"body": [
"func ($1 $2) $3($4) $5 {",
"\t$6",
"}"
],
"description": "some description"
}
And I would like this snippet to mimic the print! macro/snippet, where it fills in the variable name; for the method snippet, instead of filling a variable, it would automatically fill in the method receiver ($1 and $2) with the first letter of the struct name, and the full struct name in the second.
So, if I have the following struct:
type SomeStruct struct {}
and type:
SomeStruct.meth
then activate the snippet, it should output:
func (s SomeStruct) .(.) . {
.
}
where each . is a tab stop.
Is this sort of snippet possible? If so, how can I write it so it does this?
One thing you can do is to make a snippet in a keybinding that can parse the current line. Put this into your keybindings.json:
{
"key": "alt+w",
"command": "editor.action.insertSnippet",
"args": {
"snippet": "\n\nfunc (${TM_CURRENT_LINE/\\s*type\\s*(.)(.*)\\s* struct\\s*{}/${1:/downcase} $1$2)/} $1($2) $3 {\n\t$4\n}"
},
// "when": "langId == golang"
}
The workflow is different than what you mentioned but is also easier - you don't have to type SomeStruct.meth. Just trigger the keybinding at the end of the type SomeStruct struct {} line as in the demo.
If you want to be anywhere in the document and trigger a snippet completion, then the HyperSnips extension may be the way to go.
I am working on a VS code extension for a custom language. This contains a snippet that allows the user to create a function with parameters and start to set up some documentation inside the function. The way I am achieving this is to use variable transforms on the parameter variable (${2}) using some matching tricks to extract each individual parameter and data type. In this simpler example, each parameter name will be on its own line inside a block comment.
"function": {
"prefix": "func",
"body": [
"function ${1:functionName}(${2:params})",
"${2/([^,]+), *|([^,]+$)/\t${BLOCK_COMMENT_START} ${1}${2} ${BLOCK_COMMENT_END}\n/g}",
"end"
]
}, ...
The expected output is this:
function functionName(hello,world)
{ hello }
{ world }
end
The actual output is this:
function functionName(hello,world)
${BLOCK_COMMENT_START} hello ${BLOCK_COMMENT_END}
${BLOCK_COMMENT_START} world ${BLOCK_COMMENT_END}
end
The issue is that ${BLOCK_COMMENT_START} and _END do not expand inside the transform. I can easily get around this issue by hardcoding the curly braces in the snippet, but I would prefer to find a way where I do not have to do that.
"body": [
"function ${1:functionName}(${2:params})",
"${2/([^,]+), *|([^,]+$)/\t{ ${1}${2} }\n/g}",
"end"
]
Is there a way that I can have a variable expand in the transform?
I write some code on GDscript which is similar to python.
It has an indentation folding strategy that is fine.
But I also like #region which is very useful when need to split code into sections:
variables, setters and getters, public functions...
I found several extensions which can manage folding strategy, but they have a side-effect:
The indentation folding strategy is gone.
The only way I found is to write some comment or special symbols when folding should be ended.
"explicitFolding.rules": {
"gdscript": [
{
"begin": "#spoiler",
"end": "#end"
},
{
"begin": "func",
"endRegex": "\t$"
}
]
},
But can I use indentation folding strategy and region folding together in vs-code?
So to solve that, need to change folding rules in language-extension settings.
C:\Users\usr\.vscode\extensions\geequlim.godot-tools-1.1.2\configurations\gdscript-configuration.json
Now, need to put this to end of language settings:
"folding": {
"offSide": true,
"markers": {
"start": "#\\s*region\\b",
"end": "#\\s*end\\b"
}
}
Or what you need.
Actually, I notice that there already was some Implementation of #region, but a bit harder to match that pattern.
Sorry for wasting ur time.
I want to indent my C++ code in Emacs in way similar to the "bsd" style, with one difference: access level modifiers must belong in their own indentation level. (Since I do not use either switch or labels/goto, it can be said generally that lines ending in a colon must belong in their own indentation level.) Here is an example:
class somewhat
{
private:
int whatever;
public:
void somehow()
{
if (something_about(whatever))
like_this();
else
{
std::cerr << "It is not true that something_about("
<< whatever << ").";
like_that();
}
}
};
How do I configure my ~/.emacs to reflect this preference? Here is my current configuration:
; No tabs at all.
(setq indent-tabs-width nil)
(setq tab-width 2)
; [C-like languages]-specific configuration.
(setq c-basic-offset 2)
(setq c-default-style "bsd")
; Configuration for other languages.
; ...
You need to modify the access-label indentation in your c-offsets-alist.
I recommend you make a new 'style' with its own c-offsets-alist and add a line like:
(access-label . +)
If you want to derive from bsd style, you can do something like this:
(c-add-style "modified-bsd"
'("bsd"
(c-basic-offset . 2)
;;...MORE MODS...
(c-offsets-alist
(access-label . +))))`
Also, how did I find the offset to modify? Go to the relevant line of code and press
C-cC-s to show the syntactic analysis of CC-mode. Also be sure to check the help for c-offsets-alist.