php - Atom 编辑器:如何为 php 以不同的方式突出显示单引号和双引号字符串
问题描述
我最近安装了 Clear Linux,他们的默认是 Atom 编辑器,所以我试了一下。使用 php-autocomplete,我几乎感到非常兴奋。直到我意识到我已经习惯了我的方式,我需要对单引号和双引号字符串进行不同的突出显示。
在php
双引号中的字符串仍将被解析为$variables
和空格转义字符,如\n
and \t
; 而单引号字符串是文字,单引号之间没有解释。
我已经养成了始终使用单引号作为数组键的习惯,并且它扰乱了我的潜意识,因为单引号字符串与双引号字符串看起来不同。我搜索了很多,找不到解决方案。
有谁知道实现这种突出显示方案的方法?
截图来自 Geany。即使在 Geany 中,获得此设置也不是标准的。值得庆幸的是,十年前,这在他们的主题中是正常的,因此我能够更改当前可用的主题以查找并更改string_2
为与string_2=string_1
.
为了更好地帮助人们理解php
和 之间的差异'
以及它们之间的差异"
可能具有怎样的重要性,以下是字符串在上下文中表现不同的一种方式:
$customer = "Bill Hawthorne";
$_address = "123 Main St\nGlendale, CA 91202";
$output = "Dear $customer, please confirm the below address is correct:\n\n$_address\n";
// $output renders as:
// Dear Bill Waltz, please confirm the below address is correct:
//
// 123 Main St
// Glendale, CA 91202
//
$output = 'Dear $customer, please confirm the below address is correct:\n\n$_address\n';
// $output renders as:
// Dear $customer, please confirm the below address is correct:\n\n$_address\n
解决方案
使用Editor: Log cursor scope
命令面板中的命令查看应用于文本部分的范围。此范围应用于 DOM 中的文本,并syntax--
添加到每个段的前面。
在 的情况下language-php
,范围是string.quoted.double.php
双引号字符串和string.quoted.single.php
单引号。以下是如何定位它们的示例。注意这部分是纯 CSS/Less;我不是很了解,所以在这里可能会更简洁。
// ~/.atom/styles.less
atom-text-editor[data-grammar="text html php"] { // target PHP
.syntax--string.syntax--quoted {
&.syntax--double,
&.syntax--double .syntax--punctuation.syntax--definition.syntax--string { // get the quote chars too
color: red;
}
&.syntax--single,
&.syntax--single .syntax--punctuation.syntax--definition.syntax--string {
color: yellow;
}
}
}
例如,用这个试试<?php "foo $bar" ?>
。
推荐阅读
- windows-10 - 我可以在 Ubuntu WSL 中使用 Python QT 开发 GUI 软件吗?
- java - 硒。硒化物。由于某种原因找不到 org.openqa.selenium.WrapsDriver 的类文件
- angular - 推送到数组时的角度数据绑定更新,无需克隆或使用 observables
- javascript - 模型未根据角度 6 中的订阅回调进行相应更新
- javascript - 嵌套三元组的最佳替代品是什么?
- c# - Visual Studio 2017 asp.net 网站仅发布必要的文件
- python - Python sqlite3 查询生成
- python - 为 Supervisor 安装 Python 2.x 和 3.x Linux
- android - 在 android 设备上运行的 Ionic Cordova 给出:找不到 apk 架构:arm build-type:debug
- vbscript - Word 错误“Word 无法创建工作文件。请检查临时环境变量”