I want to use my own code snippets in Atom, but after hours of trying I am still not able to use more than first two of them and I cannot find a mistake.
When I was looking for a solution I found many, many topics but the mistake in each of them was repetitive usage of source scope but it is not my problem. I actually tried almost everything, I have made many changes in my syntax, but nothing helped.
".text.html.basic, .text.html.php":
"Include jQuery":
"prefix": "jquery"
"body": "<script src='https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js'></script>"
"Basic HTML structure":
"prefix": "start"
"body": '''
<!DOCTYPE html>
<html lang="cs">
<head>
<meta charset="utf-8">
<meta name="description" content="$1">
<meta name="author" content="MagicDev">
<meta name="keywords" content="$2">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="style.css">
<script src="script.js"></script>
<title>$3</title>
</head>
<body>
$4
</body>
</html>
'''
"DB Connection":
"prefix": "connection"
"body": '''
<?php
$servername = "$1";
$username = "$2";
$password = "$3";
$dbname = "$4";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
mysqli_query($conn, "set names utf8");
?>$5
'''
"DB Close Connection":
"prefix": "disconnection"
"body": "$conn->close();$1"
"DB Insert":
"prefix": "insert"
"body": '''
$sql = $conn->prepare("INSERT INTO ${1:"table"} (${2:"attributes"})
VALUES (${3:"?,?,?"})");
$sql->bind_param("${4:"ssi"}", ${5:"variablesToInsert"});
$sql->execute();
$sql->close();$6
'''
"Remove tags":
"prefix": "removeTags"
"body": "strip_tags($1)"
Can somebody save me, please? What am I overlooking?
Like CoffeeScript, CSON (CoffeeScript Object Notation) is indentation-sensitive. The first two snippets in your example are indented correctly, the following ones are one level too deep.
If you're unfamiliar with indentation-based language (and formats), I recommend using linter-coffeelint
. It marks all kinds of syntactical errors.
Example:
If you feel more at home using JSON, Atom also supports snippets saved in that format.
Lastly, here are your snippets with correct indentation:
".text.html.basic, .text.html.php":
"Include jQuery":
"prefix": "jquery"
"body": "<script src='https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js'></script>"
"Basic HTML structure":
"prefix": "start"
"body": '''
<!DOCTYPE html>
<html lang="cs">
<head>
<meta charset="utf-8">
<meta name="description" content="$1">
<meta name="author" content="MagicDev">
<meta name="keywords" content="$2">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="style.css">
<script src="script.js"></script>
<title>$3</title>
</head>
<body>
$4
</body>
</html>
'''
"DB Connection":
"prefix": "connection"
"body": '''
<?php
$servername = "$1";
$username = "$2";
$password = "$3";
$dbname = "$4";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
mysqli_query($conn, "set names utf8");
?>$5
'''
"DB Close Connection":
"prefix": "disconnection"
"body": "$conn->close();$1"
"DB Insert":
"prefix": "insert"
"body": '''
$sql = $conn->prepare("INSERT INTO ${1:"table"} (${2:"attributes"})
VALUES (${3:"?,?,?"})");
$sql->bind_param("${4:"ssi"}", ${5:"variablesToInsert"});
$sql->execute();
$sql->close();$6
'''
"Remove tags":
"prefix": "removeTags"
"body": "strip_tags($1)"